source: trunk/kBuild/footer.kmk@ 640

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

prototype of tools/source fetching.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 80.3 KB
Line 
1# $Id: footer.kmk 640 2006-12-01 07:42:42Z 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_old
980#$ (warning dbg: def_target_source_c_cpp_asm: 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_new = $(kb-src-one x)
1357
1358ifneq ($(filter kb-src-one,$(KMK_FEATURES)),)
1359def_target_source_c_cpp_asm_var = def_target_source_c_cpp_asm_new
1360else
1361def_target_source_c_cpp_asm_var = def_target_source_c_cpp_asm_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_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_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_var))) )
1382
1383endef
1384
1385
1386
1387## Generic macro for generating the install rule(s) for a target
1388# and update the globals with default out.
1389#
1390# @param $(target) Normalized target name.
1391# @param $(out) The output file.
1392# @param $(definst) The default _INST value.
1393# @param $(typevar) The name of the variable with all the root targets of its type.
1394# @obsolete
1395define def_target_install_pluss
1396ifndef $(target)_NOINST
1397INSTARGET_$(target) := $(patsubst %/,%/$(notdir $(out)), \
1398 $(if $($(target)_INST), $(addprefix $(PATH_INS)/,$($(target)_INST)), $(definst)/))
1399
1400$(eval $(def_link_install_rule))
1401
1402_INSTALLS += $(INSTARGET_$(target))
1403
1404ifdef KBUILD_DO_AUTO_INSTALL
1405$(typevar) += $(INSTARGET_$(target))
1406else
1407$(typevar) += $(out)
1408endif
1409else # _NOINST
1410$(typevar) += $(out)
1411endif
1412
1413_OUT_FILES += $($(target)_OUTPUT_)
1414_CLEAN_FILES += $($(target)_CLEAN)
1415_OBJS += $($(target)_OBJS_)
1416
1417endef
1418
1419
1420
1421#
1422# LIBRARIES
1423#
1424
1425## Library (one).
1426# @param $(target) Normalized library (target) name.
1427define def_lib
1428# library basics
1429## @todo prefix
1430bld_type := $(firstword $($(target)_BLD_TYPE) $(BUILD_TYPE))
1431bld_trg := $(firstword $($(target)_BLD_TRG) $(BUILD_TARGET))
1432bld_trg_arch:= $(firstword $($(target)_BLD_TRG_ARCH) $(BUILD_TARGET_ARCH))
1433bld_trg_cpu := $(firstword $($(target)_BLD_TRG_CPU) $(BUILD_TARGET_CPU))
1434tool := $(call _TARGET_TOOL,$(target),AR)
1435ifeq ($(tool),)
1436$(error kBuild: Library target $(target) does not have a tool defined!)
1437endif
1438outbase := $(call _TARGET_BASE,$(target),$(target))
1439PATH_$(target) := $(patsubst %/,%,$(dir $(outbase)))
1440suff := $(firstword\
1441 $($(target)_LIBSUFF.$(bld_trg).$(bld_trg_arch))\
1442 $($(target)_LIBSUFF.$(bld_trg))\
1443 $($(target)_LIBSUFF)\
1444 $(TOOL_$(tool)_ARLIBSUFF.$(bld_trg).$(bld_trg_arch))\
1445 $(TOOL_$(tool)_ARLIBSUFF.$(bld_trg))\
1446 $(TOOL_$(tool)_ARLIBSUFF)\
1447 $(SUFF_LIB))
1448out := $(outbase)$(suff)
1449TARGET_$(target) := $(out)
1450$(target)_OBJS_ := $(filter %.o %.obj, \
1451 $($(target)_SOURCES) \
1452 $($(target)_SOURCES.$(bld_trg)) \
1453 $($(target)_SOURCES.$(bld_trg_arch)) \
1454 $($(target)_SOURCES.$(bld_trg).$(bld_trg_arch)) \
1455 $($(target)_SOURCES.$(bld_trg_cpu)) \
1456 $($(target)_SOURCES.$(bld_type)))
1457
1458# source -> object
1459$(eval $(value def_target_sources))
1460
1461# library linking
1462tool := $(call _TARGET_TOOL,$(target),AR)
1463outbase := $(call _TARGET_BASE,$(target),$(target))
1464flags :=\
1465 $(TOOL_$(tool)_ARFLAGS)\
1466 $(TOOL_$(tool)_ARFLAGS.$(bld_type))\
1467 $(ARFLAGS)\
1468 $(ARFLAGS.$(bld_type))\
1469 $($(target)_ARFLAGS)\
1470 $($(target)_ARFLAGS.$(bld_type)) \
1471 $($(target)_ARFLAGS.$(bld_trg)) \
1472 $($(target)_ARFLAGS.$(bld_trg_arch)) \
1473 $($(target)_ARFLAGS.$(bld_trg).$(bld_trg_arch)) \
1474 $($(target)_ARFLAGS.$(bld_trg_cpu))
1475othersrc := $(filter-out %.c %.cpp %.cxx %.cc %.s %.S %.asm %.o %.obj,\
1476 $($(target)_SOURCES) \
1477 $($(target)_SOURCES.$(bld_trg)) \
1478 $($(target)_SOURCES.$(bld_trg_arch)) \
1479 $($(target)_SOURCES.$(bld_trg).$(bld_trg_arch)) \
1480 $($(target)_SOURCES.$(bld_trg_cpu)) \
1481 $($(target)_SOURCES.$(bld_type)))
1482objs = $($(target)_OBJS_)
1483dirdep := $(call DIRDEP,$(dir $(out)))
1484## @todo fix dependencies on makefiles an such
1485deps := $($(target)_DEPS)
1486
1487# dependency file
1488dep := $(out)$(SUFF_DEP)
1489ifndef NO_LINK_CMDS_DEPS
1490_DEPFILES_INCLUDED += $(dep)
1491$(if $(wildcard $(dep)),$(eval include $(dep)))
1492endif
1493
1494# check that the tool is defined.
1495ifndef TOOL_$(tool)_LINK_LIBRARY_CMDS
1496$(warning kBuild: tools: \
1497 1 $($(target)_$(source)TOOL.$(bld_trg).$(bld_trg_arch)) \
1498 2 $($(target)_$(source)TOOL.$(bld_trg)) \
1499 3 $($(target)_$(source)TOOL) \
1500 4 $($(target)_TOOL.$(bld_trg).$(bld_trg_arch)) \
1501 5 $($(target)_TOOL.$(bld_trg)) \
1502 6 $($(target)_TOOL) \
1503 7 $($(source)TOOL) \
1504 8 $($(source)TOOL.$(bld_trg).$(bld_trg_arch)) \
1505 9 $($(source)TOOL.$(bld_trg)) \
1506 10 $(TOOL.$(bld_trg).$(bld_trg_arch)) \
1507 11 $(TOOL.$(bld_trg)) \
1508 12 $(TOOL) )
1509$(error kBuild: TOOL_$(tool)_LINK_LIBRARY_CMDS isn't defined! target=$(target) )
1510endif
1511
1512# call the tool
1513$(target)_CMDS_ := $(TOOL_$(tool)_LINK_LIBRARY_CMDS)
1514$(target)_OUTPUT_ := $(TOOL_$(tool)_LINK_LIBRARY_OUTPUT)
1515$(target)_DEPEND_ := $(TOOL_$(tool)_LINK_LIBRARY_DEPEND) $(deps) $(objs)
1516$(target)_DEPORD_ := $(TOOL_$(tool)_LINK_LIBRARY_DEPORD) $(dirdep)
1517
1518# generate the link rule.
1519$(eval $(def_link_rule))
1520
1521# installing and globals
1522definst := $(PATH_LIB)
1523typevar := _LIBS
1524$(eval $(value def_target_install_pluss))
1525endef
1526
1527# Process libraries
1528mode := 0644
1529$(foreach target, $(LIBRARIES) $(LIBRARIES.$(BUILD_TARGET)) $(LIBRARIES.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)), $(eval $(value def_lib)))
1530
1531
1532#
1533# Link operations.
1534#
1535
1536##
1537# Link prolog
1538#
1539# @param $(target) Normalized target name.
1540# @param $(EXT) EXE,DLL,SYS.
1541# @param $(definst) The default _INST value.
1542# @param $(typevar) The name of the variable with all the root targets of its type.
1543define def_link_common
1544# basics
1545bld_type := $(firstword $($(target)_BLD_TYPE) $(BUILD_TYPE))
1546bld_trg := $(firstword $($(target)_BLD_TRG) $(BUILD_$(bld_trg_base_var)))
1547bld_trg_arch:= $(firstword $($(target)_BLD_TRG_ARCH) $(BUILD_$(bld_trg_base_var)_ARCH))
1548bld_trg_cpu := $(firstword $($(target)_BLD_TRG_CPU) $(BUILD_$(bld_trg_base_var)_CPU))
1549
1550tool := $(call _TARGET_TOOL,$(target),LD)
1551outbase := $(call _TARGET_BASE,$(target),$(target))
1552suff := $(firstword \
1553 $($(target)_$(EXT)SUFF) \
1554 $($(target)_$(EXT)SUFF) \
1555 $(TOOL_$(tool)_LD$(EXT)SUFF) \
1556 $($(EXTPRE)SUFF_$(EXT)))
1557out := $(outbase)$(suff)
1558PATH_$(target) := $(patsubst %/,%,$(dir $(outbase)))
1559TARGET_$(target) := $(out)
1560$(target)_OBJS_ := $(filter %.o %.obj, \
1561 $($(target)_SOURCES) \
1562 $($(target)_SOURCES.$(bld_trg)) \
1563 $($(target)_SOURCES.$(bld_trg_arch)) \
1564 $($(target)_SOURCES.$(bld_trg).$(bld_trg_arch)) \
1565 $($(target)_SOURCES.$(bld_trg_cpu)) \
1566 $($(target)_SOURCES.$(bld_type)))
1567
1568# source -> object
1569$(eval $(value def_target_sources))
1570
1571# more library stuff.
1572tool := $(call _TARGET_TOOL,$(target),LD)
1573outbase := $(call _TARGET_BASE,$(target),$(target))
1574flags :=\
1575 $(TOOL_$(tool)_LDFLAGS)\
1576 $(TOOL_$(tool)_LDFLAGS.$(bld_type))\
1577 $(TOOL_$(tool)_LDFLAGS.$(bld_trg))\
1578 $(TOOL_$(tool)_LDFLAGS.$(bld_trg_arch))\
1579 $(TOOL_$(tool)_LDFLAGS.$(bld_trg).$(bld_trg_arch))\
1580 $(TOOL_$(tool)_LDFLAGS.$(bld_trg_cpu))\
1581 $(LDFLAGS)\
1582 $(LDFLAGS.$(bld_type))\
1583 $(LDFLAGS.$(bld_trg))\
1584 $(LDFLAGS.$(bld_trg_arch))\
1585 $(LDFLAGS.$(bld_trg).$(bld_trg_arch))\
1586 $(LDFLAGS.$(bld_trg_cpu))\
1587 $($(target)_LDFLAGS)\
1588 $($(target)_LDFLAGS.$(bld_type))\
1589 $($(target)_LDFLAGS.$(bld_trg))\
1590 $($(target)_LDFLAGS.$(bld_trg_arch))\
1591 $($(target)_LDFLAGS.$(bld_trg).$(bld_trg_arch))\
1592 $($(target)_LDFLAGS.$(bld_trg_cpu))
1593othersrc := $(filter-out %.c %.cpp %.cxx %.cc %.s %.S %.asm %.o %.obj,\
1594 $($(target)_SOURCES)\
1595 $($(target)_SOURCES.$(bld_trg)) \
1596 $($(target)_SOURCES.$(bld_trg_arch)) \
1597 $($(target)_SOURCES.$(bld_trg).$(bld_trg_arch)) \
1598 $($(target)_SOURCES.$(bld_trg_cpu)) \
1599 $($(target)_SOURCES.$(bld_type)))
1600objs = $($(target)_OBJS_)
1601libs :=\
1602 $($(target)_LIBS.$(bld_trg_cpu))\
1603 $($(target)_LIBS.$(bld_trg).$(bld_trg_arch))\
1604 $($(target)_LIBS.$(bld_trg_arch))\
1605 $($(target)_LIBS.$(bld_trg))\
1606 $($(target)_LIBS.$(bld_type))\
1607 $($(target)_LIBS)\
1608 $(foreach sdk, $($(target)_SDKS.$(bld_trg).$(bld_trg_arch)) \
1609 $($(target)_SDKS.$(bld_trg_arch)) \
1610 $($(target)_SDKS.$(bld_trg)) \
1611 $($(target)_SDKS.$(bld_type)) \
1612 $($(target)_SDKS),\
1613 $(SDK_$(sdk)_LIBS.$(bld_trg_cpu))\
1614 $(SDK_$(sdk)_LIBS.$(bld_trg).$(bld_trg_arch))\
1615 $(SDK_$(sdk)_LIBS.$(bld_trg_arch))\
1616 $(SDK_$(sdk)_LIBS.$(bld_trg))\
1617 $(SDK_$(sdk)_LIBS.$(bld_type))\
1618 $(SDK_$(sdk)_LIBS))\
1619 $(LIBS.$(bld_trg_cpu))\
1620 $(LIBS.$(bld_trg).$(bld_trg_arch))\
1621 $(LIBS.$(bld_trg_arch))\
1622 $(LIBS.$(bld_trg))\
1623 $(LIBS.$(bld_type))\
1624 $(LIBS)\
1625 $(foreach sdk, $(SDKS.$(bld_trg).$(bld_trg_arch)) \
1626 $(SDKS.$(bld_trg_arch)) \
1627 $(SDKS.$(bld_trg)) \
1628 $(SDKS.$(bld_type)) \
1629 $(SDKS),\
1630 $(SDK_$(sdk)_LIBS.$(bld_trg_cpu))\
1631 $(SDK_$(sdk)_LIBS.$(bld_trg).$(bld_trg_arch))\
1632 $(SDK_$(sdk)_LIBS.$(bld_trg_arch))\
1633 $(SDK_$(sdk)_LIBS.$(bld_trg))\
1634 $(SDK_$(sdk)_LIBS.$(bld_type))\
1635 $(SDK_$(sdk)_LIBS))\
1636 $(TOOL_$(tool)_LIBS.$(bld_trg_cpu))\
1637 $(TOOL_$(tool)_LIBS.$(bld_trg).$(bld_trg_arch))\
1638 $(TOOL_$(tool)_LIBS.$(bld_trg_arch))\
1639 $(TOOL_$(tool)_LIBS.$(bld_trg))\
1640 $(TOOL_$(tool)_LIBS.$(bld_type))\
1641 $(TOOL_$(tool)_LIBS)
1642libpath :=\
1643 $($(target)_LIBPATH.$(bld_trg_cpu))\
1644 $($(target)_LIBPATH.$(bld_trg).$(bld_trg_arch))\
1645 $($(target)_LIBPATH.$(bld_trg_arch))\
1646 $($(target)_LIBPATH.$(bld_trg))\
1647 $($(target)_LIBPATH.$(bld_type))\
1648 $($(target)_LIBPATH)\
1649 $(foreach sdk, $($(target)_SDKS.$(bld_trg).$(bld_trg_arch)) \
1650 $($(target)_SDKS.$(bld_trg_arch)) \
1651 $($(target)_SDKS.$(bld_trg)) \
1652 $($(target)_SDKS.$(bld_type)) \
1653 $($(target)_SDKS),\
1654 $(SDK_$(sdk)_LIBPATH.$(bld_trg_cpu))\
1655 $(SDK_$(sdk)_LIBPATH.$(bld_trg).$(bld_trg_arch))\
1656 $(SDK_$(sdk)_LIBPATH.$(bld_trg_arch))\
1657 $(SDK_$(sdk)_LIBPATH.$(bld_trg))\
1658 $(SDK_$(sdk)_LIBPATH.$(bld_type))\
1659 $(SDK_$(sdk)_LIBPATH))\
1660 $(LIBPATH.$(bld_trg_cpu))\
1661 $(LIBPATH.$(bld_trg).$(bld_trg_arch))\
1662 $(LIBPATH.$(bld_trg_arch))\
1663 $(LIBPATH.$(bld_trg))\
1664 $(LIBPATH.$(bld_type))\
1665 $(LIBPATH)\
1666 $(foreach sdk, $(SDKS.$(bld_trg).$(bld_trg_arch)) \
1667 $(SDKS.$(bld_trg_arch)) \
1668 $(SDKS.$(bld_trg)) \
1669 $(SDKS.$(bld_type)) \
1670 $(SDKS),\
1671 $(SDK_$(sdk)_LIBPATH.$(bld_trg_cpu))\
1672 $(SDK_$(sdk)_LIBPATH.$(bld_trg).$(bld_trg_arch))\
1673 $(SDK_$(sdk)_LIBPATH.$(bld_trg_arch))\
1674 $(SDK_$(sdk)_LIBPATH.$(bld_trg))\
1675 $(SDK_$(sdk)_LIBPATH.$(bld_type))\
1676 $(SDK_$(sdk)_LIBPATH))\
1677 $(TOOL_$(tool)_LIBPATH.$(bld_trg_cpu))\
1678 $(TOOL_$(tool)_LIBPATH.$(bld_trg).$(bld_trg_arch))\
1679 $(TOOL_$(tool)_LIBPATH.$(bld_trg_arch))\
1680 $(TOOL_$(tool)_LIBPATH.$(bld_trg))\
1681 $(TOOL_$(tool)_LIBPATH.$(bld_type))\
1682 $(TOOL_$(tool)_LIBPATH)
1683dirdep := $(call DIRDEP,$(dir $(out)))
1684## @todo fix dependencies
1685deps := $($(target)_DEPS)
1686
1687## @todo this stuff can't be working.
1688custom_pre := $(strip $(firstword \
1689 $($(target)_CUSTOM_PRE.$(bld_trg).$(bld_trg_arch))\
1690 $($(target)_CUSTOM_PRE.$(bld_trg).$(bld_type))\
1691 $($(target)_CUSTOM_PRE.$(bld_trg))\
1692 $($(target)_CUSTOM_PRE.$(bld_type))\
1693 $($(target)_CUSTOM_PRE)\
1694 $(CUSTOM_PRE.$(bld_trg).$(bld_trg_arch))\
1695 $(CUSTOM_PRE.$(bld_trg).$(bld_type))\
1696 $(CUSTOM_PRE.$(bld_trg))\
1697 $(CUSTOM_PRE.$(bld_type))\
1698 $(CUSTOM_PRE)\
1699))
1700custom_post := $(strip $(firstword \
1701 $($(target)_CUSTOM_POST.$(bld_trg).$(bld_trg_arch))\
1702 $($(target)_CUSTOM_POST.$(bld_trg).$(bld_type))\
1703 $($(target)_CUSTOM_POST.$(bld_trg))\
1704 $($(target)_CUSTOM_POST.$(bld_type))\
1705 $($(target)_CUSTOM_POST)\
1706 $(CUSTOM_POST.$(bld_trg).$(bld_trg_arch))\
1707 $(CUSTOM_POST.$(bld_trg).$(bld_type))\
1708 $(CUSTOM_POST.$(bld_trg))\
1709 $(CUSTOM_POST.$(bld_type))\
1710 $(CUSTOM_POST)\
1711))
1712
1713# installation targets
1714ifndef $(target)_NOINST
1715INSTARGET_$(target) := $(patsubst %/,%/$(notdir $(out)), \
1716 $(if $($(target)_INST), $(addprefix $(PATH_INS)/,$($(target)_INST)), $(definst)/))
1717ifdef KBUILD_DO_AUTO_INSTALL
1718$(typevar) += $(INSTARGET_$(target))
1719else
1720$(typevar) += $(out)
1721endif
1722# generate the install rule
1723$(eval $(def_link_install_rule))
1724
1725else # NOINST
1726INSTARGET_$(target) :=
1727$(typevar) += $(out)
1728endif # NOINST
1729
1730# dependency file
1731dep := $(outbase)$(SUFF_DEP)
1732ifndef NO_LINK_CMDS_DEPS
1733_DEPFILES_INCLUDED += $(dep)
1734$(if $(wildcard $(dep)),$(eval include $(dep)))
1735endif
1736
1737# check that the tool is defined.
1738ifndef TOOL_$(tool)_$(tool_do)_CMDS
1739$(warning kBuild: tools: \
1740 1 $($(target)_$(source)TOOL.$(bld_trg).$(bld_trg_arch)) \
1741 2 $($(target)_$(source)TOOL.$(bld_trg)) \
1742 3 $($(target)_$(source)TOOL) \
1743 4 $($(target)_TOOL.$(bld_trg).$(bld_trg_arch)) \
1744 5 $($(target)_TOOL.$(bld_trg)) \
1745 6 $($(target)_TOOL) \
1746 7 $($(source)TOOL.$(bld_trg).$(bld_trg_arch)) \
1747 8 $($(source)TOOL.$(bld_trg)) \
1748 9 $($(source)TOOL) \
1749 10 $(TOOL.$(bld_trg).$(bld_trg_arch)) \
1750 11 $(TOOL.$(bld_trg)) \
1751 12 $(TOOL) )
1752$(error kBuild: TOOL_$(tool)_$(tool_do)_CMDS isn't defined! target=$(target) )
1753endif
1754
1755# call the tool
1756$(target)_CMDS_ := $(TOOL_$(tool)_$(tool_do)_CMDS)
1757$(target)_OUTPUT_ := $(TOOL_$(tool)_$(tool_do)_OUTPUT)
1758$(target)_DEPEND_ := $(TOOL_$(tool)_$(tool_do)_DEPEND) $(deps) $(objs)
1759$(target)_DEPORD_ := $(TOOL_$(tool)_$(tool_do)_DEPORD) $(dirdep)
1760
1761# generate the link rule.
1762$(eval $(def_link_rule))
1763
1764
1765# Update globals.
1766_OBJS += $($(target)_OBJS_)
1767_OUT_FILES += $($(target)_OUTPUT_) $(out)
1768_CLEAN_FILES += $($(target)_CLEAN)
1769_INSTALLS += $(INSTARGET_$(target))
1770
1771endef
1772
1773
1774#
1775# BLDPROGS
1776#
1777
1778## Build program (one).
1779# @param $(target) Normalized target (program) name.
1780define def_bldprog
1781
1782# set NOINST if not forced installation.
1783ifndef $(target)_INST
1784$(target)_NOINST := 1
1785endif
1786
1787# do the usual stuff.
1788$(eval $(value def_link_common))
1789
1790endef
1791
1792# Process build programs.
1793EXT := EXE
1794EXTPRE := HOST
1795tool_do := LINK_PROGRAM
1796definst := $(PATH_BIN)
1797typevar := _BLDPROGS
1798mode := 0755
1799bld_trg_base_var := PLATFORM
1800$(foreach target, $(BLDPROGS) $(BLDPROGS.$(BUILD_PLATFORM)) $(BLDPROGS.$(BUILD_PLATFORM).$(BUILD_PLATFORM_ARCH)), $(eval $(value def_bldprog)))
1801
1802
1803
1804#
1805# DLLS
1806#
1807
1808# Process dlls
1809EXT := DLL
1810EXTPRE :=
1811tool_do := LINK_DLL
1812definst := $(PATH_DLL)
1813typevar := _DLLS
1814mode := 0755
1815bld_trg_base_var := TARGET
1816$(foreach target, $(DLLS) $(DLLS.$(BUILD_TARGET)) $(DLLS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)), $(eval $(value def_link_common)))
1817
1818
1819#
1820# Process import libraries.
1821#
1822# - On OS/2 and windows these are libraries.
1823# - On other platforms they are fake DLLs.
1824ifeq ($(filter-out nt os2 win win64 win32,$(BUILD_TARGET)),)
1825$(foreach target, $(IMPORT_LIBS) $(IMPORT_LIBS.$(BUILD_TARGET)) $(IMPORT_LIBS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)), $(eval $(value def_lib)))
1826else
1827$(foreach target, $(IMPORT_LIBS) $(IMPORT_LIBS.$(BUILD_TARGET)) $(IMPORT_LIBS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)), $(eval $(value def_link_common)))
1828endif
1829$(foreach target, $(IMPORT_LIBS) $(IMPORT_LIBS.$(BUILD_TARGET)) $(IMPORT_LIBS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)), \
1830 $(eval _IMPORT_LIBS += $(if $(INSTARGET_$(target)),$(INSTARGET_$(target)), $(TARGET_$(target)))))
1831
1832
1833#
1834# PROGRAMS
1835#
1836
1837# Process programs
1838EXT := EXE
1839EXTPRE :=
1840tool_do := LINK_PROGRAM
1841definst := $(PATH_BIN)
1842typevar := _PROGRAMS
1843mode := 0755
1844bld_trg_base_var := TARGET
1845$(foreach target, $(PROGRAMS) $(PROGRAMS.$(BUILD_TARGET)) $(PROGRAMS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)), $(eval $(value def_link_common)))
1846
1847
1848
1849#
1850# SYSMODS
1851#
1852
1853# Process sysmods
1854EXT := SYS
1855EXTPRE :=
1856tool_do := LINK_SYSMOD
1857definst := $(PATH_SYS)
1858typevar := _SYSMODS
1859mode := 0644
1860bld_trg_base_var := TARGET
1861$(foreach target, $(SYSMODS) $(SYSMODS.$(BUILD_TARGET)) $(SYSMODS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)), $(eval $(value def_link_common)))
1862
1863
1864#
1865# OTHERS
1866#
1867_OTHERS = $(OTHERS) $(OTHERS.$(BUILD_TARGET)) $(OTHERS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH))
1868
1869
1870#
1871# INSTALLS
1872#
1873
1874## generate the install rule
1875define def_install_src_rule
1876# the install rule
1877$(insdst) : $(srcsrc) | $(call DIRDEP,$(dir $(insdst)))
1878 $$(if $$(filter $(INSTALL),$(inscmd)),,$$(RM) -f $$@)
1879 $(inscmd)
1880endef
1881
1882## install one file
1883define def_install_src
1884
1885# deal with '=>' in the source file name.
1886srcdst := $(subst =>, ,$(src))
1887srcsrc := $(firstword $(srcdst))
1888srcdstdir := $(dir $(word 2,$(srcdst)))
1889srcdst := $(word $(words $(srcdst)),$(srcdst))
1890
1891# _INSTFUN
1892ifdef $(srcsrc)_INSTFUN
1893instfun := $(srcsrc)_INSTFUN
1894else
1895ifdef $(target)_INSTFUN
1896instfun := $(target)_INSTFUN
1897else
1898instfun := _INSTALL_FILE
1899endif
1900endif
1901
1902# _INST
1903ifdef $(srcsrc)_INST
1904inst := $(patsubst %/,%,$($(srcsrc)_INST))/$(dir $(srcdstdir))
1905else
1906ifdef $(target)_INST
1907inst := $(patsubst %/,%,$($(target)_INST))/$(dir $(srcdstdir))
1908else
1909inst := $(dir $(srcdstdir))
1910endif
1911endif
1912
1913# calc target
1914insdst := $(call $(instfun),$(srcdst),$(target),$(inst),$(PATH_INS))
1915#$(warning instfun=$(instfun) srcdst=$(srcdst) target=$(target) inst=$(inst) => insdst=$(insdst))
1916
1917# mode, uid and gid
1918mode := $(firstword \
1919 $($(target)_$(srcsrc)_MODE.$(bld_trg).$(bld_trg_arch)) \
1920 $($(target)_$(srcsrc)_MODE.$(bld_trg)) \
1921 $($(target)_$(srcsrc)_MODE) \
1922 $($(target)_$(srcdst)_MODE.$(bld_trg).$(bld_trg_arch)) \
1923 $($(target)_$(srcdst)_MODE.$(bld_trg)) \
1924 $($(target)_$(srcdst)_MODE) \
1925 $($(srcsrc)_MODE.$(bld_trg).$(bld_trg_arch)) \
1926 $($(srcsrc)_MODE.$(bld_trg)) \
1927 $($(srcsrc)_MODE) \
1928 $($(srcdst)_MODE.$(bld_trg).$(bld_trg_arch)) \
1929 $($(srcdst)_MODE.$(bld_trg)) \
1930 $($(srcdst)_MODE) \
1931 $($(target)_MODE.$(bld_trg).$(bld_trg_arch)) \
1932 $($(target)_MODE.$(bld_trg)) \
1933 $($(target)_MODE))
1934uid := $(firstword \
1935 $($(target)_$(srcsrc)_UID.$(bld_trg).$(bld_trg_arch)) \
1936 $($(target)_$(srcsrc)_UID.$(bld_trg)) \
1937 $($(target)_$(srcsrc)_UID) \
1938 $($(target)_$(srcdst)_UID.$(bld_trg).$(bld_trg_arch)) \
1939 $($(target)_$(srcdst)_UID.$(bld_trg)) \
1940 $($(target)_$(srcdst)_UID) \
1941 $($(srcsrc)_UID.$(bld_trg).$(bld_trg_arch)) \
1942 $($(srcsrc)_UID.$(bld_trg)) \
1943 $($(srcsrc)_UID) \
1944 $($(srcdst)_UID.$(bld_trg).$(bld_trg_arch)) \
1945 $($(srcdst)_UID.$(bld_trg)) \
1946 $($(srcdst)_UID) \
1947 $($(target)_UID.$(bld_trg).$(bld_trg_arch)) \
1948 $($(target)_UID.$(bld_trg)) \
1949 $($(target)_UID))
1950gid := $(firstword \
1951 $($(target)_$(srcsrc)_GID.$(bld_trg).$(bld_trg_arch)) \
1952 $($(target)_$(srcsrc)_GID.$(bld_trg)) \
1953 $($(target)_$(srcsrc)_GID) \
1954 $($(target)_$(srcdst)_GID.$(bld_trg).$(bld_trg_arch)) \
1955 $($(target)_$(srcdst)_GID.$(bld_trg)) \
1956 $($(target)_$(srcdst)_GID) \
1957 $($(srcsrc)_GID.$(bld_trg).$(bld_trg_arch)) \
1958 $($(srcsrc)_GID.$(bld_trg)) \
1959 $($(srcsrc)_GID) \
1960 $($(srcdst)_GID.$(bld_trg).$(bld_trg_arch)) \
1961 $($(srcdst)_GID.$(bld_trg)) \
1962 $($(srcdst)_GID) \
1963 $($(target)_GID.$(bld_trg).$(bld_trg_arch)) \
1964 $($(target)_GID.$(bld_trg)) \
1965 $($(target)_GID))
1966
1967# create the command
1968ifdef $(srcsrc)_INSTALLER
1969inscmd := $(call $(srcsrc)_INSTALLER,$(srcsrc),$(insdst),$(target))
1970else
1971ifdef $(target)_INSTALLER
1972inscmd := $(call $(target)_INSTALLER,$(srcsrc),$(insdst),$(target))
1973else
1974inscmd := $$(INSTALL)\
1975 $(if $(uid),-o $(uid))\
1976 $(if $(gid),-g $(gid))\
1977 $(if $(mode),-m $(mode))\
1978 $(srcsrc) $(insdst)
1979endif
1980endif
1981
1982# generate the rule (need double evaluation here)
1983$(eval $(def_install_src_rule))
1984
1985INSTARGET_$(target) += $(insdst)
1986endef
1987
1988
1989## generate the symlink rule
1990define def_install_symlink_rule
1991# the install rule
1992$(insdst) : | $(call DIRDEP,$(dir $(insdst)))
1993 $$(RM) -f $$@
1994 $$(LN_SYMLINK) $(symdst) $(insdst)
1995endef
1996
1997## create one symlink
1998define def_install_symlink
1999
2000# deal with '=>' in the source file name.
2001symdst := $(subst =>, ,$(src))
2002symlnk := $(firstword $(symdst))
2003symdst := $(word $(words $(symdst)),$(symdst))
2004
2005# _INSTFUN
2006ifdef $(symlnk)_INSTFUN
2007instfun := $(symlnk)_INSTFUN
2008else
2009ifdef $(target)_INSTFUN
2010instfun := $(target)_INSTFUN
2011else
2012instfun := _INSTALL_FILE
2013endif
2014endif
2015
2016# _INST
2017ifdef $(symlnk)_INST
2018inst := $(patsubst %/,%,$($(symlnk)_INST))/$(dir $(symlnk))
2019else
2020ifdef $(target)_INST
2021inst := $(patsubst %/,%,$($(target)_INST))/$(dir $(symlnk))
2022else
2023inst := $(dir $(symlnk))
2024endif
2025endif
2026
2027# calc target
2028insdst := $(call $(instfun),$(symlnk),$(target),$(inst),$(PATH_INS))
2029#$(warning symlnk=$(symlnk) symdst=$(symdst) insdst=$(insdst) instfun=$(instfun) inst='$(inst)')
2030
2031# generate the rule (need double evaluation here)
2032$(eval $(def_install_symlink_rule))
2033
2034INSTARGET_$(target) += $(insdst)
2035endef
2036
2037
2038## generate the install rule
2039define def_install_directory_rule
2040# the install rule
2041$(insdst):
2042 $(INSTALL) -d \
2043 $(if $(uid),-o $(uid))\
2044 $(if $(gid),-g $(gid))\
2045 $(if $(mode),-m $(mode))\
2046 $(insdst)
2047
2048.NOTPARALLEL: $(insdst)
2049endef
2050
2051
2052## create one directory
2053define def_install_directory
2054
2055# _INST
2056ifdef $(directory)_INST
2057inst := $(PATH_INS)/$(patsubst %/,%,$($(directory)_INST))
2058else
2059ifdef $(target)_INST
2060inst := $(PATH_INS)/$(patsubst %/,%,$($(target)_INST))
2061else
2062inst := $(PATH_INS)
2063endif
2064endif
2065
2066mode := $(firstword \
2067 $($(target)_$(directory)_MODE.$(bld_trg).$(bld_trg_arch)) \
2068 $($(target)_$(directory)_MODE.$(bld_trg)) \
2069 $($(target)_$(directory)_MODE) \
2070 $($(directory)_MODE.$(bld_trg).$(bld_trg_arch)) \
2071 $($(directory)_MODE.$(bld_trg)) \
2072 $($(directory)_MODE) \
2073 $($(target)_MODE.$(bld_trg).$(bld_trg_arch)) \
2074 $($(target)_MODE.$(bld_trg)) \
2075 $($(target)_MODE))
2076uid := $(firstword \
2077 $($(target)_$(directory)_UID.$(bld_trg).$(bld_trg_arch)) \
2078 $($(target)_$(directory)_UID.$(bld_trg)) \
2079 $($(target)_$(directory)_UID) \
2080 $($(directory)_UID.$(bld_trg).$(bld_trg_arch)) \
2081 $($(directory)_UID.$(bld_trg)) \
2082 $($(directory)_UID) \
2083 $($(target)_UID.$(bld_trg).$(bld_trg_arch)) \
2084 $($(target)_UID.$(bld_trg)) \
2085 $($(target)_UID))
2086gid := $(firstword \
2087 $($(target)_$(directory)_GID.$(bld_trg).$(bld_trg_arch)) \
2088 $($(target)_$(directory)_GID.$(bld_trg)) \
2089 $($(target)_$(directory)_GID) \
2090 $($(directory)_GID.$(bld_trg).$(bld_trg_arch)) \
2091 $($(directory)_GID.$(bld_trg)) \
2092 $($(directory)_GID) \
2093 $($(target)_GID.$(bld_trg).$(bld_trg_arch)) \
2094 $($(target)_GID.$(bld_trg)) \
2095 $($(target)_GID))
2096
2097insdst := $(inst)/$(directory)/
2098#$(warning directory=$(directory) inst=$(inst) insdst=$(insdst) mode=$(mode) gid=$(gid) uid=$(uid))
2099
2100# generate the rule (need double evaluation here)
2101$(eval $(def_install_directory_rule))
2102
2103INSTARGET_DIRS_$(target) += $(insdst)
2104endef
2105
2106
2107## process one install target.
2108define def_install
2109bld_type := $(firstword $($(target)_BLD_TYPE) $(BUILD_TYPE))
2110bld_trg := $(firstword $($(target)_BLD_TRG) $(BUILD_TARGET))
2111bld_trg_arch:= $(firstword $($(target)_BLD_TRG_ARCH) $(BUILD_TARGET_ARCH))
2112bld_trg_cpu := $(firstword $($(target)_BLD_TRG_CPU) $(BUILD_TARGET_CPU))
2113
2114INSTARGET_$(target) :=
2115INSTARGET_DIRS_$(target) :=
2116
2117$(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)), \
2118 $(eval $(value def_install_directory)))
2119
2120$(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)), \
2121 $(eval $(value def_install_src)))
2122
2123$(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)), \
2124 $(eval $(value def_install_symlink)))
2125
2126_INSTALLS += $(INSTARGET_$(target)) $($(target)_GOALS)
2127_INSTALLS_DIRS += $(INSTARGET_DIRS_$(target))
2128endef
2129
2130## process all install targets
2131$(foreach target, $(INSTALLS) $(INSTALLS.$(BUILD_TARGET)) $(INSTALLS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)), \
2132 $(eval $(value def_install)))
2133
2134
2135#
2136# PACKING
2137#
2138_PACKING += $(PACKING) $(PACKING.$(BUILD_TARGET)) $(PACKING.$(BUILD_TARGET).$(BUILD_TARGET_ARCH))
2139
2140
2141#
2142# DOCS
2143#
2144
2145
2146#
2147# DIRECTORIES
2148#
2149_DIR_ALL := $(sort $(addsuffix /,$(patsubst %/,%,$(_DIRS))) $(dir $(_OUT_FILES) $(_OBJS) $(_INSTALLS)))
2150$(foreach directory,$(_INSTALLS_DIRS), $(eval _DIR_ALL := $(filter-out $(directory),$(_DIR_ALL))))
2151
2152
2153define def_mkdir_rule
2154$(directory):
2155 $(call MSG_L1,Creating directory $$@)
2156 $(MKDIR) -p $$@
2157endef
2158
2159$(foreach directory,$(_DIR_ALL),$(eval $(def_mkdir_rule)))
2160
2161
2162#
2163# NOTHING
2164#
2165do-nothing:
2166 $(call MSG_L1,Did nothing in $(CURDIR))
2167
2168
2169#
2170# CLEAN UP
2171#
2172do-clean:
2173 $(RM) -f $(_OUT_FILES) $(_OBJS) $(_DEPFILES) $(_DEPFILES_INCLUDED) $(_CLEAN_FILES) $(OTHER_CLEAN)
2174
2175
2176#
2177# PASSES (including directory and makefile walking)
2178#
2179
2180## Subdir
2181# @param $(pass) Lowercase pass name.
2182# @param $(PASS) Uppercase pass name.
2183# @param $(subdir) Subdirectory
2184# @param $(tag) tag to attach to the rule name.
2185define def_pass_subdir
2186pass_$(pass)$(tag):: $(dep)
2187 + $(QUIET)$$(MAKE) -C $(subdir) -f $$(notdir $$(firstword $$(wildcard $$(addprefix $(subdir)/,$$(DEFAULT_MAKEFILE))))) pass_$(pass)
2188endef
2189
2190## Submakefile
2191# @param $(pass) Lowercase pass name.
2192# @param $(PASS) Uppercase pass name.
2193# @param $(makefile) Makefile.
2194# @param $(tag) tag to attach to the rule name.
2195define def_pass_makefile
2196pass_$(pass)$(tag):: $(dep)
2197 + $(QUIET)$$(MAKE) -C $(patsubst %/,%,$(dir $(makefile))) -f $(notdir $(makefile)) pass_$(pass)
2198endef
2199
2200## Execute a pass.
2201# @param $(pass) Lowercase pass name.
2202# @param $(PASS) Uppercase pass name.
2203define def_pass_old
2204$(eval SUBDIRS_$(PASS) ?= $(SUBDIRS) $(SUBDIRS.$(BUILD_TARGET)) $(SUBDIRS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) )
2205$(eval SUBDIRS_AFTER_$(PASS) ?= $(SUBDIRS_AFTER) $(SUBDIRS_AFTER.$(BUILD_TARGET)) $(SUBDIRS_AFTER.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) )
2206$(eval MAKEFILES_BEFORE_$(PASS) ?= $(MAKEFILES_BEFORE) $(MAKEFILES_BEFORE.$(BUILD_TARGET)) $(MAKEFILES_BEFORE.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) )
2207$(eval MAKEFILES_AFTER_$(PASS) ?= $(MAKEFILES_AFTER) $(MAKEFILES_AFTER.$(BUILD_TARGET)) $(MAKEFILES_AFTER.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) )
2208
2209$(eval tag:=_before)
2210$(eval dep:=)
2211$(foreach subdir,$(SUBDIRS_$(PASS)) $(SUBDIRS_$(PASS).$(BUILD_TARGET)) $(SUBDIRS_$(PASS).$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) ,$(eval $(def_pass_subdir)))
2212$(foreach makefile,$(MAKEFILES_BEFORE_$(PASS)) $(MAKEFILES_BEFORE_$(PASS).$(BUILD_TARGET)) $(MAKEFILES_BEFORE_$(PASS).$(BUILD_TARGET).$(BUILD_TARGET_ARCH)),$(eval $(def_pass_makefile)))
2213
2214$(eval tag:=_after)
2215$(eval dep:=pass_$(pass)_doit)
2216$(foreach subdir,$(SUBDIRS_AFTER_$(PASS)) $(SUBDIRS_AFTER_$(PASS).$(BUILD_TARGET)) $(SUBDIRS_AFTER_$(PASS).$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) ,$(eval $(def_pass_subdir)))
2217$(foreach makefile,$(MAKEFILES_AFTER_$(PASS)) $(MAKEFILES_AFTER_$(PASS).$(BUILD_TARGET)) $(MAKEFILES_AFTER_$(PASS).$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) ,$(eval $(def_pass_makefile)))
2218
2219.NOTPARALLEL: pass_$(pass)_before pass_$(pass)_after
2220.PHONY: pass_$(pass) pass_$(pass)_before pass_$(pass)_doit pass_$(pass)_after
2221pass_$(pass)_doit: $(PASS_$(PASS)_trgs) $(foreach var,$(PASS_$(PASS)_vars),$(var))
2222pass_$(pass)_this: pass_$(pass)_before
2223 + $(QUIET)$$(MAKE) -f $$(MAKEFILE) pass_$(pass)_doit
2224pass_$(pass)_after:: pass_$(pass)_this
2225pass_$(pass): pass_$(pass)_after
2226
2227endef
2228
2229define def_pass
2230$(eval SUBDIRS_$(PASS) ?= $(SUBDIRS) $(SUBDIRS.$(BUILD_TARGET)) $(SUBDIRS.$(BUILD_TARGET.$(BUILD_TARGET_ARCH))) )
2231$(eval SUBDIRS_AFTER_$(PASS) ?= $(SUBDIRS_AFTER) $(SUBDIRS_AFTER.$(BUILD_TARGET)) $(SUBDIRS_AFTER.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) )
2232$(eval MAKEFILES_BEFORE_$(PASS) ?= $(MAKEFILES_BEFORE) $(MAKEFILES_BEFORE.$(BUILD_TARGET)) $(MAKEFILES_BEFORE.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) )
2233$(eval MAKEFILES_AFTER_$(PASS) ?= $(MAKEFILES_AFTER) $(MAKEFILES_AFTER.$(BUILD_TARGET)) $(MAKEFILES_AFTER.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) )
2234
2235$(eval tag:=_before)
2236$(eval dep:=)
2237$(foreach subdir,$(SUBDIRS_$(PASS)) $(SUBDIRS_$(PASS).$(BUILD_TARGET)) $(SUBDIRS_$(PASS).$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) ,$(eval $(def_pass_subdir)))
2238$(foreach makefile,$(MAKEFILES_BEFORE_$(PASS)) $(MAKEFILES_BEFORE_$(PASS).$(BUILD_TARGET)) $(MAKEFILES_BEFORE_$(PASS).$(BUILD_TARGET).$(BUILD_TARGET_ARCH)),$(eval $(def_pass_makefile)))
2239
2240$(eval tag:=_after)
2241$(eval dep:=pass_$(pass)_doit)
2242$(foreach subdir,$(SUBDIRS_AFTER_$(PASS)) $(SUBDIRS_AFTER_$(PASS).$(BUILD_TARGET)) $(SUBDIRS_AFTER_$(PASS).$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) ,$(eval $(def_pass_subdir)))
2243$(foreach makefile,$(MAKEFILES_AFTER_$(PASS)) $(MAKEFILES_AFTER_$(PASS).$(BUILD_TARGET)) $(MAKEFILES_AFTER_$(PASS).$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) ,$(eval $(def_pass_makefile)))
2244
2245ifdef KBUILD_SAFE_PARALLEL
2246.NOTPARALLEL: pass_$(pass) pass_$(pass)_before pass_$(pass)_after pass_$(pass)_this
2247.PHONY: pass_$(pass) pass_$(pass)_before pass_$(pass)_after pass_$(pass)_this pass_$(pass)_doit
2248pass_$(pass)_doit: $(PASS_$(PASS)_trgs) $(foreach var,$(PASS_$(PASS)_vars),$(var))
2249pass_$(pass)_this: pass_$(pass)_before
2250 + $(QUIET)$$(MAKE) -f $$(MAKEFILE) pass_$(pass)_doit
2251pass_$(pass)_after:: pass_$(pass)_this
2252pass_$(pass): pass_$(pass)_after
2253else
2254.NOTPARALLEL: pass_$(pass) pass_$(pass)_before pass_$(pass)_after pass_$(pass)_doit
2255.PHONY: pass_$(pass) pass_$(pass)_before pass_$(pass)_after pass_$(pass)_doit
2256pass_$(pass)_doit: pass_$(pass)_before \
2257 $(PASS_$(PASS)_trgs) $(foreach var,$(PASS_$(PASS)_vars),$($(var)))
2258pass_$(pass): \
2259 pass_$(pass)_before \
2260 pass_$(pass)_doit \
2261 pass_$(pass)_after
2262endif
2263
2264#$ (warning pass=$(pass) PASS=$(PASS): $(PASS_$(PASS)_trgs) $(PASS_$(PASS)_trgs) $(foreach var,$(PASS_$(PASS)_vars),$($(var))))
2265endef
2266
2267# Generate the defined passes.
2268$(foreach PASS, $(PASSES), \
2269 $(eval pass := $(PASS_$(PASS)_pass)) \
2270 $(eval $(def_pass)))
2271
2272## Pass order
2273# @param $(pass) Current pass name.
2274# @param $(prev_pass) The previous pass name.
2275define def_pass_order
2276ifdef KBUILD_SAFE_PARALLEL
2277.NOTPARALLEL: pass_$(pass)_order
2278.PHONY: pass_$(pass)_order
2279pass_$(pass)_order: $(pass_prev)
2280 $(call MSG_L1,Pass - $(if $(PASS_$(PASS)),$(PASS_$(PASS)),$(pass)))
2281 + $(QUIET)$$(MAKE) -f $$(MAKEFILE) pass_$(pass)
2282else
2283.NOTPARALLEL: pass_$(pass)_order pass_$(pass)_banner
2284.PHONY: pass_$(pass)_order pass_$(pass)_banner
2285pass_$(pass)_banner:
2286 $(call MSG_L1,Pass - $(if $(PASS_$(PASS)),$(PASS_$(PASS)),$(pass)))
2287pass_$(pass)_order: \
2288 $(pass_prev) \
2289 pass_$(pass)_banner \
2290 pass_$(pass)
2291endif
2292$(eval pass_prev := pass_$(pass)_order)
2293endef
2294
2295## PASS: order
2296# Use dependencies to ensure correct pass order.
2297pass_prev :=
2298$(foreach PASS,$(DEFAULT_PASSES),\
2299 $(eval pass := $(PASS_$(PASS)_pass)) \
2300 $(eval $(def_pass_order)))
2301
2302
2303#
2304# THE MAIN RULES
2305#
2306all_recursive: $(pass_prev)
2307
2308rebuild: clean
2309 + $(MAKE) -f $(firstword $(MAKEFILE_LIST)) all_recursive
2310
2311# @todo make this a non-default pass!
2312uninstall:
2313 $(RM) -f $(_INSTALLS)
2314
2315install: pass_installs
2316
2317# misc shortcuts.
2318targets: bldprogs libraries dlls programs sysmods others installs
2319objects: $(_OBJS)
2320bldprogs: $(_BLDPROGS)
2321libraries: $(_LIBS) $(_IMPORT_LIBS) $(_OTHER_LIBRARIES)
2322dlls: $(_DLLS)
2323programs: $(_PROGRAMS)
2324sysmods: $(_SYSMODS)
2325others: $(_OTHERS)
2326installs: $(_INSTALLS_DIRS) $(_INSTALLS)
2327
2328
2329#
2330# kBuild debugging stuff.
2331#
2332_SPACE := $(subst ., ,.)
2333_TAB := $(subst ., ,.)
2334define _NEWLINE
2335
2336
2337endef
2338NLTAB = $(_NEWLINE)$(TAB)
2339show_targets:
2340 @$(foreach target, $(ALL_TARGETS),\
2341 @$(ECHO) "target: $(target)" $(NLTAB)\
2342 @$(ECHO) " PATH_$(target)=$(PATH_$(target))" $(NLTAB)\
2343 @$(ECHO) " TARGET_$(target)=$(TARGET_$(target))" $(NLTAB)\
2344 @$(ECHO) " INSTARGET_$(target)=$(INSTARGET_$(target))" $(NLTAB)\
2345$(foreach prop,$(PROPS_SINGLE) $(PROPS_ACCUMULATE) OBJS_ CLEAN, \
2346 $(eval _tmp:=$(firstword $($(target)_BLD_TRG) $(BUILD_TARGET))) \
2347 $(if $($(target)_$(prop).$(_tmp)),\
2348 @$(ECHO) " $(target)_$(prop).$(_tmp)=$($(target)_$(prop).$(_tmp))" $(NLTAB)) \
2349 $(if $($(target)_$(prop)), $(NLTAB)@$(ECHO) " $(target)_$(prop)=$($(target)_$(prop))" $(NLTAB)) \
2350)\
2351$(foreach prop,$(PROPS_DEFERRED), \
2352 $(eval _tmp:=$(firstword $($(target)_BLD_TRG) $(BUILD_TARGET))) \
2353 $(if $(value $(target)_$(prop).$(_tmp)),\
2354 @$(ECHO) ' $(target)_$(prop).$(_tmp)=$(value $(TARGET)_$(prop).$(_tmp))' $(NLTAB)) \
2355 $(if $(value $(target)_$(prop)), $(NLTAB)@$(ECHO) ' $(target)_$(prop)=$(value $(target)_$(prop))' $(NLTAB)) \
2356))
2357
2358
2359
2360#
2361# Include dependency files.
2362#
2363$(foreach dep,$(wildcard $(_DEPFILES)),$(eval include $(dep)))
2364
2365
2366# end-of-file-content
2367__footer_kmk__ := target
2368endif # __footer_kmk__
2369
Note: See TracBrowser for help on using the repository browser.