]> rtime.felk.cvut.cz Git - omk.git/blob - snippets/cprog
8433ac5d4be01ecd42c1c4993f1208db000902d8
[omk.git] / snippets / cprog
1 c++ext = cc C cxx cpp
2 c++sources = $(foreach ext,$(c++ext),$(filter %.$(ext),$(1)))
3
4 ###
5 # template_variables - variables common to program, libraries, ...
6 #
7 define template_variables
8 USER_IDLS  += $$($(1)_SERVER_IDL) $$($(1)_CLIENT_IDL) $$($(1)_IDL)
9 $(1)_GEN_SOURCES += $$(call IDL_SERVER_SOURCES,$$($(1)_SERVER_IDL))
10 $(1)_GEN_SOURCES += $$(call IDL_CLIENT_SOURCES,$$($(1)_CLIENT_IDL))
11 $(1)_GEN_SOURCES += $$(sort $$(call IDL_SERVER_SOURCES,$$($(1)_IDL)) \
12                             $$(call IDL_CLIENT_SOURCES,$$($(1)_IDL)))
13 USER_GEN_SOURCES += $$($(1)_GEN_SOURCES)
14 $(1)_OBJS += $(foreach ext,c $(c++ext),$$(patsubst %.$(ext),%.o,$$(filter %.$(ext),$$($(1)_SOURCES) $$($(1)_GEN_SOURCES))))
15 $(1)_OBJS := $$(sort $$($(1)_OBJS:%/=%)) # Why is here the backslash substitution???
16 $(1)_OBJS := $$(addprefix $(USER_OBJS_DIR)/,$$(sort $$($(1)_OBJS:%/=%)))
17
18 USER_OBJS  += $$($(1)_OBJS)
19 USER_SOURCES += $$($(1)_SOURCES)
20 endef
21
22 ###
23 # program_template
24 #
25 # Usage: $(call program_template,<executable-name>,<bin|utils|test>)
26 define program_template
27 $(template_variables)
28 $$(eval $$(call prepare_rule_goal,\
29         $(USER_BIN_DIR)/$(1)$(EXE_SUFFIX),\
30         $$($(1)_OBJS),\
31         "LINK    ",\
32         $$(call program_cmd,$(1))))
33 endef
34
35 ###
36 # library_template
37 #
38 # Usage: $(call library_template,<library-name>)
39 define library_template
40 $(template_variables)
41 $$(eval $$(call prepare_rule_goal,\
42         $(USER_LIB_DIR)/lib$(1).a,\
43         $$($(1)_OBJS),\
44         "AR      ",\
45         $$(call library_cmd,$(1))))
46 endef
47
48 ###
49 # solib_template
50 #
51 # Usage: $(call solib_template,<library-name>)
52 define solib_template
53 $(template_variables) # FIXME: OBJSLO, etc.
54 # TODO: Add dependencies on other shared libraries ala:
55 # $(1)_libs += $$($(1)_LIBS) $$(lib_LOADLIBES)
56 # $(1)_shared_libs = $$(patsubst %,$(USER_LIB_DIR)/lib%.$(SOLIB_EXT),$$(filter $$(shared_libs),$$($(1)_libs)))
57
58 $$(eval $$(call prepare_rule_goal,\
59         $(USER_LIB_DIR)/lib$(1).$(SOLIB_EXT),\
60         $$($(1)_OBJS),\
61         "LINK    ",\
62         $$(call solib_cmd,$(1))))
63 endef
64
65 ifneq ($(bin_PROGRAMS)$(test_PROGRAMS)$(utils_PROGRAMS)$(lib_LIBRARIES)$(shared_LIBRARIES),)
66 prepare-pass::
67         @$(call mkdir_def,$(USER_OBJS_DIR))
68 endif
69
70 # TODO: $(foreach cmetrh,...)
71
72 $(foreach prog,$(bin_PROGRAMS),$(eval $(call program_template,$(prog),bin)))
73 $(foreach prog,$(utils_PROGRAMS),$(eval $(call program_template,$(prog),utils)))
74 $(foreach prog,$(test_PROGRAMS),$(eval $(call program_template,$(prog),test)))
75 $(foreach lib,$(lib_LIBRARIES),$(eval $(call library_template,$(lib))))
76 $(foreach lib,$(shared_LIBRARIES),$(eval $(call solib_template,$(lib))))
77
78 $(foreach src,$(filter %.c,$(USER_SOURCES)),\
79         $(eval $(call prepare_rule,\
80                 $(USER_OBJS_DIR)/$(src:%.c=%.o),\
81                 $(SOURCES_DIR)/$(src),\
82                 "CC      ",\
83                 $(c_o_cmd))))