source: trunk/kBuild/footer.kmk@ 744

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

More sanity checks.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 73.1 KB
Line 
1# $Id: footer.kmk 744 2006-12-17 08:36:36Z 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 _$(target)_$(prop)_R
364$(error kBuild: The target $(target) appears more than once in the target lists! Please correct the makefile(s))
365endif
366ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop)
367$(eval _$(target)_$(prop)_R = $(value $(target)_$(prop)))
368endif
369ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(BUILD_TYPE)
370$(eval _$(target)_$(prop).$(BUILD_TYPE)_R = $(value $(target)_$(prop).$(BUILD_TYPE)))
371endif
372ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg)
373$(eval _$(target)_$(prop).$(bld_trg)_R = $(value $(target)_$(prop).$(bld_trg)))
374endif
375ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg).$(bld_trg_arch)
376$(eval _$(target)_$(prop).$(bld_trg).$(bld_trg_arch)_R = $(value $(target)_$(prop).$(bld_trg).$(bld_trg_arch)))
377endif
378ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_cpu)
379$(eval _$(target)_$(prop).$(bld_trg_cpu)_R = $(value $(target)_$(prop).$(bld_trg_cpu)))
380endif
381ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_arch)
382$(eval _$(target)_$(prop).$(bld_trg_arch)_R = $(value $(target)_$(prop).$(bld_trg_arch)))
383endif
384endef
385
386## Inherit one template property the other way around.
387# Second pass, not $(value) referenced.
388# @param $(prop) Property name
389# @param $(target) Target name
390define def_inherit_template_one_accumulate_r2
391ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop)
392$(target)_$(prop) = $$(TEMPLATE_$($(target)_TEMPLATE)_$(prop)) $$(_$(target)_$(prop)_R)
393endif
394ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(BUILD_TYPE)
395$(target)_$(prop).$(BUILD_TYPE) = $$(TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(BUILD_TYPE)) $$(_$(target)_$(prop).$(BUILD_TYPE)_R)
396endif
397ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg)
398$(target)_$(prop).$(bld_trg) = $$(TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg)) $$(_$(target)_$(prop).$(bld_trg)_R)
399endif
400ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg).$(bld_trg_arch)
401$(target)_$(prop).$(bld_trg).$(bld_trg_arch) = $$(TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg).$(bld_trg_arch)) $$(_$(target)_$(prop).$(bld_trg).$(bld_trg_arch)_R)
402endif
403ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_cpu)
404$(target)_$(prop).$(bld_trg_cpu) = $$(TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_cpu)) $$(_$(target)_$(prop).$(bld_trg_cpu)_R)
405endif
406ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_arch)
407$(target)_$(prop).$(bld_trg_arch) = $$(TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_arch)) $$(_$(target)_$(prop).$(bld_trg_arch)_R)
408endif
409endef
410
411
412## Inherit template properties for on target.
413# @param $(target) Target name.
414define def_inherit_template
415# Inherit any default template.
416ifdef TEMPLATE
417ifeq ($($(target)_TEMPLATE),)
418$(eval $(target)_TEMPLATE:=$(TEMPLATE))
419endif
420endif
421# Expand the template if specified.
422ifneq ($($(target)_TEMPLATE),)
423$(foreach prop,$(PROPS_SINGLE),$(eval $(value def_inherit_template_one)))
424$(foreach prop,$(PROPS_DEFERRED),$(eval $(def_inherit_template_one_deferred))) # exploits the 2 evaluation, so no value!
425$(foreach prop,$(PROPS_ACCUMULATE_L),$(eval $(def_inherit_template_one_accumulate_l))) # += works fine (better) without value.
426$(foreach prop,$(PROPS_ACCUMULATE_R),\
427$(eval $(value def_inherit_template_one_accumulate_r1))\
428$(eval $(def_inherit_template_one_accumulate_r2))\
429) # This is a hack! (but it appears to work)
430endif
431endef
432
433# Inherit template properties
434bld_trg := $(BUILD_TARGET)
435bld_trg_arch := $(BUILD_TARGET_ARCH)
436bld_trg_cpu := $(BUILD_TARGET_CPU)
437$(foreach target, $(_ALL_BUILD_TARGET_TARGETS),$(eval $(value def_inherit_template)))
438
439bld_trg := $(BUILD_PLATFORM)
440bld_trg_arch := $(BUILD_PLATFORM_ARCH)
441bld_trg_cpu := $(BUILD_PLATFORM_CPU)
442$(foreach target, $(_ALL_BUILD_PLATFORM_TARGETS),$(eval $(value def_inherit_template)))
443
444
445#
446# Include tools & sdks
447#
448_TOOLS := $(TOOL.$(BUILD_TARGET)) $(TOOL.$(BUILD_TARGET_ARCH)) $(TOOL.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) \
449 $(TOOL.$(BUILD_PLATFORM)) $(TOOL.$(BUILD_PLATFORM_ARCH)) $(TOOL.$(BUILD_PLATFORM).$(BUILD_PLATFORM_ARCH)) \
450 $(TOOL)
451_SDKS := $(SDKS.$(BUILD_TARGET)) $(SDKS.$(BUILD_TARGET_ARCH)) $(SDKS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) \
452 $(SDKS.$(BUILD_PLATFORM)) $(SDKS.$(BUILD_PLATFORM_ARCH)) $(SDKS.$(BUILD_PLATFORM).$(BUILD_PLATFORM_ARCH)) \
453 $(SDKS.$(BUILD_TYPE)) \
454 $(SDKS)
455define def_tools_sdks_target_source
456$(eval _TOOLS += $(foreach prop, $(PROPS_TOOLS), \
457 $($(source)_$(prop).$(_bld_trg)) \
458 $($(target)_$(source)_$(prop).$(_bld_trg)) \
459 $($(source)_$(prop).$(_bld_trg).$(_bld_trg_arch)) \
460 $($(target)_$(source)_$(prop).$(_bld_trg).$(_bld_trg_arch)) \
461 $($(source)_$(prop).$(_bld_trg_arch)) \
462 $($(target)_$(source)_$(prop).$(_bld_trg_arch)) \
463 $($(source)_$(prop)) \
464 $($(target)_$(source)_$(prop))))
465$(eval _SDKS += \
466 $($(source)_SDKS.$(_bld_trg)) \
467 $($(target)_$(source)_SDKS.$(_bld_trg)) \
468 $($(source)_SDKS.$(_bld_trg).$(_bld_trg_arch)) \
469 $($(target)_$(source)_SDKS.$(_bld_trg).$(_bld_trg_arch)) \
470 $($(source)_SDKS.$(_bld_trg_arch)) \
471 $($(target)_$(source)_SDKS.$(_bld_trg_arch)) \
472 $($(source)_SDKS.$(BUILD_TYPE)) \
473 $($(target)_$(source)_SDKS.$(BUILD_TYPE)) \
474 $($(source)_SDKS) \
475 $($(target)_$(source)_SDKS))
476endef
477
478define def_tools_sdks_target
479_bld_trg := $(firstword $($(target)_BLD_TRG) $(bld_trg))
480_bld_trg_arch := $(firstword $($(target)_BLD_TRG_ARCH) $(bld_trg_arch))
481_bld_trg_cpu := $(firstword $($(target)_BLD_TRG_CPU) $(bld_trg_cpu))
482
483$(eval _TOOLS += $(foreach prop, $(PROPS_TOOLS), \
484 $($(target)_$(prop).$(_bld_trg)) \
485 $($(target)_$(prop).$(_bld_trg_arch)) \
486 $($(target)_$(prop).$(_bld_trg).$(_bld_trg_arch)) \
487 $($(target)_$(prop))))
488$(eval _SDKS += \
489 $($(target)_SDKS.$(_bld_trg)) \
490 $($(target)_SDKS.$(_bld_trg_arch)) \
491 $($(target)_SDKS.$(_bld_trg).$(_bld_trg_arch)) \
492 $($(target)_SDKS))
493$(foreach source, \
494 $($(target)_SOURCES.$(_bld_trg)) \
495 $($(target)_SOURCES.$(_bld_trg_arch)) \
496 $($(target)_SOURCES.$(_bld_trg).$(_bld_trg_arch)) \
497 $($(target)_SOURCES.$(_bld_trg_cpu)) \
498 $($(target)_SOURCES.$(BUILD_TYPE)) \
499 $($(target)_SOURCES) \
500 , $(eval $(value def_tools_sdks_target_source)))
501endef
502
503define def_tools_srcname_target
504_bld_trg := $(firstword $($(target)_BLD_TRG) $(bld_trg))
505_bld_trg_arch := $(firstword $($(target)_BLD_TRG_ARCH) $(bld_trg_arch))
506_bld_trg_cpu := $(firstword $($(target)_BLD_TRG_CPU) $(bld_trg_cpu))
507
508$(foreach source, $(notdir\
509 $($(target)_SOURCES.$(_bld_trg)) \
510 $($(target)_SOURCES.$(_bld_trg_arch)) \
511 $($(target)_SOURCES.$(_bld_trg).$(_bld_trg_arch)) \
512 $($(target)_SOURCES.$(_bld_trg_cpu)) \
513 $($(target)_SOURCES.$(BUILD_TYPE)) \
514 $($(target)_SOURCES) \
515 ), $(eval $(value def_tools_sdks_target_source)))
516endef
517
518bld_trg := $(BUILD_TARGET)
519bld_trg_arch := $(BUILD_TARGET_ARCH)
520bld_trg_cpu := $(BUILD_TARGET_CPU)
521$(foreach target, $(_ALL_BUILD_TARGET_TARGETS), $(eval $(value def_tools_sdks_target)))
522$(foreach target, $(_ALL_SRCNAME_TARGETS), $(eval $(value def_tools_srcname_target)))
523
524bld_trg := $(BUILD_PLATFORM)
525bld_trg_arch := $(BUILD_PLATFORM_ARCH)
526bld_trg_cpu := $(BUILD_PLATFORM_CPU)
527$(foreach target, $(_ALL_BUILD_PLATFORM_TARGETS), $(eval $(value def_tools_sdks_target)))
528
529
530# include TOOLS
531define def_tools_include
532ifndef TOOL_$(tool)
533TOOL_$(tool)_KMK_FILE := $(firstword $(foreach path, $(TOOL_PATHS) $(PATH_KBUILD)/tools, $(wildcard $(path)/$(tool).kmk)))
534ifeq ($(TOOL_$(tool)_KMK_FILE),)
535$(error kBuild: Cannot find include file for the tool '$(tool)'! Searched: $(TOOL_PATHS) $(PATH_KBUILD)/tools)
536endif
537include $(TOOL_$(tool)_KMK_FILE)
538endif
539endef
540
541_TOOLS := $(sort $(_TOOLS))
542$(foreach tool, $(_TOOLS), $(eval $(value def_tools_include)))
543
544
545# include SDKS
546define def_sdks_include_one
547ifndef SDK_$(sdk)
548SDK_$(sdk)_KMK_FILE := $(firstword $(foreach path, $(SDK_PATHS) $(PATH_KBUILD)/sdks, $(wildcard $(path)/$(sdk).kmk)))
549ifeq ($(SDK_$(sdk)_KMK_FILE),)
550$(error kBuild: Cannot find include file for the SDK '$(sdk)'! Searched: $(SDK_PATHS) $(PATH_KBUILD)/sdks)
551endif
552include $(SDK_$(sdk)_KMK_FILE)
553endif
554endef
555
556_SDKS := $(sort $(_SDKS))
557$(foreach sdk, $(_SDKS), $(eval $(value def_sdks_include_one)))
558
559
560
561## @page pg_fetches Fetching Tools, Sources and Similar.
562#
563# The targets listed in the the FETCHES target list have the following attributes:
564# SOURCES
565# INST
566# FETCHTOOL
567# FETCHFLAGS
568# FETCHDIR
569# UNPACKTOOL
570# UNPACKFLAGS
571#
572# As usual the target name is an alias for 'creating' the target. Other
573# aliases are:
574# pass_fetches
575# fetch
576# unfetch
577# download
578# unpack
579#
580# @remark
581#
582# This is a little bit complex because we must guarantee that if a source file
583# changes only sligtly we must refetch it and to a proper unpacking of it. It
584# is also a desire that fetched archives and unpacked files can be deleted to
585# save space.
586#
587# Thus, we must be able to cleanup what we've unpacked should any of the
588# sources be removed. We do this by maintaining a file listing the files
589# and directories that was unpacked. This operation is named 'unfetch'.
590#
591# We make use of the SIZE and MD5 attributes for each of the sources to
592# create a digest that is stored in the primary target file. Subsequent
593# runswill compare their digest with it to decide if a refetch is required.
594# When a refetch is found necessary, an 'unfetch' is performed first to
595# clean out old files and directores. Note even changes in source order
596# will cause a refetch due to the way the digest is constructed and
597# evaluated.
598#
599# By not depending directly on the archives (nor on any unpacked files)
600# but on a goal made up from the archive name, size and md5, we allow
601# the user to delete the archives. Naturally, this means we'll have to
602# check and fetch missing archives before attempting to unpack them.
603#
604# @remark
605#
606# This feature will *NOT* work correctly with vanilla GNU make becuase
607# it makes use of includedep to avoid too many unnecessary files.
608#
609# @todo
610# 1. Port md5sum or some equivalent tool and include it in kBuild.
611# 2. Download corruption / continuation.
612# 3. It's quite possible that there is one too many indirect dependency now...
613#
614
615## @todo move this!
616MD5SUM := md5sum
617
618## generates the fetch rule
619define def_fetch_src_fetch_rule
620# Indirect goal for downloading something.
621.PRECIOUS: $(out)
622$(out) $($(target)_$(srcname)_FETCH_OUTPUT_): | $($(target)_$(srcname)_FETCH_DEPORD_)
623 $$(call MSG_L1,Downloading $(source)...)
624 @## @todo do fancy stuff like download continuation.
625 $$(QUIET)$$(RM) -f $(out) $(out).md5
626 $($(target)_$(srcname)_FETCH_CMDS_)
627 $$(QUIET2)$(if $(md5),$$(APPEND) $(out).md5 "$(md5) *$(out)")
628 $$(QUIET)$(if $(md5),$$(MD5SUM) -c $(out).md5)
629
630
631
632# Intermediate goal for making sure the md5 and size matches. it will (re) fetch the archive if necessary.
633$(out).checked_$(md5)_$(size): $($(target)_$(srcname)_FETCH_DEPEND_) | $($(target)_$(srcname)_FETCH_DEPORD_)
634 $$(call MSG_L1,Checking $(out),($(source))...)
635 $$(QUIET)$$(RM) -f $$@ $(out).md5
636 @# creates the .md5 we pass to md5sum.
637 $$(QUIET2)$(if $(md5),$$(APPEND) $(out).md5 "$(md5) *$(out)")
638 @# (re)fetch the file if it doesn't exist or if it doesn't matches the md5.
639 @## @todo do fancy stuff like download continuation.
640 $$(QUIET)( test -f $(out) && $(if $(md5),$$(MD5SUM) -c $(out).md5, true) ) \
641 || ( $$(RM_EXT) -f $(out) \
642 && $$(MAKE) $(out) -f $(MAKEFILE) --no-print-directory )
643 $$(QUIET2)$$(APPEND) $$@
644
645_TARGET_$(target)_FETCHED += $(out) $(out).checked_$(md5)_$(size)
646
647# Just a little precaution.
648.NOTPARALLEL: $(out) $(out).checked_$(md5)_$(size)
649
650endef
651
652## generates the unpack rule
653define def_fetch_src_unpack_rule
654# This is the unpack rule. it has an order-only dependency on the download check.
655$(out) $($(target)_$(srcname)_UNPACK_OUTPUT_): $($(target)_$(srcname)_UNPACK_DEPEND_) \
656 | $($(target)_$(srcname)_UNPACK_DEPORD_) $(archive).checked_$(md5)_$(size)
657 $$(call MSG_L1,Unpacking $(archive),into $(inst)...)
658 $$(QUIET)$$(RM) -f $(out)
659 @# if the source archive doesn't exist fetch it (can have been deleted to save space).
660 $$(QUIET)test -f $(archive) \
661 || ( $$(RM_EXT) -f $(archive).checked_$(md5)_$(size) \
662 && $$(MAKE) $(archive).checked_$(md5)_$(size) -f $(MAKEFILE) --no-print-directory )
663 $($(target)_$(srcname)_UNPACK_CMDS_)
664 $$(QUIET2)$$(APPEND) $(out) $(notdir $(archive).checked_$(md5)_$(size))
665 $$(QUIET2)$$(APPEND) $(out) $(notdir $(out))
666
667$(eval _TARGET_$(target)_UNPACKED += $(out))
668_TARGET_$(target)_DIGEST := $(_TARGET_$(target)_DIGEST)-$(srcname)_$(md5)_$(size)
669
670.NOTPARALLEL: $(out)
671
672endef
673
674## Processes a fetch source
675#
676define def_fetch_src
677#$ (warning dbg: def_fetch_src: source='$(source)' target='$(target)')
678
679# common
680srcname := $(notdir $(source))
681inst := $(firstword \
682 $($(target)_$(source)_INST)\
683 $($(target)_$(srcname)_INST)\
684 $($(source)_INST)\
685 $($(srcname)_INST)\
686 $($(target)_INST)\
687)
688ifneq ($(patsubst %/,ok,$(inst)),ok)
689$(error kBuild: Bad or missing INST property for source '$(source)' in target '$(target)': $(inst))
690endif
691INSTARGET_$(target)_$(srcname) := $(inst)
692fetchdir := $(firstword \
693 $($(target)_$(source)_FETCHDIR)\
694 $($(target)_$(srcname)_FETCHDIR)\
695 $($(source)_FETCHDIR)\
696 $($(srcname)_FETCHDIR)\
697 $($(target)_FETCHDIR)\
698 $(FETCHDIR)\
699 $(PATH_TARGET)\
700)
701deps := \
702 $($(target)_$(source)_DEPS)\
703 $($(target)_$(srcname)_DEPS)\
704 $($(source)_DEPS)\
705 $($(srcname)_DEPS)\
706 $($(target)_DEPS)
707md5 := $(firstword \
708 $($(target)_$(source)_MD5)\
709 $($(target)_$(srcname)_MD5)\
710 $($(source)_MD5)\
711 $($(srcname)_MD5)\
712 $($(target)_MD5)\
713)
714size := $(firstword \
715 $($(target)_$(source)_SIZE)\
716 $($(target)_$(srcname)_SIZE)\
717 $($(source)_SIZE)\
718 $($(srcname)_SIZE)\
719 $($(target)_SIZE)\
720)
721dep := # not legal for fetch and unpack tools
722
723
724#
725# The fetching.
726#
727out := $(fetchdir)/$(srcname)
728archive := $(out)
729TARGET_$(target)_$(srcname) := $(out)
730dirdep := $(call DIRDEP,$(fetchdir))
731tool := $(firstword \
732 $($(target)_$(source)_FETCHTOOL)\
733 $($(target)_$(srcname)_FETCHTOOL)\
734 $($(target)_$(source)_TOOL)\
735 $($(target)_$(srcname)_TOOL)\
736 $($(source)_FETCHTOOL)\
737 $($(srcname)_FETCHTOOL)\
738 $($(source)_TOOL)\
739 $($(srcname)_TOOL)\
740 $($(target)_FETCHTOOL)\
741 $($(target)_TOOL)\
742 )
743flags :=\
744 $(TOOL_$(tool)_FETCHFLAGS)\
745 $(FETCHFLAGS)\
746 $($(target)_FETCHFLAGS)\
747 $($(srcname)_FETCHFLAGS)\
748 $($(source)_FETCHFLAGS)\
749 $($(target)_$(srcname)_FETCHFLAGS)\
750 $($(target)_$(source)_FETCHFLAGS)
751
752#$ (warning dbg: target=$(target) source=$(source) $(srcname)=$(srcname) tool=$(tool) out=$(out) flags=$(flags) dirdep=$(dirdep) fetchdir=$(fetchdir) md5=$(md5) size=$(size))
753
754ifndef TOOL_$(tool)_FETCH_CMDS
755$(warning kBuild: tools: \
756 1 $($(target)_$(source)_FETCHTOOL)\
757 2 $($(target)_$(srcname)_FETCHTOOL)\
758 3 $($(target)_$(source)_TOOL)\
759 4 $($(target)_$(srcname)_TOOL)\
760 5 $($(source)_FETCHTOOL)\
761 6 $($(srcname)_FETCHTOOL)\
762 7 $($(source)_TOOL)\
763 8 $($(srcname)_TOOL)\
764 9 $($(target)_FETCHTOOL)\
765 10 $($(target)_TOOL) )
766$(error kBuild: TOOL_$(tool)_FETCH_CMDS is not defined. source=$(source) target=$(target) )
767endif
768
769# call the tool
770$(target)_$(srcname)_FETCH_CMDS_ := $(TOOL_$(tool)_FETCH_CMDS)
771$(target)_$(srcname)_FETCH_OUTPUT_ := $(TOOL_$(tool)_FETCH_OUTPUT)
772$(target)_$(srcname)_FETCH_DEPEND_ := $(TOOL_$(tool)_FETCH_DEPEND) $(deps)
773$(target)_$(srcname)_FETCH_DEPORD_ := $(TOOL_$(tool)_FETCH_DEPORD) $(dirdep)
774
775# generate the fetch rule.
776$(eval $(def_fetch_src_fetch_rule))
777
778
779#
780# The unpacking / installing.
781#
782out := $(inst)_kBuild_$(target)_$(srcname)_unpacked.lst
783dirdep := $(call DIRDEP,$(inst))
784tool := $(firstword \
785 $($(target)_$(source)_UNPACKTOOL)\
786 $($(target)_$(srcname)_UNPACKTOOL)\
787 $($(target)_$(source)_TOOL)\
788 $($(target)_$(srcname)_TOOL)\
789 $($(source)_UNPACKTOOL)\
790 $($(srcname)_UNPACKTOOL)\
791 $($(source)_TOOL)\
792 $($(srcname)_TOOL)\
793 $($(target)_UNPACKTOOL)\
794 $($(target)_TOOL) \
795 )
796ifeq ($(tool),)
797tool := $(toupper $(subst .,,$(suffix $(subst tar.,TAR,$(srcname)))))
798$(eval $(value def_tools_include))
799endif
800flags :=\
801 $(TOOL_$(tool)_UNPACKFLAGS)\
802 $(UNPACKFLAGS)\
803 $($(target)_UNPACKFLAGS)\
804 $($(srcname)_UNPACKFLAGS)\
805 $($(source)_UNPACKFLAGS)\
806 $($(target)_$(srcname)_UNPACKFLAGS)\
807 $($(target)_$(source)_UNPACKFLAGS)
808
809#$ (warning dbg: target=$(target) source=$(source) $(srcname)=$(srcname) tool=$(tool) out=$(out) flags=$(flags) dirdep=$(dirdep) inst=$(inst) md5=$(md5) size=$(size))
810ifndef TOOL_$(tool)_UNPACK_CMDS
811$(warning kBuild: tools: \
812 1 $($(target)_$(source)_UNPACKTOOL)\
813 2 $($(target)_$(srcname)_UNPACKTOOL)\
814 3 $($(target)_$(source)_TOOL)\
815 4 $($(target)_$(srcname)_TOOL)\
816 5 $($(source)_UNPACKTOOL)\
817 6 $($(srcname)_UNPACKTOOL)\
818 7 $($(source)_TOOL)\
819 8 $($(srcname)_TOOL)\
820 9 $($(target)_UNPACKTOOL)\
821 10 $($(target)_TOOL) \
822 11 $(toupper $(subst tar.,TAR,$(ext $(srcname)))) \
823 )
824$(error kBuild: TOOL_$(tool)_UNPACK_CMDS is not defined. source=$(source) target=$(target) )
825endif
826
827# call the tool
828$(target)_$(srcname)_UNPACK_CMDS_ := $(TOOL_$(tool)_UNPACK_CMDS)
829$(target)_$(srcname)_UNPACK_OUTPUT_ := $(TOOL_$(tool)_UNPACK_OUTPUT)
830$(target)_$(srcname)_UNPACK_DEPEND_ := $(TOOL_$(tool)_UNPACK_DEPEND) $(deps)
831$(target)_$(srcname)_UNPACK_DEPORD_ := $(TOOL_$(tool)_UNPACK_DEPORD) $(dirdep)
832
833# generate the fetch rule.
834$(eval $(def_fetch_src_unpack_rule))
835
836_DIRS += $(inst) $(fetchdir)
837
838endef
839
840
841##
842# Define the target level rules for a fetch.
843# @param target
844# @param out
845# @param inst
846# @param _TARGET_$(target)_UNPACKED
847# @param _TARGET_$(target)_DIGEST
848# @param bld_trg
849# @param bld_trg_arch
850define def_fetch_rules
851
852$(out).lst: $(_TARGET_$(target)_UNPACKED) | $(call DIRDEP,$(inst))
853 $$(call MSG_L1,Successfully fetched $(target))
854 $$(QUIET)$$(RM) -f $$@ $$@.tmp
855 $$(QUIET2)$$(APPEND) $$@.tmp "$(notdir $(out))"
856 $$(QUIET)$(if $(_TARGET_$(target)_UNPACKED),$$(CAT_EXT) $(_TARGET_$(target)_UNPACKED) >> $$@.tmp)
857 $$(QUIET)$$(MV) -f $$@.tmp $$@
858
859$(out)_unfetched:
860 $$(call MSG_L1,Unfetching $(target)...)
861 $$(QUIET)$$(RM) -f $$(addprefix $(inst),$$(shell $$(CAT_EXT) $(out).lst 2> /dev/null | $$(SED) -e '/\/$$$$/d'))
862 $$(QUIET)$$(RMDIR) -p --ignore-fail-on-non-empty --ignore-fail-on-not-exist $$(dir $$@) \
863 $$(addprefix $(inst),$$(sort $$(dir $$(shell $$(CAT_EXT) $(out).lst 2> /dev/null))))
864 $$(QUIET)$$(RM) -f $(out).lst $(out)
865 $$(QUIET)$$(RMDIR) -p --ignore-fail-on-non-empty --ignore-fail-on-not-exist $$(dir $$@)
866
867$(out): $(comp-vars _TARGET_$(target)_DIGEST_PREV,_TARGET_$(target)_DIGEST,FORCE) | $(call DIRDEP,$(inst))
868 $$(QUIET)$$(RM) -f $$@
869 $$(call MSG_L1,$$(if $$(_TARGET_$(target)_DIGEST),$$(if $$(wildcard $(out).lst),Re-fetching,Fetching),Removing) $(target)...)
870 $$(QUIET)$$(if $$(wildcard $(out).lst ),$$(MAKE) -f $(MAKEFILE) --no-print-directory $(out)_unfetched)
871 $$(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 $$@))
872 $$(QUIET2)$$(if $$(_TARGET_$(target)_DIGEST),$$(APPEND) $$@ "_TARGET_$(target)_DIGEST_PREV := $(_TARGET_$(target)_DIGEST)")
873
874.NOTPARALLEL: $(out).lst $(out)_unfetched $(out)
875
876endef
877
878
879##
880# Deal with one fetch target.
881# @param target
882# @param bld_trg
883# @param bld_trg_arch
884define def_fetch
885# sanity check.
886ifdef $(target)_ALREADY_PROCESSED
887 $(error kBuild: The target $(target) appears more than once in the target lists! Please correct the makefile(s). Prev: $(EXT) This: $($(target)_ALREADY_PROCESSED))
888endif
889$(target)_ALREADY_PROCESSED := fetch
890
891# common
892INSTARGET_$(target) := $($(target)_INST)
893ifneq ($(patsubst %/,ok,$(INSTARGET_$(target))),ok)
894$(error kBuild: Bad or missing INST property for target '$(target)'. \
895 $(target)_INST='$($(target)_INST)' ($(origin $(target)_INST)))
896endif
897_TARGET_$(target)_FETCHED :=
898_TARGET_$(target)_UNPACKED :=
899_TARGET_$(target)_DIGEST :=
900
901# The 'sources'.
902#$ (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)))
903$(foreach source,$($(target)_SOURCES) $($(target)_SOURCES.$(BUILD_TYPE)) $($(target)_SOURCES.$(BUILD_TARGET)) $($(target)_SOURCES.$(BUILD_TARGET_ARCH)) $($(target)_SOURCES.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)),\
904 $(eval $(value def_fetch_src)))
905
906# The target.
907inst := $(INSTARGET_$(target))
908out := $(inst)_kBuild_fetch_$(target)
909
910$(eval includedep $(out))
911
912$(eval $(def_fetch_rules))
913
914# Define the aliases here (doesn't work if defined in def_fetch_rules, just like includedep).
915$(target):: $(out)
916$(target)_unfetch:: $(out)_unfetched
917
918_FETCHES += $(out)
919_DOWNLOADS += $(_TARGET_$(target)_FETCHED)
920_UNPACKS += $(_TARGET_$(target)_UNPACKED)
921_UNFETCHES += $(out)_unfetched
922_DIRS += $(inst)
923
924endef
925
926# Walk the FETCH target lists.
927bld_trg := $(BUILD_TARGET)
928bld_trg_arch := $(BUILD_TARGET_ARCH)
929$(foreach target, $(FETCHES) $(FETCHES.$(BUILD_TARGET)) $(FETCHES.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)), \
930 $(eval $(value def_fetch)))
931
932# some aliases.
933download: $(_DOWNLOADS)
934unpack: $(_UNPACKS)
935fetch: $(_FETCHES)
936unfetch: $(_UNFETCHES)
937
938
939
940##
941## Patching.
942##
943##
944#define def_patch_src
945#
946#endef
947#
948#
949## Deal with one patch target.
950#define def_patch
951#
952#$(foreach source,$($(target)_SOURCES) $($(target)_SOURCES.$(BUILD_TYPE)) $($(target)_SOURCES.$(BUILD_TARGET)) $($(target)_SOURCES.$(BUILD_TARGET_ARCH)) $($(target)_SOURCES.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)),\
953# $(eval $(value def_patch_src)))
954#
955#_PATCHES +=
956#endef
957#
958#$(foreach target, $(PATCHES) $(PATCHES.$(BUILD_TARGET)) $(PATCHES.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)), \
959# $(eval $(value def_patch)))
960#
961
962
963#
964# Object processing.
965#
966
967## wrapper the compile command dependency check.
968ifndef NO_COMPILE_CMDS_DEPS
969 _DEP_COMPILE_CMDS = $(comp-cmds $(target)_$(source)_CMDS_PREV_,$(target)_$(source)_CMDS_,FORCE)
970else
971 _DEP_COMPILE_CMDS =
972endif
973
974## Generates the rules for building a specific object, and the '::' aliases
975# for building a source file.
976# @param $(obj) The object file.
977define def_target_source_rule
978$(obj) $($(target)_$(source)_OUTPUT_): \
979 $($(target)_$(source)_DEPEND_) \
980 $(_DEP_COMPILE_CMDS) \
981 | \
982 $($(target)_$(source)_DEPORD_)
983 $$(call MSG_L1,Compiling $(source),=> $$@)
984 $$(QUIET)$$(RM) -f $(dep) $(obj) $($(target)_$(source)_OUTPUT_)
985 $(custom_pre)
986
987$($(target)_$(source)_CMDS_)
988
989 $(custom_post)
990ifndef NO_COMPILE_CMDS_DEPS
991 $$(QUIET2)$$(APPEND) "$(dep)"
992 $$(QUIET2)$$(APPEND) "$(dep)" 'define $(target)_$(source)_CMDS_PREV_'
993 $$(QUIET2)$$(APPEND) "$(dep)" '$(subst $(NL),'$(NL)$(TAB)@$(APPEND) "$(dep)" ',$($(target)_$(source)_CMDS_))'
994 $$(QUIET2)$$(APPEND) "$(dep)" 'endef'
995endif
996
997$(basename $(notdir $(obj))).o::
998 + $$(MAKE) -f $$(MAKEFILE) $(obj)
999$(basename $(notdir $(obj))).obj::
1000 + $$(MAKE) -f $$(MAKEFILE) $(obj)
1001endef
1002
1003
1004## wrapper the link command dependency check.
1005ifndef NO_COMPILE_CMDS_DEPS
1006 _DEP_LINK_CMDS = $(comp-cmds $(target)_CMDS_PREV_,$(target)_CMDS_,FORCE)
1007else
1008 _DEP_LINK_CMDS =
1009endif
1010
1011## Generate the link rule for a target.
1012# @param $(target) The normalized target name.
1013# @param $(dirdep) Directories we depend upon begin created before linking.
1014# @param $(dep) The name of the dependency file.
1015# @param $(out)
1016# @param $($(target)_OUTPUT_) Output files from the link.
1017# @param $($(target)_DEPEND_) Dependencies.
1018# @param $($(target)_DEPORD_) Dependencies which should only affect build order.
1019# @param $($(target)_CMDS_) The link commands.
1020# @param $($(target)_CMDS_PREV_) The link commands from the previous run.
1021define def_link_rule
1022$(out) $($(target)_OUTPUT_): \
1023 $($(target)_DEPEND_) \
1024 $(_DEP_LINK_CMDS) \
1025 | \
1026 $($(target)_DEPORD_)
1027 $$(call MSG_L1,Linking $$@)
1028 $$(QUIET)$$(RM) -f $(dep) $(out) $($(target)_OUTPUT_)
1029 $(custom_pre)
1030
1031$($(target)_CMDS_)
1032
1033 $(custom_post)
1034ifndef NO_LINK_CMDS_DEPS
1035 $$(QUIET2)$$(APPEND) "$(dep)" 'define $(target)_CMDS_PREV_'
1036 $$(QUIET2)$$(APPEND) "$(dep)" '$(subst $(NL),'$(NL)$(TAB)@$(APPEND) "$(dep)" ',$($(target)_CMDS_))'
1037 $$(QUIET2)$$(APPEND) "$(dep)" 'endef'
1038endif
1039
1040$(basename $(notdir $(out)))::
1041 + $$(MAKE) -f $$(MAKEFILE) $(out)
1042
1043endef
1044
1045
1046## Generate the link & lib install rule
1047# @param $(target) Normalized target name.
1048# @param $(out) The build target.
1049# @param $(INSTARGET_$(target)) The installation targets.
1050# @param $(mode) The file mode (optional)
1051define def_link_install_rule
1052$(INSTARGET_$(target)) : $(out) | $(call DIRDEP,$(dir $(INSTARGET_$(target))))
1053 $$(call MSG_L1,Installing $(target) => $$@)
1054 $$(QUIET)$$(INSTALL) $$(if $(mode),-m $(mode)) $(out) $$@
1055
1056ifdef KBUILD_DO_AUTO_INSTALL
1057$(basename $(notdir $(out)))::
1058 + $$(MAKE) -f $$(MAKEFILE) $(INSTARGET_$(target))
1059endif
1060endef
1061
1062
1063## Generic macro for processing C, C++ and Assembly sources.
1064# @param $(target) Normalized target name.
1065# @param $(source) Source file name.
1066# @param $(type) Source type. {C,CXX,AS}
1067# @param bld_type Build type.
1068# @param bld_trg Build target.
1069# @param bld_trg_arch Build target arch.
1070# @param bld_trg_cpu Build target cpu.
1071def_target_source_c_cpp_asm_rc_new = $(kb-src-one )
1072ifdef KMK_VERSION
1073 def_target_source_c_cpp_asm_rc_var = def_target_source_c_cpp_asm_rc_new
1074else
1075 def_target_source_c_cpp_asm_rc_var = def_target_source_c_cpp_asm_rc_old
1076endif
1077
1078## Generic macro for processing all target sources.
1079# @param $(target) Normalized target name.
1080# @param $(defpath)
1081# @param much-more...
1082define def_target_sources
1083#$ (warning def_target_sources)
1084# C sources
1085type := C
1086$(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)))\
1087 ,$(eval $(value $(def_target_source_c_cpp_asm_rc_var))) )
1088
1089# C++ sources
1090type := CXX
1091$(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)))\
1092 ,$(eval $(value $(def_target_source_c_cpp_asm_rc_var))) )
1093
1094# ASM sources
1095type := AS
1096$(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)))\
1097 ,$(eval $(value $(def_target_source_c_cpp_asm_rc_var))) )
1098
1099# Resource sources
1100type := RC
1101$(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)))\
1102 ,$(eval $(value $(def_target_source_c_cpp_asm_rc_var))) )
1103
1104endef
1105
1106
1107
1108## Generic macro for generating the install rule(s) for a target
1109# and update the globals with default out.
1110#
1111# @param $(target) Normalized target name.
1112# @param $(out) The output file.
1113# @param $(definst) The default _INST value.
1114# @param $(typevar) The name of the variable with all the root targets of its type.
1115# @remark Only library uses this now.
1116define def_target_install_pluss
1117ifndef $(target)_NOINST
1118INSTARGET_$(target) := $(patsubst %/,%/$(notdir $(out)), \
1119 $(if $($(target)_INST), $(addprefix $(PATH_INS)/,$($(target)_INST)), $(definst)/))
1120
1121$(eval $(def_link_install_rule))
1122
1123_INSTALLS += $(INSTARGET_$(target))
1124
1125ifdef KBUILD_DO_AUTO_INSTALL
1126$(typevar) += $(INSTARGET_$(target))
1127else
1128$(typevar) += $(out)
1129endif
1130else # _NOINST
1131$(typevar) += $(out)
1132endif
1133
1134_OUT_FILES += $($(target)_OUTPUT_) $(out)
1135_CLEAN_FILES += $($(target)_CLEAN)
1136_OBJS += $($(target)_OBJS_)
1137
1138endef
1139
1140
1141
1142#
1143# LIBRARIES
1144#
1145
1146## Library (one).
1147# @param $(target) Normalized library (target) name.
1148define def_lib
1149# sanity check.
1150ifdef $(target)_ALREADY_PROCESSED
1151 $(error kBuild: The target $(target) appears more than once in the target lists! Please correct the makefile(s). Prev: $(EXT) This: $($(target)_ALREADY_PROCESSED))
1152endif
1153$(target)_ALREADY_PROCESSED := lib
1154
1155# library basics
1156## @todo prefix
1157bld_type := $(firstword $($(target)_BLD_TYPE) $(BUILD_TYPE))
1158bld_trg := $(firstword $($(target)_BLD_TRG) $(BUILD_TARGET))
1159bld_trg_arch:= $(firstword $($(target)_BLD_TRG_ARCH) $(BUILD_TARGET_ARCH))
1160bld_trg_cpu := $(firstword $($(target)_BLD_TRG_CPU) $(BUILD_TARGET_CPU))
1161tool := $(call _TARGET_TOOL,$(target),AR)
1162ifeq ($(tool),)
1163$(error kBuild: Library target $(target) does not have a tool defined!)
1164endif
1165outbase := $(call TARGET_BASE,$(target),$(target))
1166ifndef PATH_$(target)
1167 PATH_$(target) := $(patsubst %/,%,$(dir $(outbase)))
1168else
1169 ifneq ($(PATH_$(target)),$(patsubst %/,%,$(dir $(outbase))))
1170 $(error kBuild internal error: PATH_$(target)=$(PATH_$(target)) expected $(patsubst %/,%,$(dir $(outbase))))
1171 endif
1172endif
1173suff := $(firstword\
1174 $($(target)_LIBSUFF.$(bld_trg).$(bld_trg_arch))\
1175 $($(target)_LIBSUFF.$(bld_trg))\
1176 $($(target)_LIBSUFF)\
1177 $(TOOL_$(tool)_ARLIBSUFF.$(bld_trg).$(bld_trg_arch))\
1178 $(TOOL_$(tool)_ARLIBSUFF.$(bld_trg))\
1179 $(TOOL_$(tool)_ARLIBSUFF)\
1180 $(SUFF_LIB))
1181out := $(outbase)$(suff)
1182TARGET_$(target) := $(out)
1183$(target)_OBJS_ :=
1184defpath := $($(target)_PATH)
1185
1186# source -> object
1187$(eval $(value def_target_sources))
1188
1189# library linking
1190tool := $(call _TARGET_TOOL,$(target),AR)
1191outbase := $(call TARGET_BASE,$(target),$(target))
1192flags :=\
1193 $(TOOL_$(tool)_ARFLAGS)\
1194 $(TOOL_$(tool)_ARFLAGS.$(bld_type))\
1195 $(ARFLAGS)\
1196 $(ARFLAGS.$(bld_type))\
1197 $($(target)_ARFLAGS)\
1198 $($(target)_ARFLAGS.$(bld_type)) \
1199 $($(target)_ARFLAGS.$(bld_trg)) \
1200 $($(target)_ARFLAGS.$(bld_trg_arch)) \
1201 $($(target)_ARFLAGS.$(bld_trg).$(bld_trg_arch)) \
1202 $($(target)_ARFLAGS.$(bld_trg_cpu))
1203othersrc := $(filter-out %.c %.cpp %.cxx %.cc %.s %.S %.asm %.o %.obj,\
1204 $($(target)_SOURCES) \
1205 $($(target)_SOURCES.$(bld_trg)) \
1206 $($(target)_SOURCES.$(bld_trg_arch)) \
1207 $($(target)_SOURCES.$(bld_trg).$(bld_trg_arch)) \
1208 $($(target)_SOURCES.$(bld_trg_cpu)) \
1209 $($(target)_SOURCES.$(bld_type)))
1210objs = $(filter %.o %.obj, \
1211 $($(target)_SOURCES) \
1212 $($(target)_SOURCES.$(bld_trg)) \
1213 $($(target)_SOURCES.$(bld_trg_arch)) \
1214 $($(target)_SOURCES.$(bld_trg).$(bld_trg_arch)) \
1215 $($(target)_SOURCES.$(bld_trg_cpu)) \
1216 $($(target)_SOURCES.$(bld_type))) \
1217 $($(target)_OBJS_)
1218dirdep := $(call DIRDEP,$(dir $(out)))
1219## @todo fix dependencies on makefiles an such
1220deps := $($(target)_DEPS)
1221
1222# Adjust paths if we got a default path.
1223ifneq ($(defpath),)
1224 objs := $(call abspathex,$(objs),$(defpath))
1225 deps := $(call abspathex,$(deps),$(defpath))
1226 othersrc := $(call abspathex,$(othersrc),$(defpath))
1227endif
1228
1229# dependency file
1230dep := $(out)$(SUFF_DEP)
1231ifndef NO_LINK_CMDS_DEPS
1232_DEPFILES_INCLUDED += $(dep)
1233$(if $(wildcard $(dep)),$(eval include $(dep)))
1234endif
1235
1236# check that the tool is defined.
1237ifndef TOOL_$(tool)_LINK_LIBRARY_CMDS
1238$(warning kBuild: tools: \
1239 1 $($(target)_$(source)TOOL.$(bld_trg).$(bld_trg_arch)) \
1240 2 $($(target)_$(source)TOOL.$(bld_trg)) \
1241 3 $($(target)_$(source)TOOL) \
1242 4 $($(target)_TOOL.$(bld_trg).$(bld_trg_arch)) \
1243 5 $($(target)_TOOL.$(bld_trg)) \
1244 6 $($(target)_TOOL) \
1245 7 $($(source)TOOL) \
1246 8 $($(source)TOOL.$(bld_trg).$(bld_trg_arch)) \
1247 9 $($(source)TOOL.$(bld_trg)) \
1248 10 $(TOOL.$(bld_trg).$(bld_trg_arch)) \
1249 11 $(TOOL.$(bld_trg)) \
1250 12 $(TOOL) )
1251$(error kBuild: TOOL_$(tool)_LINK_LIBRARY_CMDS isn't defined! target=$(target) )
1252endif
1253
1254# call the tool
1255$(target)_CMDS_ := $(TOOL_$(tool)_LINK_LIBRARY_CMDS)
1256$(target)_OUTPUT_ := $(TOOL_$(tool)_LINK_LIBRARY_OUTPUT)
1257$(target)_DEPEND_ := $(TOOL_$(tool)_LINK_LIBRARY_DEPEND) $(deps) $(objs)
1258$(target)_DEPORD_ := $(TOOL_$(tool)_LINK_LIBRARY_DEPORD) $(dirdep)
1259
1260# generate the link rule.
1261$(eval $(def_link_rule))
1262
1263# installing and globals
1264definst := $(PATH_LIB)
1265typevar := _LIBS
1266$(eval $(value def_target_install_pluss))
1267endef
1268
1269# Process libraries
1270mode := 0644
1271$(foreach target, $(LIBRARIES) $(LIBRARIES.$(BUILD_TARGET)) $(LIBRARIES.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)), $(eval $(value def_lib)))
1272
1273
1274#
1275# Link operations.
1276#
1277
1278##
1279# Link prolog
1280#
1281# @param $(target) Normalized target name.
1282# @param $(EXT) EXE,DLL,SYS.
1283# @param $(definst) The default _INST value.
1284# @param $(typevar) The name of the variable with all the root targets of its type.
1285define def_link_common
1286# sanity check.
1287ifdef $(target)_ALREADY_PROCESSED
1288 $(error kBuild: The target $(target) appears more than once in the target lists! Please correct the makefile(s). Prev: $(EXT) This: $($(target)_ALREADY_PROCESSED))
1289endif
1290$(target)_ALREADY_PROCESSED := $(EXT)
1291
1292# basics
1293bld_type := $(firstword $($(target)_BLD_TYPE) $(BUILD_TYPE))
1294bld_trg := $(firstword $($(target)_BLD_TRG) $(BUILD_$(bld_trg_base_var)))
1295bld_trg_arch:= $(firstword $($(target)_BLD_TRG_ARCH) $(BUILD_$(bld_trg_base_var)_ARCH))
1296bld_trg_cpu := $(firstword $($(target)_BLD_TRG_CPU) $(BUILD_$(bld_trg_base_var)_CPU))
1297
1298tool := $(call _TARGET_TOOL,$(target),LD)
1299outbase := $(call TARGET_BASE,$(target),$(target))
1300ifndef PATH_$(target)
1301 PATH_$(target) := $(patsubst %/,%,$(dir $(outbase)))
1302else
1303 ifneq ($(PATH_$(target)),$(patsubst %/,%,$(dir $(outbase))))
1304 $(error kBuild internal error: PATH_$(target)=$(PATH_$(target)) expected $(patsubst %/,%,$(dir $(outbase))))
1305 endif
1306endif
1307suff := $(firstword \
1308 $($(target)_$(EXT)SUFF) \
1309 $($(target)_$(EXT)SUFF) \
1310 $(TOOL_$(tool)_LD$(EXT)SUFF) \
1311 $($(EXTPRE)SUFF_$(EXT)))
1312out := $(outbase)$(suff)
1313TARGET_$(target) := $(out)
1314$(target)_OBJS_ :=
1315defpath := $($(target)_PATH)
1316
1317# source -> object
1318$(eval $(value def_target_sources))
1319
1320# more link stuff.
1321tool := $(call _TARGET_TOOL,$(target),LD)
1322outbase := $(call TARGET_BASE,$(target),$(target))
1323flags :=\
1324 $(TOOL_$(tool)_LDFLAGS)\
1325 $(TOOL_$(tool)_LDFLAGS.$(bld_type))\
1326 $(TOOL_$(tool)_LDFLAGS.$(bld_trg))\
1327 $(TOOL_$(tool)_LDFLAGS.$(bld_trg_arch))\
1328 $(TOOL_$(tool)_LDFLAGS.$(bld_trg).$(bld_trg_arch))\
1329 $(TOOL_$(tool)_LDFLAGS.$(bld_trg_cpu))\
1330 $(LDFLAGS)\
1331 $(LDFLAGS.$(bld_type))\
1332 $(LDFLAGS.$(bld_trg))\
1333 $(LDFLAGS.$(bld_trg_arch))\
1334 $(LDFLAGS.$(bld_trg).$(bld_trg_arch))\
1335 $(LDFLAGS.$(bld_trg_cpu))\
1336 $($(target)_LDFLAGS)\
1337 $($(target)_LDFLAGS.$(bld_type))\
1338 $($(target)_LDFLAGS.$(bld_trg))\
1339 $($(target)_LDFLAGS.$(bld_trg_arch))\
1340 $($(target)_LDFLAGS.$(bld_trg).$(bld_trg_arch))\
1341 $($(target)_LDFLAGS.$(bld_trg_cpu))
1342othersrc := $(filter-out %.c %.cpp %.cxx %.cc %.s %.S %.asm %.o %.obj,\
1343 $($(target)_SOURCES)\
1344 $($(target)_SOURCES.$(bld_trg)) \
1345 $($(target)_SOURCES.$(bld_trg_arch)) \
1346 $($(target)_SOURCES.$(bld_trg).$(bld_trg_arch)) \
1347 $($(target)_SOURCES.$(bld_trg_cpu)) \
1348 $($(target)_SOURCES.$(bld_type)))
1349objs = $(filter %.o %.obj, \
1350 $($(target)_SOURCES) \
1351 $($(target)_SOURCES.$(bld_trg)) \
1352 $($(target)_SOURCES.$(bld_trg_arch)) \
1353 $($(target)_SOURCES.$(bld_trg).$(bld_trg_arch)) \
1354 $($(target)_SOURCES.$(bld_trg_cpu)) \
1355 $($(target)_SOURCES.$(bld_type))) \
1356 $($(target)_OBJS_)
1357libs :=\
1358 $($(target)_LIBS.$(bld_trg_cpu))\
1359 $($(target)_LIBS.$(bld_trg).$(bld_trg_arch))\
1360 $($(target)_LIBS.$(bld_trg_arch))\
1361 $($(target)_LIBS.$(bld_trg))\
1362 $($(target)_LIBS.$(bld_type))\
1363 $($(target)_LIBS)\
1364 $(foreach sdk, $($(target)_SDKS.$(bld_trg).$(bld_trg_arch)) \
1365 $($(target)_SDKS.$(bld_trg_arch)) \
1366 $($(target)_SDKS.$(bld_trg)) \
1367 $($(target)_SDKS.$(bld_type)) \
1368 $($(target)_SDKS),\
1369 $(SDK_$(sdk)_LIBS.$(bld_trg_cpu))\
1370 $(SDK_$(sdk)_LIBS.$(bld_trg).$(bld_trg_arch))\
1371 $(SDK_$(sdk)_LIBS.$(bld_trg_arch))\
1372 $(SDK_$(sdk)_LIBS.$(bld_trg))\
1373 $(SDK_$(sdk)_LIBS.$(bld_type))\
1374 $(SDK_$(sdk)_LIBS))\
1375 $(LIBS.$(bld_trg_cpu))\
1376 $(LIBS.$(bld_trg).$(bld_trg_arch))\
1377 $(LIBS.$(bld_trg_arch))\
1378 $(LIBS.$(bld_trg))\
1379 $(LIBS.$(bld_type))\
1380 $(LIBS)\
1381 $(foreach sdk, $(SDKS.$(bld_trg).$(bld_trg_arch)) \
1382 $(SDKS.$(bld_trg_arch)) \
1383 $(SDKS.$(bld_trg)) \
1384 $(SDKS.$(bld_type)) \
1385 $(SDKS),\
1386 $(SDK_$(sdk)_LIBS.$(bld_trg_cpu))\
1387 $(SDK_$(sdk)_LIBS.$(bld_trg).$(bld_trg_arch))\
1388 $(SDK_$(sdk)_LIBS.$(bld_trg_arch))\
1389 $(SDK_$(sdk)_LIBS.$(bld_trg))\
1390 $(SDK_$(sdk)_LIBS.$(bld_type))\
1391 $(SDK_$(sdk)_LIBS))\
1392 $(TOOL_$(tool)_LIBS.$(bld_trg_cpu))\
1393 $(TOOL_$(tool)_LIBS.$(bld_trg).$(bld_trg_arch))\
1394 $(TOOL_$(tool)_LIBS.$(bld_trg_arch))\
1395 $(TOOL_$(tool)_LIBS.$(bld_trg))\
1396 $(TOOL_$(tool)_LIBS.$(bld_type))\
1397 $(TOOL_$(tool)_LIBS)
1398libpath :=\
1399 $($(target)_LIBPATH.$(bld_trg_cpu))\
1400 $($(target)_LIBPATH.$(bld_trg).$(bld_trg_arch))\
1401 $($(target)_LIBPATH.$(bld_trg_arch))\
1402 $($(target)_LIBPATH.$(bld_trg))\
1403 $($(target)_LIBPATH.$(bld_type))\
1404 $($(target)_LIBPATH)\
1405 $(foreach sdk, $($(target)_SDKS.$(bld_trg).$(bld_trg_arch)) \
1406 $($(target)_SDKS.$(bld_trg_arch)) \
1407 $($(target)_SDKS.$(bld_trg)) \
1408 $($(target)_SDKS.$(bld_type)) \
1409 $($(target)_SDKS),\
1410 $(SDK_$(sdk)_LIBPATH.$(bld_trg_cpu))\
1411 $(SDK_$(sdk)_LIBPATH.$(bld_trg).$(bld_trg_arch))\
1412 $(SDK_$(sdk)_LIBPATH.$(bld_trg_arch))\
1413 $(SDK_$(sdk)_LIBPATH.$(bld_trg))\
1414 $(SDK_$(sdk)_LIBPATH.$(bld_type))\
1415 $(SDK_$(sdk)_LIBPATH))\
1416 $(LIBPATH.$(bld_trg_cpu))\
1417 $(LIBPATH.$(bld_trg).$(bld_trg_arch))\
1418 $(LIBPATH.$(bld_trg_arch))\
1419 $(LIBPATH.$(bld_trg))\
1420 $(LIBPATH.$(bld_type))\
1421 $(LIBPATH)\
1422 $(foreach sdk, $(SDKS.$(bld_trg).$(bld_trg_arch)) \
1423 $(SDKS.$(bld_trg_arch)) \
1424 $(SDKS.$(bld_trg)) \
1425 $(SDKS.$(bld_type)) \
1426 $(SDKS),\
1427 $(SDK_$(sdk)_LIBPATH.$(bld_trg_cpu))\
1428 $(SDK_$(sdk)_LIBPATH.$(bld_trg).$(bld_trg_arch))\
1429 $(SDK_$(sdk)_LIBPATH.$(bld_trg_arch))\
1430 $(SDK_$(sdk)_LIBPATH.$(bld_trg))\
1431 $(SDK_$(sdk)_LIBPATH.$(bld_type))\
1432 $(SDK_$(sdk)_LIBPATH))\
1433 $(TOOL_$(tool)_LIBPATH.$(bld_trg_cpu))\
1434 $(TOOL_$(tool)_LIBPATH.$(bld_trg).$(bld_trg_arch))\
1435 $(TOOL_$(tool)_LIBPATH.$(bld_trg_arch))\
1436 $(TOOL_$(tool)_LIBPATH.$(bld_trg))\
1437 $(TOOL_$(tool)_LIBPATH.$(bld_type))\
1438 $(TOOL_$(tool)_LIBPATH)
1439dirdep := $(call DIRDEP,$(dir $(out)))
1440## @todo fix dependencies
1441deps := $($(target)_DEPS)
1442
1443# Adjust paths if we got a default path.
1444ifneq ($(defpath),)
1445 libpath := $(call abspathex,$(libpath)def $(target)_PATH)
1446 objs := $(call abspathex,$(objs),$(defpath))
1447 deps := $(call abspathex,$(deps),$(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)
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 += $(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_L1,Installing $(insdst),(<= $(srcsrc)))
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_L1,Installing symlink $(insdst),pointing to $(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
1780instfun := $(symlnk)_INSTFUN
1781else
1782ifdef $(target)_INSTFUN
1783instfun := $(target)_INSTFUN
1784else
1785instfun := _INSTALL_FILE
1786endif
1787endif
1788
1789# _INST
1790ifdef $(symlnk)_INST
1791 inst := $(patsubst %/,%,$($(symlnk)_INST))/$(dir $(symlnk))
1792else
1793 ifdef $(target)_INST
1794 inst := $(patsubst %/,%,$($(target)_INST))/$(dir $(symlnk))
1795 else
1796 inst := $(dir $(symlnk))
1797 endif
1798endif
1799
1800# calc target
1801insdst := $(call $(instfun),$(symlnk),$(target),$(inst),$(PATH_INS))
1802#$(warning symlnk=$(symlnk) symdst=$(symdst) insdst=$(insdst) instfun=$(instfun) inst='$(inst)')
1803
1804# generate the rule (need double evaluation here)
1805$(eval $(def_install_symlink_rule))
1806
1807INSTARGET_$(target) += $(insdst)
1808endef
1809
1810
1811## generate the install rule
1812define def_install_directory_rule
1813# the install rule
1814$(insdst):
1815 $$(call MSG_L1,Installing directory $(insdst))
1816 $$(QUIET)$$(INSTALL) -d \
1817 $(if $(uid),-o $(uid))\
1818 $(if $(gid),-g $(gid))\
1819 $(if $(mode),-m $(mode))\
1820 $(insdst)
1821
1822.NOTPARALLEL: $(insdst)
1823endef
1824
1825
1826## create one directory
1827define def_install_directory
1828
1829# _INST
1830ifdef $(directory)_INST
1831 inst := $(PATH_INS)/$(patsubst %/,%,$($(directory)_INST))
1832else
1833 ifdef $(target)_INST
1834 inst := $(PATH_INS)/$(patsubst %/,%,$($(target)_INST))
1835 else
1836 inst := $(PATH_INS)
1837 endif
1838endif
1839
1840mode := $(firstword \
1841 $($(target)_$(directory)_MODE.$(bld_trg).$(bld_trg_arch)) \
1842 $($(target)_$(directory)_MODE.$(bld_trg)) \
1843 $($(target)_$(directory)_MODE) \
1844 $($(directory)_MODE.$(bld_trg).$(bld_trg_arch)) \
1845 $($(directory)_MODE.$(bld_trg)) \
1846 $($(directory)_MODE) \
1847 $($(target)_MODE.$(bld_trg).$(bld_trg_arch)) \
1848 $($(target)_MODE.$(bld_trg)) \
1849 $($(target)_MODE))
1850uid := $(firstword \
1851 $($(target)_$(directory)_UID.$(bld_trg).$(bld_trg_arch)) \
1852 $($(target)_$(directory)_UID.$(bld_trg)) \
1853 $($(target)_$(directory)_UID) \
1854 $($(directory)_UID.$(bld_trg).$(bld_trg_arch)) \
1855 $($(directory)_UID.$(bld_trg)) \
1856 $($(directory)_UID) \
1857 $($(target)_UID.$(bld_trg).$(bld_trg_arch)) \
1858 $($(target)_UID.$(bld_trg)) \
1859 $($(target)_UID))
1860gid := $(firstword \
1861 $($(target)_$(directory)_GID.$(bld_trg).$(bld_trg_arch)) \
1862 $($(target)_$(directory)_GID.$(bld_trg)) \
1863 $($(target)_$(directory)_GID) \
1864 $($(directory)_GID.$(bld_trg).$(bld_trg_arch)) \
1865 $($(directory)_GID.$(bld_trg)) \
1866 $($(directory)_GID) \
1867 $($(target)_GID.$(bld_trg).$(bld_trg_arch)) \
1868 $($(target)_GID.$(bld_trg)) \
1869 $($(target)_GID))
1870
1871insdst := $(inst)/$(directory)/
1872#$(warning directory=$(directory) inst=$(inst) insdst=$(insdst) mode=$(mode) gid=$(gid) uid=$(uid))
1873
1874# generate the rule (need double evaluation here)
1875$(eval $(def_install_directory_rule))
1876
1877INSTARGET_DIRS_$(target) += $(insdst)
1878endef
1879
1880
1881## process one install target.
1882define def_install
1883# sanity check.
1884ifdef $(target)_ALREADY_PROCESSED
1885 $(error kBuild: The target $(target) appears more than once in the target lists! Please correct the makefile(s). Prev: $(EXT) This: $($(target)_ALREADY_PROCESSED))
1886endif
1887$(target)_ALREADY_PROCESSED := install
1888
1889# the basics.
1890bld_type := $(firstword $($(target)_BLD_TYPE) $(BUILD_TYPE))
1891bld_trg := $(firstword $($(target)_BLD_TRG) $(BUILD_TARGET))
1892bld_trg_arch:= $(firstword $($(target)_BLD_TRG_ARCH) $(BUILD_TARGET_ARCH))
1893bld_trg_cpu := $(firstword $($(target)_BLD_TRG_CPU) $(BUILD_TARGET_CPU))
1894
1895INSTARGET_$(target) :=
1896INSTARGET_DIRS_$(target) :=
1897
1898$(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)), \
1899 $(eval $(value def_install_directory)))
1900
1901$(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)), \
1902 $(eval $(value def_install_src)))
1903
1904$(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)), \
1905 $(eval $(value def_install_symlink)))
1906
1907_INSTALLS += $(INSTARGET_$(target)) $($(target)_GOALS)
1908_INSTALLS_DIRS += $(INSTARGET_DIRS_$(target))
1909endef
1910
1911## process all install targets
1912$(foreach target, $(INSTALLS) $(INSTALLS.$(BUILD_TARGET)) $(INSTALLS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)), \
1913 $(eval $(value def_install)))
1914
1915
1916#
1917# PACKING
1918#
1919_PACKING += $(PACKING) $(PACKING.$(BUILD_TARGET)) $(PACKING.$(BUILD_TARGET).$(BUILD_TARGET_ARCH))
1920
1921
1922#
1923# DOCS
1924#
1925
1926
1927#
1928# DIRECTORIES
1929#
1930_DIR_ALL := $(sort $(addsuffix /,$(patsubst %/,%,$(_DIRS))) $(dir $(_OUT_FILES) $(_OBJS) $(_INSTALLS)))
1931$(foreach directory,$(_INSTALLS_DIRS), $(eval _DIR_ALL := $(filter-out $(directory),$(_DIR_ALL))))
1932
1933
1934define def_mkdir_rule
1935$(directory):
1936 $$(call MSG_L2,Creating directory $$@)
1937 $$(QUIET)$$(MKDIR) -p $$@
1938endef
1939
1940$(foreach directory,$(_DIR_ALL),$(eval $(def_mkdir_rule)))
1941
1942
1943#
1944# NOTHING
1945#
1946do-nothing:
1947 $(call MSG_L1,Did nothing in $(CURDIR))
1948
1949
1950#
1951# CLEAN UP
1952#
1953do-clean:
1954 $(call MSG_L1,Cleaning...)
1955 $(QUIET)$(RM) -f $(_OUT_FILES) $(_OBJS) $(_DEPFILES) $(_DEPFILES_INCLUDED) $(_CLEAN_FILES) $(OTHER_CLEAN)
1956
1957
1958#
1959# PASSES (including directory and makefile walking)
1960#
1961
1962## Subdir
1963# @param $(pass) Lowercase pass name.
1964# @param $(PASS) Uppercase pass name.
1965# @param $(subdir) Subdirectory
1966# @param $(tag) tag to attach to the rule name.
1967define def_pass_subdir
1968pass_$(pass)$(tag):: $(dep)
1969 + $$(QUIET)$$(MAKE) -C $(subdir) -f $$(notdir $$(firstword $$(wildcard $$(addprefix $(subdir)/,$$(DEFAULT_MAKEFILE))))) pass_$(pass)
1970endef
1971
1972## Submakefile
1973# @param $(pass) Lowercase pass name.
1974# @param $(PASS) Uppercase pass name.
1975# @param $(makefile) Makefile.
1976# @param $(tag) tag to attach to the rule name.
1977define def_pass_makefile
1978pass_$(pass)$(tag):: $(dep)
1979 + $$(QUIET)$$(MAKE) -C $(patsubst %/,%,$(dir $(makefile))) -f $(notdir $(makefile)) pass_$(pass)
1980endef
1981
1982## Execute a pass.
1983# @param $(pass) Lowercase pass name.
1984# @param $(PASS) Uppercase pass name.
1985define def_pass_old
1986$(eval SUBDIRS_$(PASS) ?= $(SUBDIRS) $(SUBDIRS.$(BUILD_TARGET)) $(SUBDIRS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) )
1987$(eval SUBDIRS_AFTER_$(PASS) ?= $(SUBDIRS_AFTER) $(SUBDIRS_AFTER.$(BUILD_TARGET)) $(SUBDIRS_AFTER.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) )
1988$(eval MAKEFILES_BEFORE_$(PASS) ?= $(MAKEFILES_BEFORE) $(MAKEFILES_BEFORE.$(BUILD_TARGET)) $(MAKEFILES_BEFORE.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) )
1989$(eval MAKEFILES_AFTER_$(PASS) ?= $(MAKEFILES_AFTER) $(MAKEFILES_AFTER.$(BUILD_TARGET)) $(MAKEFILES_AFTER.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) )
1990
1991$(eval tag:=_before)
1992$(eval dep:=)
1993$(foreach subdir,$(SUBDIRS_$(PASS)) $(SUBDIRS_$(PASS).$(BUILD_TARGET)) $(SUBDIRS_$(PASS).$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) ,$(eval $(def_pass_subdir)))
1994$(foreach makefile,$(MAKEFILES_BEFORE_$(PASS)) $(MAKEFILES_BEFORE_$(PASS).$(BUILD_TARGET)) $(MAKEFILES_BEFORE_$(PASS).$(BUILD_TARGET).$(BUILD_TARGET_ARCH)),$(eval $(def_pass_makefile)))
1995
1996$(eval tag:=_after)
1997$(eval dep:=pass_$(pass)_doit)
1998$(foreach subdir,$(SUBDIRS_AFTER_$(PASS)) $(SUBDIRS_AFTER_$(PASS).$(BUILD_TARGET)) $(SUBDIRS_AFTER_$(PASS).$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) ,$(eval $(def_pass_subdir)))
1999$(foreach makefile,$(MAKEFILES_AFTER_$(PASS)) $(MAKEFILES_AFTER_$(PASS).$(BUILD_TARGET)) $(MAKEFILES_AFTER_$(PASS).$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) ,$(eval $(def_pass_makefile)))
2000
2001.NOTPARALLEL: pass_$(pass)_before pass_$(pass)_after
2002.PHONY: pass_$(pass) pass_$(pass)_before pass_$(pass)_doit pass_$(pass)_after
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
2008
2009endef
2010
2011define def_pass
2012$(eval SUBDIRS_$(PASS) ?= $(SUBDIRS) $(SUBDIRS.$(BUILD_TARGET)) $(SUBDIRS.$(BUILD_TARGET.$(BUILD_TARGET_ARCH))) )
2013$(eval SUBDIRS_AFTER_$(PASS) ?= $(SUBDIRS_AFTER) $(SUBDIRS_AFTER.$(BUILD_TARGET)) $(SUBDIRS_AFTER.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) )
2014$(eval MAKEFILES_BEFORE_$(PASS) ?= $(MAKEFILES_BEFORE) $(MAKEFILES_BEFORE.$(BUILD_TARGET)) $(MAKEFILES_BEFORE.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) )
2015$(eval MAKEFILES_AFTER_$(PASS) ?= $(MAKEFILES_AFTER) $(MAKEFILES_AFTER.$(BUILD_TARGET)) $(MAKEFILES_AFTER.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) )
2016
2017$(eval tag:=_before)
2018$(eval dep:=)
2019$(foreach subdir,$(SUBDIRS_$(PASS)) $(SUBDIRS_$(PASS).$(BUILD_TARGET)) $(SUBDIRS_$(PASS).$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) ,$(eval $(def_pass_subdir)))
2020$(foreach makefile,$(MAKEFILES_BEFORE_$(PASS)) $(MAKEFILES_BEFORE_$(PASS).$(BUILD_TARGET)) $(MAKEFILES_BEFORE_$(PASS).$(BUILD_TARGET).$(BUILD_TARGET_ARCH)),$(eval $(def_pass_makefile)))
2021
2022$(eval tag:=_after)
2023$(eval dep:=pass_$(pass)_doit)
2024$(foreach subdir,$(SUBDIRS_AFTER_$(PASS)) $(SUBDIRS_AFTER_$(PASS).$(BUILD_TARGET)) $(SUBDIRS_AFTER_$(PASS).$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) ,$(eval $(def_pass_subdir)))
2025$(foreach makefile,$(MAKEFILES_AFTER_$(PASS)) $(MAKEFILES_AFTER_$(PASS).$(BUILD_TARGET)) $(MAKEFILES_AFTER_$(PASS).$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) ,$(eval $(def_pass_makefile)))
2026
2027ifdef KBUILD_SAFE_PARALLEL
2028.NOTPARALLEL: pass_$(pass) pass_$(pass)_before pass_$(pass)_after pass_$(pass)_this
2029.PHONY: pass_$(pass) pass_$(pass)_before pass_$(pass)_after pass_$(pass)_this pass_$(pass)_doit
2030pass_$(pass)_doit: $(PASS_$(PASS)_trgs) $(foreach var,$(PASS_$(PASS)_vars),$(var))
2031pass_$(pass)_this: pass_$(pass)_before
2032 + $$(QUIET)$$(MAKE) -f $$(MAKEFILE) pass_$(pass)_doit
2033pass_$(pass)_after:: pass_$(pass)_this
2034pass_$(pass): pass_$(pass)_after
2035else
2036.NOTPARALLEL: pass_$(pass) pass_$(pass)_before pass_$(pass)_after pass_$(pass)_doit
2037.PHONY: pass_$(pass) pass_$(pass)_before pass_$(pass)_after pass_$(pass)_doit
2038pass_$(pass)_doit: pass_$(pass)_before \
2039 $(PASS_$(PASS)_trgs) $(foreach var,$(PASS_$(PASS)_vars),$($(var)))
2040pass_$(pass): \
2041 pass_$(pass)_before \
2042 pass_$(pass)_doit \
2043 pass_$(pass)_after
2044endif
2045
2046#$ (warning pass=$(pass) PASS=$(PASS): $(PASS_$(PASS)_trgs) $(PASS_$(PASS)_trgs) $(foreach var,$(PASS_$(PASS)_vars),$($(var))))
2047endef
2048
2049# Generate the defined passes.
2050$(foreach PASS, $(PASSES), \
2051 $(eval pass := $(PASS_$(PASS)_pass)) \
2052 $(eval $(def_pass)))
2053
2054## Pass order
2055# @param $(pass) Current pass name.
2056# @param $(prev_pass) The previous pass name.
2057define def_pass_order
2058ifdef KBUILD_SAFE_PARALLEL
2059.NOTPARALLEL: pass_$(pass)_order
2060.PHONY: pass_$(pass)_order
2061pass_$(pass)_order: $(pass_prev)
2062 $$(call MSG_L1,Pass - $$(if $$(PASS_$(PASS)),$$(PASS_$(PASS)),$(pass)))
2063 + $$(QUIET)$$(MAKE) -f $$(MAKEFILE) pass_$(pass)
2064else
2065.NOTPARALLEL: pass_$(pass)_order pass_$(pass)_banner
2066.PHONY: pass_$(pass)_order pass_$(pass)_banner
2067pass_$(pass)_banner:
2068 $$(call MSG_L1,Pass - $$(if $$(PASS_$(PASS)),$$(PASS_$(PASS)),$(pass)))
2069pass_$(pass)_order: \
2070 $(pass_prev) \
2071 pass_$(pass)_banner \
2072 pass_$(pass)
2073endif
2074$(eval pass_prev := pass_$(pass)_order)
2075endef
2076
2077## PASS: order
2078# Use dependencies to ensure correct pass order.
2079pass_prev :=
2080$(foreach PASS,$(DEFAULT_PASSES),\
2081 $(eval pass := $(PASS_$(PASS)_pass)) \
2082 $(eval $(def_pass_order)))
2083
2084
2085#
2086# THE MAIN RULES
2087#
2088all_recursive: $(pass_prev)
2089
2090rebuild: clean
2091 + $(MAKE) -f $(firstword $(MAKEFILE_LIST)) all_recursive
2092
2093# @todo make this a non-default pass!
2094uninstall:
2095 $(RM) -f $(_INSTALLS)
2096
2097install: pass_installs
2098
2099# misc shortcuts.
2100targets: bldprogs libraries dlls programs sysmods others installs
2101objects: $(_OBJS)
2102bldprogs: $(_BLDPROGS)
2103libraries: $(_LIBS) $(_IMPORT_LIBS) $(_OTHER_LIBRARIES)
2104dlls: $(_DLLS)
2105programs: $(_PROGRAMS)
2106sysmods: $(_SYSMODS)
2107others: $(_OTHERS)
2108installs: $(_INSTALLS_DIRS) $(_INSTALLS)
2109
2110
2111#
2112# kBuild debugging stuff.
2113#
2114_SPACE := $(subst ., ,.)
2115_TAB := $(subst ., ,.)
2116define _NEWLINE
2117
2118
2119endef
2120NLTAB = $(_NEWLINE)$(TAB)
2121show_targets:
2122 @$(foreach target, $(ALL_TARGETS),\
2123 @$(ECHO) "target: $(target)" $(NLTAB)\
2124 @$(ECHO) " PATH_$(target)=$(PATH_$(target))" $(NLTAB)\
2125 @$(ECHO) " TARGET_$(target)=$(TARGET_$(target))" $(NLTAB)\
2126 @$(ECHO) " INSTARGET_$(target)=$(INSTARGET_$(target))" $(NLTAB)\
2127$(foreach prop,$(PROPS_SINGLE) $(PROPS_ACCUMULATE_L) $(PROPS_ACCUMULATE_R) OBJS_ CLEAN, \
2128 $(eval _tmp:=$(firstword $($(target)_BLD_TRG) $(BUILD_TARGET))) \
2129 $(if $($(target)_$(prop).$(_tmp)),\
2130 @$(ECHO) " $(target)_$(prop).$(_tmp)=$($(target)_$(prop).$(_tmp))" $(NLTAB)) \
2131 $(if $($(target)_$(prop)), $(NLTAB)@$(ECHO) " $(target)_$(prop)=$($(target)_$(prop))" $(NLTAB)) \
2132)\
2133$(foreach prop,$(PROPS_DEFERRED), \
2134 $(eval _tmp:=$(firstword $($(target)_BLD_TRG) $(BUILD_TARGET))) \
2135 $(if $(value $(target)_$(prop).$(_tmp)),\
2136 @$(ECHO) ' $(target)_$(prop).$(_tmp)=$(value $(TARGET)_$(prop).$(_tmp))' $(NLTAB)) \
2137 $(if $(value $(target)_$(prop)), $(NLTAB)@$(ECHO) ' $(target)_$(prop)=$(value $(target)_$(prop))' $(NLTAB)) \
2138))
2139
2140
2141
2142#
2143# Include dependency files.
2144#
2145$(foreach dep,$(wildcard $(_DEPFILES)),$(eval include $(dep)))
2146
2147
2148# end-of-file-content
2149__footer_kmk__ := target
2150endif # __footer_kmk__
2151
2152
Note: See TracBrowser for help on using the repository browser.