source: trunk/kBuild/footer.kmk@ 242

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

BLDPROGS must inherit stuff too.

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