source: trunk/kBuild/footer.kmk@ 642

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

Resource file compilation.

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