source: trunk/kBuild/footer.kmk@ 688

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

more or less completed the fetch feature.

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