source: trunk/kBuild/footer.kmk@ 852

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

Warn about bad SDK files.

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