source: trunk/kBuild/footer.kmk@ 827

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

New property 'ORDERDEPS' for listing order-only dependencies.

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