update suffix.mak
[ti-make.git] / suffix.mak
blob4bee3d9842e2198b23067c121e5b41bf354b8dd0
1 # suffix makefile
3 #############################################################
4 # make define
5 # #
7 # append source files
8 define MAKE_DEFINE_FILES
9 $(1)_C_FILES += $($(1)_C_FILES-y)
10 $(1)_CPP_FILES += $($(1)_CPP_FILES-y)
11 $(1)_ASM_FILES += $($(1)_ASM_FILES-y)
12 $(1)_OBJ_FILES += $($(1)_OBJ_FILES-y)
13 endef
14 $(foreach name, $(NAMES), $(eval $(call MAKE_DEFINE_FILES,$(name))))
16 # remove repeat source files
17 define REMOVE_REPEAT_FILES
18 $(1)_C_FILES := $(sort $($(1)_C_FILES))
19 $(1)_CPP_FILES := $(sort $($(1)_CPP_FILES))
20 $(1)_ASM_FILES := $(sort $($(1)_ASM_FILES))
21 $(1)_OBJ_FILES := $(sort $($(1)_OBJ_FILES))
22 endef
23 $(foreach name, $(NAMES), $(eval $(call REMOVE_REPEAT_FILES,$(name))))
26 # cflags & ldflags
27 define MAKE_DEFINE_FLAGS
28 $(1)_CFLAGS := $(CFLAGS) $(CFLAGS-I)$(INC_DIR) $(addprefix $(CFLAGS-I), $($(1)_INC_DIR)) $($(1)_CFLAGS)
29 $(1)_LDFLAGS := $(LDFLAGS) $(LDFLAGS-L)$(LIB_DIR) $(addprefix $(LDFLAGS-L), $($(1)_LIB_DIR)) $(addprefix $(LDFLAGS-l), $($(1)_LIBS)) $($(1)_LDFLAGS)
30 $(1)_ASFLAGS := $(ASFLAGS) $(ASFLAGS-I)$(INC_DIR) $(addprefix $(ASFLAGS-I), $($(1)_INC_DIR)) $($(1)_ASFLAGS)
31 $(1)_ARFLAGS := $(ARFLAGS)
32 $(1)_SHFLAGS := $(SHFLAGS) $($(1)_SHFLAGS)
33 endef
34 $(foreach name, $(NAMES), $(eval $(call MAKE_DEFINE_FLAGS,$(name))))
36 # generate objects & source files list
37 define MAKE_DEFINE_OBJS_SRCS
38 $(1)_OBJS := $(addsuffix $(OBJ_SUFFIX), $($(1)_FILES))
39 $(1)_SRCS := $(addsuffix .c, $($(1)_C_FILES)) $(addsuffix .cpp, $($(1)_CPP_FILES)) $(addsuffix $(ASM_SUFFIX), $($(1)_ASM_FILES))
40 endef
41 $(foreach name, $(NAMES), $(eval $(name)_FILES := $($(name)_C_FILES) $($(name)_CPP_FILES) $($(name)_ASM_FILES)))
42 $(foreach name, $(NAMES), $(eval $(call MAKE_DEFINE_OBJS_SRCS,$(name))))
44 #############################################################
45 # make all
46 # #
48 define MAKE_OBJ_C
49 $(2)$(OBJ_SUFFIX) : $(2).c
50 $(CC) $(1) $(CFLAGS-o) $(2)$(OBJ_SUFFIX) $(2).c
51 endef
53 define MAKE_OBJ_CPP
54 $(2)$(OBJ_SUFFIX) : $(2).cpp
55 $(CC) $(1) $(CFLAGS-o) $(2)$(OBJ_SUFFIX) $(2).cpp
56 endef
58 define MAKE_OBJ_ASM_WITH_CC
59 $(2)$(OBJ_SUFFIX) : $(2)$(ASM_SUFFIX)
60 $(CC) $(1) $(CFLAGS-o) $(2)$(OBJ_SUFFIX) $(2)$(ASM_SUFFIX)
61 endef
63 define MAKE_OBJ_ASM_WITH_AS
64 $(2)$(OBJ_SUFFIX) : $(2)$(ASM_SUFFIX)
65 $(AS) $(1) $(ASFLAGS-o) $(2)$(OBJ_SUFFIX) $(2)$(ASM_SUFFIX)
66 endef
68 define MAKE_ALL
69 $(1)_$(2)_all: $($(2)_PREFIX)$(1)$($(2)_SUFFIX)
70 $($(1)_SUFFIX_CMD1)
71 $($(1)_SUFFIX_CMD2)
72 $($(1)_SUFFIX_CMD3)
73 $($(1)_SUFFIX_CMD4)
74 $($(1)_SUFFIX_CMD5)
76 $($(2)_PREFIX)$(1)$($(2)_SUFFIX): $($(1)_OBJS)
77 $(foreach file, $($(1)_C_FILES), $(eval $(call MAKE_OBJ_C,$($(1)_CFLAGS),$(file))))
78 $(foreach file, $($(1)_CPP_FILES), $(eval $(call MAKE_OBJ_CPP,$($(1)_CFLAGS),$(file))))
80 $(if $(AS)
81 ,$(foreach file, $($(1)_ASM_FILES), $(eval $(call MAKE_OBJ_ASM_WITH_AS,$($(1)_ASFLAGS),$(file))))
82 ,$(foreach file, $($(1)_ASM_FILES), $(eval $(call MAKE_OBJ_ASM_WITH_CC,$($(1)_CFLAGS),$(file))))
86 $(BIN_PREFIX)$(1)$(BIN_SUFFIX): $($(1)_OBJS)
87 -$(RM) $$@
88 $(LD) $(LDFLAGS-o) $$@ $$^ $(addsuffix $(OBJ_SUFFIX), $($(1)_OBJ_FILES)) $($(1)_LDFLAGS)
90 $(LIB_PREFIX)$(1)$(LIB_SUFFIX): $($(1)_OBJS)
91 -$(RM) $$@
92 $(AR) $($(1)_ARFLAGS) $$@ $$^ $(addsuffix $(OBJ_SUFFIX), $($(1)_OBJ_FILES))
93 $(if $(RANLIB),$(RANLIB) $$@,)
95 $(DLL_PREFIX)$(1)$(DLL_SUFFIX): $($(1)_OBJS)
96 -$(RM) $$@
97 $(LD) $(LDFLAGS-o) $$@ $$^ $(addsuffix $(OBJ_SUFFIX), $($(1)_OBJ_FILES)) $($(1)_LDFLAGS) $($(1)_SHFLAGS)
98 endef
101 define MAKE_ALL_SUB_PROS
102 SUB_PROS_$(1)_all:
103 $(MAKE) -C $(1)
104 endef
106 define MAKE_ALL_DEP_PROS
107 DEP_PROS_$(1)_all:
108 $(MAKE) -C $(1)
109 endef
111 all: $(foreach pro, $(DEP_PROS), DEP_PROS_$(pro)_all) $(foreach name, $(NAMES), $(if $($(name)_FILES), $(name)_$($(name)_TYPE)_all, )) $(foreach pro, $(SUB_PROS), SUB_PROS_$(pro)_all)
112 $(foreach name, $(NAMES), $(if $($(name)_FILES), $(eval $(call MAKE_ALL,$(name),$($(name)_TYPE))), ))
113 $(foreach pro, $(DEP_PROS), $(eval $(call MAKE_ALL_DEP_PROS,$(pro))))
114 $(foreach pro, $(SUB_PROS), $(eval $(call MAKE_ALL_SUB_PROS,$(pro))))
116 #############################################################
117 # make clean
119 define MAKE_CLEAN
120 $(1)_$(2)_clean:
121 -$(RM) $($(2)_PREFIX)$(1)$($(2)_SUFFIX)
122 -$(RM) $($(1)_OBJS)
123 endef
125 define MAKE_CLEAN_FILE
126 $(1)_clean:
127 -$(RM) $(1)
128 endef
130 define MAKE_CLEAN_SUB_PROS
131 SUB_PROS_$(1)_clean:
132 $(MAKE) -C $(1) clean
133 endef
135 define MAKE_CLEAN_DEP_PROS
136 DEP_PROS_$(1)_clean:
137 $(MAKE) -C $(1) clean
138 endef
140 # generate full path
141 CLEAN_FILES := $(addprefix $(shell $(PWD))$(_), $(CLEAN_FILES))
143 clean: $(foreach pro, $(DEP_PROS), DEP_PROS_$(pro)_clean) \
144 $(foreach name, $(NAMES), $(name)_$($(name)_TYPE)_clean) \
145 $(foreach file, $(CLEAN_FILES), $(file)_clean) \
146 $(foreach pro, $(SUB_PROS), SUB_PROS_$(pro)_clean)
148 $(foreach name, $(NAMES), $(eval $(call MAKE_CLEAN,$(name),$($(name)_TYPE))))
149 $(foreach file, $(CLEAN_FILES), $(eval $(call MAKE_CLEAN_FILE,$(file))))
150 $(foreach pro, $(DEP_PROS), $(eval $(call MAKE_CLEAN_DEP_PROS,$(pro))))
151 $(foreach pro, $(SUB_PROS), $(eval $(call MAKE_CLEAN_SUB_PROS,$(pro))))
153 #############################################################
154 # make install
157 # install files
158 $(foreach name, $(NAMES), $(eval $(if $(findstring LIB, $($(name)_TYPE)), LIB_FILES += $(LIB_PREFIX)$(name)$(LIB_SUFFIX), )))
159 $(foreach name, $(NAMES), $(eval $(if $(findstring DLL, $($(name)_TYPE)), LIB_FILES += $(DLL_PREFIX)$(name)$(DLL_SUFFIX), )))
160 $(foreach name, $(NAMES), $(eval $(if $(findstring BIN, $($(name)_TYPE)), BIN_FILES += $(BIN_PREFIX)$(name)$(BIN_SUFFIX), )))
161 $(foreach name, $(NAMES), $(eval OBJ_FILES += $($(name)_OBJS)))
163 # generate full path
164 INC_FILES := $(addprefix $(shell $(PWD))$(_), $(INC_FILES))
165 LIB_FILES := $(addprefix $(shell $(PWD))$(_), $(LIB_FILES))
166 BIN_FILES := $(addprefix $(shell $(PWD))$(_), $(BIN_FILES))
167 OBJ_FILES := $(addprefix $(shell $(PWD))$(_), $(OBJ_FILES))
169 INC_FILES := $(sort $(INC_FILES))
170 LIB_FILES := $(sort $(LIB_FILES))
171 BIN_FILES := $(sort $(BIN_FILES))
172 OBJ_FILES := $(sort $(OBJ_FILES))
174 INSTALL_FILES := $(INC_FILES) $(LIB_FILES) $(BIN_FILES) $(OBJ_FILES)
176 # generate include dir
177 define BIN_INC_DIR
178 $(dir $(patsubst $(SRC_DIR)$(_)%,$(BIN_DIR)$(_)inc$(_)%,$(1)))
179 endef
181 # generate library dir
182 define BIN_LIB_DIR
183 $(dir $(patsubst $(SRC_DIR)$(_)%,$(BIN_DIR)$(_)lib$(_)%,$(1)))
184 endef
186 # generate bin dir
187 define BIN_BIN_DIR
188 $(dir $(patsubst $(SRC_DIR)$(_)%,$(BIN_DIR)$(_)bin$(_)%,$(1)))
189 endef
191 # generate obj dir
192 define BIN_OBJ_DIR
193 $(dir $(patsubst $(SRC_DIR)$(_)%,$(BIN_DIR)$(_)obj$(_)%,$(1)))
194 endef
196 define MAKE_INSTALL_INC_FILES
197 $(1)_install:
198 -@$(MKDIR) $(call BIN_INC_DIR, $(1))
199 -@$(CP) $(1) $(call BIN_INC_DIR, $(1))
200 endef
202 define MAKE_INSTALL_LIB_FILES
203 $(1)_install:
204 -@$(MKDIR) $(call BIN_LIB_DIR, $(1))
205 -@$(CP) $(1) $(call BIN_LIB_DIR, $(1))
206 endef
208 define MAKE_INSTALL_BIN_FILES
209 $(1)_install:
210 -@$(MKDIR) $(call BIN_BIN_DIR, $(1))
211 -@$(CP) $(1) $(call BIN_BIN_DIR, $(1))
212 endef
214 define MAKE_INSTALL_OBJ_FILES
215 $(1)_install:
216 -@$(MKDIR) $(call BIN_OBJ_DIR, $(1))
217 -@$(CP) $(1) $(call BIN_OBJ_DIR, $(1))
218 endef
220 define MAKE_INSTALL_SUB_PROS
221 SUB_PROS_$(1)_install:
222 $(MAKE) -C $(1) install
223 endef
225 define MAKE_INSTALL_DEP_PROS
226 DEP_PROS_$(1)_install:
227 $(MAKE) -C $(1) install
228 endef
230 install: $(foreach pro, $(DEP_PROS), DEP_PROS_$(pro)_install) $(foreach file, $(INSTALL_FILES), $(file)_install) $(foreach pro, $(SUB_PROS), SUB_PROS_$(pro)_install)
232 $(foreach file, $(INC_FILES), $(eval $(call MAKE_INSTALL_INC_FILES,$(file))))
233 $(foreach file, $(LIB_FILES), $(eval $(call MAKE_INSTALL_LIB_FILES,$(file))))
234 $(foreach file, $(BIN_FILES), $(eval $(call MAKE_INSTALL_BIN_FILES,$(file))))
235 $(foreach file, $(OBJ_FILES), $(eval $(call MAKE_INSTALL_OBJ_FILES,$(file))))
236 $(foreach pro, $(DEP_PROS), $(eval $(call MAKE_INSTALL_DEP_PROS,$(pro))))
237 $(foreach pro, $(SUB_PROS), $(eval $(call MAKE_INSTALL_SUB_PROS,$(pro))))