source: trunk/kBuild/footer.kmk@ 771

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

Use the new append -v feature for generating command deps.

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