source: trunk/kBuild/footer.kmk@ 982

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

Use the new prepend operator <= instead of the slow and clumsy _r1/r2 template inheritance stuff.

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