source: trunk/kBuild/footer.kmk@ 743

Last change on this file since 743 was 743, checked in by bird, 19 years ago

set PATH_target early (i.e. in subheader/subfooter).

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