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