source: trunk/kBuild/footer.kmk@ 857

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

the installs pass include _INSTALLS_FILES too.

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