1 # Version for system-less builds.
4 # bin_PROGRAMS .. list of the require binary programs
5 # include_HEADERS .. list of the user-space public header files
6 # lib_LIBRARIES .. list of the user-space libraries
7 # lib_LDSCRIPTS .. list of LD scripts that should be copied to the lib direcotry
8 # lib_obj_SOURCES .. list of source files which should be compiled and
9 # the produced object file placed to the lib directory (e.g. crt0.S)
10 # shared_LIBRARIES .. list of the user-space shared libraries
11 # nobase_include_HEADERS .. public headers copied even with directory part
12 # renamed_include_HEADERS .. public headers copied to the different target name (xxx.h->yyy.h)
13 # utils_PROGRAMS .. list of the development utility programs (compiled for host computer, this might change in future)
14 # xxx_SOURCES .. list of specific target sources
15 # xxx_LIBS .. list of specific target libraries
16 # INCLUDES .. additional include directories and defines for user-space
17 # lib_LOADLIBES .. list of libraries linked to each executable
18 # link_VARIANTS .. list of ld script suffixes (after hypen `-') that
19 # should be used for linking (e.g. ram flash). If this is not
20 # specified, then the value of DEFAULT_LD_SCRIPT_VARIANT from config.target is used.
21 # PREFIX_DIR .. Prefix to directories in _compiled and _build. Used in config.omk.
23 # Some support to serialize some targets for parallel make
24 ifneq ($(OMK_SERIALIZE_INCLUDED),y)
25 include-pass: $(check-dir)
26 library-pass: include-pass
27 binary-pass utils-pass: library-pass
29 OMK_SERIALIZE_INCLUDED = y
32 # -------------------------------------
33 # Rules for compilation for target
34 ifdef TARGET_RULE_TEMPLATES
36 LDFLAGS += -nostartfiles
38 # FIXME: These are not used. What they are good for?
39 LIB_CPPFLAGS += $(CPPFLAGS)
40 LIB_CFLAGS += $(CFLAGS)
42 SOLIB_PICFLAGS += -shared -fpic
44 CFLAGS += -DOMK_FOR_TARGET
46 INCLUDE_DIR := $(USER_INCLUDE_DIR)
47 LIB_DIR := $(USER_LIB_DIR)
48 OBJS_DIR := $(USER_OBJS_DIR)
50 $(eval $(COMPILER_DEFS_template))
52 # Special rules for CMETRIC generated headers
54 $(foreach cmetrh,$(cmetric_include_HEADERS),$(eval $(call COMPILE_c_o_template,\
55 $(SOURCES_DIR)/$($(basename $(notdir $(cmetrh)))_CMETRIC_SOURCES),\
56 $($(basename $(notdir $(cmetrh)))_CMETRIC_SOURCES:%.c=%.o),)))
57 $(foreach cmetrh,$(cmetric_include_HEADERS),$(eval $(call CMETRIC_o_h_template,\
58 $($(basename $(notdir $(cmetrh)))_CMETRIC_SOURCES:%.c=%.o),\
59 $(addprefix $(USER_INCLUDE_DIR)/,$(cmetrh)))))
61 GEN_HEADERS+=$(cmetric_include_HEADERS:%=$(USER_INCLUDE_DIR)/%)
63 # Generate rules for compilation of programs and libraries
64 ifneq ($(link_VARIANTS),)
65 $(foreach prog,$(bin_PROGRAMS),$(foreach link,$(link_VARIANTS),$(eval $(call PROGRAM_template,$(prog),$(USER_BIN_DIR),$(link)))))
67 $(foreach prog,$(bin_PROGRAMS),$(eval $(call PROGRAM_template,$(prog),$(USER_BIN_DIR))))
70 $(foreach lib,$(lib_LIBRARIES),$(eval $(call LIBRARY_template,$(lib))))
71 $(foreach src,$(lib_obj_SOURCES),$(eval $(call LIBOBJ_template,$(addsuffix $(OBJ_EXT),$(basename $(src))))))
72 $(foreach lib,$(shared_LIBRARIES),$(eval $(call SOLIB_template,$(lib))))
75 # lib_obj_SOURCES handling
76 lib_OBJS = $(addsuffix $(OBJ_EXT),$(basename $(lib_obj_SOURCES)))
77 #$(warning lib_OBJS = $(lib_OBJS))
78 SOURCES += $(filter-out %$(OBJ_EXT),$(lib_obj_SOURCES))
80 $(LIB_DIR)/%$(OBJ_EXT): %$(OBJ_EXT)
81 @echo " CP $(^:$(MAKERULES_DIR)/%=%) -> $(@:$(MAKERULES_DIR)/%=%)"
82 $(Q)cp $(CP_FLAGS) $< $@
85 # User-space static libraries and applications object files
86 SOURCES := $(sort $(SOURCES))
87 #$(warning SOURCES = $(SOURCES))
89 # User-space shared libraries object files
90 SOLIB_SOURCES := $(sort $(SOLIB_SOURCES))
91 #$(warning SOLIB_SOURCES = $(SOLIB_SOURCES))
94 # The above generated rules produced $(SOURCES) and $(SOLIB_SOURCES)
95 # variables. Now generate rules for compilation of theese sources
96 $(foreach src,$(filter %.c,$(SOURCES)),$(eval $(call COMPILE_c_o_template,$(SOURCES_DIR)/$(src),$(src:%.c=%$(OBJ_EXT)),)))
97 $(foreach src,$(filter %.cc,$(SOURCES)),$(eval $(call COMPILE_cc_o_template,$(SOURCES_DIR)/$(src),$(src:%.cc=%$(OBJ_EXT)),)))
98 $(foreach src,$(filter %.cxx,$(SOURCES)),$(eval $(call COMPILE_cc_o_template,$(SOURCES_DIR)/$(src),$(src:%.cxx=%$(OBJ_EXT)),)))
99 $(foreach src,$(filter %$(ASM_EXT),$(SOURCES)),$(eval $(call COMPILE_S_o_template,$(SOURCES_DIR)/$(src),$(src:%$(ASM_EXT)=%$(OBJ_EXT)),)))
101 $(foreach src,$(filter %.c,$(SOLIB_SOURCES)),$(eval $(call COMPILE_c_o_template,$(SOURCES_DIR)/$(src),$(src:%.c=%.lo),$(SOLIB_PICFLAGS))))
102 $(foreach src,$(filter %.cc,$(SOLIB_SOURCES)),$(eval $(call COMPILE_cc_o_template,$(SOURCES_DIR)/$(src),$(src:%.cc=%.lo),$(SOLIB_PICFLAGS))))
103 $(foreach src,$(filter %.cxx,$(SOLIB_SOURCES)),$(eval $(call COMPILE_cc_o_template,$(SOURCES_DIR)/$(src),$(src:%.cxx=%.lo),$(SOLIB_PICFLAGS))))
104 $(foreach src,$(filter %$(ASM_EXT),$(SOLIB_SOURCES)),$(eval $(call COMPILE_S_o_template,$(SOURCES_DIR)/$(src),$(src:%$(ASM_EXT)=%.lo),$(SOLIB_PICFLAGS))))
106 library-pass-local: $(addprefix $(USER_INCLUDE_DIR)/,$(cmetric_include_HEADERS)) \
107 $(lib_LIBRARIES:%=$(LIB_DIR)/$(LIB_PREF)%$(LIB_EXT)) $(shared_LIBRARIES:%=$(LIB_DIR)/$(LIB_PREF)%.so) \
108 $(addprefix $(LIB_DIR)/,$(lib_OBJS))
110 ifneq ($(link_VARIANTS),)
111 binary-pass-local: $(foreach link,$(link_VARIANTS),$(bin_PROGRAMS:%=$(USER_BIN_DIR)/%-$(link)) \
112 $(foreach of,$(OUTPUT_FORMATS),$(bin_PROGRAMS:%=$(USER_BIN_DIR)/%-$(link).$(of))))
114 binary-pass-local: $(bin_PROGRAMS:%=$(USER_BIN_DIR)/%) \
115 $(foreach of,$(OUTPUT_FORMATS),$(bin_PROGRAMS:%=$(USER_BIN_DIR)/%.$(of)))
118 endif # TARGET_RULE_TEMPLATES
121 # -------------------------------------
122 # Rules for compilation utilities for host (user space)
123 ifdef HOST_RULE_TEMPLATES
128 SOLIB_PICFLAGS += -shared -fpic
130 # For host compilation, we don't use a specfic ld script
133 # TODO: It is probably better to use different directories for host
134 # includes, libraries and objects
135 INCLUDE_DIR := $(USER_INCLUDE_DIR)
136 LIB_DIR := $(USER_LIB_DIR)
137 OBJS_DIR := $(USER_OBJS_DIR)
139 $(eval $(COMPILER_DEFS_template))
141 #User-space static libraries and applications object files
142 #SOURCES := $(sort $(SOURCES))
143 #$(warning SOURCES = $(SOURCES))
145 # Generate rules for compilation of utility programs
146 $(foreach prog,$(utils_PROGRAMS),$(eval $(call PROGRAM_template,$(prog),$(USER_UTILS_DIR),)))
148 # The above generated rule produced $(SOURCES) variable. Now generate
149 # rules for compilation of theese sources
150 $(foreach src,$(filter %.c,$(SOURCES)),$(eval $(call COMPILE_c_o_template,$(SOURCES_DIR)/$(src),$(src:%.c=%$(OBJ_EXT)),)))
151 $(foreach src,$(filter %.cc,$(SOURCES)),$(eval $(call COMPILE_cc_o_template,$(SOURCES_DIR)/$(src),$(src:%.cc=%$(OBJ_EXT)),)))
152 $(foreach src,$(filter %.cxx,$(SOURCES)),$(eval $(call COMPILE_cc_o_template,$(SOURCES_DIR)/$(src),$(src:%.cxx=%$(OBJ_EXT)),)))
153 $(foreach src,$(filter %$(ASM_EXT),$(SOURCES)),$(eval $(call COMPILE_S_o_template,$(SOURCES_DIR)/$(src),$(src:%$(ASM_EXT)=%$(OBJ_EXT)),)))
155 utils-pass-local: $(utils_PROGRAMS:%=$(USER_UTILS_DIR)/%)
157 endif # HOST_RULE_TEMPLATES
160 #=====================================================================
161 # Automatic loading of compiled program by issuing "make load"
163 ifneq ($(OUTPUT_FORMATS),)
164 # Select a file extension (e.g. .bin) for "make load" command to load.
165 LOAD_EXTENSION = .$(firstword $(OUTPUT_FORMATS))
168 # Syntax: $(call LOAD_PROGRAM_template,<executable-name>,<dir>,<link-variant>)
169 # Used to load program to the target hardware
170 define LOAD_PROGRAM_template
171 .PHONY: load-$(1)$(3:%=-%)
172 load-$(1)$(3:%=-%): $(2)/$(1)$(3:%=-%)$(LOAD_EXTENSION)
173 @$(QUIET_CMD_ECHO) " LOAD $$<"
174 @if [ -z "$$(LOAD_CMD$(3:%=-%))" ]; then echo "No command for loading applications to '$(3)' is specified."; exit 1; fi
175 $(Q) $$(LOAD_CMD$(3:%=-%)) $$<
178 # Syntax: $(call LOAD__RUN_VARIANT_template,<link-variant>)
179 # Used to load and/or run non-default variant of the default program
180 define LOAD_RUN_VARIANT_template
181 .PHONY: load-$(1) run-$(1)
183 load-$(1): load-$(firstword $(bin_PROGRAMS))-$(1)
186 @$(QUIET_CMD_ECHO) " RUN $(1)"
187 @if [ -z "$(RUN_CMD-$(1))" ]; then echo "No command for running '$(1)' variant is specified."; exit 1; fi
192 $(foreach link,$(link_VARIANTS),$(foreach prog,$(bin_PROGRAMS),$(eval $(call LOAD_PROGRAM_template,$(prog),$(USER_BIN_DIR),$(link)))))
193 $(foreach link,$(link_VARIANTS),$(eval $(call LOAD_RUN_VARIANT_template,$(link))))
196 load: $(addprefix load-,$(firstword $(bin_PROGRAMS))-$(firstword $(link_VARIANTS)))
198 run: run-$(firstword $(link_VARIANTS))
202 #=====================================================================
203 # Generate pass rules from generic templates
204 OTHER_PASSES = dep clean install
206 $(eval $(call omk_pass_template, include-pass, $(LOCAL_BUILD_DIR),,$(include_HEADERS)$(nobase_include_HEADERS)$(renamed_include_HEADERS)$(lib_LDSCRIPTS)$(config_include_HEADERS)))
207 $(eval $(call omk_pass_template, library-pass, $(LOCAL_BUILD_DIR),TARGET_RULE_TEMPLATES=y,$(lib_LIBRARIES)$(shared_LIBRARIES)$(lib_obj_SOURCES)))
208 $(eval $(call omk_pass_template, binary-pass, $(LOCAL_BUILD_DIR),TARGET_RULE_TEMPLATES=y,$(bin_PROGRAMS)))
209 $(eval $(call omk_pass_template, utils-pass, $(LOCAL_BUILD_DIR),HOST_RULE_TEMPLATES=y,$(utils_PROGRAMS)))
212 $(eval $(call omk_pass_template,$(OTHER_PASSES),$(LOCAL_BUILD_DIR),,always))
220 $(call include-pass-template,$(USER_INCLUDE_DIR),include)
221 @$(foreach f, $(lib_LDSCRIPTS), cmp --quiet $(SOURCES_DIR)/$(f) $(USER_LIB_DIR)/$(notdir $(f)) \
222 || $(call cp_cmd,$(SOURCES_DIR)/$(f),$(USER_LIB_DIR)/$(notdir $(f))) || exit 1 ; )
226 clean-local: clean-custom
227 $(Q)rm -f $(USER_OBJS_DIR)/*.o $(USER_OBJS_DIR)/*.lo \
228 $(USER_OBJS_DIR)/*.d \
229 $(USER_OBJS_DIR)/*.map \
230 $(LOCAL_CONFIG_H:%=$(USER_OBJS_DIR)/%)
233 @$(call mkdir_def,$(USER_INCLUDE_DIR))
234 @$(call mkdir_def,$(USER_LIB_DIR))
235 @$(call mkdir_def,$(USER_BIN_DIR))
236 @$(call mkdir_def,$(USER_UTILS_DIR))
238 # Create directories only for the first time
239 ifndef CHECK_DIR_DONE
240 check-dir = check-dir
243 export CHECK_DIR_DONE
245 # Which passes to pass
246 default: $(check-dir) include-pass library-pass binary-pass utils-pass