source: trunk/kBuild/footer.kmk@ 581

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

use comp-vars

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