source: trunk/kBuild/footer.kmk@ 145

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

PATH2 and define PATH before sources are processed.

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