source: trunk/kBuild/footer.kmk@ 724

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

Kicked the gnumake compatibility crap into separate files to speed things up. Added a slow stack implementation.

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