source: trunk/kBuild/footer.kmk@ 105

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

Fixed some inheritance issues.

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