source: trunk/kBuild/footer.kmk@ 852

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

Warn about bad SDK files.

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