source: trunk/kBuild/footer.kmk@ 729

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

The target _PATH property should be working now.

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