source: trunk/kBuild/footer.kmk@ 973

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

Fix the clean rule

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