source: trunk/kBuild/footer.kmk@ 121

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

Fixed rebuild dependency reload issue. Added two _SOURCE.somthing variations.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 34.8 KB
Line 
1# $Id: footer.kmk 120 2004-06-25 17:01:36Z bird $
2## @file
3#
4# kBuild - File included at top of makefile.
5#
6# Copyright (c) source004 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 source 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 typetype0, Boston, MA 0sourcetargettargettarget-targettype07 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) $(SYSMODS) $(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_SYSMODS:=
52_DIRS :=
53
54# all objs of a specific target
55define def_objs_var
56_OBJS_$target :=
57endef
58$(foreach target, $(ALL_TARGETS), $(eval _OBJS_$(target) := ))
59
60
61#
62# Basic macros
63#
64
65## Figure out the tool for a source
66# @param $target source file
67# @param $source normalized main target
68# @param $type tooltype
69_SOURCE_TOOL = $(strip $(firstword \
70 $($(target)_$(source)_$(type)TOOL.$(BUILD_TARGET)) \
71 $($(target)_$(source)_$(type)TOOL) \
72 $($(target)_$(source)_TOOL.$(BUILD_TARGET)) \
73 $($(target)_$(source)_TOOL) \
74 $($(target)_$(type)TOOL.$(BUILD_TARGET)) \
75 $($(target)_$(type)TOOL) \
76 $($(target)_TOOL.$(BUILD_TARGET)) \
77 $($(target)_TOOL) \
78 $($(source)_$(type)TOOL.$(BUILD_TARGET)) \
79 $($(source)_$(type)TOOL) \
80 $($(source)_TOOL.$(BUILD_TARGET)) \
81 $($(source)_TOOL) \
82 $($(type)TOOL.$(BUILD_TARGET)) \
83 $($(type)TOOL) \
84 $(TOOL.$(BUILD_TARGET)) \
85 $(TOOL) ))
86
87_SOURCE_TOOL_OLD = $(strip $(firstword \
88 $($(target)_$(source)_$(type)TOOL.$(BUILD_TARGET)) $($(target)_$(source)_TOOL.$(BUILD_TARGET)) \
89 $($(target)_$(source)_$(type)TOOL) $($target_$source_TOOL) \
90 $($(target)_$(type)TOOL.$(BUILD_TARGET)) $($(target)_TOOL.$(BUILD_TARGET)) \
91 $($(target)_$(type)TOOL) $($target_TOOL) \
92 $($(source)_$(type)TOOL.$(BUILD_TARGET)) $($(source)_TOOL.$(BUILD_TARGET)) \
93 $($(source)_$(type)TOOL) $($(source)_TOOL) \
94 $($(type)TOOL.$(BUILD_TARGET)) $(TOOL.$(BUILD_TARGET)) \
95 $($(type)TOOL) $(TOOL) ))
96
97## Figure out the tool for a target.
98# @param $target normalized target.
99# @param $source tooltype.
100_TARGET_TOOL = $(strip $(firstword \
101 $($(target)_$(source)TOOL.$(BUILD_TARGET)) \
102 $($(target)_$(source)TOOL) \
103 $($(target)_TOOL.$(BUILD_TARGET)) \
104 $($(target)_TOOL) \
105 $($(source)TOOL) \
106 $($(source)TOOL.$(BUILD_TARGET)) \
107 $(TOOL.$(BUILD_TARGET)) \
108 $(TOOL) \
109 ))
110
111## Figure out where to put object files.
112# @param $1 source file
113# @param $2 normalized main target
114_OBJECT_BASE = $(PATH_TARGET)/$(2)/$(basename $(1))
115
116## Figure out where to put object files.
117# @param $1 real target name.
118# @param $2 normalized main target
119_TARGET_BASE = $(PATH_TARGET)/$(2)/$(basename $(1))
120
121
122#
123# Include templates
124#
125_TEMPLATES := $(TEMPLATE)
126define def_templates
127ifdef $(target)_TEMPLATE
128_TEMPLATES += $($(target)_TEMPLATE)
129endif
130endef
131$(foreach target, $(ALL_TARGETS), $(eval $(def_templates)))
132_TEMPLATES := $(sort $(_TEMPLATES))
133# $ (warning dbg: _TEMPLATES=$(_TEMPLATES))
134
135define def_templates_include
136ifndef TEMPLATE_$(template)
137include $(firstword $(wildcard $(PATH_KBUILD)/templates/$(template).kmk))
138endif
139endef
140$(foreach template, $(_TEMPLATES), $(eval $(def_templates)))
141
142
143#
144# Common Inheritance
145#
146
147## Inherit defaults property
148# @param $(prop) Property name
149# @param $(target) Target name.
150define def_inherit_defaults_one
151ifndef $(target)_$(prop)
152ifndef $(target)_$(prop).$(BUILD_TARGET)
153ifdef $(prop)
154$$(eval $(target)_$(prop) := $($(prop)))
155endif
156ifdef $(prop).$(BUILD_TARGET)
157$$(eval $(target)_$(prop).$(BUILD_TARGET) := $($(prop).$(BUILD_TARGET)))
158endif
159endif
160endif
161endef
162
163## Inherit default properties for one target.
164# A bit tricky this one, but it depends a bit on whether or not TEMPLATE
165# is inherited from the default properties.
166# @param $(target) Target name
167#
168define def_inherit_defaults
169ifdef $(target)_TEMPLATE
170ifeq ($(strip $(TEMPLATE_$($(target)_TEMPLATE)_TOOL) $(TEMPLATE_$($(target)_TEMPLATE)_TOOL.$(BUILD_TARGET))),)
171$$(foreach prop,TOOL, $$(eval $$(def_inherit_defaults_one)))
172endif
173ifeq ($(strip $(TEMPLATE_$($(target)_TEMPLATE)_SDKS) $(TEMPLATE_$($(target)_TEMPLATE)_SDKS.$(BUILD_TARGET))),)
174$$(foreach prop,SDKS, $$(eval $$(def_inherit_defaults_one)))
175endif
176else
177$$(foreach prop,TEMPLATE TOOL SDKS, $$(eval $$(def_inherit_defaults_one)))
178endif
179endef
180# Inherit default properties.
181# !!!!!!THIS IS MESSY AND NOT NECESSARY!!!!!!
182$(foreach target, $(ALL_TARGETS),$(eval $(def_inherit_defaults)))
183
184
185## Inherit one template property in a accumulative manner.
186# @param $(prop) Property name
187# @param $(target) Target name
188# @todo fix the precedence order for some properties.
189define def_inherit_template_one
190ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop)
191ifndef $(target)_$(prop)
192#$$ (warning dbgtarget: $(target)_$(prop):='$(TEMPLATE_$($(target)_TEMPLATE)_$(prop))' TEMPLATE_$($(target)_TEMPLATE)_$(prop))
193$$(target)_$$(prop) := $$(TEMPLATE_$$($$(target)_TEMPLATE)_$$(prop))
194endif
195endif
196ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(BUILD_TARGET)
197ifndef $(target)_$(prop).$(BUILD_TARGET)
198#$$ (warning dbgsource: $(target)_$(prop).$(BUILD_TARGET)="TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(BUILD_TARGET)" TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(BUILD_TARGET))
199$$(target)_$$(prop).$$(BUILD_TARGET) := $$(TEMPLATE_$$($$(target)_TEMPLATE)_$$(prop).$$(BUILD_TARGET))
200endif
201endif
202endef
203
204## Inherit one template property.
205# @param $(prop) Property name
206# @param $(target) Target name
207define def_inherit_template_one_accumulate
208ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop)
209#$$ (warning dbgtype: TEMPLATE_$($(target)_TEMPLATE)_$(prop) $(target)_$(prop)=$($(target)_$(prop)) $(TEMPLATE_$($(target)_TEMPLATE)_$(prop)))
210$$(eval $(target)_$(prop) := $($(target)_$(prop)) $(TEMPLATE_$($(target)_TEMPLATE)_$(prop)))
211#$$ (warning dbgtype: $(target)_$(prop)=$($(target)_$(prop)))
212endif
213ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(BUILD_TARGET)
214#$$ (warning dbg4: TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(BUILD_TARGET))
215$$(eval $(target)_$(prop).$(BUILD_TARGET) := $($(target)_$(prop).$(BUILD_TARGET)) $(TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(BUILD_TARGET)))
216endif
217ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(BUILD_TARGET_CPU)
218#$$ (warning dbg5: TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(BUILD_TARGET_CPU))
219$$(eval $(target)_$(prop).$(BUILD_TARGET_CPU) := $($(target)_$(prop).$(BUILD_TARGET)) $(TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(BUILD_TARGET_CPU)))
220endif
221ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(BUILD_TARGET_ARCH)
222#$$ (warning dbg6: TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(BUILD_TARGET_ARCH))
223$$(eval $(target)_$(prop).$(BUILD_TARGET_ARCH) := $($(target)_$(prop).$(BUILD_TARGET)) $(TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(BUILD_TARGET_ARCH)))
224endif
225endef
226
227
228## Inherit template properties for on target.
229# @param $(target) Target name.
230define def_inherit_template
231$$(foreach prop, TOOL ARTOOL CTOOL CXXTOOL ASTOOL LDTOOL\
232 ,$$(eval $$(def_inherit_template_one)))
233$$(foreach prop,SDKS DEFS INCS COPTS CFLAGS CDEFS CINCS CXXOPTS CXXFLAGS CXXDEFS CXXINCS ASOPTS ASFLAGS ASDEFS ASINCS LDFLAGS LIBS LIBPATH \
234 ,$$(eval $$(def_inherit_template_one_accumulate)))
235endef
236# Inherit template properties
237$(foreach target, $(ALL_TARGETS),$(eval $(def_inherit_template)))
238
239
240#
241# Include tools
242#
243_TOOLS := $(TOOL)
244define def_tools_target_source
245$(foreach tool,\
246 $($(source)_TOOL.$(BUILD_TARGET)) $($(target)_$(source)_TOOL.$(BUILD_TARGET))\
247 $($(source)_TOOL) $($(target)_$(source)_TOOL)\
248 $($(source)_CTOOL.$(BUILD_TARGET)) $($(target)_$(source)_CTOOL.$(BUILD_TARGET))\
249 $($(source)_CTOOL) $($(target)_$(source)_CTOOL)\
250 $($(source)_CXXTOOL.$(BUILD_TARGET)) $($(target)_$(source)_CXXTOOL.$(BUILD_TARGET))\
251 $($(source)_CXXTOOL) $($(target)_$(source)_CXXTOOL)\
252 $($(source)_ASTOOL.$(BUILD_TARGET)) $($(target)_$(source)_ASTOOL.$(BUILD_TARGET))\
253 $($(source)_ASTOOL) $($(target)_$(source)_ASTOOL)\
254 $($(source)_ARTOOL.$(BUILD_TARGET)) $($(target)_$(source)_ARTOOL.$(BUILD_TARGET))\
255 $($(source)_ARTOOL) $($(target)_$(source)_ARTOOL)\
256 $($(source)_LDTOOL.$(BUILD_TARGET)) $($(target)_$(source)_LDTOOL.$(BUILD_TARGET))\
257 $($(source)_LDTOOL) $($(target)_$(source)_LDTOOL)\
258 ,$(eval _TOOLS += $(tool)))
259endef
260define def_tools_target
261$(foreach tool,\
262 $($(target)_TOOL.$(BUILD_TARGET))\
263 $($(target)_TOOL)\
264 $($(target)_CTOOL.$(BUILD_TARGET))\
265 $($(target)_CTOOL)\
266 $($(target)_CXXTOOL.$(BUILD_TARGET))\
267 $($(target)_CXXTOOL)\
268 $($(target)_ASTOOL.$(BUILD_TARGET))\
269 $($(target)_ASTOOL)\
270 $($(target)_ARTOOL.$(BUILD_TARGET))\
271 $($(target)_ARTOOL)\
272 $($(target)_LDTOOL.$(BUILD_TARGET))\
273 $($(target)_LDTOOL)\
274 ,$(eval _TOOLS += $(tool)))
275$(foreach source, $($(target)_SOURCES) $($(target)_SOURCES.$(BUILD_TARGET)) $($(target)_SOURCES.$(BUILD_MODE)) \
276 , $(eval $(def_tools_target_source)))
277endef
278$(foreach target, $(ALL_TARGETS), $(eval $(def_tools_target)))
279_TOOLS := $(sort $(_TOOLS))
280
281define def_tools_include
282ifndef TOOL_$(tool)
283include $(firstword $(wildcard $(PATH_KBUILD)/tools/$(tool).kmk))
284endif
285endef
286$(foreach tool, $(_TOOLS), $(eval $(def_tools_include)))
287
288
289#
290# Include SDKs
291#
292_SDKS := $(SDKS)
293define def_sdks_target_source
294$(foreach sdk, $($(source)_SDKS) $($(target)_$(source)_SDKS), \
295 $(eval _SDKS += $(sdk)))
296endef
297define def_sdks_target
298$(foreach sdk, $($(target)_SDKS), $(eval _SDKS += $(sdk)))
299$(foreach source, $($(target)_SOURCES) $($(target)_SOURCES.$(BUILD_TARGET)) $($(target)_SOURCES.$(BUILD_MODE))\
300 , $(eval $(def_sdks_target_source)))
301endef
302$(foreach target, $(ALL_TARGETS), $(eval $(def_sdks_target)))
303_SDKS := $(sort $(_SDKS))
304
305define def_sdks_include
306ifndef SDK_$(sdk)
307include $(firstword $(wildcard $(PATH_KBUILD)/sdks/$(sdk).kmk))
308endif
309endef
310$(foreach sdk, $(_SDKS), $(eval $(def_sdk)))
311
312#
313# Object processing.
314#
315
316## Generic macro for processing C, C++ and Assembly sources.
317# @param $(target) Normalized target name.
318# @param $(source) Source file name.
319# @param $(type) Source type. {C,CXX,AS}
320#
321# @remark I've no clue why I've to $(eval ..) everything in this define. MAKE bug?
322# @remark I now have a clue. Have to use $$ if not.
323define def_target_source_c_cpp_asm
324#$ (warning dbg: def_target_source_c_cpp_asm: source='$(source)' target='$(target)' type='$(type)')
325
326$(eval tool:=$(call _SOURCE_TOOL,$(source),$(target),$(type)))
327$(eval outbase := $(call _OBJECT_BASE,$(source),$(target)))
328$(eval PATH_$(target)_$(source) := $(patsubst %/,%,$(dir $(outbase))))
329$(eval dirdep := $(dir $(outbase)).dir_created)
330$(eval defs :=\
331 $(TOOL_$(tool)_DEFS)\
332 $(TOOL_$(tool)_DEFS.$(BUILD_TYPE))\
333 $(TOOL_$(tool)_DEFS.$(BUILD_TARGET))\
334 $(TOOL_$(tool)_DEFS.$(BUILD_TARGET_ARCH))\
335 $(TOOL_$(tool)_DEFS.$(BUILD_TARGET_CPU))\
336 $(TOOL_$(tool)_$(type)DEFS)\
337 $(TOOL_$(tool)_$(type)DEFS.$(BUILD_TYPE))\
338 $(foreach sdk, $(SDKS.$(BUILD_TARGET)) \
339 $(SDKS.$(BUILD_TYPE)) \
340 $(SDKS),\
341 $(SDK_$(sdk)_DEFS)\
342 $(SDK_$(sdk)_DEFS.$(BUILD_TYPE))\
343 $(SDK_$(sdk)_DEFS.$(BUILD_TARGET))\
344 $(SDK_$(sdk)_DEFS.$(BUILD_TARGET_ARCH))\
345 $(SDK_$(sdk)_DEFS.$(BUILD_TARGET_CPU))
346 $(SDK_$(sdk)_$(type)DEFS)\
347 $(SDK_$(sdk)_$(type)DEFS.$(BUILD_TYPE))\
348 $(SDK_$(sdk)_$(type)DEFS.$(BUILD_TARGET))\
349 $(SDK_$(sdk)_$(type)DEFS.$(BUILD_TARGET_ARCH))\
350 $(SDK_$(sdk)_$(type)DEFS.$(BUILD_TARGET_CPU)))\
351 $(DEFS)\
352 $(DEFS.$(BUILD_TYPE))\
353 $(DEFS.$(BUILD_TARGET))\
354 $(DEFS.$(BUILD_TARGET_ARCH))\
355 $(DEFS.$(BUILD_TARGET_CPU))\
356 $($(type)DEFS)\
357 $($(type)DEFS.$(BUILD_TYPE))\
358 $($(type)DEFS.$(BUILD_TARGET))\
359 $($(type)DEFS.$(BUILD_TARGET_ARCH))\
360 $($(type)DEFS.$(BUILD_TARGET_CPU))\
361 $(foreach sdk, $($(target)_SDKS.$(BUILD_TARGET)) \
362 $($(target)_SDKS.$(BUILD_TYPE)) \
363 $($(target)_SDKS),\
364 $(SDK_$(sdk)_DEFS)\
365 $(SDK_$(sdk)_DEFS.$(BUILD_TYPE))\
366 $(SDK_$(sdk)_DEFS.$(BUILD_TARGET))\
367 $(SDK_$(sdk)_DEFS.$(BUILD_TARGET_ARCH))\
368 $(SDK_$(sdk)_DEFS.$(BUILD_TARGET_CPU))
369 $(SDK_$(sdk)_$(type)DEFS)\
370 $(SDK_$(sdk)_$(type)DEFS.$(BUILD_TYPE))\
371 $(SDK_$(sdk)_$(type)DEFS.$(BUILD_TARGET))\
372 $(SDK_$(sdk)_$(type)DEFS.$(BUILD_TARGET_ARCH))\
373 $(SDK_$(sdk)_$(type)DEFS.$(BUILD_TARGET_CPU)))\
374 $($(target)_DEFS)\
375 $($(target)_DEFS.$(BUILD_TYPE))\
376 $($(target)_DEFS.$(BUILD_TARGET))\
377 $($(target)_DEFS.$(BUILD_TARGET_ARCH))\
378 $($(target)_DEFS.$(BUILD_TARGET_CPU))\
379 $($(target)_$(type)DEFS)\
380 $($(target)_$(type)DEFS.$(BUILD_TYPE))\
381 $($(target)_$(type)DEFS.$(BUILD_TARGET))\
382 $($(target)_$(type)DEFS.$(BUILD_TARGET_ARCH))\
383 $($(target)_$(type)DEFS.$(BUILD_TARGET_CPU))\
384 $(foreach sdk, $($(source)_SDKS.$(BUILD_TARGET)) \
385 $($(source)_SDKS.$(BUILD_TYPE)) \
386 $($(source)_SDKS),\
387 $(SDK_$(sdk)_DEFS)\
388 $(SDK_$(sdk)_DEFS.$(BUILD_TYPE))\
389 $(SDK_$(sdk)_DEFS.$(BUILD_TARGET))\
390 $(SDK_$(sdk)_DEFS.$(BUILD_TARGET_ARCH))\
391 $(SDK_$(sdk)_DEFS.$(BUILD_TARGET_CPU))
392 $(SDK_$(sdk)_$(type)DEFS)\
393 $(SDK_$(sdk)_$(type)DEFS.$(BUILD_TYPE))\
394 $(SDK_$(sdk)_$(type)DEFS.$(BUILD_TARGET))\
395 $(SDK_$(sdk)_$(type)DEFS.$(BUILD_TARGET_ARCH))\
396 $(SDK_$(sdk)_$(type)DEFS.$(BUILD_TARGET_CPU)))\
397 $($(source)_DEFS)\
398 $($(source)_DEFS.$(BUILD_TYPE))\
399 $($(source)_DEFS.$(BUILD_TARGET))\
400 $($(source)_DEFS.$(BUILD_TARGET_ARCH))\
401 $($(source)_DEFS.$(BUILD_TARGET_CPU))\
402 $($(source)_$(type)DEFS)\
403 $($(source)_$(type)DEFS.$(BUILD_TYPE))\
404 $($(source)_$(type)DEFS.$(BUILD_TARGET))\
405 $($(source)_$(type)DEFS.$(BUILD_TARGET_ARCH))\
406 $($(source)_$(type)DEFS.$(BUILD_TARGET_CPU))\
407 $(foreach sdk, $($(target)_$(source)_SDKS.$(BUILD_TARGET)) \
408 $($(target)_$(source)_SDKS.$(BUILD_TYPE)) \
409 $($(target)_$(source)_SDKS),\
410 $(SDK_$(sdk)_DEFS)\
411 $(SDK_$(sdk)_DEFS.$(BUILD_TYPE))\
412 $(SDK_$(sdk)_DEFS.$(BUILD_TARGET))\
413 $(SDK_$(sdk)_DEFS.$(BUILD_TARGET_ARCH))\
414 $(SDK_$(sdk)_DEFS.$(BUILD_TARGET_CPU))
415 $(SDK_$(sdk)_$(type)DEFS)\
416 $(SDK_$(sdk)_$(type)DEFS.$(BUILD_TYPE))\
417 $(SDK_$(sdk)_$(type)DEFS.$(BUILD_TARGET))\
418 $(SDK_$(sdk)_$(type)DEFS.$(BUILD_TARGET_ARCH))\
419 $(SDK_$(sdk)_$(type)DEFS.$(BUILD_TARGET_CPU)))\
420 $($(target)_$(source)_DEFS)\
421 $($(target)_$(source)_DEFS.$(BUILD_TYPE))\
422 $($(target)_$(source)_DEFS.$(BUILD_TARGET))\
423 $($(target)_$(source)_DEFS.$(BUILD_TARGET_ARCH))\
424 $($(target)_$(source)_DEFS.$(BUILD_TARGET_CPU))\
425 $($(target)_$(source)_$(type)DEFS)\
426 $($(target)_$(source)_$(type)DEFS.$(BUILD_TYPE))\
427 $($(target)_$(source)_$(type)DEFS.$(BUILD_TARGET))\
428 $($(target)_$(source)_$(type)DEFS.$(BUILD_TARGET_ARCH))\
429 $($(target)_$(source)_$(type)DEFS.$(BUILD_TARGET_CPU))\
430 )
431$(eval incs :=\
432 $($(target)_$(source)_$(type)INCS.$(BUILD_TARGET_CPU))\
433 $($(target)_$(source)_$(type)INCS.$(BUILD_TARGET_ARCH))\
434 $($(target)_$(source)_$(type)INCS.$(BUILD_TARGET))\
435 $($(target)_$(source)_$(type)INCS.$(BUILD_TYPE))\
436 $($(target)_$(source)_$(type)INCS)\
437 $($(target)_$(source)_INCS.$(BUILD_TARGET_CPU))\
438 $($(target)_$(source)_INCS.$(BUILD_TARGET_ARCH))\
439 $($(target)_$(source)_INCS.$(BUILD_TARGET))\
440 $($(target)_$(source)_INCS.$(BUILD_TYPE))\
441 $($(target)_$(source)_INCS)\
442 $(foreach sdk, $($(target)_$(source)_SDKS.$(BUILD_TARGET)) \
443 $($(target)_$(source)_SDKS.$(BUILD_TYPE)) \
444 $($(target)_$(source)_SDKS),
445 $(SDK_$(sdk)_$(type)INCS.$(BUILD_TARGET_CPU))\
446 $(SDK_$(sdk)_$(type)INCS.$(BUILD_TARGET_ARCH))\
447 $(SDK_$(sdk)_$(type)INCS.$(BUILD_TARGET))\
448 $(SDK_$(sdk)_$(type)INCS.$(BUILD_TYPE))\
449 $(SDK_$(sdk)_$(type)INCS)\
450 $(SDK_$(sdk)_INCS.$(BUILD_TARGET_CPU))\
451 $(SDK_$(sdk)_INCS.$(BUILD_TARGET_ARCH))\
452 $(SDK_$(sdk)_INCS.$(BUILD_TARGET))\
453 $(SDK_$(sdk)_INCS.$(BUILD_TYPE))\
454 $(SDK_$(sdk)_INCS))\
455 $($(source)_$(type)INCS.$(BUILD_TARGET_CPU))\
456 $($(source)_$(type)INCS.$(BUILD_TARGET_ARCH))\
457 $($(source)_$(type)INCS.$(BUILD_TARGET))\
458 $($(source)_$(type)INCS.$(BUILD_TYPE))\
459 $($(source)_$(type)INCS)\
460 $($(source)_INCS.$(BUILD_TARGET_CPU))\
461 $($(source)_INCS.$(BUILD_TARGET_ARCH))\
462 $($(source)_INCS.$(BUILD_TARGET))\
463 $($(source)_INCS.$(BUILD_TYPE))\
464 $($(source)_INCS)\
465 $(foreach sdk, $($(source)_SDKS.$(BUILD_TARGET)) \
466 $($(source)_SDKS.$(BUILD_TYPE)) \
467 $($(source)_SDKS),\
468 $(SDK_$(sdk)_$(type)INCS.$(BUILD_TARGET_CPU))\
469 $(SDK_$(sdk)_$(type)INCS.$(BUILD_TARGET_ARCH))\
470 $(SDK_$(sdk)_$(type)INCS.$(BUILD_TARGET))\
471 $(SDK_$(sdk)_$(type)INCS.$(BUILD_TYPE))\
472 $(SDK_$(sdk)_$(type)INCS)\
473 $(SDK_$(sdk)_INCS.$(BUILD_TARGET_CPU))\
474 $(SDK_$(sdk)_INCS.$(BUILD_TARGET_ARCH))\
475 $(SDK_$(sdk)_INCS.$(BUILD_TARGET))\
476 $(SDK_$(sdk)_INCS.$(BUILD_TYPE))\
477 $(SDK_$(sdk)_INCS))\
478 $($(target)_$(type)INCS.$(BUILD_TARGET_CPU))\
479 $($(target)_$(type)INCS.$(BUILD_TARGET_ARCH))\
480 $($(target)_$(type)INCS.$(BUILD_TARGET))\
481 $($(target)_$(type)INCS.$(BUILD_TYPE))\
482 $($(target)_$(type)INCS)\
483 $($(target)_INCS.$(BUILD_TARGET_CPU))\
484 $($(target)_INCS.$(BUILD_TARGET_ARCH))\
485 $($(target)_INCS.$(BUILD_TARGET))\
486 $($(target)_INCS.$(BUILD_TYPE))\
487 $($(target)_INCS)\
488 $(foreach sdk, $($(target)_SDKS.$(BUILD_TARGET)) \
489 $($(target)_SDKS.$(BUILD_TYPE)) \
490 $($(target)_SDKS),\
491 $(SDK_$(sdk)_$(type)INCS.$(BUILD_TARGET_CPU))\
492 $(SDK_$(sdk)_$(type)INCS.$(BUILD_TARGET_ARCH))\
493 $(SDK_$(sdk)_$(type)INCS.$(BUILD_TARGET))\
494 $(SDK_$(sdk)_$(type)INCS.$(BUILD_TYPE))\
495 $(SDK_$(sdk)_$(type)INCS)\
496 $(SDK_$(sdk)_INCS.$(BUILD_TARGET_CPU))\
497 $(SDK_$(sdk)_INCS.$(BUILD_TARGET_ARCH))\
498 $(SDK_$(sdk)_INCS.$(BUILD_TARGET))\
499 $(SDK_$(sdk)_INCS.$(BUILD_TYPE))\
500 $(SDK_$(sdk)_INCS))\
501 $(INCS.$(BUILD_TARGET_CPU))\
502 $(INCS.$(BUILD_TARGET_ARCH))\
503 $(INCS.$(BUILD_TARGET))\
504 $(INCS.$(BUILD_TYPE))\
505 $(INCS)\
506 $(foreach sdk, $(SDKS.$(BUILD_TARGET)) \
507 $(SDKS.$(BUILD_TYPE)) \
508 $(SDKS),\
509 $(SDK_$(sdk)_$(type)INCS.$(BUILD_TARGET_CPU))\
510 $(SDK_$(sdk)_$(type)INCS.$(BUILD_TARGET_ARCH))\
511 $(SDK_$(sdk)_$(type)INCS.$(BUILD_TARGET))\
512 $(SDK_$(sdk)_$(type)INCS.$(BUILD_TYPE))\
513 $(SDK_$(sdk)_$(type)INCS)\
514 $(SDK_$(sdk)_INCS.$(BUILD_TARGET_CPU))\
515 $(SDK_$(sdk)_INCS.$(BUILD_TARGET_ARCH))\
516 $(SDK_$(sdk)_INCS.$(BUILD_TARGET))\
517 $(SDK_$(sdk)_INCS.$(BUILD_TYPE))\
518 $(SDK_$(sdk)_INCS))\
519 $(TOOL_$(tool)_$(type)INCS.$(BUILD_TARGET_CPU))\
520 $(TOOL_$(tool)_$(type)INCS.$(BUILD_TARGET_ARCH))\
521 $(TOOL_$(tool)_$(type)INCS.$(BUILD_TARGET))\
522 $(TOOL_$(tool)_$(type)INCS.$(BUILD_TYPE))\
523 $(TOOL_$(tool)_$(type)INCS)\
524 )
525$(eval flags :=\
526 $(TOOL_$(tool)_$(type)FLAGS)\
527 $(TOOL_$(tool)_$(type)FLAGS.$(BUILD_TYPE))\
528 $(TOOL_$(tool)_$(type)FLAGS.$(BUILD_TARGET))\
529 $(TOOL_$(tool)_$(type)FLAGS.$(BUILD_TARGET_ARCH))\
530 $(TOOL_$(tool)_$(type)FLAGS.$(BUILD_TARGET_CPU))\
531 $($(type)FLAGS)\
532 $($(type)FLAGS.$(BUILD_TYPE))\
533 $($(type)FLAGS.$(BUILD_TARGET))\
534 $($(type)FLAGS.$(BUILD_TARGET_ARCH))\
535 $($(type)FLAGS.$(BUILD_TARGET_CPU))\
536 $($(target)_$(type)FLAGS)\
537 $($(target)_$(type)FLAGS.$(BUILD_TYPE))\
538 $($(target)_$(type)FLAGS.$(BUILD_TARGET))\
539 $($(target)_$(type)FLAGS.$(BUILD_TARGET_ARCH))\
540 $($(target)_$(type)FLAGS.$(BUILD_TARGET_CPU))\
541 $($(source)_$(type)FLAGS)\
542 $($(source)_$(type)FLAGS.$(BUILD_TYPE))\
543 $($(source)_$(type)FLAGS.$(BUILD_TARGET))\
544 $($(source)_$(type)FLAGS.$(BUILD_TARGET_ARCH))\
545 $($(source)_$(type)FLAGS.$(BUILD_TARGET_CPU))\
546 $($(target)_$(source)_$(type)FLAGS)\
547 $($(target)_$(source)_$(type)FLAGS.$(BUILD_TYPE))\
548 $($(target)_$(source)_$(type)FLAGS.$(BUILD_TARGET))\
549 $($(target)_$(source)_$(type)FLAGS.$(BUILD_TARGET_ARCH))\
550 $($(target)_$(source)_$(type)FLAGS.$(BUILD_TARGET_CPU))\
551 )
552$(eval objsuff := $(firstword \
553 $($(target)_$(source)_OBJSUFF.$(BUILD_TARGET))\
554 $($(target)_$(source)_OBJSUFF)\
555 $($(source)_OBJSUFF.$(BUILD_TARGET))\
556 $($(source)_OBJSUFF)\
557 $($(target)_OBJSUFF.$(BUILD_TARGET))\
558 $($(target)_OBJSUFF)\
559 $(TOOL_$(tool)_$(type)OBJSUFF.$(BUILD_TARGET))\
560 $(TOOL_$(tool)_$(type)OBJSUFF)\
561 $(SUFF_OBJ)\
562 ))
563$(eval obj := $(outbase)$(objsuff))
564$(eval dep := $(outbase)$(SUFF_DEP))
565
566#$ (warning dbg: target=$(target) source=$(source) tool=$(tool) obj=$(obj) dep=$(dep) flags=$(flags) defs=$(defs) incs=$(incs) dirdep=$(dirdep) outbase=$(outbase) objsuff=$(objsuff))
567ifndef TOOL_$(tool)_COMPILE_$(type)
568$$(warning kBuild: TOOL_$(tool)_COMPILE_$(type) is not defined. source=$(source) target=$(target) )
569$$(warning kBuild: tools: \
570 1 $($(target)_$(source)_$(type)TOOL.$(BUILD_TARGET)) \
571 2 $($(target)_$(source)_$(type)TOOL) \
572 3 $($(target)_$(source)_TOOL.$(BUILD_TARGET)) \
573 4 $($(target)_$(source)_TOOL) \
574 5 $($(target)_$(type)TOOL.$(BUILD_TARGET)) \
575 6 $($(target)_$(type)TOOL) \
576 7 $($(target)_TOOL.$(BUILD_TARGET)) \
577 8 $($(target)_TOOL) \
578 9 $($(source)_$(type)TOOL.$(BUILD_TARGET)) \
579 10 $($(source)_$(type)TOOL) \
580 11 $($(source)_TOOL.$(BUILD_TARGET)) \
581 12 $($(source)_TOOL) \
582 13 $($(type)TOOL.$(BUILD_TARGET)) \
583 14 $($(type)TOOL) \
584 15 $(TOOL.$(BUILD_TARGET)) \
585 16 $(TOOL) )
586endif
587$(eval $(TOOL_$(tool)_COMPILE_$(type)))
588
589$(eval _OBJS_$(target) += $(obj))
590$(eval _DEPFILES += $(dep))
591
592endef
593
594## Generic macro for processing all target sources.
595# @param $(target) Normalized target name.
596define def_target_sources
597#$ (warning def_target_sources)
598# C sources
599$(foreach type,C,$(foreach source, $(filter %.c, $($(target)_SOURCES) $($(target)_SOURCES.$(BUILD_TARGET)) $($(target)_SOURCES.$(BUILD_MODE)))\
600 ,$(eval $(def_target_source_c_cpp_asm)) ))
601
602# C++ sources
603$(foreach type,CXX,$(foreach source, $(filter %.cpp %.cxx %.xx, $($(target)_SOURCES) $($(target)_SOURCES.$(BUILD_TARGET)) $($(target)_SOURCES.$(BUILD_MODE)))\
604 ,$(eval $(def_target_source_c_cpp_asm)) ))
605
606# ASM sources
607$(foreach type,AS,$(foreach source, $(filter %.asm %.s %.S, $($(target)_SOURCES) $($(target)_SOURCES.$(BUILD_TARGET)) $($(target)_SOURCES.$(BUILD_MODE)))\
608 ,$(eval $(def_target_source_c_cpp_asm)) ))
609endef
610
611
612#
613# LIBRARIES
614#
615
616## Library (one).
617# @param $(target) Normalized library (target) name.
618define def_lib
619# source -> object
620$(eval $(def_target_sources))
621
622# library
623$(eval tool := $(call _TARGET_TOOL,$(target),AR))
624ifeq ($(tool),)
625$$(error kBuild: Library target $(target) doesn't have a tool defined!)
626endif
627## @todo prefix
628$(eval outbase := $(call _TARGET_BASE,$(target),$(target)))
629$(eval PATH_$(target) := $(patsubst %/,%,$(dir $(outbase))))
630$(eval lib := $(outbase)$(libsuff))
631$(eval flags :=\
632 $(TOOL_$(tool)_ARFLAGS)\
633 $(TOOL_$(tool)_ARFLAGS.$(BUILD_TYPE))\
634 $(ARFLAGS)\
635 $(ARFLAGS.$(BUILD_TYPE))\
636 $($(target)_ARFLAGS)\
637 $($(target)_ARFLAGS.$(BUILD_TYPE))\
638 )
639$(eval libsuff := $(firstword\
640 $($(target)_LIBSUFF.$(BUILD_TARGET))\
641 $($(target)_LIBSUFF)\
642 $(TOOL_$(tool)_ARLIBSUFF.$(BUILD_TARGET))\
643 $(TOOL_$(tool)_ARLIBSUFF)\
644 $(SUFF_LIB)\
645))
646$(eval objs = $(_OBJS_$(target)))
647$(eval othersrc := $(filter-out %.c %.cpp %.cxx %.cc %.s %.S %.asm,$($(target)_SOURCES) $($(target)_SOURCES.$(BUILD_TARGET)) $($(target)_SOURCES.$(BUILD_MODE))))
648$(eval dirdep := $(dir $(lib)).dir_created)
649## @todo fix dependencies on makefiles an such
650$(eval deps := )
651
652$(eval $(TOOL_$(tool)_LINK_LIBRARY))
653
654_OBJS += $(_OBJS_$(target))
655_LIBS += $(lib)
656_OUT_FILES += $(lib)
657endef
658
659# Process libraries
660$(foreach target, $(LIBRARIES), $(eval $(def_lib)))
661
662
663
664#
665# PROGRAMS
666#
667
668## Program (one).
669# @param $(target) Normalized target (program) name.
670define def_program
671# source -> object
672$(eval $(def_target_sources))
673
674# library
675$(eval tool := $(call _TARGET_TOOL,$(target),LD))
676$(eval outbase := $(call _TARGET_BASE,$(target),$(target)))
677$(eval PATH_$(target) := $(patsubst %/,%,$(dir $(outbase))))
678$(eval exesuff := $(firstword $($(target)_EXESUFF) $($(target)_EXESUFF) $(TOOL_$(tool)_LDEXESUFF) $(SUFF_EXE)))
679$(eval exe := $(outbase)$(exesuff))
680$(eval objs = $(_OBJS_$(target)))
681$(eval flags :=\
682 $(TOOL_$(tool)_LDFLAGS)\
683 $(TOOL_$(tool)_LDFLAGS.$(BUILD_TYPE))\
684 $(TOOL_$(tool)_LDFLAGS.$(BUILD_TARGET))\
685 $(TOOL_$(tool)_LDFLAGS.$(BUILD_TARGET_ARCH))\
686 $(TOOL_$(tool)_LDFLAGS.$(BUILD_TARGET_CPU))\
687 $(LDFLAGS)\
688 $(LDFLAGS.$(BUILD_TYPE))\
689 $(LDFLAGS.$(BUILD_TARGET))\
690 $(LDFLAGS.$(BUILD_TARGET_ARCH))\
691 $(LDFLAGS.$(BUILD_TARGET_CPU))\
692 $($(target)_LDFLAGS)\
693 $($(target)_LDFLAGS.$(BUILD_TYPE))\
694 $($(target)_LDFLAGS.$(BUILD_TARGET))\
695 $($(target)_LDFLAGS.$(BUILD_TARGET_ARCH))\
696 $($(target)_LDFLAGS.$(BUILD_TARGET_CPU))\
697)
698$(eval libs :=\
699 $($(target)_LIBS.$(BUILD_TARGET_CPU))\
700 $($(target)_LIBS.$(BUILD_TARGET_ARCH))\
701 $($(target)_LIBS.$(BUILD_TARGET))\
702 $($(target)_LIBS.$(BUILD_TYPE))\
703 $($(target)_LIBS)\
704 $(LIBS.$(BUILD_TARGET_CPU))\
705 $(LIBS.$(BUILD_TARGET_ARCH))\
706 $(LIBS.$(BUILD_TARGET))\
707 $(LIBS.$(BUILD_TYPE))\
708 $(LIBS)\
709 $(TOOL_$(tool)_LIBS.$(BUILD_TYPE))\
710 $(TOOL_$(tool)_LIBS)\
711)
712$(eval libpath :=\
713 $($(target)_LIBPATH.$(BUILD_TARGET_CPU))\
714 $($(target)_LIBPATH.$(BUILD_TARGET_ARCH))\
715 $($(target)_LIBPATH.$(BUILD_TARGET))\
716 $($(target)_LIBPATH.$(BUILD_TYPE))\
717 $($(target)_LIBPATH)\
718 $(LIBPATH.$(BUILD_TARGET_CPU))\
719 $(LIBPATH.$(BUILD_TARGET_ARCH))\
720 $(LIBPATH.$(BUILD_TARGET))\
721 $(LIBPATH.$(BUILD_TYPE))\
722 $(LIBPATH)\
723 $(TOOL_$(tool)_LIBPATH.$(BUILD_TARGET_CPU))\
724 $(TOOL_$(tool)_LIBPATH.$(BUILD_TARGET_ARCH))\
725 $(TOOL_$(tool)_LIBPATH.$(BUILD_TARGET))\
726 $(TOOL_$(tool)_LIBPATH.$(BUILD_TYPE))\
727 $(TOOL_$(tool)_LIBPATH)\
728)
729$(eval dirdep := $(dir $(exe)).dir_created)
730## @todo fix dependencies
731$(eval deps := )
732#
733$(eval deffile := $(strip $(firstword
734 $($(target)_DEFFILE.$(BUILD_TARGET).$(BUILD_TYPE))\
735 $($(target)_DEFFILE.$(BUILD_TARGET))\
736 $($(target)_DEFFILE.$(BUILD_TYPE))\
737 $($(target)_DEFFILE)\
738 $(DEFFILE.$(BUILD_TARGET).$(BUILD_TYPE))\
739 $(DEFFILE.$(BUILD_TARGET))\
740 $(DEFFILE.$(BUILD_TYPE))\
741 $(DEFFILE)\
742)))
743$(eval custom_pre := $(strip $(firstword
744 $($(target)_CUSTOM_PRE.$(BUILD_TARGET).$(BUILD_TYPE))\
745 $($(target)_CUSTOM_PRE.$(BUILD_TARGET))\
746 $($(target)_CUSTOM_PRE.$(BUILD_TYPE))\
747 $($(target)_CUSTOM_PRE)\
748 $(CUSTOM_PRE.$(BUILD_TARGET).$(BUILD_TYPE))\
749 $(CUSTOM_PRE.$(BUILD_TARGET))\
750 $(CUSTOM_PRE.$(BUILD_TYPE))\
751 $(CUSTOM_PRE)\
752)))
753$(eval custom_post := $(strip $(firstword
754 $($(target)_CUSTOM_POST.$(BUILD_TARGET).$(BUILD_TYPE))\
755 $($(target)_CUSTOM_POST.$(BUILD_TARGET))\
756 $($(target)_CUSTOM_POST.$(BUILD_TYPE))\
757 $($(target)_CUSTOM_POST)\
758 $(CUSTOM_POST.$(BUILD_TARGET).$(BUILD_TYPE))\
759 $(CUSTOM_POST.$(BUILD_TARGET))\
760 $(CUSTOM_POST.$(BUILD_TYPE))\
761 $(CUSTOM_POST)\
762)))
763$(eval othersrc := $(filter-out %.c %.cpp %.cxx %.cc %.s %.S %.asm,$($(target)_SOURCES) $($(target)_SOURCES.$(BUILD_TARGET)) $($(target)_SOURCES.$(BUILD_MODE))))
764
765$(eval $(TOOL_$(tool)_LINK_PROGRAM))
766
767_OBJS += $(_OBJS_$(target))
768_EXES += $(exe)
769_OUT_FILES += $(exe)
770endef
771
772# Process libraries
773$(foreach target, $(PROGRAMS), $(eval $(def_program)))
774
775
776
777#
778# DLLS
779#
780
781
782
783#
784# SYSMODS
785#
786
787## System moduler (one).
788# @param $(target) Normalized target (program) name.
789define def_sysmod
790# source -> object
791$(eval $(def_target_sources))
792
793# sysmod
794$(eval tool := $(call _TARGET_TOOL,$(target),LD))
795$(eval outbase := $(call _TARGET_BASE,$(target),$(target)))
796$(eval PATH_$(target) := $(patsubst %/,%,$(dir $(outbase))))
797$(eval syssuff := $(firstword $($(target)_SYSSUFF) $($(target)_SYSSUFF) $(TOOL_$(tool)_LDSYSSUFF) $(SUFF_SYS)))
798$(eval sys := $(outbase)$(syssuff))
799$(eval objs = $(_OBJS_$(target)))
800$(eval flags :=\
801 $(TOOL_$(tool)_LDFLAGS)\
802 $(TOOL_$(tool)_LDFLAGS.$(BUILD_TYPE))\
803 $(TOOL_$(tool)_LDFLAGS.$(BUILD_TARGET))\
804 $(TOOL_$(tool)_LDFLAGS.$(BUILD_TARGET_ARCH))\
805 $(TOOL_$(tool)_LDFLAGS.$(BUILD_TARGET_CPU))\
806 $(LDFLAGS)\
807 $(LDFLAGS.$(BUILD_TYPE))\
808 $(LDFLAGS.$(BUILD_TARGET))\
809 $(LDFLAGS.$(BUILD_TARGET_ARCH))\
810 $(LDFLAGS.$(BUILD_TARGET_CPU))\
811 $($(target)_LDFLAGS)\
812 $($(target)_LDFLAGS.$(BUILD_TYPE))\
813 $($(target)_LDFLAGS.$(BUILD_TARGET))\
814 $($(target)_LDFLAGS.$(BUILD_TARGET_ARCH))\
815 $($(target)_LDFLAGS.$(BUILD_TARGET_CPU))\
816)
817$(eval libs :=\
818 $($(target)_LIBS.$(BUILD_TARGET_CPU))\
819 $($(target)_LIBS.$(BUILD_TARGET_ARCH))\
820 $($(target)_LIBS.$(BUILD_TARGET))\
821 $($(target)_LIBS.$(BUILD_TYPE))\
822 $($(target)_LIBS)\
823 $(LIBS.$(BUILD_TARGET_CPU))\
824 $(LIBS.$(BUILD_TARGET_ARCH))\
825 $(LIBS.$(BUILD_TARGET))\
826 $(LIBS.$(BUILD_TYPE))\
827 $(LIBS)\
828 $(TOOL_$(tool)_LIBS.$(BUILD_TYPE))\
829 $(TOOL_$(tool)_LIBS)\
830)
831$(eval libpath :=\
832 $($(target)_LIBPATH.$(BUILD_TARGET_CPU))\
833 $($(target)_LIBPATH.$(BUILD_TARGET_ARCH))\
834 $($(target)_LIBPATH.$(BUILD_TARGET))\
835 $($(target)_LIBPATH.$(BUILD_TYPE))\
836 $($(target)_LIBPATH)\
837 $(LIBPATH.$(BUILD_TARGET_CPU))\
838 $(LIBPATH.$(BUILD_TARGET_ARCH))\
839 $(LIBPATH.$(BUILD_TARGET))\
840 $(LIBPATH.$(BUILD_TYPE))\
841 $(LIBPATH)\
842 $(TOOL_$(tool)_LIBPATH.$(BUILD_TARGET_CPU))\
843 $(TOOL_$(tool)_LIBPATH.$(BUILD_TARGET_ARCH))\
844 $(TOOL_$(tool)_LIBPATH.$(BUILD_TARGET))\
845 $(TOOL_$(tool)_LIBPATH.$(BUILD_TYPE))\
846 $(TOOL_$(tool)_LIBPATH)\
847)
848$(eval dirdep := $(dir $(sys)).dir_created)
849## @todo fix dependencies
850$(eval deps := )
851#
852$(eval deffile := $(strip $(firstword
853 $($(target)_DEFFILE.$(BUILD_TARGET).$(BUILD_TYPE))\
854 $($(target)_DEFFILE.$(BUILD_TARGET))\
855 $($(target)_DEFFILE.$(BUILD_TYPE))\
856 $($(target)_DEFFILE)\
857 $(DEFFILE.$(BUILD_TARGET).$(BUILD_TYPE))\
858 $(DEFFILE.$(BUILD_TARGET))\
859 $(DEFFILE.$(BUILD_TYPE))\
860 $(DEFFILE)\
861)))
862$(eval custom_pre := $(strip $(firstword
863 $($(target)_CUSTOM_PRE.$(BUILD_TARGET).$(BUILD_TYPE))\
864 $($(target)_CUSTOM_PRE.$(BUILD_TARGET))\
865 $($(target)_CUSTOM_PRE.$(BUILD_TYPE))\
866 $($(target)_CUSTOM_PRE)\
867 $(CUSTOM_PRE.$(BUILD_TARGET).$(BUILD_TYPE))\
868 $(CUSTOM_PRE.$(BUILD_TARGET))\
869 $(CUSTOM_PRE.$(BUILD_TYPE))\
870 $(CUSTOM_PRE)\
871)))
872$(eval custom_post := $(strip $(firstword
873 $($(target)_CUSTOM_POST.$(BUILD_TARGET).$(BUILD_TYPE))\
874 $($(target)_CUSTOM_POST.$(BUILD_TARGET))\
875 $($(target)_CUSTOM_POST.$(BUILD_TYPE))\
876 $($(target)_CUSTOM_POST)\
877 $(CUSTOM_POST.$(BUILD_TARGET).$(BUILD_TYPE))\
878 $(CUSTOM_POST.$(BUILD_TARGET))\
879 $(CUSTOM_POST.$(BUILD_TYPE))\
880 $(CUSTOM_POST)\
881)))
882$(eval othersrc := $(filter-out %.c %.cpp %.cxx %.cc %.s %.S %.asm,$($(target)_SOURCES) $($(target)_SOURCES.$(BUILD_TARGET)) $($(target)_SOURCES.$(BUILD_MODE))))
883
884ifndef TOOL_$(tool)_LINK_SYSMOD
885$$(warning kBuild: TOOL_$(tool)_LINK_SYSMOD is not defined. target=$(target) )
886$$(warning kBuild: tools: \
887 1 $($(target)_$(source)TOOL.$(BUILD_TARGET)) \
888 2 $($(target)_$(source)TOOL) \
889 3 $($(target)_TOOL.$(BUILD_TARGET)) \
890 4 $($(target)_TOOL) \
891 5 $($(source)TOOL) \
892 6 $($(source)TOOL.$(BUILD_TARGET)) \
893 7 $(TOOL.$(BUILD_TARGET)) \
894 8 $(TOOL) )
895endif
896
897$(eval $(TOOL_$(tool)_LINK_SYSMOD))
898
899_OBJS += $(_OBJS_$(target))
900_SYSMODS += $(sys)
901_OUT_FILES += $(sys)
902endef
903
904# Process libraries
905$(foreach target, $(SYSMODS), $(eval $(def_sysmod)))
906
907
908
909#
910# OTHERS
911#
912
913
914
915#
916# DOCS
917#
918
919
920#
921# Directories.
922#
923_OUTPUT_FILES := $(_OBJS) $(_LIBS) $(_EXES) $(_DLLS) $(_SYSMODS)
924_DIRFILES := $(sort $(addsuffix /.dir_created,$(_DIRS)) $(addsuffix .dir_created,$(dir $(_OUTPUT_FILES))))
925
926define def_createdir
927$(dirfile):
928 $(call MSG_Ltarget,Creating directory $$(@D))
929 $(MKDIR) -p $$(@D)
930 @echo dir_created > $$@
931endef
932
933$(foreach dirfile,$(_DIRFILES),$(eval $(def_createdir)))
934
935
936#
937# Include dependency files.
938#
939$(foreach dep,$(wildcard $(_DEPFILES)),$(eval include $(dep)))
940
941
942#
943# PASSES (including directory and makefile walking)
944#
945# Do all the default passes if it's unspecified.
946
947#PASSES ?= needed libraries binaries others publish
948PASSES ?= libraries binaries
949
950## Proritized list of the default makefile when walking subdirectories.
951# The user can overload this list.
952DEFAULT_MAKEFILE ?= Makefile.kmk makefile.kmk Makefile makefile
953
954## Subdir
955# @param $(pass) Lowercase pass name.
956# @param $(PASS) Uppercase pass name.
957# @param $(subdir) Subdirectory
958# @param $(tag) tag to attach to the rule name.
959define def_pass_subdir
960pass_$(pass)$(tag)::
961 $(QUIET)$$(MAKE) -C $(subdir) -f $$(notdir $$(firstword $$(wildcard $$(addprefix $(subdir)/,$$(DEFAULT_MAKEFILE))))) pass_$(pass)
962endef
963
964## Submakefile
965# @param $(pass) Lowercase pass name.
966# @param $(PASS) Uppercase pass name.
967# @param $(makefile) Makefile.
968# @param $(tag) tag to attach to the rule name.
969define def_pass_makefile
970pass_$(pass)$(tag)::
971 $(QUIET)$$(MAKE) -C $(patsubst %/,%,$(dir $(makefile))) -f $(notdir $(makefile)) pass_$(pass)
972endef
973
974
975## Execute a pass.
976# @param $(pass) Lowercase pass name.
977# @param $(PASS) Uppercase pass name.
978define def_pass
979$(eval SUBDIRS_$(PASS) ?= $(SUBDIRS))
980$(eval SUBDIRS_AFTER_$(PASS) ?= $(SUBDIRS_AFTER))
981$(eval MAKEFILES_BEFORE_$(PASS) ?= $(MAKEFILES_BEFORE))
982$(eval MAKEFILES_AFTER_$(PASS) ?= $(MAKEFILES_AFTER))
983
984$(eval tag:=_before)
985$(foreach subdir,$(SUBDIRS_$(PASS)),$(eval $(def_pass_subdir)))
986$(foreach makefile,$(MAKEFILES_BEFORE_$(PASS)),$(eval $(def_pass_makefile)))
987
988$(eval tag:=_after)
989$(foreach subdir,$(SUBDIRS_AFTER_$(PASS)),$(eval $(def_pass_subdir)))
990$(foreach makefile,$(MAKEFILES_AFTER_$(PASS)),$(eval $(def_pass_makefile)))
991
992.NOTPARALLEL: pass_$(pass)_before pass_$(pass)_after
993.PHONY: pass_$(pass) pass_$(pass)_before pass_$(pass)_doit pass_$(pass)_after
994pass_$(pass): \
995 pass_$(pass)_before \
996 pass_$(pass)_doit \
997 pass_$(pass)_after
998
999endef
1000
1001
1002## PASS: needed
1003# This pass builds targets which are required for building the rest.
1004pass_needed_doit: $(_NEEDEDS)
1005pass := needed
1006PASS := NEEDED
1007$(eval $(def_pass))
1008
1009## PASS: libraries
1010# This pass builds library targets.
1011pass_libraries_doit: $(_LIBS) $(_IMPORT_LIBS) $(_OTHER_LIBRARIES)
1012pass := libraries
1013PASS := LIBRARIES
1014$(eval $(def_pass))
1015
1016## PASS: binaries
1017# This pass builds binary targets, i.e. programs, dlls, system modules and stuff.
1018pass_binaries_doit: $(_DLLS) $(_EXES) $(_SYSMODS) $(_OTHER_BINARIES)
1019pass := binaries
1020PASS := BINARIES
1021$(eval $(def_pass))
1022
1023## PASS: others
1024# This pass builds other targets.
1025pass_others_doit: $(_OTHERS)
1026pass := others
1027PASS := OTHERS
1028$(eval $(def_pass))
1029
1030## PASS: publish
1031# This pass installs the built entities to a sandbox area.
1032pass_publish_doit: publish
1033publish::
1034pass := publish
1035PASS := PUBLISH
1036# $(sort).. not nice.
1037SUBDIRS_PUBLISH ?= $(sort $(SUBDIRS) $(SUBDIRS_LIBRARIES) $(SUBDIRS_BINARIES) $(SUBDIRS_OTHERS))
1038SUBDIRS_AFTER_PUBLISH ?= $(sort $(SUBDIRS_AFTER) $(SUBDIRS_AFTER_LIBRARIES) $(SUBDIRS_AFTER_BINARIES) $(SUBDIRS_AFTER_OTHERS))
1039MAKEFILES_BEFORE_PUBLISH?= $(sort $(MAKEFILES_BEFORE) $(MAKEFILES_BEFORE_LIBRARIES) $(MAKEFILES_BEFORE_BINARIES) $(MAKEFILES_BEFORE_OTHERS))
1040MAKEFILES_AFTER_PUBLISH ?= $(sort $(MAKEFILES_AFTER) $(MAKEFILES_AFTER_LIBRARIES) $(MAKEFILES_AFTER_BINARIES) $(MAKEFILES_AFTER_OTHERS))
1041$(eval $(def_pass))
1042
1043## PASS: packing
1044# This pass processes custom packing rules.
1045pass_packing_doit: packing
1046packing::
1047pass := packing
1048PASS := PACKING
1049$(eval $(def_pass))
1050
1051## PASS: clean
1052# This pass removes all generated files.
1053pass_clean_doit:
1054 $(RM) -f $(_OUT_FILES) $(_OBJS) $(_DEPFILES) $(_DIRFILES)
1055pass := clean
1056PASS := CLEAN
1057$(eval $(def_pass))
1058clean: pass_clean
1059
1060## PASS: nothing
1061# This pass just walks the tree.
1062pass_nothing_doit:
1063 $(call MSG_Ltarget,Did nothing in $(CURDIR))
1064pass := nothing
1065PASS := NOTHING
1066$(eval $(def_pass))
1067nothing: pass_nothing
1068
1069
1070
1071#
1072# THE MAIN RULES
1073#
1074all_recursive: $(foreach pass,$(PASSES),pass_$(pass))
1075
1076rebuild: clean
1077 $(MAKE) -f $(firstword $(MAKEFILE_LIST)) all_recursive
1078
1079
1080# misc shortcuts.
1081target: needed libraries binaries others
1082objects: $(_OBJS)
1083programs: $(_EXES)
1084dlls: $(_DLLS)
1085sysmods: $(_SYSMODS)
1086
1087
1088# end-of-file-content
1089__footer_kmk__ := target
1090endif # __footer_kmk__
Note: See TracBrowser for help on using the repository browser.