source: trunk/kBuild/footer.kmk@ 719

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

Fixed bug in the library processing causing the output dir not to be created. When autoinstall, install the target when the shortcut is invoked (not very elegant but it does the job).

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 87.9 KB
Line 
1# $Id: footer.kmk 719 2006-12-14 04:48:20Z 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# create a digest that is stored in the primary target file. Subsequent
638# runswill compare their digest with it to decide if a refetch is required.
639# When a refetch is found necessary, an 'unfetch' is performed first to
640# clean out old files and directores. Note even changes in source order
641# will cause a refetch due to the way the digest is constructed and
642# evaluated.
643#
644# By not depending directly on the archives (nor on any unpacked files)
645# but on a goal made up from the archive name, size and md5, we allow
646# the user to delete the archives. Naturally, this means we'll have to
647# check and fetch missing archives before attempting to unpack them.
648#
649# @remark
650#
651# This feature will *NOT* work correctly with vanilla GNU make becuase
652# it makes use of includedep to avoid too many unnecessary files.
653#
654# @todo
655# 1. Port md5sum or some equivalent tool and include it in kBuild.
656# 2. Download corruption / continuation.
657# 3. It's quite possible that there is one too many indirect dependency now...
658#
659
660## @todo move this!
661MD5SUM := md5sum
662
663## generates the fetch rule
664define def_fetch_src_fetch_rule
665# Indirect goal for downloading something.
666.PRECIOUS: $(out)
667$(out) $($(target)_$(srcname)_FETCH_OUTPUT_): | $($(target)_$(srcname)_FETCH_DEPORD_)
668 $$(call MSG_L1,Downloading $(source)...)
669 @## @todo do fancy stuff like download continuation.
670 $$(QUIET)$$(RM) -f $(out) $(out).md5
671 $($(target)_$(srcname)_FETCH_CMDS_)
672 $$(QUIET2)$(if $(md5),$$(APPEND) $(out).md5 "$(md5) *$(out)")
673 $$(QUIET)$(if $(md5),$$(MD5SUM) -c $(out).md5)
674
675
676
677# Intermediate goal for making sure the md5 and size matches. it will (re) fetch the archive if necessary.
678$(out).checked_$(md5)_$(size): $($(target)_$(srcname)_FETCH_DEPEND_) | $($(target)_$(srcname)_FETCH_DEPORD_)
679 $$(call MSG_L1,Checking $(out),($(source))...)
680 $$(QUIET)$$(RM) -f $$@ $(out).md5
681 @# creates the .md5 we pass to md5sum.
682 $$(QUIET2)$(if $(md5),$$(APPEND) $(out).md5 "$(md5) *$(out)")
683 @# (re)fetch the file if it doesn't exist or if it doesn't matches the md5.
684 @## @todo do fancy stuff like download continuation.
685 $$(QUIET)( test -f $(out) && $(if $(md5),$$(MD5SUM) -c $(out).md5, true) ) \
686 || ( $$(RM_EXT) -f $(out) \
687 && $$(MAKE) $(out) -f $(MAKEFILE) --no-print-directory )
688 $$(QUIET2)$$(APPEND) $$@
689
690_TARGET_$(target)_FETCHED += $(out) $(out).checked_$(md5)_$(size)
691
692# Just a little precaution.
693.NOTPARALLEL: $(out) $(out).checked_$(md5)_$(size)
694
695endef
696
697## generates the unpack rule
698define def_fetch_src_unpack_rule
699# This is the unpack rule. it has an order-only dependency on the download check.
700$(out) $($(target)_$(srcname)_UNPACK_OUTPUT_): $($(target)_$(srcname)_UNPACK_DEPEND_) \
701 | $($(target)_$(srcname)_UNPACK_DEPORD_) $(archive).checked_$(md5)_$(size)
702 $$(call MSG_L1,Unpacking $(archive),into $(inst)...)
703 $$(QUIET)$$(RM) -f $(out)
704 @# if the source archive doesn't exist fetch it (can have been deleted to save space).
705 $$(QUIET)test -f $(archive) \
706 || ( $$(RM_EXT) -f $(archive).checked_$(md5)_$(size) \
707 && $$(MAKE) $(archive).checked_$(md5)_$(size) -f $(MAKEFILE) --no-print-directory )
708 $($(target)_$(srcname)_UNPACK_CMDS_)
709 $$(QUIET2)$$(APPEND) $(out) $(notdir $(archive).checked_$(md5)_$(size))
710 $$(QUIET2)$$(APPEND) $(out) $(notdir $(out))
711
712$(eval _TARGET_$(target)_UNPACKED += $(out))
713_TARGET_$(target)_DIGEST := $(_TARGET_$(target)_DIGEST)-$(srcname)_$(md5)_$(size)
714
715.NOTPARALLEL: $(out)
716
717endef
718
719## Processes a fetch source
720#
721define def_fetch_src
722#$ (warning dbg: def_fetch_src: source='$(source)' target='$(target)')
723
724# common
725srcname := $(notdir $(source))
726inst := $(firstword \
727 $($(target)_$(source)_INST)\
728 $($(target)_$(srcname)_INST)\
729 $($(source)_INST)\
730 $($(srcname)_INST)\
731 $($(target)_INST)\
732)
733ifneq ($(patsubst %/,ok,$(inst)),ok)
734$(error kBuild: Bad or missing INST property for source '$(source)' in target '$(target)': $(inst))
735endif
736INSTARGET_$(target)_$(srcname) := $(inst)
737fetchdir := $(firstword \
738 $($(target)_$(source)_FETCHDIR)\
739 $($(target)_$(srcname)_FETCHDIR)\
740 $($(source)_FETCHDIR)\
741 $($(srcname)_FETCHDIR)\
742 $($(target)_FETCHDIR)\
743 $(FETCHDIR)\
744 $(PATH_TARGET)\
745)
746deps := \
747 $($(target)_$(source)_DEPS)\
748 $($(target)_$(srcname)_DEPS)\
749 $($(source)_DEPS)\
750 $($(srcname)_DEPS)\
751 $($(target)_DEPS)
752md5 := $(firstword \
753 $($(target)_$(source)_MD5)\
754 $($(target)_$(srcname)_MD5)\
755 $($(source)_MD5)\
756 $($(srcname)_MD5)\
757 $($(target)_MD5)\
758)
759size := $(firstword \
760 $($(target)_$(source)_SIZE)\
761 $($(target)_$(srcname)_SIZE)\
762 $($(source)_SIZE)\
763 $($(srcname)_SIZE)\
764 $($(target)_SIZE)\
765)
766dep := # not legal for fetch and unpack tools
767
768
769#
770# The fetching.
771#
772out := $(fetchdir)/$(srcname)
773archive := $(out)
774TARGET_$(target)_$(srcname) := $(out)
775dirdep := $(call DIRDEP,$(fetchdir))
776tool := $(firstword \
777 $($(target)_$(source)_FETCHTOOL)\
778 $($(target)_$(srcname)_FETCHTOOL)\
779 $($(target)_$(source)_TOOL)\
780 $($(target)_$(srcname)_TOOL)\
781 $($(source)_FETCHTOOL)\
782 $($(srcname)_FETCHTOOL)\
783 $($(source)_TOOL)\
784 $($(srcname)_TOOL)\
785 $($(target)_FETCHTOOL)\
786 $($(target)_TOOL)\
787 )
788flags :=\
789 $(TOOL_$(tool)_FETCHFLAGS)\
790 $(FETCHFLAGS)\
791 $($(target)_FETCHFLAGS)\
792 $($(srcname)_FETCHFLAGS)\
793 $($(source)_FETCHFLAGS)\
794 $($(target)_$(srcname)_FETCHFLAGS)\
795 $($(target)_$(source)_FETCHFLAGS)
796
797#$ (warning dbg: target=$(target) source=$(source) $(srcname)=$(srcname) tool=$(tool) out=$(out) flags=$(flags) dirdep=$(dirdep) fetchdir=$(fetchdir) md5=$(md5) size=$(size))
798
799ifndef TOOL_$(tool)_FETCH_CMDS
800$(warning kBuild: tools: \
801 1 $($(target)_$(source)_FETCHTOOL)\
802 2 $($(target)_$(srcname)_FETCHTOOL)\
803 3 $($(target)_$(source)_TOOL)\
804 4 $($(target)_$(srcname)_TOOL)\
805 5 $($(source)_FETCHTOOL)\
806 6 $($(srcname)_FETCHTOOL)\
807 7 $($(source)_TOOL)\
808 8 $($(srcname)_TOOL)\
809 9 $($(target)_FETCHTOOL)\
810 10 $($(target)_TOOL) )
811$(error kBuild: TOOL_$(tool)_FETCH_CMDS is not defined. source=$(source) target=$(target) )
812endif
813
814# call the tool
815$(target)_$(srcname)_FETCH_CMDS_ := $(TOOL_$(tool)_FETCH_CMDS)
816$(target)_$(srcname)_FETCH_OUTPUT_ := $(TOOL_$(tool)_FETCH_OUTPUT)
817$(target)_$(srcname)_FETCH_DEPEND_ := $(TOOL_$(tool)_FETCH_DEPEND) $(deps)
818$(target)_$(srcname)_FETCH_DEPORD_ := $(TOOL_$(tool)_FETCH_DEPORD) $(dirdep)
819
820# generate the fetch rule.
821$(eval $(def_fetch_src_fetch_rule))
822
823
824#
825# The unpacking / installing.
826#
827out := $(inst)_kBuild_$(target)_$(srcname)_unpacked.lst
828dirdep := $(call DIRDEP,$(inst))
829tool := $(firstword \
830 $($(target)_$(source)_UNPACKTOOL)\
831 $($(target)_$(srcname)_UNPACKTOOL)\
832 $($(target)_$(source)_TOOL)\
833 $($(target)_$(srcname)_TOOL)\
834 $($(source)_UNPACKTOOL)\
835 $($(srcname)_UNPACKTOOL)\
836 $($(source)_TOOL)\
837 $($(srcname)_TOOL)\
838 $($(target)_UNPACKTOOL)\
839 $($(target)_TOOL) \
840 )
841ifeq ($(tool),)
842tool := $(toupper $(subst .,,$(suffix $(subst tar.,TAR,$(srcname)))))
843$(eval $(value def_tools_include))
844endif
845flags :=\
846 $(TOOL_$(tool)_UNPACKFLAGS)\
847 $(UNPACKFLAGS)\
848 $($(target)_UNPACKFLAGS)\
849 $($(srcname)_UNPACKFLAGS)\
850 $($(source)_UNPACKFLAGS)\
851 $($(target)_$(srcname)_UNPACKFLAGS)\
852 $($(target)_$(source)_UNPACKFLAGS)
853
854#$ (warning dbg: target=$(target) source=$(source) $(srcname)=$(srcname) tool=$(tool) out=$(out) flags=$(flags) dirdep=$(dirdep) inst=$(inst) md5=$(md5) size=$(size))
855ifndef TOOL_$(tool)_UNPACK_CMDS
856$(warning kBuild: tools: \
857 1 $($(target)_$(source)_UNPACKTOOL)\
858 2 $($(target)_$(srcname)_UNPACKTOOL)\
859 3 $($(target)_$(source)_TOOL)\
860 4 $($(target)_$(srcname)_TOOL)\
861 5 $($(source)_UNPACKTOOL)\
862 6 $($(srcname)_UNPACKTOOL)\
863 7 $($(source)_TOOL)\
864 8 $($(srcname)_TOOL)\
865 9 $($(target)_UNPACKTOOL)\
866 10 $($(target)_TOOL) \
867 11 $(toupper $(subst tar.,TAR,$(ext $(srcname)))) \
868 )
869$(error kBuild: TOOL_$(tool)_UNPACK_CMDS is not defined. source=$(source) target=$(target) )
870endif
871
872# call the tool
873$(target)_$(srcname)_UNPACK_CMDS_ := $(TOOL_$(tool)_UNPACK_CMDS)
874$(target)_$(srcname)_UNPACK_OUTPUT_ := $(TOOL_$(tool)_UNPACK_OUTPUT)
875$(target)_$(srcname)_UNPACK_DEPEND_ := $(TOOL_$(tool)_UNPACK_DEPEND) $(deps)
876$(target)_$(srcname)_UNPACK_DEPORD_ := $(TOOL_$(tool)_UNPACK_DEPORD) $(dirdep)
877
878# generate the fetch rule.
879$(eval $(def_fetch_src_unpack_rule))
880
881_DIRS += $(inst) $(fetchdir)
882
883endef
884
885
886##
887# Define the target level rules for a fetch.
888# @param target
889# @param out
890# @param inst
891# @param _TARGET_$(target)_UNPACKED
892# @param _TARGET_$(target)_DIGEST
893# @param bld_trg
894# @param bld_trg_arch
895define def_fetch_rules
896
897$(out).lst: $(_TARGET_$(target)_UNPACKED) | $(call DIRDEP,$(inst))
898 $$(call MSG_L1,Successfully fetched $(target))
899 $$(QUIET)$$(RM) -f $$@ $$@.tmp
900 $$(QUIET2)$$(APPEND) $$@.tmp "$(notdir $(out))"
901 $$(QUIET)$(if $(_TARGET_$(target)_UNPACKED),$$(CAT_EXT) $(_TARGET_$(target)_UNPACKED) >> $$@.tmp)
902 $$(QUIET)$$(MV) -f $$@.tmp $$@
903
904$(out)_unfetched:
905 $$(call MSG_L1,Unfetching $(target)...)
906 $$(QUIET)$$(RM) -f $$(addprefix $(inst),$$(shell $$(CAT_EXT) $(out).lst 2> /dev/null | $$(SED) -e '/\/$$$$/d'))
907 $$(QUIET)$$(RMDIR) -p --ignore-fail-on-non-empty --ignore-fail-on-not-exist $$(dir $$@) \
908 $$(addprefix $(inst),$$(sort $$(dir $$(shell $$(CAT_EXT) $(out).lst 2> /dev/null))))
909 $$(QUIET)$$(RM) -f $(out).lst $(out)
910 $$(QUIET)$$(RMDIR) -p --ignore-fail-on-non-empty --ignore-fail-on-not-exist $$(dir $$@)
911
912$(out): $(comp-vars _TARGET_$(target)_DIGEST_PREV,_TARGET_$(target)_DIGEST,FORCE) | $(call DIRDEP,$(inst))
913 $$(QUIET)$$(RM) -f $$@
914 $$(call MSG_L1,$$(if $$(wildcard $(out).lst),$$(if $$(_TARGET_$(target)_DIGEST),Re-fetching,Removing),Fetching) $(target)...)
915 $$(QUIET)$$(if $$(wildcard $(out).lst ),$$(MAKE) -f $(MAKEFILE) --no-print-directory $(out)_unfetched)
916 $$(QUIET)$$(if $$(_TARGET_$(target)_DIGEST),$$(MAKE) -f $(MAKEFILE) --no-print-directory $(out).lst,$$(RMDIR) -p --ignore-fail-on-non-empty --ignore-fail-on-not-exist $$(dir $$@))
917 $$(QUIET2)$$(if $$(_TARGET_$(target)_DIGEST),$$(APPEND) $$@ "_TARGET_$(target)_DIGEST_PREV := $(_TARGET_$(target)_DIGEST)")
918
919.NOTPARALLEL: $(out).lst $(out)_unfetched $(out)
920
921endef
922
923
924##
925# Deal with one fetch target.
926# @param target
927# @param bld_trg
928# @param bld_trg_arch
929define def_fetch
930
931# common
932INSTARGET_$(target) := $($(target)_INST)
933ifneq ($(patsubst %/,ok,$(INSTARGET_$(target))),ok)
934$(error kBuild: Bad or missing INST property for target '$(target)'. \
935 $(target)_INST='$($(target)_INST)' ($(origin $(target)_INST)))
936endif
937_TARGET_$(target)_FETCHED :=
938_TARGET_$(target)_UNPACKED :=
939_TARGET_$(target)_DIGEST :=
940
941# The 'sources'.
942#$ (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)))
943$(foreach source,$($(target)_SOURCES) $($(target)_SOURCES.$(BUILD_TYPE)) $($(target)_SOURCES.$(BUILD_TARGET)) $($(target)_SOURCES.$(BUILD_TARGET_ARCH)) $($(target)_SOURCES.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)),\
944 $(eval $(value def_fetch_src)))
945
946# The target.
947inst := $(INSTARGET_$(target))
948out := $(inst)_kBuild_fetch_$(target)
949
950$(eval includedep $(out))
951
952$(eval $(def_fetch_rules))
953
954# Define the aliases here (doesn't work if defined in def_fetch_rules, just like includedep).
955$(target):: $(out)
956$(target)_unfetch:: $(out)_unfetched
957
958_FETCHES += $(out)
959_DOWNLOADS += $(_TARGET_$(target)_FETCHED)
960_UNPACKS += $(_TARGET_$(target)_UNPACKED)
961_UNFETCHES += $(out)_unfetched
962_DIRS += $(inst)
963
964endef
965
966# Walk the FETCH target lists.
967bld_trg := $(BUILD_TARGET)
968bld_trg_arch := $(BUILD_TARGET_ARCH)
969$(foreach target, $(FETCHES) $(FETCHES.$(BUILD_TARGET)) $(FETCHES.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)), \
970 $(eval $(value def_fetch)))
971
972# some aliases.
973download: $(_DOWNLOADS)
974unpack: $(_UNPACKS)
975fetch: $(_FETCHES)
976unfetch: $(_UNFETCHES)
977
978
979
980##
981## Patching.
982##
983##
984#define def_patch_src
985#
986#endef
987#
988#
989## Deal with one patch target.
990#define def_patch
991#
992#$(foreach source,$($(target)_SOURCES) $($(target)_SOURCES.$(BUILD_TYPE)) $($(target)_SOURCES.$(BUILD_TARGET)) $($(target)_SOURCES.$(BUILD_TARGET_ARCH)) $($(target)_SOURCES.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)),\
993# $(eval $(value def_patch_src)))
994#
995#_PATCHES +=
996#endef
997#
998#$(foreach target, $(PATCHES) $(PATCHES.$(BUILD_TARGET)) $(PATCHES.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)), \
999# $(eval $(value def_patch)))
1000#
1001
1002
1003#
1004# Object processing.
1005#
1006
1007## wrapper the compile command dependency check.
1008ifndef NO_COMPILE_CMDS_DEPS
1009 ifneq ($(filter comp-vars,$(KMK_FEATURES)),)
1010_DEP_COMPILE_CMDS = $(comp-vars $(target)_$(source)_CMDS_PREV_,$(target)_$(source)_CMDS_,FORCE)
1011 else
1012_DEP_COMPILE_CMDS = $(if $(subst $(strip $($(target)_$(source)_CMDS_PREV_)),,$(strip $($(target)_$(source)_CMDS_))),FORCE,)
1013 endif
1014else
1015_DEP_COMPILE_CMDS =
1016endif
1017
1018## Generates the rules for building a specific object, and the '::' aliases
1019# for building a source file.
1020# @param $(obj) The object file.
1021define def_target_source_rule
1022$(obj) $($(target)_$(source)_OUTPUT_): \
1023 $($(target)_$(source)_DEPEND_) \
1024 $(_DEP_COMPILE_CMDS) \
1025 | \
1026 $($(target)_$(source)_DEPORD_)
1027 $$(call MSG_L1,Compiling $(source),=> $$@)
1028 $$(QUIET)$$(RM) -f $(dep) $(obj) $($(target)_$(source)_OUTPUT_)
1029 $(custom_pre)
1030
1031$($(target)_$(source)_CMDS_)
1032
1033 $(custom_post)
1034ifndef NO_COMPILE_CMDS_DEPS
1035 $$(QUIET2)$$(APPEND) "$(dep)"
1036 $$(QUIET2)$$(APPEND) "$(dep)" 'define $(target)_$(source)_CMDS_PREV_'
1037 $$(QUIET2)$$(APPEND) "$(dep)" '$(subst $(NL),'$(NL)$(TAB)@$(APPEND) "$(dep)" ',$($(target)_$(source)_CMDS_))'
1038 $$(QUIET2)$$(APPEND) "$(dep)" 'endef'
1039endif
1040
1041$(basename $(notdir $(obj))).o::
1042 + $$(MAKE) -f $$(MAKEFILE) $(obj)
1043$(basename $(notdir $(obj))).obj::
1044 + $$(MAKE) -f $$(MAKEFILE) $(obj)
1045endef
1046
1047
1048## wrapper the link command dependency check.
1049ifndef NO_COMPILE_CMDS_DEPS
1050 ifneq ($(filter comp-vars,$(KMK_FEATURES)),)
1051_DEP_LINK_CMDS = $(comp-vars $(target)_CMDS_PREV_,$(target)_CMDS_,FORCE)
1052 else
1053_DEP_LINK_CMDS = $(if $(subst $(strip $($(target)_CMDS_PREV_)),,$(strip $($(target)_CMDS_))),FORCE,)
1054 endif
1055else
1056_DEP_LINK_CMDS =
1057endif
1058
1059## Generate the link rule for a target.
1060# @param $(target) The normalized target name.
1061# @param $(dirdep) Directories we depend upon begin created before linking.
1062# @param $(dep) The name of the dependency file.
1063# @param $(out)
1064# @param $($(target)_OUTPUT_) Output files from the link.
1065# @param $($(target)_DEPEND_) Dependencies.
1066# @param $($(target)_DEPORD_) Dependencies which should only affect build order.
1067# @param $($(target)_CMDS_) The link commands.
1068# @param $($(target)_CMDS_PREV_) The link commands from the previous run.
1069define def_link_rule
1070$(out) $($(target)_OUTPUT_): \
1071 $($(target)_DEPEND_) \
1072 $(_DEP_LINK_CMDS) \
1073 | \
1074 $($(target)_DEPORD_)
1075 $$(call MSG_L1,Linking $$@)
1076 $$(QUIET)$$(RM) -f $(dep) $(out) $($(target)_OUTPUT_)
1077 $(custom_pre)
1078
1079$($(target)_CMDS_)
1080
1081 $(custom_post)
1082ifndef NO_LINK_CMDS_DEPS
1083 $$(QUIET2)$$(APPEND) "$(dep)" 'define $(target)_CMDS_PREV_'
1084 $$(QUIET2)$$(APPEND) "$(dep)" '$(subst $(NL),'$(NL)$(TAB)@$(APPEND) "$(dep)" ',$($(target)_CMDS_))'
1085 $$(QUIET2)$$(APPEND) "$(dep)" 'endef'
1086endif
1087
1088$(basename $(notdir $(out)))::
1089 + $$(MAKE) -f $$(MAKEFILE) $(out)
1090
1091endef
1092
1093
1094## Generate the link & lib install rule
1095# @param $(target) Normalized target name.
1096# @param $(out) The build target.
1097# @param $(INSTARGET_$(target)) The installation targets.
1098# @param $(mode) The file mode (optional)
1099define def_link_install_rule
1100$(INSTARGET_$(target)) : $(out) | $(call DIRDEP,$(dir $(INSTARGET_$(target))))
1101 $$(call MSG_L1,Installing $(target),=> $$@)
1102 $$(QUIET)$$(INSTALL) $$(if $(mode),-m $(mode)) $(out) $$@
1103
1104ifdef KBUILD_DO_AUTO_INSTALL
1105$(basename $(notdir $(out)))::
1106 + $$(MAKE) -f $$(MAKEFILE) $(INSTARGET_$(target))
1107endif
1108endef
1109
1110
1111
1112## Generic macro for processing C, C++ and Assembly sources.
1113# @param $(target) Normalized target name.
1114# @param $(source) Source file name.
1115# @param $(type) Source type. {C,CXX,AS}
1116# @param bld_type Build type.
1117# @param bld_trg Build target.
1118# @param bld_trg_arch Build target arch.
1119# @param bld_trg_cpu Build target cpu.
1120# @remark obsoleted by kBuild helpers in kmk. Only required for limited gmake compatbility.
1121#
1122define def_target_source_c_cpp_asm_rc_old
1123#$ (warning dbg: def_target_source_c_cpp_asm_rc_old: source='$(source)' target='$(target)' type='$(type)')
1124
1125tool := $(call _SOURCE_TOOL,$(source),$(target),$(type))
1126outbase := $(call _OBJECT_BASE,$(source),$(target))
1127PATH_$(target)_$(source) := $(patsubst %/,%,$(dir $(outbase)))
1128dirdep := $(call DIRDEP,$(dir $(outbase)))
1129defs :=\
1130 $(TOOL_$(tool)_DEFS)\
1131 $(TOOL_$(tool)_DEFS.$(bld_type))\
1132 $(TOOL_$(tool)_DEFS.$(bld_trg))\
1133 $(TOOL_$(tool)_DEFS.$(bld_trg_arch))\
1134 $(TOOL_$(tool)_DEFS.$(bld_trg).$(bld_trg_arch))\
1135 $(TOOL_$(tool)_DEFS.$(bld_trg_cpu))\
1136 $(TOOL_$(tool)_$(type)DEFS)\
1137 $(TOOL_$(tool)_$(type)DEFS.$(bld_type))\
1138 $(foreach sdk, $(SDKS.$(bld_trg).$(bld_trg_arch)) \
1139 $(SDKS.$(bld_trg_arch)) \
1140 $(SDKS.$(bld_trg)) \
1141 $(SDKS.$(bld_type)) \
1142 $(SDKS),\
1143 $(SDK_$(sdk)_DEFS)\
1144 $(SDK_$(sdk)_DEFS.$(bld_type))\
1145 $(SDK_$(sdk)_DEFS.$(bld_trg))\
1146 $(SDK_$(sdk)_DEFS.$(bld_trg_arch))\
1147 $(SDK_$(sdk)_DEFS.$(bld_trg).$(bld_trg_arch))\
1148 $(SDK_$(sdk)_DEFS.$(bld_trg_cpu))\
1149 $(SDK_$(sdk)_$(type)DEFS)\
1150 $(SDK_$(sdk)_$(type)DEFS.$(bld_type))\
1151 $(SDK_$(sdk)_$(type)DEFS.$(bld_trg))\
1152 $(SDK_$(sdk)_$(type)DEFS.$(bld_trg_arch))\
1153 $(SDK_$(sdk)_$(type)DEFS.$(bld_trg).$(bld_trg_arch))\
1154 $(SDK_$(sdk)_$(type)DEFS.$(bld_trg_cpu)))\
1155 $(DEFS)\
1156 $(DEFS.$(bld_type))\
1157 $(DEFS.$(bld_trg))\
1158 $(DEFS.$(bld_trg_arch))\
1159 $(DEFS.$(bld_trg).$(bld_trg_arch))\
1160 $(DEFS.$(bld_trg_cpu))\
1161 $($(type)DEFS)\
1162 $($(type)DEFS.$(bld_type))\
1163 $($(type)DEFS.$(bld_trg))\
1164 $($(type)DEFS.$(bld_trg_arch))\
1165 $($(type)DEFS.$(bld_trg).$(bld_trg_arch))\
1166 $($(type)DEFS.$(bld_trg_cpu))\
1167 $(foreach sdk, $($(target)_SDKS.$(bld_trg).$(bld_trg_arch)) \
1168 $($(target)_SDKS.$(bld_trg_arch)) \
1169 $($(target)_SDKS.$(bld_trg)) \
1170 $($(target)_SDKS.$(bld_type)) \
1171 $($(target)_SDKS),\
1172 $(SDK_$(sdk)_DEFS)\
1173 $(SDK_$(sdk)_DEFS.$(bld_type))\
1174 $(SDK_$(sdk)_DEFS.$(bld_trg))\
1175 $(SDK_$(sdk)_DEFS.$(bld_trg_arch))\
1176 $(SDK_$(sdk)_DEFS.$(bld_trg).$(bld_trg_arch))\
1177 $(SDK_$(sdk)_DEFS.$(bld_trg_cpu))\
1178 $(SDK_$(sdk)_$(type)DEFS)\
1179 $(SDK_$(sdk)_$(type)DEFS.$(bld_type))\
1180 $(SDK_$(sdk)_$(type)DEFS.$(bld_trg))\
1181 $(SDK_$(sdk)_$(type)DEFS.$(bld_trg_arch))\
1182 $(SDK_$(sdk)_$(type)DEFS.$(bld_trg).$(bld_trg_arch))\
1183 $(SDK_$(sdk)_$(type)DEFS.$(bld_trg_cpu)))\
1184 $($(target)_DEFS)\
1185 $($(target)_DEFS.$(bld_type))\
1186 $($(target)_DEFS.$(bld_trg))\
1187 $($(target)_DEFS.$(bld_trg_arch))\
1188 $($(target)_DEFS.$(bld_trg).$(bld_trg_arch))\
1189 $($(target)_DEFS.$(bld_trg_cpu))\
1190 $($(target)_$(type)DEFS)\
1191 $($(target)_$(type)DEFS.$(bld_type))\
1192 $($(target)_$(type)DEFS.$(bld_trg))\
1193 $($(target)_$(type)DEFS.$(bld_trg_arch))\
1194 $($(target)_$(type)DEFS.$(bld_trg).$(bld_trg_arch))\
1195 $($(target)_$(type)DEFS.$(bld_trg_cpu))\
1196 $(foreach sdk, $($(source)_SDKS.$(bld_trg).$(bld_trg_arch)) \
1197 $($(source)_SDKS.$(bld_trg_arch)) \
1198 $($(source)_SDKS.$(bld_trg)) \
1199 $($(source)_SDKS.$(bld_type)) \
1200 $($(source)_SDKS),\
1201 $(SDK_$(sdk)_DEFS)\
1202 $(SDK_$(sdk)_DEFS.$(bld_type))\
1203 $(SDK_$(sdk)_DEFS.$(bld_trg))\
1204 $(SDK_$(sdk)_DEFS.$(bld_trg_arch))\
1205 $(SDK_$(sdk)_DEFS.$(bld_trg).$(bld_trg_arch))\
1206 $(SDK_$(sdk)_DEFS.$(bld_trg_cpu))\
1207 $(SDK_$(sdk)_$(type)DEFS)\
1208 $(SDK_$(sdk)_$(type)DEFS.$(bld_type))\
1209 $(SDK_$(sdk)_$(type)DEFS.$(bld_trg))\
1210 $(SDK_$(sdk)_$(type)DEFS.$(bld_trg_arch))\
1211 $(SDK_$(sdk)_$(type)DEFS.$(bld_trg).$(bld_trg_arch))\
1212 $(SDK_$(sdk)_$(type)DEFS.$(bld_trg_cpu)))\
1213 $($(source)_DEFS)\
1214 $($(source)_DEFS.$(bld_type))\
1215 $($(source)_DEFS.$(bld_trg))\
1216 $($(source)_DEFS.$(bld_trg_arch))\
1217 $($(source)_DEFS.$(bld_trg).$(bld_trg_arch))\
1218 $($(source)_DEFS.$(bld_trg_cpu))\
1219 $($(source)_$(type)DEFS)\
1220 $($(source)_$(type)DEFS.$(bld_type))\
1221 $($(source)_$(type)DEFS.$(bld_trg))\
1222 $($(source)_$(type)DEFS.$(bld_trg_arch))\
1223 $($(source)_$(type)DEFS.$(bld_trg).$(bld_trg_arch))\
1224 $($(source)_$(type)DEFS.$(bld_trg_cpu))\
1225 $(foreach sdk, $($(target)_$(source)_SDKS.$(bld_trg).$(bld_trg_arch)) \
1226 $($(target)_$(source)_SDKS.$(bld_trg_arch)) \
1227 $($(target)_$(source)_SDKS.$(bld_trg)) \
1228 $($(target)_$(source)_SDKS.$(bld_type)) \
1229 $($(target)_$(source)_SDKS),\
1230 $(SDK_$(sdk)_DEFS)\
1231 $(SDK_$(sdk)_DEFS.$(bld_type))\
1232 $(SDK_$(sdk)_DEFS.$(bld_trg))\
1233 $(SDK_$(sdk)_DEFS.$(bld_trg_arch))\
1234 $(SDK_$(sdk)_DEFS.$(bld_trg).$(bld_trg_arch))\
1235 $(SDK_$(sdk)_DEFS.$(bld_trg_cpu))\
1236 $(SDK_$(sdk)_$(type)DEFS)\
1237 $(SDK_$(sdk)_$(type)DEFS.$(bld_type))\
1238 $(SDK_$(sdk)_$(type)DEFS.$(bld_trg))\
1239 $(SDK_$(sdk)_$(type)DEFS.$(bld_trg_arch))\
1240 $(SDK_$(sdk)_$(type)DEFS.$(bld_trg).$(bld_trg_arch))\
1241 $(SDK_$(sdk)_$(type)DEFS.$(bld_trg_cpu)))\
1242 $($(target)_$(source)_DEFS)\
1243 $($(target)_$(source)_DEFS.$(bld_type))\
1244 $($(target)_$(source)_DEFS.$(bld_trg))\
1245 $($(target)_$(source)_DEFS.$(bld_trg_arch))\
1246 $($(target)_$(source)_DEFS.$(bld_trg).$(bld_trg_arch))\
1247 $($(target)_$(source)_DEFS.$(bld_trg_cpu))\
1248 $($(target)_$(source)_$(type)DEFS)\
1249 $($(target)_$(source)_$(type)DEFS.$(bld_type))\
1250 $($(target)_$(source)_$(type)DEFS.$(bld_trg))\
1251 $($(target)_$(source)_$(type)DEFS.$(bld_trg_arch))\
1252 $($(target)_$(source)_$(type)DEFS.$(bld_trg).$(bld_trg_arch))\
1253 $($(target)_$(source)_$(type)DEFS.$(bld_trg_cpu))
1254incs :=\
1255 $($(target)_$(source)_$(type)INCS.$(bld_trg_cpu))\
1256 $($(target)_$(source)_$(type)INCS.$(bld_trg).$(bld_trg_arch))\
1257 $($(target)_$(source)_$(type)INCS.$(bld_trg_arch))\
1258 $($(target)_$(source)_$(type)INCS.$(bld_trg))\
1259 $($(target)_$(source)_$(type)INCS.$(bld_type))\
1260 $($(target)_$(source)_$(type)INCS)\
1261 $($(target)_$(source)_INCS.$(bld_trg_cpu))\
1262 $($(target)_$(source)_INCS.$(bld_trg).$(bld_trg_arch))\
1263 $($(target)_$(source)_INCS.$(bld_trg_arch))\
1264 $($(target)_$(source)_INCS.$(bld_trg))\
1265 $($(target)_$(source)_INCS.$(bld_type))\
1266 $($(target)_$(source)_INCS)\
1267 $(foreach sdk, $($(target)_$(source)_SDKS.$(bld_trg).$(bld_trg_arch)) \
1268 $($(target)_$(source)_SDKS.$(bld_trg_arch)) \
1269 $($(target)_$(source)_SDKS.$(bld_trg)) \
1270 $($(target)_$(source)_SDKS.$(bld_type)) \
1271 $($(target)_$(source)_SDKS),\
1272 $(SDK_$(sdk)_$(type)INCS.$(bld_trg_cpu))\
1273 $(SDK_$(sdk)_$(type)INCS.$(bld_trg).$(bld_trg_arch))\
1274 $(SDK_$(sdk)_$(type)INCS.$(bld_trg_arch))\
1275 $(SDK_$(sdk)_$(type)INCS.$(bld_trg))\
1276 $(SDK_$(sdk)_$(type)INCS.$(bld_type))\
1277 $(SDK_$(sdk)_$(type)INCS)\
1278 $(SDK_$(sdk)_INCS.$(bld_trg_cpu))\
1279 $(SDK_$(sdk)_INCS.$(bld_trg).$(bld_trg_arch))\
1280 $(SDK_$(sdk)_INCS.$(bld_trg_arch))\
1281 $(SDK_$(sdk)_INCS.$(bld_trg))\
1282 $(SDK_$(sdk)_INCS.$(bld_type))\
1283 $(SDK_$(sdk)_INCS))\
1284 $($(source)_$(type)INCS.$(bld_trg_cpu))\
1285 $($(source)_$(type)INCS.$(bld_trg).$(bld_trg_arch))\
1286 $($(source)_$(type)INCS.$(bld_trg_arch))\
1287 $($(source)_$(type)INCS.$(bld_trg))\
1288 $($(source)_$(type)INCS.$(bld_type))\
1289 $($(source)_$(type)INCS)\
1290 $($(source)_INCS.$(bld_trg_cpu))\
1291 $($(source)_INCS.$(bld_trg).$(bld_trg_arch))\
1292 $($(source)_INCS.$(bld_trg_arch))\
1293 $($(source)_INCS.$(bld_trg))\
1294 $($(source)_INCS.$(bld_type))\
1295 $($(source)_INCS)\
1296 $(foreach sdk, $($(source)_SDKS.$(bld_trg).$(bld_trg_arch)) \
1297 $($(source)_SDKS.$(bld_trg_arch)) \
1298 $($(source)_SDKS.$(bld_trg)) \
1299 $($(source)_SDKS.$(bld_type)) \
1300 $($(source)_SDKS),\
1301 $(SDK_$(sdk)_$(type)INCS.$(bld_trg_cpu))\
1302 $(SDK_$(sdk)_$(type)INCS.$(bld_trg).$(bld_trg_arch))\
1303 $(SDK_$(sdk)_$(type)INCS.$(bld_trg_arch))\
1304 $(SDK_$(sdk)_$(type)INCS.$(bld_trg))\
1305 $(SDK_$(sdk)_$(type)INCS.$(bld_type))\
1306 $(SDK_$(sdk)_$(type)INCS)\
1307 $(SDK_$(sdk)_INCS.$(bld_trg_cpu))\
1308 $(SDK_$(sdk)_INCS.$(bld_trg).$(bld_trg_arch))\
1309 $(SDK_$(sdk)_INCS.$(bld_trg_arch))\
1310 $(SDK_$(sdk)_INCS.$(bld_trg))\
1311 $(SDK_$(sdk)_INCS.$(bld_type))\
1312 $(SDK_$(sdk)_INCS))\
1313 $($(target)_$(type)INCS.$(bld_trg_cpu))\
1314 $($(target)_$(type)INCS.$(bld_trg).$(bld_trg_arch))\
1315 $($(target)_$(type)INCS.$(bld_trg_arch))\
1316 $($(target)_$(type)INCS.$(bld_trg))\
1317 $($(target)_$(type)INCS.$(bld_type))\
1318 $($(target)_$(type)INCS)\
1319 $($(target)_INCS.$(bld_trg_cpu))\
1320 $($(target)_INCS.$(bld_trg).$(bld_trg_arch))\
1321 $($(target)_INCS.$(bld_trg_arch))\
1322 $($(target)_INCS.$(bld_trg))\
1323 $($(target)_INCS.$(bld_type))\
1324 $($(target)_INCS)\
1325 $(foreach sdk, $($(target)_SDKS.$(bld_trg).$(bld_trg_arch)) \
1326 $($(target)_SDKS.$(bld_trg_arch)) \
1327 $($(target)_SDKS.$(bld_trg)) \
1328 $($(target)_SDKS.$(bld_type)) \
1329 $($(target)_SDKS),\
1330 $(SDK_$(sdk)_$(type)INCS.$(bld_trg_cpu))\
1331 $(SDK_$(sdk)_$(type)INCS.$(bld_trg).$(bld_trg_arch))\
1332 $(SDK_$(sdk)_$(type)INCS.$(bld_trg_arch))\
1333 $(SDK_$(sdk)_$(type)INCS.$(bld_trg))\
1334 $(SDK_$(sdk)_$(type)INCS.$(bld_type))\
1335 $(SDK_$(sdk)_$(type)INCS)\
1336 $(SDK_$(sdk)_INCS.$(bld_trg_cpu))\
1337 $(SDK_$(sdk)_INCS.$(bld_trg).$(bld_trg_arch))\
1338 $(SDK_$(sdk)_INCS.$(bld_trg_arch))\
1339 $(SDK_$(sdk)_INCS.$(bld_trg))\
1340 $(SDK_$(sdk)_INCS.$(bld_type))\
1341 $(SDK_$(sdk)_INCS))\
1342 $(INCS.$(bld_trg_cpu))\
1343 $(INCS.$(bld_trg).$(bld_trg_arch))\
1344 $(INCS.$(bld_trg_arch))\
1345 $(INCS.$(bld_trg))\
1346 $(INCS.$(bld_type))\
1347 $(INCS)\
1348 $(foreach sdk, $(SDKS.$(bld_trg).$(bld_trg_arch)) \
1349 $(SDKS.$(bld_trg_arch)) \
1350 $(SDKS.$(bld_trg)) \
1351 $(SDKS.$(bld_type)) \
1352 $(SDKS),\
1353 $(SDK_$(sdk)_$(type)INCS.$(bld_trg_cpu))\
1354 $(SDK_$(sdk)_$(type)INCS.$(bld_trg).$(bld_trg_arch))\
1355 $(SDK_$(sdk)_$(type)INCS.$(bld_trg_arch))\
1356 $(SDK_$(sdk)_$(type)INCS.$(bld_trg))\
1357 $(SDK_$(sdk)_$(type)INCS.$(bld_type))\
1358 $(SDK_$(sdk)_$(type)INCS)\
1359 $(SDK_$(sdk)_INCS.$(bld_trg_cpu))\
1360 $(SDK_$(sdk)_INCS.$(bld_trg).$(bld_trg_arch))\
1361 $(SDK_$(sdk)_INCS.$(bld_trg_arch))\
1362 $(SDK_$(sdk)_INCS.$(bld_trg))\
1363 $(SDK_$(sdk)_INCS.$(bld_type))\
1364 $(SDK_$(sdk)_INCS))\
1365 $(TOOL_$(tool)_$(type)INCS.$(bld_trg_cpu))\
1366 $(TOOL_$(tool)_$(type)INCS.$(bld_trg).$(bld_trg_arch))\
1367 $(TOOL_$(tool)_$(type)INCS.$(bld_trg_arch))\
1368 $(TOOL_$(tool)_$(type)INCS.$(bld_trg))\
1369 $(TOOL_$(tool)_$(type)INCS.$(bld_type))\
1370 $(TOOL_$(tool)_$(type)INCS)
1371flags :=\
1372 $(TOOL_$(tool)_$(type)FLAGS)\
1373 $(TOOL_$(tool)_$(type)FLAGS.$(bld_type))\
1374 $(TOOL_$(tool)_$(type)FLAGS.$(bld_trg))\
1375 $(TOOL_$(tool)_$(type)FLAGS.$(bld_trg_arch))\
1376 $(TOOL_$(tool)_$(type)FLAGS.$(bld_trg).$(bld_trg_arch))\
1377 $(TOOL_$(tool)_$(type)FLAGS.$(bld_trg_cpu))\
1378 $($(type)FLAGS)\
1379 $($(type)FLAGS.$(bld_type))\
1380 $($(type)FLAGS.$(bld_trg))\
1381 $($(type)FLAGS.$(bld_trg_arch))\
1382 $($(type)FLAGS.$(bld_trg).$(bld_trg_arch))\
1383 $($(type)FLAGS.$(bld_trg_cpu))\
1384 $($(target)_$(type)FLAGS)\
1385 $($(target)_$(type)FLAGS.$(bld_type))\
1386 $($(target)_$(type)FLAGS.$(bld_trg))\
1387 $($(target)_$(type)FLAGS.$(bld_trg_arch))\
1388 $($(target)_$(type)FLAGS.$(bld_trg).$(bld_trg_arch))\
1389 $($(target)_$(type)FLAGS.$(bld_trg_cpu))\
1390 $($(source)_$(type)FLAGS)\
1391 $($(source)_$(type)FLAGS.$(bld_type))\
1392 $($(source)_$(type)FLAGS.$(bld_trg))\
1393 $($(source)_$(type)FLAGS.$(bld_trg_arch))\
1394 $($(source)_$(type)FLAGS.$(bld_trg).$(bld_trg_arch))\
1395 $($(source)_$(type)FLAGS.$(bld_trg_cpu))\
1396 $($(target)_$(source)_$(type)FLAGS)\
1397 $($(target)_$(source)_$(type)FLAGS.$(bld_type))\
1398 $($(target)_$(source)_$(type)FLAGS.$(bld_trg))\
1399 $($(target)_$(source)_$(type)FLAGS.$(bld_trg_arch))\
1400 $($(target)_$(source)_$(type)FLAGS.$(bld_trg).$(bld_trg_arch))\
1401 $($(target)_$(source)_$(type)FLAGS.$(bld_trg_cpu))
1402# this isn't 100% in sync with kBuild, but it doesn't matter as it's only for gmake now.
1403objsuff := $(firstword \
1404 $($(target)_$(source)_OBJSUFF.$(bld_trg).$(bld_trg_arch))\
1405 $($(target)_$(source)_OBJSUFF.$(bld_trg))\
1406 $($(target)_$(source)_OBJSUFF)\
1407 $($(source)_OBJSUFF.$(bld_trg).$(bld_trg_arch))\
1408 $($(source)_OBJSUFF.$(bld_trg))\
1409 $($(source)_OBJSUFF)\
1410 $($(target)_OBJSUFF.$(bld_trg).$(bld_trg_arch))\
1411 $($(target)_OBJSUFF.$(bld_trg))\
1412 $($(target)_OBJSUFF)\
1413 $(TOOL_$(tool)_$(type)OBJSUFF.$(bld_trg).$(bld_trg_arch))\
1414 $(TOOL_$(tool)_$(type)OBJSUFF.$(bld_trg))\
1415 $(TOOL_$(tool)_$(type)OBJSUFF)\
1416 $(SUFF_OBJ))
1417obj := $(outbase)$(objsuff)
1418deps := \
1419 $($(target)_$(source)_DEPS)\
1420 $($(target)_$(source)_DEPS.$(bld_type))\
1421 $($(target)_$(source)_DEPS.$(bld_trg))\
1422 $($(target)_$(source)_DEPS.$(bld_trg_arch))\
1423 $($(target)_$(source)_DEPS.$(bld_trg).$(bld_trg_arch))\
1424 $($(target)_$(source)_DEPS.$(bld_trg_cpu))\
1425 $($(source)_DEPS)\
1426 $($(source)_DEPS.$(bld_type))\
1427 $($(source)_DEPS.$(bld_trg))\
1428 $($(source)_DEPS.$(bld_trg_arch))\
1429 $($(source)_DEPS.$(bld_trg).$(bld_trg_arch))\
1430 $($(source)_DEPS.$(bld_trg_cpu))\
1431 $($(target)_DEPS)\
1432 $($(target)_DEPS.$(bld_type))\
1433 $($(target)_DEPS.$(bld_trg))\
1434 $($(target)_DEPS.$(bld_trg_arch))\
1435 $($(target)_DEPS.$(bld_trg).$(bld_trg_arch))\
1436 $($(target)_DEPS.$(bld_trg_cpu))
1437
1438# dependencies
1439dep := $(obj)$(SUFF_DEP)
1440ifndef NO_COMPILE_CMDS_DEPS
1441_DEPFILES_INCLUDED += $(dep)
1442$(if $(wildcard $(dep)),$(eval include $(dep)))
1443endif
1444
1445#$ (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))
1446ifndef TOOL_$(tool)_COMPILE_$(type)_CMDS
1447$(warning kBuild: tools: \
1448 1 $($(target)_$(source)_$(type)TOOL.$(bld_trg).$(bld_trg_arch)) \
1449 2 $($(target)_$(source)_$(type)TOOL.$(bld_trg)) \
1450 3 $($(target)_$(source)_$(type)TOOL) \
1451 4 $($(target)_$(source)_TOOL.$(bld_trg).$(bld_trg_arch)) \
1452 5 $($(target)_$(source)_TOOL.$(bld_trg)) \
1453 6 $($(target)_$(source)_TOOL) \
1454 7 $($(target)_$(type)TOOL.$(bld_trg).$(bld_trg_arch)) \
1455 8 $($(target)_$(type)TOOL.$(bld_trg)) \
1456 9 $($(target)_$(type)TOOL) \
1457 10 $($(target)_TOOL.$(bld_trg).$(bld_trg_arch)) \
1458 11 $($(target)_TOOL.$(bld_trg)) \
1459 12 $($(target)_TOOL) \
1460 13 $($(source)_$(type)TOOL.$(bld_trg).$(bld_trg_arch)) \
1461 14 $($(source)_$(type)TOOL.$(bld_trg)) \
1462 15 $($(source)_$(type)TOOL) \
1463 16 $($(source)_TOOL.$(bld_trg).$(bld_trg_arch)) \
1464 17 $($(source)_TOOL.$(bld_trg)) \
1465 18 $($(source)_TOOL) \
1466 19 $($(type)TOOL.$(bld_trg).$(bld_trg_arch)) \
1467 20 $($(type)TOOL.$(bld_trg)) \
1468 21 $($(type)TOOL) \
1469 22 $(TOOL.$(bld_trg).$(bld_trg_arch)) \
1470 23 $(TOOL.$(bld_trg)) \
1471 24 $(TOOL) )
1472$(error kBuild: TOOL_$(tool)_COMPILE_$(type)_CMDS is not defined. source=$(source) target=$(target) )
1473endif
1474
1475# call the tool
1476$(target)_$(source)_CMDS_ := $(TOOL_$(tool)_COMPILE_$(type)_CMDS)
1477$(target)_$(source)_OUTPUT_ := $(TOOL_$(tool)_COMPILE_$(type)_OUTPUT)
1478$(target)_$(source)_DEPEND_ := $(TOOL_$(tool)_COMPILE_$(type)_DEPEND) $(deps) $(source)
1479$(target)_$(source)_DEPORD_ := $(TOOL_$(tool)_COMPILE_$(type)_DEPORD) $(dirdep)
1480
1481# generate the compile rule.
1482$(eval $(def_target_source_rule))
1483
1484_OUT_FILES += $($(target)_$(source)_OUTPUT_)
1485$(target)_OBJS_ += $(obj)
1486
1487endef
1488
1489## Generic macro for processing C, C++ and Assembly sources.
1490# @param $(target) Normalized target name.
1491# @param $(source) Source file name.
1492# @param $(type) Source type. {C,CXX,AS}
1493# @param bld_type Build type.
1494# @param bld_trg Build target.
1495# @param bld_trg_arch Build target arch.
1496# @param bld_trg_cpu Build target cpu.
1497#
1498#$ (warning dbg: def_target_source_c_cpp_asm: source='$(source)' target='$(target)' type='$(type)')
1499def_target_source_c_cpp_asm_rc_new = $(kb-src-one x)
1500
1501ifneq ($(filter kb-src-one,$(KMK_FEATURES)),)
1502def_target_source_c_cpp_asm_rc_var = def_target_source_c_cpp_asm_rc_new
1503else
1504def_target_source_c_cpp_asm_rc_var = def_target_source_c_cpp_asm_rc_old
1505endif
1506
1507## Generic macro for processing all target sources.
1508# @param $(target) Normalized target name.
1509define def_target_sources
1510#$ (warning def_target_sources)
1511# C sources
1512type := C
1513$(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)))\
1514 ,$(eval $(value $(def_target_source_c_cpp_asm_rc_var))) )
1515
1516# C++ sources
1517type := CXX
1518$(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)))\
1519 ,$(eval $(value $(def_target_source_c_cpp_asm_rc_var))) )
1520
1521# ASM sources
1522type := AS
1523$(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)))\
1524 ,$(eval $(value $(def_target_source_c_cpp_asm_rc_var))) )
1525
1526# Resource sources
1527type := RC
1528$(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)))\
1529 ,$(eval $(value $(def_target_source_c_cpp_asm_rc_var))) )
1530
1531endef
1532
1533
1534
1535## Generic macro for generating the install rule(s) for a target
1536# and update the globals with default out.
1537#
1538# @param $(target) Normalized target name.
1539# @param $(out) The output file.
1540# @param $(definst) The default _INST value.
1541# @param $(typevar) The name of the variable with all the root targets of its type.
1542# @obsolete Only library uses this now.
1543define def_target_install_pluss
1544ifndef $(target)_NOINST
1545INSTARGET_$(target) := $(patsubst %/,%/$(notdir $(out)), \
1546 $(if $($(target)_INST), $(addprefix $(PATH_INS)/,$($(target)_INST)), $(definst)/))
1547
1548$(eval $(def_link_install_rule))
1549
1550_INSTALLS += $(INSTARGET_$(target))
1551
1552ifdef KBUILD_DO_AUTO_INSTALL
1553$(typevar) += $(INSTARGET_$(target))
1554else
1555$(typevar) += $(out)
1556endif
1557else # _NOINST
1558$(typevar) += $(out)
1559endif
1560
1561_OUT_FILES += $($(target)_OUTPUT_) $(out)
1562_CLEAN_FILES += $($(target)_CLEAN)
1563_OBJS += $($(target)_OBJS_)
1564
1565endef
1566
1567
1568
1569#
1570# LIBRARIES
1571#
1572
1573## Library (one).
1574# @param $(target) Normalized library (target) name.
1575define def_lib
1576# library basics
1577## @todo prefix
1578bld_type := $(firstword $($(target)_BLD_TYPE) $(BUILD_TYPE))
1579bld_trg := $(firstword $($(target)_BLD_TRG) $(BUILD_TARGET))
1580bld_trg_arch:= $(firstword $($(target)_BLD_TRG_ARCH) $(BUILD_TARGET_ARCH))
1581bld_trg_cpu := $(firstword $($(target)_BLD_TRG_CPU) $(BUILD_TARGET_CPU))
1582tool := $(call _TARGET_TOOL,$(target),AR)
1583ifeq ($(tool),)
1584$(error kBuild: Library target $(target) does not have a tool defined!)
1585endif
1586outbase := $(call _TARGET_BASE,$(target),$(target))
1587PATH_$(target) := $(patsubst %/,%,$(dir $(outbase)))
1588suff := $(firstword\
1589 $($(target)_LIBSUFF.$(bld_trg).$(bld_trg_arch))\
1590 $($(target)_LIBSUFF.$(bld_trg))\
1591 $($(target)_LIBSUFF)\
1592 $(TOOL_$(tool)_ARLIBSUFF.$(bld_trg).$(bld_trg_arch))\
1593 $(TOOL_$(tool)_ARLIBSUFF.$(bld_trg))\
1594 $(TOOL_$(tool)_ARLIBSUFF)\
1595 $(SUFF_LIB))
1596out := $(outbase)$(suff)
1597TARGET_$(target) := $(out)
1598$(target)_OBJS_ :=
1599
1600# source -> object
1601$(eval $(value def_target_sources))
1602
1603# library linking
1604tool := $(call _TARGET_TOOL,$(target),AR)
1605outbase := $(call _TARGET_BASE,$(target),$(target))
1606flags :=\
1607 $(TOOL_$(tool)_ARFLAGS)\
1608 $(TOOL_$(tool)_ARFLAGS.$(bld_type))\
1609 $(ARFLAGS)\
1610 $(ARFLAGS.$(bld_type))\
1611 $($(target)_ARFLAGS)\
1612 $($(target)_ARFLAGS.$(bld_type)) \
1613 $($(target)_ARFLAGS.$(bld_trg)) \
1614 $($(target)_ARFLAGS.$(bld_trg_arch)) \
1615 $($(target)_ARFLAGS.$(bld_trg).$(bld_trg_arch)) \
1616 $($(target)_ARFLAGS.$(bld_trg_cpu))
1617othersrc := $(filter-out %.c %.cpp %.cxx %.cc %.s %.S %.asm %.o %.obj,\
1618 $($(target)_SOURCES) \
1619 $($(target)_SOURCES.$(bld_trg)) \
1620 $($(target)_SOURCES.$(bld_trg_arch)) \
1621 $($(target)_SOURCES.$(bld_trg).$(bld_trg_arch)) \
1622 $($(target)_SOURCES.$(bld_trg_cpu)) \
1623 $($(target)_SOURCES.$(bld_type)))
1624objs = $(filter %.o %.obj, \
1625 $($(target)_SOURCES) \
1626 $($(target)_SOURCES.$(bld_trg)) \
1627 $($(target)_SOURCES.$(bld_trg_arch)) \
1628 $($(target)_SOURCES.$(bld_trg).$(bld_trg_arch)) \
1629 $($(target)_SOURCES.$(bld_trg_cpu)) \
1630 $($(target)_SOURCES.$(bld_type))) \
1631 $($(target)_OBJS_)
1632dirdep := $(call DIRDEP,$(dir $(out)))
1633## @todo fix dependencies on makefiles an such
1634deps := $($(target)_DEPS)
1635
1636# dependency file
1637dep := $(out)$(SUFF_DEP)
1638ifndef NO_LINK_CMDS_DEPS
1639_DEPFILES_INCLUDED += $(dep)
1640$(if $(wildcard $(dep)),$(eval include $(dep)))
1641endif
1642
1643# check that the tool is defined.
1644ifndef TOOL_$(tool)_LINK_LIBRARY_CMDS
1645$(warning kBuild: tools: \
1646 1 $($(target)_$(source)TOOL.$(bld_trg).$(bld_trg_arch)) \
1647 2 $($(target)_$(source)TOOL.$(bld_trg)) \
1648 3 $($(target)_$(source)TOOL) \
1649 4 $($(target)_TOOL.$(bld_trg).$(bld_trg_arch)) \
1650 5 $($(target)_TOOL.$(bld_trg)) \
1651 6 $($(target)_TOOL) \
1652 7 $($(source)TOOL) \
1653 8 $($(source)TOOL.$(bld_trg).$(bld_trg_arch)) \
1654 9 $($(source)TOOL.$(bld_trg)) \
1655 10 $(TOOL.$(bld_trg).$(bld_trg_arch)) \
1656 11 $(TOOL.$(bld_trg)) \
1657 12 $(TOOL) )
1658$(error kBuild: TOOL_$(tool)_LINK_LIBRARY_CMDS isn't defined! target=$(target) )
1659endif
1660
1661# call the tool
1662$(target)_CMDS_ := $(TOOL_$(tool)_LINK_LIBRARY_CMDS)
1663$(target)_OUTPUT_ := $(TOOL_$(tool)_LINK_LIBRARY_OUTPUT)
1664$(target)_DEPEND_ := $(TOOL_$(tool)_LINK_LIBRARY_DEPEND) $(deps) $(objs)
1665$(target)_DEPORD_ := $(TOOL_$(tool)_LINK_LIBRARY_DEPORD) $(dirdep)
1666
1667# generate the link rule.
1668$(eval $(def_link_rule))
1669
1670# installing and globals
1671definst := $(PATH_LIB)
1672typevar := _LIBS
1673$(eval $(value def_target_install_pluss))
1674endef
1675
1676# Process libraries
1677mode := 0644
1678$(foreach target, $(LIBRARIES) $(LIBRARIES.$(BUILD_TARGET)) $(LIBRARIES.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)), $(eval $(value def_lib)))
1679
1680
1681#
1682# Link operations.
1683#
1684
1685##
1686# Link prolog
1687#
1688# @param $(target) Normalized target name.
1689# @param $(EXT) EXE,DLL,SYS.
1690# @param $(definst) The default _INST value.
1691# @param $(typevar) The name of the variable with all the root targets of its type.
1692define def_link_common
1693# basics
1694bld_type := $(firstword $($(target)_BLD_TYPE) $(BUILD_TYPE))
1695bld_trg := $(firstword $($(target)_BLD_TRG) $(BUILD_$(bld_trg_base_var)))
1696bld_trg_arch:= $(firstword $($(target)_BLD_TRG_ARCH) $(BUILD_$(bld_trg_base_var)_ARCH))
1697bld_trg_cpu := $(firstword $($(target)_BLD_TRG_CPU) $(BUILD_$(bld_trg_base_var)_CPU))
1698
1699tool := $(call _TARGET_TOOL,$(target),LD)
1700outbase := $(call _TARGET_BASE,$(target),$(target))
1701suff := $(firstword \
1702 $($(target)_$(EXT)SUFF) \
1703 $($(target)_$(EXT)SUFF) \
1704 $(TOOL_$(tool)_LD$(EXT)SUFF) \
1705 $($(EXTPRE)SUFF_$(EXT)))
1706out := $(outbase)$(suff)
1707PATH_$(target) := $(patsubst %/,%,$(dir $(outbase)))
1708TARGET_$(target) := $(out)
1709$(target)_OBJS_ :=
1710
1711# source -> object
1712$(eval $(value def_target_sources))
1713
1714# more library stuff.
1715tool := $(call _TARGET_TOOL,$(target),LD)
1716outbase := $(call _TARGET_BASE,$(target),$(target))
1717flags :=\
1718 $(TOOL_$(tool)_LDFLAGS)\
1719 $(TOOL_$(tool)_LDFLAGS.$(bld_type))\
1720 $(TOOL_$(tool)_LDFLAGS.$(bld_trg))\
1721 $(TOOL_$(tool)_LDFLAGS.$(bld_trg_arch))\
1722 $(TOOL_$(tool)_LDFLAGS.$(bld_trg).$(bld_trg_arch))\
1723 $(TOOL_$(tool)_LDFLAGS.$(bld_trg_cpu))\
1724 $(LDFLAGS)\
1725 $(LDFLAGS.$(bld_type))\
1726 $(LDFLAGS.$(bld_trg))\
1727 $(LDFLAGS.$(bld_trg_arch))\
1728 $(LDFLAGS.$(bld_trg).$(bld_trg_arch))\
1729 $(LDFLAGS.$(bld_trg_cpu))\
1730 $($(target)_LDFLAGS)\
1731 $($(target)_LDFLAGS.$(bld_type))\
1732 $($(target)_LDFLAGS.$(bld_trg))\
1733 $($(target)_LDFLAGS.$(bld_trg_arch))\
1734 $($(target)_LDFLAGS.$(bld_trg).$(bld_trg_arch))\
1735 $($(target)_LDFLAGS.$(bld_trg_cpu))
1736othersrc := $(filter-out %.c %.cpp %.cxx %.cc %.s %.S %.asm %.o %.obj,\
1737 $($(target)_SOURCES)\
1738 $($(target)_SOURCES.$(bld_trg)) \
1739 $($(target)_SOURCES.$(bld_trg_arch)) \
1740 $($(target)_SOURCES.$(bld_trg).$(bld_trg_arch)) \
1741 $($(target)_SOURCES.$(bld_trg_cpu)) \
1742 $($(target)_SOURCES.$(bld_type)))
1743objs = $(filter %.o %.obj, \
1744 $($(target)_SOURCES) \
1745 $($(target)_SOURCES.$(bld_trg)) \
1746 $($(target)_SOURCES.$(bld_trg_arch)) \
1747 $($(target)_SOURCES.$(bld_trg).$(bld_trg_arch)) \
1748 $($(target)_SOURCES.$(bld_trg_cpu)) \
1749 $($(target)_SOURCES.$(bld_type))) \
1750 $($(target)_OBJS_)
1751libs :=\
1752 $($(target)_LIBS.$(bld_trg_cpu))\
1753 $($(target)_LIBS.$(bld_trg).$(bld_trg_arch))\
1754 $($(target)_LIBS.$(bld_trg_arch))\
1755 $($(target)_LIBS.$(bld_trg))\
1756 $($(target)_LIBS.$(bld_type))\
1757 $($(target)_LIBS)\
1758 $(foreach sdk, $($(target)_SDKS.$(bld_trg).$(bld_trg_arch)) \
1759 $($(target)_SDKS.$(bld_trg_arch)) \
1760 $($(target)_SDKS.$(bld_trg)) \
1761 $($(target)_SDKS.$(bld_type)) \
1762 $($(target)_SDKS),\
1763 $(SDK_$(sdk)_LIBS.$(bld_trg_cpu))\
1764 $(SDK_$(sdk)_LIBS.$(bld_trg).$(bld_trg_arch))\
1765 $(SDK_$(sdk)_LIBS.$(bld_trg_arch))\
1766 $(SDK_$(sdk)_LIBS.$(bld_trg))\
1767 $(SDK_$(sdk)_LIBS.$(bld_type))\
1768 $(SDK_$(sdk)_LIBS))\
1769 $(LIBS.$(bld_trg_cpu))\
1770 $(LIBS.$(bld_trg).$(bld_trg_arch))\
1771 $(LIBS.$(bld_trg_arch))\
1772 $(LIBS.$(bld_trg))\
1773 $(LIBS.$(bld_type))\
1774 $(LIBS)\
1775 $(foreach sdk, $(SDKS.$(bld_trg).$(bld_trg_arch)) \
1776 $(SDKS.$(bld_trg_arch)) \
1777 $(SDKS.$(bld_trg)) \
1778 $(SDKS.$(bld_type)) \
1779 $(SDKS),\
1780 $(SDK_$(sdk)_LIBS.$(bld_trg_cpu))\
1781 $(SDK_$(sdk)_LIBS.$(bld_trg).$(bld_trg_arch))\
1782 $(SDK_$(sdk)_LIBS.$(bld_trg_arch))\
1783 $(SDK_$(sdk)_LIBS.$(bld_trg))\
1784 $(SDK_$(sdk)_LIBS.$(bld_type))\
1785 $(SDK_$(sdk)_LIBS))\
1786 $(TOOL_$(tool)_LIBS.$(bld_trg_cpu))\
1787 $(TOOL_$(tool)_LIBS.$(bld_trg).$(bld_trg_arch))\
1788 $(TOOL_$(tool)_LIBS.$(bld_trg_arch))\
1789 $(TOOL_$(tool)_LIBS.$(bld_trg))\
1790 $(TOOL_$(tool)_LIBS.$(bld_type))\
1791 $(TOOL_$(tool)_LIBS)
1792libpath :=\
1793 $($(target)_LIBPATH.$(bld_trg_cpu))\
1794 $($(target)_LIBPATH.$(bld_trg).$(bld_trg_arch))\
1795 $($(target)_LIBPATH.$(bld_trg_arch))\
1796 $($(target)_LIBPATH.$(bld_trg))\
1797 $($(target)_LIBPATH.$(bld_type))\
1798 $($(target)_LIBPATH)\
1799 $(foreach sdk, $($(target)_SDKS.$(bld_trg).$(bld_trg_arch)) \
1800 $($(target)_SDKS.$(bld_trg_arch)) \
1801 $($(target)_SDKS.$(bld_trg)) \
1802 $($(target)_SDKS.$(bld_type)) \
1803 $($(target)_SDKS),\
1804 $(SDK_$(sdk)_LIBPATH.$(bld_trg_cpu))\
1805 $(SDK_$(sdk)_LIBPATH.$(bld_trg).$(bld_trg_arch))\
1806 $(SDK_$(sdk)_LIBPATH.$(bld_trg_arch))\
1807 $(SDK_$(sdk)_LIBPATH.$(bld_trg))\
1808 $(SDK_$(sdk)_LIBPATH.$(bld_type))\
1809 $(SDK_$(sdk)_LIBPATH))\
1810 $(LIBPATH.$(bld_trg_cpu))\
1811 $(LIBPATH.$(bld_trg).$(bld_trg_arch))\
1812 $(LIBPATH.$(bld_trg_arch))\
1813 $(LIBPATH.$(bld_trg))\
1814 $(LIBPATH.$(bld_type))\
1815 $(LIBPATH)\
1816 $(foreach sdk, $(SDKS.$(bld_trg).$(bld_trg_arch)) \
1817 $(SDKS.$(bld_trg_arch)) \
1818 $(SDKS.$(bld_trg)) \
1819 $(SDKS.$(bld_type)) \
1820 $(SDKS),\
1821 $(SDK_$(sdk)_LIBPATH.$(bld_trg_cpu))\
1822 $(SDK_$(sdk)_LIBPATH.$(bld_trg).$(bld_trg_arch))\
1823 $(SDK_$(sdk)_LIBPATH.$(bld_trg_arch))\
1824 $(SDK_$(sdk)_LIBPATH.$(bld_trg))\
1825 $(SDK_$(sdk)_LIBPATH.$(bld_type))\
1826 $(SDK_$(sdk)_LIBPATH))\
1827 $(TOOL_$(tool)_LIBPATH.$(bld_trg_cpu))\
1828 $(TOOL_$(tool)_LIBPATH.$(bld_trg).$(bld_trg_arch))\
1829 $(TOOL_$(tool)_LIBPATH.$(bld_trg_arch))\
1830 $(TOOL_$(tool)_LIBPATH.$(bld_trg))\
1831 $(TOOL_$(tool)_LIBPATH.$(bld_type))\
1832 $(TOOL_$(tool)_LIBPATH)
1833dirdep := $(call DIRDEP,$(dir $(out)))
1834## @todo fix dependencies
1835deps := $($(target)_DEPS)
1836
1837## @todo this stuff can't be working.
1838custom_pre := $(strip $(firstword \
1839 $($(target)_CUSTOM_PRE.$(bld_trg).$(bld_trg_arch))\
1840 $($(target)_CUSTOM_PRE.$(bld_trg).$(bld_type))\
1841 $($(target)_CUSTOM_PRE.$(bld_trg))\
1842 $($(target)_CUSTOM_PRE.$(bld_type))\
1843 $($(target)_CUSTOM_PRE)\
1844 $(CUSTOM_PRE.$(bld_trg).$(bld_trg_arch))\
1845 $(CUSTOM_PRE.$(bld_trg).$(bld_type))\
1846 $(CUSTOM_PRE.$(bld_trg))\
1847 $(CUSTOM_PRE.$(bld_type))\
1848 $(CUSTOM_PRE)\
1849))
1850custom_post := $(strip $(firstword \
1851 $($(target)_CUSTOM_POST.$(bld_trg).$(bld_trg_arch))\
1852 $($(target)_CUSTOM_POST.$(bld_trg).$(bld_type))\
1853 $($(target)_CUSTOM_POST.$(bld_trg))\
1854 $($(target)_CUSTOM_POST.$(bld_type))\
1855 $($(target)_CUSTOM_POST)\
1856 $(CUSTOM_POST.$(bld_trg).$(bld_trg_arch))\
1857 $(CUSTOM_POST.$(bld_trg).$(bld_type))\
1858 $(CUSTOM_POST.$(bld_trg))\
1859 $(CUSTOM_POST.$(bld_type))\
1860 $(CUSTOM_POST)\
1861))
1862
1863# installation targets
1864ifndef $(target)_NOINST
1865INSTARGET_$(target) := $(patsubst %/,%/$(notdir $(out)), \
1866 $(if $($(target)_INST), $(addprefix $(PATH_INS)/,$($(target)_INST)), $(definst)/))
1867ifdef KBUILD_DO_AUTO_INSTALL
1868$(typevar) += $(INSTARGET_$(target))
1869else
1870$(typevar) += $(out)
1871endif
1872# generate the install rule
1873$(eval $(def_link_install_rule))
1874
1875else # NOINST
1876INSTARGET_$(target) :=
1877$(typevar) += $(out)
1878endif # NOINST
1879
1880# dependency file
1881dep := $(outbase)$(SUFF_DEP)
1882ifndef NO_LINK_CMDS_DEPS
1883_DEPFILES_INCLUDED += $(dep)
1884$(if $(wildcard $(dep)),$(eval include $(dep)))
1885endif
1886
1887# check that the tool is defined.
1888ifndef TOOL_$(tool)_$(tool_do)_CMDS
1889$(warning kBuild: tools: \
1890 1 $($(target)_$(source)TOOL.$(bld_trg).$(bld_trg_arch)) \
1891 2 $($(target)_$(source)TOOL.$(bld_trg)) \
1892 3 $($(target)_$(source)TOOL) \
1893 4 $($(target)_TOOL.$(bld_trg).$(bld_trg_arch)) \
1894 5 $($(target)_TOOL.$(bld_trg)) \
1895 6 $($(target)_TOOL) \
1896 7 $($(source)TOOL.$(bld_trg).$(bld_trg_arch)) \
1897 8 $($(source)TOOL.$(bld_trg)) \
1898 9 $($(source)TOOL) \
1899 10 $(TOOL.$(bld_trg).$(bld_trg_arch)) \
1900 11 $(TOOL.$(bld_trg)) \
1901 12 $(TOOL) )
1902$(error kBuild: TOOL_$(tool)_$(tool_do)_CMDS isn't defined! target=$(target) )
1903endif
1904
1905# call the tool
1906$(target)_CMDS_ := $(TOOL_$(tool)_$(tool_do)_CMDS)
1907$(target)_OUTPUT_ := $(TOOL_$(tool)_$(tool_do)_OUTPUT)
1908$(target)_DEPEND_ := $(TOOL_$(tool)_$(tool_do)_DEPEND) $(deps) $(objs)
1909$(target)_DEPORD_ := $(TOOL_$(tool)_$(tool_do)_DEPORD) $(dirdep)
1910
1911# generate the link rule.
1912$(eval $(def_link_rule))
1913
1914
1915# Update globals.
1916_OBJS += $($(target)_OBJS_)
1917_OUT_FILES += $($(target)_OUTPUT_) $(out)
1918_CLEAN_FILES += $($(target)_CLEAN)
1919_INSTALLS += $(INSTARGET_$(target))
1920
1921endef
1922
1923
1924#
1925# BLDPROGS
1926#
1927
1928## Build program (one).
1929# @param $(target) Normalized target (program) name.
1930define def_bldprog
1931
1932# set NOINST if not forced installation.
1933ifndef $(target)_INST
1934$(target)_NOINST := 1
1935endif
1936
1937# do the usual stuff.
1938$(eval $(value def_link_common))
1939
1940endef
1941
1942# Process build programs.
1943EXT := EXE
1944EXTPRE := HOST
1945tool_do := LINK_PROGRAM
1946definst := $(PATH_BIN)
1947typevar := _BLDPROGS
1948mode := 0755
1949bld_trg_base_var := PLATFORM
1950$(foreach target, $(BLDPROGS) $(BLDPROGS.$(BUILD_PLATFORM)) $(BLDPROGS.$(BUILD_PLATFORM).$(BUILD_PLATFORM_ARCH)), $(eval $(value def_bldprog)))
1951
1952
1953
1954#
1955# DLLS
1956#
1957
1958# Process dlls
1959EXT := DLL
1960EXTPRE :=
1961tool_do := LINK_DLL
1962definst := $(PATH_DLL)
1963typevar := _DLLS
1964mode := 0755
1965bld_trg_base_var := TARGET
1966$(foreach target, $(DLLS) $(DLLS.$(BUILD_TARGET)) $(DLLS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)), $(eval $(value def_link_common)))
1967
1968
1969#
1970# Process import libraries.
1971#
1972# - On OS/2 and windows these are libraries.
1973# - On other platforms they are fake DLLs.
1974ifeq ($(filter-out nt os2 win win64 win32,$(BUILD_TARGET)),)
1975$(foreach target, $(IMPORT_LIBS) $(IMPORT_LIBS.$(BUILD_TARGET)) $(IMPORT_LIBS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)), $(eval $(value def_lib)))
1976else
1977$(foreach target, $(IMPORT_LIBS) $(IMPORT_LIBS.$(BUILD_TARGET)) $(IMPORT_LIBS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)), $(eval $(value def_link_common)))
1978endif
1979$(foreach target, $(IMPORT_LIBS) $(IMPORT_LIBS.$(BUILD_TARGET)) $(IMPORT_LIBS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)), \
1980 $(eval _IMPORT_LIBS += $(if $(INSTARGET_$(target)),$(INSTARGET_$(target)), $(TARGET_$(target)))))
1981
1982
1983#
1984# PROGRAMS
1985#
1986
1987# Process programs
1988EXT := EXE
1989EXTPRE :=
1990tool_do := LINK_PROGRAM
1991definst := $(PATH_BIN)
1992typevar := _PROGRAMS
1993mode := 0755
1994bld_trg_base_var := TARGET
1995$(foreach target, $(PROGRAMS) $(PROGRAMS.$(BUILD_TARGET)) $(PROGRAMS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)), $(eval $(value def_link_common)))
1996
1997
1998
1999#
2000# SYSMODS
2001#
2002
2003# Process sysmods
2004EXT := SYS
2005EXTPRE :=
2006tool_do := LINK_SYSMOD
2007definst := $(PATH_SYS)
2008typevar := _SYSMODS
2009mode := 0644
2010bld_trg_base_var := TARGET
2011$(foreach target, $(SYSMODS) $(SYSMODS.$(BUILD_TARGET)) $(SYSMODS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)), $(eval $(value def_link_common)))
2012
2013
2014#
2015# OTHERS
2016#
2017_OTHERS = $(OTHERS) $(OTHERS.$(BUILD_TARGET)) $(OTHERS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH))
2018
2019
2020#
2021# INSTALLS
2022#
2023
2024## generate the install rule
2025define def_install_src_rule
2026# the install rule
2027$(insdst) : $(srcsrc) | $(call DIRDEP,$(dir $(insdst)))
2028 $$(call MSG_L1,Installing $(srcsrc),=> $(insdst))
2029 $$(QUIET)$$(if $$(filter $(INSTALL),$(inscmd)),,$$(RM) -f $$@)
2030 $$(QUIET)$(inscmd)
2031endef
2032
2033## install one file
2034define def_install_src
2035
2036# deal with '=>' in the source file name.
2037srcdst := $(subst =>, ,$(src))
2038srcsrc := $(firstword $(srcdst))
2039srcdstdir := $(dir $(word 2,$(srcdst)))
2040srcdst := $(word $(words $(srcdst)),$(srcdst))
2041
2042# _INSTFUN
2043ifdef $(srcsrc)_INSTFUN
2044instfun := $(srcsrc)_INSTFUN
2045else
2046ifdef $(target)_INSTFUN
2047instfun := $(target)_INSTFUN
2048else
2049instfun := _INSTALL_FILE
2050endif
2051endif
2052
2053# _INST
2054ifdef $(srcsrc)_INST
2055inst := $(patsubst %/,%,$($(srcsrc)_INST))/$(dir $(srcdstdir))
2056else
2057ifdef $(target)_INST
2058inst := $(patsubst %/,%,$($(target)_INST))/$(dir $(srcdstdir))
2059else
2060inst := $(dir $(srcdstdir))
2061endif
2062endif
2063
2064# calc target
2065insdst := $(call $(instfun),$(srcdst),$(target),$(inst),$(PATH_INS))
2066#$(warning instfun=$(instfun) srcdst=$(srcdst) target=$(target) inst=$(inst) => insdst=$(insdst))
2067
2068# mode, uid and gid
2069mode := $(firstword \
2070 $($(target)_$(srcsrc)_MODE.$(bld_trg).$(bld_trg_arch)) \
2071 $($(target)_$(srcsrc)_MODE.$(bld_trg)) \
2072 $($(target)_$(srcsrc)_MODE) \
2073 $($(target)_$(srcdst)_MODE.$(bld_trg).$(bld_trg_arch)) \
2074 $($(target)_$(srcdst)_MODE.$(bld_trg)) \
2075 $($(target)_$(srcdst)_MODE) \
2076 $($(srcsrc)_MODE.$(bld_trg).$(bld_trg_arch)) \
2077 $($(srcsrc)_MODE.$(bld_trg)) \
2078 $($(srcsrc)_MODE) \
2079 $($(srcdst)_MODE.$(bld_trg).$(bld_trg_arch)) \
2080 $($(srcdst)_MODE.$(bld_trg)) \
2081 $($(srcdst)_MODE) \
2082 $($(target)_MODE.$(bld_trg).$(bld_trg_arch)) \
2083 $($(target)_MODE.$(bld_trg)) \
2084 $($(target)_MODE))
2085uid := $(firstword \
2086 $($(target)_$(srcsrc)_UID.$(bld_trg).$(bld_trg_arch)) \
2087 $($(target)_$(srcsrc)_UID.$(bld_trg)) \
2088 $($(target)_$(srcsrc)_UID) \
2089 $($(target)_$(srcdst)_UID.$(bld_trg).$(bld_trg_arch)) \
2090 $($(target)_$(srcdst)_UID.$(bld_trg)) \
2091 $($(target)_$(srcdst)_UID) \
2092 $($(srcsrc)_UID.$(bld_trg).$(bld_trg_arch)) \
2093 $($(srcsrc)_UID.$(bld_trg)) \
2094 $($(srcsrc)_UID) \
2095 $($(srcdst)_UID.$(bld_trg).$(bld_trg_arch)) \
2096 $($(srcdst)_UID.$(bld_trg)) \
2097 $($(srcdst)_UID) \
2098 $($(target)_UID.$(bld_trg).$(bld_trg_arch)) \
2099 $($(target)_UID.$(bld_trg)) \
2100 $($(target)_UID))
2101gid := $(firstword \
2102 $($(target)_$(srcsrc)_GID.$(bld_trg).$(bld_trg_arch)) \
2103 $($(target)_$(srcsrc)_GID.$(bld_trg)) \
2104 $($(target)_$(srcsrc)_GID) \
2105 $($(target)_$(srcdst)_GID.$(bld_trg).$(bld_trg_arch)) \
2106 $($(target)_$(srcdst)_GID.$(bld_trg)) \
2107 $($(target)_$(srcdst)_GID) \
2108 $($(srcsrc)_GID.$(bld_trg).$(bld_trg_arch)) \
2109 $($(srcsrc)_GID.$(bld_trg)) \
2110 $($(srcsrc)_GID) \
2111 $($(srcdst)_GID.$(bld_trg).$(bld_trg_arch)) \
2112 $($(srcdst)_GID.$(bld_trg)) \
2113 $($(srcdst)_GID) \
2114 $($(target)_GID.$(bld_trg).$(bld_trg_arch)) \
2115 $($(target)_GID.$(bld_trg)) \
2116 $($(target)_GID))
2117
2118# create the command
2119ifdef $(srcsrc)_INSTALLER
2120inscmd := $(call $(srcsrc)_INSTALLER,$(srcsrc),$(insdst),$(target))
2121else
2122ifdef $(target)_INSTALLER
2123inscmd := $(call $(target)_INSTALLER,$(srcsrc),$(insdst),$(target))
2124else
2125inscmd := $$(INSTALL)\
2126 $(if $(uid),-o $(uid))\
2127 $(if $(gid),-g $(gid))\
2128 $(if $(mode),-m $(mode))\
2129 $(srcsrc) $(insdst)
2130endif
2131endif
2132
2133# generate the rule (need double evaluation here)
2134$(eval $(def_install_src_rule))
2135
2136INSTARGET_$(target) += $(insdst)
2137endef
2138
2139
2140## generate the symlink rule
2141define def_install_symlink_rule
2142# the install rule
2143$(insdst) : | $(call DIRDEP,$(dir $(insdst)))
2144 $$(call MSG_L1,Installing symlink $(insdst),pointing to $(symdst))
2145 $$(QUIET)$$(RM) -f $$@
2146 $$(QUIET)$$(LN_SYMLINK) $(symdst) $(insdst)
2147endef
2148
2149## create one symlink
2150define def_install_symlink
2151
2152# deal with '=>' in the source file name.
2153symdst := $(subst =>, ,$(src))
2154symlnk := $(firstword $(symdst))
2155symdst := $(word $(words $(symdst)),$(symdst))
2156
2157# _INSTFUN
2158ifdef $(symlnk)_INSTFUN
2159instfun := $(symlnk)_INSTFUN
2160else
2161ifdef $(target)_INSTFUN
2162instfun := $(target)_INSTFUN
2163else
2164instfun := _INSTALL_FILE
2165endif
2166endif
2167
2168# _INST
2169ifdef $(symlnk)_INST
2170inst := $(patsubst %/,%,$($(symlnk)_INST))/$(dir $(symlnk))
2171else
2172ifdef $(target)_INST
2173inst := $(patsubst %/,%,$($(target)_INST))/$(dir $(symlnk))
2174else
2175inst := $(dir $(symlnk))
2176endif
2177endif
2178
2179# calc target
2180insdst := $(call $(instfun),$(symlnk),$(target),$(inst),$(PATH_INS))
2181#$(warning symlnk=$(symlnk) symdst=$(symdst) insdst=$(insdst) instfun=$(instfun) inst='$(inst)')
2182
2183# generate the rule (need double evaluation here)
2184$(eval $(def_install_symlink_rule))
2185
2186INSTARGET_$(target) += $(insdst)
2187endef
2188
2189
2190## generate the install rule
2191define def_install_directory_rule
2192# the install rule
2193$(insdst):
2194 $$(call MSG_L1,Installing directory $(insdst))
2195 $$(QUIET)$$(INSTALL) -d \
2196 $(if $(uid),-o $(uid))\
2197 $(if $(gid),-g $(gid))\
2198 $(if $(mode),-m $(mode))\
2199 $(insdst)
2200
2201.NOTPARALLEL: $(insdst)
2202endef
2203
2204
2205## create one directory
2206define def_install_directory
2207
2208# _INST
2209ifdef $(directory)_INST
2210inst := $(PATH_INS)/$(patsubst %/,%,$($(directory)_INST))
2211else
2212ifdef $(target)_INST
2213inst := $(PATH_INS)/$(patsubst %/,%,$($(target)_INST))
2214else
2215inst := $(PATH_INS)
2216endif
2217endif
2218
2219mode := $(firstword \
2220 $($(target)_$(directory)_MODE.$(bld_trg).$(bld_trg_arch)) \
2221 $($(target)_$(directory)_MODE.$(bld_trg)) \
2222 $($(target)_$(directory)_MODE) \
2223 $($(directory)_MODE.$(bld_trg).$(bld_trg_arch)) \
2224 $($(directory)_MODE.$(bld_trg)) \
2225 $($(directory)_MODE) \
2226 $($(target)_MODE.$(bld_trg).$(bld_trg_arch)) \
2227 $($(target)_MODE.$(bld_trg)) \
2228 $($(target)_MODE))
2229uid := $(firstword \
2230 $($(target)_$(directory)_UID.$(bld_trg).$(bld_trg_arch)) \
2231 $($(target)_$(directory)_UID.$(bld_trg)) \
2232 $($(target)_$(directory)_UID) \
2233 $($(directory)_UID.$(bld_trg).$(bld_trg_arch)) \
2234 $($(directory)_UID.$(bld_trg)) \
2235 $($(directory)_UID) \
2236 $($(target)_UID.$(bld_trg).$(bld_trg_arch)) \
2237 $($(target)_UID.$(bld_trg)) \
2238 $($(target)_UID))
2239gid := $(firstword \
2240 $($(target)_$(directory)_GID.$(bld_trg).$(bld_trg_arch)) \
2241 $($(target)_$(directory)_GID.$(bld_trg)) \
2242 $($(target)_$(directory)_GID) \
2243 $($(directory)_GID.$(bld_trg).$(bld_trg_arch)) \
2244 $($(directory)_GID.$(bld_trg)) \
2245 $($(directory)_GID) \
2246 $($(target)_GID.$(bld_trg).$(bld_trg_arch)) \
2247 $($(target)_GID.$(bld_trg)) \
2248 $($(target)_GID))
2249
2250insdst := $(inst)/$(directory)/
2251#$(warning directory=$(directory) inst=$(inst) insdst=$(insdst) mode=$(mode) gid=$(gid) uid=$(uid))
2252
2253# generate the rule (need double evaluation here)
2254$(eval $(def_install_directory_rule))
2255
2256INSTARGET_DIRS_$(target) += $(insdst)
2257endef
2258
2259
2260## process one install target.
2261define def_install
2262bld_type := $(firstword $($(target)_BLD_TYPE) $(BUILD_TYPE))
2263bld_trg := $(firstword $($(target)_BLD_TRG) $(BUILD_TARGET))
2264bld_trg_arch:= $(firstword $($(target)_BLD_TRG_ARCH) $(BUILD_TARGET_ARCH))
2265bld_trg_cpu := $(firstword $($(target)_BLD_TRG_CPU) $(BUILD_TARGET_CPU))
2266
2267INSTARGET_$(target) :=
2268INSTARGET_DIRS_$(target) :=
2269
2270$(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)), \
2271 $(eval $(value def_install_directory)))
2272
2273$(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)), \
2274 $(eval $(value def_install_src)))
2275
2276$(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)), \
2277 $(eval $(value def_install_symlink)))
2278
2279_INSTALLS += $(INSTARGET_$(target)) $($(target)_GOALS)
2280_INSTALLS_DIRS += $(INSTARGET_DIRS_$(target))
2281endef
2282
2283## process all install targets
2284$(foreach target, $(INSTALLS) $(INSTALLS.$(BUILD_TARGET)) $(INSTALLS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)), \
2285 $(eval $(value def_install)))
2286
2287
2288#
2289# PACKING
2290#
2291_PACKING += $(PACKING) $(PACKING.$(BUILD_TARGET)) $(PACKING.$(BUILD_TARGET).$(BUILD_TARGET_ARCH))
2292
2293
2294#
2295# DOCS
2296#
2297
2298
2299#
2300# DIRECTORIES
2301#
2302_DIR_ALL := $(sort $(addsuffix /,$(patsubst %/,%,$(_DIRS))) $(dir $(_OUT_FILES) $(_OBJS) $(_INSTALLS)))
2303$(foreach directory,$(_INSTALLS_DIRS), $(eval _DIR_ALL := $(filter-out $(directory),$(_DIR_ALL))))
2304
2305
2306define def_mkdir_rule
2307$(directory):
2308 $$(call MSG_L2,Creating directory $$@)
2309 $$(QUIET)$$(MKDIR) -p $$@
2310endef
2311
2312$(foreach directory,$(_DIR_ALL),$(eval $(def_mkdir_rule)))
2313
2314
2315#
2316# NOTHING
2317#
2318do-nothing:
2319 $(call MSG_L1,Did nothing in $(CURDIR))
2320
2321
2322#
2323# CLEAN UP
2324#
2325do-clean:
2326 $(call MSG_L1,Cleaning...)
2327 $(QUIET)$(RM) -f $(_OUT_FILES) $(_OBJS) $(_DEPFILES) $(_DEPFILES_INCLUDED) $(_CLEAN_FILES) $(OTHER_CLEAN)
2328
2329
2330#
2331# PASSES (including directory and makefile walking)
2332#
2333
2334## Subdir
2335# @param $(pass) Lowercase pass name.
2336# @param $(PASS) Uppercase pass name.
2337# @param $(subdir) Subdirectory
2338# @param $(tag) tag to attach to the rule name.
2339define def_pass_subdir
2340pass_$(pass)$(tag):: $(dep)
2341 + $$(QUIET)$$(MAKE) -C $(subdir) -f $$(notdir $$(firstword $$(wildcard $$(addprefix $(subdir)/,$$(DEFAULT_MAKEFILE))))) pass_$(pass)
2342endef
2343
2344## Submakefile
2345# @param $(pass) Lowercase pass name.
2346# @param $(PASS) Uppercase pass name.
2347# @param $(makefile) Makefile.
2348# @param $(tag) tag to attach to the rule name.
2349define def_pass_makefile
2350pass_$(pass)$(tag):: $(dep)
2351 + $$(QUIET)$$(MAKE) -C $(patsubst %/,%,$(dir $(makefile))) -f $(notdir $(makefile)) pass_$(pass)
2352endef
2353
2354## Execute a pass.
2355# @param $(pass) Lowercase pass name.
2356# @param $(PASS) Uppercase pass name.
2357define def_pass_old
2358$(eval SUBDIRS_$(PASS) ?= $(SUBDIRS) $(SUBDIRS.$(BUILD_TARGET)) $(SUBDIRS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) )
2359$(eval SUBDIRS_AFTER_$(PASS) ?= $(SUBDIRS_AFTER) $(SUBDIRS_AFTER.$(BUILD_TARGET)) $(SUBDIRS_AFTER.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) )
2360$(eval MAKEFILES_BEFORE_$(PASS) ?= $(MAKEFILES_BEFORE) $(MAKEFILES_BEFORE.$(BUILD_TARGET)) $(MAKEFILES_BEFORE.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) )
2361$(eval MAKEFILES_AFTER_$(PASS) ?= $(MAKEFILES_AFTER) $(MAKEFILES_AFTER.$(BUILD_TARGET)) $(MAKEFILES_AFTER.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) )
2362
2363$(eval tag:=_before)
2364$(eval dep:=)
2365$(foreach subdir,$(SUBDIRS_$(PASS)) $(SUBDIRS_$(PASS).$(BUILD_TARGET)) $(SUBDIRS_$(PASS).$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) ,$(eval $(def_pass_subdir)))
2366$(foreach makefile,$(MAKEFILES_BEFORE_$(PASS)) $(MAKEFILES_BEFORE_$(PASS).$(BUILD_TARGET)) $(MAKEFILES_BEFORE_$(PASS).$(BUILD_TARGET).$(BUILD_TARGET_ARCH)),$(eval $(def_pass_makefile)))
2367
2368$(eval tag:=_after)
2369$(eval dep:=pass_$(pass)_doit)
2370$(foreach subdir,$(SUBDIRS_AFTER_$(PASS)) $(SUBDIRS_AFTER_$(PASS).$(BUILD_TARGET)) $(SUBDIRS_AFTER_$(PASS).$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) ,$(eval $(def_pass_subdir)))
2371$(foreach makefile,$(MAKEFILES_AFTER_$(PASS)) $(MAKEFILES_AFTER_$(PASS).$(BUILD_TARGET)) $(MAKEFILES_AFTER_$(PASS).$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) ,$(eval $(def_pass_makefile)))
2372
2373.NOTPARALLEL: pass_$(pass)_before pass_$(pass)_after
2374.PHONY: pass_$(pass) pass_$(pass)_before pass_$(pass)_doit pass_$(pass)_after
2375pass_$(pass)_doit: $(PASS_$(PASS)_trgs) $(foreach var,$(PASS_$(PASS)_vars),$(var))
2376pass_$(pass)_this: pass_$(pass)_before
2377 + $$(QUIET)$$(MAKE) -f $$(MAKEFILE) pass_$(pass)_doit
2378pass_$(pass)_after:: pass_$(pass)_this
2379pass_$(pass): pass_$(pass)_after
2380
2381endef
2382
2383define def_pass
2384$(eval SUBDIRS_$(PASS) ?= $(SUBDIRS) $(SUBDIRS.$(BUILD_TARGET)) $(SUBDIRS.$(BUILD_TARGET.$(BUILD_TARGET_ARCH))) )
2385$(eval SUBDIRS_AFTER_$(PASS) ?= $(SUBDIRS_AFTER) $(SUBDIRS_AFTER.$(BUILD_TARGET)) $(SUBDIRS_AFTER.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) )
2386$(eval MAKEFILES_BEFORE_$(PASS) ?= $(MAKEFILES_BEFORE) $(MAKEFILES_BEFORE.$(BUILD_TARGET)) $(MAKEFILES_BEFORE.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) )
2387$(eval MAKEFILES_AFTER_$(PASS) ?= $(MAKEFILES_AFTER) $(MAKEFILES_AFTER.$(BUILD_TARGET)) $(MAKEFILES_AFTER.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) )
2388
2389$(eval tag:=_before)
2390$(eval dep:=)
2391$(foreach subdir,$(SUBDIRS_$(PASS)) $(SUBDIRS_$(PASS).$(BUILD_TARGET)) $(SUBDIRS_$(PASS).$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) ,$(eval $(def_pass_subdir)))
2392$(foreach makefile,$(MAKEFILES_BEFORE_$(PASS)) $(MAKEFILES_BEFORE_$(PASS).$(BUILD_TARGET)) $(MAKEFILES_BEFORE_$(PASS).$(BUILD_TARGET).$(BUILD_TARGET_ARCH)),$(eval $(def_pass_makefile)))
2393
2394$(eval tag:=_after)
2395$(eval dep:=pass_$(pass)_doit)
2396$(foreach subdir,$(SUBDIRS_AFTER_$(PASS)) $(SUBDIRS_AFTER_$(PASS).$(BUILD_TARGET)) $(SUBDIRS_AFTER_$(PASS).$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) ,$(eval $(def_pass_subdir)))
2397$(foreach makefile,$(MAKEFILES_AFTER_$(PASS)) $(MAKEFILES_AFTER_$(PASS).$(BUILD_TARGET)) $(MAKEFILES_AFTER_$(PASS).$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) ,$(eval $(def_pass_makefile)))
2398
2399ifdef KBUILD_SAFE_PARALLEL
2400.NOTPARALLEL: pass_$(pass) pass_$(pass)_before pass_$(pass)_after pass_$(pass)_this
2401.PHONY: pass_$(pass) pass_$(pass)_before pass_$(pass)_after pass_$(pass)_this pass_$(pass)_doit
2402pass_$(pass)_doit: $(PASS_$(PASS)_trgs) $(foreach var,$(PASS_$(PASS)_vars),$(var))
2403pass_$(pass)_this: pass_$(pass)_before
2404 + $$(QUIET)$$(MAKE) -f $$(MAKEFILE) pass_$(pass)_doit
2405pass_$(pass)_after:: pass_$(pass)_this
2406pass_$(pass): pass_$(pass)_after
2407else
2408.NOTPARALLEL: pass_$(pass) pass_$(pass)_before pass_$(pass)_after pass_$(pass)_doit
2409.PHONY: pass_$(pass) pass_$(pass)_before pass_$(pass)_after pass_$(pass)_doit
2410pass_$(pass)_doit: pass_$(pass)_before \
2411 $(PASS_$(PASS)_trgs) $(foreach var,$(PASS_$(PASS)_vars),$($(var)))
2412pass_$(pass): \
2413 pass_$(pass)_before \
2414 pass_$(pass)_doit \
2415 pass_$(pass)_after
2416endif
2417
2418#$ (warning pass=$(pass) PASS=$(PASS): $(PASS_$(PASS)_trgs) $(PASS_$(PASS)_trgs) $(foreach var,$(PASS_$(PASS)_vars),$($(var))))
2419endef
2420
2421# Generate the defined passes.
2422$(foreach PASS, $(PASSES), \
2423 $(eval pass := $(PASS_$(PASS)_pass)) \
2424 $(eval $(def_pass)))
2425
2426## Pass order
2427# @param $(pass) Current pass name.
2428# @param $(prev_pass) The previous pass name.
2429define def_pass_order
2430ifdef KBUILD_SAFE_PARALLEL
2431.NOTPARALLEL: pass_$(pass)_order
2432.PHONY: pass_$(pass)_order
2433pass_$(pass)_order: $(pass_prev)
2434 $$(call MSG_L1,Pass - $$(if $$(PASS_$(PASS)),$$(PASS_$(PASS)),$(pass)))
2435 + $$(QUIET)$$(MAKE) -f $$(MAKEFILE) pass_$(pass)
2436else
2437.NOTPARALLEL: pass_$(pass)_order pass_$(pass)_banner
2438.PHONY: pass_$(pass)_order pass_$(pass)_banner
2439pass_$(pass)_banner:
2440 $$(call MSG_L1,Pass - $$(if $$(PASS_$(PASS)),$$(PASS_$(PASS)),$(pass)))
2441pass_$(pass)_order: \
2442 $(pass_prev) \
2443 pass_$(pass)_banner \
2444 pass_$(pass)
2445endif
2446$(eval pass_prev := pass_$(pass)_order)
2447endef
2448
2449## PASS: order
2450# Use dependencies to ensure correct pass order.
2451pass_prev :=
2452$(foreach PASS,$(DEFAULT_PASSES),\
2453 $(eval pass := $(PASS_$(PASS)_pass)) \
2454 $(eval $(def_pass_order)))
2455
2456
2457#
2458# THE MAIN RULES
2459#
2460all_recursive: $(pass_prev)
2461
2462rebuild: clean
2463 + $(MAKE) -f $(firstword $(MAKEFILE_LIST)) all_recursive
2464
2465# @todo make this a non-default pass!
2466uninstall:
2467 $(RM) -f $(_INSTALLS)
2468
2469install: pass_installs
2470
2471# misc shortcuts.
2472targets: bldprogs libraries dlls programs sysmods others installs
2473objects: $(_OBJS)
2474bldprogs: $(_BLDPROGS)
2475libraries: $(_LIBS) $(_IMPORT_LIBS) $(_OTHER_LIBRARIES)
2476dlls: $(_DLLS)
2477programs: $(_PROGRAMS)
2478sysmods: $(_SYSMODS)
2479others: $(_OTHERS)
2480installs: $(_INSTALLS_DIRS) $(_INSTALLS)
2481
2482
2483#
2484# kBuild debugging stuff.
2485#
2486_SPACE := $(subst ., ,.)
2487_TAB := $(subst ., ,.)
2488define _NEWLINE
2489
2490
2491endef
2492NLTAB = $(_NEWLINE)$(TAB)
2493show_targets:
2494 @$(foreach target, $(ALL_TARGETS),\
2495 @$(ECHO) "target: $(target)" $(NLTAB)\
2496 @$(ECHO) " PATH_$(target)=$(PATH_$(target))" $(NLTAB)\
2497 @$(ECHO) " TARGET_$(target)=$(TARGET_$(target))" $(NLTAB)\
2498 @$(ECHO) " INSTARGET_$(target)=$(INSTARGET_$(target))" $(NLTAB)\
2499$(foreach prop,$(PROPS_SINGLE) $(PROPS_ACCUMULATE_L) $(PROPS_ACCUMULATE_R) OBJS_ CLEAN, \
2500 $(eval _tmp:=$(firstword $($(target)_BLD_TRG) $(BUILD_TARGET))) \
2501 $(if $($(target)_$(prop).$(_tmp)),\
2502 @$(ECHO) " $(target)_$(prop).$(_tmp)=$($(target)_$(prop).$(_tmp))" $(NLTAB)) \
2503 $(if $($(target)_$(prop)), $(NLTAB)@$(ECHO) " $(target)_$(prop)=$($(target)_$(prop))" $(NLTAB)) \
2504)\
2505$(foreach prop,$(PROPS_DEFERRED), \
2506 $(eval _tmp:=$(firstword $($(target)_BLD_TRG) $(BUILD_TARGET))) \
2507 $(if $(value $(target)_$(prop).$(_tmp)),\
2508 @$(ECHO) ' $(target)_$(prop).$(_tmp)=$(value $(TARGET)_$(prop).$(_tmp))' $(NLTAB)) \
2509 $(if $(value $(target)_$(prop)), $(NLTAB)@$(ECHO) ' $(target)_$(prop)=$(value $(target)_$(prop))' $(NLTAB)) \
2510))
2511
2512
2513
2514#
2515# Include dependency files.
2516#
2517$(foreach dep,$(wildcard $(_DEPFILES)),$(eval include $(dep)))
2518
2519
2520# end-of-file-content
2521__footer_kmk__ := target
2522endif # __footer_kmk__
2523
Note: See TracBrowser for help on using the repository browser.