source: trunk/kBuild/footer.kmk@ 564

Last change on this file since 564 was 552, checked in by bird, 19 years ago
  • kBuild/footer.kmk:

o Recursive template inheritance.

  • kBuild/header.kmk, kBuild/footer.kmk:

o Removed some checks for features which are present in both gmake 3.81 and kmk.

Anyone trying to bootstrap kBuild will have to build gmake 3.81 first.

  • Config.kmk, src/gmake:

o Allow all kinds of ways of saying Windows in BUILD_TARGET.

  • kBuild/bin/x86.win32/:

o Rebuilt kmk.exe.

  • kBuild/bin/x86.os2/:

o Added kDepPre.exe and kDepIDB.exe.
o Rebuilt kmk.exe and kmk_gmake.exe.

  • src/gmake:

o Update KMK_FEATURES to include the optimizations from earlier this week.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 69.0 KB
Line 
1# $Id: footer.kmk 552 2006-09-24 07:37:41Z 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_DEP_LINK_CMDS = $(if $(subst $(strip $($(target)_CMDS_PREV_)),,$(strip $($(target)_CMDS_))),FORCE,)
562else
563_DEP_LINK_CMDS =
564endif
565
566## Generate the link rule for a target.
567# @param $(target) The normalized target name.
568# @param $(dirdep) Directories we depend upon begin created before linking.
569# @param $(dep) The name of the dependency file.
570# @param $(out)
571# @param $($(target)_OUTPUT_) Output files from the link.
572# @param $($(target)_DEPEND_) Dependencies.
573# @param $($(target)_DEPORD_) Dependencies which should only affect build order.
574# @param $($(target)_CMDS_) The link commands.
575# @param $($(target)_CMDS_PREV_) The link commands from the previous run.
576define def_link_rule
577$(out) $($(target)_OUTPUT_): \
578 $($(target)_DEPEND_) \
579 $(_DEP_LINK_CMDS) \
580 | \
581 $($(target)_DEPORD_)
582 $(call MSG_L1,Creating $$@)
583 $(RM) -f $(dep) $(out) $($(target)_OUTPUT_)
584 $(custom_pre)
585
586$($(target)_CMDS_)
587
588 $(custom_post)
589ifndef NO_LINK_CMDS_DEPS
590 @$(APPEND) "$(dep)" 'define $(target)_CMDS_PREV_'
591 @$(APPEND) "$(dep)" '$(subst $(NL),'$(NL)$(TAB)@$(APPEND) "$(dep)" ',$($(target)_CMDS_))'
592 @$(APPEND) "$(dep)" 'endef'
593endif
594
595$(basename $(notdir $(out)))::
596 + $$(MAKE) -f $$(MAKEFILE) $(out)
597endef
598
599
600## Generate the link & lib install rule
601# @param $(target) Normalized target name.
602# @param $(out) The build target.
603# @param $(INSTARGET_$(target)) The installation targets.
604# @param $(mode) The file mode (optional)
605define def_link_install_rule
606$(INSTARGET_$(target)) : $(out) | $(call DIRDEP,$(dir $(INSTARGET_$(target))))
607 $(INSTALL) $$(if $(mode),-m $(mode)) $(out) $$@
608endef
609
610
611
612## Generic macro for processing C, C++ and Assembly sources.
613# @param $(target) Normalized target name.
614# @param $(source) Source file name.
615# @param $(type) Source type. {C,CXX,AS}
616# @param bld_type Build type.
617# @param bld_trg Build target.
618# @param bld_trg_arch Build target arch.
619# @param bld_trg_cpu Build target cpu.
620# @remark obsoleted by kBuild helpers in kmk. Only required for gmake compatbility.
621#
622define def_target_source_c_cpp_asm_old
623#$ (warning dbg: def_target_source_c_cpp_asm: source='$(source)' target='$(target)' type='$(type)')
624
625tool := $(call _SOURCE_TOOL,$(source),$(target),$(type))
626outbase := $(call _OBJECT_BASE,$(source),$(target))
627PATH_$(target)_$(source) := $(patsubst %/,%,$(dir $(outbase)))
628dirdep := $(call DIRDEP,$(dir $(outbase)))
629defs :=\
630 $(TOOL_$(tool)_DEFS)\
631 $(TOOL_$(tool)_DEFS.$(bld_type))\
632 $(TOOL_$(tool)_DEFS.$(bld_trg))\
633 $(TOOL_$(tool)_DEFS.$(bld_trg_arch))\
634 $(TOOL_$(tool)_DEFS.$(bld_trg).$(bld_trg_arch))\
635 $(TOOL_$(tool)_DEFS.$(bld_trg_cpu))\
636 $(TOOL_$(tool)_$(type)DEFS)\
637 $(TOOL_$(tool)_$(type)DEFS.$(bld_type))\
638 $(foreach sdk, $(SDKS.$(bld_trg)) \
639 $(SDKS.$(bld_trg).$(bld_trg_arch)) \
640 $(SDKS.$(bld_type)) \
641 $(SDKS),\
642 $(SDK_$(sdk)_DEFS)\
643 $(SDK_$(sdk)_DEFS.$(bld_type))\
644 $(SDK_$(sdk)_DEFS.$(bld_trg))\
645 $(SDK_$(sdk)_DEFS.$(bld_trg_arch))\
646 $(SDK_$(sdk)_DEFS.$(bld_trg).$(bld_trg_arch))\
647 $(SDK_$(sdk)_DEFS.$(bld_trg_cpu))\
648 $(SDK_$(sdk)_$(type)DEFS)\
649 $(SDK_$(sdk)_$(type)DEFS.$(bld_type))\
650 $(SDK_$(sdk)_$(type)DEFS.$(bld_trg))\
651 $(SDK_$(sdk)_$(type)DEFS.$(bld_trg_arch))\
652 $(SDK_$(sdk)_$(type)DEFS.$(bld_trg).$(bld_trg_arch))\
653 $(SDK_$(sdk)_$(type)DEFS.$(bld_trg_cpu)))\
654 $(DEFS)\
655 $(DEFS.$(bld_type))\
656 $(DEFS.$(bld_trg))\
657 $(DEFS.$(bld_trg_arch))\
658 $(DEFS.$(bld_trg).$(bld_trg_arch))\
659 $(DEFS.$(bld_trg_cpu))\
660 $($(type)DEFS)\
661 $($(type)DEFS.$(bld_type))\
662 $($(type)DEFS.$(bld_trg))\
663 $($(type)DEFS.$(bld_trg_arch))\
664 $($(type)DEFS.$(bld_trg).$(bld_trg_arch))\
665 $($(type)DEFS.$(bld_trg_cpu))\
666 $(foreach sdk, $($(target)_SDKS.$(bld_trg)) \
667 $($(target)_SDKS.$(bld_trg).$(bld_trg_arch)) \
668 $($(target)_SDKS.$(bld_type)) \
669 $($(target)_SDKS),\
670 $(SDK_$(sdk)_DEFS)\
671 $(SDK_$(sdk)_DEFS.$(bld_type))\
672 $(SDK_$(sdk)_DEFS.$(bld_trg))\
673 $(SDK_$(sdk)_DEFS.$(bld_trg_arch))\
674 $(SDK_$(sdk)_DEFS.$(bld_trg).$(bld_trg_arch))\
675 $(SDK_$(sdk)_DEFS.$(bld_trg_cpu))\
676 $(SDK_$(sdk)_$(type)DEFS)\
677 $(SDK_$(sdk)_$(type)DEFS.$(bld_type))\
678 $(SDK_$(sdk)_$(type)DEFS.$(bld_trg))\
679 $(SDK_$(sdk)_$(type)DEFS.$(bld_trg_arch))\
680 $(SDK_$(sdk)_$(type)DEFS.$(bld_trg).$(bld_trg_arch))\
681 $(SDK_$(sdk)_$(type)DEFS.$(bld_trg_cpu)))\
682 $($(target)_DEFS)\
683 $($(target)_DEFS.$(bld_type))\
684 $($(target)_DEFS.$(bld_trg))\
685 $($(target)_DEFS.$(bld_trg_arch))\
686 $($(target)_DEFS.$(bld_trg).$(bld_trg_arch))\
687 $($(target)_DEFS.$(bld_trg_cpu))\
688 $($(target)_$(type)DEFS)\
689 $($(target)_$(type)DEFS.$(bld_type))\
690 $($(target)_$(type)DEFS.$(bld_trg))\
691 $($(target)_$(type)DEFS.$(bld_trg_arch))\
692 $($(target)_$(type)DEFS.$(bld_trg).$(bld_trg_arch))\
693 $($(target)_$(type)DEFS.$(bld_trg_cpu))\
694 $(foreach sdk, $($(source)_SDKS.$(bld_trg)) \
695 $($(source)_SDKS.$(bld_trg).$(bld_trg_arch)) \
696 $($(source)_SDKS.$(bld_type)) \
697 $($(source)_SDKS),\
698 $(SDK_$(sdk)_DEFS)\
699 $(SDK_$(sdk)_DEFS.$(bld_type))\
700 $(SDK_$(sdk)_DEFS.$(bld_trg))\
701 $(SDK_$(sdk)_DEFS.$(bld_trg_arch))\
702 $(SDK_$(sdk)_DEFS.$(bld_trg).$(bld_trg_arch))\
703 $(SDK_$(sdk)_DEFS.$(bld_trg_cpu))\
704 $(SDK_$(sdk)_$(type)DEFS)\
705 $(SDK_$(sdk)_$(type)DEFS.$(bld_type))\
706 $(SDK_$(sdk)_$(type)DEFS.$(bld_trg))\
707 $(SDK_$(sdk)_$(type)DEFS.$(bld_trg_arch))\
708 $(SDK_$(sdk)_$(type)DEFS.$(bld_trg).$(bld_trg_arch))\
709 $(SDK_$(sdk)_$(type)DEFS.$(bld_trg_cpu)))\
710 $($(source)_DEFS)\
711 $($(source)_DEFS.$(bld_type))\
712 $($(source)_DEFS.$(bld_trg))\
713 $($(source)_DEFS.$(bld_trg_arch))\
714 $($(source)_DEFS.$(bld_trg).$(bld_trg_arch))\
715 $($(source)_DEFS.$(bld_trg_cpu))\
716 $($(source)_$(type)DEFS)\
717 $($(source)_$(type)DEFS.$(bld_type))\
718 $($(source)_$(type)DEFS.$(bld_trg))\
719 $($(source)_$(type)DEFS.$(bld_trg_arch))\
720 $($(source)_$(type)DEFS.$(bld_trg).$(bld_trg_arch))\
721 $($(source)_$(type)DEFS.$(bld_trg_cpu))\
722 $(foreach sdk, $($(target)_$(source)_SDKS.$(bld_trg)) \
723 $($(target)_$(source)_SDKS.$(bld_trg).$(bld_trg_arch)) \
724 $($(target)_$(source)_SDKS.$(bld_type)) \
725 $($(target)_$(source)_SDKS),\
726 $(SDK_$(sdk)_DEFS)\
727 $(SDK_$(sdk)_DEFS.$(bld_type))\
728 $(SDK_$(sdk)_DEFS.$(bld_trg))\
729 $(SDK_$(sdk)_DEFS.$(bld_trg_arch))\
730 $(SDK_$(sdk)_DEFS.$(bld_trg).$(bld_trg_arch))\
731 $(SDK_$(sdk)_DEFS.$(bld_trg_cpu))\
732 $(SDK_$(sdk)_$(type)DEFS)\
733 $(SDK_$(sdk)_$(type)DEFS.$(bld_type))\
734 $(SDK_$(sdk)_$(type)DEFS.$(bld_trg))\
735 $(SDK_$(sdk)_$(type)DEFS.$(bld_trg_arch))\
736 $(SDK_$(sdk)_$(type)DEFS.$(bld_trg).$(bld_trg_arch))\
737 $(SDK_$(sdk)_$(type)DEFS.$(bld_trg_cpu)))\
738 $($(target)_$(source)_DEFS)\
739 $($(target)_$(source)_DEFS.$(bld_type))\
740 $($(target)_$(source)_DEFS.$(bld_trg))\
741 $($(target)_$(source)_DEFS.$(bld_trg_arch))\
742 $($(target)_$(source)_DEFS.$(bld_trg).$(bld_trg_arch))\
743 $($(target)_$(source)_DEFS.$(bld_trg_cpu))\
744 $($(target)_$(source)_$(type)DEFS)\
745 $($(target)_$(source)_$(type)DEFS.$(bld_type))\
746 $($(target)_$(source)_$(type)DEFS.$(bld_trg))\
747 $($(target)_$(source)_$(type)DEFS.$(bld_trg_arch))\
748 $($(target)_$(source)_$(type)DEFS.$(bld_trg).$(bld_trg_arch))\
749 $($(target)_$(source)_$(type)DEFS.$(bld_trg_cpu))
750incs :=\
751 $($(target)_$(source)_$(type)INCS.$(bld_trg_cpu))\
752 $($(target)_$(source)_$(type)INCS.$(bld_trg).$(bld_trg_arch))\
753 $($(target)_$(source)_$(type)INCS.$(bld_trg_arch))\
754 $($(target)_$(source)_$(type)INCS.$(bld_trg))\
755 $($(target)_$(source)_$(type)INCS.$(bld_type))\
756 $($(target)_$(source)_$(type)INCS)\
757 $($(target)_$(source)_INCS.$(bld_trg_cpu))\
758 $($(target)_$(source)_INCS.$(bld_trg).$(bld_trg_arch))\
759 $($(target)_$(source)_INCS.$(bld_trg_arch))\
760 $($(target)_$(source)_INCS.$(bld_trg))\
761 $($(target)_$(source)_INCS.$(bld_type))\
762 $($(target)_$(source)_INCS)\
763 $(foreach sdk, $($(target)_$(source)_SDKS.$(bld_trg)) \
764 $($(target)_$(source)_SDKS.$(bld_trg).$(bld_trg_arch)) \
765 $($(target)_$(source)_SDKS.$(bld_type)) \
766 $($(target)_$(source)_SDKS),\
767 $(SDK_$(sdk)_$(type)INCS.$(bld_trg_cpu))\
768 $(SDK_$(sdk)_$(type)INCS.$(bld_trg).$(bld_trg_arch))\
769 $(SDK_$(sdk)_$(type)INCS.$(bld_trg_arch))\
770 $(SDK_$(sdk)_$(type)INCS.$(bld_trg))\
771 $(SDK_$(sdk)_$(type)INCS.$(bld_type))\
772 $(SDK_$(sdk)_$(type)INCS)\
773 $(SDK_$(sdk)_INCS.$(bld_trg_cpu))\
774 $(SDK_$(sdk)_INCS.$(bld_trg).$(bld_trg_arch))\
775 $(SDK_$(sdk)_INCS.$(bld_trg_arch))\
776 $(SDK_$(sdk)_INCS.$(bld_trg))\
777 $(SDK_$(sdk)_INCS.$(bld_type))\
778 $(SDK_$(sdk)_INCS))\
779 $($(source)_$(type)INCS.$(bld_trg_cpu))\
780 $($(source)_$(type)INCS.$(bld_trg).$(bld_trg_arch))\
781 $($(source)_$(type)INCS.$(bld_trg_arch))\
782 $($(source)_$(type)INCS.$(bld_trg))\
783 $($(source)_$(type)INCS.$(bld_type))\
784 $($(source)_$(type)INCS)\
785 $($(source)_INCS.$(bld_trg_cpu))\
786 $($(source)_INCS.$(bld_trg).$(bld_trg_arch))\
787 $($(source)_INCS.$(bld_trg_arch))\
788 $($(source)_INCS.$(bld_trg))\
789 $($(source)_INCS.$(bld_type))\
790 $($(source)_INCS)\
791 $(foreach sdk, $($(source)_SDKS.$(bld_trg)) \
792 $($(source)_SDKS.$(bld_trg).$(bld_trg_arch)) \
793 $($(source)_SDKS.$(bld_type)) \
794 $($(source)_SDKS),\
795 $(SDK_$(sdk)_$(type)INCS.$(bld_trg_cpu))\
796 $(SDK_$(sdk)_$(type)INCS.$(bld_trg).$(bld_trg_arch))\
797 $(SDK_$(sdk)_$(type)INCS.$(bld_trg_arch))\
798 $(SDK_$(sdk)_$(type)INCS.$(bld_trg))\
799 $(SDK_$(sdk)_$(type)INCS.$(bld_type))\
800 $(SDK_$(sdk)_$(type)INCS)\
801 $(SDK_$(sdk)_INCS.$(bld_trg_cpu))\
802 $(SDK_$(sdk)_INCS.$(bld_trg).$(bld_trg_arch))\
803 $(SDK_$(sdk)_INCS.$(bld_trg_arch))\
804 $(SDK_$(sdk)_INCS.$(bld_trg))\
805 $(SDK_$(sdk)_INCS.$(bld_type))\
806 $(SDK_$(sdk)_INCS))\
807 $($(target)_$(type)INCS.$(bld_trg_cpu))\
808 $($(target)_$(type)INCS.$(bld_trg).$(bld_trg_arch))\
809 $($(target)_$(type)INCS.$(bld_trg_arch))\
810 $($(target)_$(type)INCS.$(bld_trg))\
811 $($(target)_$(type)INCS.$(bld_type))\
812 $($(target)_$(type)INCS)\
813 $($(target)_INCS.$(bld_trg_cpu))\
814 $($(target)_INCS.$(bld_trg).$(bld_trg_arch))\
815 $($(target)_INCS.$(bld_trg_arch))\
816 $($(target)_INCS.$(bld_trg))\
817 $($(target)_INCS.$(bld_type))\
818 $($(target)_INCS)\
819 $(foreach sdk, $($(target)_SDKS.$(bld_trg)) \
820 $($(target)_SDKS.$(bld_trg).$(bld_trg_arch)) \
821 $($(target)_SDKS.$(bld_type)) \
822 $($(target)_SDKS),\
823 $(SDK_$(sdk)_$(type)INCS.$(bld_trg_cpu))\
824 $(SDK_$(sdk)_$(type)INCS.$(bld_trg).$(bld_trg_arch))\
825 $(SDK_$(sdk)_$(type)INCS.$(bld_trg_arch))\
826 $(SDK_$(sdk)_$(type)INCS.$(bld_trg))\
827 $(SDK_$(sdk)_$(type)INCS.$(bld_type))\
828 $(SDK_$(sdk)_$(type)INCS)\
829 $(SDK_$(sdk)_INCS.$(bld_trg_cpu))\
830 $(SDK_$(sdk)_INCS.$(bld_trg).$(bld_trg_arch))\
831 $(SDK_$(sdk)_INCS.$(bld_trg_arch))\
832 $(SDK_$(sdk)_INCS.$(bld_trg))\
833 $(SDK_$(sdk)_INCS.$(bld_type))\
834 $(SDK_$(sdk)_INCS))\
835 $(INCS.$(bld_trg_cpu))\
836 $(INCS.$(bld_trg).$(bld_trg_arch))\
837 $(INCS.$(bld_trg_arch))\
838 $(INCS.$(bld_trg))\
839 $(INCS.$(bld_type))\
840 $(INCS)\
841 $(foreach sdk, $(SDKS.$(bld_trg)) \
842 $(SDKS.$(bld_trg).$(bld_trg_arch)) \
843 $(SDKS.$(bld_type)) \
844 $(SDKS),\
845 $(SDK_$(sdk)_$(type)INCS.$(bld_trg_cpu))\
846 $(SDK_$(sdk)_$(type)INCS.$(bld_trg).$(bld_trg_arch))\
847 $(SDK_$(sdk)_$(type)INCS.$(bld_trg_arch))\
848 $(SDK_$(sdk)_$(type)INCS.$(bld_trg))\
849 $(SDK_$(sdk)_$(type)INCS.$(bld_type))\
850 $(SDK_$(sdk)_$(type)INCS)\
851 $(SDK_$(sdk)_INCS.$(bld_trg_cpu))\
852 $(SDK_$(sdk)_INCS.$(bld_trg).$(bld_trg_arch))\
853 $(SDK_$(sdk)_INCS.$(bld_trg_arch))\
854 $(SDK_$(sdk)_INCS.$(bld_trg))\
855 $(SDK_$(sdk)_INCS.$(bld_type))\
856 $(SDK_$(sdk)_INCS))\
857 $(TOOL_$(tool)_$(type)INCS.$(bld_trg_cpu))\
858 $(TOOL_$(tool)_$(type)INCS.$(bld_trg).$(bld_trg_arch))\
859 $(TOOL_$(tool)_$(type)INCS.$(bld_trg_arch))\
860 $(TOOL_$(tool)_$(type)INCS.$(bld_trg))\
861 $(TOOL_$(tool)_$(type)INCS.$(bld_type))\
862 $(TOOL_$(tool)_$(type)INCS)
863flags :=\
864 $(TOOL_$(tool)_$(type)FLAGS)\
865 $(TOOL_$(tool)_$(type)FLAGS.$(bld_type))\
866 $(TOOL_$(tool)_$(type)FLAGS.$(bld_trg))\
867 $(TOOL_$(tool)_$(type)FLAGS.$(bld_trg_arch))\
868 $(TOOL_$(tool)_$(type)FLAGS.$(bld_trg).$(bld_trg_arch))\
869 $(TOOL_$(tool)_$(type)FLAGS.$(bld_trg_cpu))\
870 $($(type)FLAGS)\
871 $($(type)FLAGS.$(bld_type))\
872 $($(type)FLAGS.$(bld_trg))\
873 $($(type)FLAGS.$(bld_trg_arch))\
874 $($(type)FLAGS.$(bld_trg).$(bld_trg_arch))\
875 $($(type)FLAGS.$(bld_trg_cpu))\
876 $($(target)_$(type)FLAGS)\
877 $($(target)_$(type)FLAGS.$(bld_type))\
878 $($(target)_$(type)FLAGS.$(bld_trg))\
879 $($(target)_$(type)FLAGS.$(bld_trg_arch))\
880 $($(target)_$(type)FLAGS.$(bld_trg).$(bld_trg_arch))\
881 $($(target)_$(type)FLAGS.$(bld_trg_cpu))\
882 $($(source)_$(type)FLAGS)\
883 $($(source)_$(type)FLAGS.$(bld_type))\
884 $($(source)_$(type)FLAGS.$(bld_trg))\
885 $($(source)_$(type)FLAGS.$(bld_trg_arch))\
886 $($(source)_$(type)FLAGS.$(bld_trg).$(bld_trg_arch))\
887 $($(source)_$(type)FLAGS.$(bld_trg_cpu))\
888 $($(target)_$(source)_$(type)FLAGS)\
889 $($(target)_$(source)_$(type)FLAGS.$(bld_type))\
890 $($(target)_$(source)_$(type)FLAGS.$(bld_trg))\
891 $($(target)_$(source)_$(type)FLAGS.$(bld_trg_arch))\
892 $($(target)_$(source)_$(type)FLAGS.$(bld_trg).$(bld_trg_arch))\
893 $($(target)_$(source)_$(type)FLAGS.$(bld_trg_cpu))
894# this isn't 100% in sync with kBuild, but it doesn't matter as it's only for gmake now.
895objsuff := $(firstword \
896 $($(target)_$(source)_OBJSUFF.$(bld_trg).$(bld_trg_arch))\
897 $($(target)_$(source)_OBJSUFF.$(bld_trg))\
898 $($(target)_$(source)_OBJSUFF)\
899 $($(source)_OBJSUFF.$(bld_trg).$(bld_trg_arch))\
900 $($(source)_OBJSUFF.$(bld_trg))\
901 $($(source)_OBJSUFF)\
902 $($(target)_OBJSUFF.$(bld_trg).$(bld_trg_arch))\
903 $($(target)_OBJSUFF.$(bld_trg))\
904 $($(target)_OBJSUFF)\
905 $(TOOL_$(tool)_$(type)OBJSUFF.$(bld_trg).$(bld_trg_arch))\
906 $(TOOL_$(tool)_$(type)OBJSUFF.$(bld_trg))\
907 $(TOOL_$(tool)_$(type)OBJSUFF)\
908 $(SUFF_OBJ))
909obj := $(outbase)$(objsuff)
910deps := \
911 $($(target)_$(source)_DEPS)\
912 $($(target)_$(source)_DEPS.$(bld_type))\
913 $($(target)_$(source)_DEPS.$(bld_trg))\
914 $($(target)_$(source)_DEPS.$(bld_trg_arch))\
915 $($(target)_$(source)_DEPS.$(bld_trg).$(bld_trg_arch))\
916 $($(target)_$(source)_DEPS.$(bld_trg_cpu))\
917 $($(source)_DEPS)\
918 $($(source)_DEPS.$(bld_type))\
919 $($(source)_DEPS.$(bld_trg))\
920 $($(source)_DEPS.$(bld_trg_arch))\
921 $($(source)_DEPS.$(bld_trg).$(bld_trg_arch))\
922 $($(source)_DEPS.$(bld_trg_cpu))\
923 $($(target)_DEPS)\
924 $($(target)_DEPS.$(bld_type))\
925 $($(target)_DEPS.$(bld_trg))\
926 $($(target)_DEPS.$(bld_trg_arch))\
927 $($(target)_DEPS.$(bld_trg).$(bld_trg_arch))\
928 $($(target)_DEPS.$(bld_trg_cpu))
929
930# dependencies
931dep := $(obj)$(SUFF_DEP)
932ifndef NO_COMPILE_CMDS_DEPS
933_DEPFILES_INCLUDED += $(dep)
934$(if $(wildcard $(dep)),$(eval include $(dep)))
935endif
936
937#$ (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))
938ifndef TOOL_$(tool)_COMPILE_$(type)_CMDS
939$(warning kBuild: tools: \
940 1 $($(target)_$(source)_$(type)TOOL.$(bld_trg).$(bld_trg_arch)) \
941 2 $($(target)_$(source)_$(type)TOOL.$(bld_trg)) \
942 3 $($(target)_$(source)_$(type)TOOL) \
943 4 $($(target)_$(source)_TOOL.$(bld_trg).$(bld_trg_arch)) \
944 5 $($(target)_$(source)_TOOL.$(bld_trg)) \
945 6 $($(target)_$(source)_TOOL) \
946 7 $($(target)_$(type)TOOL.$(bld_trg).$(bld_trg_arch)) \
947 8 $($(target)_$(type)TOOL.$(bld_trg)) \
948 9 $($(target)_$(type)TOOL) \
949 10 $($(target)_TOOL.$(bld_trg).$(bld_trg_arch)) \
950 11 $($(target)_TOOL.$(bld_trg)) \
951 12 $($(target)_TOOL) \
952 13 $($(source)_$(type)TOOL.$(bld_trg).$(bld_trg_arch)) \
953 14 $($(source)_$(type)TOOL.$(bld_trg)) \
954 15 $($(source)_$(type)TOOL) \
955 16 $($(source)_TOOL.$(bld_trg).$(bld_trg_arch)) \
956 17 $($(source)_TOOL.$(bld_trg)) \
957 18 $($(source)_TOOL) \
958 19 $($(type)TOOL.$(bld_trg).$(bld_trg_arch)) \
959 20 $($(type)TOOL.$(bld_trg)) \
960 21 $($(type)TOOL) \
961 22 $(TOOL.$(bld_trg).$(bld_trg_arch)) \
962 23 $(TOOL.$(bld_trg)) \
963 24 $(TOOL) )
964$(error kBuild: TOOL_$(tool)_COMPILE_$(type)_CMDS is not defined. source=$(source) target=$(target) )
965endif
966
967# call the tool
968$(target)_$(source)_CMDS_ := $(TOOL_$(tool)_COMPILE_$(type)_CMDS)
969$(target)_$(source)_OUTPUT_ := $(TOOL_$(tool)_COMPILE_$(type)_OUTPUT)
970$(target)_$(source)_DEPEND_ := $(TOOL_$(tool)_COMPILE_$(type)_DEPEND) $(deps) $(source)
971$(target)_$(source)_DEPORD_ := $(TOOL_$(tool)_COMPILE_$(type)_DEPORD) $(dirdep)
972
973# generate the compile rule.
974$(eval $(def_target_source_rule))
975
976_OUT_FILES += $($(target)_$(source)_OUTPUT_)
977$(target)_OBJS_ += $(obj)
978
979endef
980
981## Generic macro for processing C, C++ and Assembly sources.
982# @param $(target) Normalized target name.
983# @param $(source) Source file name.
984# @param $(type) Source type. {C,CXX,AS}
985# @param bld_type Build type.
986# @param bld_trg Build target.
987# @param bld_trg_arch Build target arch.
988# @param bld_trg_cpu Build target cpu.
989#
990#$ (warning dbg: def_target_source_c_cpp_asm: source='$(source)' target='$(target)' type='$(type)')
991def_target_source_c_cpp_asm_new = $(kb-src-one x)
992
993ifneq ($(filter kb-src-one,$(KMK_FEATURES)),)
994def_target_source_c_cpp_asm_var = def_target_source_c_cpp_asm_new
995else
996def_target_source_c_cpp_asm_var = def_target_source_c_cpp_asm_old
997endif
998
999## Generic macro for processing all target sources.
1000# @param $(target) Normalized target name.
1001define def_target_sources
1002#$ (warning def_target_sources)
1003# C sources
1004type := C
1005$(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)))\
1006 ,$(eval $(value $(def_target_source_c_cpp_asm_var))) )
1007
1008# C++ sources
1009type := CXX
1010$(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)))\
1011 ,$(eval $(value $(def_target_source_c_cpp_asm_var))) )
1012
1013# ASM sources
1014type := AS
1015$(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)))\
1016 ,$(eval $(value $(def_target_source_c_cpp_asm_var))) )
1017
1018endef
1019
1020
1021
1022## Generic macro for generating the install rule(s) for a target
1023# and update the globals with default out.
1024#
1025# @param $(target) Normalized target name.
1026# @param $(out) The output file.
1027# @param $(definst) The default _INST value.
1028# @param $(typevar) The name of the variable with all the root targets of its type.
1029# @obsolete
1030define def_target_install_pluss
1031ifndef $(target)_NOINST
1032INSTARGET_$(target) := $(patsubst %/,%/$(notdir $(out)), \
1033 $(if $($(target)_INST), $(addprefix $(PATH_INS)/,$($(target)_INST)), $(definst)/))
1034
1035$(eval $(def_link_install_rule))
1036
1037_INSTALLS += $(INSTARGET_$(target))
1038
1039ifdef KBUILD_DO_AUTO_INSTALL
1040$(typevar) += $(INSTARGET_$(target))
1041else
1042$(typevar) += $(out)
1043endif
1044else # _NOINST
1045$(typevar) += $(out)
1046endif
1047
1048_OUT_FILES += $(out)
1049_CLEAN_FILES += $($(target)_CLEAN)
1050_OBJS += $($(target)_OBJS_)
1051
1052endef
1053
1054
1055
1056#
1057# LIBRARIES
1058#
1059
1060## Library (one).
1061# @param $(target) Normalized library (target) name.
1062define def_lib
1063# library basics
1064## @todo prefix
1065bld_type := $(firstword $($(target)_BLD_TYPE) $(BUILD_TYPE))
1066bld_trg := $(firstword $($(target)_BLD_TRG) $(BUILD_TARGET))
1067bld_trg_arch:= $(firstword $($(target)_BLD_TRG_ARCH) $(BUILD_TARGET_ARCH))
1068bld_trg_cpu := $(firstword $($(target)_BLD_TRG_CPU) $(BUILD_TARGET_CPU))
1069tool := $(call _TARGET_TOOL,$(target),AR)
1070ifeq ($(tool),)
1071$(error kBuild: Library target $(target) does not have a tool defined!)
1072endif
1073outbase := $(call _TARGET_BASE,$(target),$(target))
1074PATH_$(target) := $(patsubst %/,%,$(dir $(outbase)))
1075suff := $(firstword\
1076 $($(target)_LIBSUFF.$(bld_trg).$(bld_trg_arch))\
1077 $($(target)_LIBSUFF.$(bld_trg))\
1078 $($(target)_LIBSUFF)\
1079 $(TOOL_$(tool)_ARLIBSUFF.$(bld_trg).$(bld_trg_arch))\
1080 $(TOOL_$(tool)_ARLIBSUFF.$(bld_trg))\
1081 $(TOOL_$(tool)_ARLIBSUFF)\
1082 $(SUFF_LIB))
1083out := $(outbase)$(suff)
1084TARGET_$(target) := $(out)
1085$(target)_OBJS_ := $(filter %.o %.obj, \
1086 $($(target)_SOURCES) \
1087 $($(target)_SOURCES.$(bld_trg)) \
1088 $($(target)_SOURCES.$(bld_trg_arch)) \
1089 $($(target)_SOURCES.$(bld_trg).$(bld_trg_arch)) \
1090 $($(target)_SOURCES.$(bld_trg_cpu)) \
1091 $($(target)_SOURCES.$(bld_type)))
1092
1093
1094# source -> object
1095$(eval $(value def_target_sources))
1096
1097# library linking
1098tool := $(call _TARGET_TOOL,$(target),AR)
1099outbase := $(call _TARGET_BASE,$(target),$(target))
1100flags :=\
1101 $(TOOL_$(tool)_ARFLAGS)\
1102 $(TOOL_$(tool)_ARFLAGS.$(bld_type))\
1103 $(ARFLAGS)\
1104 $(ARFLAGS.$(bld_type))\
1105 $($(target)_ARFLAGS)\
1106 $($(target)_ARFLAGS.$(bld_type)) \
1107 $($(target)_ARFLAGS.$(bld_trg)) \
1108 $($(target)_ARFLAGS.$(bld_trg_arch)) \
1109 $($(target)_ARFLAGS.$(bld_trg).$(bld_trg_arch)) \
1110 $($(target)_ARFLAGS.$(bld_trg_cpu))
1111othersrc := $(filter-out %.c %.cpp %.cxx %.cc %.s %.S %.asm %.o %.obj,\
1112 $($(target)_SOURCES) \
1113 $($(target)_SOURCES.$(bld_trg)) \
1114 $($(target)_SOURCES.$(bld_trg_arch)) \
1115 $($(target)_SOURCES.$(bld_trg).$(bld_trg_arch)) \
1116 $($(target)_SOURCES.$(bld_trg_cpu)) \
1117 $($(target)_SOURCES.$(bld_type)))
1118objs = $($(target)_OBJS_)
1119dirdep := $(call DIRDEP,$(dir $(out)))
1120## @todo fix dependencies on makefiles an such
1121deps := $($(target)_DEPS)
1122
1123# dependency file
1124dep := $(out)$(SUFF_DEP)
1125ifndef NO_LINK_CMDS_DEPS
1126_DEPFILES_INCLUDED += $(dep)
1127$(if $(wildcard $(dep)),$(eval include $(dep)))
1128endif
1129
1130# check that the tool is defined.
1131ifndef TOOL_$(tool)_LINK_LIBRARY_CMDS
1132$(warning kBuild: tools: \
1133 1 $($(target)_$(source)TOOL.$(bld_trg).$(bld_trg_arch)) \
1134 2 $($(target)_$(source)TOOL.$(bld_trg)) \
1135 3 $($(target)_$(source)TOOL) \
1136 4 $($(target)_TOOL.$(bld_trg).$(bld_trg_arch)) \
1137 5 $($(target)_TOOL.$(bld_trg)) \
1138 6 $($(target)_TOOL) \
1139 7 $($(source)TOOL) \
1140 8 $($(source)TOOL.$(bld_trg).$(bld_trg_arch)) \
1141 9 $($(source)TOOL.$(bld_trg)) \
1142 10 $(TOOL.$(bld_trg).$(bld_trg_arch)) \
1143 11 $(TOOL.$(bld_trg)) \
1144 12 $(TOOL) )
1145$(error kBuild: TOOL_$(tool)_LINK_LIBRARY_CMDS isn't defined! target=$(target) )
1146endif
1147
1148# call the tool
1149$(target)_CMDS_ := $(TOOL_$(tool)_LINK_LIBRARY_CMDS)
1150$(target)_OUTPUT_ := $(TOOL_$(tool)_LINK_LIBRARY_OUTPUT)
1151$(target)_DEPEND_ := $(TOOL_$(tool)_LINK_LIBRARY_DEPEND) $(deps) $(objs)
1152$(target)_DEPORD_ := $(TOOL_$(tool)_LINK_LIBRARY_DEPORD) $(dirdep)
1153
1154# generate the link rule.
1155$(eval $(def_link_rule))
1156
1157# installing and globals
1158definst := $(PATH_LIB)
1159typevar := _LIBS
1160$(eval $(value def_target_install_pluss))
1161endef
1162
1163# Process libraries
1164mode := 0644
1165$(foreach target, $(LIBRARIES) $(LIBRARIES.$(BUILD_TARGET)) $(LIBRARIES.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)), $(eval $(value def_lib)))
1166
1167
1168#
1169# Link operations.
1170#
1171
1172##
1173# Link prolog
1174#
1175# @param $(target) Normalized target name.
1176# @param $(EXT) EXE,DLL,SYS.
1177# @param $(definst) The default _INST value.
1178# @param $(typevar) The name of the variable with all the root targets of its type.
1179define def_link_common
1180# basics
1181bld_type := $(firstword $($(target)_BLD_TYPE) $(BUILD_TYPE))
1182bld_trg := $(firstword $($(target)_BLD_TRG) $(BUILD_$(bld_trg_base_var)))
1183bld_trg_arch:= $(firstword $($(target)_BLD_TRG_ARCH) $(BUILD_$(bld_trg_base_var)_ARCH))
1184bld_trg_cpu := $(firstword $($(target)_BLD_TRG_CPU) $(BUILD_$(bld_trg_base_var)_CPU))
1185
1186tool := $(call _TARGET_TOOL,$(target),LD)
1187outbase := $(call _TARGET_BASE,$(target),$(target))
1188suff := $(firstword \
1189 $($(target)_$(EXT)SUFF) \
1190 $($(target)_$(EXT)SUFF) \
1191 $(TOOL_$(tool)_LD$(EXT)SUFF) \
1192 $($(EXTPRE)SUFF_$(EXT)))
1193out := $(outbase)$(suff)
1194PATH_$(target) := $(patsubst %/,%,$(dir $(outbase)))
1195TARGET_$(target) := $(out)
1196$(target)_OBJS_ := $(filter %.o %.obj, \
1197 $($(target)_SOURCES) \
1198 $($(target)_SOURCES.$(bld_trg)) \
1199 $($(target)_SOURCES.$(bld_trg_arch)) \
1200 $($(target)_SOURCES.$(bld_trg).$(bld_trg_arch)) \
1201 $($(target)_SOURCES.$(bld_trg_cpu)) \
1202 $($(target)_SOURCES.$(bld_type)))
1203
1204# source -> object
1205$(eval $(value def_target_sources))
1206
1207# more library stuff.
1208tool := $(call _TARGET_TOOL,$(target),LD)
1209outbase := $(call _TARGET_BASE,$(target),$(target))
1210flags :=\
1211 $(TOOL_$(tool)_LDFLAGS)\
1212 $(TOOL_$(tool)_LDFLAGS.$(bld_type))\
1213 $(TOOL_$(tool)_LDFLAGS.$(bld_trg))\
1214 $(TOOL_$(tool)_LDFLAGS.$(bld_trg_arch))\
1215 $(TOOL_$(tool)_LDFLAGS.$(bld_trg).$(bld_trg_arch))\
1216 $(TOOL_$(tool)_LDFLAGS.$(bld_trg_cpu))\
1217 $(LDFLAGS)\
1218 $(LDFLAGS.$(bld_type))\
1219 $(LDFLAGS.$(bld_trg))\
1220 $(LDFLAGS.$(bld_trg_arch))\
1221 $(LDFLAGS.$(bld_trg).$(bld_trg_arch))\
1222 $(LDFLAGS.$(bld_trg_cpu))\
1223 $($(target)_LDFLAGS)\
1224 $($(target)_LDFLAGS.$(bld_type))\
1225 $($(target)_LDFLAGS.$(bld_trg))\
1226 $($(target)_LDFLAGS.$(bld_trg_arch))\
1227 $($(target)_LDFLAGS.$(bld_trg).$(bld_trg_arch))\
1228 $($(target)_LDFLAGS.$(bld_trg_cpu))
1229othersrc := $(filter-out %.c %.cpp %.cxx %.cc %.s %.S %.asm %.o %.obj,\
1230 $($(target)_SOURCES)\
1231 $($(target)_SOURCES.$(bld_trg)) \
1232 $($(target)_SOURCES.$(bld_trg_arch)) \
1233 $($(target)_SOURCES.$(bld_trg).$(bld_trg_arch)) \
1234 $($(target)_SOURCES.$(bld_trg_cpu)) \
1235 $($(target)_SOURCES.$(bld_type)))
1236objs = $($(target)_OBJS_)
1237libs :=\
1238 $($(target)_LIBS.$(bld_trg_cpu))\
1239 $($(target)_LIBS.$(bld_trg).$(bld_trg_arch))\
1240 $($(target)_LIBS.$(bld_trg_arch))\
1241 $($(target)_LIBS.$(bld_trg))\
1242 $($(target)_LIBS.$(bld_type))\
1243 $($(target)_LIBS)\
1244 $(foreach sdk, $($(target)_SDKS.$(bld_trg)) \
1245 $($(target)_SDKS.$(bld_trg).$(bld_trg_arch)) \
1246 $($(target)_SDKS.$(bld_type)) \
1247 $($(target)_SDKS),\
1248 $(SDK_$(sdk)_LIBS.$(bld_trg_cpu))\
1249 $(SDK_$(sdk)_LIBS.$(bld_trg).$(bld_trg_arch))\
1250 $(SDK_$(sdk)_LIBS.$(bld_trg_arch))\
1251 $(SDK_$(sdk)_LIBS.$(bld_trg))\
1252 $(SDK_$(sdk)_LIBS.$(bld_type))\
1253 $(SDK_$(sdk)_LIBS))\
1254 $(LIBS.$(bld_trg_cpu))\
1255 $(LIBS.$(bld_trg).$(bld_trg_arch))\
1256 $(LIBS.$(bld_trg_arch))\
1257 $(LIBS.$(bld_trg))\
1258 $(LIBS.$(bld_type))\
1259 $(LIBS)\
1260 $(foreach sdk, $(SDKS.$(bld_trg)) \
1261 $(SDKS.$(bld_trg).$(bld_trg_arch)) \
1262 $(SDKS.$(bld_type)) \
1263 $(SDKS),\
1264 $(SDK_$(sdk)_LIBS.$(bld_trg_cpu))\
1265 $(SDK_$(sdk)_LIBS.$(bld_trg).$(bld_trg_arch))\
1266 $(SDK_$(sdk)_LIBS.$(bld_trg_arch))\
1267 $(SDK_$(sdk)_LIBS.$(bld_trg))\
1268 $(SDK_$(sdk)_LIBS.$(bld_type))\
1269 $(SDK_$(sdk)_LIBS))\
1270 $(TOOL_$(tool)_LIBS.$(bld_trg_cpu))\
1271 $(TOOL_$(tool)_LIBS.$(bld_trg).$(bld_trg_arch))\
1272 $(TOOL_$(tool)_LIBS.$(bld_trg_arch))\
1273 $(TOOL_$(tool)_LIBS.$(bld_trg))\
1274 $(TOOL_$(tool)_LIBS.$(bld_type))\
1275 $(TOOL_$(tool)_LIBS)
1276libpath :=\
1277 $($(target)_LIBPATH.$(bld_trg_cpu))\
1278 $($(target)_LIBPATH.$(bld_trg).$(bld_trg_arch))\
1279 $($(target)_LIBPATH.$(bld_trg_arch))\
1280 $($(target)_LIBPATH.$(bld_trg))\
1281 $($(target)_LIBPATH.$(bld_type))\
1282 $($(target)_LIBPATH)\
1283 $(foreach sdk, $($(target)_SDKS.$(bld_trg)) \
1284 $($(target)_SDKS.$(bld_trg).$(bld_trg_arch)) \
1285 $($(target)_SDKS.$(bld_type)) \
1286 $($(target)_SDKS),\
1287 $(SDK_$(sdk)_LIBPATH.$(bld_trg_cpu))\
1288 $(SDK_$(sdk)_LIBPATH.$(bld_trg).$(bld_trg_arch))\
1289 $(SDK_$(sdk)_LIBPATH.$(bld_trg_arch))\
1290 $(SDK_$(sdk)_LIBPATH.$(bld_trg))\
1291 $(SDK_$(sdk)_LIBPATH.$(bld_type))\
1292 $(SDK_$(sdk)_LIBPATH))\
1293 $(LIBPATH.$(bld_trg_cpu))\
1294 $(LIBPATH.$(bld_trg).$(bld_trg_arch))\
1295 $(LIBPATH.$(bld_trg_arch))\
1296 $(LIBPATH.$(bld_trg))\
1297 $(LIBPATH.$(bld_type))\
1298 $(LIBPATH)\
1299 $(foreach sdk, $(SDKS.$(bld_trg)) \
1300 $(SDKS.$(bld_trg).$(bld_trg_arch)) \
1301 $(SDKS.$(bld_type)) \
1302 $(SDKS),\
1303 $(SDK_$(sdk)_LIBPATH.$(bld_trg_cpu))\
1304 $(SDK_$(sdk)_LIBPATH.$(bld_trg).$(bld_trg_arch))\
1305 $(SDK_$(sdk)_LIBPATH.$(bld_trg_arch))\
1306 $(SDK_$(sdk)_LIBPATH.$(bld_trg))\
1307 $(SDK_$(sdk)_LIBPATH.$(bld_type))\
1308 $(SDK_$(sdk)_LIBPATH))\
1309 $(TOOL_$(tool)_LIBPATH.$(bld_trg_cpu))\
1310 $(TOOL_$(tool)_LIBPATH.$(bld_trg).$(bld_trg_arch))\
1311 $(TOOL_$(tool)_LIBPATH.$(bld_trg_arch))\
1312 $(TOOL_$(tool)_LIBPATH.$(bld_trg))\
1313 $(TOOL_$(tool)_LIBPATH.$(bld_type))\
1314 $(TOOL_$(tool)_LIBPATH)
1315dirdep := $(call DIRDEP,$(dir $(out)))
1316## @todo fix dependencies
1317deps := $($(target)_DEPS)
1318
1319## @todo this stuff can't be working.
1320custom_pre := $(strip $(firstword \
1321 $($(target)_CUSTOM_PRE.$(bld_trg).$(bld_trg_arch))\
1322 $($(target)_CUSTOM_PRE.$(bld_trg).$(bld_type))\
1323 $($(target)_CUSTOM_PRE.$(bld_trg))\
1324 $($(target)_CUSTOM_PRE.$(bld_type))\
1325 $($(target)_CUSTOM_PRE)\
1326 $(CUSTOM_PRE.$(bld_trg).$(bld_trg_arch))\
1327 $(CUSTOM_PRE.$(bld_trg).$(bld_type))\
1328 $(CUSTOM_PRE.$(bld_trg))\
1329 $(CUSTOM_PRE.$(bld_type))\
1330 $(CUSTOM_PRE)\
1331))
1332custom_post := $(strip $(firstword \
1333 $($(target)_CUSTOM_POST.$(bld_trg).$(bld_trg_arch))\
1334 $($(target)_CUSTOM_POST.$(bld_trg).$(bld_type))\
1335 $($(target)_CUSTOM_POST.$(bld_trg))\
1336 $($(target)_CUSTOM_POST.$(bld_type))\
1337 $($(target)_CUSTOM_POST)\
1338 $(CUSTOM_POST.$(bld_trg).$(bld_trg_arch))\
1339 $(CUSTOM_POST.$(bld_trg).$(bld_type))\
1340 $(CUSTOM_POST.$(bld_trg))\
1341 $(CUSTOM_POST.$(bld_type))\
1342 $(CUSTOM_POST)\
1343))
1344
1345# installation targets
1346ifndef $(target)_NOINST
1347INSTARGET_$(target) := $(patsubst %/,%/$(notdir $(out)), \
1348 $(if $($(target)_INST), $(addprefix $(PATH_INS)/,$($(target)_INST)), $(definst)/))
1349ifdef KBUILD_DO_AUTO_INSTALL
1350$(typevar) += $(INSTARGET_$(target))
1351else
1352$(typevar) += $(out)
1353endif
1354# generate the install rule
1355$(eval $(def_link_install_rule))
1356
1357else # NOINST
1358INSTARGET_$(target) :=
1359$(typevar) += $(out)
1360endif # NOINST
1361
1362# dependency file
1363dep := $(outbase)$(SUFF_DEP)
1364ifndef NO_LINK_CMDS_DEPS
1365_DEPFILES_INCLUDED += $(dep)
1366$(if $(wildcard $(dep)),$(eval include $(dep)))
1367endif
1368
1369# check that the tool is defined.
1370ifndef TOOL_$(tool)_$(tool_do)_CMDS
1371$(warning kBuild: tools: \
1372 1 $($(target)_$(source)TOOL.$(bld_trg).$(bld_trg_arch)) \
1373 2 $($(target)_$(source)TOOL.$(bld_trg)) \
1374 3 $($(target)_$(source)TOOL) \
1375 4 $($(target)_TOOL.$(bld_trg).$(bld_trg_arch)) \
1376 5 $($(target)_TOOL.$(bld_trg)) \
1377 6 $($(target)_TOOL) \
1378 7 $($(source)TOOL.$(bld_trg).$(bld_trg_arch)) \
1379 8 $($(source)TOOL.$(bld_trg)) \
1380 9 $($(source)TOOL) \
1381 10 $(TOOL.$(bld_trg).$(bld_trg_arch)) \
1382 11 $(TOOL.$(bld_trg)) \
1383 12 $(TOOL) )
1384$(error kBuild: TOOL_$(tool)_$(tool_do)_CMDS isn't defined! target=$(target) )
1385endif
1386
1387# call the tool
1388$(target)_CMDS_ := $(TOOL_$(tool)_$(tool_do)_CMDS)
1389$(target)_OUTPUT_ := $(TOOL_$(tool)_$(tool_do)_OUTPUT)
1390$(target)_DEPEND_ := $(TOOL_$(tool)_$(tool_do)_DEPEND) $(deps) $(objs)
1391$(target)_DEPORD_ := $(TOOL_$(tool)_$(tool_do)_DEPORD) $(dirdep)
1392
1393# generate the link rule.
1394$(eval $(def_link_rule))
1395
1396
1397# Update globals.
1398_OBJS += $($(target)_OBJS_)
1399_OUT_FILES += $($(target)_OUTPUT_) $(out)
1400_CLEAN_FILES += $($(target)_CLEAN)
1401_INSTALLS += $(INSTARGET_$(target))
1402
1403endef
1404
1405
1406#
1407# BLDPROGS
1408#
1409
1410## Build program (one).
1411# @param $(target) Normalized target (program) name.
1412define def_bldprog
1413
1414# set NOINST if not forced installation.
1415ifndef $(target)_INST
1416$(target)_NOINST := 1
1417endif
1418
1419# do the usual stuff.
1420$(eval $(value def_link_common))
1421
1422endef
1423
1424# Process build programs.
1425EXT := EXE
1426EXTPRE := HOST
1427tool_do := LINK_PROGRAM
1428definst := $(PATH_BIN)
1429typevar := _BLDPROGS
1430mode := 0755
1431bld_trg_base_var := PLATFORM
1432$(foreach target, $(BLDPROGS) $(BLDPROGS.$(BUILD_PLATFORM)) $(BLDPROGS.$(BUILD_PLATFORM).$(BUILD_PLATFORM_ARCH)), $(eval $(value def_bldprog)))
1433
1434
1435
1436#
1437# DLLS
1438#
1439
1440# Process dlls
1441EXT := DLL
1442EXTPRE :=
1443tool_do := LINK_DLL
1444definst := $(PATH_DLL)
1445typevar := _DLLS
1446mode := 0755
1447bld_trg_base_var := TARGET
1448$(foreach target, $(DLLS) $(DLLS.$(BUILD_TARGET)) $(DLLS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)), $(eval $(value def_link_common)))
1449
1450
1451#
1452# Process import libraries.
1453#
1454# - On OS/2 and windows these are libraries.
1455# - On other platforms they are fake DLLs.
1456ifeq ($(filter-out nt os2 win win64 win32,$(BUILD_TARGET)),)
1457$(foreach target, $(IMPORT_LIBS) $(IMPORT_LIBS.$(BUILD_TARGET)) $(IMPORT_LIBS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)), $(eval $(value def_lib)))
1458else
1459$(foreach target, $(IMPORT_LIBS) $(IMPORT_LIBS.$(BUILD_TARGET)) $(IMPORT_LIBS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)), $(eval $(value def_link_common)))
1460endif
1461$(foreach target, $(IMPORT_LIBS) $(IMPORT_LIBS.$(BUILD_TARGET)) $(IMPORT_LIBS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)), \
1462 $(eval _IMPORT_LIBS += $(if $(INSTARGET_$(target)),$(INSTARGET_$(target)), $(TARGET_$(target)))))
1463
1464
1465#
1466# PROGRAMS
1467#
1468
1469# Process programs
1470EXT := EXE
1471EXTPRE :=
1472tool_do := LINK_PROGRAM
1473definst := $(PATH_BIN)
1474typevar := _PROGRAMS
1475mode := 0755
1476bld_trg_base_var := TARGET
1477$(foreach target, $(PROGRAMS) $(PROGRAMS.$(BUILD_TARGET)) $(PROGRAMS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)), $(eval $(value def_link_common)))
1478
1479
1480
1481#
1482# SYSMODS
1483#
1484
1485# Process sysmods
1486EXT := SYS
1487EXTPRE :=
1488tool_do := LINK_SYSMOD
1489definst := $(PATH_SYS)
1490typevar := _SYSMODS
1491mode := 0644
1492bld_trg_base_var := TARGET
1493$(foreach target, $(SYSMODS) $(SYSMODS.$(BUILD_TARGET)) $(SYSMODS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)), $(eval $(value def_link_common)))
1494
1495
1496#
1497# OTHERS
1498#
1499_OTHERS = $(OTHERS) $(OTHERS.$(BUILD_TARGET)) $(OTHERS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH))
1500
1501
1502#
1503# INSTALLS
1504#
1505
1506## generate the install rule
1507define def_install_src_rule
1508# the install rule
1509$(insdst) : $(srcsrc) | $(call DIRDEP,$(dir $(insdst)))
1510 $$(if $$(filter $(INSTALL),$(inscmd)),,$$(RM) -f $$@)
1511 $(inscmd)
1512endef
1513
1514## install one file
1515define def_install_src
1516
1517# deal with '=>' in the source file name.
1518srcdst := $(subst =>, ,$(src))
1519srcsrc := $(firstword $(srcdst))
1520srcdstdir := $(dir $(word 2,$(srcdst)))
1521srcdst := $(word $(words $(srcdst)),$(srcdst))
1522
1523# _INSTFUN
1524ifdef $(srcsrc)_INSTFUN
1525instfun := $(srcsrc)_INSTFUN
1526else
1527ifdef $(target)_INSTFUN
1528instfun := $(target)_INSTFUN
1529else
1530instfun := _INSTALL_FILE
1531endif
1532endif
1533
1534# _INST
1535ifdef $(srcsrc)_INST
1536inst := $(patsubst %/,%,$($(srcsrc)_INST))/$(dir $(srcdstdir))
1537else
1538ifdef $(target)_INST
1539inst := $(patsubst %/,%,$($(target)_INST))/$(dir $(srcdstdir))
1540else
1541inst := $(dir $(srcdstdir))
1542endif
1543endif
1544
1545# calc target
1546insdst := $(call $(instfun),$(srcdst),$(target),$(inst),$(PATH_INS))
1547#$(warning instfun=$(instfun) srcdst=$(srcdst) target=$(target) inst=$(inst) => insdst=$(insdst))
1548
1549# mode, uid and gid
1550mode := $(firstword \
1551 $($(target)_$(srcsrc)_MODE.$(bld_trg).$(bld_trg_arch)) \
1552 $($(target)_$(srcsrc)_MODE.$(bld_trg)) \
1553 $($(target)_$(srcsrc)_MODE) \
1554 $($(target)_$(srcdst)_MODE.$(bld_trg).$(bld_trg_arch)) \
1555 $($(target)_$(srcdst)_MODE.$(bld_trg)) \
1556 $($(target)_$(srcdst)_MODE) \
1557 $($(srcsrc)_MODE.$(bld_trg).$(bld_trg_arch)) \
1558 $($(srcsrc)_MODE.$(bld_trg)) \
1559 $($(srcsrc)_MODE) \
1560 $($(srcdst)_MODE.$(bld_trg).$(bld_trg_arch)) \
1561 $($(srcdst)_MODE.$(bld_trg)) \
1562 $($(srcdst)_MODE) \
1563 $($(target)_MODE.$(bld_trg).$(bld_trg_arch)) \
1564 $($(target)_MODE.$(bld_trg)) \
1565 $($(target)_MODE))
1566uid := $(firstword \
1567 $($(target)_$(srcsrc)_UID.$(bld_trg).$(bld_trg_arch)) \
1568 $($(target)_$(srcsrc)_UID.$(bld_trg)) \
1569 $($(target)_$(srcsrc)_UID) \
1570 $($(target)_$(srcdst)_UID.$(bld_trg).$(bld_trg_arch)) \
1571 $($(target)_$(srcdst)_UID.$(bld_trg)) \
1572 $($(target)_$(srcdst)_UID) \
1573 $($(srcsrc)_UID.$(bld_trg).$(bld_trg_arch)) \
1574 $($(srcsrc)_UID.$(bld_trg)) \
1575 $($(srcsrc)_UID) \
1576 $($(srcdst)_UID.$(bld_trg).$(bld_trg_arch)) \
1577 $($(srcdst)_UID.$(bld_trg)) \
1578 $($(srcdst)_UID) \
1579 $($(target)_UID.$(bld_trg).$(bld_trg_arch)) \
1580 $($(target)_UID.$(bld_trg)) \
1581 $($(target)_UID))
1582gid := $(firstword \
1583 $($(target)_$(srcsrc)_GID.$(bld_trg).$(bld_trg_arch)) \
1584 $($(target)_$(srcsrc)_GID.$(bld_trg)) \
1585 $($(target)_$(srcsrc)_GID) \
1586 $($(target)_$(srcdst)_GID.$(bld_trg).$(bld_trg_arch)) \
1587 $($(target)_$(srcdst)_GID.$(bld_trg)) \
1588 $($(target)_$(srcdst)_GID) \
1589 $($(srcsrc)_GID.$(bld_trg).$(bld_trg_arch)) \
1590 $($(srcsrc)_GID.$(bld_trg)) \
1591 $($(srcsrc)_GID) \
1592 $($(srcdst)_GID.$(bld_trg).$(bld_trg_arch)) \
1593 $($(srcdst)_GID.$(bld_trg)) \
1594 $($(srcdst)_GID) \
1595 $($(target)_GID.$(bld_trg).$(bld_trg_arch)) \
1596 $($(target)_GID.$(bld_trg)) \
1597 $($(target)_GID))
1598
1599# create the command
1600ifdef $(srcsrc)_INSTALLER
1601inscmd := $(call $(srcsrc)_INSTALLER,$(srcsrc),$(insdst),$(target))
1602else
1603ifdef $(target)_INSTALLER
1604inscmd := $(call $(target)_INSTALLER,$(srcsrc),$(insdst),$(target))
1605else
1606inscmd := $$(INSTALL)\
1607 $(if $(uid),-o $(uid))\
1608 $(if $(gid),-g $(gid))\
1609 $(if $(mode),-m $(mode))\
1610 $(srcsrc) $(insdst)
1611endif
1612endif
1613
1614# generate the rule (need double evaluation here)
1615$(eval $(def_install_src_rule))
1616
1617INSTARGET_$(target) += $(insdst)
1618endef
1619
1620
1621## generate the symlink rule
1622define def_install_symlink_rule
1623# the install rule
1624$(insdst) : | $(call DIRDEP,$(dir $(insdst)))
1625 $$(RM) -f $$@
1626 $$(LN_SYMLINK) $(symdst) $(insdst)
1627endef
1628
1629## create one symlink
1630define def_install_symlink
1631
1632# deal with '=>' in the source file name.
1633symdst := $(subst =>, ,$(src))
1634symlnk := $(firstword $(symdst))
1635symdst := $(word $(words $(symdst)),$(symdst))
1636
1637# _INSTFUN
1638ifdef $(symlnk)_INSTFUN
1639instfun := $(symlnk)_INSTFUN
1640else
1641ifdef $(target)_INSTFUN
1642instfun := $(target)_INSTFUN
1643else
1644instfun := _INSTALL_FILE
1645endif
1646endif
1647
1648# _INST
1649ifdef $(symlnk)_INST
1650inst := $(patsubst %/,%,$($(symlnk)_INST))/$(dir $(symlnk))
1651else
1652ifdef $(target)_INST
1653inst := $(patsubst %/,%,$($(target)_INST))/$(dir $(symlnk))
1654else
1655inst := $(dir $(symlnk))
1656endif
1657endif
1658
1659# calc target
1660insdst := $(call $(instfun),$(symlnk),$(target),$(inst),$(PATH_INS))
1661#$(warning symlnk=$(symlnk) symdst=$(symdst) insdst=$(insdst) instfun=$(instfun) inst='$(inst)')
1662
1663# generate the rule (need double evaluation here)
1664$(eval $(def_install_symlink_rule))
1665
1666INSTARGET_$(target) += $(insdst)
1667endef
1668
1669
1670## generate the install rule
1671define def_install_directory_rule
1672# the install rule
1673$(insdst):
1674 $(INSTALL) -d \
1675 $(if $(uid),-o $(uid))\
1676 $(if $(gid),-g $(gid))\
1677 $(if $(mode),-m $(mode))\
1678 $(insdst)
1679
1680.NOTPARALLEL: $(insdst)
1681endef
1682
1683
1684## create one directory
1685define def_install_directory
1686
1687# _INST
1688ifdef $(directory)_INST
1689inst := $(PATH_INS)/$(patsubst %/,%,$($(directory)_INST))
1690else
1691ifdef $(target)_INST
1692inst := $(PATH_INS)/$(patsubst %/,%,$($(target)_INST))
1693else
1694inst := $(PATH_INS)
1695endif
1696endif
1697
1698mode := $(firstword \
1699 $($(target)_$(directory)_MODE.$(bld_trg).$(bld_trg_arch)) \
1700 $($(target)_$(directory)_MODE.$(bld_trg)) \
1701 $($(target)_$(directory)_MODE) \
1702 $($(directory)_MODE.$(bld_trg).$(bld_trg_arch)) \
1703 $($(directory)_MODE.$(bld_trg)) \
1704 $($(directory)_MODE) \
1705 $($(target)_MODE.$(bld_trg).$(bld_trg_arch)) \
1706 $($(target)_MODE.$(bld_trg)) \
1707 $($(target)_MODE))
1708uid := $(firstword \
1709 $($(target)_$(directory)_UID.$(bld_trg).$(bld_trg_arch)) \
1710 $($(target)_$(directory)_UID.$(bld_trg)) \
1711 $($(target)_$(directory)_UID) \
1712 $($(directory)_UID.$(bld_trg).$(bld_trg_arch)) \
1713 $($(directory)_UID.$(bld_trg)) \
1714 $($(directory)_UID) \
1715 $($(target)_UID.$(bld_trg).$(bld_trg_arch)) \
1716 $($(target)_UID.$(bld_trg)) \
1717 $($(target)_UID))
1718gid := $(firstword \
1719 $($(target)_$(directory)_GID.$(bld_trg).$(bld_trg_arch)) \
1720 $($(target)_$(directory)_GID.$(bld_trg)) \
1721 $($(target)_$(directory)_GID) \
1722 $($(directory)_GID.$(bld_trg).$(bld_trg_arch)) \
1723 $($(directory)_GID.$(bld_trg)) \
1724 $($(directory)_GID) \
1725 $($(target)_GID.$(bld_trg).$(bld_trg_arch)) \
1726 $($(target)_GID.$(bld_trg)) \
1727 $($(target)_GID))
1728
1729insdst := $(inst)/$(directory)/
1730#$(warning directory=$(directory) inst=$(inst) insdst=$(insdst) mode=$(mode) gid=$(gid) uid=$(uid))
1731
1732# generate the rule (need double evaluation here)
1733$(eval $(def_install_directory_rule))
1734
1735INSTARGET_DIRS_$(target) += $(insdst)
1736endef
1737
1738
1739## process one install target.
1740define def_install
1741bld_type := $(firstword $($(target)_BLD_TYPE) $(BUILD_TYPE))
1742bld_trg := $(firstword $($(target)_BLD_TRG) $(BUILD_TARGET))
1743bld_trg_arch:= $(firstword $($(target)_BLD_TRG_ARCH) $(BUILD_TARGET_ARCH))
1744bld_trg_cpu := $(firstword $($(target)_BLD_TRG_CPU) $(BUILD_TARGET_CPU))
1745
1746INSTARGET_$(target) :=
1747INSTARGET_DIRS_$(target) :=
1748
1749$(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)), \
1750 $(eval $(value def_install_directory)))
1751
1752$(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)), \
1753 $(eval $(value def_install_src)))
1754
1755$(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)), \
1756 $(eval $(value def_install_symlink)))
1757
1758_INSTALLS += $(INSTARGET_$(target)) $($(target)_GOALS)
1759_INSTALLS_DIRS += $(INSTARGET_DIRS_$(target))
1760endef
1761
1762## process all install targets
1763$(foreach target, $(INSTALLS) $(INSTALLS.$(BUILD_TARGET)) $(INSTALLS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)), \
1764 $(eval $(value def_install)))
1765
1766
1767#
1768# PACKING
1769#
1770_PACKING += $(PACKING) $(PACKING.$(BUILD_TARGET)) $(PACKING.$(BUILD_TARGET).$(BUILD_TARGET_ARCH))
1771
1772
1773#
1774# DOCS
1775#
1776
1777
1778#
1779# DIRECTORIES
1780#
1781_DIR_ALL := $(sort $(addsuffix /,$(patsubst %/,%,$(_DIRS))) $(dir $(_OUT_FILES) $(_OBJS) $(_INSTALLS)))
1782$(foreach directory,$(_INSTALLS_DIRS), $(eval _DIR_ALL := $(filter-out $(directory),$(_DIR_ALL))))
1783
1784
1785define def_mkdir_rule
1786$(directory):
1787 $(call MSG_L1,Creating directory $$@)
1788 $(MKDIR) -p $$@
1789endef
1790
1791$(foreach directory,$(_DIR_ALL),$(eval $(def_mkdir_rule)))
1792
1793
1794#
1795# NOTHING
1796#
1797do-nothing:
1798 $(call MSG_L1,Did nothing in $(CURDIR))
1799
1800
1801#
1802# CLEAN UP
1803#
1804do-clean:
1805 $(RM) -f $(_OUT_FILES) $(_OBJS) $(_DEPFILES) $(_DEPFILES_INCLUDED) $(_CLEAN_FILES) $(OTHER_CLEAN)
1806
1807
1808#
1809# PASSES (including directory and makefile walking)
1810#
1811
1812## Subdir
1813# @param $(pass) Lowercase pass name.
1814# @param $(PASS) Uppercase pass name.
1815# @param $(subdir) Subdirectory
1816# @param $(tag) tag to attach to the rule name.
1817define def_pass_subdir
1818pass_$(pass)$(tag):: $(dep)
1819 + $(QUIET)$$(MAKE) -C $(subdir) -f $$(notdir $$(firstword $$(wildcard $$(addprefix $(subdir)/,$$(DEFAULT_MAKEFILE))))) pass_$(pass)
1820endef
1821
1822## Submakefile
1823# @param $(pass) Lowercase pass name.
1824# @param $(PASS) Uppercase pass name.
1825# @param $(makefile) Makefile.
1826# @param $(tag) tag to attach to the rule name.
1827define def_pass_makefile
1828pass_$(pass)$(tag):: $(dep)
1829 + $(QUIET)$$(MAKE) -C $(patsubst %/,%,$(dir $(makefile))) -f $(notdir $(makefile)) pass_$(pass)
1830endef
1831
1832## Execute a pass.
1833# @param $(pass) Lowercase pass name.
1834# @param $(PASS) Uppercase pass name.
1835define def_pass_old
1836$(eval SUBDIRS_$(PASS) ?= $(SUBDIRS) $(SUBDIRS.$(BUILD_TARGET)) $(SUBDIRS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) )
1837$(eval SUBDIRS_AFTER_$(PASS) ?= $(SUBDIRS_AFTER) $(SUBDIRS_AFTER.$(BUILD_TARGET)) $(SUBDIRS_AFTER.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) )
1838$(eval MAKEFILES_BEFORE_$(PASS) ?= $(MAKEFILES_BEFORE) $(MAKEFILES_BEFORE.$(BUILD_TARGET)) $(MAKEFILES_BEFORE.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) )
1839$(eval MAKEFILES_AFTER_$(PASS) ?= $(MAKEFILES_AFTER) $(MAKEFILES_AFTER.$(BUILD_TARGET)) $(MAKEFILES_AFTER.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) )
1840
1841$(eval tag:=_before)
1842$(eval dep:=)
1843$(foreach subdir,$(SUBDIRS_$(PASS)) $(SUBDIRS_$(PASS).$(BUILD_TARGET)) $(SUBDIRS_$(PASS).$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) ,$(eval $(def_pass_subdir)))
1844$(foreach makefile,$(MAKEFILES_BEFORE_$(PASS)) $(MAKEFILES_BEFORE_$(PASS).$(BUILD_TARGET)) $(MAKEFILES_BEFORE_$(PASS).$(BUILD_TARGET).$(BUILD_TARGET_ARCH)),$(eval $(def_pass_makefile)))
1845
1846$(eval tag:=_after)
1847$(eval dep:=pass_$(pass)_doit)
1848$(foreach subdir,$(SUBDIRS_AFTER_$(PASS)) $(SUBDIRS_AFTER_$(PASS).$(BUILD_TARGET)) $(SUBDIRS_AFTER_$(PASS).$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) ,$(eval $(def_pass_subdir)))
1849$(foreach makefile,$(MAKEFILES_AFTER_$(PASS)) $(MAKEFILES_AFTER_$(PASS).$(BUILD_TARGET)) $(MAKEFILES_AFTER_$(PASS).$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) ,$(eval $(def_pass_makefile)))
1850
1851.NOTPARALLEL: pass_$(pass)_before pass_$(pass)_after
1852.PHONY: pass_$(pass) pass_$(pass)_before pass_$(pass)_doit pass_$(pass)_after
1853pass_$(pass)_doit: $(PASS_$(PASS)_trgs) $(foreach var,$(PASS_$(PASS)_vars),$(var))
1854pass_$(pass)_this: pass_$(pass)_before
1855 + $(QUIET)$$(MAKE) -f $$(MAKEFILE) pass_$(pass)_doit
1856pass_$(pass)_after:: pass_$(pass)_this
1857pass_$(pass): pass_$(pass)_after
1858
1859endef
1860
1861define def_pass
1862$(eval SUBDIRS_$(PASS) ?= $(SUBDIRS) $(SUBDIRS.$(BUILD_TARGET)) $(SUBDIRS.$(BUILD_TARGET.$(BUILD_TARGET_ARCH))) )
1863$(eval SUBDIRS_AFTER_$(PASS) ?= $(SUBDIRS_AFTER) $(SUBDIRS_AFTER.$(BUILD_TARGET)) $(SUBDIRS_AFTER.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) )
1864$(eval MAKEFILES_BEFORE_$(PASS) ?= $(MAKEFILES_BEFORE) $(MAKEFILES_BEFORE.$(BUILD_TARGET)) $(MAKEFILES_BEFORE.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) )
1865$(eval MAKEFILES_AFTER_$(PASS) ?= $(MAKEFILES_AFTER) $(MAKEFILES_AFTER.$(BUILD_TARGET)) $(MAKEFILES_AFTER.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) )
1866
1867$(eval tag:=_before)
1868$(eval dep:=)
1869$(foreach subdir,$(SUBDIRS_$(PASS)) $(SUBDIRS_$(PASS).$(BUILD_TARGET)) $(SUBDIRS_$(PASS).$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) ,$(eval $(def_pass_subdir)))
1870$(foreach makefile,$(MAKEFILES_BEFORE_$(PASS)) $(MAKEFILES_BEFORE_$(PASS).$(BUILD_TARGET)) $(MAKEFILES_BEFORE_$(PASS).$(BUILD_TARGET).$(BUILD_TARGET_ARCH)),$(eval $(def_pass_makefile)))
1871
1872$(eval tag:=_after)
1873$(eval dep:=pass_$(pass)_doit)
1874$(foreach subdir,$(SUBDIRS_AFTER_$(PASS)) $(SUBDIRS_AFTER_$(PASS).$(BUILD_TARGET)) $(SUBDIRS_AFTER_$(PASS).$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) ,$(eval $(def_pass_subdir)))
1875$(foreach makefile,$(MAKEFILES_AFTER_$(PASS)) $(MAKEFILES_AFTER_$(PASS).$(BUILD_TARGET)) $(MAKEFILES_AFTER_$(PASS).$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) ,$(eval $(def_pass_makefile)))
1876
1877ifdef KBUILD_SAFE_PARALLEL
1878.NOTPARALLEL: pass_$(pass) pass_$(pass)_before pass_$(pass)_after pass_$(pass)_this
1879.PHONY: pass_$(pass) pass_$(pass)_before pass_$(pass)_after pass_$(pass)_this pass_$(pass)_doit
1880pass_$(pass)_doit: $(PASS_$(PASS)_trgs) $(foreach var,$(PASS_$(PASS)_vars),$(var))
1881pass_$(pass)_this: pass_$(pass)_before
1882 + $(QUIET)$$(MAKE) -f $$(MAKEFILE) pass_$(pass)_doit
1883pass_$(pass)_after:: pass_$(pass)_this
1884pass_$(pass): pass_$(pass)_after
1885else
1886.NOTPARALLEL: pass_$(pass) pass_$(pass)_before pass_$(pass)_after pass_$(pass)_doit
1887.PHONY: pass_$(pass) pass_$(pass)_before pass_$(pass)_after pass_$(pass)_doit
1888pass_$(pass)_doit: pass_$(pass)_before \
1889 $(PASS_$(PASS)_trgs) $(foreach var,$(PASS_$(PASS)_vars),$($(var)))
1890pass_$(pass): \
1891 pass_$(pass)_before \
1892 pass_$(pass)_doit \
1893 pass_$(pass)_after
1894endif
1895
1896#$ (warning pass=$(pass) PASS=$(PASS): $(PASS_$(PASS)_trgs) $(PASS_$(PASS)_trgs) $(foreach var,$(PASS_$(PASS)_vars),$($(var))))
1897endef
1898
1899# Generate the defined passes.
1900$(foreach PASS, $(PASSES), \
1901 $(eval pass := $(PASS_$(PASS)_pass)) \
1902 $(eval $(def_pass)))
1903
1904## Pass order
1905# @param $(pass) Current pass name.
1906# @param $(prev_pass) The previous pass name.
1907define def_pass_order
1908ifdef KBUILD_SAFE_PARALLEL
1909.NOTPARALLEL: pass_$(pass)_order
1910.PHONY: pass_$(pass)_order
1911pass_$(pass)_order: $(pass_prev)
1912 $(call MSG_L1,Pass - $(if $(PASS_$(PASS)),$(PASS_$(PASS)),$(pass)))
1913 + $(QUIET)$$(MAKE) -f $$(MAKEFILE) pass_$(pass)
1914else
1915.NOTPARALLEL: pass_$(pass)_order pass_$(pass)_banner
1916.PHONY: pass_$(pass)_order pass_$(pass)_banner
1917pass_$(pass)_banner:
1918 $(call MSG_L1,Pass - $(if $(PASS_$(PASS)),$(PASS_$(PASS)),$(pass)))
1919pass_$(pass)_order: \
1920 $(pass_prev) \
1921 pass_$(pass)_banner \
1922 pass_$(pass)
1923endif
1924$(eval pass_prev := pass_$(pass)_order)
1925endef
1926
1927## PASS: order
1928# Use dependencies to ensure correct pass order.
1929pass_prev :=
1930$(foreach PASS,$(DEFAULT_PASSES),\
1931 $(eval pass := $(PASS_$(PASS)_pass)) \
1932 $(eval $(def_pass_order)))
1933
1934
1935#
1936# THE MAIN RULES
1937#
1938all_recursive: $(pass_prev)
1939
1940rebuild: clean
1941 + $(MAKE) -f $(firstword $(MAKEFILE_LIST)) all_recursive
1942
1943# @todo make this a non-default pass!
1944uninstall:
1945 $(RM) -f $(_INSTALLS)
1946
1947install: pass_installs
1948
1949# misc shortcuts.
1950targets: bldprogs libraries dlls programs sysmods others installs
1951objects: $(_OBJS)
1952bldprogs: $(_BLDPROGS)
1953libraries: $(_LIBS) $(_IMPORT_LIBS) $(_OTHER_LIBRARIES)
1954dlls: $(_DLLS)
1955programs: $(_PROGRAMS)
1956sysmods: $(_SYSMODS)
1957others: $(_OTHERS)
1958installs: $(_INSTALLS_DIRS) $(_INSTALLS)
1959
1960
1961#
1962# kBuild debugging stuff.
1963#
1964_SPACE := $(subst ., ,.)
1965_TAB := $(subst ., ,.)
1966define _NEWLINE
1967
1968
1969endef
1970NLTAB = $(_NEWLINE)$(TAB)
1971show_targets:
1972 @$(foreach target, $(ALL_TARGETS),\
1973 @$(ECHO) "target: $(target)" $(NLTAB)\
1974 @$(ECHO) " PATH_$(target)=$(PATH_$(target))" $(NLTAB)\
1975 @$(ECHO) " TARGET_$(target)=$(TARGET_$(target))" $(NLTAB)\
1976 @$(ECHO) " INSTARGET_$(target)=$(INSTARGET_$(target))" $(NLTAB)\
1977$(foreach prop,$(PROPS_SINGLE) $(PROPS_ACCUMULATE) OBJS_ CLEAN, \
1978 $(eval _tmp:=$(firstword $($(target)_BLD_TRG) $(BUILD_TARGET))) \
1979 $(if $($(target)_$(prop).$(_tmp)),\
1980 @$(ECHO) " $(target)_$(prop).$(_tmp)=$($(target)_$(prop).$(_tmp))" $(NLTAB)) \
1981 $(if $($(target)_$(prop)), $(NLTAB)@$(ECHO) " $(target)_$(prop)=$($(target)_$(prop))" $(NLTAB)) \
1982)\
1983$(foreach prop,$(PROPS_DEFERRED), \
1984 $(eval _tmp:=$(firstword $($(target)_BLD_TRG) $(BUILD_TARGET))) \
1985 $(if $(value $(target)_$(prop).$(_tmp)),\
1986 @$(ECHO) ' $(target)_$(prop).$(_tmp)=$(value $(TARGET)_$(prop).$(_tmp))' $(NLTAB)) \
1987 $(if $(value $(target)_$(prop)), $(NLTAB)@$(ECHO) ' $(target)_$(prop)=$(value $(target)_$(prop))' $(NLTAB)) \
1988))
1989
1990
1991
1992#
1993# Include dependency files.
1994#
1995$(foreach dep,$(wildcard $(_DEPFILES)),$(eval include $(dep)))
1996
1997
1998# end-of-file-content
1999__footer_kmk__ := target
2000endif # __footer_kmk__
2001
Note: See TracBrowser for help on using the repository browser.