source: trunk/kBuild/footer.kmk@ 886

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

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

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