source: trunk/kBuild/footer.kmk@ 185

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

Check of a recurring problem with _TEMPLATE containing tabs.

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