]> rtime.felk.cvut.cz Git - omk.git/blob - snippets/sysless
move setting of varibables BUILD_OS and TARGET_OS into file linux-setup
[omk.git] / snippets / sysless
1 #                   Version for system-less builds.
2 #
3 #
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.
23
24 .PHONY: check-dir
25
26 # Some support to serialize some targets for parallel make
27 ifneq ($(OMK_SERIALIZE_INCLUDED),y)
28 include-pass: check-dir
29 library-pass: include-pass
30 binary-pass utils-pass: library-pass
31
32 override OMK_SERIALIZE_INCLUDED = y
33 endif
34
35 # -------------------------------------
36 # Rules for compilation for target
37 ifdef TARGET_RULE_TEMPLATES
38
39 LDFLAGS += -nostartfiles
40
41  # FIXME: These are not used. What they are good for?
42 LIB_CPPFLAGS += $(CPPFLAGS)
43 LIB_CFLAGS   += $(CFLAGS)
44
45 SOLIB_PICFLAGS += -shared -fpic
46
47 CFLAGS += -DOMK_FOR_TARGET
48
49 INCLUDE_DIR := $(USER_INCLUDE_DIR)
50 LIB_DIR     := $(USER_LIB_DIR)
51 OBJS_DIR    := $(USER_OBJS_DIR)
52
53 $(eval $(COMPILER_DEFS_template))
54
55 # Special rules for CMETRIC generated headers
56
57 $(foreach cmetrh,$(cmetric_include_HEADERS),$(eval $(call COMPILE_c_o_template,\
58                 $(SOURCES_DIR)/$($(basename $(notdir $(cmetrh)))_CMETRIC_SOURCES),\
59                 $($(basename $(notdir $(cmetrh)))_CMETRIC_SOURCES:%.c=%.o),)))
60 $(foreach cmetrh,$(cmetric_include_HEADERS),$(eval $(call CMETRIC_o_h_template,\
61                 $($(basename $(notdir $(cmetrh)))_CMETRIC_SOURCES:%.c=%.o),\
62                 $(addprefix $(USER_INCLUDE_DIR)/,$(cmetrh)))))
63
64 GEN_HEADERS+=$(cmetric_include_HEADERS:%=$(USER_INCLUDE_DIR)/%)
65
66 # Generate rules for compilation of programs and libraries
67 ifneq ($(link_VARIANTS),)
68 $(foreach prog,$(bin_PROGRAMS),$(foreach link,$(link_VARIANTS),$(eval $(call PROGRAM_template,$(prog),$(USER_BIN_DIR),$(link)))))
69 $(foreach prog,$(test_PROGRAMS),$(foreach link,$(link_VARIANTS),$(eval $(call PROGRAM_template,$(prog),$(USER_TESTS_DIR),$(link)))))
70 else
71 $(foreach prog,$(bin_PROGRAMS),$(eval $(call PROGRAM_template,$(prog),$(USER_BIN_DIR))))
72 $(foreach prog,$(test_PROGRAMS),$(eval $(call PROGRAM_template,$(prog),$(USER_TESTS_DIR))))
73 endif
74
75 $(foreach lib,$(lib_LIBRARIES),$(eval $(call LIBRARY_template,$(lib))))
76 $(foreach src,$(lib_obj_SOURCES),$(eval $(call LIBOBJ_template,$(addsuffix $(OBJ_EXT),$(basename $(src))))))
77 $(foreach lib,$(shared_LIBRARIES),$(eval $(call SOLIB_template,$(lib))))
78
79
80 # lib_obj_SOURCES handling
81 lib_OBJS = $(addsuffix $(OBJ_EXT),$(basename $(lib_obj_SOURCES)))
82 #$(warning lib_OBJS = $(lib_OBJS))
83 SOURCES += $(filter-out %$(OBJ_EXT),$(lib_obj_SOURCES))
84
85 $(LIB_DIR)/%$(OBJ_EXT): %$(OBJ_EXT)
86         @echo "  CP      $(^:$(MAKERULES_DIR)/%=%) -> $(@:$(MAKERULES_DIR)/%=%)"
87         $(Q)cp $(CP_FLAGS) $< $@
88
89
90 # User-space static libraries and applications object files
91 SOURCES := $(sort $(SOURCES))
92 #$(warning SOURCES = $(SOURCES))
93
94 # User-space shared libraries object files
95 SOLIB_SOURCES := $(sort $(SOLIB_SOURCES))
96 #$(warning SOLIB_SOURCES = $(SOLIB_SOURCES))
97
98
99 # The above generated rules produced $(SOURCES) and $(SOLIB_SOURCES)
100 # variables. Now generate rules for compilation of theese sources
101 $(foreach src,$(filter %.c,$(SOURCES)),$(eval $(call COMPILE_c_o_template,$(SOURCES_DIR)/$(src),$(src:%.c=%$(OBJ_EXT)),)))
102 $(foreach src,$(filter %.cc,$(SOURCES)),$(eval $(call COMPILE_cc_o_template,$(SOURCES_DIR)/$(src),$(src:%.cc=%$(OBJ_EXT)),)))
103 $(foreach src,$(filter %.cxx,$(SOURCES)),$(eval $(call COMPILE_cc_o_template,$(SOURCES_DIR)/$(src),$(src:%.cxx=%$(OBJ_EXT)),)))
104 $(foreach src,$(filter %$(ASM_EXT),$(SOURCES)),$(eval $(call COMPILE_S_o_template,$(SOURCES_DIR)/$(src),$(src:%$(ASM_EXT)=%$(OBJ_EXT)),)))
105
106 $(foreach src,$(filter %.c,$(SOLIB_SOURCES)),$(eval $(call COMPILE_c_o_template,$(SOURCES_DIR)/$(src),$(src:%.c=%.lo),$(SOLIB_PICFLAGS))))
107 $(foreach src,$(filter %.cc,$(SOLIB_SOURCES)),$(eval $(call COMPILE_cc_o_template,$(SOURCES_DIR)/$(src),$(src:%.cc=%.lo),$(SOLIB_PICFLAGS))))
108 $(foreach src,$(filter %.cxx,$(SOLIB_SOURCES)),$(eval $(call COMPILE_cc_o_template,$(SOURCES_DIR)/$(src),$(src:%.cxx=%.lo),$(SOLIB_PICFLAGS))))
109 $(foreach src,$(filter %$(ASM_EXT),$(SOLIB_SOURCES)),$(eval $(call COMPILE_S_o_template,$(SOURCES_DIR)/$(src),$(src:%$(ASM_EXT)=%.lo),$(SOLIB_PICFLAGS))))
110
111 library-pass-local: $(addprefix $(USER_INCLUDE_DIR)/,$(cmetric_include_HEADERS)) \
112                     $(lib_LIBRARIES:%=$(LIB_DIR)/$(LIB_PREF)%$(LIB_EXT)) $(shared_LIBRARIES:%=$(LIB_DIR)/$(LIB_PREF)%.so) \
113                     $(addprefix $(LIB_DIR)/,$(lib_OBJS))
114
115 ifneq ($(link_VARIANTS),)
116 binary-pass-local:  $(foreach link,$(link_VARIANTS),$(bin_PROGRAMS:%=$(USER_BIN_DIR)/%-$(link)) $(test_PROGRAMS:%=$(USER_TESTS_DIR)/%-$(link)) \
117                     $(foreach of,$(OUTPUT_FORMATS),$(bin_PROGRAMS:%=$(USER_BIN_DIR)/%-$(link).$(of)) $(test_PROGRAMS:%=$(USER_TESTS_DIR)/%-$(link).$(of))))
118 else
119 binary-pass-local:  $(bin_PROGRAMS:%=$(USER_BIN_DIR)/%) $(test_PROGRAMS:%=$(USER_TESTS_DIR)/%) \
120                     $(foreach of,$(OUTPUT_FORMATS),$(bin_PROGRAMS:%=$(USER_BIN_DIR)/%.$(of)) $(test_PROGRAMS:%=$(USER_TESTS_DIR)/%.$(of)))
121 endif
122
123 endif # TARGET_RULE_TEMPLATES
124
125
126 # -------------------------------------
127 # Rules for compilation utilities for host (user space)
128 ifdef HOST_RULE_TEMPLATES
129
130 CROSS_COMPILE =
131 TARGET_ARCH =
132
133 SOLIB_PICFLAGS += -shared -fpic
134
135 # For host compilation, we don't use a specfic ld script
136 LD_SCRIPT =
137
138 # TODO: It is probably better to use different directories for host
139 # includes, libraries and objects
140 INCLUDE_DIR := $(USER_INCLUDE_DIR)
141 LIB_DIR     := $(USER_LIB_DIR)
142 OBJS_DIR    := $(USER_OBJS_DIR)
143
144 $(eval $(COMPILER_DEFS_template))
145
146  #User-space static libraries and applications object files
147 #SOURCES := $(sort $(SOURCES))
148 #$(warning SOURCES = $(SOURCES))
149
150 # Generate rules for compilation of utility programs
151 $(foreach prog,$(utils_PROGRAMS),$(eval $(call PROGRAM_template,$(prog),$(USER_UTILS_DIR),)))
152
153 # The above generated rule produced $(SOURCES) variable. Now generate
154 # rules for compilation of theese sources
155 $(foreach src,$(filter %.c,$(SOURCES)),$(eval $(call COMPILE_c_o_template,$(SOURCES_DIR)/$(src),$(src:%.c=%$(OBJ_EXT)),)))
156 $(foreach src,$(filter %.cc,$(SOURCES)),$(eval $(call COMPILE_cc_o_template,$(SOURCES_DIR)/$(src),$(src:%.cc=%$(OBJ_EXT)),)))
157 $(foreach src,$(filter %.cxx,$(SOURCES)),$(eval $(call COMPILE_cc_o_template,$(SOURCES_DIR)/$(src),$(src:%.cxx=%$(OBJ_EXT)),)))
158 $(foreach src,$(filter %$(ASM_EXT),$(SOURCES)),$(eval $(call COMPILE_S_o_template,$(SOURCES_DIR)/$(src),$(src:%$(ASM_EXT)=%$(OBJ_EXT)),)))
159
160 utils-pass-local: $(utils_PROGRAMS:%=$(USER_UTILS_DIR)/%)
161
162 endif # HOST_RULE_TEMPLATES
163
164
165 #=====================================================================
166 # Automatic loading of compiled program by issuing "make load"
167
168 ifneq ($(OUTPUT_FORMATS),)
169 # Select a file extension (e.g. .bin) for "make load" command to load.
170 LOAD_EXTENSION = .$(firstword $(OUTPUT_FORMATS))
171 endif
172
173 # Syntax: $(call LOAD_PROGRAM_template,<executable-name>,<dir>,<link-variant>)
174 # Used to load program to the target hardware
175 define LOAD_PROGRAM_template
176 .PHONY: load-$(1)$(3:%=-%)
177 load-$(1)$(3:%=-%): $(2)/$(1)$(3:%=-%)$(LOAD_EXTENSION)
178         @$(QUIET_CMD_ECHO) "  LOAD    $$<"
179         @if [ -z "$$(LOAD_CMD$(3:%=-%))" ]; then echo "No command for loading applications to '$(3)' is specified."; exit 1; fi
180         $(Q) $$(LOAD_CMD$(3:%=-%)) $$<
181 endef
182
183 # Syntax: $(call LOAD__RUN_VARIANT_template,<link-variant>)
184 # Used to load and/or run non-default variant of the default program
185 define LOAD_RUN_VARIANT_template
186 .PHONY: load-$(1) run-$(1)
187
188 load-$(1): load-$(firstword $(bin_PROGRAMS) $(test_PROGRAMS))-$(1)
189
190 run-$(1):
191         @$(QUIET_CMD_ECHO) "  RUN     $(1)"
192         @if [ -z "$(RUN_CMD-$(1))" ]; then echo "No command for running '$(1)' variant is specified."; exit 1; fi
193         $(Q) $(RUN_CMD-$(1))
194
195 endef
196
197 $(foreach link,$(link_VARIANTS),$(foreach prog,$(bin_PROGRAMS),$(eval $(call LOAD_PROGRAM_template,$(prog),$(USER_BIN_DIR),$(link)))))
198 $(foreach link,$(link_VARIANTS),$(foreach prog,$(test_PROGRAMS),$(eval $(call LOAD_PROGRAM_template,$(prog),$(USER_TEST_DIR),$(link)))))
199 $(foreach link,$(link_VARIANTS),$(eval $(call LOAD_RUN_VARIANT_template,$(link))))
200
201 .PHONY: load run
202 load: $(addprefix load-,$(firstword $(bin_PROGRAMS) $(test_PROGRAMS))-$(firstword $(link_VARIANTS)))
203
204 run: run-$(firstword $(link_VARIANTS))
205
206
207
208 #=====================================================================
209 # Generate pass rules from generic templates
210 OTHER_PASSES = dep clean install
211
212 $(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)))
213 $(eval $(call omk_pass_template, library-pass, $(LOCAL_BUILD_DIR),TARGET_RULE_TEMPLATES=y,$(lib_LIBRARIES)$(shared_LIBRARIES)$(lib_obj_SOURCES)))
214 $(eval $(call omk_pass_template, binary-pass,  $(LOCAL_BUILD_DIR),TARGET_RULE_TEMPLATES=y,$(bin_PROGRAMS) $(test_PROGRAMS)))
215 $(eval $(call omk_pass_template, utils-pass,   $(LOCAL_BUILD_DIR),HOST_RULE_TEMPLATES=y,$(utils_PROGRAMS)))
216
217
218 $(eval $(call omk_pass_template,$(OTHER_PASSES),$(LOCAL_BUILD_DIR),,always))
219
220
221 dep-local:
222
223 install-local:
224
225 include-pass-local:
226         $(call include-pass-template,$(USER_INCLUDE_DIR),include)
227         @$(foreach f, $(lib_LDSCRIPTS), cmp --quiet $(SOURCES_DIR)/$(f) $(USER_LIB_DIR)/$(notdir $(f)) \
228            || $(call cp_cmd,$(SOURCES_DIR)/$(f),$(USER_LIB_DIR)/$(notdir $(f))) || exit 1 ; )
229
230
231 .PHONY: clean-custom
232 clean-local: clean-custom
233         $(Q)rm -f $(USER_OBJS_DIR)/*.o $(USER_OBJS_DIR)/*.lo \
234                $(USER_OBJS_DIR)/*.d \
235                $(USER_OBJS_DIR)/*.map \
236                $(LOCAL_CONFIG_H:%=$(USER_OBJS_DIR)/%)
237
238 check-dir:
239         @$(call mkdir_def,$(USER_INCLUDE_DIR))
240         @$(call mkdir_def,$(USER_LIB_DIR))
241         @$(call mkdir_def,$(USER_BIN_DIR))
242         @$(call mkdir_def,$(USER_UTILS_DIR))
243         @$(call mkdir_def,$(USER_TESTS_DIR))
244
245 # Which passes to pass
246 default: include-pass library-pass binary-pass utils-pass
247
248 # Local Variables:
249 # mode:makefile
250 # End: