3 #############################################################
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
)
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
))
23 $(foreach name
, $(NAMES
), $(eval
$(call REMOVE_REPEAT_FILES
,$(name
))))
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
)
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
))
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 #############################################################
49 $(2)$(OBJ_SUFFIX
) : $(2).c
50 $(CC
) $(1) $(CFLAGS-o
) $(2)$(OBJ_SUFFIX
) $(2).c
54 $(2)$(OBJ_SUFFIX
) : $(2).
cpp
55 $(CC
) $(1) $(CFLAGS-o
) $(2)$(OBJ_SUFFIX
) $(2).
cpp
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
)
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
)
69 $(1)_
$(2)_all
: $($(2)_PREFIX
)$(1)$($(2)_SUFFIX
)
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
))))
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
)
88 $(LD
) $(LDFLAGS-o
) $$@
$$^
$(addsuffix $(OBJ_SUFFIX
), $($(1)_OBJ_FILES
)) $($(1)_LDFLAGS
)
90 $(LIB_PREFIX
)$(1)$(LIB_SUFFIX
): $($(1)_OBJS
)
92 $(AR
) $($(1)_ARFLAGS
) $$@
$$^
$(addsuffix $(OBJ_SUFFIX
), $($(1)_OBJ_FILES
))
93 $(if
$(RANLIB
),$(RANLIB
) $$@
,)
95 $(DLL_PREFIX
)$(1)$(DLL_SUFFIX
): $($(1)_OBJS
)
97 $(LD
) $(LDFLAGS-o
) $$@
$$^
$(addsuffix $(OBJ_SUFFIX
), $($(1)_OBJ_FILES
)) $($(1)_LDFLAGS
) $($(1)_SHFLAGS
)
101 define MAKE_ALL_SUB_PROS
106 define MAKE_ALL_DEP_PROS
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 #############################################################
121 -$(RM
) $($(2)_PREFIX
)$(1)$($(2)_SUFFIX
)
125 define MAKE_CLEAN_FILE
130 define MAKE_CLEAN_SUB_PROS
132 $(MAKE
) -C
$(1) clean
135 define MAKE_CLEAN_DEP_PROS
137 $(MAKE
) -C
$(1) clean
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 #############################################################
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
)))
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
178 $(dir $(patsubst $(SRC_DIR
)$(_
)%,$(BIN_DIR
)$(_
)inc
$(_
)%,$(1)))
181 # generate library dir
183 $(dir $(patsubst $(SRC_DIR
)$(_
)%,$(BIN_DIR
)$(_
)lib
$(_
)%,$(1)))
188 $(dir $(patsubst $(SRC_DIR
)$(_
)%,$(BIN_DIR
)$(_
)bin
$(_
)%,$(1)))
193 $(dir $(patsubst $(SRC_DIR
)$(_
)%,$(BIN_DIR
)$(_
)obj
$(_
)%,$(1)))
196 define MAKE_INSTALL_INC_FILES
198 -@
$(MKDIR
) $(call BIN_INC_DIR
, $(1))
199 -@
$(CP
) $(1) $(call BIN_INC_DIR
, $(1))
202 define MAKE_INSTALL_LIB_FILES
204 -@
$(MKDIR
) $(call BIN_LIB_DIR
, $(1))
205 -@
$(CP
) $(1) $(call BIN_LIB_DIR
, $(1))
208 define MAKE_INSTALL_BIN_FILES
210 -@
$(MKDIR
) $(call BIN_BIN_DIR
, $(1))
211 -@
$(CP
) $(1) $(call BIN_BIN_DIR
, $(1))
214 define MAKE_INSTALL_OBJ_FILES
216 -@
$(MKDIR
) $(call BIN_OBJ_DIR
, $(1))
217 -@
$(CP
) $(1) $(call BIN_OBJ_DIR
, $(1))
220 define MAKE_INSTALL_SUB_PROS
221 SUB_PROS_
$(1)_install
:
222 $(MAKE
) -C
$(1) install
225 define MAKE_INSTALL_DEP_PROS
226 DEP_PROS_
$(1)_install
:
227 $(MAKE
) -C
$(1) install
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
))))