source: trunk/kBuild/footer.kmk@ 838

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

Added missing $(PATH_TARGET) dep.

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