source: trunk/kBuild/footer.kmk@ 530

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

Added kBuild specific functions for speeding up source processing.

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