1 | # $Id: footer.kmk 73 2004-05-31 01:11:52Z bird $
|
---|
2 | ## @file
|
---|
3 | #
|
---|
4 | # kBuild - File included at top of makefile.
|
---|
5 | #
|
---|
6 | # Copyright (c) 2004 knut st. osmundsen <bird-srcspam@anduin.net>
|
---|
7 | #
|
---|
8 | #
|
---|
9 | # This file is part of kBuild.
|
---|
10 | #
|
---|
11 | # kBuild is free software; you can redistribute it and/or modify
|
---|
12 | # it under the terms of the GNU General Public License as published by
|
---|
13 | # the Free Software Foundation; either version 2 of the License, or
|
---|
14 | # (at your option) any later version.
|
---|
15 | #
|
---|
16 | # kBuild is distributed in the hope that it will be useful,
|
---|
17 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
18 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
19 | # GNU General Public License for more details.
|
---|
20 | #
|
---|
21 | # You should have received a copy of the GNU General Public License
|
---|
22 | # along with kBuild; if not, write to the Free Software
|
---|
23 | # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
---|
24 | #
|
---|
25 | #
|
---|
26 |
|
---|
27 | ifndef __footer_kmk__
|
---|
28 | # start-of-file-content
|
---|
29 |
|
---|
30 | #
|
---|
31 | # Variables.
|
---|
32 | # (Some of these need initialization before including definitions using them.)
|
---|
33 | #
|
---|
34 |
|
---|
35 | # all targets.
|
---|
36 | ALL_TARGETS := $(LIBRARIES) $(PROGRAMS) $(DLLS) $(DRIVERS) $(OTHERS)
|
---|
37 |
|
---|
38 | # all of a type
|
---|
39 | _OBJS :=
|
---|
40 | _LIBS :=
|
---|
41 | _DLLS :=
|
---|
42 | _EXES :=
|
---|
43 | _DIRS :=
|
---|
44 |
|
---|
45 | # all objs of a specific target
|
---|
46 | define def_objs_var
|
---|
47 | _OBJS_$1 :=
|
---|
48 | endef
|
---|
49 | $(foreach target, $(ALL_TARGETS), $(eval _OBJS_$(target) := ))
|
---|
50 |
|
---|
51 | # misc
|
---|
52 | type :=
|
---|
53 |
|
---|
54 |
|
---|
55 | #
|
---|
56 | # Basic macros
|
---|
57 | #
|
---|
58 |
|
---|
59 | ## Figure out the tool for a source
|
---|
60 | # @param $1 source file
|
---|
61 | # @param $2 normalized main target
|
---|
62 | _SOURCE_TOOL = $(firstword $($1_$2_TOOL) $($1_TOOL) $($2_TOOL) )
|
---|
63 |
|
---|
64 | ## Figure out where to put object files.
|
---|
65 | # @param $1 source file
|
---|
66 | # @param $2 normalized main target
|
---|
67 | _OBJECT_BASE = $(PATH_TARGET)/$(2)/$(basename $(1))
|
---|
68 |
|
---|
69 | ## Figure out where to put object files.
|
---|
70 | # @param $1 real target name.
|
---|
71 | # @param $2 normalized main target
|
---|
72 | _TARGET_BASE = $(PATH_TARGET)/$(2)/$(basename $(1))
|
---|
73 |
|
---|
74 |
|
---|
75 | #
|
---|
76 | # Include templates
|
---|
77 | #
|
---|
78 | _TEMPLATES := $(TEMPLATE)
|
---|
79 | define def_templates
|
---|
80 | ifdef $(target)_TEMPLATE
|
---|
81 | _TEMPLATES += $($(target)_TEMPLATE)
|
---|
82 | endif
|
---|
83 | endef
|
---|
84 | $(foreach target, $(ALL_TARGETS), $(eval $(def_templates)))
|
---|
85 | _TEMPLATES := $(sort $(_TEMPLATES))
|
---|
86 | # $ (warning dbg: _TEMPLATES=$(_TEMPLATES))
|
---|
87 |
|
---|
88 | define def_templates_include
|
---|
89 | ifndef TEMPLATE_$(template)
|
---|
90 | include $(firstword $(wildcard $(PATH_KBUILD)/templates/$(template).kmk))
|
---|
91 | endif
|
---|
92 | endef
|
---|
93 | $(foreach template, $(_TEMPLATES), $(eval $(def_templates)))
|
---|
94 |
|
---|
95 |
|
---|
96 | #
|
---|
97 | # Common Inheritance
|
---|
98 | #
|
---|
99 |
|
---|
100 | ## Inherit defaults property
|
---|
101 | # @param $(prop) Property name
|
---|
102 | # @param $(target) Target name.
|
---|
103 | define def_inherit_defaults_one
|
---|
104 | ifndef $1_$(prop)
|
---|
105 | ifdef $(prop)
|
---|
106 | $1_$(prop) := $($(prop))
|
---|
107 | endif
|
---|
108 | endif
|
---|
109 | endef
|
---|
110 |
|
---|
111 | ## Inherit default properties for one target.
|
---|
112 | # A bit tricky this one, but it depends a bit on whether or not TEMPLATE
|
---|
113 | # is inherited from the default properties.
|
---|
114 | # @param $(target) Target name
|
---|
115 | define def_inherit_defaults
|
---|
116 | ifdef $(target)_TEMPLATE
|
---|
117 | ifndef TEMPLATE_$($(target)_TEMPLATE)_TOOL
|
---|
118 | $(foreach prop, TOOL, $(eval $(def_inherit_defaults_one)))
|
---|
119 | endif
|
---|
120 | ifndef TEMPLATE_$($(target)_TEMPLATE)_SDKS
|
---|
121 | $(foreach prop, SDKS, $(eval $(def_inherit_defaults_one)))
|
---|
122 | endif
|
---|
123 | else
|
---|
124 | $(foreach prop, TEMPLATE TOOL SDKS, $(eval $(def_inherit_defaults_one)))
|
---|
125 | endif
|
---|
126 | endef
|
---|
127 | # Inherit default properties.
|
---|
128 | $(foreach target, $(ALL_TARGETS), $(eval $(def_inherit_defaults)))
|
---|
129 |
|
---|
130 |
|
---|
131 | ## Inherit one template property.
|
---|
132 | # @param $(prop) Property name
|
---|
133 | # @param $(target) Target name
|
---|
134 | define def_inherit_template_one
|
---|
135 | ifndef $(target)_$(prop)
|
---|
136 | ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop)
|
---|
137 | $(target)_$(prop) := $(TEMPLATE_$($(target)_TEMPLATE)_$(prop))
|
---|
138 | endif
|
---|
139 | endif
|
---|
140 | endef
|
---|
141 |
|
---|
142 | ## Inherit template properties for on target.
|
---|
143 | # @param $(target) Target name.
|
---|
144 | define def_inherit_template
|
---|
145 | $(foreach prop,TOOL SDKS DEFS INCS COPTS CFLAGS CDEFS CINCS CXXOPTS CXXFLAGS CXXDEFS CXXINCS ASOPTS ASFLAGS ASDEFS ASINCS, \
|
---|
146 | $(eval $(def_inherit_template_one)))
|
---|
147 | endef
|
---|
148 | # Inherit template properties
|
---|
149 | $(foreach target, $(ALL_TARGETS), $(eval $(def_inherit_template)))
|
---|
150 |
|
---|
151 |
|
---|
152 |
|
---|
153 | #
|
---|
154 | # Include tools
|
---|
155 | #
|
---|
156 | _TOOLS := $(TOOL)
|
---|
157 | define def_tools_target_source
|
---|
158 | #$ (warning dbg: src=$(source))
|
---|
159 | $(foreach tool,$($(source)_TOOL) $($(target)_$(source)_TOOL),\
|
---|
160 | $(eval _TOOLS += $(tool)))
|
---|
161 | endef
|
---|
162 | define def_tools_target
|
---|
163 | #$ (warning dbg: trg=$(target))
|
---|
164 | $(foreach tool, $($(target)_TOOL), $(eval _TOOLS += $(tool)))
|
---|
165 | $(foreach source, $($(target)_SOURCES), $(eval $(def_tools_target_source)))
|
---|
166 | endef
|
---|
167 | $(foreach target, $(ALL_TARGETS), $(eval $(def_tools_target)))
|
---|
168 | _TOOLS := $(sort $(_TOOLS))
|
---|
169 | #$ (warning dbg: _TOOLS=$(_TOOLS))
|
---|
170 |
|
---|
171 | define def_tools_include
|
---|
172 | ifndef TOOL_$(tool)
|
---|
173 | include $(firstword $(wildcard $(PATH_KBUILD)/tools/$(tool).kmk))
|
---|
174 | endif
|
---|
175 | endef
|
---|
176 | $(foreach tool, $(_TOOLS), $(eval $(def_tools_include)))
|
---|
177 |
|
---|
178 |
|
---|
179 | #
|
---|
180 | # Include SDKs
|
---|
181 | #
|
---|
182 | _SDKS := $(SDKS)
|
---|
183 | define def_sdks_target_source
|
---|
184 | $(foreach sdk, $($(source)_SDKS) $($(target)_$(source)_SDKS), \
|
---|
185 | $(eval _SDKS += $(sdk)))
|
---|
186 | endef
|
---|
187 | define def_sdks_target
|
---|
188 | $(foreach sdk, $($(target)_SDKS), $(eval _SDKS += $(sdk)))
|
---|
189 | $(foreach source, $($(target)_SOURCES), $(eval $(def_sdks_target_source)))
|
---|
190 | endef
|
---|
191 | $(foreach target, $(ALL_TARGETS), $(eval $(def_sdks_target)))
|
---|
192 | _SDKS := $(sort $(_SDKS))
|
---|
193 | #$ (warning dbg: _SDKS=$(_SDKS))
|
---|
194 |
|
---|
195 | define def_sdks_include
|
---|
196 | ifndef SDK_$(sdk)
|
---|
197 | include $(firstword $(wildcard $(PATH_KBUILD)/sdks/$(sdk).kmk))
|
---|
198 | endif
|
---|
199 | endef
|
---|
200 | $(foreach sdk, $(_SDKS), $(eval $(def_sdk)))
|
---|
201 |
|
---|
202 | #
|
---|
203 | # Object processing.
|
---|
204 | #
|
---|
205 |
|
---|
206 | ## Generic macro for processing C, C++ and Assembly sources.
|
---|
207 | # @param $(target) Normalized target name.
|
---|
208 | # @param $(source) Source file name.
|
---|
209 | # @param $(type) Source type. {C,CXX,AS}
|
---|
210 | #
|
---|
211 | # @remark I've no clue why I've to $(eval ..) everything in this define. MAKE bug?
|
---|
212 | define def_target_source_c_cpp_asm
|
---|
213 | #$ (warning dbg: def_target_source_c_cpp_asm: source=$(source) target=$(target) type=$(type))
|
---|
214 |
|
---|
215 | $(eval tool:=$(call _SOURCE_TOOL,$(source),$(target)))
|
---|
216 | $(eval defs :=\
|
---|
217 | $($(target)_$(source)_$(type)DEFS)\
|
---|
218 | $($(target)_$(source)_DEFS)\
|
---|
219 | $($(source)_$(type)DEFS)\
|
---|
220 | $($(source)_DEFS)\
|
---|
221 | $($(target)_$(type)DEFS)\
|
---|
222 | $($(target)_DEFS)\
|
---|
223 | $(DEFS)\
|
---|
224 | $(TOOL_$(tool)_$(type)DEFS)\
|
---|
225 | )
|
---|
226 | $(eval incs :=\
|
---|
227 | $($(target)_$(source)_$(type)INCS)\
|
---|
228 | $($(target)_$(source)_INCS)\
|
---|
229 | $($(source)_$(type)INCS)\
|
---|
230 | $($(source)_INCS)\
|
---|
231 | $($(target)_$(type)INCS)\
|
---|
232 | $($(target)_INCS)\
|
---|
233 | $(INCS)\
|
---|
234 | $(TOOL_$(tool)_$(type)INCS)\
|
---|
235 | )
|
---|
236 | $(eval flags :=\
|
---|
237 | $(TOOL_$(tool)_$(type)FLAGS)\
|
---|
238 | $(TOOL_$(tool)_$(type)FLAGS.$(BUILD_TYPE))\
|
---|
239 | $($(type)FLAGS)\
|
---|
240 | $($(type)FLAGS.$(BUILD_TYPE))\
|
---|
241 | $($(target)_$(type)FLAGS)\
|
---|
242 | $($(target)_$(type)FLAGS.$(BUILD_TYPE))\
|
---|
243 | $($(source)_$(type)FLAGS)\
|
---|
244 | $($(source)_$(type)FLAGS.$(BUILD_TYPE))\
|
---|
245 | $($(target)_$(source)_$(type)FLAGS)\
|
---|
246 | $($(target)_$(source)_$(type)FLAGS.$(BUILD_TYPE))\
|
---|
247 | )
|
---|
248 | $(eval outbase := $(call _OBJECT_BASE,$(source),$(target)))
|
---|
249 | $(eval dirdep := $(dir $(outbase)).dir_created)
|
---|
250 | $(eval objsuff := $(firstword $($(target)_$(source)_OBJSUFF) $($(source)_OBJSUFF) $($(target)_OBJSUFF) $(TOOL_$(tool)_$(type)OBJSUFF) $(SUFF_OBJ)))
|
---|
251 | $(eval obj := $(outbase)$(objsuff))
|
---|
252 | $(eval depfile := $(outbase)$(SUFF_DEP))
|
---|
253 |
|
---|
254 | #$ (warning dbg: target=$(target) source=$(source) tool=$(tool) obj=$(obj) dep=$(dep) flags=$(flags) defs=$(defs) incs=$(incs) dirdep=$(dirdep) outbase=$(outbase) objsuff=$(objsuff))
|
---|
255 | $(eval $(TOOL_$(tool)_COMPILE_$(type)))
|
---|
256 |
|
---|
257 | $(eval _OBJS_$(target) += $(obj))
|
---|
258 | $(eval _DEPFILES += $(dep))
|
---|
259 |
|
---|
260 | endef
|
---|
261 |
|
---|
262 | ## Generic macro for processing all target sources.
|
---|
263 | # @param $target Normalized target name.
|
---|
264 | define def_target_sources
|
---|
265 | #$ (warning def_target_sources)
|
---|
266 | # C sources
|
---|
267 | $(foreach type,C,$(foreach source, $(filter %.c, $($(target)_SOURCES))\
|
---|
268 | ,$(eval $(def_target_source_c_cpp_asm)) ))
|
---|
269 |
|
---|
270 | # C++ sources
|
---|
271 | $(foreach type,CXX,$(foreach source, $(filter %.cpp, $($(target)_SOURCES)) $(filter %.cxx, $($(target)_SOURCES)) $(filter %.cc, $($(target)_SOURCES))\
|
---|
272 | ,$(eval $(def_target_source_c_cpp_asm)) ))
|
---|
273 |
|
---|
274 | # ASM sources
|
---|
275 | $(foreach type,AS,$(foreach source, $(filter %.asm, $($(target)_SOURCES)) $(filter %.s, $($(target)_SOURCES)) $(filter %.S, $($(target)_SOURCES))\
|
---|
276 | ,$(eval $(def_target_source_c_cpp_asm)) ))
|
---|
277 | endef
|
---|
278 |
|
---|
279 |
|
---|
280 | #
|
---|
281 | # LIBRARIES
|
---|
282 | #
|
---|
283 |
|
---|
284 | ## Library (one).
|
---|
285 | # @param $(lib) Library name
|
---|
286 | define def_lib
|
---|
287 | # source -> object
|
---|
288 | $(eval $(def_target_sources))
|
---|
289 |
|
---|
290 | # library
|
---|
291 | $(eval tool := $(firstword $($(target)_TOOL) $(TOOL)))
|
---|
292 | $(eval flags := $($(target)_ARFLAGS) $(ARFLAGS) $(TOOL_$(tool)_ARFLAGS))
|
---|
293 | $(eval libsuff := $(firstword $($(target)_LIBSUFF) $($(target)_LIBSUFF) $(TOOL_$(tool)_ARLIBSUFF) $(SUFF_LIB)))
|
---|
294 | ## @todo prefix
|
---|
295 | $(eval outbase := $(call _TARGET_BASE,$(target),$(target)))
|
---|
296 | $(eval lib := $(outbase)$(libsuff))
|
---|
297 | $(eval objs = $(_OBJS_$(target)))
|
---|
298 | $(eval dirdep := $(dir $(lib)).dir_created)
|
---|
299 | ## @todo fix dependencies
|
---|
300 | $(eval deps := )
|
---|
301 |
|
---|
302 | $(eval $(TOOL_$(tool)_LINK_LIBRARY))
|
---|
303 |
|
---|
304 | _OBJS += $(_OBJS_$(target))
|
---|
305 | _LIBS += $(lib)
|
---|
306 | endef
|
---|
307 |
|
---|
308 | # Process libraries
|
---|
309 | $(foreach target, $(LIBRARIES), $(eval $(def_lib)))
|
---|
310 |
|
---|
311 |
|
---|
312 |
|
---|
313 | #
|
---|
314 | # PROGRAMS
|
---|
315 | #
|
---|
316 |
|
---|
317 |
|
---|
318 |
|
---|
319 | #
|
---|
320 | # DLLS
|
---|
321 | #
|
---|
322 |
|
---|
323 |
|
---|
324 |
|
---|
325 | #
|
---|
326 | # DRIVERS
|
---|
327 | #
|
---|
328 |
|
---|
329 |
|
---|
330 |
|
---|
331 | #
|
---|
332 | # OTHERS
|
---|
333 | #
|
---|
334 |
|
---|
335 |
|
---|
336 |
|
---|
337 | #
|
---|
338 | # DOCS
|
---|
339 | #
|
---|
340 |
|
---|
341 |
|
---|
342 | #
|
---|
343 | # Directories.
|
---|
344 | #
|
---|
345 | _DIRFILES := $(sort $(addsuffix /.dir_created,$(_DIRS)) $(addsuffix .dir_created,$(dir $(_OBJS) $(_LIBS) $(_EXES) $(_DLLS))))
|
---|
346 |
|
---|
347 | define def_createdir
|
---|
348 | $(dirfile):
|
---|
349 | $(call MSG_L1,Creating directory $$(@D))
|
---|
350 | $(MKDIR) -p $$(@D)
|
---|
351 | @echo dir_created > $$@
|
---|
352 | endef
|
---|
353 |
|
---|
354 | $(foreach dirfile,$(_DIRFILES),$(eval $(def_createdir)))
|
---|
355 |
|
---|
356 | #
|
---|
357 | # THE MAIN RULES
|
---|
358 | #
|
---|
359 | all_recursive:
|
---|
360 |
|
---|
361 |
|
---|
362 | objs: $(_OBJS)
|
---|
363 | echo "dbg: _OBJS = $(_OBJS)"
|
---|
364 |
|
---|
365 | libs: $(_LIBS)
|
---|
366 | echo "dbg: _LIBS = $(_LIBS)"
|
---|
367 |
|
---|
368 |
|
---|
369 | # end-of-file-content
|
---|
370 | __footer_kmk__ := 1
|
---|
371 | endif # __footer_kmk__
|
---|