source: trunk/kBuild/footer.kmk@ 524

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

Made up my mind about the command depency blocker variables; NO_LINK_CMDS_DEPS and NO_COMPILE_CMDS_DEPS.

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