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