source: trunk/kBuild/footer.kmk@ 829

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

Split the target list processing up into two passes so that it's possible to make use of the TARGET_xxxx and INSTARGET_xxxx variables in the properties of any other target.

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