source: trunk/kBuild/footer.kmk@ 238

Last change on this file since 238 was 238, checked in by bird, 20 years ago

Incorrect target tool resolving.

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