source: trunk/kBuild/footer.kmk@ 215

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

.o and .obj editor rules.

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