source: trunk/kBuild/footer.kmk@ 984

Last change on this file since 984 was 984, checked in by bird, 18 years ago

enabled the multi target rules. added some PORTME hints.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 85.0 KB
RevLine 
[72]1# $Id: footer.kmk 984 2007-05-28 19:41:38Z bird $
2## @file
3#
4# kBuild - File included at top of makefile.
5#
[782]6# Copyright (c) 2004-2007 knut st. osmundsen <bird-kBuild-spam@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
[353]23# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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.
[984]36_ALL_TARGETS := \
[640]37 $(FETCHES) $(FETCHES.$(BUILD_TARGET)) $(FETCHES.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) \
38 $(PATCHES) $(PATCHES.$(BUILD_TARGET)) $(PATCHES.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) \
[481]39 $(BLDPROGS) $(BLDPROGS.$(BUILD_PLATFORM)) $(BLDPROGS.$(BUILD_PLATFORM).$(BUILD_PLATFORM_ARCH)) \
40 $(LIBRARIES) $(LIBRARIES.$(BUILD_TARGET)) $(LIBRARIES.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) \
41 $(IMPORT_LIBS) $(IMPORT_LIBS.$(BUILD_TARGET)) $(IMPORT_LIBS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) \
42 $(DLLS) $(DLLS.$(BUILD_TARGET)) $(DLLS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) \
43 $(PROGRAMS) $(PROGRAMS.$(BUILD_TARGET)) $(PROGRAMS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) \
44 $(SYSMODS) $(SYSMODS.$(BUILD_TARGET)) $(SYSMODS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) \
45 $(INSTALLS) $(INSTALLS.$(BUILD_TARGET)) $(INSTALLS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) \
46 $(OTHERS) $(OTHERS.$(BUILD_TARGET)) $(OTHERS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH))
[72]47
[447]48# all $(BUILD_TARGET) targets.
[984]49_ALL_BUILD_TARGET_TARGETS := \
[640]50 $(FETCHES) $(FETCHES.$(BUILD_TARGET)) $(FETCHES.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) \
51 $(PATCHES) $(PATCHES.$(BUILD_TARGET)) $(PATCHES.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) \
[482]52 $(LIBRARIES) $(LIBRARIES.$(BUILD_TARGET)) $(LIBRARIES.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) \
[481]53 $(IMPORT_LIBS) $(IMPORT_LIBS.$(BUILD_TARGET)) $(IMPORT_LIBS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) \
[482]54 $(DLLS) $(DLLS.$(BUILD_TARGET)) $(DLLS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) \
55 $(PROGRAMS) $(PROGRAMS.$(BUILD_TARGET)) $(PROGRAMS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) \
56 $(SYSMODS) $(SYSMODS.$(BUILD_TARGET)) $(SYSMODS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) \
57 $(INSTALLS) $(INSTALLS.$(BUILD_TARGET)) $(INSTALLS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) \
58 $(OTHERS) $(OTHERS.$(BUILD_TARGET)) $(OTHERS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH))
[447]59
60# all $(BUILD_TARGET) targets.
[984]61_ALL_BUILD_PLATFORM_TARGETS := \
[481]62 $(BLDPROGS) $(BLDPROGS.$(BUILD_PLATFORM)) $(BLDPROGS.$(BUILD_PLATFORM).$(BUILD_PLATFORM_ARCH))
[447]63
[984]64## all linkable targets.
65#_ALL_LINKABLE_TARGETS := \
66# $(BLDPROGS) $(BLDPROGS.$(BUILD_PLATFORM)) $(BLDPROGS.$(BUILD_PLATFORM).$(BUILD_PLATFORM_ARCH)) \
67# $(DLLS) $(DLLS.$(BUILD_TARGET)) $(DLLS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) \
68# $(PROGRAMS) $(PROGRAMS.$(BUILD_TARGET)) $(PROGRAMS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) \
69# $(SYSMODS) $(SYSMODS.$(BUILD_TARGET)) $(SYSMODS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH))
70#
71## all library targets.
72#_ALL_LIBRARY_TARGETS := \
73# $(LIBRARIES) $(LIBRARIES.$(BUILD_TARGET)) $(LIBRARIES.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) \
74# $(IMPORT_LIBS) $(IMPORT_LIBS.$(BUILD_TARGET)) $(IMPORT_LIBS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) \
75
[640]76# all targets making use of srcname.
[984]77_ALL_SRCNAME_TARGETS := \
[640]78 $(FETCHES) $(FETCHES.$(BUILD_TARGET)) $(FETCHES.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) \
79 $(PATCHES) $(PATCHES.$(BUILD_TARGET)) $(PATCHES.$(BUILD_TARGET).$(BUILD_TARGET_ARCH))
80
[75]81# dependency files.
82_DEPFILES :=
83
[380]84# included dependency files.
85_DEPFILES_INCLUDED :=
86
87
[75]88# All kind of output files except for _OBJS and _DEPFILES.
89# Compiling or linking definition outputting other things that $@ and any
90# required dependency file must add those output files to this variable.
91_OUT_FILES :=
92
[353]93# Files which only requires cleaning up.
94_CLEAN_FILES :=
95
[72]96# all of a type
[219]97_OBJS :=
[640]98_FETCHES :=
99_DOWNLOADS:=
100_UNPACKS :=
101_PATCHES :=
[688]102_UNFETCHES:=
[222]103_BLDPROGS :=
[219]104_LIBS :=
105_DLLS :=
106_PROGRAMS :=
107_SYSMODS :=
[353]108_INSTALLS :=
[827]109_INSTALLS_FILES :=
[380]110_INSTALLS_DIRS :=
[353]111_OTHERS :=
[417]112_PACKING :=
[897]113_DIRS := $(PATH_TARGET)/ $(PATH_TARGET) $(BLDDIRS)
[189]114_IMPORT_LIBS :=
[72]115
[220]116# misc
117pass_prev :=
118
119
[984]120
[72]121#
[984]122# Footer macros
[73]123#
124
[78]125## Figure out the tool for a target.
[753]126# @param $1 normalized target.
127# @param $2 tooltype.
[222]128# @param bld_trg build target.
[481]129# @param bld_trg_arch build target architecture.
[79]130_TARGET_TOOL = $(strip $(firstword \
[753]131 $($(1)_$(2)TOOL.$(bld_trg).$(bld_trg_arch)) \
132 $($(1)_$(2)TOOL.$(bld_trg)) \
133 $($(1)_$(2)TOOL) \
134 $($(1)_TOOL.$(bld_trg).$(bld_trg_arch)) \
135 $($(1)_TOOL.$(bld_trg)) \
136 $($(1)_TOOL) \
137 $($(2)TOOL.$(bld_trg).$(bld_trg_arch)) \
138 $($(2)TOOL.$(bld_trg)) \
139 $($(2)TOOL) \
[481]140 $(TOOL.$(bld_trg).$(bld_trg_arch)) \
[222]141 $(TOOL.$(bld_trg)) \
[106]142 $(TOOL) \
[79]143 ))
[183]144
[353]145## Figure out the actual name of an installed file.
146# @param $1 The file to install.
147# @param $2 The target name.
148# @param $3 The _INST value (can be empty).
149# @param $4 The default directory to use when $3 is empty.
150_INSTALL_FILE = $(patsubst %/,%/$(notdir $(1)),$(if $(3),$(PATH_INS)/$(3),$(4)/))
151
152
[723]153
154#
[185]155# Check syntax which leads to weird syntax errors.
156#
157
158## Check
159# @param $(target) Target name.
160define def_check_target
161ifneq ("$($(target)_TEMPLATE)","$(strip $($(target)_TEMPLATE))")
162$$(error $(target) have an incorrect template name. Remove any tabs!)
163endif
164endef
[984]165$(foreach target, $(_ALL_TARGETS),$(eval $(def_check_target)))
[185]166
167
168#
[984]169# Target inheritance.
170#
171# $ (foreach ...
172
173
174#
[72]175# Include templates
176#
177_TEMPLATES := $(TEMPLATE)
178define def_templates
179ifdef $(target)_TEMPLATE
180_TEMPLATES += $($(target)_TEMPLATE)
181endif
182endef
[984]183$(foreach target, $(_ALL_TARGETS), $(eval $(def_templates)))
[72]184_TEMPLATES := $(sort $(_TEMPLATES))
185# $ (warning dbg: _TEMPLATES=$(_TEMPLATES))
186
187define def_templates_include
188ifndef TEMPLATE_$(template)
[353]189include $(firstword $(foreach path, $(TEMPLATE_PATHS) $(PATH_KBUILD)/templates/, $(wildcard $(path)/$(template).kmk)))
[72]190endif
191endef
192$(foreach template, $(_TEMPLATES), $(eval $(def_templates)))
193
[74]194
[72]195#
[412]196# Template Inheritance.
197#
198define def_template_extends_prop
199ifndef TEMPLATE_$(template)_$(prop)
[552]200 ifdef TEMPLATE_$(parent)_$(prop)
[412]201TEMPLATE_$(template)_$(prop) = $$(TEMPLATE_$(parent)_$(prop))
[552]202 endif
[412]203endif
204endef
205
[552]206
[412]207define def_template_extends
208ifdef TEMPLATE_$(template)_EXTENDS
[552]209 ifndef TEMPLATE_$(template)_EXTENDS_STATUS_
210 TEMPLATE_$(template)_EXTENDS_STATUS_ := 0
211 parent := $(strip $(TEMPLATE_$(template)_EXTENDS))
[412]212
[552]213 # recursivly process the parent if it's inherting from somebody too.
214 ifdef TEMPLATE_$(parent)_EXTENDS
[594]215 ifneq ($(TEMPLATE_$(parent)_EXTENDS_STATUS_),42)
[552]216 # foreach will create 'template' in a new variable context hiding our current variable.
[594]217 $(foreach template, $(parent), $(eval $(value def_template_extends)))
[552]218 parent := $(strip $(TEMPLATE_$(template)_EXTENDS))
219 endif
220 endif
221
222 # inherit properties.
[660]223 $(foreach prop, $(PROPS_SINGLE) $(PROPS_ACCUMULATE_R) $(PROPS_ACCUMULATE_L) $(PROPS_DEFERRED)\
224 $(addsuffix .$(BUILD_TARGET), $(PROPS_SINGLE) $(PROPS_ACCUMULATE_L) $(PROPS_ACCUMULATE_R) $(PROPS_DEFERRED))\
225 $(addsuffix .$(BUILD_TARGET).$(BUILD_TARGET_ARCH), $(PROPS_SINGLE) $(PROPS_ACCUMULATE_L) $(PROPS_ACCUMULATE_R) $(PROPS_DEFERRED))\
226 $(addsuffix .$(BUILD_TARGET_ARCH), $(PROPS_SINGLE) $(PROPS_ACCUMULATE_L) $(PROPS_ACCUMULATE_R) $(PROPS_DEFERRED))\
227 $(addsuffix .$(BUILD_TARGET_CPU), $(PROPS_SINGLE) $(PROPS_ACCUMULATE_L) $(PROPS_ACCUMULATE_R) $(PROPS_DEFERRED))\
228 $(addsuffix .$(BUILD_TYPE), $(PROPS_SINGLE) $(PROPS_ACCUMULATE_L) $(PROPS_ACCUMULATE_R) $(PROPS_DEFERRED))\
[594]229 ,$(eval $(def_template_extends_prop))) # exploits the 2 evaluation, so no value!
[552]230
231 TEMPLATE_$(template)_EXTENDS_STATUS_ := 42
232 else
233 # protect against inheritance loops.
234 ifneq ($(TEMPLATE_$(template)_EXTENDS_STATUS_),42)
235 $(error kBuild: inheritance loop! template=$(template))
236 endif
237 endif
[412]238endif
239endef
240
241# $ (foreach template, $(_TEMPLATES), $(if TEMPLATE_$(template)_EXTENDS, $(eval $(value def_template_extends))))
242$(foreach template, $(_TEMPLATES), $(eval $(value def_template_extends)))
243
244
245#
[72]246# Common Inheritance
247#
248
[353]249## Inherit one template property in a non-accumulative manner.
[72]250# @param $(prop) Property name
251# @param $(target) Target name
[78]252# @todo fix the precedence order for some properties.
[72]253define def_inherit_template_one
[78]254ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop)
[72]255ifndef $(target)_$(prop)
[353]256$(target)_$(prop) := $(TEMPLATE_$($(target)_TEMPLATE)_$(prop))
257#$ (warning dbgtarget: $(target)_$(prop):='$(value $(target)_$(prop))' TEMPLATE_$($(target)_TEMPLATE)_$(prop))
[72]258endif
259endif
[447]260ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg)
261ifndef $(target)_$(prop).$(bld_trg)
262#$ (warning dbgsource: $(target)_$(prop).$(bld_trg)="TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg)" TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg))
263$(target)_$(prop).$(bld_trg) := $(TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg))
[79]264endif
265endif
[481]266ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg).$(bld_trg_arch)
267ifndef $(target)_$(prop).$(bld_trg).$(bld_trg_arch)
268#$ (warning dbgsource: $(target)_$(prop).$(bld_trg).$(bld_trg_arch)="TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg).$(bld_trg_arch)" TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg).$(bld_trg_arch))
269$(target)_$(prop).$(bld_trg).$(bld_trg_arch) := $(TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg).$(bld_trg_arch))
270endif
271endif
[455]272ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_arch)
273ifndef $(target)_$(prop).$(bld_trg_arch)
274#$ (warning dbgsource: $(target)_$(prop).$(bld_trg_arch)="TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_arch)" TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_arch))
275$(target)_$(prop).$(bld_trg_arch) := $(TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_arch))
276endif
277endif
278ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_cpu)
279ifndef $(target)_$(prop).$(bld_trg_cpu)
280#$ (warning dbgsource: $(target)_$(prop).$(bld_trg_cpu)="TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_cpu)" TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_cpu))
281$(target)_$(prop).$(bld_trg_cpu) := $(TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_cpu))
282endif
283endif
[72]284endef
285
[353]286## Inherit one template property in a non-accumulative manner, deferred expansion.
287# @param 1: $(prop) Property name
288# @param 2: $(target) Target name
289# @todo fix the precedence order for some properties.
290# @remark this define relies on double evaluation
291define def_inherit_template_one_deferred
292ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop)
293ifndef $(target)_$(prop)
294$(target)_$(prop) = $$(TEMPLATE_$($(target)_TEMPLATE)_$(prop))
295#$ (warning dbgtarget: $(target)_$(prop):='$(value $(target)_$(prop))' TEMPLATE_$($(target)_TEMPLATE)_$(prop))
296endif
297endif
[447]298ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg)
299ifndef $(target)_$(prop).$(bld_trg)
300#$ (warning dbgsource: $(target)_$(prop).$(bld_trg)="TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg)" TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg))
301$(target)_$(prop).$(bld_trg) = $$(TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg))
[353]302endif
303endif
[481]304ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg).$(bld_trg_arch)
305ifndef $(target)_$(prop).$(bld_trg).$(bld_trg_arch)
306#$ (warning dbgsource: $(target)_$(prop).$(bld_trg).$(bld_trg_arch)="TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg).$(bld_trg_arch)" TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg).$(bld_trg_arch))
307$(target)_$(prop).$(bld_trg).$(bld_trg_arch) = $$(TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg).$(bld_trg_arch))
308endif
309endif
[455]310ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_arch)
311ifndef $(target)_$(prop).$(bld_trg_arch)
312#$ (warning dbgsource: $(target)_$(prop).$(bld_trg_arch)="TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_arch)" TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_arch))
313$(target)_$(prop).$(bld_trg_arch) = $$(TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_arch))
314endif
315endif
316ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_cpu)
317ifndef $(target)_$(prop).$(bld_trg_cpu)
318#$ (warning dbgsource: $(target)_$(prop).$(bld_trg_cpu)="TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_cpu)" TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_cpu))
319$(target)_$(prop).$(bld_trg_cpu) = $$(TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_cpu))
320endif
321endif
[353]322endef
323
[660]324## Inherit one acculumlative template property where the 'most significant' items are at the left end.
[78]325# @param $(prop) Property name
326# @param $(target) Target name
[660]327define def_inherit_template_one_accumulate_l
[78]328ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop)
[353]329#$ (warning dbgtype: TEMPLATE_$($(target)_TEMPLATE)_$(prop) $(target)_$(prop)=$($(target)_$(prop)) $(TEMPLATE_$($(target)_TEMPLATE)_$(prop)))
[659]330$(target)_$(prop) += $$(TEMPLATE_$($(target)_TEMPLATE)_$(prop))
[442]331#$ (warning dbgtype: $(target)_$(prop)=$($(target)_$(prop)))
[78]332endif
[243]333ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(BUILD_TYPE)
[353]334#$ (warning dbg4: TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(BUILD_TYPE))
[659]335$(target)_$(prop).$(BUILD_TYPE) += $$(TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(BUILD_TYPE))
[243]336endif
[447]337ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg)
[659]338#$ (warning dbg5: TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg))
339$(target)_$(prop).$(bld_trg) += $$(TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg))
[79]340endif
[481]341ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg).$(bld_trg_arch)
342#$ (warning dbg4: TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg).$(bld_trg_arch))
[659]343$(target)_$(prop).$(bld_trg).$(bld_trg_arch) += $$(TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg).$(bld_trg_arch))
[481]344endif
[447]345ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_cpu)
346#$ (warning dbg5: TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_cpu))
[659]347$(target)_$(prop).$(bld_trg_cpu) += $$(TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_cpu))
[79]348endif
[447]349ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_arch)
350#$ (warning dbg6: TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_arch))
[659]351$(target)_$(prop).$(bld_trg_arch) += $$(TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_arch))
[79]352endif
[78]353endef
354
[660]355## Inherit one acculumlative template property where the 'most significant' items are at the right end.
356# @param $(prop) Property name
357# @param $(target) Target name
[981]358define def_inherit_template_one_accumulate_r
[660]359ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop)
[981]360#$ (warning dbgtype: TEMPLATE_$($(target)_TEMPLATE)_$(prop) $(target)_$(prop)=$($(target)_$(prop)) $(TEMPLATE_$($(target)_TEMPLATE)_$(prop)))
361$(target)_$(prop) <=$$(TEMPLATE_$($(target)_TEMPLATE)_$(prop))
362#$ (warning dbgtype: $(target)_$(prop)=$($(target)_$(prop)))
[660]363endif
364ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(BUILD_TYPE)
[981]365#$ (warning dbg4: TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(BUILD_TYPE))
366$(target)_$(prop).$(BUILD_TYPE) <=$$(TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(BUILD_TYPE))
[660]367endif
368ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg)
[981]369#$ (warning dbg5: TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg))
370$(target)_$(prop).$(bld_trg) <=$$(TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg))
[660]371endif
372ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg).$(bld_trg_arch)
[981]373#$ (warning dbg4: TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg).$(bld_trg_arch))
374$(target)_$(prop).$(bld_trg).$(bld_trg_arch) <=$$(TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg).$(bld_trg_arch))
[660]375endif
376ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_cpu)
[981]377#$ (warning dbg5: TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_cpu))
378$(target)_$(prop).$(bld_trg_cpu) <=$$(TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_cpu))
[660]379endif
380ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_arch)
[981]381#$ (warning dbg6: TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_arch))
382$(target)_$(prop).$(bld_trg_arch) <=$$(TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_arch))
[660]383endif
384endef
385
386
[72]387## Inherit template properties for on target.
388# @param $(target) Target name.
389define def_inherit_template
[745]390# sanity check.
391ifdef _$(target)_ALREADY_PROCESSED
392 $(error kBuild: The target $(target) appears more than once in the target lists! Please correct the makefile(s))
393endif
394_$(target)_ALREADY_PROCESSED := 1
395
[447]396# Inherit any default template.
397ifdef TEMPLATE
398ifeq ($($(target)_TEMPLATE),)
399$(eval $(target)_TEMPLATE:=$(TEMPLATE))
400endif
401endif
402# Expand the template if specified.
403ifneq ($($(target)_TEMPLATE),)
[353]404$(foreach prop,$(PROPS_SINGLE),$(eval $(value def_inherit_template_one)))
405$(foreach prop,$(PROPS_DEFERRED),$(eval $(def_inherit_template_one_deferred))) # exploits the 2 evaluation, so no value!
[981]406$(foreach prop,$(PROPS_ACCUMULATE_L),$(eval $(def_inherit_template_one_accumulate_l))) # += works fine without value
407$(foreach prop,$(PROPS_ACCUMULATE_R),$(eval $(def_inherit_template_one_accumulate_r))) # use <= (kmk addition)
[447]408endif
[72]409endef
[353]410
[72]411# Inherit template properties
[447]412bld_trg := $(BUILD_TARGET)
413bld_trg_arch := $(BUILD_TARGET_ARCH)
414bld_trg_cpu := $(BUILD_TARGET_CPU)
415$(foreach target, $(_ALL_BUILD_TARGET_TARGETS),$(eval $(value def_inherit_template)))
[72]416
[447]417bld_trg := $(BUILD_PLATFORM)
418bld_trg_arch := $(BUILD_PLATFORM_ARCH)
419bld_trg_cpu := $(BUILD_PLATFORM_CPU)
420$(foreach target, $(_ALL_BUILD_PLATFORM_TARGETS),$(eval $(value def_inherit_template)))
[72]421
[447]422
[72]423#
[460]424# Include tools & sdks
[183]425#
[592]426_TOOLS := $(TOOL.$(BUILD_TARGET)) $(TOOL.$(BUILD_TARGET_ARCH)) $(TOOL.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) \
427 $(TOOL.$(BUILD_PLATFORM)) $(TOOL.$(BUILD_PLATFORM_ARCH)) $(TOOL.$(BUILD_PLATFORM).$(BUILD_PLATFORM_ARCH)) \
428 $(TOOL)
429_SDKS := $(SDKS.$(BUILD_TARGET)) $(SDKS.$(BUILD_TARGET_ARCH)) $(SDKS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) \
430 $(SDKS.$(BUILD_PLATFORM)) $(SDKS.$(BUILD_PLATFORM_ARCH)) $(SDKS.$(BUILD_PLATFORM).$(BUILD_PLATFORM_ARCH)) \
431 $(SDKS.$(BUILD_TYPE)) \
432 $(SDKS)
[460]433define def_tools_sdks_target_source
[353]434$(eval _TOOLS += $(foreach prop, $(PROPS_TOOLS), \
[460]435 $($(source)_$(prop).$(_bld_trg)) \
436 $($(target)_$(source)_$(prop).$(_bld_trg)) \
[481]437 $($(source)_$(prop).$(_bld_trg).$(_bld_trg_arch)) \
438 $($(target)_$(source)_$(prop).$(_bld_trg).$(_bld_trg_arch)) \
[460]439 $($(source)_$(prop).$(_bld_trg_arch)) \
440 $($(target)_$(source)_$(prop).$(_bld_trg_arch)) \
[353]441 $($(source)_$(prop)) \
442 $($(target)_$(source)_$(prop))))
[460]443$(eval _SDKS += \
444 $($(source)_SDKS.$(_bld_trg)) \
445 $($(target)_$(source)_SDKS.$(_bld_trg)) \
[481]446 $($(source)_SDKS.$(_bld_trg).$(_bld_trg_arch)) \
447 $($(target)_$(source)_SDKS.$(_bld_trg).$(_bld_trg_arch)) \
[460]448 $($(source)_SDKS.$(_bld_trg_arch)) \
449 $($(target)_$(source)_SDKS.$(_bld_trg_arch)) \
[592]450 $($(source)_SDKS.$(BUILD_TYPE)) \
451 $($(target)_$(source)_SDKS.$(BUILD_TYPE)) \
[460]452 $($(source)_SDKS) \
453 $($(target)_$(source)_SDKS))
[72]454endef
[353]455
[460]456define def_tools_sdks_target
457_bld_trg := $(firstword $($(target)_BLD_TRG) $(bld_trg))
458_bld_trg_arch := $(firstword $($(target)_BLD_TRG_ARCH) $(bld_trg_arch))
459_bld_trg_cpu := $(firstword $($(target)_BLD_TRG_CPU) $(bld_trg_cpu))
460
[353]461$(eval _TOOLS += $(foreach prop, $(PROPS_TOOLS), \
[460]462 $($(target)_$(prop).$(_bld_trg)) \
463 $($(target)_$(prop).$(_bld_trg_arch)) \
[481]464 $($(target)_$(prop).$(_bld_trg).$(_bld_trg_arch)) \
[353]465 $($(target)_$(prop))))
[460]466$(eval _SDKS += \
467 $($(target)_SDKS.$(_bld_trg)) \
468 $($(target)_SDKS.$(_bld_trg_arch)) \
[481]469 $($(target)_SDKS.$(_bld_trg).$(_bld_trg_arch)) \
[460]470 $($(target)_SDKS))
[353]471$(foreach source, \
[460]472 $($(target)_SOURCES.$(_bld_trg)) \
473 $($(target)_SOURCES.$(_bld_trg_arch)) \
[481]474 $($(target)_SOURCES.$(_bld_trg).$(_bld_trg_arch)) \
[460]475 $($(target)_SOURCES.$(_bld_trg_cpu)) \
[353]476 $($(target)_SOURCES.$(BUILD_TYPE)) \
477 $($(target)_SOURCES) \
[460]478 , $(eval $(value def_tools_sdks_target_source)))
[72]479endef
[353]480
[640]481define def_tools_srcname_target
482_bld_trg := $(firstword $($(target)_BLD_TRG) $(bld_trg))
483_bld_trg_arch := $(firstword $($(target)_BLD_TRG_ARCH) $(bld_trg_arch))
484_bld_trg_cpu := $(firstword $($(target)_BLD_TRG_CPU) $(bld_trg_cpu))
485
486$(foreach source, $(notdir\
487 $($(target)_SOURCES.$(_bld_trg)) \
488 $($(target)_SOURCES.$(_bld_trg_arch)) \
489 $($(target)_SOURCES.$(_bld_trg).$(_bld_trg_arch)) \
490 $($(target)_SOURCES.$(_bld_trg_cpu)) \
491 $($(target)_SOURCES.$(BUILD_TYPE)) \
492 $($(target)_SOURCES) \
493 ), $(eval $(value def_tools_sdks_target_source)))
494endef
495
[460]496bld_trg := $(BUILD_TARGET)
497bld_trg_arch := $(BUILD_TARGET_ARCH)
498bld_trg_cpu := $(BUILD_TARGET_CPU)
499$(foreach target, $(_ALL_BUILD_TARGET_TARGETS), $(eval $(value def_tools_sdks_target)))
[640]500$(foreach target, $(_ALL_SRCNAME_TARGETS), $(eval $(value def_tools_srcname_target)))
[72]501
[460]502bld_trg := $(BUILD_PLATFORM)
503bld_trg_arch := $(BUILD_PLATFORM_ARCH)
504bld_trg_cpu := $(BUILD_PLATFORM_CPU)
505$(foreach target, $(_ALL_BUILD_PLATFORM_TARGETS), $(eval $(value def_tools_sdks_target)))
506
507
508# include TOOLS
[72]509define def_tools_include
510ifndef TOOL_$(tool)
[353]511TOOL_$(tool)_KMK_FILE := $(firstword $(foreach path, $(TOOL_PATHS) $(PATH_KBUILD)/tools, $(wildcard $(path)/$(tool).kmk)))
512ifeq ($(TOOL_$(tool)_KMK_FILE),)
513$(error kBuild: Cannot find include file for the tool '$(tool)'! Searched: $(TOOL_PATHS) $(PATH_KBUILD)/tools)
[72]514endif
[353]515include $(TOOL_$(tool)_KMK_FILE)
[853]516ifndef TOOL_$(tool)
517$(warning kBuild: TOOL_$(tool) was not by $(TOOL_$(tool)_KMK_FILE)!)
[353]518endif
[853]519endif
[72]520endef
[460]521
522_TOOLS := $(sort $(_TOOLS))
[353]523$(foreach tool, $(_TOOLS), $(eval $(value def_tools_include)))
[72]524
525
[460]526# include SDKS
[122]527define def_sdks_include_one
[72]528ifndef SDK_$(sdk)
[353]529SDK_$(sdk)_KMK_FILE := $(firstword $(foreach path, $(SDK_PATHS) $(PATH_KBUILD)/sdks, $(wildcard $(path)/$(sdk).kmk)))
530ifeq ($(SDK_$(sdk)_KMK_FILE),)
531$(error kBuild: Cannot find include file for the SDK '$(sdk)'! Searched: $(SDK_PATHS) $(PATH_KBUILD)/sdks)
[72]532endif
[353]533include $(SDK_$(sdk)_KMK_FILE)
[852]534ifndef SDK_$(sdk)
[853]535$(warning kBuild: SDK_$(sdk) was not defined by $(SDK_$(sdk)_KMK_FILE)!)
[353]536endif
[852]537endif
[72]538endef
[460]539
[859]540_SDKS := $(sort $(_SDKS))
[353]541$(foreach sdk, $(_SDKS), $(eval $(value def_sdks_include_one)))
[72]542
[380]543
[640]544
[828]545#
546#
547# Target lists - Pass 1
548#
549# This pass is for defining variables that might be referenced in
550# properties of other targets.
551#
552#
553
554# Don't do anything for fetch targets (yet).
555
556##
557# Link prolog for Pass 1.
558#
559# @param $(target) Normalized target name.
560# @param $(EXT) EXE,DLL,SYS,LIB.
561# @param $(EXTPRE) HOST or nothing.
562# @param $(definst) The default _INST value.
563# @param $(tool_prefix) LD or AR.
564# @param $(bld_trg_base_var) TARGET or PLATFORM.
565define def_pass1_link_common
566
567bld_type := $(firstword $($(target)_BLD_TYPE) $(BUILD_TYPE))
568bld_trg := $(firstword $($(target)_BLD_TRG) $(BUILD_$(bld_trg_base_var)))
569bld_trg_arch:= $(firstword $($(target)_BLD_TRG_ARCH) $(BUILD_$(bld_trg_base_var)_ARCH))
570bld_trg_cpu := $(firstword $($(target)_BLD_TRG_CPU) $(BUILD_$(bld_trg_base_var)_CPU))
571
[889]572tool := $(call _TARGET_TOOL,$(target),$(tool_prefix))
573name := $(firstword\
574 $($(target)_NAME.$(bld_trg).$(bld_trg_arch))\
575 $($(target)_NAME.$(bld_trg_arch))\
576 $($(target)_NAME.$(bld_trg))\
577 $($(target)_NAME.$(bld_type))\
578 $($(target)_NAME)\
579 $(target))
580outbase := $(call TARGET_BASE,$(name),$(target))
[828]581ifndef PATH_$(target)
582 PATH_$(target) := $(patsubst %/,%,$(dir $(outbase)))
583else ifneq ($(PATH_$(target)),$(patsubst %/,%,$(dir $(outbase))))
584 $(error kBuild internal error: PATH_$(target)=$(PATH_$(target)) expected $(patsubst %/,%,$(dir $(outbase))))
585endif
586ifeq ($(tool_prefix),AR) ## @todo fix this mess!
587suff := $(firstword\
588 $($(target)_$(EXT)SUFF.$(bld_trg).$(bld_trg_arch))\
589 $($(target)_$(EXT)SUFF.$(bld_trg))\
590 $($(target)_$(EXT)SUFF)\
591 $(TOOL_$(tool)_$(tool_prefix)$(EXT)SUFF.$(bld_trg).$(bld_trg_arch))\
592 $(TOOL_$(tool)_$(tool_prefix)$(EXT)SUFF.$(bld_trg))\
593 $(TOOL_$(tool)_$(tool_prefix)$(EXT)SUFF)\
594 $(SUFF_LIB))
595else
596suff := $(firstword \
597 $($(target)_$(EXT)SUFF) \
598 $($(target)_$(EXT)SUFF) \
599 $(TOOL_$(tool)_$(tool_prefix)$(EXT)SUFF) \
600 $($(EXTPRE)SUFF_$(EXT)))
601endif
602out := $(outbase)$(suff)
603
604# TARGET_*
605TARGET_$(target) := $(out)
606
607# INSTARGET_*
608ifndef $(target)_NOINST
609INSTARGET_$(target) := $(patsubst %/,%/$(notdir $(out)), \
610 $(if $($(target)_INST), $(addprefix $(PATH_INS)/,$($(target)_INST)), $(definst)/))
611
612else # NOINST
613INSTARGET_$(target) :=
614endif # NOINST
615
616endef
617
618
619#
620# BLDPROGS (Pass 1)
621#
622define def_pass1_bldprog
623# set NOINST if not forced installation before doing the usual stuff.
624ifndef $(target)_INST
625$(target)_NOINST := 1
626endif
627$(eval $(value def_pass1_link_common))
628endef
629
630EXT := EXE
631EXTPRE := HOST
632definst := $(PATH_BIN)
633tool_prefix := LD
634bld_trg_base_var := PLATFORM
635$(foreach target, $(BLDPROGS) $(BLDPROGS.$(BUILD_PLATFORM)) $(BLDPROGS.$(BUILD_PLATFORM).$(BUILD_PLATFORM_ARCH)), \
636 $(eval $(value def_pass1_bldprog)))
637
638
639#
640# LIBRARIES (Pass 1)
641#
642EXT := LIB
643EXTPRE :=
644definst := $(PATH_LIB)
645tool_prefix := AR
646bld_trg_base_var := TARGET
647$(foreach target, $(LIBRARIES) $(LIBRARIES.$(BUILD_TARGET)) $(LIBRARIES.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)), \
648 $(eval $(value def_pass1_link_common)))
649
650
651#
652# DLLS (Pass 1)
653#
654EXT := DLL
655EXTPRE :=
656definst := $(PATH_DLL)
657tool_prefix := LD
658bld_trg_base_var := TARGET
659$(foreach target, $(DLLS) $(DLLS.$(BUILD_TARGET)) $(DLLS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)), \
660 $(eval $(value def_pass1_link_common)))
661
662
663#
664# IMPORT LIBRARIES (Pass 1)
665#
666# - On OS/2 and windows these are libraries.
667# - On other platforms they are fake DLLs.
668#
669ifeq ($(filter-out nt os2 win win64 win32,$(BUILD_TARGET)),)
670 EXT := LIB
671 EXTPRE :=
672 definst := $(PATH_LIB)
673 tool_prefix := AR
674 bld_trg_base_var := TARGET
675 $(foreach target, $(IMPORT_LIBS) $(IMPORT_LIBS.$(BUILD_TARGET)) $(IMPORT_LIBS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)), \
676 $(eval $(value def_pass1_lib)))
677else
678 EXT := DLL
679 EXTPRE :=
680 definst := $(PATH_DLL)
681 tool_prefix := LD
682 bld_trg_base_var := TARGET
683 $(foreach target, $(IMPORT_LIBS) $(IMPORT_LIBS.$(BUILD_TARGET)) $(IMPORT_LIBS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)), \
684 $(eval $(value def_pass1_link_common)))
685endif
686
687
688#
689# PROGRAMS (Pass 1)
690#
691EXT := EXE
692EXTPRE :=
693definst := $(PATH_BIN)
694tool_prefix := LD
695bld_trg_base_var := TARGET
696$(foreach target, $(PROGRAMS) $(PROGRAMS.$(BUILD_TARGET)) $(PROGRAMS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)), \
697 $(eval $(value def_pass1_link_common)))
698
699
700#
701# SYSMODS (Pass 1)
702#
703EXT := SYS
704EXTPRE :=
705definst := $(PATH_SYS)
706tool_prefix := LD
707bld_trg_base_var := TARGET
708$(foreach target, $(SYSMODS) $(SYSMODS.$(BUILD_TARGET)) $(SYSMODS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)), \
709 $(eval $(value def_pass1_link_common)))
710
711
712#
713# INSTALLS (Pass 1)
714# Note! INSTARGET_* for INSTALLS aren't available until later.
715#
716define def_pass1_install
717bld_type := $(firstword $($(target)_BLD_TYPE) $(BUILD_TYPE))
718bld_trg := $(firstword $($(target)_BLD_TRG) $(BUILD_TARGET))
719bld_trg_arch:= $(firstword $($(target)_BLD_TRG_ARCH) $(BUILD_TARGET_ARCH))
720bld_trg_cpu := $(firstword $($(target)_BLD_TRG_CPU) $(BUILD_TARGET_CPU))
721# TARGET_*
722TARGET_$(target) := $(PATH_TARGET)/$(target).ins
723# INSTARGET_ later.
724endef
725$(foreach target, $(INSTALLS) $(INSTALLS.$(BUILD_TARGET)) $(INSTALLS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)), \
726 $(eval $(value def_pass1_install)))
727
728
729
730
731#
732#
733# Target lists - Pass 2
734#
735#
736
737
[688]738## @page pg_fetches Fetching Tools, Sources and Similar.
[73]739#
[688]740# The targets listed in the the FETCHES target list have the following attributes:
741# SOURCES
742# INST
743# FETCHTOOL
744# FETCHFLAGS
745# FETCHDIR
746# UNPACKTOOL
747# UNPACKFLAGS
[640]748#
[719]749# As usual the target name is an alias for 'creating' the target. Other
[688]750# aliases are:
751# pass_fetches
752# fetch
753# unfetch
754# download
755# unpack
756#
757# @remark
758#
759# This is a little bit complex because we must guarantee that if a source file
[719]760# changes only sligtly we must refetch it and to a proper unpacking of it. It
761# is also a desire that fetched archives and unpacked files can be deleted to
[688]762# save space.
763#
[719]764# Thus, we must be able to cleanup what we've unpacked should any of the
[688]765# sources be removed. We do this by maintaining a file listing the files
766# and directories that was unpacked. This operation is named 'unfetch'.
767#
[719]768# We make use of the SIZE and MD5 attributes for each of the sources to
[689]769# create a digest that is stored in the primary target file. Subsequent
770# runswill compare their digest with it to decide if a refetch is required.
[719]771# When a refetch is found necessary, an 'unfetch' is performed first to
[689]772# clean out old files and directores. Note even changes in source order
[719]773# will cause a refetch due to the way the digest is constructed and
[689]774# evaluated.
[688]775#
776# By not depending directly on the archives (nor on any unpacked files)
777# but on a goal made up from the archive name, size and md5, we allow
778# the user to delete the archives. Naturally, this means we'll have to
779# check and fetch missing archives before attempting to unpack them.
[689]780#
781# @remark
782#
[719]783# This feature will *NOT* work correctly with vanilla GNU make becuase
[689]784# it makes use of includedep to avoid too many unnecessary files.
[719]785#
[689]786# @todo
[688]787# 1. Port md5sum or some equivalent tool and include it in kBuild.
788# 2. Download corruption / continuation.
789# 3. It's quite possible that there is one too many indirect dependency now...
790#
791
792## @todo move this!
[640]793MD5SUM := md5sum
794
795## generates the fetch rule
796define def_fetch_src_fetch_rule
797# Indirect goal for downloading something.
[682]798.PRECIOUS: $(out)
[640]799$(out) $($(target)_$(srcname)_FETCH_OUTPUT_): | $($(target)_$(srcname)_FETCH_DEPORD_)
[776]800 $$(call MSG_FETCH_DL,$(target),$(source),$(out))
[696]801 @## @todo do fancy stuff like download continuation.
802 $$(QUIET)$$(RM) -f $(out) $(out).md5
[640]803 $($(target)_$(srcname)_FETCH_CMDS_)
[696]804 $$(QUIET2)$(if $(md5),$$(APPEND) $(out).md5 "$(md5) *$(out)")
805 $$(QUIET)$(if $(md5),$$(MD5SUM) -c $(out).md5)
[640]806
807
[682]808
[640]809# Intermediate goal for making sure the md5 and size matches. it will (re) fetch the archive if necessary.
810$(out).checked_$(md5)_$(size): $($(target)_$(srcname)_FETCH_DEPEND_) | $($(target)_$(srcname)_FETCH_DEPORD_)
[776]811 $$(call MSG_FETCH_CHK,$(target),$(source),$(out))
[696]812 $$(QUIET)$$(RM) -f $$@ $(out).md5
[640]813 @# creates the .md5 we pass to md5sum.
[696]814 $$(QUIET2)$(if $(md5),$$(APPEND) $(out).md5 "$(md5) *$(out)")
[688]815 @# (re)fetch the file if it doesn't exist or if it doesn't matches the md5.
[696]816 @## @todo do fancy stuff like download continuation.
817 $$(QUIET)( test -f $(out) && $(if $(md5),$$(MD5SUM) -c $(out).md5, true) ) \
818 || ( $$(RM_EXT) -f $(out) \
819 && $$(MAKE) $(out) -f $(MAKEFILE) --no-print-directory )
820 $$(QUIET2)$$(APPEND) $$@
[640]821
[719]822_TARGET_$(target)_FETCHED += $(out) $(out).checked_$(md5)_$(size)
[640]823
[688]824# Just a little precaution.
825.NOTPARALLEL: $(out) $(out).checked_$(md5)_$(size)
826
[640]827endef
828
829## generates the unpack rule
830define def_fetch_src_unpack_rule
831# This is the unpack rule. it has an order-only dependency on the download check.
832$(out) $($(target)_$(srcname)_UNPACK_OUTPUT_): $($(target)_$(srcname)_UNPACK_DEPEND_) \
833 | $($(target)_$(srcname)_UNPACK_DEPORD_) $(archive).checked_$(md5)_$(size)
[776]834 $$(call MSG_FETCH_UP,$(target),$(archive),$(inst))
[696]835 $$(QUIET)$$(RM) -f $(out)
[688]836 @# if the source archive doesn't exist fetch it (can have been deleted to save space).
[696]837 $$(QUIET)test -f $(archive) \
838 || ( $$(RM_EXT) -f $(archive).checked_$(md5)_$(size) \
839 && $$(MAKE) $(archive).checked_$(md5)_$(size) -f $(MAKEFILE) --no-print-directory )
[640]840 $($(target)_$(srcname)_UNPACK_CMDS_)
[696]841 $$(QUIET2)$$(APPEND) $(out) $(notdir $(archive).checked_$(md5)_$(size))
842 $$(QUIET2)$$(APPEND) $(out) $(notdir $(out))
[640]843
844$(eval _TARGET_$(target)_UNPACKED += $(out))
845_TARGET_$(target)_DIGEST := $(_TARGET_$(target)_DIGEST)-$(srcname)_$(md5)_$(size)
846
[688]847.NOTPARALLEL: $(out)
848
[719]849endef
[640]850
851## Processes a fetch source
852#
853define def_fetch_src
854#$ (warning dbg: def_fetch_src: source='$(source)' target='$(target)')
855
856# common
857srcname := $(notdir $(source))
858inst := $(firstword \
859 $($(target)_$(source)_INST)\
860 $($(target)_$(srcname)_INST)\
861 $($(source)_INST)\
862 $($(srcname)_INST)\
863 $($(target)_INST)\
864)
865ifneq ($(patsubst %/,ok,$(inst)),ok)
866$(error kBuild: Bad or missing INST property for source '$(source)' in target '$(target)': $(inst))
867endif
868INSTARGET_$(target)_$(srcname) := $(inst)
869fetchdir := $(firstword \
870 $($(target)_$(source)_FETCHDIR)\
871 $($(target)_$(srcname)_FETCHDIR)\
872 $($(source)_FETCHDIR)\
873 $($(srcname)_FETCHDIR)\
874 $($(target)_FETCHDIR)\
875 $(FETCHDIR)\
876 $(PATH_TARGET)\
877)
878deps := \
879 $($(target)_$(source)_DEPS)\
880 $($(target)_$(srcname)_DEPS)\
881 $($(source)_DEPS)\
882 $($(srcname)_DEPS)\
883 $($(target)_DEPS)
[827]884orderdeps := \
885 $($(target)_$(source)_ORDERDEPS)\
886 $($(target)_$(srcname)_ORDERDEPS)\
887 $($(source)_ORDERDEPS)\
888 $($(srcname)_ORDERDEPS)\
889 $($(target)_ORDERDEPS)
[640]890md5 := $(firstword \
891 $($(target)_$(source)_MD5)\
892 $($(target)_$(srcname)_MD5)\
893 $($(source)_MD5)\
894 $($(srcname)_MD5)\
895 $($(target)_MD5)\
896)
897size := $(firstword \
898 $($(target)_$(source)_SIZE)\
899 $($(target)_$(srcname)_SIZE)\
900 $($(source)_SIZE)\
901 $($(srcname)_SIZE)\
902 $($(target)_SIZE)\
903)
904dep := # not legal for fetch and unpack tools
905
906
907#
908# The fetching.
909#
910out := $(fetchdir)/$(srcname)
911archive := $(out)
912TARGET_$(target)_$(srcname) := $(out)
913dirdep := $(call DIRDEP,$(fetchdir))
914tool := $(firstword \
915 $($(target)_$(source)_FETCHTOOL)\
916 $($(target)_$(srcname)_FETCHTOOL)\
917 $($(target)_$(source)_TOOL)\
918 $($(target)_$(srcname)_TOOL)\
919 $($(source)_FETCHTOOL)\
920 $($(srcname)_FETCHTOOL)\
921 $($(source)_TOOL)\
922 $($(srcname)_TOOL)\
923 $($(target)_FETCHTOOL)\
924 $($(target)_TOOL)\
925 )
926flags :=\
927 $(TOOL_$(tool)_FETCHFLAGS)\
928 $(FETCHFLAGS)\
929 $($(target)_FETCHFLAGS)\
930 $($(srcname)_FETCHFLAGS)\
931 $($(source)_FETCHFLAGS)\
932 $($(target)_$(srcname)_FETCHFLAGS)\
933 $($(target)_$(source)_FETCHFLAGS)
934
935#$ (warning dbg: target=$(target) source=$(source) $(srcname)=$(srcname) tool=$(tool) out=$(out) flags=$(flags) dirdep=$(dirdep) fetchdir=$(fetchdir) md5=$(md5) size=$(size))
936
937ifndef TOOL_$(tool)_FETCH_CMDS
938$(warning kBuild: tools: \
939 1 $($(target)_$(source)_FETCHTOOL)\
940 2 $($(target)_$(srcname)_FETCHTOOL)\
941 3 $($(target)_$(source)_TOOL)\
942 4 $($(target)_$(srcname)_TOOL)\
943 5 $($(source)_FETCHTOOL)\
944 6 $($(srcname)_FETCHTOOL)\
945 7 $($(source)_TOOL)\
946 8 $($(srcname)_TOOL)\
947 9 $($(target)_FETCHTOOL)\
948 10 $($(target)_TOOL) )
949$(error kBuild: TOOL_$(tool)_FETCH_CMDS is not defined. source=$(source) target=$(target) )
950endif
951
952# call the tool
953$(target)_$(srcname)_FETCH_CMDS_ := $(TOOL_$(tool)_FETCH_CMDS)
954$(target)_$(srcname)_FETCH_OUTPUT_ := $(TOOL_$(tool)_FETCH_OUTPUT)
955$(target)_$(srcname)_FETCH_DEPEND_ := $(TOOL_$(tool)_FETCH_DEPEND) $(deps)
[827]956$(target)_$(srcname)_FETCH_DEPORD_ := $(TOOL_$(tool)_FETCH_DEPORD) $(dirdep) $(orderdeps)
[640]957
958# generate the fetch rule.
959$(eval $(def_fetch_src_fetch_rule))
960
961
962#
963# The unpacking / installing.
964#
965out := $(inst)_kBuild_$(target)_$(srcname)_unpacked.lst
966dirdep := $(call DIRDEP,$(inst))
967tool := $(firstword \
968 $($(target)_$(source)_UNPACKTOOL)\
969 $($(target)_$(srcname)_UNPACKTOOL)\
970 $($(target)_$(source)_TOOL)\
971 $($(target)_$(srcname)_TOOL)\
972 $($(source)_UNPACKTOOL)\
973 $($(srcname)_UNPACKTOOL)\
974 $($(source)_TOOL)\
975 $($(srcname)_TOOL)\
976 $($(target)_UNPACKTOOL)\
977 $($(target)_TOOL) \
978 )
979ifeq ($(tool),)
980tool := $(toupper $(subst .,,$(suffix $(subst tar.,TAR,$(srcname)))))
981$(eval $(value def_tools_include))
982endif
983flags :=\
984 $(TOOL_$(tool)_UNPACKFLAGS)\
985 $(UNPACKFLAGS)\
986 $($(target)_UNPACKFLAGS)\
987 $($(srcname)_UNPACKFLAGS)\
988 $($(source)_UNPACKFLAGS)\
989 $($(target)_$(srcname)_UNPACKFLAGS)\
990 $($(target)_$(source)_UNPACKFLAGS)
991
992#$ (warning dbg: target=$(target) source=$(source) $(srcname)=$(srcname) tool=$(tool) out=$(out) flags=$(flags) dirdep=$(dirdep) inst=$(inst) md5=$(md5) size=$(size))
993ifndef TOOL_$(tool)_UNPACK_CMDS
994$(warning kBuild: tools: \
995 1 $($(target)_$(source)_UNPACKTOOL)\
996 2 $($(target)_$(srcname)_UNPACKTOOL)\
997 3 $($(target)_$(source)_TOOL)\
998 4 $($(target)_$(srcname)_TOOL)\
999 5 $($(source)_UNPACKTOOL)\
1000 6 $($(srcname)_UNPACKTOOL)\
1001 7 $($(source)_TOOL)\
1002 8 $($(srcname)_TOOL)\
1003 9 $($(target)_UNPACKTOOL)\
1004 10 $($(target)_TOOL) \
1005 11 $(toupper $(subst tar.,TAR,$(ext $(srcname)))) \
1006 )
1007$(error kBuild: TOOL_$(tool)_UNPACK_CMDS is not defined. source=$(source) target=$(target) )
1008endif
1009
1010# call the tool
1011$(target)_$(srcname)_UNPACK_CMDS_ := $(TOOL_$(tool)_UNPACK_CMDS)
1012$(target)_$(srcname)_UNPACK_OUTPUT_ := $(TOOL_$(tool)_UNPACK_OUTPUT)
1013$(target)_$(srcname)_UNPACK_DEPEND_ := $(TOOL_$(tool)_UNPACK_DEPEND) $(deps)
[827]1014$(target)_$(srcname)_UNPACK_DEPORD_ := $(TOOL_$(tool)_UNPACK_DEPORD) $(dirdep) $(orderdeps)
[640]1015
1016# generate the fetch rule.
1017$(eval $(def_fetch_src_unpack_rule))
1018
1019_DIRS += $(inst) $(fetchdir)
1020
1021endef
1022
1023
1024##
1025# Define the target level rules for a fetch.
1026# @param target
1027# @param out
1028# @param inst
[688]1029# @param _TARGET_$(target)_UNPACKED
1030# @param _TARGET_$(target)_DIGEST
[640]1031# @param bld_trg
1032# @param bld_trg_arch
1033define def_fetch_rules
1034
[689]1035$(out).lst: $(_TARGET_$(target)_UNPACKED) | $(call DIRDEP,$(inst))
[776]1036 $$(call MSG_FETCH_OK,$(target))
[696]1037 $$(QUIET)$$(RM) -f $$@ $$@.tmp
1038 $$(QUIET2)$$(APPEND) $$@.tmp "$(notdir $(out))"
1039 $$(QUIET)$(if $(_TARGET_$(target)_UNPACKED),$$(CAT_EXT) $(_TARGET_$(target)_UNPACKED) >> $$@.tmp)
1040 $$(QUIET)$$(MV) -f $$@.tmp $$@
[640]1041
1042$(out)_unfetched:
[776]1043 $$(call MSG_UNFETCH,$(target))
[696]1044 $$(QUIET)$$(RM) -f $$(addprefix $(inst),$$(shell $$(CAT_EXT) $(out).lst 2> /dev/null | $$(SED) -e '/\/$$$$/d'))
1045 $$(QUIET)$$(RMDIR) -p --ignore-fail-on-non-empty --ignore-fail-on-not-exist $$(dir $$@) \
[689]1046 $$(addprefix $(inst),$$(sort $$(dir $$(shell $$(CAT_EXT) $(out).lst 2> /dev/null))))
[696]1047 $$(QUIET)$$(RM) -f $(out).lst $(out)
1048 $$(QUIET)$$(RMDIR) -p --ignore-fail-on-non-empty --ignore-fail-on-not-exist $$(dir $$@)
[640]1049
[689]1050$(out): $(comp-vars _TARGET_$(target)_DIGEST_PREV,_TARGET_$(target)_DIGEST,FORCE) | $(call DIRDEP,$(inst))
[696]1051 $$(QUIET)$$(RM) -f $$@
[776]1052 $$(if $$(_TARGET_$(target)_DIGEST),$$(if $$(wildcard $(out).lst)\
1053 ,$$(call MSG_REFETCH,$(target)),$$(call MSG_FETCH,$(target))),$$(call MSG_UNFETCH,$(target)))
[696]1054 $$(QUIET)$$(if $$(wildcard $(out).lst ),$$(MAKE) -f $(MAKEFILE) --no-print-directory $(out)_unfetched)
[701]1055 $$(QUIET)$$(if $$(_TARGET_$(target)_DIGEST),$$(MAKE) -f $(MAKEFILE) --no-print-directory $(out).lst,$$(RMDIR) -p --ignore-fail-on-non-empty --ignore-fail-on-not-exist $$(dir $$@))
[696]1056 $$(QUIET2)$$(if $$(_TARGET_$(target)_DIGEST),$$(APPEND) $$@ "_TARGET_$(target)_DIGEST_PREV := $(_TARGET_$(target)_DIGEST)")
[760]1057
[689]1058.NOTPARALLEL: $(out).lst $(out)_unfetched $(out)
[688]1059
[640]1060endef
1061
1062
1063##
1064# Deal with one fetch target.
1065# @param target
1066# @param bld_trg
1067# @param bld_trg_arch
1068define def_fetch
1069# common
1070INSTARGET_$(target) := $($(target)_INST)
1071ifneq ($(patsubst %/,ok,$(INSTARGET_$(target))),ok)
[679]1072$(error kBuild: Bad or missing INST property for target '$(target)'. \
1073 $(target)_INST='$($(target)_INST)' ($(origin $(target)_INST)))
[640]1074endif
1075_TARGET_$(target)_FETCHED :=
1076_TARGET_$(target)_UNPACKED :=
1077_TARGET_$(target)_DIGEST :=
1078
1079# The 'sources'.
1080#$ (warning dbg fetch: target=$(target) sources=$($(target)_SOURCES) $($(target)_SOURCES.$(BUILD_TYPE)) $($(target)_SOURCES.$(BUILD_TARGET)) $($(target)_SOURCES.$(BUILD_TARGET_ARCH)) $($(target)_SOURCES.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)))
1081$(foreach source,$($(target)_SOURCES) $($(target)_SOURCES.$(BUILD_TYPE)) $($(target)_SOURCES.$(BUILD_TARGET)) $($(target)_SOURCES.$(BUILD_TARGET_ARCH)) $($(target)_SOURCES.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)),\
1082 $(eval $(value def_fetch_src)))
1083
1084# The target.
1085inst := $(INSTARGET_$(target))
1086out := $(inst)_kBuild_fetch_$(target)
1087
[689]1088$(eval includedep $(out))
[690]1089
[640]1090$(eval $(def_fetch_rules))
1091
[690]1092# Define the aliases here (doesn't work if defined in def_fetch_rules, just like includedep).
[749]1093$(target): $(out)
1094$(target)_unfetch: $(out)_unfetched
[690]1095
[689]1096_FETCHES += $(out)
[640]1097_DOWNLOADS += $(_TARGET_$(target)_FETCHED)
1098_UNPACKS += $(_TARGET_$(target)_UNPACKED)
1099_UNFETCHES += $(out)_unfetched
1100_DIRS += $(inst)
1101
1102endef
1103
1104# Walk the FETCH target lists.
1105bld_trg := $(BUILD_TARGET)
1106bld_trg_arch := $(BUILD_TARGET_ARCH)
1107$(foreach target, $(FETCHES) $(FETCHES.$(BUILD_TARGET)) $(FETCHES.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)), \
1108 $(eval $(value def_fetch)))
1109
1110# some aliases.
1111download: $(_DOWNLOADS)
[688]1112unpack: $(_UNPACKS)
1113fetch: $(_FETCHES)
1114unfetch: $(_UNFETCHES)
[640]1115
1116
1117
1118##
1119## Patching.
1120##
1121##
[688]1122#define def_patch_src
[640]1123#
1124#endef
1125#
1126#
1127## Deal with one patch target.
1128#define def_patch
1129#
1130#$(foreach source,$($(target)_SOURCES) $($(target)_SOURCES.$(BUILD_TYPE)) $($(target)_SOURCES.$(BUILD_TARGET)) $($(target)_SOURCES.$(BUILD_TARGET_ARCH)) $($(target)_SOURCES.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)),\
[688]1131# $(eval $(value def_patch_src)))
[640]1132#
[719]1133#_PATCHES +=
[640]1134#endef
1135#
1136#$(foreach target, $(PATCHES) $(PATCHES.$(BUILD_TARGET)) $(PATCHES.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)), \
1137# $(eval $(value def_patch)))
1138#
1139
1140
1141#
[73]1142# Object processing.
1143#
[72]1144
[380]1145## wrapper the compile command dependency check.
1146ifndef NO_COMPILE_CMDS_DEPS
[741]1147 _DEP_COMPILE_CMDS = $(comp-cmds $(target)_$(source)_CMDS_PREV_,$(target)_$(source)_CMDS_,FORCE)
[380]1148else
[730]1149 _DEP_COMPILE_CMDS =
[380]1150endif
1151
[749]1152## Generates the rules for building a specific object, and the aliases
[380]1153# for building a source file.
[353]1154# @param $(obj) The object file.
[380]1155define def_target_source_rule
[984]1156$(obj) + $($(target)_$(source)_OUTPUT_) : \
[380]1157 $($(target)_$(source)_DEPEND_) \
1158 $(_DEP_COMPILE_CMDS) \
1159 | \
1160 $($(target)_$(source)_DEPORD_)
[776]1161 $$(call MSG_COMPILE,$(target),$(source),$$@,$(type))
[696]1162 $$(QUIET)$$(RM) -f $(dep) $(obj) $($(target)_$(source)_OUTPUT_)
[412]1163
[380]1164$($(target)_$(source)_CMDS_)
1165
1166ifndef NO_COMPILE_CMDS_DEPS
[696]1167 $$(QUIET2)$$(APPEND) "$(dep)"
1168 $$(QUIET2)$$(APPEND) "$(dep)" 'define $(target)_$(source)_CMDS_PREV_'
[770]1169ifeq ($(filter append-dash-n,$(KMK_FEATURES)),append-dash-n)
1170 $$(QUIET2)$$(APPEND) -v "$(dep)" '$(target)_$(source)_CMDS_'
1171else
[696]1172 $$(QUIET2)$$(APPEND) "$(dep)" '$(subst $(NL),'$(NL)$(TAB)@$(APPEND) "$(dep)" ',$($(target)_$(source)_CMDS_))'
[770]1173endif
[696]1174 $$(QUIET2)$$(APPEND) "$(dep)" 'endef'
[412]1175endif
[380]1176
[749]1177$(basename $(notdir $(obj))).o: $(obj)
1178$(basename $(notdir $(obj))).obj: $(obj)
[353]1179endef
[205]1180
[353]1181
[380]1182## wrapper the link command dependency check.
1183ifndef NO_COMPILE_CMDS_DEPS
[741]1184 _DEP_LINK_CMDS = $(comp-cmds $(target)_CMDS_PREV_,$(target)_CMDS_,FORCE)
[380]1185else
[730]1186 _DEP_LINK_CMDS =
[380]1187endif
1188
1189## Generate the link rule for a target.
1190# @param $(target) The normalized target name.
1191# @param $(dirdep) Directories we depend upon begin created before linking.
1192# @param $(dep) The name of the dependency file.
1193# @param $(out)
1194# @param $($(target)_OUTPUT_) Output files from the link.
1195# @param $($(target)_DEPEND_) Dependencies.
1196# @param $($(target)_DEPORD_) Dependencies which should only affect build order.
1197# @param $($(target)_CMDS_) The link commands.
1198# @param $($(target)_CMDS_PREV_) The link commands from the previous run.
1199define def_link_rule
[984]1200$(out) + $($(target)_OUTPUT_) : \
[380]1201 $($(target)_DEPEND_) \
1202 $(_DEP_LINK_CMDS) \
1203 | \
1204 $($(target)_DEPORD_)
[776]1205 $$(call MSG_LINK,$(target),$$@,$(tool_do))
[696]1206 $$(QUIET)$$(RM) -f $(dep) $(out) $($(target)_OUTPUT_)
[412]1207
[380]1208$($(target)_CMDS_)
1209
[524]1210ifndef NO_LINK_CMDS_DEPS
[696]1211 $$(QUIET2)$$(APPEND) "$(dep)" 'define $(target)_CMDS_PREV_'
[770]1212ifeq ($(filter append-dash-n,$(KMK_FEATURES)),append-dash-n)
1213 $$(QUIET2)$$(APPEND) -v "$(dep)" '$(target)_CMDS_'
1214else
[696]1215 $$(QUIET2)$$(APPEND) "$(dep)" '$(subst $(NL),'$(NL)$(TAB)@$(APPEND) "$(dep)" ',$($(target)_CMDS_))'
[770]1216endif
[696]1217 $$(QUIET2)$$(APPEND) "$(dep)" 'endef'
[412]1218endif
[380]1219
[749]1220$(basename $(notdir $(out))): $(out)
[719]1221
[380]1222endef
1223
1224
1225## Generate the link & lib install rule
1226# @param $(target) Normalized target name.
1227# @param $(out) The build target.
1228# @param $(INSTARGET_$(target)) The installation targets.
1229# @param $(mode) The file mode (optional)
1230define def_link_install_rule
1231$(INSTARGET_$(target)) : $(out) | $(call DIRDEP,$(dir $(INSTARGET_$(target))))
[776]1232 $$(call MSG_INST_TRG,$(target),$(out),$$@)
[696]1233 $$(QUIET)$$(INSTALL) $$(if $(mode),-m $(mode)) $(out) $$@
[719]1234
1235ifdef KBUILD_DO_AUTO_INSTALL
[749]1236$(basename $(notdir $(out))): $(INSTARGET_$(target))
[719]1237endif
[380]1238endef
1239
1240
[73]1241## Generic macro for processing C, C++ and Assembly sources.
1242# @param $(target) Normalized target name.
1243# @param $(source) Source file name.
1244# @param $(type) Source type. {C,CXX,AS}
[221]1245# @param bld_type Build type.
1246# @param bld_trg Build target.
1247# @param bld_trg_arch Build target arch.
1248# @param bld_trg_cpu Build target cpu.
[729]1249def_target_source_c_cpp_asm_rc_new = $(kb-src-one )
[741]1250ifdef KMK_VERSION
[723]1251 def_target_source_c_cpp_asm_rc_var = def_target_source_c_cpp_asm_rc_new
[530]1252else
[723]1253 def_target_source_c_cpp_asm_rc_var = def_target_source_c_cpp_asm_rc_old
[530]1254endif
1255
[73]1256## Generic macro for processing all target sources.
[74]1257# @param $(target) Normalized target name.
[725]1258# @param $(defpath)
1259# @param much-more...
[73]1260define def_target_sources
1261#$ (warning def_target_sources)
1262# C sources
[353]1263type := C
[481]1264$(foreach source, $(filter %.c , $($(target)_SOURCES) $($(target)_SOURCES.$(bld_trg)) $($(target)_SOURCES.$(bld_trg).$(bld_trg_arch)) $($(target)_SOURCES.$(bld_trg_arch)) $($(target)_SOURCES.$(bld_trg_cpu)) $($(target)_SOURCES.$(bld_type)))\
[641]1265 ,$(eval $(value $(def_target_source_c_cpp_asm_rc_var))) )
[73]1266
1267# C++ sources
[353]1268type := CXX
[481]1269$(foreach source, $(filter %.cpp %.cxx %.xx, $($(target)_SOURCES) $($(target)_SOURCES.$(bld_trg)) $($(target)_SOURCES.$(bld_trg).$(bld_trg_arch)) $($(target)_SOURCES.$(bld_trg_arch)) $($(target)_SOURCES.$(bld_trg_cpu)) $($(target)_SOURCES.$(bld_type)))\
[641]1270 ,$(eval $(value $(def_target_source_c_cpp_asm_rc_var))) )
[73]1271
1272# ASM sources
[353]1273type := AS
[481]1274$(foreach source, $(filter %.asm %.s %.S , $($(target)_SOURCES) $($(target)_SOURCES.$(bld_trg)) $($(target)_SOURCES.$(bld_trg).$(bld_trg_arch)) $($(target)_SOURCES.$(bld_trg_arch)) $($(target)_SOURCES.$(bld_trg_cpu)) $($(target)_SOURCES.$(bld_type)))\
[641]1275 ,$(eval $(value $(def_target_source_c_cpp_asm_rc_var))) )
[353]1276
[641]1277# Resource sources
1278type := RC
1279$(foreach source, $(filter %.rc , $($(target)_SOURCES) $($(target)_SOURCES.$(bld_trg)) $($(target)_SOURCES.$(bld_trg).$(bld_trg_arch)) $($(target)_SOURCES.$(bld_trg_arch)) $($(target)_SOURCES.$(bld_trg_cpu)) $($(target)_SOURCES.$(bld_type)))\
1280 ,$(eval $(value $(def_target_source_c_cpp_asm_rc_var))) )
1281
[73]1282endef
1283
1284
[219]1285
[353]1286## Generic macro for generating the install rule(s) for a target
1287# and update the globals with default out.
[219]1288#
[353]1289# @param $(target) Normalized target name.
1290# @param $(out) The output file.
1291# @param $(definst) The default _INST value.
1292# @param $(typevar) The name of the variable with all the root targets of its type.
[729]1293# @remark Only library uses this now.
[353]1294define def_target_install_pluss
1295ifndef $(target)_NOINST
1296INSTARGET_$(target) := $(patsubst %/,%/$(notdir $(out)), \
1297 $(if $($(target)_INST), $(addprefix $(PATH_INS)/,$($(target)_INST)), $(definst)/))
[219]1298
[353]1299$(eval $(def_link_install_rule))
[239]1300
[827]1301_INSTALLS_FILES += $(INSTARGET_$(target))
[272]1302
[353]1303ifdef KBUILD_DO_AUTO_INSTALL
[579]1304$(typevar) += $(INSTARGET_$(target))
[219]1305else
[579]1306$(typevar) += $(out)
[219]1307endif
[353]1308else # _NOINST
[579]1309$(typevar) += $(out)
[353]1310endif
1311
[719]1312_OUT_FILES += $($(target)_OUTPUT_) $(out)
[905]1313_CLEAN_FILES += $($(target)_CLEAN) $($(target)_CLEAN.$(bld_trg)) $($(target)_CLEAN.$(bld_trg).$(bld_trg_arch)) $($(target)_CLEAN.$(bld_trg_arch)) $($(target)_CLEAN.$(bld_trg_cpu)) $($(target)_CLEAN.$(bld_type))
1314_DIRS += $($(target)_BLDDIRS) $($(target)_BLDDIRS.$(bld_trg)) $($(target)_BLDDIRS.$(bld_trg).$(bld_trg_arch)) $($(target)_BLDDIRS.$(bld_trg_arch)) $($(target)_BLDDIRS.$(bld_trg_cpu)) $($(target)_BLDDIRS.$(bld_type))
[353]1315_OBJS += $($(target)_OBJS_)
1316
[219]1317endef
1318
1319
1320
1321#
[72]1322# LIBRARIES
[73]1323#
[72]1324
1325## Library (one).
[74]1326# @param $(target) Normalized library (target) name.
[72]1327define def_lib
[145]1328# library basics
[222]1329## @todo prefix
[353]1330bld_type := $(firstword $($(target)_BLD_TYPE) $(BUILD_TYPE))
1331bld_trg := $(firstword $($(target)_BLD_TRG) $(BUILD_TARGET))
1332bld_trg_arch:= $(firstword $($(target)_BLD_TRG_ARCH) $(BUILD_TARGET_ARCH))
1333bld_trg_cpu := $(firstword $($(target)_BLD_TRG_CPU) $(BUILD_TARGET_CPU))
1334tool := $(call _TARGET_TOOL,$(target),AR)
[78]1335ifeq ($(tool),)
[353]1336$(error kBuild: Library target $(target) does not have a tool defined!)
[78]1337endif
[889]1338name := $(firstword\
1339 $($(target)_NAME.$(bld_trg).$(bld_trg_arch))\
1340 $($(target)_NAME.$(bld_trg_arch))\
1341 $($(target)_NAME.$(bld_trg))\
1342 $($(target)_NAME.$(bld_type))\
1343 $($(target)_NAME)\
1344 $(target))
1345outbase := $(call TARGET_BASE,$(name),$(target))
[743]1346ifndef PATH_$(target)
1347 PATH_$(target) := $(patsubst %/,%,$(dir $(outbase)))
1348else
1349 ifneq ($(PATH_$(target)),$(patsubst %/,%,$(dir $(outbase))))
1350 $(error kBuild internal error: PATH_$(target)=$(PATH_$(target)) expected $(patsubst %/,%,$(dir $(outbase))))
1351 endif
1352endif
[353]1353suff := $(firstword\
[481]1354 $($(target)_LIBSUFF.$(bld_trg).$(bld_trg_arch))\
[221]1355 $($(target)_LIBSUFF.$(bld_trg))\
[126]1356 $($(target)_LIBSUFF)\
[481]1357 $(TOOL_$(tool)_ARLIBSUFF.$(bld_trg).$(bld_trg_arch))\
[221]1358 $(TOOL_$(tool)_ARLIBSUFF.$(bld_trg))\
[126]1359 $(TOOL_$(tool)_ARLIBSUFF)\
[353]1360 $(SUFF_LIB))
1361out := $(outbase)$(suff)
1362TARGET_$(target) := $(out)
[719]1363$(target)_OBJS_ :=
[725]1364defpath := $($(target)_PATH)
[145]1365
1366# source -> object
[353]1367$(eval $(value def_target_sources))
[145]1368
1369# library linking
[353]1370tool := $(call _TARGET_TOOL,$(target),AR)
[889]1371name := $(firstword\
1372 $($(target)_NAME.$(bld_trg).$(bld_trg_arch))\
1373 $($(target)_NAME.$(bld_trg_arch))\
1374 $($(target)_NAME.$(bld_trg))\
1375 $($(target)_NAME.$(bld_type))\
1376 $($(target)_NAME)\
1377 $(target))
1378outbase := $(call TARGET_BASE,$(name),$(target))
[353]1379flags :=\
[74]1380 $(TOOL_$(tool)_ARFLAGS)\
[221]1381 $(TOOL_$(tool)_ARFLAGS.$(bld_type))\
[74]1382 $(ARFLAGS)\
[221]1383 $(ARFLAGS.$(bld_type))\
[74]1384 $($(target)_ARFLAGS)\
[481]1385 $($(target)_ARFLAGS.$(bld_type)) \
1386 $($(target)_ARFLAGS.$(bld_trg)) \
1387 $($(target)_ARFLAGS.$(bld_trg_arch)) \
1388 $($(target)_ARFLAGS.$(bld_trg).$(bld_trg_arch)) \
1389 $($(target)_ARFLAGS.$(bld_trg_cpu))
[353]1390othersrc := $(filter-out %.c %.cpp %.cxx %.cc %.s %.S %.asm %.o %.obj,\
1391 $($(target)_SOURCES) \
1392 $($(target)_SOURCES.$(bld_trg)) \
1393 $($(target)_SOURCES.$(bld_trg_arch)) \
[481]1394 $($(target)_SOURCES.$(bld_trg).$(bld_trg_arch)) \
[353]1395 $($(target)_SOURCES.$(bld_trg_cpu)) \
1396 $($(target)_SOURCES.$(bld_type)))
[643]1397objs = $(filter %.o %.obj, \
1398 $($(target)_SOURCES) \
1399 $($(target)_SOURCES.$(bld_trg)) \
1400 $($(target)_SOURCES.$(bld_trg_arch)) \
1401 $($(target)_SOURCES.$(bld_trg).$(bld_trg_arch)) \
1402 $($(target)_SOURCES.$(bld_trg_cpu)) \
1403 $($(target)_SOURCES.$(bld_type))) \
1404 $($(target)_OBJS_)
[353]1405dirdep := $(call DIRDEP,$(dir $(out)))
1406deps := $($(target)_DEPS)
[827]1407orderdeps := $($(target)_ORDERDEPS)
[72]1408
[725]1409# Adjust paths if we got a default path.
1410ifneq ($(defpath),)
[979]1411 objs := $(abspathex $(objs),$(defpath))
1412 deps := $(abspathex $(deps),$(defpath))
1413 orderdeps := $(abspathex $(orderdeps),$(defpath))
1414 othersrc := $(abspathex $(othersrc),$(defpath))
[725]1415endif
1416
[859]1417
1418# Custom pre-link actions.
1419ifdef $(target)_PRE_CMDS.$(bld_trg).$(bld_trg_arch).$(bld_type)
1420 pre_cmds := $($(target)_PRE_CMDS.$(bld_trg).$(bld_trg_arch).$(bld_type))
1421else ifdef $(target)_PRE_CMDS.$(bld_trg).$(bld_trg_arch)
1422 pre_cmds := $($(target)_PRE_CMDS.$(bld_trg).$(bld_trg_arch))
1423else ifdef $(target)_PRE_CMDS.$(bld_trg).$(bld_type)
1424 pre_cmds := $($(target)_PRE_CMDS.$(bld_trg).$(bld_type))
1425else ifdef $(target)_PRE_CMDS.$(bld_trg_arch)
1426 pre_cmds := $($(target)_PRE_CMDS.$(bld_trg_arch))
1427else ifdef $(target)_PRE_CMDS.$(bld_trg)
1428 pre_cmds := $($(target)_PRE_CMDS.$(bld_trg))
1429else ifdef $(target)_PRE_CMDS.$(bld_type)
1430 pre_cmds := $($(target)_PRE_CMDS.$(bld_type))
1431else ifdef $(target)_PRE_CMDS
1432 pre_cmds := $($(target)_PRE_CMDS)
1433else ifdef PRE_CMDS.$(bld_trg).$(bld_trg_arch).$(bld_type)
1434 pre_cmds := $(PRE_CMDS.$(bld_trg).$(bld_trg_arch).$(bld_type))
1435else ifdef PRE_CMDS.$(bld_trg).$(bld_trg_arch)
1436 pre_cmds := $(PRE_CMDS.$(bld_trg).$(bld_trg_arch))
1437else ifdef PRE_CMDS.$(bld_trg).$(bld_type)
1438 pre_cmds := $(PRE_CMDS.$(bld_trg).$(bld_type))
1439else ifdef PRE_CMDS.$(bld_trg_arch)
1440 pre_cmds := $(PRE_CMDS.$(bld_trg_arch))
1441else ifdef PRE_CMDS.$(bld_trg)
1442 pre_cmds := $(PRE_CMDS.$(bld_trg))
1443else ifdef PRE_CMDS.$(bld_type)
1444 pre_cmds := $(PRE_CMDS.$(bld_type))
1445else
1446 pre_cmds := $(PRE_CMDS)
1447endif
1448
1449# Custom post-link actions.
1450ifdef $(target)_POST_CMDS.$(bld_trg).$(bld_trg_arch).$(bld_type)
1451 post_cmds := $($(target)_POST_CMDS.$(bld_trg).$(bld_trg_arch).$(bld_type))
1452else ifdef $(target)_POST_CMDS.$(bld_trg).$(bld_trg_arch)
1453 post_cmds := $($(target)_POST_CMDS.$(bld_trg).$(bld_trg_arch))
1454else ifdef $(target)_POST_CMDS.$(bld_trg).$(bld_type)
1455 post_cmds := $($(target)_POST_CMDS.$(bld_trg).$(bld_type))
1456else ifdef $(target)_POST_CMDS.$(bld_trg_arch)
1457 post_cmds := $($(target)_POST_CMDS.$(bld_trg_arch))
1458else ifdef $(target)_POST_CMDS.$(bld_trg)
1459 post_cmds := $($(target)_POST_CMDS.$(bld_trg))
1460else ifdef $(target)_POST_CMDS.$(bld_type)
1461 post_cmds := $($(target)_POST_CMDS.$(bld_type))
1462else ifdef $(target)_POST_CMDS
1463 post_cmds := $($(target)_POST_CMDS)
1464else ifdef POST_CMDS.$(bld_trg).$(bld_trg_arch).$(bld_type)
1465 post_cmds := $(POST_CMDS.$(bld_trg).$(bld_trg_arch).$(bld_type))
1466else ifdef POST_CMDS.$(bld_trg).$(bld_trg_arch)
1467 post_cmds := $(POST_CMDS.$(bld_trg).$(bld_trg_arch))
1468else ifdef POST_CMDS.$(bld_trg).$(bld_type)
1469 post_cmds := $(POST_CMDS.$(bld_trg).$(bld_type))
1470else ifdef POST_CMDS.$(bld_trg_arch)
1471 post_cmds := $(POST_CMDS.$(bld_trg_arch))
1472else ifdef POST_CMDS.$(bld_trg)
1473 post_cmds := $(POST_CMDS.$(bld_trg))
1474else ifdef POST_CMDS.$(bld_type)
1475 post_cmds := $(POST_CMDS.$(bld_type))
1476else
1477 post_cmds := $(POST_CMDS)
1478endif
1479
[380]1480# dependency file
1481dep := $(out)$(SUFF_DEP)
[524]1482ifndef NO_LINK_CMDS_DEPS
[893]1483 _DEPFILES_INCLUDED += $(dep)
1484 $(eval includedep $(dep))
[380]1485endif
[72]1486
[380]1487# check that the tool is defined.
1488ifndef TOOL_$(tool)_LINK_LIBRARY_CMDS
1489$(warning kBuild: tools: \
[481]1490 1 $($(target)_$(source)TOOL.$(bld_trg).$(bld_trg_arch)) \
1491 2 $($(target)_$(source)TOOL.$(bld_trg)) \
1492 3 $($(target)_$(source)TOOL) \
1493 4 $($(target)_TOOL.$(bld_trg).$(bld_trg_arch)) \
1494 5 $($(target)_TOOL.$(bld_trg)) \
1495 6 $($(target)_TOOL) \
1496 7 $($(source)TOOL) \
1497 8 $($(source)TOOL.$(bld_trg).$(bld_trg_arch)) \
1498 9 $($(source)TOOL.$(bld_trg)) \
1499 10 $(TOOL.$(bld_trg).$(bld_trg_arch)) \
1500 11 $(TOOL.$(bld_trg)) \
1501 12 $(TOOL) )
[380]1502$(error kBuild: TOOL_$(tool)_LINK_LIBRARY_CMDS isn't defined! target=$(target) )
1503endif
1504
1505# call the tool
1506$(target)_CMDS_ := $(TOOL_$(tool)_LINK_LIBRARY_CMDS)
[859]1507ifneq ($(pre_cmds),)
1508 $(target)_CMDS_ := $(TAB)$(pre_cmds)$(NL)$(TAB)$($(target)_CMDS_)
1509endif
1510ifneq ($(post_cmds),)
1511 $(target)_CMDS_ := $($(target)_CMDS_)$(NL)$(TAB)$(post_cmds)
1512endif
[380]1513$(target)_OUTPUT_ := $(TOOL_$(tool)_LINK_LIBRARY_OUTPUT)
1514$(target)_DEPEND_ := $(TOOL_$(tool)_LINK_LIBRARY_DEPEND) $(deps) $(objs)
[827]1515$(target)_DEPORD_ := $(TOOL_$(tool)_LINK_LIBRARY_DEPORD) $(dirdep) $(orderdeps)
[380]1516
[412]1517# generate the link rule.
[380]1518$(eval $(def_link_rule))
1519
[353]1520# installing and globals
1521$(eval $(value def_target_install_pluss))
[72]1522endef
1523
1524# Process libraries
[859]1525definst := $(PATH_LIB)
1526typevar := _LIBS
[776]1527tool_do := LINK_LIBRARY
[380]1528mode := 0644
[481]1529$(foreach target, $(LIBRARIES) $(LIBRARIES.$(BUILD_TARGET)) $(LIBRARIES.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)), $(eval $(value def_lib)))
[72]1530
1531
1532#
[353]1533# Link operations.
[72]1534#
1535
[353]1536##
1537# Link prolog
1538#
1539# @param $(target) Normalized target name.
1540# @param $(EXT) EXE,DLL,SYS.
1541# @param $(definst) The default _INST value.
1542# @param $(typevar) The name of the variable with all the root targets of its type.
[380]1543define def_link_common
[353]1544# basics
1545bld_type := $(firstword $($(target)_BLD_TYPE) $(BUILD_TYPE))
1546bld_trg := $(firstword $($(target)_BLD_TRG) $(BUILD_$(bld_trg_base_var)))
1547bld_trg_arch:= $(firstword $($(target)_BLD_TRG_ARCH) $(BUILD_$(bld_trg_base_var)_ARCH))
1548bld_trg_cpu := $(firstword $($(target)_BLD_TRG_CPU) $(BUILD_$(bld_trg_base_var)_CPU))
[145]1549
[353]1550tool := $(call _TARGET_TOOL,$(target),LD)
[889]1551name := $(firstword\
1552 $($(target)_NAME.$(bld_trg).$(bld_trg_arch))\
1553 $($(target)_NAME.$(bld_trg_arch))\
1554 $($(target)_NAME.$(bld_trg))\
1555 $($(target)_NAME.$(bld_type))\
1556 $($(target)_NAME)\
1557 $(target))
1558outbase := $(call TARGET_BASE,$(name),$(target))
[743]1559ifndef PATH_$(target)
1560 PATH_$(target) := $(patsubst %/,%,$(dir $(outbase)))
1561else
1562 ifneq ($(PATH_$(target)),$(patsubst %/,%,$(dir $(outbase))))
1563 $(error kBuild internal error: PATH_$(target)=$(PATH_$(target)) expected $(patsubst %/,%,$(dir $(outbase))))
1564 endif
1565endif
[353]1566suff := $(firstword \
1567 $($(target)_$(EXT)SUFF) \
1568 $($(target)_$(EXT)SUFF) \
1569 $(TOOL_$(tool)_LD$(EXT)SUFF) \
1570 $($(EXTPRE)SUFF_$(EXT)))
1571out := $(outbase)$(suff)
1572TARGET_$(target) := $(out)
[719]1573$(target)_OBJS_ :=
[725]1574defpath := $($(target)_PATH)
[353]1575
[145]1576# source -> object
[353]1577$(eval $(value def_target_sources))
[145]1578
[744]1579# more link stuff.
[353]1580tool := $(call _TARGET_TOOL,$(target),LD)
[889]1581name := $(firstword\
1582 $($(target)_NAME.$(bld_trg).$(bld_trg_arch))\
1583 $($(target)_NAME.$(bld_trg_arch))\
1584 $($(target)_NAME.$(bld_trg))\
1585 $($(target)_NAME.$(bld_type))\
1586 $($(target)_NAME)\
1587 $(target))
1588outbase := $(call TARGET_BASE,$(name),$(target))
[353]1589flags :=\
[74]1590 $(TOOL_$(tool)_LDFLAGS)\
[221]1591 $(TOOL_$(tool)_LDFLAGS.$(bld_type))\
1592 $(TOOL_$(tool)_LDFLAGS.$(bld_trg))\
1593 $(TOOL_$(tool)_LDFLAGS.$(bld_trg_arch))\
[481]1594 $(TOOL_$(tool)_LDFLAGS.$(bld_trg).$(bld_trg_arch))\
[221]1595 $(TOOL_$(tool)_LDFLAGS.$(bld_trg_cpu))\
[74]1596 $(LDFLAGS)\
[221]1597 $(LDFLAGS.$(bld_type))\
1598 $(LDFLAGS.$(bld_trg))\
1599 $(LDFLAGS.$(bld_trg_arch))\
[481]1600 $(LDFLAGS.$(bld_trg).$(bld_trg_arch))\
[221]1601 $(LDFLAGS.$(bld_trg_cpu))\
[74]1602 $($(target)_LDFLAGS)\
[221]1603 $($(target)_LDFLAGS.$(bld_type))\
1604 $($(target)_LDFLAGS.$(bld_trg))\
1605 $($(target)_LDFLAGS.$(bld_trg_arch))\
[481]1606 $($(target)_LDFLAGS.$(bld_trg).$(bld_trg_arch))\
[353]1607 $($(target)_LDFLAGS.$(bld_trg_cpu))
1608othersrc := $(filter-out %.c %.cpp %.cxx %.cc %.s %.S %.asm %.o %.obj,\
1609 $($(target)_SOURCES)\
1610 $($(target)_SOURCES.$(bld_trg)) \
1611 $($(target)_SOURCES.$(bld_trg_arch)) \
[481]1612 $($(target)_SOURCES.$(bld_trg).$(bld_trg_arch)) \
[353]1613 $($(target)_SOURCES.$(bld_trg_cpu)) \
1614 $($(target)_SOURCES.$(bld_type)))
[643]1615objs = $(filter %.o %.obj, \
1616 $($(target)_SOURCES) \
1617 $($(target)_SOURCES.$(bld_trg)) \
1618 $($(target)_SOURCES.$(bld_trg_arch)) \
1619 $($(target)_SOURCES.$(bld_trg).$(bld_trg_arch)) \
1620 $($(target)_SOURCES.$(bld_trg_cpu)) \
1621 $($(target)_SOURCES.$(bld_type))) \
1622 $($(target)_OBJS_)
[353]1623libs :=\
[221]1624 $($(target)_LIBS.$(bld_trg_cpu))\
[481]1625 $($(target)_LIBS.$(bld_trg).$(bld_trg_arch))\
[221]1626 $($(target)_LIBS.$(bld_trg_arch))\
1627 $($(target)_LIBS.$(bld_trg))\
1628 $($(target)_LIBS.$(bld_type))\
[74]1629 $($(target)_LIBS)\
[592]1630 $(foreach sdk, $($(target)_SDKS.$(bld_trg).$(bld_trg_arch)) \
1631 $($(target)_SDKS.$(bld_trg_arch)) \
1632 $($(target)_SDKS.$(bld_trg)) \
1633 $($(target)_SDKS.$(bld_type)) \
1634 $($(target)_SDKS),\
[353]1635 $(SDK_$(sdk)_LIBS.$(bld_trg_cpu))\
[481]1636 $(SDK_$(sdk)_LIBS.$(bld_trg).$(bld_trg_arch))\
[353]1637 $(SDK_$(sdk)_LIBS.$(bld_trg_arch))\
1638 $(SDK_$(sdk)_LIBS.$(bld_trg))\
1639 $(SDK_$(sdk)_LIBS.$(bld_type))\
1640 $(SDK_$(sdk)_LIBS))\
[221]1641 $(LIBS.$(bld_trg_cpu))\
[481]1642 $(LIBS.$(bld_trg).$(bld_trg_arch))\
[221]1643 $(LIBS.$(bld_trg_arch))\
1644 $(LIBS.$(bld_trg))\
1645 $(LIBS.$(bld_type))\
[74]1646 $(LIBS)\
[592]1647 $(foreach sdk, $(SDKS.$(bld_trg).$(bld_trg_arch)) \
1648 $(SDKS.$(bld_trg_arch)) \
1649 $(SDKS.$(bld_trg)) \
1650 $(SDKS.$(bld_type)) \
1651 $(SDKS),\
[353]1652 $(SDK_$(sdk)_LIBS.$(bld_trg_cpu))\
[481]1653 $(SDK_$(sdk)_LIBS.$(bld_trg).$(bld_trg_arch))\
[353]1654 $(SDK_$(sdk)_LIBS.$(bld_trg_arch))\
1655 $(SDK_$(sdk)_LIBS.$(bld_trg))\
1656 $(SDK_$(sdk)_LIBS.$(bld_type))\
1657 $(SDK_$(sdk)_LIBS))\
[221]1658 $(TOOL_$(tool)_LIBS.$(bld_trg_cpu))\
[481]1659 $(TOOL_$(tool)_LIBS.$(bld_trg).$(bld_trg_arch))\
[221]1660 $(TOOL_$(tool)_LIBS.$(bld_trg_arch))\
1661 $(TOOL_$(tool)_LIBS.$(bld_trg))\
1662 $(TOOL_$(tool)_LIBS.$(bld_type))\
[353]1663 $(TOOL_$(tool)_LIBS)
1664libpath :=\
[221]1665 $($(target)_LIBPATH.$(bld_trg_cpu))\
[481]1666 $($(target)_LIBPATH.$(bld_trg).$(bld_trg_arch))\
[221]1667 $($(target)_LIBPATH.$(bld_trg_arch))\
1668 $($(target)_LIBPATH.$(bld_trg))\
1669 $($(target)_LIBPATH.$(bld_type))\
[74]1670 $($(target)_LIBPATH)\
[592]1671 $(foreach sdk, $($(target)_SDKS.$(bld_trg).$(bld_trg_arch)) \
1672 $($(target)_SDKS.$(bld_trg_arch)) \
1673 $($(target)_SDKS.$(bld_trg)) \
1674 $($(target)_SDKS.$(bld_type)) \
1675 $($(target)_SDKS),\
[353]1676 $(SDK_$(sdk)_LIBPATH.$(bld_trg_cpu))\
[481]1677 $(SDK_$(sdk)_LIBPATH.$(bld_trg).$(bld_trg_arch))\
[353]1678 $(SDK_$(sdk)_LIBPATH.$(bld_trg_arch))\
1679 $(SDK_$(sdk)_LIBPATH.$(bld_trg))\
1680 $(SDK_$(sdk)_LIBPATH.$(bld_type))\
1681 $(SDK_$(sdk)_LIBPATH))\
[221]1682 $(LIBPATH.$(bld_trg_cpu))\
[481]1683 $(LIBPATH.$(bld_trg).$(bld_trg_arch))\
[221]1684 $(LIBPATH.$(bld_trg_arch))\
1685 $(LIBPATH.$(bld_trg))\
1686 $(LIBPATH.$(bld_type))\
[74]1687 $(LIBPATH)\
[592]1688 $(foreach sdk, $(SDKS.$(bld_trg).$(bld_trg_arch)) \
1689 $(SDKS.$(bld_trg_arch)) \
1690 $(SDKS.$(bld_trg)) \
1691 $(SDKS.$(bld_type)) \
1692 $(SDKS),\
[353]1693 $(SDK_$(sdk)_LIBPATH.$(bld_trg_cpu))\
[481]1694 $(SDK_$(sdk)_LIBPATH.$(bld_trg).$(bld_trg_arch))\
[353]1695 $(SDK_$(sdk)_LIBPATH.$(bld_trg_arch))\
1696 $(SDK_$(sdk)_LIBPATH.$(bld_trg))\
1697 $(SDK_$(sdk)_LIBPATH.$(bld_type))\
1698 $(SDK_$(sdk)_LIBPATH))\
[221]1699 $(TOOL_$(tool)_LIBPATH.$(bld_trg_cpu))\
[481]1700 $(TOOL_$(tool)_LIBPATH.$(bld_trg).$(bld_trg_arch))\
[221]1701 $(TOOL_$(tool)_LIBPATH.$(bld_trg_arch))\
1702 $(TOOL_$(tool)_LIBPATH.$(bld_trg))\
1703 $(TOOL_$(tool)_LIBPATH.$(bld_type))\
[353]1704 $(TOOL_$(tool)_LIBPATH)
1705dirdep := $(call DIRDEP,$(dir $(out)))
1706deps := $($(target)_DEPS)
[827]1707orderdeps := $($(target)_ORDERDEPS)
[353]1708
[725]1709# Adjust paths if we got a default path.
1710ifneq ($(defpath),)
[979]1711 libpath := $(abspathex $(libpath),$(defpath))
1712 objs := $(abspathex $(objs),$(defpath))
1713 deps := $(abspathex $(deps),$(defpath))
1714 orderdeps := $(abspathex $(orderdeps),$(defpath))
1715 othersrc := $(abspathex $(othersrc),$(defpath))
[725]1716 # libs are not subject to this because of the the -l<lib> stuff. Use $(<target>_PATH)/lib if relative to current dir!
1717endif
1718
[859]1719# Custom pre-link actions.
1720ifdef $(target)_PRE_CMDS.$(bld_trg).$(bld_trg_arch).$(bld_type)
1721 pre_cmds := $($(target)_PRE_CMDS.$(bld_trg).$(bld_trg_arch).$(bld_type))
1722else ifdef $(target)_PRE_CMDS.$(bld_trg).$(bld_trg_arch)
1723 pre_cmds := $($(target)_PRE_CMDS.$(bld_trg).$(bld_trg_arch))
1724else ifdef $(target)_PRE_CMDS.$(bld_trg).$(bld_type)
1725 pre_cmds := $($(target)_PRE_CMDS.$(bld_trg).$(bld_type))
1726else ifdef $(target)_PRE_CMDS.$(bld_trg_arch)
1727 pre_cmds := $($(target)_PRE_CMDS.$(bld_trg_arch))
1728else ifdef $(target)_PRE_CMDS.$(bld_trg)
1729 pre_cmds := $($(target)_PRE_CMDS.$(bld_trg))
1730else ifdef $(target)_PRE_CMDS.$(bld_type)
1731 pre_cmds := $($(target)_PRE_CMDS.$(bld_type))
1732else ifdef $(target)_PRE_CMDS
1733 pre_cmds := $($(target)_PRE_CMDS)
1734else ifdef PRE_CMDS.$(bld_trg).$(bld_trg_arch).$(bld_type)
1735 pre_cmds := $(PRE_CMDS.$(bld_trg).$(bld_trg_arch).$(bld_type))
1736else ifdef PRE_CMDS.$(bld_trg).$(bld_trg_arch)
1737 pre_cmds := $(PRE_CMDS.$(bld_trg).$(bld_trg_arch))
1738else ifdef PRE_CMDS.$(bld_trg).$(bld_type)
1739 pre_cmds := $(PRE_CMDS.$(bld_trg).$(bld_type))
1740else ifdef PRE_CMDS.$(bld_trg_arch)
1741 pre_cmds := $(PRE_CMDS.$(bld_trg_arch))
1742else ifdef PRE_CMDS.$(bld_trg)
1743 pre_cmds := $(PRE_CMDS.$(bld_trg))
1744else ifdef PRE_CMDS.$(bld_type)
1745 pre_cmds := $(PRE_CMDS.$(bld_type))
1746else
1747 pre_cmds := $(PRE_CMDS)
1748endif
[72]1749
[859]1750# Custom post-link actions.
1751ifdef $(target)_POST_CMDS.$(bld_trg).$(bld_trg_arch).$(bld_type)
1752 post_cmds := $($(target)_POST_CMDS.$(bld_trg).$(bld_trg_arch).$(bld_type))
1753else ifdef $(target)_POST_CMDS.$(bld_trg).$(bld_trg_arch)
1754 post_cmds := $($(target)_POST_CMDS.$(bld_trg).$(bld_trg_arch))
1755else ifdef $(target)_POST_CMDS.$(bld_trg).$(bld_type)
1756 post_cmds := $($(target)_POST_CMDS.$(bld_trg).$(bld_type))
1757else ifdef $(target)_POST_CMDS.$(bld_trg_arch)
1758 post_cmds := $($(target)_POST_CMDS.$(bld_trg_arch))
1759else ifdef $(target)_POST_CMDS.$(bld_trg)
1760 post_cmds := $($(target)_POST_CMDS.$(bld_trg))
1761else ifdef $(target)_POST_CMDS.$(bld_type)
1762 post_cmds := $($(target)_POST_CMDS.$(bld_type))
1763else ifdef $(target)_POST_CMDS
1764 post_cmds := $($(target)_POST_CMDS)
1765else ifdef POST_CMDS.$(bld_trg).$(bld_trg_arch).$(bld_type)
1766 post_cmds := $(POST_CMDS.$(bld_trg).$(bld_trg_arch).$(bld_type))
1767else ifdef POST_CMDS.$(bld_trg).$(bld_trg_arch)
1768 post_cmds := $(POST_CMDS.$(bld_trg).$(bld_trg_arch))
1769else ifdef POST_CMDS.$(bld_trg).$(bld_type)
1770 post_cmds := $(POST_CMDS.$(bld_trg).$(bld_type))
1771else ifdef POST_CMDS.$(bld_trg_arch)
1772 post_cmds := $(POST_CMDS.$(bld_trg_arch))
1773else ifdef POST_CMDS.$(bld_trg)
1774 post_cmds := $(POST_CMDS.$(bld_trg))
1775else ifdef POST_CMDS.$(bld_type)
1776 post_cmds := $(POST_CMDS.$(bld_type))
1777else
1778 post_cmds := $(POST_CMDS)
1779endif
1780
[353]1781# installation targets
1782ifndef $(target)_NOINST
1783INSTARGET_$(target) := $(patsubst %/,%/$(notdir $(out)), \
1784 $(if $($(target)_INST), $(addprefix $(PATH_INS)/,$($(target)_INST)), $(definst)/))
1785ifdef KBUILD_DO_AUTO_INSTALL
1786$(typevar) += $(INSTARGET_$(target))
1787else
1788$(typevar) += $(out)
1789endif
1790# generate the install rule
1791$(eval $(def_link_install_rule))
1792
1793else # NOINST
1794INSTARGET_$(target) :=
1795$(typevar) += $(out)
1796endif # NOINST
1797
[380]1798# dependency file
1799dep := $(outbase)$(SUFF_DEP)
[524]1800ifndef NO_LINK_CMDS_DEPS
[893]1801 _DEPFILES_INCLUDED += $(dep)
1802 $(eval includedep $(dep))
[380]1803endif
[353]1804
[380]1805# check that the tool is defined.
1806ifndef TOOL_$(tool)_$(tool_do)_CMDS
1807$(warning kBuild: tools: \
[481]1808 1 $($(target)_$(source)TOOL.$(bld_trg).$(bld_trg_arch)) \
1809 2 $($(target)_$(source)TOOL.$(bld_trg)) \
1810 3 $($(target)_$(source)TOOL) \
1811 4 $($(target)_TOOL.$(bld_trg).$(bld_trg_arch)) \
1812 5 $($(target)_TOOL.$(bld_trg)) \
1813 6 $($(target)_TOOL) \
1814 7 $($(source)TOOL.$(bld_trg).$(bld_trg_arch)) \
1815 8 $($(source)TOOL.$(bld_trg)) \
1816 9 $($(source)TOOL) \
1817 10 $(TOOL.$(bld_trg).$(bld_trg_arch)) \
1818 11 $(TOOL.$(bld_trg)) \
1819 12 $(TOOL) )
[380]1820$(error kBuild: TOOL_$(tool)_$(tool_do)_CMDS isn't defined! target=$(target) )
1821endif
[353]1822
[380]1823# call the tool
1824$(target)_CMDS_ := $(TOOL_$(tool)_$(tool_do)_CMDS)
[859]1825ifneq ($(pre_cmds),)
1826 $(target)_CMDS_ := $(TAB)$(pre_cmds)$(NL)$(TAB)$($(target)_CMDS_)
1827endif
1828ifneq ($(post_cmds),)
1829 $(target)_CMDS_ := $($(target)_CMDS_)$(NL)$(TAB)$(post_cmds)
1830endif
[380]1831$(target)_OUTPUT_ := $(TOOL_$(tool)_$(tool_do)_OUTPUT)
1832$(target)_DEPEND_ := $(TOOL_$(tool)_$(tool_do)_DEPEND) $(deps) $(objs)
[827]1833$(target)_DEPORD_ := $(TOOL_$(tool)_$(tool_do)_DEPORD) $(dirdep) $(orderdeps)
[353]1834
[412]1835# generate the link rule.
[380]1836$(eval $(def_link_rule))
1837
[412]1838
[380]1839# Update globals.
[579]1840_OBJS += $($(target)_OBJS_)
1841_OUT_FILES += $($(target)_OUTPUT_) $(out)
[905]1842_CLEAN_FILES += $($(target)_CLEAN) $($(target)_CLEAN.$(bld_trg)) $($(target)_CLEAN.$(bld_trg).$(bld_trg_arch)) $($(target)_CLEAN.$(bld_trg_arch)) $($(target)_CLEAN.$(bld_trg_cpu)) $($(target)_CLEAN.$(bld_type))
1843_DIRS += $($(target)_BLDDIRS) $($(target)_BLDDIRS.$(bld_trg)) $($(target)_BLDDIRS.$(bld_trg).$(bld_trg_arch)) $($(target)_BLDDIRS.$(bld_trg_arch)) $($(target)_BLDDIRS.$(bld_trg_cpu)) $($(target)_BLDDIRS.$(bld_type))
[827]1844_INSTALLS_FILES += $(INSTARGET_$(target))
[353]1845
1846endef
1847
1848
1849#
1850# BLDPROGS
1851#
1852
1853## Build program (one).
1854# @param $(target) Normalized target (program) name.
1855define def_bldprog
1856
1857# set NOINST if not forced installation.
1858ifndef $(target)_INST
1859$(target)_NOINST := 1
1860endif
1861
[380]1862# do the usual stuff.
1863$(eval $(value def_link_common))
[353]1864
1865endef
1866
1867# Process build programs.
1868EXT := EXE
1869EXTPRE := HOST
[380]1870tool_do := LINK_PROGRAM
[353]1871definst := $(PATH_BIN)
1872typevar := _BLDPROGS
[380]1873mode := 0755
[353]1874bld_trg_base_var := PLATFORM
[481]1875$(foreach target, $(BLDPROGS) $(BLDPROGS.$(BUILD_PLATFORM)) $(BLDPROGS.$(BUILD_PLATFORM).$(BUILD_PLATFORM_ARCH)), $(eval $(value def_bldprog)))
[353]1876
1877
1878
1879#
1880# DLLS
1881#
1882
[189]1883# Process dlls
[353]1884EXT := DLL
1885EXTPRE :=
[380]1886tool_do := LINK_DLL
[353]1887definst := $(PATH_DLL)
1888typevar := _DLLS
[830]1889mode := 0644
[353]1890bld_trg_base_var := TARGET
[481]1891$(foreach target, $(DLLS) $(DLLS.$(BUILD_TARGET)) $(DLLS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)), $(eval $(value def_link_common)))
[74]1892
1893
[72]1894#
[830]1895# IMPORT LIBRARIES
[72]1896#
[219]1897# - On OS/2 and windows these are libraries.
[189]1898# - On other platforms they are fake DLLs.
[830]1899#
1900EXTPRE :=
1901typevar := _IMPORT_LIBS
1902mode := 0644
1903bld_trg_base_var := TARGET
[481]1904ifeq ($(filter-out nt os2 win win64 win32,$(BUILD_TARGET)),)
[830]1905 EXT := LIB
1906 tool_do := LINK_LIBRARY
1907 definst := $(PATH_LIB)
1908 $(foreach target, $(IMPORT_LIBS) $(IMPORT_LIBS.$(BUILD_TARGET)) $(IMPORT_LIBS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)), $(eval $(value def_lib)))
[189]1909else
[830]1910 EXT := DLL
1911 tool_do := LINK_DLL
1912 definst := $(PATH_DLL)
1913 $(foreach target, $(IMPORT_LIBS) $(IMPORT_LIBS.$(BUILD_TARGET)) $(IMPORT_LIBS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)), $(eval $(value def_link_common)))
[189]1914endif
[72]1915
[189]1916
1917#
1918# PROGRAMS
1919#
1920
[353]1921# Process programs
1922EXT := EXE
1923EXTPRE :=
[380]1924tool_do := LINK_PROGRAM
[353]1925definst := $(PATH_BIN)
1926typevar := _PROGRAMS
[380]1927mode := 0755
[353]1928bld_trg_base_var := TARGET
[481]1929$(foreach target, $(PROGRAMS) $(PROGRAMS.$(BUILD_TARGET)) $(PROGRAMS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)), $(eval $(value def_link_common)))
[130]1930
1931
[189]1932
[72]1933#
[83]1934# SYSMODS
[72]1935#
1936
[130]1937# Process sysmods
[353]1938EXT := SYS
1939EXTPRE :=
[380]1940tool_do := LINK_SYSMOD
[353]1941definst := $(PATH_SYS)
1942typevar := _SYSMODS
[380]1943mode := 0644
[353]1944bld_trg_base_var := TARGET
[481]1945$(foreach target, $(SYSMODS) $(SYSMODS.$(BUILD_TARGET)) $(SYSMODS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)), $(eval $(value def_link_common)))
[83]1946
1947
[72]1948#
1949# OTHERS
1950#
[481]1951_OTHERS = $(OTHERS) $(OTHERS.$(BUILD_TARGET)) $(OTHERS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH))
[72]1952
1953
[353]1954#
1955# INSTALLS
1956#
[72]1957
[353]1958## generate the install rule
1959define def_install_src_rule
1960# the install rule
1961$(insdst) : $(srcsrc) | $(call DIRDEP,$(dir $(insdst)))
[776]1962 $$(call MSG_INST_FILE,$(srcsrc),$(insdst))
[696]1963 $$(QUIET)$$(if $$(filter $(INSTALL),$(inscmd)),,$$(RM) -f $$@)
1964 $$(QUIET)$(inscmd)
[353]1965endef
1966
1967## install one file
1968define def_install_src
1969
1970# deal with '=>' in the source file name.
1971srcdst := $(subst =>, ,$(src))
1972srcsrc := $(firstword $(srcdst))
[424]1973srcdstdir := $(dir $(word 2,$(srcdst)))
[353]1974srcdst := $(word $(words $(srcdst)),$(srcdst))
1975
1976# _INSTFUN
1977ifdef $(srcsrc)_INSTFUN
[725]1978 instfun := $(srcsrc)_INSTFUN
[353]1979else
[725]1980 ifdef $(target)_INSTFUN
1981 instfun := $(target)_INSTFUN
1982 else
1983 instfun := _INSTALL_FILE
1984 endif
[353]1985endif
1986
1987# _INST
1988ifdef $(srcsrc)_INST
[725]1989 inst := $(patsubst %/,%,$($(srcsrc)_INST))/$(dir $(srcdstdir))
[353]1990else
[725]1991 ifdef $(target)_INST
1992 inst := $(patsubst %/,%,$($(target)_INST))/$(dir $(srcdstdir))
1993 else
1994 inst := $(dir $(srcdstdir))
1995 endif
[353]1996endif
1997
1998# calc target
[380]1999insdst := $(call $(instfun),$(srcdst),$(target),$(inst),$(PATH_INS))
[424]2000#$(warning instfun=$(instfun) srcdst=$(srcdst) target=$(target) inst=$(inst) => insdst=$(insdst))
[353]2001
[414]2002# mode, uid and gid
2003mode := $(firstword \
[481]2004 $($(target)_$(srcsrc)_MODE.$(bld_trg).$(bld_trg_arch)) \
[414]2005 $($(target)_$(srcsrc)_MODE.$(bld_trg)) \
2006 $($(target)_$(srcsrc)_MODE) \
[481]2007 $($(target)_$(srcdst)_MODE.$(bld_trg).$(bld_trg_arch)) \
[414]2008 $($(target)_$(srcdst)_MODE.$(bld_trg)) \
2009 $($(target)_$(srcdst)_MODE) \
[481]2010 $($(srcsrc)_MODE.$(bld_trg).$(bld_trg_arch)) \
[414]2011 $($(srcsrc)_MODE.$(bld_trg)) \
2012 $($(srcsrc)_MODE) \
[481]2013 $($(srcdst)_MODE.$(bld_trg).$(bld_trg_arch)) \
[414]2014 $($(srcdst)_MODE.$(bld_trg)) \
2015 $($(srcdst)_MODE) \
[481]2016 $($(target)_MODE.$(bld_trg).$(bld_trg_arch)) \
[414]2017 $($(target)_MODE.$(bld_trg)) \
2018 $($(target)_MODE))
2019uid := $(firstword \
[481]2020 $($(target)_$(srcsrc)_UID.$(bld_trg).$(bld_trg_arch)) \
[414]2021 $($(target)_$(srcsrc)_UID.$(bld_trg)) \
2022 $($(target)_$(srcsrc)_UID) \
[481]2023 $($(target)_$(srcdst)_UID.$(bld_trg).$(bld_trg_arch)) \
[414]2024 $($(target)_$(srcdst)_UID.$(bld_trg)) \
2025 $($(target)_$(srcdst)_UID) \
[481]2026 $($(srcsrc)_UID.$(bld_trg).$(bld_trg_arch)) \
[414]2027 $($(srcsrc)_UID.$(bld_trg)) \
2028 $($(srcsrc)_UID) \
[481]2029 $($(srcdst)_UID.$(bld_trg).$(bld_trg_arch)) \
[414]2030 $($(srcdst)_UID.$(bld_trg)) \
2031 $($(srcdst)_UID) \
[481]2032 $($(target)_UID.$(bld_trg).$(bld_trg_arch)) \
[414]2033 $($(target)_UID.$(bld_trg)) \
2034 $($(target)_UID))
2035gid := $(firstword \
[481]2036 $($(target)_$(srcsrc)_GID.$(bld_trg).$(bld_trg_arch)) \
[414]2037 $($(target)_$(srcsrc)_GID.$(bld_trg)) \
2038 $($(target)_$(srcsrc)_GID) \
[481]2039 $($(target)_$(srcdst)_GID.$(bld_trg).$(bld_trg_arch)) \
[414]2040 $($(target)_$(srcdst)_GID.$(bld_trg)) \
2041 $($(target)_$(srcdst)_GID) \
[481]2042 $($(srcsrc)_GID.$(bld_trg).$(bld_trg_arch)) \
[414]2043 $($(srcsrc)_GID.$(bld_trg)) \
2044 $($(srcsrc)_GID) \
[481]2045 $($(srcdst)_GID.$(bld_trg).$(bld_trg_arch)) \
[414]2046 $($(srcdst)_GID.$(bld_trg)) \
2047 $($(srcdst)_GID) \
[481]2048 $($(target)_GID.$(bld_trg).$(bld_trg_arch)) \
[414]2049 $($(target)_GID.$(bld_trg)) \
2050 $($(target)_GID))
[830]2051flags := \
2052 $($(target)_IFFLAGS) \
2053 $($(target)_IFFLAGS.$(bld_trg)) \
2054 $($(target)_IFFLAGS.$(bld_trg).$(bld_trg_arch)) \
2055 $($(srcdst)_IFFLAGS) \
2056 $($(srcdst)_IFFLAGS.$(bld_trg)) \
2057 $($(srcdst)_IFFLAGS.$(bld_trg).$(bld_trg_arch)) \
2058 $($(srcsrc)_IFFLAGS) \
2059 $($(srcsrc)_IFFLAGS.$(bld_trg)) \
2060 $($(srcsrc)_IFFLAGS.$(bld_trg).$(bld_trg_arch)) \
2061 $($(target)_$(srcdst)_IFFLAGS) \
2062 $($(target)_$(srcdst)_IFFLAGS.$(bld_trg)) \
2063 $($(target)_$(srcdst)_IFFLAGS.$(bld_trg).$(bld_trg_arch)) \
2064 $($(target)_$(srcsrc)_IFFLAGS) \
2065 $($(target)_$(srcsrc)_IFFLAGS.$(bld_trg)) \
2066 $($(target)_$(srcsrc)_IFFLAGS.$(bld_trg).$(bld_trg_arch))
[414]2067
[725]2068
2069# Adjust the source if we got a default PATH. (This must be done this late!)
2070ifdef $(target)_PATH
[979]2071 srcsrc := $(abspathex $(srcsrc),$($(target)_PATH))
[725]2072endif
2073
[353]2074# create the command
2075ifdef $(srcsrc)_INSTALLER
[830]2076 inscmd := $(call $(srcsrc)_INSTALLER,$(srcsrc),$(insdst),$(target),$(flags))
2077else ifdef $(target)_INSTALLER
2078 inscmd := $(call $(target)_INSTALLER,$(srcsrc),$(insdst),$(target),$(flags))
[353]2079else
[830]2080 inscmd := $$(INSTALL)\
[414]2081 $(if $(uid),-o $(uid))\
2082 $(if $(gid),-g $(gid))\
2083 $(if $(mode),-m $(mode))\
[830]2084 $(flags)\
[414]2085 $(srcsrc) $(insdst)
[353]2086endif
2087
2088# generate the rule (need double evaluation here)
2089$(eval $(def_install_src_rule))
2090
2091INSTARGET_$(target) += $(insdst)
2092endef
2093
2094
2095## generate the symlink rule
2096define def_install_symlink_rule
2097# the install rule
2098$(insdst) : | $(call DIRDEP,$(dir $(insdst)))
[776]2099 $$(call MSG_INST_SYM,$(insdst),$(symdst))
[696]2100 $$(QUIET)$$(RM) -f $$@
2101 $$(QUIET)$$(LN_SYMLINK) $(symdst) $(insdst)
[353]2102endef
2103
2104## create one symlink
2105define def_install_symlink
2106
2107# deal with '=>' in the source file name.
[380]2108symdst := $(subst =>, ,$(src))
2109symlnk := $(firstword $(symdst))
2110symdst := $(word $(words $(symdst)),$(symdst))
[353]2111
2112# _INSTFUN
[380]2113ifdef $(symlnk)_INSTFUN
[827]2114 instfun := $(symlnk)_INSTFUN
2115else ifdef $(target)_INSTFUN
[830]2116 instfun := $(target)_INSTFUN
[353]2117else
[827]2118 instfun := _INSTALL_FILE
[353]2119endif
2120
2121# _INST
[380]2122ifdef $(symlnk)_INST
[725]2123 inst := $(patsubst %/,%,$($(symlnk)_INST))/$(dir $(symlnk))
[827]2124else ifdef $(target)_INST
2125 inst := $(patsubst %/,%,$($(target)_INST))/$(dir $(symlnk))
[353]2126else
[827]2127 inst := $(dir $(symlnk))
[353]2128endif
2129
2130# calc target
[380]2131insdst := $(call $(instfun),$(symlnk),$(target),$(inst),$(PATH_INS))
2132#$(warning symlnk=$(symlnk) symdst=$(symdst) insdst=$(insdst) instfun=$(instfun) inst='$(inst)')
[353]2133
2134# generate the rule (need double evaluation here)
2135$(eval $(def_install_symlink_rule))
2136
2137INSTARGET_$(target) += $(insdst)
2138endef
2139
[412]2140
[380]2141## generate the install rule
2142define def_install_directory_rule
2143# the install rule
2144$(insdst):
[776]2145 $$(call MSG_INST_DIR,$(insdst))
[696]2146 $$(QUIET)$$(INSTALL) -d \
[380]2147 $(if $(uid),-o $(uid))\
2148 $(if $(gid),-g $(gid))\
2149 $(if $(mode),-m $(mode))\
[830]2150 $(flags)\
[380]2151 $(insdst)
[412]2152
2153.NOTPARALLEL: $(insdst)
[380]2154endef
2155
[412]2156
[380]2157## create one directory
2158define def_install_directory
2159
2160# _INST
2161ifdef $(directory)_INST
[725]2162 inst := $(PATH_INS)/$(patsubst %/,%,$($(directory)_INST))
[827]2163else ifdef $(target)_INST
2164 inst := $(PATH_INS)/$(patsubst %/,%,$($(target)_INST))
[380]2165else
[827]2166 inst := $(PATH_INS)
[380]2167endif
2168
2169mode := $(firstword \
[481]2170 $($(target)_$(directory)_MODE.$(bld_trg).$(bld_trg_arch)) \
[380]2171 $($(target)_$(directory)_MODE.$(bld_trg)) \
2172 $($(target)_$(directory)_MODE) \
[481]2173 $($(directory)_MODE.$(bld_trg).$(bld_trg_arch)) \
[380]2174 $($(directory)_MODE.$(bld_trg)) \
2175 $($(directory)_MODE) \
[481]2176 $($(target)_MODE.$(bld_trg).$(bld_trg_arch)) \
[380]2177 $($(target)_MODE.$(bld_trg)) \
2178 $($(target)_MODE))
2179uid := $(firstword \
[481]2180 $($(target)_$(directory)_UID.$(bld_trg).$(bld_trg_arch)) \
[380]2181 $($(target)_$(directory)_UID.$(bld_trg)) \
2182 $($(target)_$(directory)_UID) \
[481]2183 $($(directory)_UID.$(bld_trg).$(bld_trg_arch)) \
[380]2184 $($(directory)_UID.$(bld_trg)) \
2185 $($(directory)_UID) \
[481]2186 $($(target)_UID.$(bld_trg).$(bld_trg_arch)) \
[380]2187 $($(target)_UID.$(bld_trg)) \
2188 $($(target)_UID))
2189gid := $(firstword \
[481]2190 $($(target)_$(directory)_GID.$(bld_trg).$(bld_trg_arch)) \
[380]2191 $($(target)_$(directory)_GID.$(bld_trg)) \
2192 $($(target)_$(directory)_GID) \
[481]2193 $($(directory)_GID.$(bld_trg).$(bld_trg_arch)) \
[380]2194 $($(directory)_GID.$(bld_trg)) \
2195 $($(directory)_GID) \
[481]2196 $($(target)_GID.$(bld_trg).$(bld_trg_arch)) \
[380]2197 $($(target)_GID.$(bld_trg)) \
2198 $($(target)_GID))
[830]2199flags := \
2200 $($(target)_IDFLAGS)\
2201 $($(target)_IDFLAGS.$(bld_trg)) \
2202 $($(target)_IDFLAGS.$(bld_trg).$(bld_trg_arch)) \
2203 $($(directory)_IDFLAGS) \
2204 $($(directory)_IDFLAGS.$(bld_trg)) \
2205 $($(directory)_IDFLAGS.$(bld_trg).$(bld_trg_arch)) \
2206 $($(target)_$(directory)_IDFLAGS) \
2207 $($(target)_$(directory)_IDFLAGS.$(bld_trg)) \
2208 $($(target)_$(directory)_IDFLAGS.$(bld_trg).$(bld_trg_arch))
[380]2209
2210insdst := $(inst)/$(directory)/
2211#$(warning directory=$(directory) inst=$(inst) insdst=$(insdst) mode=$(mode) gid=$(gid) uid=$(uid))
2212
2213# generate the rule (need double evaluation here)
2214$(eval $(def_install_directory_rule))
2215
2216INSTARGET_DIRS_$(target) += $(insdst)
2217endef
2218
2219
[353]2220## process one install target.
2221define def_install
[744]2222# the basics.
[353]2223bld_type := $(firstword $($(target)_BLD_TYPE) $(BUILD_TYPE))
2224bld_trg := $(firstword $($(target)_BLD_TRG) $(BUILD_TARGET))
2225bld_trg_arch:= $(firstword $($(target)_BLD_TRG_ARCH) $(BUILD_TARGET_ARCH))
2226bld_trg_cpu := $(firstword $($(target)_BLD_TRG_CPU) $(BUILD_TARGET_CPU))
2227
[827]2228INSTARGET_$(target) := $($(target)_GOALS)
[380]2229INSTARGET_DIRS_$(target) :=
2230
[481]2231$(foreach directory,$($(target)_DIRS) $($(target)_DIRS.$(bld_trg)) $($(target)_DIRS.$(bld_trg).$(bld_trg_arch)) $($(target)_DIRS.$(bld_trg_arch)) $($(target)_DIRS.$(bld_trg_cpu)) $($(target)_DIRS.$(bld_type)), \
[380]2232 $(eval $(value def_install_directory)))
2233
[481]2234$(foreach src,$($(target)_SOURCES) $($(target)_SOURCES.$(bld_trg)) $($(target)_SOURCES.$(bld_trg).$(bld_trg_arch)) $($(target)_SOURCES.$(bld_trg_arch)) $($(target)_SOURCES.$(bld_trg_cpu)) $($(target)_SOURCES.$(bld_type)), \
[353]2235 $(eval $(value def_install_src)))
2236
[481]2237$(foreach src,$($(target)_SYMLINKS) $($(target)_SYMLINKS.$(bld_trg)) $($(target)_SYMLINKS.$(bld_trg).$(bld_trg_arch)) $($(target)_SYMLINKS.$(bld_trg_arch)) $($(target)_SYMLINKS.$(bld_trg_cpu)) $($(target)_SYMLINKS.$(bld_type)), \
[353]2238 $(eval $(value def_install_symlink)))
2239
[827]2240# the collection target
2241TARGET_$(target) := $(PATH_TARGET)/$(target).ins
[838]2242$(TARGET_$(target)): $(INSTARGET_$(target)) | $(INSTARGET_DIRS_$(target)) $(call DIRDEP,$(PATH_TARGET))
[827]2243 @$(QUIET2)$(APPEND) $@
2244
2245$(target): $(TARGET_$(target))
2246
2247_INSTALLS += $(TARGET_$(target))
2248_INSTALLS_FILES += $(INSTARGET_$(target))
[380]2249_INSTALLS_DIRS += $(INSTARGET_DIRS_$(target))
[905]2250_CLEAN_FILES += $($(target)_CLEAN) $($(target)_CLEAN.$(bld_trg)) $($(target)_CLEAN.$(bld_trg).$(bld_trg_arch)) $($(target)_CLEAN.$(bld_trg_arch)) $($(target)_CLEAN.$(bld_trg_cpu)) $($(target)_CLEAN.$(bld_type))
2251_DIRS += $($(target)_BLDDIRS) $($(target)_BLDDIRS.$(bld_trg)) $($(target)_BLDDIRS.$(bld_trg).$(bld_trg_arch)) $($(target)_BLDDIRS.$(bld_trg_arch)) $($(target)_BLDDIRS.$(bld_trg_cpu)) $($(target)_BLDDIRS.$(bld_type))
[353]2252endef
2253
2254## process all install targets
[481]2255$(foreach target, $(INSTALLS) $(INSTALLS.$(BUILD_TARGET)) $(INSTALLS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)), \
[353]2256 $(eval $(value def_install)))
2257
2258
[72]2259#
[417]2260# PACKING
2261#
[481]2262_PACKING += $(PACKING) $(PACKING.$(BUILD_TARGET)) $(PACKING.$(BUILD_TARGET).$(BUILD_TARGET_ARCH))
[417]2263
2264
2265#
[72]2266# DOCS
2267#
2268
2269
2270#
[353]2271# DIRECTORIES
2272#
[827]2273_DIR_ALL := $(sort $(addsuffix /,$(patsubst %/,%,$(_DIRS))) $(dir $(_OUT_FILES) $(_OBJS) $(_INSTALLS_FILES)))
[380]2274$(foreach directory,$(_INSTALLS_DIRS), $(eval _DIR_ALL := $(filter-out $(directory),$(_DIR_ALL))))
[353]2275
[380]2276
[353]2277define def_mkdir_rule
2278$(directory):
[776]2279 $$(call MSG_MKDIR,$$@)
[696]2280 $$(QUIET)$$(MKDIR) -p $$@
[72]2281endef
2282
[353]2283$(foreach directory,$(_DIR_ALL),$(eval $(def_mkdir_rule)))
[72]2284
[183]2285
[72]2286#
[353]2287# NOTHING
[72]2288#
[353]2289do-nothing:
[776]2290 $(call MSG_NOTHING)
[72]2291
[183]2292
[75]2293#
[353]2294# CLEAN UP
[75]2295#
[353]2296do-clean:
[776]2297 $(call MSG_CLEAN)
[701]2298 $(QUIET)$(RM) -f $(_OUT_FILES) $(_OBJS) $(_DEPFILES) $(_DEPFILES_INCLUDED) $(_CLEAN_FILES) $(OTHER_CLEAN)
[966]2299 $(QUIET)$(RMDIR) -p --ignore-fail-on-non-empty --ignore-fail-on-not-exist $(rsort $(dir $(_OUT_FILES) $(_OBJS) $(_DEPFILES) $(_DEPFILES_INCLUDED) $(_CLEAN_FILES) $(OTHER_CLEAN)))
[72]2300
[98]2301
[897]2302
[353]2303#
2304# PASSES (including directory and makefile walking)
2305#
[221]2306
[75]2307## Subdir
2308# @param $(pass) Lowercase pass name.
2309# @param $(PASS) Uppercase pass name.
2310# @param $(subdir) Subdirectory
2311# @param $(tag) tag to attach to the rule name.
2312define def_pass_subdir
[219]2313pass_$(pass)$(tag):: $(dep)
[696]2314 + $$(QUIET)$$(MAKE) -C $(subdir) -f $$(notdir $$(firstword $$(wildcard $$(addprefix $(subdir)/,$$(DEFAULT_MAKEFILE))))) pass_$(pass)
[75]2315endef
[72]2316
[75]2317## Submakefile
2318# @param $(pass) Lowercase pass name.
2319# @param $(PASS) Uppercase pass name.
2320# @param $(makefile) Makefile.
2321# @param $(tag) tag to attach to the rule name.
2322define def_pass_makefile
[219]2323pass_$(pass)$(tag):: $(dep)
[696]2324 + $$(QUIET)$$(MAKE) -C $(patsubst %/,%,$(dir $(makefile))) -f $(notdir $(makefile)) pass_$(pass)
[75]2325endef
[73]2326
[75]2327## Execute a pass.
2328# @param $(pass) Lowercase pass name.
2329# @param $(PASS) Uppercase pass name.
[353]2330define def_pass_old
[481]2331$(eval SUBDIRS_$(PASS) ?= $(SUBDIRS) $(SUBDIRS.$(BUILD_TARGET)) $(SUBDIRS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) )
2332$(eval SUBDIRS_AFTER_$(PASS) ?= $(SUBDIRS_AFTER) $(SUBDIRS_AFTER.$(BUILD_TARGET)) $(SUBDIRS_AFTER.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) )
2333$(eval MAKEFILES_BEFORE_$(PASS) ?= $(MAKEFILES_BEFORE) $(MAKEFILES_BEFORE.$(BUILD_TARGET)) $(MAKEFILES_BEFORE.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) )
2334$(eval MAKEFILES_AFTER_$(PASS) ?= $(MAKEFILES_AFTER) $(MAKEFILES_AFTER.$(BUILD_TARGET)) $(MAKEFILES_AFTER.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) )
[75]2335
2336$(eval tag:=_before)
[219]2337$(eval dep:=)
[481]2338$(foreach subdir,$(SUBDIRS_$(PASS)) $(SUBDIRS_$(PASS).$(BUILD_TARGET)) $(SUBDIRS_$(PASS).$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) ,$(eval $(def_pass_subdir)))
2339$(foreach makefile,$(MAKEFILES_BEFORE_$(PASS)) $(MAKEFILES_BEFORE_$(PASS).$(BUILD_TARGET)) $(MAKEFILES_BEFORE_$(PASS).$(BUILD_TARGET).$(BUILD_TARGET_ARCH)),$(eval $(def_pass_makefile)))
[75]2340
2341$(eval tag:=_after)
[219]2342$(eval dep:=pass_$(pass)_doit)
[481]2343$(foreach subdir,$(SUBDIRS_AFTER_$(PASS)) $(SUBDIRS_AFTER_$(PASS).$(BUILD_TARGET)) $(SUBDIRS_AFTER_$(PASS).$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) ,$(eval $(def_pass_subdir)))
2344$(foreach makefile,$(MAKEFILES_AFTER_$(PASS)) $(MAKEFILES_AFTER_$(PASS).$(BUILD_TARGET)) $(MAKEFILES_AFTER_$(PASS).$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) ,$(eval $(def_pass_makefile)))
[75]2345
2346.NOTPARALLEL: pass_$(pass)_before pass_$(pass)_after
2347.PHONY: pass_$(pass) pass_$(pass)_before pass_$(pass)_doit pass_$(pass)_after
[353]2348pass_$(pass)_doit: $(PASS_$(PASS)_trgs) $(foreach var,$(PASS_$(PASS)_vars),$(var))
[272]2349pass_$(pass)_this: pass_$(pass)_before
[696]2350 + $$(QUIET)$$(MAKE) -f $$(MAKEFILE) pass_$(pass)_doit
[220]2351pass_$(pass)_after:: pass_$(pass)_this
[219]2352pass_$(pass): pass_$(pass)_after
[75]2353
[183]2354endef
2355
[353]2356define def_pass
[481]2357$(eval SUBDIRS_$(PASS) ?= $(SUBDIRS) $(SUBDIRS.$(BUILD_TARGET)) $(SUBDIRS.$(BUILD_TARGET.$(BUILD_TARGET_ARCH))) )
2358$(eval SUBDIRS_AFTER_$(PASS) ?= $(SUBDIRS_AFTER) $(SUBDIRS_AFTER.$(BUILD_TARGET)) $(SUBDIRS_AFTER.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) )
2359$(eval MAKEFILES_BEFORE_$(PASS) ?= $(MAKEFILES_BEFORE) $(MAKEFILES_BEFORE.$(BUILD_TARGET)) $(MAKEFILES_BEFORE.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) )
2360$(eval MAKEFILES_AFTER_$(PASS) ?= $(MAKEFILES_AFTER) $(MAKEFILES_AFTER.$(BUILD_TARGET)) $(MAKEFILES_AFTER.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) )
[183]2361
[353]2362$(eval tag:=_before)
2363$(eval dep:=)
[481]2364$(foreach subdir,$(SUBDIRS_$(PASS)) $(SUBDIRS_$(PASS).$(BUILD_TARGET)) $(SUBDIRS_$(PASS).$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) ,$(eval $(def_pass_subdir)))
2365$(foreach makefile,$(MAKEFILES_BEFORE_$(PASS)) $(MAKEFILES_BEFORE_$(PASS).$(BUILD_TARGET)) $(MAKEFILES_BEFORE_$(PASS).$(BUILD_TARGET).$(BUILD_TARGET_ARCH)),$(eval $(def_pass_makefile)))
[75]2366
[353]2367$(eval tag:=_after)
2368$(eval dep:=pass_$(pass)_doit)
[481]2369$(foreach subdir,$(SUBDIRS_AFTER_$(PASS)) $(SUBDIRS_AFTER_$(PASS).$(BUILD_TARGET)) $(SUBDIRS_AFTER_$(PASS).$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) ,$(eval $(def_pass_subdir)))
2370$(foreach makefile,$(MAKEFILES_AFTER_$(PASS)) $(MAKEFILES_AFTER_$(PASS).$(BUILD_TARGET)) $(MAKEFILES_AFTER_$(PASS).$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) ,$(eval $(def_pass_makefile)))
[75]2371
[380]2372ifdef KBUILD_SAFE_PARALLEL
[353]2373.NOTPARALLEL: pass_$(pass) pass_$(pass)_before pass_$(pass)_after pass_$(pass)_this
2374.PHONY: pass_$(pass) pass_$(pass)_before pass_$(pass)_after pass_$(pass)_this pass_$(pass)_doit
2375pass_$(pass)_doit: $(PASS_$(PASS)_trgs) $(foreach var,$(PASS_$(PASS)_vars),$(var))
2376pass_$(pass)_this: pass_$(pass)_before
[696]2377 + $$(QUIET)$$(MAKE) -f $$(MAKEFILE) pass_$(pass)_doit
[353]2378pass_$(pass)_after:: pass_$(pass)_this
2379pass_$(pass): pass_$(pass)_after
2380else
[388]2381.NOTPARALLEL: pass_$(pass) pass_$(pass)_before pass_$(pass)_after pass_$(pass)_doit
[353]2382.PHONY: pass_$(pass) pass_$(pass)_before pass_$(pass)_after pass_$(pass)_doit
2383pass_$(pass)_doit: pass_$(pass)_before \
2384 $(PASS_$(PASS)_trgs) $(foreach var,$(PASS_$(PASS)_vars),$($(var)))
2385pass_$(pass): \
2386 pass_$(pass)_before \
2387 pass_$(pass)_doit \
[388]2388 pass_$(pass)_after
[353]2389endif
[189]2390
[353]2391#$ (warning pass=$(pass) PASS=$(PASS): $(PASS_$(PASS)_trgs) $(PASS_$(PASS)_trgs) $(foreach var,$(PASS_$(PASS)_vars),$($(var))))
2392endef
[75]2393
[353]2394# Generate the defined passes.
2395$(foreach PASS, $(PASSES), \
2396 $(eval pass := $(PASS_$(PASS)_pass)) \
2397 $(eval $(def_pass)))
[75]2398
[219]2399## Pass order
2400# @param $(pass) Current pass name.
2401# @param $(prev_pass) The previous pass name.
2402define def_pass_order
[380]2403ifdef KBUILD_SAFE_PARALLEL
[353]2404.NOTPARALLEL: pass_$(pass)_order
2405.PHONY: pass_$(pass)_order
[219]2406pass_$(pass)_order: $(pass_prev)
[776]2407 $$(call MSG_PASS,$$(if $$(PASS_$(PASS)),$$(PASS_$(PASS)),$(pass)))
[696]2408 + $$(QUIET)$$(MAKE) -f $$(MAKEFILE) pass_$(pass)
[353]2409else
2410.NOTPARALLEL: pass_$(pass)_order pass_$(pass)_banner
[388]2411.PHONY: pass_$(pass)_order pass_$(pass)_banner
[353]2412pass_$(pass)_banner:
[776]2413 $$(call MSG_PASS,$$(if $$(PASS_$(PASS)),$$(PASS_$(PASS)),$(pass)))
[353]2414pass_$(pass)_order: \
2415 $(pass_prev) \
2416 pass_$(pass)_banner \
2417 pass_$(pass)
2418endif
[219]2419$(eval pass_prev := pass_$(pass)_order)
2420endef
[183]2421
[219]2422## PASS: order
2423# Use dependencies to ensure correct pass order.
2424pass_prev :=
[353]2425$(foreach PASS,$(DEFAULT_PASSES),\
2426 $(eval pass := $(PASS_$(PASS)_pass)) \
2427 $(eval $(def_pass_order)))
[219]2428
[272]2429
[897]2430
[75]2431#
2432# THE MAIN RULES
2433#
[219]2434all_recursive: $(pass_prev)
[75]2435
[130]2436rebuild: clean
[219]2437 + $(MAKE) -f $(firstword $(MAKEFILE_LIST)) all_recursive
[78]2438
[412]2439# @todo make this a non-default pass!
[353]2440uninstall:
[827]2441 $(RM) -f $(_INSTALLS_FILES)
[412]2442
[380]2443install: pass_installs
[78]2444
[75]2445# misc shortcuts.
[380]2446targets: bldprogs libraries dlls programs sysmods others installs
[75]2447objects: $(_OBJS)
[222]2448bldprogs: $(_BLDPROGS)
[189]2449libraries: $(_LIBS) $(_IMPORT_LIBS) $(_OTHER_LIBRARIES)
[205]2450dlls: $(_DLLS)
[219]2451programs: $(_PROGRAMS)
[205]2452sysmods: $(_SYSMODS)
[353]2453others: $(_OTHERS)
[854]2454installs: $(_INSTALLS) $(_INSTALLS_DIRS) $(_INSTALLS_FILES)
[75]2455
2456
[897]2457
[353]2458#
2459# kBuild debugging stuff.
2460#
2461show_targets:
[984]2462 @$(foreach target, $(_ALL_TARGETS),\
[353]2463 @$(ECHO) "target: $(target)" $(NLTAB)\
2464 @$(ECHO) " PATH_$(target)=$(PATH_$(target))" $(NLTAB)\
2465 @$(ECHO) " TARGET_$(target)=$(TARGET_$(target))" $(NLTAB)\
2466 @$(ECHO) " INSTARGET_$(target)=$(INSTARGET_$(target))" $(NLTAB)\
[660]2467$(foreach prop,$(PROPS_SINGLE) $(PROPS_ACCUMULATE_L) $(PROPS_ACCUMULATE_R) OBJS_ CLEAN, \
[353]2468 $(eval _tmp:=$(firstword $($(target)_BLD_TRG) $(BUILD_TARGET))) \
2469 $(if $($(target)_$(prop).$(_tmp)),\
2470 @$(ECHO) " $(target)_$(prop).$(_tmp)=$($(target)_$(prop).$(_tmp))" $(NLTAB)) \
2471 $(if $($(target)_$(prop)), $(NLTAB)@$(ECHO) " $(target)_$(prop)=$($(target)_$(prop))" $(NLTAB)) \
2472)\
2473$(foreach prop,$(PROPS_DEFERRED), \
2474 $(eval _tmp:=$(firstword $($(target)_BLD_TRG) $(BUILD_TARGET))) \
2475 $(if $(value $(target)_$(prop).$(_tmp)),\
2476 @$(ECHO) ' $(target)_$(prop).$(_tmp)=$(value $(TARGET)_$(prop).$(_tmp))' $(NLTAB)) \
2477 $(if $(value $(target)_$(prop)), $(NLTAB)@$(ECHO) ' $(target)_$(prop)=$(value $(target)_$(prop))' $(NLTAB)) \
2478))
2479
2480
2481
2482#
2483# Include dependency files.
2484#
[893]2485ifneq ($(_DEPFILES),)
2486 includedep $(_DEPFILES)
2487endif
[353]2488
2489
[72]2490# end-of-file-content
[106]2491__footer_kmk__ := target
[72]2492endif # __footer_kmk__
[438]2493
Note: See TracBrowser for help on using the repository browser.