source: trunk/kBuild/footer.kmk@ 78

Last change on this file since 78 was 78, checked in by bird, 21 years ago

..

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 24.9 KB
Line 
1# $Id: footer.kmk 78 2004-06-01 01:07:24Z 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
27ifndef __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.
36ALL_TARGETS := $(LIBRARIES) $(PROGRAMS) $(DLLS) $(DRIVERS) $(OTHERS)
37
38# dependency files.
39_DEPFILES :=
40
41# All kind of output files except for _OBJS and _DEPFILES.
42# Compiling or linking definition outputting other things that $@ and any
43# required dependency file must add those output files to this variable.
44_OUT_FILES :=
45
46# all of a type
47_OBJS :=
48_LIBS :=
49_DLLS :=
50_EXES :=
51_DIRS :=
52
53# all objs of a specific target
54define def_objs_var
55_OBJS_$1 :=
56endef
57$(foreach target, $(ALL_TARGETS), $(eval _OBJS_$(target) := ))
58
59
60#
61# Basic macros
62#
63
64## Figure out the tool for a source
65# @param $1 source file
66# @param $2 normalized main target
67# @param $3 tooltype
68_SOURCE_TOOL = $(strip $(firstword $($1_$2_$(3)TOOL) $($1_$2_TOOL) $($1_$(3)TOOL) $($1_TOOL) $($2_$(3)TOOL) $($2_TOOL) $($(3)TOOL) $(TOOL) ))
69
70## Figure out the tool for a target.
71# @param $1 normalized target.
72# @param $2 tooltype.
73_TARGET_TOOL = $(strip $(firstword $($(1)_$(2)TOOL) $($(1)_TOOL) $($(2)TOOL) $(TOOL) ))
74
75## Figure out where to put object files.
76# @param $1 source file
77# @param $2 normalized main target
78_OBJECT_BASE = $(PATH_TARGET)/$(2)/$(basename $(1))
79
80## Figure out where to put object files.
81# @param $1 real target name.
82# @param $2 normalized main target
83_TARGET_BASE = $(PATH_TARGET)/$(2)/$(basename $(1))
84
85
86#
87# Include templates
88#
89_TEMPLATES := $(TEMPLATE)
90define def_templates
91ifdef $(target)_TEMPLATE
92_TEMPLATES += $($(target)_TEMPLATE)
93endif
94endef
95$(foreach target, $(ALL_TARGETS), $(eval $(def_templates)))
96_TEMPLATES := $(sort $(_TEMPLATES))
97# $ (warning dbg: _TEMPLATES=$(_TEMPLATES))
98
99define def_templates_include
100ifndef TEMPLATE_$(template)
101include $(firstword $(wildcard $(PATH_KBUILD)/templates/$(template).kmk))
102endif
103endef
104$(foreach template, $(_TEMPLATES), $(eval $(def_templates)))
105
106
107#
108# Common Inheritance
109#
110
111## Inherit defaults property
112# @param $(prop) Property name
113# @param $(target) Target name.
114define def_inherit_defaults_one
115ifndef $(target)_$(prop)
116ifdef $(prop)
117$(target)_$(prop) := $($(prop))
118endif
119endif
120endef
121
122## Inherit default properties for one target.
123# A bit tricky this one, but it depends a bit on whether or not TEMPLATE
124# is inherited from the default properties.
125# @param $(target) Target name
126#
127define def_inherit_defaults
128ifdef $(target)_TEMPLATE
129ifndef TEMPLATE_$($(target)_TEMPLATE)_TOOL
130$(foreach prop,TOOL, $(eval $(def_inherit_defaults_one)))
131endif
132ifndef TEMPLATE_$($(target)_TEMPLATE)_SDKS
133$(foreach prop,SDKS, $(eval $(def_inherit_defaults_one)))
134endif
135else
136$(foreach prop,TEMPLATE TOOL SDKS,$(eval $(def_inherit_defaults_one)))
137endif
138endef
139# Inherit default properties.
140$(foreach target, $(ALL_TARGETS), $(eval $(def_inherit_defaults)))
141
142
143## Inherit one template property in a accumulative manner.
144# @param $(prop) Property name
145# @param $(target) Target name
146# @todo fix the precedence order for some properties.
147define def_inherit_template_one
148ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop)
149ifndef $(target)_$(prop)
150$(eval $(target)_$(prop) := $(TEMPLATE_$($(target)_TEMPLATE)_$(prop)))
151endif
152endif
153endef
154
155## Inherit one template property.
156# @param $(prop) Property name
157# @param $(target) Target name
158define def_inherit_template_one_accumulate
159ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop)
160$(eval $(target)_$(prop) := $($(target)_$(prop)) $(TEMPLATE_$($(target)_TEMPLATE)_$(prop)))
161endif
162#$ (warning 1b $(target)_$(prop)=$($(target)_$(prop)) org=$(origin $(target)_$(prop)) TEMPLATE_$($(target)_TEMPLATE)_$(prop)=$(TEMPLATE_$($(target)_TEMPLATE)_$(prop)) org=$(origin TEMPLATE_$($(target)_TEMPLATE)_$(prop)))
163endef
164
165## Inherit template properties for on target.
166# @param $(target) Target name.
167define def_inherit_template
168$(foreach prop,TOOL ARTOOL CTOOL CXXTOOL ASTOOL\
169 ,$(eval $(def_inherit_template_one)))
170$(foreach prop,SDKS DEFS INCS COPTS CFLAGS CDEFS CINCS CXXOPTS CXXFLAGS CXXDEFS CXXINCS ASOPTS ASFLAGS ASDEFS ASINCS\
171 ,$(eval $(def_inherit_template_one_accumulate)))
172endef
173# Inherit template properties
174$(foreach target, $(ALL_TARGETS), $(eval $(def_inherit_template)))
175
176
177
178#
179# Include tools
180#
181_TOOLS := $(TOOL)
182define def_tools_target_source
183$(foreach tool,\
184 $($(source)_TOOL) $($(target)_$(source)_TOOL)\
185 $($(source)_CTOOL) $($(target)_$(source)_CTOOL)\
186 $($(source)_CXXTOOL) $($(target)_$(source)_CXXTOOL)\
187 $($(source)_ASTOOL) $($(target)_$(source)_ASTOOL)\
188 $($(source)_ARTOOL) $($(target)_$(source)_ARTOOL)\
189 $($(source)_LDTOOL) $($(target)_$(source)_LDTOOL)\
190 ,$(eval _TOOLS += $(tool)))
191endef
192define def_tools_target
193$(foreach tool,\
194 $($(target)_TOOL)\
195 $($(target)_CTOOL)\
196 $($(target)_CXXTOOL)\
197 $($(target)_ASTOOL)\
198 $($(target)_ARTOOL)\
199 $($(target)_LDTOOL)\
200 , $(eval _TOOLS += $(tool)))
201$(foreach source, $($(target)_SOURCES), $(eval $(def_tools_target_source)))
202endef
203$(foreach target, $(ALL_TARGETS), $(eval $(def_tools_target)))
204_TOOLS := $(sort $(_TOOLS))
205
206define def_tools_include
207ifndef TOOL_$(tool)
208include $(firstword $(wildcard $(PATH_KBUILD)/tools/$(tool).kmk))
209endif
210endef
211$(foreach tool, $(_TOOLS), $(eval $(def_tools_include)))
212
213
214#
215# Include SDKs
216#
217_SDKS := $(SDKS)
218define def_sdks_target_source
219$(foreach sdk, $($(source)_SDKS) $($(target)_$(source)_SDKS), \
220 $(eval _SDKS += $(sdk)))
221endef
222define def_sdks_target
223$(foreach sdk, $($(target)_SDKS), $(eval _SDKS += $(sdk)))
224$(foreach source, $($(target)_SOURCES), $(eval $(def_sdks_target_source)))
225endef
226$(foreach target, $(ALL_TARGETS), $(eval $(def_sdks_target)))
227_SDKS := $(sort $(_SDKS))
228
229define def_sdks_include
230ifndef SDK_$(sdk)
231include $(firstword $(wildcard $(PATH_KBUILD)/sdks/$(sdk).kmk))
232endif
233endef
234$(foreach sdk, $(_SDKS), $(eval $(def_sdk)))
235
236#
237# Object processing.
238#
239
240## Generic macro for processing C, C++ and Assembly sources.
241# @param $(target) Normalized target name.
242# @param $(source) Source file name.
243# @param $(type) Source type. {C,CXX,AS}
244#
245# @remark I've no clue why I've to $(eval ..) everything in this define. MAKE bug?
246define def_target_source_c_cpp_asm
247#$ (warning dbg: def_target_source_c_cpp_asm: source=$(source) target=$(target) type=$(type))
248
249$(eval tool:=$(call _SOURCE_TOOL,$(source),$(target),$(type)))
250$(eval defs :=\
251 $(TOOL_$(tool)_DEFS)\
252 $(TOOL_$(tool)_DEFS.$(BUILD_TYPE))\
253 $(TOOL_$(tool)_DEFS.$(BUILD_TARGET))\
254 $(TOOL_$(tool)_DEFS.$(BUILD_TARGET_ARCH))\
255 $(TOOL_$(tool)_DEFS.$(BUILD_TARGET_CPU))\
256 $(TOOL_$(tool)_$(type)DEFS)\
257 $(TOOL_$(tool)_$(type)DEFS.$(BUILD_TYPE))\
258 $(foreach sdk, $(SDKS.$(BUILD_TARGET)) \
259 $(SDKS.$(BUILD_TYPE)) \
260 $(SDKS),\
261 $(SDK_$(sdk)_DEFS)\
262 $(SDK_$(sdk)_DEFS.$(BUILD_TYPE))\
263 $(SDK_$(sdk)_DEFS.$(BUILD_TARGET))\
264 $(SDK_$(sdk)_DEFS.$(BUILD_TARGET_ARCH))\
265 $(SDK_$(sdk)_DEFS.$(BUILD_TARGET_CPU))
266 $(SDK_$(sdk)_$(type)DEFS)\
267 $(SDK_$(sdk)_$(type)DEFS.$(BUILD_TYPE))\
268 $(SDK_$(sdk)_$(type)DEFS.$(BUILD_TARGET))\
269 $(SDK_$(sdk)_$(type)DEFS.$(BUILD_TARGET_ARCH))\
270 $(SDK_$(sdk)_$(type)DEFS.$(BUILD_TARGET_CPU)))\
271 $(DEFS)\
272 $(DEFS.$(BUILD_TYPE))\
273 $(DEFS.$(BUILD_TARGET))\
274 $(DEFS.$(BUILD_TARGET_ARCH))\
275 $(DEFS.$(BUILD_TARGET_CPU))\
276 $($(type)DEFS)\
277 $($(type)DEFS.$(BUILD_TYPE))\
278 $($(type)DEFS.$(BUILD_TARGET))\
279 $($(type)DEFS.$(BUILD_TARGET_ARCH))\
280 $($(type)DEFS.$(BUILD_TARGET_CPU))\
281 $(foreach sdk, $($(target)_SDKS.$(BUILD_TARGET)) \
282 $($(target)_SDKS.$(BUILD_TYPE)) \
283 $($(target)_SDKS),\
284 $(SDK_$(sdk)_DEFS)\
285 $(SDK_$(sdk)_DEFS.$(BUILD_TYPE))\
286 $(SDK_$(sdk)_DEFS.$(BUILD_TARGET))\
287 $(SDK_$(sdk)_DEFS.$(BUILD_TARGET_ARCH))\
288 $(SDK_$(sdk)_DEFS.$(BUILD_TARGET_CPU))
289 $(SDK_$(sdk)_$(type)DEFS)\
290 $(SDK_$(sdk)_$(type)DEFS.$(BUILD_TYPE))\
291 $(SDK_$(sdk)_$(type)DEFS.$(BUILD_TARGET))\
292 $(SDK_$(sdk)_$(type)DEFS.$(BUILD_TARGET_ARCH))\
293 $(SDK_$(sdk)_$(type)DEFS.$(BUILD_TARGET_CPU)))\
294 $($(target)_DEFS)\
295 $($(target)_DEFS.$(BUILD_TYPE))\
296 $($(target)_DEFS.$(BUILD_TARGET))\
297 $($(target)_DEFS.$(BUILD_TARGET_ARCH))\
298 $($(target)_DEFS.$(BUILD_TARGET_CPU))\
299 $($(target)_$(type)DEFS)\
300 $($(target)_$(type)DEFS.$(BUILD_TYPE))\
301 $($(target)_$(type)DEFS.$(BUILD_TARGET))\
302 $($(target)_$(type)DEFS.$(BUILD_TARGET_ARCH))\
303 $($(target)_$(type)DEFS.$(BUILD_TARGET_CPU))\
304 $(foreach sdk, $($(source)_SDKS.$(BUILD_TARGET)) \
305 $($(source)_SDKS.$(BUILD_TYPE)) \
306 $($(source)_SDKS),\
307 $(SDK_$(sdk)_DEFS)\
308 $(SDK_$(sdk)_DEFS.$(BUILD_TYPE))\
309 $(SDK_$(sdk)_DEFS.$(BUILD_TARGET))\
310 $(SDK_$(sdk)_DEFS.$(BUILD_TARGET_ARCH))\
311 $(SDK_$(sdk)_DEFS.$(BUILD_TARGET_CPU))
312 $(SDK_$(sdk)_$(type)DEFS)\
313 $(SDK_$(sdk)_$(type)DEFS.$(BUILD_TYPE))\
314 $(SDK_$(sdk)_$(type)DEFS.$(BUILD_TARGET))\
315 $(SDK_$(sdk)_$(type)DEFS.$(BUILD_TARGET_ARCH))\
316 $(SDK_$(sdk)_$(type)DEFS.$(BUILD_TARGET_CPU)))\
317 $($(source)_DEFS)\
318 $($(source)_DEFS.$(BUILD_TYPE))\
319 $($(source)_DEFS.$(BUILD_TARGET))\
320 $($(source)_DEFS.$(BUILD_TARGET_ARCH))\
321 $($(source)_DEFS.$(BUILD_TARGET_CPU))\
322 $($(source)_$(type)DEFS)\
323 $($(source)_$(type)DEFS.$(BUILD_TYPE))\
324 $($(source)_$(type)DEFS.$(BUILD_TARGET))\
325 $($(source)_$(type)DEFS.$(BUILD_TARGET_ARCH))\
326 $($(source)_$(type)DEFS.$(BUILD_TARGET_CPU))\
327 $(foreach sdk, $($(target)_$(source)_SDKS.$(BUILD_TARGET)) \
328 $($(target)_$(source)_SDKS.$(BUILD_TYPE)) \
329 $($(target)_$(source)_SDKS),\
330 $(SDK_$(sdk)_DEFS)\
331 $(SDK_$(sdk)_DEFS.$(BUILD_TYPE))\
332 $(SDK_$(sdk)_DEFS.$(BUILD_TARGET))\
333 $(SDK_$(sdk)_DEFS.$(BUILD_TARGET_ARCH))\
334 $(SDK_$(sdk)_DEFS.$(BUILD_TARGET_CPU))
335 $(SDK_$(sdk)_$(type)DEFS)\
336 $(SDK_$(sdk)_$(type)DEFS.$(BUILD_TYPE))\
337 $(SDK_$(sdk)_$(type)DEFS.$(BUILD_TARGET))\
338 $(SDK_$(sdk)_$(type)DEFS.$(BUILD_TARGET_ARCH))\
339 $(SDK_$(sdk)_$(type)DEFS.$(BUILD_TARGET_CPU)))\
340 $($(target)_$(source)_DEFS)\
341 $($(target)_$(source)_DEFS.$(BUILD_TYPE))\
342 $($(target)_$(source)_DEFS.$(BUILD_TARGET))\
343 $($(target)_$(source)_DEFS.$(BUILD_TARGET_ARCH))\
344 $($(target)_$(source)_DEFS.$(BUILD_TARGET_CPU))\
345 $($(target)_$(source)_$(type)DEFS)\
346 $($(target)_$(source)_$(type)DEFS.$(BUILD_TYPE))\
347 $($(target)_$(source)_$(type)DEFS.$(BUILD_TARGET))\
348 $($(target)_$(source)_$(type)DEFS.$(BUILD_TARGET_ARCH))\
349 $($(target)_$(source)_$(type)DEFS.$(BUILD_TARGET_CPU))\
350 )
351$(eval incs :=\
352 $($(target)_$(source)_$(type)INCS.$(BUILD_TARGET_CPU))\
353 $($(target)_$(source)_$(type)INCS.$(BUILD_TARGET_ARCH))\
354 $($(target)_$(source)_$(type)INCS.$(BUILD_TARGET))\
355 $($(target)_$(source)_$(type)INCS.$(BUILD_TYPE))\
356 $($(target)_$(source)_$(type)INCS)\
357 $($(target)_$(source)_INCS.$(BUILD_TARGET_CPU))\
358 $($(target)_$(source)_INCS.$(BUILD_TARGET_ARCH))\
359 $($(target)_$(source)_INCS.$(BUILD_TARGET))\
360 $($(target)_$(source)_INCS.$(BUILD_TYPE))\
361 $($(target)_$(source)_INCS)\
362 $(foreach sdk, $($(target)_$(source)_SDKS.$(BUILD_TARGET)) \
363 $($(target)_$(source)_SDKS.$(BUILD_TYPE)) \
364 $($(target)_$(source)_SDKS),
365 $(SDK_$(sdk)_$(type)INCS.$(BUILD_TARGET_CPU))\
366 $(SDK_$(sdk)_$(type)INCS.$(BUILD_TARGET_ARCH))\
367 $(SDK_$(sdk)_$(type)INCS.$(BUILD_TARGET))\
368 $(SDK_$(sdk)_$(type)INCS.$(BUILD_TYPE))\
369 $(SDK_$(sdk)_$(type)INCS)\
370 $(SDK_$(sdk)_INCS.$(BUILD_TARGET_CPU))\
371 $(SDK_$(sdk)_INCS.$(BUILD_TARGET_ARCH))\
372 $(SDK_$(sdk)_INCS.$(BUILD_TARGET))\
373 $(SDK_$(sdk)_INCS.$(BUILD_TYPE))\
374 $(SDK_$(sdk)_INCS))\
375 $($(source)_$(type)INCS.$(BUILD_TARGET_CPU))\
376 $($(source)_$(type)INCS.$(BUILD_TARGET_ARCH))\
377 $($(source)_$(type)INCS.$(BUILD_TARGET))\
378 $($(source)_$(type)INCS.$(BUILD_TYPE))\
379 $($(source)_$(type)INCS)\
380 $($(source)_INCS.$(BUILD_TARGET_CPU))\
381 $($(source)_INCS.$(BUILD_TARGET_ARCH))\
382 $($(source)_INCS.$(BUILD_TARGET))\
383 $($(source)_INCS.$(BUILD_TYPE))\
384 $($(source)_INCS)\
385 $(foreach sdk, $($(source)_SDKS.$(BUILD_TARGET)) \
386 $($(source)_SDKS.$(BUILD_TYPE)) \
387 $($(source)_SDKS),\
388 $(SDK_$(sdk)_$(type)INCS.$(BUILD_TARGET_CPU))\
389 $(SDK_$(sdk)_$(type)INCS.$(BUILD_TARGET_ARCH))\
390 $(SDK_$(sdk)_$(type)INCS.$(BUILD_TARGET))\
391 $(SDK_$(sdk)_$(type)INCS.$(BUILD_TYPE))\
392 $(SDK_$(sdk)_$(type)INCS)\
393 $(SDK_$(sdk)_INCS.$(BUILD_TARGET_CPU))\
394 $(SDK_$(sdk)_INCS.$(BUILD_TARGET_ARCH))\
395 $(SDK_$(sdk)_INCS.$(BUILD_TARGET))\
396 $(SDK_$(sdk)_INCS.$(BUILD_TYPE))\
397 $(SDK_$(sdk)_INCS))\
398 $($(target)_$(type)INCS.$(BUILD_TARGET_CPU))\
399 $($(target)_$(type)INCS.$(BUILD_TARGET_ARCH))\
400 $($(target)_$(type)INCS.$(BUILD_TARGET))\
401 $($(target)_$(type)INCS.$(BUILD_TYPE))\
402 $($(target)_$(type)INCS)\
403 $($(target)_INCS.$(BUILD_TARGET_CPU))\
404 $($(target)_INCS.$(BUILD_TARGET_ARCH))\
405 $($(target)_INCS.$(BUILD_TARGET))\
406 $($(target)_INCS.$(BUILD_TYPE))\
407 $($(target)_INCS)\
408 $(foreach sdk, $($(target)_SDKS.$(BUILD_TARGET)) \
409 $($(target)_SDKS.$(BUILD_TYPE)) \
410 $($(target)_SDKS),\
411 $(SDK_$(sdk)_$(type)INCS.$(BUILD_TARGET_CPU))\
412 $(SDK_$(sdk)_$(type)INCS.$(BUILD_TARGET_ARCH))\
413 $(SDK_$(sdk)_$(type)INCS.$(BUILD_TARGET))\
414 $(SDK_$(sdk)_$(type)INCS.$(BUILD_TYPE))\
415 $(SDK_$(sdk)_$(type)INCS)\
416 $(SDK_$(sdk)_INCS.$(BUILD_TARGET_CPU))\
417 $(SDK_$(sdk)_INCS.$(BUILD_TARGET_ARCH))\
418 $(SDK_$(sdk)_INCS.$(BUILD_TARGET))\
419 $(SDK_$(sdk)_INCS.$(BUILD_TYPE))\
420 $(SDK_$(sdk)_INCS))\
421 $(INCS.$(BUILD_TARGET_CPU))\
422 $(INCS.$(BUILD_TARGET_ARCH))\
423 $(INCS.$(BUILD_TARGET))\
424 $(INCS.$(BUILD_TYPE))\
425 $(INCS)\
426 $(foreach sdk, $(SDKS.$(BUILD_TARGET)) \
427 $(SDKS.$(BUILD_TYPE)) \
428 $(SDKS),\
429 $(SDK_$(sdk)_$(type)INCS.$(BUILD_TARGET_CPU))\
430 $(SDK_$(sdk)_$(type)INCS.$(BUILD_TARGET_ARCH))\
431 $(SDK_$(sdk)_$(type)INCS.$(BUILD_TARGET))\
432 $(SDK_$(sdk)_$(type)INCS.$(BUILD_TYPE))\
433 $(SDK_$(sdk)_$(type)INCS)\
434 $(SDK_$(sdk)_INCS.$(BUILD_TARGET_CPU))\
435 $(SDK_$(sdk)_INCS.$(BUILD_TARGET_ARCH))\
436 $(SDK_$(sdk)_INCS.$(BUILD_TARGET))\
437 $(SDK_$(sdk)_INCS.$(BUILD_TYPE))\
438 $(SDK_$(sdk)_INCS))\
439 $(TOOL_$(tool)_$(type)INCS.$(BUILD_TARGET_CPU))\
440 $(TOOL_$(tool)_$(type)INCS.$(BUILD_TARGET_ARCH))\
441 $(TOOL_$(tool)_$(type)INCS.$(BUILD_TARGET))\
442 $(TOOL_$(tool)_$(type)INCS.$(BUILD_TYPE))\
443 $(TOOL_$(tool)_$(type)INCS)\
444 )
445$(eval flags :=\
446 $(TOOL_$(tool)_$(type)FLAGS)\
447 $(TOOL_$(tool)_$(type)FLAGS.$(BUILD_TYPE))\
448 $(TOOL_$(tool)_$(type)FLAGS.$(BUILD_TARGET))\
449 $(TOOL_$(tool)_$(type)FLAGS.$(BUILD_TARGET_ARCH))\
450 $(TOOL_$(tool)_$(type)FLAGS.$(BUILD_TARGET_CPU))\
451 $($(type)FLAGS)\
452 $($(type)FLAGS.$(BUILD_TYPE))\
453 $($(type)FLAGS.$(BUILD_TARGET))\
454 $($(type)FLAGS.$(BUILD_TARGET_ARCH))\
455 $($(type)FLAGS.$(BUILD_TARGET_CPU))\
456 $($(target)_$(type)FLAGS)\
457 $($(target)_$(type)FLAGS.$(BUILD_TYPE))\
458 $($(target)_$(type)FLAGS.$(BUILD_TARGET))\
459 $($(target)_$(type)FLAGS.$(BUILD_TARGET_ARCH))\
460 $($(target)_$(type)FLAGS.$(BUILD_TARGET_CPU))\
461 $($(source)_$(type)FLAGS)\
462 $($(source)_$(type)FLAGS.$(BUILD_TYPE))\
463 $($(source)_$(type)FLAGS.$(BUILD_TARGET))\
464 $($(source)_$(type)FLAGS.$(BUILD_TARGET_ARCH))\
465 $($(source)_$(type)FLAGS.$(BUILD_TARGET_CPU))\
466 $($(target)_$(source)_$(type)FLAGS)\
467 $($(target)_$(source)_$(type)FLAGS.$(BUILD_TYPE))\
468 $($(target)_$(source)_$(type)FLAGS.$(BUILD_TARGET))\
469 $($(target)_$(source)_$(type)FLAGS.$(BUILD_TARGET_ARCH))\
470 $($(target)_$(source)_$(type)FLAGS.$(BUILD_TARGET_CPU))\
471 )
472$(eval outbase := $(call _OBJECT_BASE,$(source),$(target)))
473$(eval dirdep := $(dir $(outbase)).dir_created)
474$(eval objsuff := $(firstword \
475 $($(target)_$(source)_OBJSUFF.$(BUILD_TARGET))\
476 $($(target)_$(source)_OBJSUFF)\
477 $($(source)_OBJSUFF.$(BUILD_TARGET))\
478 $($(source)_OBJSUFF)\
479 $($(target)_OBJSUFF.$(BUILD_TARGET))\
480 $($(target)_OBJSUFF)\
481 $(TOOL_$(tool)_$(type)OBJSUFF.$(BUILD_TARGET))\
482 $(TOOL_$(tool)_$(type)OBJSUFF)\
483 $(SUFF_OBJ)\
484 ))
485$(eval obj := $(outbase)$(objsuff))
486$(eval dep := $(outbase)$(SUFF_DEP))
487
488#$ (warning dbg: target=$(target) source=$(source) tool=$(tool) obj=$(obj) dep=$(dep) flags=$(flags) defs=$(defs) incs=$(incs) dirdep=$(dirdep) outbase=$(outbase) objsuff=$(objsuff))
489$(eval $(TOOL_$(tool)_COMPILE_$(type)))
490
491$(eval _OBJS_$(target) += $(obj))
492$(eval _DEPFILES += $(dep))
493
494endef
495
496## Generic macro for processing all target sources.
497# @param $(target) Normalized target name.
498define def_target_sources
499#$ (warning def_target_sources)
500# C sources
501$(foreach type,C,$(foreach source, $(filter %.c, $($(target)_SOURCES))\
502 ,$(eval $(def_target_source_c_cpp_asm)) ))
503
504# C++ sources
505$(foreach type,CXX,$(foreach source, $(filter %.cpp, $($(target)_SOURCES)) $(filter %.cxx, $($(target)_SOURCES)) $(filter %.cc, $($(target)_SOURCES))\
506 ,$(eval $(def_target_source_c_cpp_asm)) ))
507
508# ASM sources
509$(foreach type,AS,$(foreach source, $(filter %.asm, $($(target)_SOURCES)) $(filter %.s, $($(target)_SOURCES)) $(filter %.S, $($(target)_SOURCES))\
510 ,$(eval $(def_target_source_c_cpp_asm)) ))
511endef
512
513
514#
515# LIBRARIES
516#
517
518## Library (one).
519# @param $(target) Normalized library (target) name.
520define def_lib
521# source -> object
522$(eval $(def_target_sources))
523
524# library
525$(eval tool := $(call _TARGET_TOOL,$(target),AR))
526ifeq ($(tool),)
527$$(error kBuild: Library target $(target) doesn't have a tool defined!)
528endif
529$(eval flags :=\
530 $(TOOL_$(tool)_ARFLAGS)\
531 $(TOOL_$(tool)_ARFLAGS.$(BUILD_TYPE))\
532 $(ARFLAGS)\
533 $(ARFLAGS.$(BUILD_TYPE))\
534 $($(target)_ARFLAGS)\
535 $($(target)_ARFLAGS.$(BUILD_TYPE))\
536 )
537$(eval libsuff := $(firstword\
538 $($(target)_LIBSUFF.$(BUILD_TARGET))\
539 $($(target)_LIBSUFF)\
540 $(TOOL_$(tool)_ARLIBSUFF.$(BUILD_TARGET))\
541 $(TOOL_$(tool)_ARLIBSUFF)\
542 $(SUFF_LIB)\
543))
544## @todo prefix
545$(eval outbase := $(call _TARGET_BASE,$(target),$(target)))
546$(eval lib := $(outbase)$(libsuff))
547$(eval objs = $(_OBJS_$(target)))
548$(eval dirdep := $(dir $(lib)).dir_created)
549## @todo fix dependencies on makefiles an such
550$(eval deps := )
551
552$(eval $(TOOL_$(tool)_LINK_LIBRARY))
553
554_OBJS += $(_OBJS_$(target))
555_LIBS += $(lib)
556_OUT_FILES += $(lib)
557endef
558
559# Process libraries
560$(foreach target, $(LIBRARIES), $(eval $(def_lib)))
561
562
563
564#
565# PROGRAMS
566#
567
568## Program (one).
569# @param $(target) Normalized target (program) name.
570define def_program
571# source -> object
572$(eval $(def_target_sources))
573
574# library
575$(eval tool := $(call _TARGET_TOOL,$(target),LD))
576$(eval flags :=\
577 $(TOOL_$(tool)_LDFLAGS)\
578 $(TOOL_$(tool)_LDFLAGS.$(BUILD_TYPE))\
579 $(LDFLAGS)\
580 $(LDFLAGS.$(BUILD_TYPE))\
581 $($(target)_LDFLAGS)\
582 $($(target)_LDFLAGS.$(BUILD_TYPE))\
583)
584$(eval exesuff := $(firstword $($(target)_EXESUFF) $($(target)_EXESUFF) $(TOOL_$(tool)_LDEXESUFF) $(SUFF_EXE)))
585$(eval outbase := $(call _TARGET_BASE,$(target),$(target)))
586$(eval exe := $(outbase)$(exesuff))
587$(eval objs = $(_OBJS_$(target)))
588$(eval libs :=\
589 $($(target)_LIBS.$(BUILD_TYPE))\
590 $($(target)_LIBS)\
591 $(LIBS.$(BUILD_TYPE))\
592 $(LIBS)\
593 $(TOOL_$(tool)_LIBS.$(BUILD_TYPE))\
594 $(TOOL_$(tool)_LIBS)\
595)
596$(eval libpath :=\
597 $($(target)_LIBPATH.$(BUILD_TYPE))\
598 $($(target)_LIBPATH)\
599 $(LIBPATH.$(BUILD_TYPE))\
600 $(LIBPATH)\
601 $(TOOL_$(tool)_LIBPATH.$(BUILD_TYPE))\
602 $(TOOL_$(tool)_LIBPATH)\
603)
604$(eval dirdep := $(dir $(exe)).dir_created)
605## @todo fix dependencies
606$(eval deps := )
607#
608$(eval deffile := $(strip $(firstword
609 $($(target)_DEFFILE.$(BUILD_TARGET).$(BUILD_TYPE))\
610 $($(target)_DEFFILE.$(BUILD_TARGET))\
611 $($(target)_DEFFILE.$(BUILD_TYPE))\
612 $($(target)_DEFFILE)\
613 $(DEFFILE.$(BUILD_TARGET).$(BUILD_TYPE))\
614 $(DEFFILE.$(BUILD_TARGET))\
615 $(DEFFILE.$(BUILD_TYPE))\
616 $(DEFFILE)\
617)))
618$(eval custom_pre := $(strip $(firstword
619 $($(target)_CUSTOM_PRE.$(BUILD_TARGET).$(BUILD_TYPE))\
620 $($(target)_CUSTOM_PRE.$(BUILD_TARGET))\
621 $($(target)_CUSTOM_PRE.$(BUILD_TYPE))\
622 $($(target)_CUSTOM_PRE)\
623 $(CUSTOM_PRE.$(BUILD_TARGET).$(BUILD_TYPE))\
624 $(CUSTOM_PRE.$(BUILD_TARGET))\
625 $(CUSTOM_PRE.$(BUILD_TYPE))\
626 $(CUSTOM_PRE)\
627)))
628$(eval custom_post := $(strip $(firstword
629 $($(target)_CUSTOM_POST.$(BUILD_TARGET).$(BUILD_TYPE))\
630 $($(target)_CUSTOM_POST.$(BUILD_TARGET))\
631 $($(target)_CUSTOM_POST.$(BUILD_TYPE))\
632 $($(target)_CUSTOM_POST)\
633 $(CUSTOM_POST.$(BUILD_TARGET).$(BUILD_TYPE))\
634 $(CUSTOM_POST.$(BUILD_TARGET))\
635 $(CUSTOM_POST.$(BUILD_TYPE))\
636 $(CUSTOM_POST)\
637)))
638
639$(eval $(TOOL_$(tool)_LINK_PROGRAM))
640
641_OBJS += $(_OBJS_$(target))
642_EXES += $(exe)
643_OUT_FILES += $(exe)
644endef
645
646# Process libraries
647$(foreach target, $(PROGRAMS), $(eval $(def_program)))
648
649
650
651#
652# DLLS
653#
654
655
656
657#
658# DRIVERS
659#
660
661
662
663#
664# OTHERS
665#
666
667
668
669#
670# DOCS
671#
672
673
674#
675# Directories.
676#
677_OUTPUT_FILES := $(_OBJS) $(_LIBS) $(_EXES) $(_DLLS)
678_DIRFILES := $(sort $(addsuffix /.dir_created,$(_DIRS)) $(addsuffix .dir_created,$(dir $(_OUTPUT_FILES))))
679
680define def_createdir
681$(dirfile):
682 $(call MSG_L1,Creating directory $$(@D))
683 $(MKDIR) -p $$(@D)
684 @echo dir_created > $$@
685endef
686
687$(foreach dirfile,$(_DIRFILES),$(eval $(def_createdir)))
688
689
690#
691# Include dependency files.
692#
693$(foreach dep,$(wildcard $(_DEPFILES)),$(eval include $(dep)))
694
695
696#
697# PASSES (including directory and makefile walking)
698#
699# Do all the default passes if it's unspecified.
700PASSES ?= needed libraries binaries others publish
701
702## Proritized list of the default makefile when walking subdirectories.
703# The user can overload this list.
704DEFAULT_MAKEFILE ?= Makefile.kmk makefile.kmk Makefile makefile
705
706## Subdir
707# @param $(pass) Lowercase pass name.
708# @param $(PASS) Uppercase pass name.
709# @param $(subdir) Subdirectory
710# @param $(tag) tag to attach to the rule name.
711define def_pass_subdir
712pass_$(pass)$(tag)::
713 $(QUIET)$$(MAKE) -C $(subdir) -f $$(notdir $$(firstword $$(wildcard $$(addprefix $(subdir)/,$$(DEFAULT_MAKEFILE))))) pass_$(pass)
714endef
715
716## Submakefile
717# @param $(pass) Lowercase pass name.
718# @param $(PASS) Uppercase pass name.
719# @param $(makefile) Makefile.
720# @param $(tag) tag to attach to the rule name.
721define def_pass_makefile
722pass_$(pass)$(tag)::
723 $(QUIET)$$(MAKE) -C $(patsubst %/,%,$(dir $(makefile))) -f $(notdir $(makefile)) pass_$(pass)
724endef
725
726
727## Execute a pass.
728# @param $(pass) Lowercase pass name.
729# @param $(PASS) Uppercase pass name.
730define def_pass
731$(eval SUBDIRS_$(PASS) ?= $(SUBDIRS))
732$(eval SUBDIRS_AFTER_$(PASS) ?= $(SUBDIRS_AFTER))
733$(eval MAKEFILES_BEFORE_$(PASS) ?= $(MAKEFILES_BEFORE))
734$(eval MAKEFILES_AFTER_$(PASS) ?= $(MAKEFILES_AFTER))
735
736$(eval tag:=_before)
737$(foreach subdir,$(SUBDIRS_$(PASS)),$(eval $(def_pass_subdir)))
738$(foreach makefile,$(MAKEFILES_BEFORE_$(PASS)),$(eval $(def_pass_makefile)))
739
740$(eval tag:=_after)
741$(foreach subdir,$(SUBDIRS_AFTER_$(PASS)),$(eval $(def_pass_subdir)))
742$(foreach makefile,$(MAKEFILES_AFTER_$(PASS)),$(eval $(def_pass_makefile)))
743
744.NOTPARALLEL: pass_$(pass)_before pass_$(pass)_after
745.PHONY: pass_$(pass) pass_$(pass)_before pass_$(pass)_doit pass_$(pass)_after
746pass_$(pass): \
747 pass_$(pass)_before \
748 pass_$(pass)_doit \
749 pass_$(pass)_after
750
751endef
752
753
754## PASS: needed
755# This pass builds targets which are required for building the rest.
756pass_needed_doit: $(_NEEDEDS)
757pass := needed
758PASS := NEEDED
759$(eval $(def_pass))
760
761## PASS: libraries
762# This pass builds library targets.
763pass_libraries_doit: $(_LIBS) $(_IMPORT_LIBS) $(_OTHER_LIBRARIES)
764pass := libraries
765PASS := LIBRARIES
766$(eval $(def_pass))
767
768## PASS: binaries
769# This pass builds binary targets, i.e. programs, dlls, drivers and stuff.
770pass_binaries_doit: $(_DLLS) $(_EXES) $(_KMODS) $(_OTHER_BINARIES)
771pass := binaries
772PASS := BINARIES
773$(eval $(def_pass))
774
775## PASS: others
776# This pass builds binary targets, i.e. programs, dlls, drivers and stuff.
777pass_others_doit: $(_OTHERS)
778pass := others
779PASS := OTHERS
780$(eval $(def_pass))
781
782## PASS: publish
783# This pass installs the built entities to a sandbox area.
784pass_publish_doit: publish
785publish::
786pass := publish
787PASS := PUBLISH
788# $(sort).. not nice.
789SUBDIRS_PUBLISH ?= $(sort $(SUBDIRS) $(SUBDIRS_LIBRARIES) $(SUBDIRS_BINARIES) $(SUBDIRS_OTHERS))
790SUBDIRS_AFTER_PUBLISH ?= $(sort $(SUBDIRS_AFTER) $(SUBDIRS_AFTER_LIBRARIES) $(SUBDIRS_AFTER_BINARIES) $(SUBDIRS_AFTER_OTHERS))
791MAKEFILES_BEFORE_PUBLISH?= $(sort $(MAKEFILES_BEFORE) $(MAKEFILES_BEFORE_LIBRARIES) $(MAKEFILES_BEFORE_BINARIES) $(MAKEFILES_BEFORE_OTHERS))
792MAKEFILES_AFTER_PUBLISH ?= $(sort $(MAKEFILES_AFTER) $(MAKEFILES_AFTER_LIBRARIES) $(MAKEFILES_AFTER_BINARIES) $(MAKEFILES_AFTER_OTHERS))
793$(eval $(def_pass))
794
795## PASS: packing
796# This pass processes custom packing rules.
797pass_packing_doit: packing
798packing::
799pass := packing
800PASS := PACKING
801$(eval $(def_pass))
802
803## PASS: clean
804# This pass removes all generated files.
805pass_clean_doit:
806 $(RM) -f $(_OUT_FILES) $(_OBJS) $(_DEPFILES) $(_DIRFILES)
807pass := clean
808PASS := CLEAN
809$(eval $(def_pass))
810clean: pass_clean
811
812## PASS: nothing
813# This pass just walks the tree.
814pass_nothing_doit:
815 $(call MSG_L1,Did nothing in $(CURDIR))
816pass := nothing
817PASS := NOTHING
818$(eval $(def_pass))
819nothing: pass_nothing
820
821
822
823#
824# THE MAIN RULES
825#
826all_recursive: $(foreach pass,$(PASSES),pass_$(pass))
827
828rebuild: clean all_recursive
829
830
831# misc shortcuts.
832target: needed libraries binaries others
833objects: $(_OBJS)
834programs: $(_EXES)
835dlls: $(_DLLS)
836kernelmodules: $(_KMODS)
837
838
839# end-of-file-content
840__footer_kmk__ := 1
841endif # __footer_kmk__
Note: See TracBrowser for help on using the repository browser.