1 # Version for system-less builds.
4 # bin_PROGRAMS .. list of the require binary programs
5 # test_PROGRAMS .. list of the test programs
6 # include_HEADERS .. list of the user-space public header files
7 # lib_LIBRARIES .. list of the user-space libraries
8 # lib_LDSCRIPTS .. list of LD scripts that should be copied to the lib direcotry
9 # lib_obj_SOURCES .. list of source files which should be compiled and
10 # the produced object file placed to the lib directory (e.g. crt0.S)
11 # shared_LIBRARIES .. list of the user-space shared libraries
12 # nobase_include_HEADERS .. public headers copied even with directory part
13 # renamed_include_HEADERS .. public headers copied to the different target name (xxx.h->yyy.h)
14 # utils_PROGRAMS .. list of the development utility programs (compiled for host computer, this might change in future)
15 # xxx_SOURCES .. list of specific target sources
16 # xxx_LIBS .. list of specific target libraries
17 # INCLUDES .. additional include directories and defines for user-space
18 # lib_LOADLIBES .. list of libraries linked to each executable
19 # link_VARIANTS .. list of ld script suffixes (after hypen `-') that
20 # should be used for linking (e.g. ram flash). If this is not
21 # specified, then the value of DEFAULT_LD_SCRIPT_VARIANT from config.target is used.
22 # PREFIX_DIR .. Prefix to directories in _compiled and _build. Used in config.omk.
24 BUILD_DIR_NAME = _build$(addprefix /,$(PREFIX_DIR))
25 COMPILED_DIR_NAME = _compiled$(addprefix /,$(PREFIX_DIR))
27 LOCAL_BUILD_DIR=$(MAKERULES_DIR)/$(BUILD_DIR_NAME)/$(RELATIVE_DIR)
28 #$(warning LOCAL_BUILD_DIR = $(LOCAL_BUILD_DIR))
30 #=====================================================================
31 # Common utility rules
33 link_VARIANTS ?= $(DEFAULT_LD_SCRIPT_VARIANT)
36 #=====================================================================
37 # Include correct rules for just running pass
39 USER_COMPILED_DIR_NAME=$(MAKERULES_DIR)/$(COMPILED_DIR_NAME)
41 USER_INCLUDE_DIR = $(USER_COMPILED_DIR_NAME)/include
42 USER_LIB_DIR = $(USER_COMPILED_DIR_NAME)/lib
43 USER_UTILS_DIR = $(USER_COMPILED_DIR_NAME)/bin-utils
44 USER_TESTS_DIR = $(USER_COMPILED_DIR_NAME)/bin-tests
45 USER_BIN_DIR = $(USER_COMPILED_DIR_NAME)/bin
46 USER_OBJS_DIR = $(LOCAL_BUILD_DIR)
50 # Some support to serialize some targets for parallel make
51 ifneq ($(OMK_SERIALIZE_INCLUDED),y)
52 include-pass: check-dir
53 library-pass: include-pass
54 binary-pass utils-pass: library-pass
56 override OMK_SERIALIZE_INCLUDED = y
57 MAKEOVERRIDES := $(filter-out OMK_SERIALIZE_INCLUDED=n,$(MAKEOVERRIDES))
60 # -------------------------------------
61 # Rules for compilation for target
62 ifdef TARGET_RULE_TEMPLATES
64 LDFLAGS += -nostartfiles
66 # FIXME: These are not used. What they are good for?
67 LIB_CPPFLAGS += $(CPPFLAGS)
68 LIB_CFLAGS += $(CFLAGS)
70 SOLIB_PICFLAGS += -shared -fpic
72 CFLAGS += -DOMK_FOR_TARGET
74 INCLUDE_DIR := $(USER_INCLUDE_DIR)
75 LIB_DIR := $(USER_LIB_DIR)
76 OBJS_DIR := $(USER_OBJS_DIR)
78 $(eval $(COMPILER_DEFS_template))
80 # Special rules for CMETRIC generated headers
82 $(foreach cmetrh,$(cmetric_include_HEADERS),$(eval $(call COMPILE_c_o_template,\
83 $(SOURCES_DIR)/$($(basename $(notdir $(cmetrh)))_CMETRIC_SOURCES),\
84 $($(basename $(notdir $(cmetrh)))_CMETRIC_SOURCES:%.c=%.o),)))
85 $(foreach cmetrh,$(cmetric_include_HEADERS),$(eval $(call CMETRIC_o_h_template,\
86 $($(basename $(notdir $(cmetrh)))_CMETRIC_SOURCES:%.c=%.o),\
87 $(addprefix $(USER_INCLUDE_DIR)/,$(cmetrh)))))
89 GEN_HEADERS+=$(cmetric_include_HEADERS:%=$(USER_INCLUDE_DIR)/%)
91 # Generate rules for compilation of programs and libraries
92 ifneq ($(link_VARIANTS),)
93 $(foreach prog,$(bin_PROGRAMS),$(foreach link,$(link_VARIANTS),$(eval $(call PROGRAM_template,$(prog),$(USER_BIN_DIR),$(link)))))
94 $(foreach prog,$(test_PROGRAMS),$(foreach link,$(link_VARIANTS),$(eval $(call PROGRAM_template,$(prog),$(USER_TESTS_DIR),$(link)))))
96 $(foreach prog,$(bin_PROGRAMS),$(eval $(call PROGRAM_template,$(prog),$(USER_BIN_DIR))))
97 $(foreach prog,$(test_PROGRAMS),$(eval $(call PROGRAM_template,$(prog),$(USER_TESTS_DIR))))
100 $(foreach lib,$(lib_LIBRARIES),$(eval $(call LIBRARY_template,$(lib))))
101 $(foreach src,$(lib_obj_SOURCES),$(eval $(call LIBOBJ_template,$(addsuffix $(OBJ_EXT),$(basename $(src))))))
102 $(foreach lib,$(shared_LIBRARIES),$(eval $(call SOLIB_template,$(lib))))
105 # lib_obj_SOURCES handling
106 lib_OBJS = $(addsuffix $(OBJ_EXT),$(basename $(lib_obj_SOURCES)))
107 #$(warning lib_OBJS = $(lib_OBJS))
108 SOURCES += $(filter-out %$(OBJ_EXT),$(lib_obj_SOURCES))
110 $(LIB_DIR)/%$(OBJ_EXT): %$(OBJ_EXT)
111 @echo " CP $(^:$(MAKERULES_DIR)/%=%) -> $(@:$(MAKERULES_DIR)/%=%)"
112 $(Q)cp $(CP_FLAGS) $< $@
115 # User-space static libraries and applications object files
116 SOURCES := $(sort $(SOURCES))
117 #$(warning SOURCES = $(SOURCES))
119 # User-space shared libraries object files
120 SOLIB_SOURCES := $(sort $(SOLIB_SOURCES))
121 #$(warning SOLIB_SOURCES = $(SOLIB_SOURCES))
124 # The above generated rules produced $(SOURCES) and $(SOLIB_SOURCES)
125 # variables. Now generate rules for compilation of theese sources
126 $(foreach src,$(filter %.c,$(SOURCES)),$(eval $(call COMPILE_c_o_template,$(SOURCES_DIR)/$(src),$(src:%.c=%$(OBJ_EXT)),)))
127 $(foreach src,$(filter %.cc,$(SOURCES)),$(eval $(call COMPILE_cc_o_template,$(SOURCES_DIR)/$(src),$(src:%.cc=%$(OBJ_EXT)),)))
128 $(foreach src,$(filter %.cxx,$(SOURCES)),$(eval $(call COMPILE_cc_o_template,$(SOURCES_DIR)/$(src),$(src:%.cxx=%$(OBJ_EXT)),)))
129 $(foreach src,$(filter %$(ASM_EXT),$(SOURCES)),$(eval $(call COMPILE_S_o_template,$(SOURCES_DIR)/$(src),$(src:%$(ASM_EXT)=%$(OBJ_EXT)),)))
131 $(foreach src,$(filter %.c,$(SOLIB_SOURCES)),$(eval $(call COMPILE_c_o_template,$(SOURCES_DIR)/$(src),$(src:%.c=%.lo),$(SOLIB_PICFLAGS))))
132 $(foreach src,$(filter %.cc,$(SOLIB_SOURCES)),$(eval $(call COMPILE_cc_o_template,$(SOURCES_DIR)/$(src),$(src:%.cc=%.lo),$(SOLIB_PICFLAGS))))
133 $(foreach src,$(filter %.cxx,$(SOLIB_SOURCES)),$(eval $(call COMPILE_cc_o_template,$(SOURCES_DIR)/$(src),$(src:%.cxx=%.lo),$(SOLIB_PICFLAGS))))
134 $(foreach src,$(filter %$(ASM_EXT),$(SOLIB_SOURCES)),$(eval $(call COMPILE_S_o_template,$(SOURCES_DIR)/$(src),$(src:%$(ASM_EXT)=%.lo),$(SOLIB_PICFLAGS))))
136 library-pass-local: $(addprefix $(USER_INCLUDE_DIR)/,$(cmetric_include_HEADERS)) \
137 $(lib_LIBRARIES:%=$(LIB_DIR)/$(LIB_PREF)%$(LIB_EXT)) $(shared_LIBRARIES:%=$(LIB_DIR)/$(LIB_PREF)%.so) \
138 $(addprefix $(LIB_DIR)/,$(lib_OBJS))
140 ifneq ($(link_VARIANTS),)
141 binary-pass-local: $(foreach link,$(link_VARIANTS),$(bin_PROGRAMS:%=$(USER_BIN_DIR)/%-$(link)) $(test_PROGRAMS:%=$(USER_TESTS_DIR)/%-$(link)) \
142 $(foreach of,$(OUTPUT_FORMATS),$(bin_PROGRAMS:%=$(USER_BIN_DIR)/%-$(link).$(of)) $(test_PROGRAMS:%=$(USER_TESTS_DIR)/%-$(link).$(of))))
144 binary-pass-local: $(bin_PROGRAMS:%=$(USER_BIN_DIR)/%) $(test_PROGRAMS:%=$(USER_TESTS_DIR)/%) \
145 $(foreach of,$(OUTPUT_FORMATS),$(bin_PROGRAMS:%=$(USER_BIN_DIR)/%.$(of)) $(test_PROGRAMS:%=$(USER_TESTS_DIR)/%.$(of)))
148 endif # TARGET_RULE_TEMPLATES
151 # -------------------------------------
152 # Rules for compilation utilities for host (user space)
153 ifdef HOST_RULE_TEMPLATES
158 SOLIB_PICFLAGS += -shared -fpic
160 # For host compilation, we don't use a specfic ld script
163 # TODO: It is probably better to use different directories for host
164 # includes, libraries and objects
165 INCLUDE_DIR := $(USER_INCLUDE_DIR)
166 LIB_DIR := $(USER_LIB_DIR)
167 OBJS_DIR := $(USER_OBJS_DIR)
169 $(eval $(COMPILER_DEFS_template))
171 #User-space static libraries and applications object files
172 #SOURCES := $(sort $(SOURCES))
173 #$(warning SOURCES = $(SOURCES))
175 # Generate rules for compilation of utility programs
176 $(foreach prog,$(utils_PROGRAMS),$(eval $(call PROGRAM_template,$(prog),$(USER_UTILS_DIR),)))
178 # The above generated rule produced $(SOURCES) variable. Now generate
179 # rules for compilation of theese sources
180 $(foreach src,$(filter %.c,$(SOURCES)),$(eval $(call COMPILE_c_o_template,$(SOURCES_DIR)/$(src),$(src:%.c=%$(OBJ_EXT)),)))
181 $(foreach src,$(filter %.cc,$(SOURCES)),$(eval $(call COMPILE_cc_o_template,$(SOURCES_DIR)/$(src),$(src:%.cc=%$(OBJ_EXT)),)))
182 $(foreach src,$(filter %.cxx,$(SOURCES)),$(eval $(call COMPILE_cc_o_template,$(SOURCES_DIR)/$(src),$(src:%.cxx=%$(OBJ_EXT)),)))
183 $(foreach src,$(filter %$(ASM_EXT),$(SOURCES)),$(eval $(call COMPILE_S_o_template,$(SOURCES_DIR)/$(src),$(src:%$(ASM_EXT)=%$(OBJ_EXT)),)))
185 utils-pass-local: $(utils_PROGRAMS:%=$(USER_UTILS_DIR)/%)
187 endif # HOST_RULE_TEMPLATES
189 # Checks for OMK tester
191 default-config-pass-check include-pass-check:
192 library-pass-check binary-pass-check:
193 @[ -x "$(shell which $(CC))" ] || $(call canttest,Cannot find compiler: $(CC))
196 #=====================================================================
197 # Automatic loading of compiled program by issuing "make load"
199 ifneq ($(OUTPUT_FORMATS),)
200 # Select a file extension (e.g. .bin) for "make load" command to load.
201 LOAD_EXTENSION = .$(firstword $(OUTPUT_FORMATS))
204 # Syntax: $(call LOAD_PROGRAM_template,<executable-name>,<dir>,<link-variant>)
205 # Used to load program to the target hardware
206 define LOAD_PROGRAM_template
207 .PHONY: load-$(1)$(3:%=-%)
208 load-$(1)$(3:%=-%): $(2)/$(1)$(3:%=-%)$(LOAD_EXTENSION)
209 @$(QUIET_CMD_ECHO) " LOAD $$<"
210 @if [ -z '$$(LOAD_CMD$(3:%=-%))' ]; then echo "No command for loading applications to '$(3)' is specified."; exit 1; fi
211 $(Q) $$(LOAD_CMD$(3:%=-%)) $$<
214 # Syntax: $(call LOAD__RUN_VARIANT_template,<link-variant>)
215 # Used to load and/or run non-default variant of the default program
216 define LOAD_RUN_VARIANT_template
217 .PHONY: load-$(1) run-$(1)
219 load-$(1): load-$(firstword $(bin_PROGRAMS) $(test_PROGRAMS))-$(1)
222 @$(QUIET_CMD_ECHO) " RUN $(1)"
223 @if [ -z "$(RUN_CMD-$(1))" ]; then echo "No command for running '$(1)' variant is specified."; exit 1; fi
228 $(foreach link,$(link_VARIANTS),$(foreach prog,$(bin_PROGRAMS),$(eval $(call LOAD_PROGRAM_template,$(prog),$(USER_BIN_DIR),$(link)))))
229 $(foreach link,$(link_VARIANTS),$(foreach prog,$(test_PROGRAMS),$(eval $(call LOAD_PROGRAM_template,$(prog),$(USER_TESTS_DIR),$(link)))))
230 $(foreach link,$(link_VARIANTS),$(eval $(call LOAD_RUN_VARIANT_template,$(link))))
233 load: $(addprefix load-,$(firstword $(bin_PROGRAMS) $(test_PROGRAMS))-$(firstword $(link_VARIANTS)))
235 run: run-$(firstword $(link_VARIANTS))
239 #=====================================================================
240 # Generate pass rules from generic templates
242 $(eval $(call omk_pass_template, include-pass, $(LOCAL_BUILD_DIR),,$(include_HEADERS)$(nobase_include_HEADERS)$(renamed_include_HEADERS)$(lib_LDSCRIPTS)$(config_include_HEADERS)$(LOCAL_CONFIG_H)))
243 $(eval $(call omk_pass_template, library-pass, $(LOCAL_BUILD_DIR),TARGET_RULE_TEMPLATES=y,$(lib_LIBRARIES)$(shared_LIBRARIES)$(lib_obj_SOURCES)))
244 $(eval $(call omk_pass_template, binary-pass, $(LOCAL_BUILD_DIR),TARGET_RULE_TEMPLATES=y,$(bin_PROGRAMS) $(test_PROGRAMS)))
245 $(eval $(call omk_pass_template, utils-pass, $(LOCAL_BUILD_DIR),HOST_RULE_TEMPLATES=y,$(utils_PROGRAMS)))
246 $(eval $(call omk_pass_template, dep, $(LOCAL_BUILD_DIR),,always))
247 $(eval $(call omk_pass_template, clean, $(LOCAL_BUILD_DIR),,always))
248 $(eval $(call omk_pass_template, install,$(LOCAL_BUILD_DIR),,always))
255 $(eval $(call include-pass-template,$(USER_INCLUDE_DIR),include))
258 @$(foreach f, $(lib_LDSCRIPTS), cmp --quiet $(SOURCES_DIR)/$(f) $(USER_LIB_DIR)/$(notdir $(f)) \
259 || $(call cp_cmd,$(SOURCES_DIR)/$(f),$(USER_LIB_DIR)/$(notdir $(f))) || exit 1 ; )
263 clean-local: clean-custom
264 $(Q)rm -f $(USER_OBJS_DIR)/*.o $(USER_OBJS_DIR)/*.lo \
265 $(USER_OBJS_DIR)/*.d \
266 $(USER_OBJS_DIR)/*.map \
267 $(LOCAL_CONFIG_H:%=$(USER_OBJS_DIR)/%)
270 @$(call mkdir_def,$(USER_INCLUDE_DIR))
271 @$(call mkdir_def,$(USER_LIB_DIR))
272 @$(call mkdir_def,$(USER_BIN_DIR))
273 @$(call mkdir_def,$(USER_UTILS_DIR))
274 @$(call mkdir_def,$(USER_TESTS_DIR))
276 include-pass-submakes: extra-rules-subdirs
277 # Which passes to pass
278 default: include-pass library-pass binary-pass utils-pass