source: trunk/kBuild/footer.kmk@ 874

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

Moved the PATH_* finalizing to header.kmk and applied abspath to all of them.

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