source: trunk/kBuild/footer.kmk@ 894

Last change on this file since 894 was 893, checked in by bird, 18 years ago

using includedep for all dependencies.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 84.0 KB
Line 
1# $Id: footer.kmk 893 2007-05-04 04:48:10Z bird $
2## @file
3#
4# kBuild - File included at top of makefile.
5#
6# Copyright (c) 2004-2007 knut st. osmundsen <bird-kBuild-spam@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 $(FETCHES) $(FETCHES.$(BUILD_TARGET)) $(FETCHES.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) \
38 $(PATCHES) $(PATCHES.$(BUILD_TARGET)) $(PATCHES.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) \
39 $(BLDPROGS) $(BLDPROGS.$(BUILD_PLATFORM)) $(BLDPROGS.$(BUILD_PLATFORM).$(BUILD_PLATFORM_ARCH)) \
40 $(LIBRARIES) $(LIBRARIES.$(BUILD_TARGET)) $(LIBRARIES.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) \
41 $(IMPORT_LIBS) $(IMPORT_LIBS.$(BUILD_TARGET)) $(IMPORT_LIBS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) \
42 $(DLLS) $(DLLS.$(BUILD_TARGET)) $(DLLS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) \
43 $(PROGRAMS) $(PROGRAMS.$(BUILD_TARGET)) $(PROGRAMS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) \
44 $(SYSMODS) $(SYSMODS.$(BUILD_TARGET)) $(SYSMODS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) \
45 $(INSTALLS) $(INSTALLS.$(BUILD_TARGET)) $(INSTALLS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) \
46 $(OTHERS) $(OTHERS.$(BUILD_TARGET)) $(OTHERS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH))
47
48# all $(BUILD_TARGET) targets.
49_ALL_BUILD_TARGET_TARGETS += \
50 $(FETCHES) $(FETCHES.$(BUILD_TARGET)) $(FETCHES.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) \
51 $(PATCHES) $(PATCHES.$(BUILD_TARGET)) $(PATCHES.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) \
52 $(LIBRARIES) $(LIBRARIES.$(BUILD_TARGET)) $(LIBRARIES.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) \
53 $(IMPORT_LIBS) $(IMPORT_LIBS.$(BUILD_TARGET)) $(IMPORT_LIBS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) \
54 $(DLLS) $(DLLS.$(BUILD_TARGET)) $(DLLS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) \
55 $(PROGRAMS) $(PROGRAMS.$(BUILD_TARGET)) $(PROGRAMS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) \
56 $(SYSMODS) $(SYSMODS.$(BUILD_TARGET)) $(SYSMODS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) \
57 $(INSTALLS) $(INSTALLS.$(BUILD_TARGET)) $(INSTALLS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) \
58 $(OTHERS) $(OTHERS.$(BUILD_TARGET)) $(OTHERS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH))
59
60# all $(BUILD_TARGET) targets.
61_ALL_BUILD_PLATFORM_TARGETS += \
62 $(BLDPROGS) $(BLDPROGS.$(BUILD_PLATFORM)) $(BLDPROGS.$(BUILD_PLATFORM).$(BUILD_PLATFORM_ARCH))
63
64# all targets making use of srcname.
65_ALL_SRCNAME_TARGETS += \
66 $(FETCHES) $(FETCHES.$(BUILD_TARGET)) $(FETCHES.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) \
67 $(PATCHES) $(PATCHES.$(BUILD_TARGET)) $(PATCHES.$(BUILD_TARGET).$(BUILD_TARGET_ARCH))
68
69# dependency files.
70_DEPFILES :=
71
72# included dependency files.
73_DEPFILES_INCLUDED :=
74
75
76# All kind of output files except for _OBJS and _DEPFILES.
77# Compiling or linking definition outputting other things that $@ and any
78# required dependency file must add those output files to this variable.
79_OUT_FILES :=
80
81# Files which only requires cleaning up.
82_CLEAN_FILES :=
83
84# all of a type
85_OBJS :=
86_FETCHES :=
87_DOWNLOADS:=
88_UNPACKS :=
89_PATCHES :=
90_UNFETCHES:=
91_BLDPROGS :=
92_LIBS :=
93_DLLS :=
94_PROGRAMS :=
95_SYSMODS :=
96_INSTALLS :=
97_INSTALLS_FILES :=
98_INSTALLS_DIRS :=
99_OTHERS :=
100_PACKING :=
101_DIRS := $(PATH_TARGET)/ $(PATH_TARGET)
102_IMPORT_LIBS :=
103
104# misc
105pass_prev :=
106
107
108#
109# Basic macros
110#
111
112## Figure out the tool for a target.
113# @param $1 normalized target.
114# @param $2 tooltype.
115# @param bld_trg build target.
116# @param bld_trg_arch build target architecture.
117_TARGET_TOOL = $(strip $(firstword \
118 $($(1)_$(2)TOOL.$(bld_trg).$(bld_trg_arch)) \
119 $($(1)_$(2)TOOL.$(bld_trg)) \
120 $($(1)_$(2)TOOL) \
121 $($(1)_TOOL.$(bld_trg).$(bld_trg_arch)) \
122 $($(1)_TOOL.$(bld_trg)) \
123 $($(1)_TOOL) \
124 $($(2)TOOL.$(bld_trg).$(bld_trg_arch)) \
125 $($(2)TOOL.$(bld_trg)) \
126 $($(2)TOOL) \
127 $(TOOL.$(bld_trg).$(bld_trg_arch)) \
128 $(TOOL.$(bld_trg)) \
129 $(TOOL) \
130 ))
131
132## Figure out the actual name of an installed file.
133# @param $1 The file to install.
134# @param $2 The target name.
135# @param $3 The _INST value (can be empty).
136# @param $4 The default directory to use when $3 is empty.
137_INSTALL_FILE = $(patsubst %/,%/$(notdir $(1)),$(if $(3),$(PATH_INS)/$(3),$(4)/))
138
139
140#
141# Include the additional footer macros when bootstrapping kBuild.
142#
143ifndef KMK_VERSION
144 include $(PATH_KBUILD)/gnumake-footer.kmk
145endif
146
147
148
149#
150# Check syntax which leads to weird syntax errors.
151#
152
153## Check
154# @param $(target) Target name.
155define def_check_target
156ifneq ("$($(target)_TEMPLATE)","$(strip $($(target)_TEMPLATE))")
157$$(error $(target) have an incorrect template name. Remove any tabs!)
158endif
159endef
160$(foreach target, $(ALL_TARGETS),$(eval $(def_check_target)))
161
162
163#
164# Include templates
165#
166_TEMPLATES := $(TEMPLATE)
167define def_templates
168ifdef $(target)_TEMPLATE
169_TEMPLATES += $($(target)_TEMPLATE)
170endif
171endef
172$(foreach target, $(ALL_TARGETS), $(eval $(def_templates)))
173_TEMPLATES := $(sort $(_TEMPLATES))
174# $ (warning dbg: _TEMPLATES=$(_TEMPLATES))
175
176define def_templates_include
177ifndef TEMPLATE_$(template)
178include $(firstword $(foreach path, $(TEMPLATE_PATHS) $(PATH_KBUILD)/templates/, $(wildcard $(path)/$(template).kmk)))
179endif
180endef
181$(foreach template, $(_TEMPLATES), $(eval $(def_templates)))
182
183
184#
185# Template Inheritance.
186#
187define def_template_extends_prop
188ifndef TEMPLATE_$(template)_$(prop)
189 ifdef TEMPLATE_$(parent)_$(prop)
190TEMPLATE_$(template)_$(prop) = $$(TEMPLATE_$(parent)_$(prop))
191 endif
192endif
193endef
194
195
196define def_template_extends
197ifdef TEMPLATE_$(template)_EXTENDS
198 ifndef TEMPLATE_$(template)_EXTENDS_STATUS_
199 TEMPLATE_$(template)_EXTENDS_STATUS_ := 0
200 parent := $(strip $(TEMPLATE_$(template)_EXTENDS))
201
202 # recursivly process the parent if it's inherting from somebody too.
203 ifdef TEMPLATE_$(parent)_EXTENDS
204 ifneq ($(TEMPLATE_$(parent)_EXTENDS_STATUS_),42)
205 # foreach will create 'template' in a new variable context hiding our current variable.
206 $(foreach template, $(parent), $(eval $(value def_template_extends)))
207 parent := $(strip $(TEMPLATE_$(template)_EXTENDS))
208 endif
209 endif
210
211 # inherit properties.
212 $(foreach prop, $(PROPS_SINGLE) $(PROPS_ACCUMULATE_R) $(PROPS_ACCUMULATE_L) $(PROPS_DEFERRED)\
213 $(addsuffix .$(BUILD_TARGET), $(PROPS_SINGLE) $(PROPS_ACCUMULATE_L) $(PROPS_ACCUMULATE_R) $(PROPS_DEFERRED))\
214 $(addsuffix .$(BUILD_TARGET).$(BUILD_TARGET_ARCH), $(PROPS_SINGLE) $(PROPS_ACCUMULATE_L) $(PROPS_ACCUMULATE_R) $(PROPS_DEFERRED))\
215 $(addsuffix .$(BUILD_TARGET_ARCH), $(PROPS_SINGLE) $(PROPS_ACCUMULATE_L) $(PROPS_ACCUMULATE_R) $(PROPS_DEFERRED))\
216 $(addsuffix .$(BUILD_TARGET_CPU), $(PROPS_SINGLE) $(PROPS_ACCUMULATE_L) $(PROPS_ACCUMULATE_R) $(PROPS_DEFERRED))\
217 $(addsuffix .$(BUILD_TYPE), $(PROPS_SINGLE) $(PROPS_ACCUMULATE_L) $(PROPS_ACCUMULATE_R) $(PROPS_DEFERRED))\
218 ,$(eval $(def_template_extends_prop))) # exploits the 2 evaluation, so no value!
219
220 TEMPLATE_$(template)_EXTENDS_STATUS_ := 42
221 else
222 # protect against inheritance loops.
223 ifneq ($(TEMPLATE_$(template)_EXTENDS_STATUS_),42)
224 $(error kBuild: inheritance loop! template=$(template))
225 endif
226 endif
227endif
228endef
229
230# $ (foreach template, $(_TEMPLATES), $(if TEMPLATE_$(template)_EXTENDS, $(eval $(value def_template_extends))))
231$(foreach template, $(_TEMPLATES), $(eval $(value def_template_extends)))
232
233
234#
235# Common Inheritance
236#
237
238## Inherit one template property in a non-accumulative manner.
239# @param $(prop) Property name
240# @param $(target) Target name
241# @todo fix the precedence order for some properties.
242define def_inherit_template_one
243ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop)
244ifndef $(target)_$(prop)
245$(target)_$(prop) := $(TEMPLATE_$($(target)_TEMPLATE)_$(prop))
246#$ (warning dbgtarget: $(target)_$(prop):='$(value $(target)_$(prop))' TEMPLATE_$($(target)_TEMPLATE)_$(prop))
247endif
248endif
249ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg)
250ifndef $(target)_$(prop).$(bld_trg)
251#$ (warning dbgsource: $(target)_$(prop).$(bld_trg)="TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg)" TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg))
252$(target)_$(prop).$(bld_trg) := $(TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg))
253endif
254endif
255ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg).$(bld_trg_arch)
256ifndef $(target)_$(prop).$(bld_trg).$(bld_trg_arch)
257#$ (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))
258$(target)_$(prop).$(bld_trg).$(bld_trg_arch) := $(TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg).$(bld_trg_arch))
259endif
260endif
261ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_arch)
262ifndef $(target)_$(prop).$(bld_trg_arch)
263#$ (warning dbgsource: $(target)_$(prop).$(bld_trg_arch)="TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_arch)" TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_arch))
264$(target)_$(prop).$(bld_trg_arch) := $(TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_arch))
265endif
266endif
267ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_cpu)
268ifndef $(target)_$(prop).$(bld_trg_cpu)
269#$ (warning dbgsource: $(target)_$(prop).$(bld_trg_cpu)="TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_cpu)" TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_cpu))
270$(target)_$(prop).$(bld_trg_cpu) := $(TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_cpu))
271endif
272endif
273endef
274
275## Inherit one template property in a non-accumulative manner, deferred expansion.
276# @param 1: $(prop) Property name
277# @param 2: $(target) Target name
278# @todo fix the precedence order for some properties.
279# @remark this define relies on double evaluation
280define def_inherit_template_one_deferred
281ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop)
282ifndef $(target)_$(prop)
283$(target)_$(prop) = $$(TEMPLATE_$($(target)_TEMPLATE)_$(prop))
284#$ (warning dbgtarget: $(target)_$(prop):='$(value $(target)_$(prop))' TEMPLATE_$($(target)_TEMPLATE)_$(prop))
285endif
286endif
287ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg)
288ifndef $(target)_$(prop).$(bld_trg)
289#$ (warning dbgsource: $(target)_$(prop).$(bld_trg)="TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg)" TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg))
290$(target)_$(prop).$(bld_trg) = $$(TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg))
291endif
292endif
293ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg).$(bld_trg_arch)
294ifndef $(target)_$(prop).$(bld_trg).$(bld_trg_arch)
295#$ (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))
296$(target)_$(prop).$(bld_trg).$(bld_trg_arch) = $$(TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg).$(bld_trg_arch))
297endif
298endif
299ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_arch)
300ifndef $(target)_$(prop).$(bld_trg_arch)
301#$ (warning dbgsource: $(target)_$(prop).$(bld_trg_arch)="TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_arch)" TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_arch))
302$(target)_$(prop).$(bld_trg_arch) = $$(TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_arch))
303endif
304endif
305ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_cpu)
306ifndef $(target)_$(prop).$(bld_trg_cpu)
307#$ (warning dbgsource: $(target)_$(prop).$(bld_trg_cpu)="TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_cpu)" TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_cpu))
308$(target)_$(prop).$(bld_trg_cpu) = $$(TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_cpu))
309endif
310endif
311endef
312
313## Inherit one acculumlative template property where the 'most significant' items are at the left end.
314# @param $(prop) Property name
315# @param $(target) Target name
316define def_inherit_template_one_accumulate_l
317ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop)
318#$ (warning dbgtype: TEMPLATE_$($(target)_TEMPLATE)_$(prop) $(target)_$(prop)=$($(target)_$(prop)) $(TEMPLATE_$($(target)_TEMPLATE)_$(prop)))
319$(target)_$(prop) += $$(TEMPLATE_$($(target)_TEMPLATE)_$(prop))
320#$ (warning dbgtype: $(target)_$(prop)=$($(target)_$(prop)))
321endif
322ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(BUILD_TYPE)
323#$ (warning dbg4: TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(BUILD_TYPE))
324$(target)_$(prop).$(BUILD_TYPE) += $$(TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(BUILD_TYPE))
325endif
326ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg)
327#$ (warning dbg5: TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg))
328$(target)_$(prop).$(bld_trg) += $$(TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg))
329endif
330ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg).$(bld_trg_arch)
331#$ (warning dbg4: TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg).$(bld_trg_arch))
332$(target)_$(prop).$(bld_trg).$(bld_trg_arch) += $$(TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg).$(bld_trg_arch))
333endif
334ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_cpu)
335#$ (warning dbg5: TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_cpu))
336$(target)_$(prop).$(bld_trg_cpu) += $$(TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_cpu))
337endif
338ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_arch)
339#$ (warning dbg6: TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_arch))
340$(target)_$(prop).$(bld_trg_arch) += $$(TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_arch))
341endif
342endef
343
344## Inherit one acculumlative template property where the 'most significant' items are at the right end.
345# First pass, $(value) referenced.
346# @param $(prop) Property name
347# @param $(target) Target name
348define def_inherit_template_one_accumulate_r1
349ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop)
350$(eval _$(target)_$(prop)_R = $(value $(target)_$(prop)))
351endif
352ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(BUILD_TYPE)
353$(eval _$(target)_$(prop).$(BUILD_TYPE)_R = $(value $(target)_$(prop).$(BUILD_TYPE)))
354endif
355ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg)
356$(eval _$(target)_$(prop).$(bld_trg)_R = $(value $(target)_$(prop).$(bld_trg)))
357endif
358ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg).$(bld_trg_arch)
359$(eval _$(target)_$(prop).$(bld_trg).$(bld_trg_arch)_R = $(value $(target)_$(prop).$(bld_trg).$(bld_trg_arch)))
360endif
361ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_cpu)
362$(eval _$(target)_$(prop).$(bld_trg_cpu)_R = $(value $(target)_$(prop).$(bld_trg_cpu)))
363endif
364ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_arch)
365$(eval _$(target)_$(prop).$(bld_trg_arch)_R = $(value $(target)_$(prop).$(bld_trg_arch)))
366endif
367endef
368
369## Inherit one template property the other way around.
370# Second pass, not $(value) referenced.
371# @param $(prop) Property name
372# @param $(target) Target name
373define def_inherit_template_one_accumulate_r2
374ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop)
375$(target)_$(prop) = $$(TEMPLATE_$($(target)_TEMPLATE)_$(prop)) $$(_$(target)_$(prop)_R)
376endif
377ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(BUILD_TYPE)
378$(target)_$(prop).$(BUILD_TYPE) = $$(TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(BUILD_TYPE)) $$(_$(target)_$(prop).$(BUILD_TYPE)_R)
379endif
380ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg)
381$(target)_$(prop).$(bld_trg) = $$(TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg)) $$(_$(target)_$(prop).$(bld_trg)_R)
382endif
383ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg).$(bld_trg_arch)
384$(target)_$(prop).$(bld_trg).$(bld_trg_arch) = $$(TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg).$(bld_trg_arch)) $$(_$(target)_$(prop).$(bld_trg).$(bld_trg_arch)_R)
385endif
386ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_cpu)
387$(target)_$(prop).$(bld_trg_cpu) = $$(TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_cpu)) $$(_$(target)_$(prop).$(bld_trg_cpu)_R)
388endif
389ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_arch)
390$(target)_$(prop).$(bld_trg_arch) = $$(TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_arch)) $$(_$(target)_$(prop).$(bld_trg_arch)_R)
391endif
392endef
393
394
395## Inherit template properties for on target.
396# @param $(target) Target name.
397define def_inherit_template
398# sanity check.
399ifdef _$(target)_ALREADY_PROCESSED
400 $(error kBuild: The target $(target) appears more than once in the target lists! Please correct the makefile(s))
401endif
402_$(target)_ALREADY_PROCESSED := 1
403
404# Inherit any default template.
405ifdef TEMPLATE
406ifeq ($($(target)_TEMPLATE),)
407$(eval $(target)_TEMPLATE:=$(TEMPLATE))
408endif
409endif
410# Expand the template if specified.
411ifneq ($($(target)_TEMPLATE),)
412$(foreach prop,$(PROPS_SINGLE),$(eval $(value def_inherit_template_one)))
413$(foreach prop,$(PROPS_DEFERRED),$(eval $(def_inherit_template_one_deferred))) # exploits the 2 evaluation, so no value!
414$(foreach prop,$(PROPS_ACCUMULATE_L),$(eval $(def_inherit_template_one_accumulate_l))) # += works fine (better) without value.
415$(foreach prop,$(PROPS_ACCUMULATE_R),\
416$(eval $(value def_inherit_template_one_accumulate_r1))\
417$(eval $(def_inherit_template_one_accumulate_r2))\
418) # This is a hack! (but it appears to work)
419endif
420endef
421
422# Inherit template properties
423bld_trg := $(BUILD_TARGET)
424bld_trg_arch := $(BUILD_TARGET_ARCH)
425bld_trg_cpu := $(BUILD_TARGET_CPU)
426$(foreach target, $(_ALL_BUILD_TARGET_TARGETS),$(eval $(value def_inherit_template)))
427
428bld_trg := $(BUILD_PLATFORM)
429bld_trg_arch := $(BUILD_PLATFORM_ARCH)
430bld_trg_cpu := $(BUILD_PLATFORM_CPU)
431$(foreach target, $(_ALL_BUILD_PLATFORM_TARGETS),$(eval $(value def_inherit_template)))
432
433
434#
435# Include tools & sdks
436#
437_TOOLS := $(TOOL.$(BUILD_TARGET)) $(TOOL.$(BUILD_TARGET_ARCH)) $(TOOL.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) \
438 $(TOOL.$(BUILD_PLATFORM)) $(TOOL.$(BUILD_PLATFORM_ARCH)) $(TOOL.$(BUILD_PLATFORM).$(BUILD_PLATFORM_ARCH)) \
439 $(TOOL)
440_SDKS := $(SDKS.$(BUILD_TARGET)) $(SDKS.$(BUILD_TARGET_ARCH)) $(SDKS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) \
441 $(SDKS.$(BUILD_PLATFORM)) $(SDKS.$(BUILD_PLATFORM_ARCH)) $(SDKS.$(BUILD_PLATFORM).$(BUILD_PLATFORM_ARCH)) \
442 $(SDKS.$(BUILD_TYPE)) \
443 $(SDKS)
444define def_tools_sdks_target_source
445$(eval _TOOLS += $(foreach prop, $(PROPS_TOOLS), \
446 $($(source)_$(prop).$(_bld_trg)) \
447 $($(target)_$(source)_$(prop).$(_bld_trg)) \
448 $($(source)_$(prop).$(_bld_trg).$(_bld_trg_arch)) \
449 $($(target)_$(source)_$(prop).$(_bld_trg).$(_bld_trg_arch)) \
450 $($(source)_$(prop).$(_bld_trg_arch)) \
451 $($(target)_$(source)_$(prop).$(_bld_trg_arch)) \
452 $($(source)_$(prop)) \
453 $($(target)_$(source)_$(prop))))
454$(eval _SDKS += \
455 $($(source)_SDKS.$(_bld_trg)) \
456 $($(target)_$(source)_SDKS.$(_bld_trg)) \
457 $($(source)_SDKS.$(_bld_trg).$(_bld_trg_arch)) \
458 $($(target)_$(source)_SDKS.$(_bld_trg).$(_bld_trg_arch)) \
459 $($(source)_SDKS.$(_bld_trg_arch)) \
460 $($(target)_$(source)_SDKS.$(_bld_trg_arch)) \
461 $($(source)_SDKS.$(BUILD_TYPE)) \
462 $($(target)_$(source)_SDKS.$(BUILD_TYPE)) \
463 $($(source)_SDKS) \
464 $($(target)_$(source)_SDKS))
465endef
466
467define def_tools_sdks_target
468_bld_trg := $(firstword $($(target)_BLD_TRG) $(bld_trg))
469_bld_trg_arch := $(firstword $($(target)_BLD_TRG_ARCH) $(bld_trg_arch))
470_bld_trg_cpu := $(firstword $($(target)_BLD_TRG_CPU) $(bld_trg_cpu))
471
472$(eval _TOOLS += $(foreach prop, $(PROPS_TOOLS), \
473 $($(target)_$(prop).$(_bld_trg)) \
474 $($(target)_$(prop).$(_bld_trg_arch)) \
475 $($(target)_$(prop).$(_bld_trg).$(_bld_trg_arch)) \
476 $($(target)_$(prop))))
477$(eval _SDKS += \
478 $($(target)_SDKS.$(_bld_trg)) \
479 $($(target)_SDKS.$(_bld_trg_arch)) \
480 $($(target)_SDKS.$(_bld_trg).$(_bld_trg_arch)) \
481 $($(target)_SDKS))
482$(foreach source, \
483 $($(target)_SOURCES.$(_bld_trg)) \
484 $($(target)_SOURCES.$(_bld_trg_arch)) \
485 $($(target)_SOURCES.$(_bld_trg).$(_bld_trg_arch)) \
486 $($(target)_SOURCES.$(_bld_trg_cpu)) \
487 $($(target)_SOURCES.$(BUILD_TYPE)) \
488 $($(target)_SOURCES) \
489 , $(eval $(value def_tools_sdks_target_source)))
490endef
491
492define def_tools_srcname_target
493_bld_trg := $(firstword $($(target)_BLD_TRG) $(bld_trg))
494_bld_trg_arch := $(firstword $($(target)_BLD_TRG_ARCH) $(bld_trg_arch))
495_bld_trg_cpu := $(firstword $($(target)_BLD_TRG_CPU) $(bld_trg_cpu))
496
497$(foreach source, $(notdir\
498 $($(target)_SOURCES.$(_bld_trg)) \
499 $($(target)_SOURCES.$(_bld_trg_arch)) \
500 $($(target)_SOURCES.$(_bld_trg).$(_bld_trg_arch)) \
501 $($(target)_SOURCES.$(_bld_trg_cpu)) \
502 $($(target)_SOURCES.$(BUILD_TYPE)) \
503 $($(target)_SOURCES) \
504 ), $(eval $(value def_tools_sdks_target_source)))
505endef
506
507bld_trg := $(BUILD_TARGET)
508bld_trg_arch := $(BUILD_TARGET_ARCH)
509bld_trg_cpu := $(BUILD_TARGET_CPU)
510$(foreach target, $(_ALL_BUILD_TARGET_TARGETS), $(eval $(value def_tools_sdks_target)))
511$(foreach target, $(_ALL_SRCNAME_TARGETS), $(eval $(value def_tools_srcname_target)))
512
513bld_trg := $(BUILD_PLATFORM)
514bld_trg_arch := $(BUILD_PLATFORM_ARCH)
515bld_trg_cpu := $(BUILD_PLATFORM_CPU)
516$(foreach target, $(_ALL_BUILD_PLATFORM_TARGETS), $(eval $(value def_tools_sdks_target)))
517
518
519# include TOOLS
520define def_tools_include
521ifndef TOOL_$(tool)
522TOOL_$(tool)_KMK_FILE := $(firstword $(foreach path, $(TOOL_PATHS) $(PATH_KBUILD)/tools, $(wildcard $(path)/$(tool).kmk)))
523ifeq ($(TOOL_$(tool)_KMK_FILE),)
524$(error kBuild: Cannot find include file for the tool '$(tool)'! Searched: $(TOOL_PATHS) $(PATH_KBUILD)/tools)
525endif
526include $(TOOL_$(tool)_KMK_FILE)
527ifndef TOOL_$(tool)
528$(warning kBuild: TOOL_$(tool) was not by $(TOOL_$(tool)_KMK_FILE)!)
529endif
530endif
531endef
532
533_TOOLS := $(sort $(_TOOLS))
534$(foreach tool, $(_TOOLS), $(eval $(value def_tools_include)))
535
536
537# include SDKS
538define def_sdks_include_one
539ifndef SDK_$(sdk)
540SDK_$(sdk)_KMK_FILE := $(firstword $(foreach path, $(SDK_PATHS) $(PATH_KBUILD)/sdks, $(wildcard $(path)/$(sdk).kmk)))
541ifeq ($(SDK_$(sdk)_KMK_FILE),)
542$(error kBuild: Cannot find include file for the SDK '$(sdk)'! Searched: $(SDK_PATHS) $(PATH_KBUILD)/sdks)
543endif
544include $(SDK_$(sdk)_KMK_FILE)
545ifndef SDK_$(sdk)
546$(warning kBuild: SDK_$(sdk) was not defined by $(SDK_$(sdk)_KMK_FILE)!)
547endif
548endif
549endef
550
551_SDKS := $(sort $(_SDKS))
552$(foreach sdk, $(_SDKS), $(eval $(value def_sdks_include_one)))
553
554
555
556#
557#
558# Target lists - Pass 1
559#
560# This pass is for defining variables that might be referenced in
561# properties of other targets.
562#
563#
564
565# Don't do anything for fetch targets (yet).
566
567##
568# Link prolog for Pass 1.
569#
570# @param $(target) Normalized target name.
571# @param $(EXT) EXE,DLL,SYS,LIB.
572# @param $(EXTPRE) HOST or nothing.
573# @param $(definst) The default _INST value.
574# @param $(tool_prefix) LD or AR.
575# @param $(bld_trg_base_var) TARGET or PLATFORM.
576define def_pass1_link_common
577
578bld_type := $(firstword $($(target)_BLD_TYPE) $(BUILD_TYPE))
579bld_trg := $(firstword $($(target)_BLD_TRG) $(BUILD_$(bld_trg_base_var)))
580bld_trg_arch:= $(firstword $($(target)_BLD_TRG_ARCH) $(BUILD_$(bld_trg_base_var)_ARCH))
581bld_trg_cpu := $(firstword $($(target)_BLD_TRG_CPU) $(BUILD_$(bld_trg_base_var)_CPU))
582
583tool := $(call _TARGET_TOOL,$(target),$(tool_prefix))
584name := $(firstword\
585 $($(target)_NAME.$(bld_trg).$(bld_trg_arch))\
586 $($(target)_NAME.$(bld_trg_arch))\
587 $($(target)_NAME.$(bld_trg))\
588 $($(target)_NAME.$(bld_type))\
589 $($(target)_NAME)\
590 $(target))
591outbase := $(call TARGET_BASE,$(name),$(target))
592ifndef PATH_$(target)
593 PATH_$(target) := $(patsubst %/,%,$(dir $(outbase)))
594else ifneq ($(PATH_$(target)),$(patsubst %/,%,$(dir $(outbase))))
595 $(error kBuild internal error: PATH_$(target)=$(PATH_$(target)) expected $(patsubst %/,%,$(dir $(outbase))))
596endif
597ifeq ($(tool_prefix),AR) ## @todo fix this mess!
598suff := $(firstword\
599 $($(target)_$(EXT)SUFF.$(bld_trg).$(bld_trg_arch))\
600 $($(target)_$(EXT)SUFF.$(bld_trg))\
601 $($(target)_$(EXT)SUFF)\
602 $(TOOL_$(tool)_$(tool_prefix)$(EXT)SUFF.$(bld_trg).$(bld_trg_arch))\
603 $(TOOL_$(tool)_$(tool_prefix)$(EXT)SUFF.$(bld_trg))\
604 $(TOOL_$(tool)_$(tool_prefix)$(EXT)SUFF)\
605 $(SUFF_LIB))
606else
607suff := $(firstword \
608 $($(target)_$(EXT)SUFF) \
609 $($(target)_$(EXT)SUFF) \
610 $(TOOL_$(tool)_$(tool_prefix)$(EXT)SUFF) \
611 $($(EXTPRE)SUFF_$(EXT)))
612endif
613out := $(outbase)$(suff)
614
615# TARGET_*
616TARGET_$(target) := $(out)
617
618# INSTARGET_*
619ifndef $(target)_NOINST
620INSTARGET_$(target) := $(patsubst %/,%/$(notdir $(out)), \
621 $(if $($(target)_INST), $(addprefix $(PATH_INS)/,$($(target)_INST)), $(definst)/))
622
623else # NOINST
624INSTARGET_$(target) :=
625endif # NOINST
626
627endef
628
629
630#
631# BLDPROGS (Pass 1)
632#
633define def_pass1_bldprog
634# set NOINST if not forced installation before doing the usual stuff.
635ifndef $(target)_INST
636$(target)_NOINST := 1
637endif
638$(eval $(value def_pass1_link_common))
639endef
640
641EXT := EXE
642EXTPRE := HOST
643definst := $(PATH_BIN)
644tool_prefix := LD
645bld_trg_base_var := PLATFORM
646$(foreach target, $(BLDPROGS) $(BLDPROGS.$(BUILD_PLATFORM)) $(BLDPROGS.$(BUILD_PLATFORM).$(BUILD_PLATFORM_ARCH)), \
647 $(eval $(value def_pass1_bldprog)))
648
649
650#
651# LIBRARIES (Pass 1)
652#
653EXT := LIB
654EXTPRE :=
655definst := $(PATH_LIB)
656tool_prefix := AR
657bld_trg_base_var := TARGET
658$(foreach target, $(LIBRARIES) $(LIBRARIES.$(BUILD_TARGET)) $(LIBRARIES.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)), \
659 $(eval $(value def_pass1_link_common)))
660
661
662#
663# DLLS (Pass 1)
664#
665EXT := DLL
666EXTPRE :=
667definst := $(PATH_DLL)
668tool_prefix := LD
669bld_trg_base_var := TARGET
670$(foreach target, $(DLLS) $(DLLS.$(BUILD_TARGET)) $(DLLS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)), \
671 $(eval $(value def_pass1_link_common)))
672
673
674#
675# IMPORT LIBRARIES (Pass 1)
676#
677# - On OS/2 and windows these are libraries.
678# - On other platforms they are fake DLLs.
679#
680ifeq ($(filter-out nt os2 win win64 win32,$(BUILD_TARGET)),)
681 EXT := LIB
682 EXTPRE :=
683 definst := $(PATH_LIB)
684 tool_prefix := AR
685 bld_trg_base_var := TARGET
686 $(foreach target, $(IMPORT_LIBS) $(IMPORT_LIBS.$(BUILD_TARGET)) $(IMPORT_LIBS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)), \
687 $(eval $(value def_pass1_lib)))
688else
689 EXT := DLL
690 EXTPRE :=
691 definst := $(PATH_DLL)
692 tool_prefix := LD
693 bld_trg_base_var := TARGET
694 $(foreach target, $(IMPORT_LIBS) $(IMPORT_LIBS.$(BUILD_TARGET)) $(IMPORT_LIBS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)), \
695 $(eval $(value def_pass1_link_common)))
696endif
697
698
699#
700# PROGRAMS (Pass 1)
701#
702EXT := EXE
703EXTPRE :=
704definst := $(PATH_BIN)
705tool_prefix := LD
706bld_trg_base_var := TARGET
707$(foreach target, $(PROGRAMS) $(PROGRAMS.$(BUILD_TARGET)) $(PROGRAMS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)), \
708 $(eval $(value def_pass1_link_common)))
709
710
711#
712# SYSMODS (Pass 1)
713#
714EXT := SYS
715EXTPRE :=
716definst := $(PATH_SYS)
717tool_prefix := LD
718bld_trg_base_var := TARGET
719$(foreach target, $(SYSMODS) $(SYSMODS.$(BUILD_TARGET)) $(SYSMODS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)), \
720 $(eval $(value def_pass1_link_common)))
721
722
723#
724# INSTALLS (Pass 1)
725# Note! INSTARGET_* for INSTALLS aren't available until later.
726#
727define def_pass1_install
728bld_type := $(firstword $($(target)_BLD_TYPE) $(BUILD_TYPE))
729bld_trg := $(firstword $($(target)_BLD_TRG) $(BUILD_TARGET))
730bld_trg_arch:= $(firstword $($(target)_BLD_TRG_ARCH) $(BUILD_TARGET_ARCH))
731bld_trg_cpu := $(firstword $($(target)_BLD_TRG_CPU) $(BUILD_TARGET_CPU))
732# TARGET_*
733TARGET_$(target) := $(PATH_TARGET)/$(target).ins
734# INSTARGET_ later.
735endef
736$(foreach target, $(INSTALLS) $(INSTALLS.$(BUILD_TARGET)) $(INSTALLS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)), \
737 $(eval $(value def_pass1_install)))
738
739
740
741
742#
743#
744# Target lists - Pass 2
745#
746#
747
748
749## @page pg_fetches Fetching Tools, Sources and Similar.
750#
751# The targets listed in the the FETCHES target list have the following attributes:
752# SOURCES
753# INST
754# FETCHTOOL
755# FETCHFLAGS
756# FETCHDIR
757# UNPACKTOOL
758# UNPACKFLAGS
759#
760# As usual the target name is an alias for 'creating' the target. Other
761# aliases are:
762# pass_fetches
763# fetch
764# unfetch
765# download
766# unpack
767#
768# @remark
769#
770# This is a little bit complex because we must guarantee that if a source file
771# changes only sligtly we must refetch it and to a proper unpacking of it. It
772# is also a desire that fetched archives and unpacked files can be deleted to
773# save space.
774#
775# Thus, we must be able to cleanup what we've unpacked should any of the
776# sources be removed. We do this by maintaining a file listing the files
777# and directories that was unpacked. This operation is named 'unfetch'.
778#
779# We make use of the SIZE and MD5 attributes for each of the sources to
780# create a digest that is stored in the primary target file. Subsequent
781# runswill compare their digest with it to decide if a refetch is required.
782# When a refetch is found necessary, an 'unfetch' is performed first to
783# clean out old files and directores. Note even changes in source order
784# will cause a refetch due to the way the digest is constructed and
785# evaluated.
786#
787# By not depending directly on the archives (nor on any unpacked files)
788# but on a goal made up from the archive name, size and md5, we allow
789# the user to delete the archives. Naturally, this means we'll have to
790# check and fetch missing archives before attempting to unpack them.
791#
792# @remark
793#
794# This feature will *NOT* work correctly with vanilla GNU make becuase
795# it makes use of includedep to avoid too many unnecessary files.
796#
797# @todo
798# 1. Port md5sum or some equivalent tool and include it in kBuild.
799# 2. Download corruption / continuation.
800# 3. It's quite possible that there is one too many indirect dependency now...
801#
802
803## @todo move this!
804MD5SUM := md5sum
805
806## generates the fetch rule
807define def_fetch_src_fetch_rule
808# Indirect goal for downloading something.
809.PRECIOUS: $(out)
810$(out) $($(target)_$(srcname)_FETCH_OUTPUT_): | $($(target)_$(srcname)_FETCH_DEPORD_)
811 $$(call MSG_FETCH_DL,$(target),$(source),$(out))
812 @## @todo do fancy stuff like download continuation.
813 $$(QUIET)$$(RM) -f $(out) $(out).md5
814 $($(target)_$(srcname)_FETCH_CMDS_)
815 $$(QUIET2)$(if $(md5),$$(APPEND) $(out).md5 "$(md5) *$(out)")
816 $$(QUIET)$(if $(md5),$$(MD5SUM) -c $(out).md5)
817
818
819
820# Intermediate goal for making sure the md5 and size matches. it will (re) fetch the archive if necessary.
821$(out).checked_$(md5)_$(size): $($(target)_$(srcname)_FETCH_DEPEND_) | $($(target)_$(srcname)_FETCH_DEPORD_)
822 $$(call MSG_FETCH_CHK,$(target),$(source),$(out))
823 $$(QUIET)$$(RM) -f $$@ $(out).md5
824 @# creates the .md5 we pass to md5sum.
825 $$(QUIET2)$(if $(md5),$$(APPEND) $(out).md5 "$(md5) *$(out)")
826 @# (re)fetch the file if it doesn't exist or if it doesn't matches the md5.
827 @## @todo do fancy stuff like download continuation.
828 $$(QUIET)( test -f $(out) && $(if $(md5),$$(MD5SUM) -c $(out).md5, true) ) \
829 || ( $$(RM_EXT) -f $(out) \
830 && $$(MAKE) $(out) -f $(MAKEFILE) --no-print-directory )
831 $$(QUIET2)$$(APPEND) $$@
832
833_TARGET_$(target)_FETCHED += $(out) $(out).checked_$(md5)_$(size)
834
835# Just a little precaution.
836.NOTPARALLEL: $(out) $(out).checked_$(md5)_$(size)
837
838endef
839
840## generates the unpack rule
841define def_fetch_src_unpack_rule
842# This is the unpack rule. it has an order-only dependency on the download check.
843$(out) $($(target)_$(srcname)_UNPACK_OUTPUT_): $($(target)_$(srcname)_UNPACK_DEPEND_) \
844 | $($(target)_$(srcname)_UNPACK_DEPORD_) $(archive).checked_$(md5)_$(size)
845 $$(call MSG_FETCH_UP,$(target),$(archive),$(inst))
846 $$(QUIET)$$(RM) -f $(out)
847 @# if the source archive doesn't exist fetch it (can have been deleted to save space).
848 $$(QUIET)test -f $(archive) \
849 || ( $$(RM_EXT) -f $(archive).checked_$(md5)_$(size) \
850 && $$(MAKE) $(archive).checked_$(md5)_$(size) -f $(MAKEFILE) --no-print-directory )
851 $($(target)_$(srcname)_UNPACK_CMDS_)
852 $$(QUIET2)$$(APPEND) $(out) $(notdir $(archive).checked_$(md5)_$(size))
853 $$(QUIET2)$$(APPEND) $(out) $(notdir $(out))
854
855$(eval _TARGET_$(target)_UNPACKED += $(out))
856_TARGET_$(target)_DIGEST := $(_TARGET_$(target)_DIGEST)-$(srcname)_$(md5)_$(size)
857
858.NOTPARALLEL: $(out)
859
860endef
861
862## Processes a fetch source
863#
864define def_fetch_src
865#$ (warning dbg: def_fetch_src: source='$(source)' target='$(target)')
866
867# common
868srcname := $(notdir $(source))
869inst := $(firstword \
870 $($(target)_$(source)_INST)\
871 $($(target)_$(srcname)_INST)\
872 $($(source)_INST)\
873 $($(srcname)_INST)\
874 $($(target)_INST)\
875)
876ifneq ($(patsubst %/,ok,$(inst)),ok)
877$(error kBuild: Bad or missing INST property for source '$(source)' in target '$(target)': $(inst))
878endif
879INSTARGET_$(target)_$(srcname) := $(inst)
880fetchdir := $(firstword \
881 $($(target)_$(source)_FETCHDIR)\
882 $($(target)_$(srcname)_FETCHDIR)\
883 $($(source)_FETCHDIR)\
884 $($(srcname)_FETCHDIR)\
885 $($(target)_FETCHDIR)\
886 $(FETCHDIR)\
887 $(PATH_TARGET)\
888)
889deps := \
890 $($(target)_$(source)_DEPS)\
891 $($(target)_$(srcname)_DEPS)\
892 $($(source)_DEPS)\
893 $($(srcname)_DEPS)\
894 $($(target)_DEPS)
895orderdeps := \
896 $($(target)_$(source)_ORDERDEPS)\
897 $($(target)_$(srcname)_ORDERDEPS)\
898 $($(source)_ORDERDEPS)\
899 $($(srcname)_ORDERDEPS)\
900 $($(target)_ORDERDEPS)
901md5 := $(firstword \
902 $($(target)_$(source)_MD5)\
903 $($(target)_$(srcname)_MD5)\
904 $($(source)_MD5)\
905 $($(srcname)_MD5)\
906 $($(target)_MD5)\
907)
908size := $(firstword \
909 $($(target)_$(source)_SIZE)\
910 $($(target)_$(srcname)_SIZE)\
911 $($(source)_SIZE)\
912 $($(srcname)_SIZE)\
913 $($(target)_SIZE)\
914)
915dep := # not legal for fetch and unpack tools
916
917
918#
919# The fetching.
920#
921out := $(fetchdir)/$(srcname)
922archive := $(out)
923TARGET_$(target)_$(srcname) := $(out)
924dirdep := $(call DIRDEP,$(fetchdir))
925tool := $(firstword \
926 $($(target)_$(source)_FETCHTOOL)\
927 $($(target)_$(srcname)_FETCHTOOL)\
928 $($(target)_$(source)_TOOL)\
929 $($(target)_$(srcname)_TOOL)\
930 $($(source)_FETCHTOOL)\
931 $($(srcname)_FETCHTOOL)\
932 $($(source)_TOOL)\
933 $($(srcname)_TOOL)\
934 $($(target)_FETCHTOOL)\
935 $($(target)_TOOL)\
936 )
937flags :=\
938 $(TOOL_$(tool)_FETCHFLAGS)\
939 $(FETCHFLAGS)\
940 $($(target)_FETCHFLAGS)\
941 $($(srcname)_FETCHFLAGS)\
942 $($(source)_FETCHFLAGS)\
943 $($(target)_$(srcname)_FETCHFLAGS)\
944 $($(target)_$(source)_FETCHFLAGS)
945
946#$ (warning dbg: target=$(target) source=$(source) $(srcname)=$(srcname) tool=$(tool) out=$(out) flags=$(flags) dirdep=$(dirdep) fetchdir=$(fetchdir) md5=$(md5) size=$(size))
947
948ifndef TOOL_$(tool)_FETCH_CMDS
949$(warning kBuild: tools: \
950 1 $($(target)_$(source)_FETCHTOOL)\
951 2 $($(target)_$(srcname)_FETCHTOOL)\
952 3 $($(target)_$(source)_TOOL)\
953 4 $($(target)_$(srcname)_TOOL)\
954 5 $($(source)_FETCHTOOL)\
955 6 $($(srcname)_FETCHTOOL)\
956 7 $($(source)_TOOL)\
957 8 $($(srcname)_TOOL)\
958 9 $($(target)_FETCHTOOL)\
959 10 $($(target)_TOOL) )
960$(error kBuild: TOOL_$(tool)_FETCH_CMDS is not defined. source=$(source) target=$(target) )
961endif
962
963# call the tool
964$(target)_$(srcname)_FETCH_CMDS_ := $(TOOL_$(tool)_FETCH_CMDS)
965$(target)_$(srcname)_FETCH_OUTPUT_ := $(TOOL_$(tool)_FETCH_OUTPUT)
966$(target)_$(srcname)_FETCH_DEPEND_ := $(TOOL_$(tool)_FETCH_DEPEND) $(deps)
967$(target)_$(srcname)_FETCH_DEPORD_ := $(TOOL_$(tool)_FETCH_DEPORD) $(dirdep) $(orderdeps)
968
969# generate the fetch rule.
970$(eval $(def_fetch_src_fetch_rule))
971
972
973#
974# The unpacking / installing.
975#
976out := $(inst)_kBuild_$(target)_$(srcname)_unpacked.lst
977dirdep := $(call DIRDEP,$(inst))
978tool := $(firstword \
979 $($(target)_$(source)_UNPACKTOOL)\
980 $($(target)_$(srcname)_UNPACKTOOL)\
981 $($(target)_$(source)_TOOL)\
982 $($(target)_$(srcname)_TOOL)\
983 $($(source)_UNPACKTOOL)\
984 $($(srcname)_UNPACKTOOL)\
985 $($(source)_TOOL)\
986 $($(srcname)_TOOL)\
987 $($(target)_UNPACKTOOL)\
988 $($(target)_TOOL) \
989 )
990ifeq ($(tool),)
991tool := $(toupper $(subst .,,$(suffix $(subst tar.,TAR,$(srcname)))))
992$(eval $(value def_tools_include))
993endif
994flags :=\
995 $(TOOL_$(tool)_UNPACKFLAGS)\
996 $(UNPACKFLAGS)\
997 $($(target)_UNPACKFLAGS)\
998 $($(srcname)_UNPACKFLAGS)\
999 $($(source)_UNPACKFLAGS)\
1000 $($(target)_$(srcname)_UNPACKFLAGS)\
1001 $($(target)_$(source)_UNPACKFLAGS)
1002
1003#$ (warning dbg: target=$(target) source=$(source) $(srcname)=$(srcname) tool=$(tool) out=$(out) flags=$(flags) dirdep=$(dirdep) inst=$(inst) md5=$(md5) size=$(size))
1004ifndef TOOL_$(tool)_UNPACK_CMDS
1005$(warning kBuild: tools: \
1006 1 $($(target)_$(source)_UNPACKTOOL)\
1007 2 $($(target)_$(srcname)_UNPACKTOOL)\
1008 3 $($(target)_$(source)_TOOL)\
1009 4 $($(target)_$(srcname)_TOOL)\
1010 5 $($(source)_UNPACKTOOL)\
1011 6 $($(srcname)_UNPACKTOOL)\
1012 7 $($(source)_TOOL)\
1013 8 $($(srcname)_TOOL)\
1014 9 $($(target)_UNPACKTOOL)\
1015 10 $($(target)_TOOL) \
1016 11 $(toupper $(subst tar.,TAR,$(ext $(srcname)))) \
1017 )
1018$(error kBuild: TOOL_$(tool)_UNPACK_CMDS is not defined. source=$(source) target=$(target) )
1019endif
1020
1021# call the tool
1022$(target)_$(srcname)_UNPACK_CMDS_ := $(TOOL_$(tool)_UNPACK_CMDS)
1023$(target)_$(srcname)_UNPACK_OUTPUT_ := $(TOOL_$(tool)_UNPACK_OUTPUT)
1024$(target)_$(srcname)_UNPACK_DEPEND_ := $(TOOL_$(tool)_UNPACK_DEPEND) $(deps)
1025$(target)_$(srcname)_UNPACK_DEPORD_ := $(TOOL_$(tool)_UNPACK_DEPORD) $(dirdep) $(orderdeps)
1026
1027# generate the fetch rule.
1028$(eval $(def_fetch_src_unpack_rule))
1029
1030_DIRS += $(inst) $(fetchdir)
1031
1032endef
1033
1034
1035##
1036# Define the target level rules for a fetch.
1037# @param target
1038# @param out
1039# @param inst
1040# @param _TARGET_$(target)_UNPACKED
1041# @param _TARGET_$(target)_DIGEST
1042# @param bld_trg
1043# @param bld_trg_arch
1044define def_fetch_rules
1045
1046$(out).lst: $(_TARGET_$(target)_UNPACKED) | $(call DIRDEP,$(inst))
1047 $$(call MSG_FETCH_OK,$(target))
1048 $$(QUIET)$$(RM) -f $$@ $$@.tmp
1049 $$(QUIET2)$$(APPEND) $$@.tmp "$(notdir $(out))"
1050 $$(QUIET)$(if $(_TARGET_$(target)_UNPACKED),$$(CAT_EXT) $(_TARGET_$(target)_UNPACKED) >> $$@.tmp)
1051 $$(QUIET)$$(MV) -f $$@.tmp $$@
1052
1053$(out)_unfetched:
1054 $$(call MSG_UNFETCH,$(target))
1055 $$(QUIET)$$(RM) -f $$(addprefix $(inst),$$(shell $$(CAT_EXT) $(out).lst 2> /dev/null | $$(SED) -e '/\/$$$$/d'))
1056 $$(QUIET)$$(RMDIR) -p --ignore-fail-on-non-empty --ignore-fail-on-not-exist $$(dir $$@) \
1057 $$(addprefix $(inst),$$(sort $$(dir $$(shell $$(CAT_EXT) $(out).lst 2> /dev/null))))
1058 $$(QUIET)$$(RM) -f $(out).lst $(out)
1059 $$(QUIET)$$(RMDIR) -p --ignore-fail-on-non-empty --ignore-fail-on-not-exist $$(dir $$@)
1060
1061$(out): $(comp-vars _TARGET_$(target)_DIGEST_PREV,_TARGET_$(target)_DIGEST,FORCE) | $(call DIRDEP,$(inst))
1062 $$(QUIET)$$(RM) -f $$@
1063 $$(if $$(_TARGET_$(target)_DIGEST),$$(if $$(wildcard $(out).lst)\
1064 ,$$(call MSG_REFETCH,$(target)),$$(call MSG_FETCH,$(target))),$$(call MSG_UNFETCH,$(target)))
1065 $$(QUIET)$$(if $$(wildcard $(out).lst ),$$(MAKE) -f $(MAKEFILE) --no-print-directory $(out)_unfetched)
1066 $$(QUIET)$$(if $$(_TARGET_$(target)_DIGEST),$$(MAKE) -f $(MAKEFILE) --no-print-directory $(out).lst,$$(RMDIR) -p --ignore-fail-on-non-empty --ignore-fail-on-not-exist $$(dir $$@))
1067 $$(QUIET2)$$(if $$(_TARGET_$(target)_DIGEST),$$(APPEND) $$@ "_TARGET_$(target)_DIGEST_PREV := $(_TARGET_$(target)_DIGEST)")
1068
1069.NOTPARALLEL: $(out).lst $(out)_unfetched $(out)
1070
1071endef
1072
1073
1074##
1075# Deal with one fetch target.
1076# @param target
1077# @param bld_trg
1078# @param bld_trg_arch
1079define def_fetch
1080# common
1081INSTARGET_$(target) := $($(target)_INST)
1082ifneq ($(patsubst %/,ok,$(INSTARGET_$(target))),ok)
1083$(error kBuild: Bad or missing INST property for target '$(target)'. \
1084 $(target)_INST='$($(target)_INST)' ($(origin $(target)_INST)))
1085endif
1086_TARGET_$(target)_FETCHED :=
1087_TARGET_$(target)_UNPACKED :=
1088_TARGET_$(target)_DIGEST :=
1089
1090# The 'sources'.
1091#$ (warning dbg fetch: target=$(target) sources=$($(target)_SOURCES) $($(target)_SOURCES.$(BUILD_TYPE)) $($(target)_SOURCES.$(BUILD_TARGET)) $($(target)_SOURCES.$(BUILD_TARGET_ARCH)) $($(target)_SOURCES.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)))
1092$(foreach source,$($(target)_SOURCES) $($(target)_SOURCES.$(BUILD_TYPE)) $($(target)_SOURCES.$(BUILD_TARGET)) $($(target)_SOURCES.$(BUILD_TARGET_ARCH)) $($(target)_SOURCES.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)),\
1093 $(eval $(value def_fetch_src)))
1094
1095# The target.
1096inst := $(INSTARGET_$(target))
1097out := $(inst)_kBuild_fetch_$(target)
1098
1099$(eval includedep $(out))
1100
1101$(eval $(def_fetch_rules))
1102
1103# Define the aliases here (doesn't work if defined in def_fetch_rules, just like includedep).
1104$(target): $(out)
1105$(target)_unfetch: $(out)_unfetched
1106
1107_FETCHES += $(out)
1108_DOWNLOADS += $(_TARGET_$(target)_FETCHED)
1109_UNPACKS += $(_TARGET_$(target)_UNPACKED)
1110_UNFETCHES += $(out)_unfetched
1111_DIRS += $(inst)
1112
1113endef
1114
1115# Walk the FETCH target lists.
1116bld_trg := $(BUILD_TARGET)
1117bld_trg_arch := $(BUILD_TARGET_ARCH)
1118$(foreach target, $(FETCHES) $(FETCHES.$(BUILD_TARGET)) $(FETCHES.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)), \
1119 $(eval $(value def_fetch)))
1120
1121# some aliases.
1122download: $(_DOWNLOADS)
1123unpack: $(_UNPACKS)
1124fetch: $(_FETCHES)
1125unfetch: $(_UNFETCHES)
1126
1127
1128
1129##
1130## Patching.
1131##
1132##
1133#define def_patch_src
1134#
1135#endef
1136#
1137#
1138## Deal with one patch target.
1139#define def_patch
1140#
1141#$(foreach source,$($(target)_SOURCES) $($(target)_SOURCES.$(BUILD_TYPE)) $($(target)_SOURCES.$(BUILD_TARGET)) $($(target)_SOURCES.$(BUILD_TARGET_ARCH)) $($(target)_SOURCES.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)),\
1142# $(eval $(value def_patch_src)))
1143#
1144#_PATCHES +=
1145#endef
1146#
1147#$(foreach target, $(PATCHES) $(PATCHES.$(BUILD_TARGET)) $(PATCHES.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)), \
1148# $(eval $(value def_patch)))
1149#
1150
1151
1152#
1153# Object processing.
1154#
1155
1156## wrapper the compile command dependency check.
1157ifndef NO_COMPILE_CMDS_DEPS
1158 _DEP_COMPILE_CMDS = $(comp-cmds $(target)_$(source)_CMDS_PREV_,$(target)_$(source)_CMDS_,FORCE)
1159else
1160 _DEP_COMPILE_CMDS =
1161endif
1162
1163## Generates the rules for building a specific object, and the aliases
1164# for building a source file.
1165# @param $(obj) The object file.
1166define def_target_source_rule
1167$(obj) $($(target)_$(source)_OUTPUT_): \
1168 $($(target)_$(source)_DEPEND_) \
1169 $(_DEP_COMPILE_CMDS) \
1170 | \
1171 $($(target)_$(source)_DEPORD_)
1172 $$(call MSG_COMPILE,$(target),$(source),$$@,$(type))
1173 $$(QUIET)$$(RM) -f $(dep) $(obj) $($(target)_$(source)_OUTPUT_)
1174
1175$($(target)_$(source)_CMDS_)
1176
1177ifndef NO_COMPILE_CMDS_DEPS
1178 $$(QUIET2)$$(APPEND) "$(dep)"
1179 $$(QUIET2)$$(APPEND) "$(dep)" 'define $(target)_$(source)_CMDS_PREV_'
1180ifeq ($(filter append-dash-n,$(KMK_FEATURES)),append-dash-n)
1181 $$(QUIET2)$$(APPEND) -v "$(dep)" '$(target)_$(source)_CMDS_'
1182else
1183 $$(QUIET2)$$(APPEND) "$(dep)" '$(subst $(NL),'$(NL)$(TAB)@$(APPEND) "$(dep)" ',$($(target)_$(source)_CMDS_))'
1184endif
1185 $$(QUIET2)$$(APPEND) "$(dep)" 'endef'
1186endif
1187
1188$(basename $(notdir $(obj))).o: $(obj)
1189$(basename $(notdir $(obj))).obj: $(obj)
1190endef
1191
1192
1193## wrapper the link command dependency check.
1194ifndef NO_COMPILE_CMDS_DEPS
1195 _DEP_LINK_CMDS = $(comp-cmds $(target)_CMDS_PREV_,$(target)_CMDS_,FORCE)
1196else
1197 _DEP_LINK_CMDS =
1198endif
1199
1200## Generate the link rule for a target.
1201# @param $(target) The normalized target name.
1202# @param $(dirdep) Directories we depend upon begin created before linking.
1203# @param $(dep) The name of the dependency file.
1204# @param $(out)
1205# @param $($(target)_OUTPUT_) Output files from the link.
1206# @param $($(target)_DEPEND_) Dependencies.
1207# @param $($(target)_DEPORD_) Dependencies which should only affect build order.
1208# @param $($(target)_CMDS_) The link commands.
1209# @param $($(target)_CMDS_PREV_) The link commands from the previous run.
1210define def_link_rule
1211$(out) $($(target)_OUTPUT_): \
1212 $($(target)_DEPEND_) \
1213 $(_DEP_LINK_CMDS) \
1214 | \
1215 $($(target)_DEPORD_)
1216 $$(call MSG_LINK,$(target),$$@,$(tool_do))
1217 $$(QUIET)$$(RM) -f $(dep) $(out) $($(target)_OUTPUT_)
1218
1219$($(target)_CMDS_)
1220
1221ifndef NO_LINK_CMDS_DEPS
1222 $$(QUIET2)$$(APPEND) "$(dep)" 'define $(target)_CMDS_PREV_'
1223ifeq ($(filter append-dash-n,$(KMK_FEATURES)),append-dash-n)
1224 $$(QUIET2)$$(APPEND) -v "$(dep)" '$(target)_CMDS_'
1225else
1226 $$(QUIET2)$$(APPEND) "$(dep)" '$(subst $(NL),'$(NL)$(TAB)@$(APPEND) "$(dep)" ',$($(target)_CMDS_))'
1227endif
1228 $$(QUIET2)$$(APPEND) "$(dep)" 'endef'
1229endif
1230
1231$(basename $(notdir $(out))): $(out)
1232
1233endef
1234
1235
1236## Generate the link & lib install rule
1237# @param $(target) Normalized target name.
1238# @param $(out) The build target.
1239# @param $(INSTARGET_$(target)) The installation targets.
1240# @param $(mode) The file mode (optional)
1241define def_link_install_rule
1242$(INSTARGET_$(target)) : $(out) | $(call DIRDEP,$(dir $(INSTARGET_$(target))))
1243 $$(call MSG_INST_TRG,$(target),$(out),$$@)
1244 $$(QUIET)$$(INSTALL) $$(if $(mode),-m $(mode)) $(out) $$@
1245
1246ifdef KBUILD_DO_AUTO_INSTALL
1247$(basename $(notdir $(out))): $(INSTARGET_$(target))
1248endif
1249endef
1250
1251
1252## Generic macro for processing C, C++ and Assembly sources.
1253# @param $(target) Normalized target name.
1254# @param $(source) Source file name.
1255# @param $(type) Source type. {C,CXX,AS}
1256# @param bld_type Build type.
1257# @param bld_trg Build target.
1258# @param bld_trg_arch Build target arch.
1259# @param bld_trg_cpu Build target cpu.
1260def_target_source_c_cpp_asm_rc_new = $(kb-src-one )
1261ifdef KMK_VERSION
1262 def_target_source_c_cpp_asm_rc_var = def_target_source_c_cpp_asm_rc_new
1263else
1264 def_target_source_c_cpp_asm_rc_var = def_target_source_c_cpp_asm_rc_old
1265endif
1266
1267## Generic macro for processing all target sources.
1268# @param $(target) Normalized target name.
1269# @param $(defpath)
1270# @param much-more...
1271define def_target_sources
1272#$ (warning def_target_sources)
1273# C sources
1274type := C
1275$(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)))\
1276 ,$(eval $(value $(def_target_source_c_cpp_asm_rc_var))) )
1277
1278# C++ sources
1279type := CXX
1280$(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)))\
1281 ,$(eval $(value $(def_target_source_c_cpp_asm_rc_var))) )
1282
1283# ASM sources
1284type := AS
1285$(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)))\
1286 ,$(eval $(value $(def_target_source_c_cpp_asm_rc_var))) )
1287
1288# Resource sources
1289type := RC
1290$(foreach source, $(filter %.rc , $($(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)))\
1291 ,$(eval $(value $(def_target_source_c_cpp_asm_rc_var))) )
1292
1293endef
1294
1295
1296
1297## Generic macro for generating the install rule(s) for a target
1298# and update the globals with default out.
1299#
1300# @param $(target) Normalized target name.
1301# @param $(out) The output file.
1302# @param $(definst) The default _INST value.
1303# @param $(typevar) The name of the variable with all the root targets of its type.
1304# @remark Only library uses this now.
1305define def_target_install_pluss
1306ifndef $(target)_NOINST
1307INSTARGET_$(target) := $(patsubst %/,%/$(notdir $(out)), \
1308 $(if $($(target)_INST), $(addprefix $(PATH_INS)/,$($(target)_INST)), $(definst)/))
1309
1310$(eval $(def_link_install_rule))
1311
1312_INSTALLS_FILES += $(INSTARGET_$(target))
1313
1314ifdef KBUILD_DO_AUTO_INSTALL
1315$(typevar) += $(INSTARGET_$(target))
1316else
1317$(typevar) += $(out)
1318endif
1319else # _NOINST
1320$(typevar) += $(out)
1321endif
1322
1323_OUT_FILES += $($(target)_OUTPUT_) $(out)
1324_CLEAN_FILES += $($(target)_CLEAN)
1325_OBJS += $($(target)_OBJS_)
1326
1327endef
1328
1329
1330
1331#
1332# LIBRARIES
1333#
1334
1335## Library (one).
1336# @param $(target) Normalized library (target) name.
1337define def_lib
1338# library basics
1339## @todo prefix
1340bld_type := $(firstword $($(target)_BLD_TYPE) $(BUILD_TYPE))
1341bld_trg := $(firstword $($(target)_BLD_TRG) $(BUILD_TARGET))
1342bld_trg_arch:= $(firstword $($(target)_BLD_TRG_ARCH) $(BUILD_TARGET_ARCH))
1343bld_trg_cpu := $(firstword $($(target)_BLD_TRG_CPU) $(BUILD_TARGET_CPU))
1344tool := $(call _TARGET_TOOL,$(target),AR)
1345ifeq ($(tool),)
1346$(error kBuild: Library target $(target) does not have a tool defined!)
1347endif
1348name := $(firstword\
1349 $($(target)_NAME.$(bld_trg).$(bld_trg_arch))\
1350 $($(target)_NAME.$(bld_trg_arch))\
1351 $($(target)_NAME.$(bld_trg))\
1352 $($(target)_NAME.$(bld_type))\
1353 $($(target)_NAME)\
1354 $(target))
1355outbase := $(call TARGET_BASE,$(name),$(target))
1356ifndef PATH_$(target)
1357 PATH_$(target) := $(patsubst %/,%,$(dir $(outbase)))
1358else
1359 ifneq ($(PATH_$(target)),$(patsubst %/,%,$(dir $(outbase))))
1360 $(error kBuild internal error: PATH_$(target)=$(PATH_$(target)) expected $(patsubst %/,%,$(dir $(outbase))))
1361 endif
1362endif
1363suff := $(firstword\
1364 $($(target)_LIBSUFF.$(bld_trg).$(bld_trg_arch))\
1365 $($(target)_LIBSUFF.$(bld_trg))\
1366 $($(target)_LIBSUFF)\
1367 $(TOOL_$(tool)_ARLIBSUFF.$(bld_trg).$(bld_trg_arch))\
1368 $(TOOL_$(tool)_ARLIBSUFF.$(bld_trg))\
1369 $(TOOL_$(tool)_ARLIBSUFF)\
1370 $(SUFF_LIB))
1371out := $(outbase)$(suff)
1372TARGET_$(target) := $(out)
1373$(target)_OBJS_ :=
1374defpath := $($(target)_PATH)
1375
1376# source -> object
1377$(eval $(value def_target_sources))
1378
1379# library linking
1380tool := $(call _TARGET_TOOL,$(target),AR)
1381name := $(firstword\
1382 $($(target)_NAME.$(bld_trg).$(bld_trg_arch))\
1383 $($(target)_NAME.$(bld_trg_arch))\
1384 $($(target)_NAME.$(bld_trg))\
1385 $($(target)_NAME.$(bld_type))\
1386 $($(target)_NAME)\
1387 $(target))
1388outbase := $(call TARGET_BASE,$(name),$(target))
1389flags :=\
1390 $(TOOL_$(tool)_ARFLAGS)\
1391 $(TOOL_$(tool)_ARFLAGS.$(bld_type))\
1392 $(ARFLAGS)\
1393 $(ARFLAGS.$(bld_type))\
1394 $($(target)_ARFLAGS)\
1395 $($(target)_ARFLAGS.$(bld_type)) \
1396 $($(target)_ARFLAGS.$(bld_trg)) \
1397 $($(target)_ARFLAGS.$(bld_trg_arch)) \
1398 $($(target)_ARFLAGS.$(bld_trg).$(bld_trg_arch)) \
1399 $($(target)_ARFLAGS.$(bld_trg_cpu))
1400othersrc := $(filter-out %.c %.cpp %.cxx %.cc %.s %.S %.asm %.o %.obj,\
1401 $($(target)_SOURCES) \
1402 $($(target)_SOURCES.$(bld_trg)) \
1403 $($(target)_SOURCES.$(bld_trg_arch)) \
1404 $($(target)_SOURCES.$(bld_trg).$(bld_trg_arch)) \
1405 $($(target)_SOURCES.$(bld_trg_cpu)) \
1406 $($(target)_SOURCES.$(bld_type)))
1407objs = $(filter %.o %.obj, \
1408 $($(target)_SOURCES) \
1409 $($(target)_SOURCES.$(bld_trg)) \
1410 $($(target)_SOURCES.$(bld_trg_arch)) \
1411 $($(target)_SOURCES.$(bld_trg).$(bld_trg_arch)) \
1412 $($(target)_SOURCES.$(bld_trg_cpu)) \
1413 $($(target)_SOURCES.$(bld_type))) \
1414 $($(target)_OBJS_)
1415dirdep := $(call DIRDEP,$(dir $(out)))
1416deps := $($(target)_DEPS)
1417orderdeps := $($(target)_ORDERDEPS)
1418
1419# Adjust paths if we got a default path.
1420ifneq ($(defpath),)
1421 objs := $(call abspathex,$(objs),$(defpath))
1422 deps := $(call abspathex,$(deps),$(defpath))
1423 orderdeps := $(call abspathex,$(orderdeps),$(defpath))
1424 othersrc := $(call abspathex,$(othersrc),$(defpath))
1425endif
1426
1427
1428# Custom pre-link actions.
1429ifdef $(target)_PRE_CMDS.$(bld_trg).$(bld_trg_arch).$(bld_type)
1430 pre_cmds := $($(target)_PRE_CMDS.$(bld_trg).$(bld_trg_arch).$(bld_type))
1431else ifdef $(target)_PRE_CMDS.$(bld_trg).$(bld_trg_arch)
1432 pre_cmds := $($(target)_PRE_CMDS.$(bld_trg).$(bld_trg_arch))
1433else ifdef $(target)_PRE_CMDS.$(bld_trg).$(bld_type)
1434 pre_cmds := $($(target)_PRE_CMDS.$(bld_trg).$(bld_type))
1435else ifdef $(target)_PRE_CMDS.$(bld_trg_arch)
1436 pre_cmds := $($(target)_PRE_CMDS.$(bld_trg_arch))
1437else ifdef $(target)_PRE_CMDS.$(bld_trg)
1438 pre_cmds := $($(target)_PRE_CMDS.$(bld_trg))
1439else ifdef $(target)_PRE_CMDS.$(bld_type)
1440 pre_cmds := $($(target)_PRE_CMDS.$(bld_type))
1441else ifdef $(target)_PRE_CMDS
1442 pre_cmds := $($(target)_PRE_CMDS)
1443else ifdef PRE_CMDS.$(bld_trg).$(bld_trg_arch).$(bld_type)
1444 pre_cmds := $(PRE_CMDS.$(bld_trg).$(bld_trg_arch).$(bld_type))
1445else ifdef PRE_CMDS.$(bld_trg).$(bld_trg_arch)
1446 pre_cmds := $(PRE_CMDS.$(bld_trg).$(bld_trg_arch))
1447else ifdef PRE_CMDS.$(bld_trg).$(bld_type)
1448 pre_cmds := $(PRE_CMDS.$(bld_trg).$(bld_type))
1449else ifdef PRE_CMDS.$(bld_trg_arch)
1450 pre_cmds := $(PRE_CMDS.$(bld_trg_arch))
1451else ifdef PRE_CMDS.$(bld_trg)
1452 pre_cmds := $(PRE_CMDS.$(bld_trg))
1453else ifdef PRE_CMDS.$(bld_type)
1454 pre_cmds := $(PRE_CMDS.$(bld_type))
1455else
1456 pre_cmds := $(PRE_CMDS)
1457endif
1458
1459# Custom post-link actions.
1460ifdef $(target)_POST_CMDS.$(bld_trg).$(bld_trg_arch).$(bld_type)
1461 post_cmds := $($(target)_POST_CMDS.$(bld_trg).$(bld_trg_arch).$(bld_type))
1462else ifdef $(target)_POST_CMDS.$(bld_trg).$(bld_trg_arch)
1463 post_cmds := $($(target)_POST_CMDS.$(bld_trg).$(bld_trg_arch))
1464else ifdef $(target)_POST_CMDS.$(bld_trg).$(bld_type)
1465 post_cmds := $($(target)_POST_CMDS.$(bld_trg).$(bld_type))
1466else ifdef $(target)_POST_CMDS.$(bld_trg_arch)
1467 post_cmds := $($(target)_POST_CMDS.$(bld_trg_arch))
1468else ifdef $(target)_POST_CMDS.$(bld_trg)
1469 post_cmds := $($(target)_POST_CMDS.$(bld_trg))
1470else ifdef $(target)_POST_CMDS.$(bld_type)
1471 post_cmds := $($(target)_POST_CMDS.$(bld_type))
1472else ifdef $(target)_POST_CMDS
1473 post_cmds := $($(target)_POST_CMDS)
1474else ifdef POST_CMDS.$(bld_trg).$(bld_trg_arch).$(bld_type)
1475 post_cmds := $(POST_CMDS.$(bld_trg).$(bld_trg_arch).$(bld_type))
1476else ifdef POST_CMDS.$(bld_trg).$(bld_trg_arch)
1477 post_cmds := $(POST_CMDS.$(bld_trg).$(bld_trg_arch))
1478else ifdef POST_CMDS.$(bld_trg).$(bld_type)
1479 post_cmds := $(POST_CMDS.$(bld_trg).$(bld_type))
1480else ifdef POST_CMDS.$(bld_trg_arch)
1481 post_cmds := $(POST_CMDS.$(bld_trg_arch))
1482else ifdef POST_CMDS.$(bld_trg)
1483 post_cmds := $(POST_CMDS.$(bld_trg))
1484else ifdef POST_CMDS.$(bld_type)
1485 post_cmds := $(POST_CMDS.$(bld_type))
1486else
1487 post_cmds := $(POST_CMDS)
1488endif
1489
1490# dependency file
1491dep := $(out)$(SUFF_DEP)
1492ifndef NO_LINK_CMDS_DEPS
1493 _DEPFILES_INCLUDED += $(dep)
1494 $(eval includedep $(dep))
1495endif
1496
1497# check that the tool is defined.
1498ifndef TOOL_$(tool)_LINK_LIBRARY_CMDS
1499$(warning kBuild: tools: \
1500 1 $($(target)_$(source)TOOL.$(bld_trg).$(bld_trg_arch)) \
1501 2 $($(target)_$(source)TOOL.$(bld_trg)) \
1502 3 $($(target)_$(source)TOOL) \
1503 4 $($(target)_TOOL.$(bld_trg).$(bld_trg_arch)) \
1504 5 $($(target)_TOOL.$(bld_trg)) \
1505 6 $($(target)_TOOL) \
1506 7 $($(source)TOOL) \
1507 8 $($(source)TOOL.$(bld_trg).$(bld_trg_arch)) \
1508 9 $($(source)TOOL.$(bld_trg)) \
1509 10 $(TOOL.$(bld_trg).$(bld_trg_arch)) \
1510 11 $(TOOL.$(bld_trg)) \
1511 12 $(TOOL) )
1512$(error kBuild: TOOL_$(tool)_LINK_LIBRARY_CMDS isn't defined! target=$(target) )
1513endif
1514
1515# call the tool
1516$(target)_CMDS_ := $(TOOL_$(tool)_LINK_LIBRARY_CMDS)
1517ifneq ($(pre_cmds),)
1518 $(target)_CMDS_ := $(TAB)$(pre_cmds)$(NL)$(TAB)$($(target)_CMDS_)
1519endif
1520ifneq ($(post_cmds),)
1521 $(target)_CMDS_ := $($(target)_CMDS_)$(NL)$(TAB)$(post_cmds)
1522endif
1523$(target)_OUTPUT_ := $(TOOL_$(tool)_LINK_LIBRARY_OUTPUT)
1524$(target)_DEPEND_ := $(TOOL_$(tool)_LINK_LIBRARY_DEPEND) $(deps) $(objs)
1525$(target)_DEPORD_ := $(TOOL_$(tool)_LINK_LIBRARY_DEPORD) $(dirdep) $(orderdeps)
1526
1527# generate the link rule.
1528$(eval $(def_link_rule))
1529
1530# installing and globals
1531$(eval $(value def_target_install_pluss))
1532endef
1533
1534# Process libraries
1535definst := $(PATH_LIB)
1536typevar := _LIBS
1537tool_do := LINK_LIBRARY
1538mode := 0644
1539$(foreach target, $(LIBRARIES) $(LIBRARIES.$(BUILD_TARGET)) $(LIBRARIES.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)), $(eval $(value def_lib)))
1540
1541
1542#
1543# Link operations.
1544#
1545
1546##
1547# Link prolog
1548#
1549# @param $(target) Normalized target name.
1550# @param $(EXT) EXE,DLL,SYS.
1551# @param $(definst) The default _INST value.
1552# @param $(typevar) The name of the variable with all the root targets of its type.
1553define def_link_common
1554# basics
1555bld_type := $(firstword $($(target)_BLD_TYPE) $(BUILD_TYPE))
1556bld_trg := $(firstword $($(target)_BLD_TRG) $(BUILD_$(bld_trg_base_var)))
1557bld_trg_arch:= $(firstword $($(target)_BLD_TRG_ARCH) $(BUILD_$(bld_trg_base_var)_ARCH))
1558bld_trg_cpu := $(firstword $($(target)_BLD_TRG_CPU) $(BUILD_$(bld_trg_base_var)_CPU))
1559
1560tool := $(call _TARGET_TOOL,$(target),LD)
1561name := $(firstword\
1562 $($(target)_NAME.$(bld_trg).$(bld_trg_arch))\
1563 $($(target)_NAME.$(bld_trg_arch))\
1564 $($(target)_NAME.$(bld_trg))\
1565 $($(target)_NAME.$(bld_type))\
1566 $($(target)_NAME)\
1567 $(target))
1568outbase := $(call TARGET_BASE,$(name),$(target))
1569ifndef PATH_$(target)
1570 PATH_$(target) := $(patsubst %/,%,$(dir $(outbase)))
1571else
1572 ifneq ($(PATH_$(target)),$(patsubst %/,%,$(dir $(outbase))))
1573 $(error kBuild internal error: PATH_$(target)=$(PATH_$(target)) expected $(patsubst %/,%,$(dir $(outbase))))
1574 endif
1575endif
1576suff := $(firstword \
1577 $($(target)_$(EXT)SUFF) \
1578 $($(target)_$(EXT)SUFF) \
1579 $(TOOL_$(tool)_LD$(EXT)SUFF) \
1580 $($(EXTPRE)SUFF_$(EXT)))
1581out := $(outbase)$(suff)
1582TARGET_$(target) := $(out)
1583$(target)_OBJS_ :=
1584defpath := $($(target)_PATH)
1585
1586# source -> object
1587$(eval $(value def_target_sources))
1588
1589# more link stuff.
1590tool := $(call _TARGET_TOOL,$(target),LD)
1591name := $(firstword\
1592 $($(target)_NAME.$(bld_trg).$(bld_trg_arch))\
1593 $($(target)_NAME.$(bld_trg_arch))\
1594 $($(target)_NAME.$(bld_trg))\
1595 $($(target)_NAME.$(bld_type))\
1596 $($(target)_NAME)\
1597 $(target))
1598outbase := $(call TARGET_BASE,$(name),$(target))
1599flags :=\
1600 $(TOOL_$(tool)_LDFLAGS)\
1601 $(TOOL_$(tool)_LDFLAGS.$(bld_type))\
1602 $(TOOL_$(tool)_LDFLAGS.$(bld_trg))\
1603 $(TOOL_$(tool)_LDFLAGS.$(bld_trg_arch))\
1604 $(TOOL_$(tool)_LDFLAGS.$(bld_trg).$(bld_trg_arch))\
1605 $(TOOL_$(tool)_LDFLAGS.$(bld_trg_cpu))\
1606 $(LDFLAGS)\
1607 $(LDFLAGS.$(bld_type))\
1608 $(LDFLAGS.$(bld_trg))\
1609 $(LDFLAGS.$(bld_trg_arch))\
1610 $(LDFLAGS.$(bld_trg).$(bld_trg_arch))\
1611 $(LDFLAGS.$(bld_trg_cpu))\
1612 $($(target)_LDFLAGS)\
1613 $($(target)_LDFLAGS.$(bld_type))\
1614 $($(target)_LDFLAGS.$(bld_trg))\
1615 $($(target)_LDFLAGS.$(bld_trg_arch))\
1616 $($(target)_LDFLAGS.$(bld_trg).$(bld_trg_arch))\
1617 $($(target)_LDFLAGS.$(bld_trg_cpu))
1618othersrc := $(filter-out %.c %.cpp %.cxx %.cc %.s %.S %.asm %.o %.obj,\
1619 $($(target)_SOURCES)\
1620 $($(target)_SOURCES.$(bld_trg)) \
1621 $($(target)_SOURCES.$(bld_trg_arch)) \
1622 $($(target)_SOURCES.$(bld_trg).$(bld_trg_arch)) \
1623 $($(target)_SOURCES.$(bld_trg_cpu)) \
1624 $($(target)_SOURCES.$(bld_type)))
1625objs = $(filter %.o %.obj, \
1626 $($(target)_SOURCES) \
1627 $($(target)_SOURCES.$(bld_trg)) \
1628 $($(target)_SOURCES.$(bld_trg_arch)) \
1629 $($(target)_SOURCES.$(bld_trg).$(bld_trg_arch)) \
1630 $($(target)_SOURCES.$(bld_trg_cpu)) \
1631 $($(target)_SOURCES.$(bld_type))) \
1632 $($(target)_OBJS_)
1633libs :=\
1634 $($(target)_LIBS.$(bld_trg_cpu))\
1635 $($(target)_LIBS.$(bld_trg).$(bld_trg_arch))\
1636 $($(target)_LIBS.$(bld_trg_arch))\
1637 $($(target)_LIBS.$(bld_trg))\
1638 $($(target)_LIBS.$(bld_type))\
1639 $($(target)_LIBS)\
1640 $(foreach sdk, $($(target)_SDKS.$(bld_trg).$(bld_trg_arch)) \
1641 $($(target)_SDKS.$(bld_trg_arch)) \
1642 $($(target)_SDKS.$(bld_trg)) \
1643 $($(target)_SDKS.$(bld_type)) \
1644 $($(target)_SDKS),\
1645 $(SDK_$(sdk)_LIBS.$(bld_trg_cpu))\
1646 $(SDK_$(sdk)_LIBS.$(bld_trg).$(bld_trg_arch))\
1647 $(SDK_$(sdk)_LIBS.$(bld_trg_arch))\
1648 $(SDK_$(sdk)_LIBS.$(bld_trg))\
1649 $(SDK_$(sdk)_LIBS.$(bld_type))\
1650 $(SDK_$(sdk)_LIBS))\
1651 $(LIBS.$(bld_trg_cpu))\
1652 $(LIBS.$(bld_trg).$(bld_trg_arch))\
1653 $(LIBS.$(bld_trg_arch))\
1654 $(LIBS.$(bld_trg))\
1655 $(LIBS.$(bld_type))\
1656 $(LIBS)\
1657 $(foreach sdk, $(SDKS.$(bld_trg).$(bld_trg_arch)) \
1658 $(SDKS.$(bld_trg_arch)) \
1659 $(SDKS.$(bld_trg)) \
1660 $(SDKS.$(bld_type)) \
1661 $(SDKS),\
1662 $(SDK_$(sdk)_LIBS.$(bld_trg_cpu))\
1663 $(SDK_$(sdk)_LIBS.$(bld_trg).$(bld_trg_arch))\
1664 $(SDK_$(sdk)_LIBS.$(bld_trg_arch))\
1665 $(SDK_$(sdk)_LIBS.$(bld_trg))\
1666 $(SDK_$(sdk)_LIBS.$(bld_type))\
1667 $(SDK_$(sdk)_LIBS))\
1668 $(TOOL_$(tool)_LIBS.$(bld_trg_cpu))\
1669 $(TOOL_$(tool)_LIBS.$(bld_trg).$(bld_trg_arch))\
1670 $(TOOL_$(tool)_LIBS.$(bld_trg_arch))\
1671 $(TOOL_$(tool)_LIBS.$(bld_trg))\
1672 $(TOOL_$(tool)_LIBS.$(bld_type))\
1673 $(TOOL_$(tool)_LIBS)
1674libpath :=\
1675 $($(target)_LIBPATH.$(bld_trg_cpu))\
1676 $($(target)_LIBPATH.$(bld_trg).$(bld_trg_arch))\
1677 $($(target)_LIBPATH.$(bld_trg_arch))\
1678 $($(target)_LIBPATH.$(bld_trg))\
1679 $($(target)_LIBPATH.$(bld_type))\
1680 $($(target)_LIBPATH)\
1681 $(foreach sdk, $($(target)_SDKS.$(bld_trg).$(bld_trg_arch)) \
1682 $($(target)_SDKS.$(bld_trg_arch)) \
1683 $($(target)_SDKS.$(bld_trg)) \
1684 $($(target)_SDKS.$(bld_type)) \
1685 $($(target)_SDKS),\
1686 $(SDK_$(sdk)_LIBPATH.$(bld_trg_cpu))\
1687 $(SDK_$(sdk)_LIBPATH.$(bld_trg).$(bld_trg_arch))\
1688 $(SDK_$(sdk)_LIBPATH.$(bld_trg_arch))\
1689 $(SDK_$(sdk)_LIBPATH.$(bld_trg))\
1690 $(SDK_$(sdk)_LIBPATH.$(bld_type))\
1691 $(SDK_$(sdk)_LIBPATH))\
1692 $(LIBPATH.$(bld_trg_cpu))\
1693 $(LIBPATH.$(bld_trg).$(bld_trg_arch))\
1694 $(LIBPATH.$(bld_trg_arch))\
1695 $(LIBPATH.$(bld_trg))\
1696 $(LIBPATH.$(bld_type))\
1697 $(LIBPATH)\
1698 $(foreach sdk, $(SDKS.$(bld_trg).$(bld_trg_arch)) \
1699 $(SDKS.$(bld_trg_arch)) \
1700 $(SDKS.$(bld_trg)) \
1701 $(SDKS.$(bld_type)) \
1702 $(SDKS),\
1703 $(SDK_$(sdk)_LIBPATH.$(bld_trg_cpu))\
1704 $(SDK_$(sdk)_LIBPATH.$(bld_trg).$(bld_trg_arch))\
1705 $(SDK_$(sdk)_LIBPATH.$(bld_trg_arch))\
1706 $(SDK_$(sdk)_LIBPATH.$(bld_trg))\
1707 $(SDK_$(sdk)_LIBPATH.$(bld_type))\
1708 $(SDK_$(sdk)_LIBPATH))\
1709 $(TOOL_$(tool)_LIBPATH.$(bld_trg_cpu))\
1710 $(TOOL_$(tool)_LIBPATH.$(bld_trg).$(bld_trg_arch))\
1711 $(TOOL_$(tool)_LIBPATH.$(bld_trg_arch))\
1712 $(TOOL_$(tool)_LIBPATH.$(bld_trg))\
1713 $(TOOL_$(tool)_LIBPATH.$(bld_type))\
1714 $(TOOL_$(tool)_LIBPATH)
1715dirdep := $(call DIRDEP,$(dir $(out)))
1716deps := $($(target)_DEPS)
1717orderdeps := $($(target)_ORDERDEPS)
1718
1719# Adjust paths if we got a default path.
1720ifneq ($(defpath),)
1721 libpath := $(call abspathex,$(libpath),$(defpath))
1722 objs := $(call abspathex,$(objs),$(defpath))
1723 deps := $(call abspathex,$(deps),$(defpath))
1724 orderdeps := $(call abspathex,$(orderdeps),$(defpath))
1725 othersrc := $(call abspathex,$(othersrc),$(defpath))
1726 # libs are not subject to this because of the the -l<lib> stuff. Use $(<target>_PATH)/lib if relative to current dir!
1727endif
1728
1729# Custom pre-link actions.
1730ifdef $(target)_PRE_CMDS.$(bld_trg).$(bld_trg_arch).$(bld_type)
1731 pre_cmds := $($(target)_PRE_CMDS.$(bld_trg).$(bld_trg_arch).$(bld_type))
1732else ifdef $(target)_PRE_CMDS.$(bld_trg).$(bld_trg_arch)
1733 pre_cmds := $($(target)_PRE_CMDS.$(bld_trg).$(bld_trg_arch))
1734else ifdef $(target)_PRE_CMDS.$(bld_trg).$(bld_type)
1735 pre_cmds := $($(target)_PRE_CMDS.$(bld_trg).$(bld_type))
1736else ifdef $(target)_PRE_CMDS.$(bld_trg_arch)
1737 pre_cmds := $($(target)_PRE_CMDS.$(bld_trg_arch))
1738else ifdef $(target)_PRE_CMDS.$(bld_trg)
1739 pre_cmds := $($(target)_PRE_CMDS.$(bld_trg))
1740else ifdef $(target)_PRE_CMDS.$(bld_type)
1741 pre_cmds := $($(target)_PRE_CMDS.$(bld_type))
1742else ifdef $(target)_PRE_CMDS
1743 pre_cmds := $($(target)_PRE_CMDS)
1744else ifdef PRE_CMDS.$(bld_trg).$(bld_trg_arch).$(bld_type)
1745 pre_cmds := $(PRE_CMDS.$(bld_trg).$(bld_trg_arch).$(bld_type))
1746else ifdef PRE_CMDS.$(bld_trg).$(bld_trg_arch)
1747 pre_cmds := $(PRE_CMDS.$(bld_trg).$(bld_trg_arch))
1748else ifdef PRE_CMDS.$(bld_trg).$(bld_type)
1749 pre_cmds := $(PRE_CMDS.$(bld_trg).$(bld_type))
1750else ifdef PRE_CMDS.$(bld_trg_arch)
1751 pre_cmds := $(PRE_CMDS.$(bld_trg_arch))
1752else ifdef PRE_CMDS.$(bld_trg)
1753 pre_cmds := $(PRE_CMDS.$(bld_trg))
1754else ifdef PRE_CMDS.$(bld_type)
1755 pre_cmds := $(PRE_CMDS.$(bld_type))
1756else
1757 pre_cmds := $(PRE_CMDS)
1758endif
1759
1760# Custom post-link actions.
1761ifdef $(target)_POST_CMDS.$(bld_trg).$(bld_trg_arch).$(bld_type)
1762 post_cmds := $($(target)_POST_CMDS.$(bld_trg).$(bld_trg_arch).$(bld_type))
1763else ifdef $(target)_POST_CMDS.$(bld_trg).$(bld_trg_arch)
1764 post_cmds := $($(target)_POST_CMDS.$(bld_trg).$(bld_trg_arch))
1765else ifdef $(target)_POST_CMDS.$(bld_trg).$(bld_type)
1766 post_cmds := $($(target)_POST_CMDS.$(bld_trg).$(bld_type))
1767else ifdef $(target)_POST_CMDS.$(bld_trg_arch)
1768 post_cmds := $($(target)_POST_CMDS.$(bld_trg_arch))
1769else ifdef $(target)_POST_CMDS.$(bld_trg)
1770 post_cmds := $($(target)_POST_CMDS.$(bld_trg))
1771else ifdef $(target)_POST_CMDS.$(bld_type)
1772 post_cmds := $($(target)_POST_CMDS.$(bld_type))
1773else ifdef $(target)_POST_CMDS
1774 post_cmds := $($(target)_POST_CMDS)
1775else ifdef POST_CMDS.$(bld_trg).$(bld_trg_arch).$(bld_type)
1776 post_cmds := $(POST_CMDS.$(bld_trg).$(bld_trg_arch).$(bld_type))
1777else ifdef POST_CMDS.$(bld_trg).$(bld_trg_arch)
1778 post_cmds := $(POST_CMDS.$(bld_trg).$(bld_trg_arch))
1779else ifdef POST_CMDS.$(bld_trg).$(bld_type)
1780 post_cmds := $(POST_CMDS.$(bld_trg).$(bld_type))
1781else ifdef POST_CMDS.$(bld_trg_arch)
1782 post_cmds := $(POST_CMDS.$(bld_trg_arch))
1783else ifdef POST_CMDS.$(bld_trg)
1784 post_cmds := $(POST_CMDS.$(bld_trg))
1785else ifdef POST_CMDS.$(bld_type)
1786 post_cmds := $(POST_CMDS.$(bld_type))
1787else
1788 post_cmds := $(POST_CMDS)
1789endif
1790
1791# installation targets
1792ifndef $(target)_NOINST
1793INSTARGET_$(target) := $(patsubst %/,%/$(notdir $(out)), \
1794 $(if $($(target)_INST), $(addprefix $(PATH_INS)/,$($(target)_INST)), $(definst)/))
1795ifdef KBUILD_DO_AUTO_INSTALL
1796$(typevar) += $(INSTARGET_$(target))
1797else
1798$(typevar) += $(out)
1799endif
1800# generate the install rule
1801$(eval $(def_link_install_rule))
1802
1803else # NOINST
1804INSTARGET_$(target) :=
1805$(typevar) += $(out)
1806endif # NOINST
1807
1808# dependency file
1809dep := $(outbase)$(SUFF_DEP)
1810ifndef NO_LINK_CMDS_DEPS
1811 _DEPFILES_INCLUDED += $(dep)
1812 $(eval includedep $(dep))
1813endif
1814
1815# check that the tool is defined.
1816ifndef TOOL_$(tool)_$(tool_do)_CMDS
1817$(warning kBuild: tools: \
1818 1 $($(target)_$(source)TOOL.$(bld_trg).$(bld_trg_arch)) \
1819 2 $($(target)_$(source)TOOL.$(bld_trg)) \
1820 3 $($(target)_$(source)TOOL) \
1821 4 $($(target)_TOOL.$(bld_trg).$(bld_trg_arch)) \
1822 5 $($(target)_TOOL.$(bld_trg)) \
1823 6 $($(target)_TOOL) \
1824 7 $($(source)TOOL.$(bld_trg).$(bld_trg_arch)) \
1825 8 $($(source)TOOL.$(bld_trg)) \
1826 9 $($(source)TOOL) \
1827 10 $(TOOL.$(bld_trg).$(bld_trg_arch)) \
1828 11 $(TOOL.$(bld_trg)) \
1829 12 $(TOOL) )
1830$(error kBuild: TOOL_$(tool)_$(tool_do)_CMDS isn't defined! target=$(target) )
1831endif
1832
1833# call the tool
1834$(target)_CMDS_ := $(TOOL_$(tool)_$(tool_do)_CMDS)
1835ifneq ($(pre_cmds),)
1836 $(target)_CMDS_ := $(TAB)$(pre_cmds)$(NL)$(TAB)$($(target)_CMDS_)
1837endif
1838ifneq ($(post_cmds),)
1839 $(target)_CMDS_ := $($(target)_CMDS_)$(NL)$(TAB)$(post_cmds)
1840endif
1841$(target)_OUTPUT_ := $(TOOL_$(tool)_$(tool_do)_OUTPUT)
1842$(target)_DEPEND_ := $(TOOL_$(tool)_$(tool_do)_DEPEND) $(deps) $(objs)
1843$(target)_DEPORD_ := $(TOOL_$(tool)_$(tool_do)_DEPORD) $(dirdep) $(orderdeps)
1844
1845# generate the link rule.
1846$(eval $(def_link_rule))
1847
1848
1849# Update globals.
1850_OBJS += $($(target)_OBJS_)
1851_OUT_FILES += $($(target)_OUTPUT_) $(out)
1852_CLEAN_FILES += $($(target)_CLEAN)
1853_INSTALLS_FILES += $(INSTARGET_$(target))
1854
1855endef
1856
1857
1858#
1859# BLDPROGS
1860#
1861
1862## Build program (one).
1863# @param $(target) Normalized target (program) name.
1864define def_bldprog
1865
1866# set NOINST if not forced installation.
1867ifndef $(target)_INST
1868$(target)_NOINST := 1
1869endif
1870
1871# do the usual stuff.
1872$(eval $(value def_link_common))
1873
1874endef
1875
1876# Process build programs.
1877EXT := EXE
1878EXTPRE := HOST
1879tool_do := LINK_PROGRAM
1880definst := $(PATH_BIN)
1881typevar := _BLDPROGS
1882mode := 0755
1883bld_trg_base_var := PLATFORM
1884$(foreach target, $(BLDPROGS) $(BLDPROGS.$(BUILD_PLATFORM)) $(BLDPROGS.$(BUILD_PLATFORM).$(BUILD_PLATFORM_ARCH)), $(eval $(value def_bldprog)))
1885
1886
1887
1888#
1889# DLLS
1890#
1891
1892# Process dlls
1893EXT := DLL
1894EXTPRE :=
1895tool_do := LINK_DLL
1896definst := $(PATH_DLL)
1897typevar := _DLLS
1898mode := 0644
1899bld_trg_base_var := TARGET
1900$(foreach target, $(DLLS) $(DLLS.$(BUILD_TARGET)) $(DLLS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)), $(eval $(value def_link_common)))
1901
1902
1903#
1904# IMPORT LIBRARIES
1905#
1906# - On OS/2 and windows these are libraries.
1907# - On other platforms they are fake DLLs.
1908#
1909EXTPRE :=
1910typevar := _IMPORT_LIBS
1911mode := 0644
1912bld_trg_base_var := TARGET
1913ifeq ($(filter-out nt os2 win win64 win32,$(BUILD_TARGET)),)
1914 EXT := LIB
1915 tool_do := LINK_LIBRARY
1916 definst := $(PATH_LIB)
1917 $(foreach target, $(IMPORT_LIBS) $(IMPORT_LIBS.$(BUILD_TARGET)) $(IMPORT_LIBS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)), $(eval $(value def_lib)))
1918else
1919 EXT := DLL
1920 tool_do := LINK_DLL
1921 definst := $(PATH_DLL)
1922 $(foreach target, $(IMPORT_LIBS) $(IMPORT_LIBS.$(BUILD_TARGET)) $(IMPORT_LIBS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)), $(eval $(value def_link_common)))
1923endif
1924
1925
1926#
1927# PROGRAMS
1928#
1929
1930# Process programs
1931EXT := EXE
1932EXTPRE :=
1933tool_do := LINK_PROGRAM
1934definst := $(PATH_BIN)
1935typevar := _PROGRAMS
1936mode := 0755
1937bld_trg_base_var := TARGET
1938$(foreach target, $(PROGRAMS) $(PROGRAMS.$(BUILD_TARGET)) $(PROGRAMS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)), $(eval $(value def_link_common)))
1939
1940
1941
1942#
1943# SYSMODS
1944#
1945
1946# Process sysmods
1947EXT := SYS
1948EXTPRE :=
1949tool_do := LINK_SYSMOD
1950definst := $(PATH_SYS)
1951typevar := _SYSMODS
1952mode := 0644
1953bld_trg_base_var := TARGET
1954$(foreach target, $(SYSMODS) $(SYSMODS.$(BUILD_TARGET)) $(SYSMODS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)), $(eval $(value def_link_common)))
1955
1956
1957#
1958# OTHERS
1959#
1960_OTHERS = $(OTHERS) $(OTHERS.$(BUILD_TARGET)) $(OTHERS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH))
1961
1962
1963#
1964# INSTALLS
1965#
1966
1967## generate the install rule
1968define def_install_src_rule
1969# the install rule
1970$(insdst) : $(srcsrc) | $(call DIRDEP,$(dir $(insdst)))
1971 $$(call MSG_INST_FILE,$(srcsrc),$(insdst))
1972 $$(QUIET)$$(if $$(filter $(INSTALL),$(inscmd)),,$$(RM) -f $$@)
1973 $$(QUIET)$(inscmd)
1974endef
1975
1976## install one file
1977define def_install_src
1978
1979# deal with '=>' in the source file name.
1980srcdst := $(subst =>, ,$(src))
1981srcsrc := $(firstword $(srcdst))
1982srcdstdir := $(dir $(word 2,$(srcdst)))
1983srcdst := $(word $(words $(srcdst)),$(srcdst))
1984
1985# _INSTFUN
1986ifdef $(srcsrc)_INSTFUN
1987 instfun := $(srcsrc)_INSTFUN
1988else
1989 ifdef $(target)_INSTFUN
1990 instfun := $(target)_INSTFUN
1991 else
1992 instfun := _INSTALL_FILE
1993 endif
1994endif
1995
1996# _INST
1997ifdef $(srcsrc)_INST
1998 inst := $(patsubst %/,%,$($(srcsrc)_INST))/$(dir $(srcdstdir))
1999else
2000 ifdef $(target)_INST
2001 inst := $(patsubst %/,%,$($(target)_INST))/$(dir $(srcdstdir))
2002 else
2003 inst := $(dir $(srcdstdir))
2004 endif
2005endif
2006
2007# calc target
2008insdst := $(call $(instfun),$(srcdst),$(target),$(inst),$(PATH_INS))
2009#$(warning instfun=$(instfun) srcdst=$(srcdst) target=$(target) inst=$(inst) => insdst=$(insdst))
2010
2011# mode, uid and gid
2012mode := $(firstword \
2013 $($(target)_$(srcsrc)_MODE.$(bld_trg).$(bld_trg_arch)) \
2014 $($(target)_$(srcsrc)_MODE.$(bld_trg)) \
2015 $($(target)_$(srcsrc)_MODE) \
2016 $($(target)_$(srcdst)_MODE.$(bld_trg).$(bld_trg_arch)) \
2017 $($(target)_$(srcdst)_MODE.$(bld_trg)) \
2018 $($(target)_$(srcdst)_MODE) \
2019 $($(srcsrc)_MODE.$(bld_trg).$(bld_trg_arch)) \
2020 $($(srcsrc)_MODE.$(bld_trg)) \
2021 $($(srcsrc)_MODE) \
2022 $($(srcdst)_MODE.$(bld_trg).$(bld_trg_arch)) \
2023 $($(srcdst)_MODE.$(bld_trg)) \
2024 $($(srcdst)_MODE) \
2025 $($(target)_MODE.$(bld_trg).$(bld_trg_arch)) \
2026 $($(target)_MODE.$(bld_trg)) \
2027 $($(target)_MODE))
2028uid := $(firstword \
2029 $($(target)_$(srcsrc)_UID.$(bld_trg).$(bld_trg_arch)) \
2030 $($(target)_$(srcsrc)_UID.$(bld_trg)) \
2031 $($(target)_$(srcsrc)_UID) \
2032 $($(target)_$(srcdst)_UID.$(bld_trg).$(bld_trg_arch)) \
2033 $($(target)_$(srcdst)_UID.$(bld_trg)) \
2034 $($(target)_$(srcdst)_UID) \
2035 $($(srcsrc)_UID.$(bld_trg).$(bld_trg_arch)) \
2036 $($(srcsrc)_UID.$(bld_trg)) \
2037 $($(srcsrc)_UID) \
2038 $($(srcdst)_UID.$(bld_trg).$(bld_trg_arch)) \
2039 $($(srcdst)_UID.$(bld_trg)) \
2040 $($(srcdst)_UID) \
2041 $($(target)_UID.$(bld_trg).$(bld_trg_arch)) \
2042 $($(target)_UID.$(bld_trg)) \
2043 $($(target)_UID))
2044gid := $(firstword \
2045 $($(target)_$(srcsrc)_GID.$(bld_trg).$(bld_trg_arch)) \
2046 $($(target)_$(srcsrc)_GID.$(bld_trg)) \
2047 $($(target)_$(srcsrc)_GID) \
2048 $($(target)_$(srcdst)_GID.$(bld_trg).$(bld_trg_arch)) \
2049 $($(target)_$(srcdst)_GID.$(bld_trg)) \
2050 $($(target)_$(srcdst)_GID) \
2051 $($(srcsrc)_GID.$(bld_trg).$(bld_trg_arch)) \
2052 $($(srcsrc)_GID.$(bld_trg)) \
2053 $($(srcsrc)_GID) \
2054 $($(srcdst)_GID.$(bld_trg).$(bld_trg_arch)) \
2055 $($(srcdst)_GID.$(bld_trg)) \
2056 $($(srcdst)_GID) \
2057 $($(target)_GID.$(bld_trg).$(bld_trg_arch)) \
2058 $($(target)_GID.$(bld_trg)) \
2059 $($(target)_GID))
2060flags := \
2061 $($(target)_IFFLAGS) \
2062 $($(target)_IFFLAGS.$(bld_trg)) \
2063 $($(target)_IFFLAGS.$(bld_trg).$(bld_trg_arch)) \
2064 $($(srcdst)_IFFLAGS) \
2065 $($(srcdst)_IFFLAGS.$(bld_trg)) \
2066 $($(srcdst)_IFFLAGS.$(bld_trg).$(bld_trg_arch)) \
2067 $($(srcsrc)_IFFLAGS) \
2068 $($(srcsrc)_IFFLAGS.$(bld_trg)) \
2069 $($(srcsrc)_IFFLAGS.$(bld_trg).$(bld_trg_arch)) \
2070 $($(target)_$(srcdst)_IFFLAGS) \
2071 $($(target)_$(srcdst)_IFFLAGS.$(bld_trg)) \
2072 $($(target)_$(srcdst)_IFFLAGS.$(bld_trg).$(bld_trg_arch)) \
2073 $($(target)_$(srcsrc)_IFFLAGS) \
2074 $($(target)_$(srcsrc)_IFFLAGS.$(bld_trg)) \
2075 $($(target)_$(srcsrc)_IFFLAGS.$(bld_trg).$(bld_trg_arch))
2076
2077
2078# Adjust the source if we got a default PATH. (This must be done this late!)
2079ifdef $(target)_PATH
2080 srcsrc := $(call abspathex,$(srcsrc),$($(target)_PATH))
2081endif
2082
2083# create the command
2084ifdef $(srcsrc)_INSTALLER
2085 inscmd := $(call $(srcsrc)_INSTALLER,$(srcsrc),$(insdst),$(target),$(flags))
2086else ifdef $(target)_INSTALLER
2087 inscmd := $(call $(target)_INSTALLER,$(srcsrc),$(insdst),$(target),$(flags))
2088else
2089 inscmd := $$(INSTALL)\
2090 $(if $(uid),-o $(uid))\
2091 $(if $(gid),-g $(gid))\
2092 $(if $(mode),-m $(mode))\
2093 $(flags)\
2094 $(srcsrc) $(insdst)
2095endif
2096
2097# generate the rule (need double evaluation here)
2098$(eval $(def_install_src_rule))
2099
2100INSTARGET_$(target) += $(insdst)
2101endef
2102
2103
2104## generate the symlink rule
2105define def_install_symlink_rule
2106# the install rule
2107$(insdst) : | $(call DIRDEP,$(dir $(insdst)))
2108 $$(call MSG_INST_SYM,$(insdst),$(symdst))
2109 $$(QUIET)$$(RM) -f $$@
2110 $$(QUIET)$$(LN_SYMLINK) $(symdst) $(insdst)
2111endef
2112
2113## create one symlink
2114define def_install_symlink
2115
2116# deal with '=>' in the source file name.
2117symdst := $(subst =>, ,$(src))
2118symlnk := $(firstword $(symdst))
2119symdst := $(word $(words $(symdst)),$(symdst))
2120
2121# _INSTFUN
2122ifdef $(symlnk)_INSTFUN
2123 instfun := $(symlnk)_INSTFUN
2124else ifdef $(target)_INSTFUN
2125 instfun := $(target)_INSTFUN
2126else
2127 instfun := _INSTALL_FILE
2128endif
2129
2130# _INST
2131ifdef $(symlnk)_INST
2132 inst := $(patsubst %/,%,$($(symlnk)_INST))/$(dir $(symlnk))
2133else ifdef $(target)_INST
2134 inst := $(patsubst %/,%,$($(target)_INST))/$(dir $(symlnk))
2135else
2136 inst := $(dir $(symlnk))
2137endif
2138
2139# calc target
2140insdst := $(call $(instfun),$(symlnk),$(target),$(inst),$(PATH_INS))
2141#$(warning symlnk=$(symlnk) symdst=$(symdst) insdst=$(insdst) instfun=$(instfun) inst='$(inst)')
2142
2143# generate the rule (need double evaluation here)
2144$(eval $(def_install_symlink_rule))
2145
2146INSTARGET_$(target) += $(insdst)
2147endef
2148
2149
2150## generate the install rule
2151define def_install_directory_rule
2152# the install rule
2153$(insdst):
2154 $$(call MSG_INST_DIR,$(insdst))
2155 $$(QUIET)$$(INSTALL) -d \
2156 $(if $(uid),-o $(uid))\
2157 $(if $(gid),-g $(gid))\
2158 $(if $(mode),-m $(mode))\
2159 $(flags)\
2160 $(insdst)
2161
2162.NOTPARALLEL: $(insdst)
2163endef
2164
2165
2166## create one directory
2167define def_install_directory
2168
2169# _INST
2170ifdef $(directory)_INST
2171 inst := $(PATH_INS)/$(patsubst %/,%,$($(directory)_INST))
2172else ifdef $(target)_INST
2173 inst := $(PATH_INS)/$(patsubst %/,%,$($(target)_INST))
2174else
2175 inst := $(PATH_INS)
2176endif
2177
2178mode := $(firstword \
2179 $($(target)_$(directory)_MODE.$(bld_trg).$(bld_trg_arch)) \
2180 $($(target)_$(directory)_MODE.$(bld_trg)) \
2181 $($(target)_$(directory)_MODE) \
2182 $($(directory)_MODE.$(bld_trg).$(bld_trg_arch)) \
2183 $($(directory)_MODE.$(bld_trg)) \
2184 $($(directory)_MODE) \
2185 $($(target)_MODE.$(bld_trg).$(bld_trg_arch)) \
2186 $($(target)_MODE.$(bld_trg)) \
2187 $($(target)_MODE))
2188uid := $(firstword \
2189 $($(target)_$(directory)_UID.$(bld_trg).$(bld_trg_arch)) \
2190 $($(target)_$(directory)_UID.$(bld_trg)) \
2191 $($(target)_$(directory)_UID) \
2192 $($(directory)_UID.$(bld_trg).$(bld_trg_arch)) \
2193 $($(directory)_UID.$(bld_trg)) \
2194 $($(directory)_UID) \
2195 $($(target)_UID.$(bld_trg).$(bld_trg_arch)) \
2196 $($(target)_UID.$(bld_trg)) \
2197 $($(target)_UID))
2198gid := $(firstword \
2199 $($(target)_$(directory)_GID.$(bld_trg).$(bld_trg_arch)) \
2200 $($(target)_$(directory)_GID.$(bld_trg)) \
2201 $($(target)_$(directory)_GID) \
2202 $($(directory)_GID.$(bld_trg).$(bld_trg_arch)) \
2203 $($(directory)_GID.$(bld_trg)) \
2204 $($(directory)_GID) \
2205 $($(target)_GID.$(bld_trg).$(bld_trg_arch)) \
2206 $($(target)_GID.$(bld_trg)) \
2207 $($(target)_GID))
2208flags := \
2209 $($(target)_IDFLAGS)\
2210 $($(target)_IDFLAGS.$(bld_trg)) \
2211 $($(target)_IDFLAGS.$(bld_trg).$(bld_trg_arch)) \
2212 $($(directory)_IDFLAGS) \
2213 $($(directory)_IDFLAGS.$(bld_trg)) \
2214 $($(directory)_IDFLAGS.$(bld_trg).$(bld_trg_arch)) \
2215 $($(target)_$(directory)_IDFLAGS) \
2216 $($(target)_$(directory)_IDFLAGS.$(bld_trg)) \
2217 $($(target)_$(directory)_IDFLAGS.$(bld_trg).$(bld_trg_arch))
2218
2219insdst := $(inst)/$(directory)/
2220#$(warning directory=$(directory) inst=$(inst) insdst=$(insdst) mode=$(mode) gid=$(gid) uid=$(uid))
2221
2222# generate the rule (need double evaluation here)
2223$(eval $(def_install_directory_rule))
2224
2225INSTARGET_DIRS_$(target) += $(insdst)
2226endef
2227
2228
2229## process one install target.
2230define def_install
2231# the basics.
2232bld_type := $(firstword $($(target)_BLD_TYPE) $(BUILD_TYPE))
2233bld_trg := $(firstword $($(target)_BLD_TRG) $(BUILD_TARGET))
2234bld_trg_arch:= $(firstword $($(target)_BLD_TRG_ARCH) $(BUILD_TARGET_ARCH))
2235bld_trg_cpu := $(firstword $($(target)_BLD_TRG_CPU) $(BUILD_TARGET_CPU))
2236
2237INSTARGET_$(target) := $($(target)_GOALS)
2238INSTARGET_DIRS_$(target) :=
2239
2240$(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)), \
2241 $(eval $(value def_install_directory)))
2242
2243$(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)), \
2244 $(eval $(value def_install_src)))
2245
2246$(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)), \
2247 $(eval $(value def_install_symlink)))
2248
2249# the collection target
2250TARGET_$(target) := $(PATH_TARGET)/$(target).ins
2251$(TARGET_$(target)): $(INSTARGET_$(target)) | $(INSTARGET_DIRS_$(target)) $(call DIRDEP,$(PATH_TARGET))
2252 @$(QUIET2)$(APPEND) $@
2253
2254$(target): $(TARGET_$(target))
2255
2256_INSTALLS += $(TARGET_$(target))
2257_INSTALLS_FILES += $(INSTARGET_$(target))
2258_INSTALLS_DIRS += $(INSTARGET_DIRS_$(target))
2259endef
2260
2261## process all install targets
2262$(foreach target, $(INSTALLS) $(INSTALLS.$(BUILD_TARGET)) $(INSTALLS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)), \
2263 $(eval $(value def_install)))
2264
2265
2266#
2267# PACKING
2268#
2269_PACKING += $(PACKING) $(PACKING.$(BUILD_TARGET)) $(PACKING.$(BUILD_TARGET).$(BUILD_TARGET_ARCH))
2270
2271
2272#
2273# DOCS
2274#
2275
2276
2277#
2278# DIRECTORIES
2279#
2280_DIR_ALL := $(sort $(addsuffix /,$(patsubst %/,%,$(_DIRS))) $(dir $(_OUT_FILES) $(_OBJS) $(_INSTALLS_FILES)))
2281$(foreach directory,$(_INSTALLS_DIRS), $(eval _DIR_ALL := $(filter-out $(directory),$(_DIR_ALL))))
2282
2283
2284define def_mkdir_rule
2285$(directory):
2286 $$(call MSG_MKDIR,$$@)
2287 $$(QUIET)$$(MKDIR) -p $$@
2288endef
2289
2290$(foreach directory,$(_DIR_ALL),$(eval $(def_mkdir_rule)))
2291
2292
2293#
2294# NOTHING
2295#
2296do-nothing:
2297 $(call MSG_NOTHING)
2298
2299
2300#
2301# CLEAN UP
2302#
2303do-clean:
2304 $(call MSG_CLEAN)
2305 $(QUIET)$(RM) -f $(_OUT_FILES) $(_OBJS) $(_DEPFILES) $(_DEPFILES_INCLUDED) $(_CLEAN_FILES) $(OTHER_CLEAN)
2306
2307
2308#
2309# PASSES (including directory and makefile walking)
2310#
2311
2312## Subdir
2313# @param $(pass) Lowercase pass name.
2314# @param $(PASS) Uppercase pass name.
2315# @param $(subdir) Subdirectory
2316# @param $(tag) tag to attach to the rule name.
2317define def_pass_subdir
2318pass_$(pass)$(tag):: $(dep)
2319 + $$(QUIET)$$(MAKE) -C $(subdir) -f $$(notdir $$(firstword $$(wildcard $$(addprefix $(subdir)/,$$(DEFAULT_MAKEFILE))))) pass_$(pass)
2320endef
2321
2322## Submakefile
2323# @param $(pass) Lowercase pass name.
2324# @param $(PASS) Uppercase pass name.
2325# @param $(makefile) Makefile.
2326# @param $(tag) tag to attach to the rule name.
2327define def_pass_makefile
2328pass_$(pass)$(tag):: $(dep)
2329 + $$(QUIET)$$(MAKE) -C $(patsubst %/,%,$(dir $(makefile))) -f $(notdir $(makefile)) pass_$(pass)
2330endef
2331
2332## Execute a pass.
2333# @param $(pass) Lowercase pass name.
2334# @param $(PASS) Uppercase pass name.
2335define def_pass_old
2336$(eval SUBDIRS_$(PASS) ?= $(SUBDIRS) $(SUBDIRS.$(BUILD_TARGET)) $(SUBDIRS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) )
2337$(eval SUBDIRS_AFTER_$(PASS) ?= $(SUBDIRS_AFTER) $(SUBDIRS_AFTER.$(BUILD_TARGET)) $(SUBDIRS_AFTER.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) )
2338$(eval MAKEFILES_BEFORE_$(PASS) ?= $(MAKEFILES_BEFORE) $(MAKEFILES_BEFORE.$(BUILD_TARGET)) $(MAKEFILES_BEFORE.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) )
2339$(eval MAKEFILES_AFTER_$(PASS) ?= $(MAKEFILES_AFTER) $(MAKEFILES_AFTER.$(BUILD_TARGET)) $(MAKEFILES_AFTER.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) )
2340
2341$(eval tag:=_before)
2342$(eval dep:=)
2343$(foreach subdir,$(SUBDIRS_$(PASS)) $(SUBDIRS_$(PASS).$(BUILD_TARGET)) $(SUBDIRS_$(PASS).$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) ,$(eval $(def_pass_subdir)))
2344$(foreach makefile,$(MAKEFILES_BEFORE_$(PASS)) $(MAKEFILES_BEFORE_$(PASS).$(BUILD_TARGET)) $(MAKEFILES_BEFORE_$(PASS).$(BUILD_TARGET).$(BUILD_TARGET_ARCH)),$(eval $(def_pass_makefile)))
2345
2346$(eval tag:=_after)
2347$(eval dep:=pass_$(pass)_doit)
2348$(foreach subdir,$(SUBDIRS_AFTER_$(PASS)) $(SUBDIRS_AFTER_$(PASS).$(BUILD_TARGET)) $(SUBDIRS_AFTER_$(PASS).$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) ,$(eval $(def_pass_subdir)))
2349$(foreach makefile,$(MAKEFILES_AFTER_$(PASS)) $(MAKEFILES_AFTER_$(PASS).$(BUILD_TARGET)) $(MAKEFILES_AFTER_$(PASS).$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) ,$(eval $(def_pass_makefile)))
2350
2351.NOTPARALLEL: pass_$(pass)_before pass_$(pass)_after
2352.PHONY: pass_$(pass) pass_$(pass)_before pass_$(pass)_doit pass_$(pass)_after
2353pass_$(pass)_doit: $(PASS_$(PASS)_trgs) $(foreach var,$(PASS_$(PASS)_vars),$(var))
2354pass_$(pass)_this: pass_$(pass)_before
2355 + $$(QUIET)$$(MAKE) -f $$(MAKEFILE) pass_$(pass)_doit
2356pass_$(pass)_after:: pass_$(pass)_this
2357pass_$(pass): pass_$(pass)_after
2358
2359endef
2360
2361define def_pass
2362$(eval SUBDIRS_$(PASS) ?= $(SUBDIRS) $(SUBDIRS.$(BUILD_TARGET)) $(SUBDIRS.$(BUILD_TARGET.$(BUILD_TARGET_ARCH))) )
2363$(eval SUBDIRS_AFTER_$(PASS) ?= $(SUBDIRS_AFTER) $(SUBDIRS_AFTER.$(BUILD_TARGET)) $(SUBDIRS_AFTER.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) )
2364$(eval MAKEFILES_BEFORE_$(PASS) ?= $(MAKEFILES_BEFORE) $(MAKEFILES_BEFORE.$(BUILD_TARGET)) $(MAKEFILES_BEFORE.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) )
2365$(eval MAKEFILES_AFTER_$(PASS) ?= $(MAKEFILES_AFTER) $(MAKEFILES_AFTER.$(BUILD_TARGET)) $(MAKEFILES_AFTER.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) )
2366
2367$(eval tag:=_before)
2368$(eval dep:=)
2369$(foreach subdir,$(SUBDIRS_$(PASS)) $(SUBDIRS_$(PASS).$(BUILD_TARGET)) $(SUBDIRS_$(PASS).$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) ,$(eval $(def_pass_subdir)))
2370$(foreach makefile,$(MAKEFILES_BEFORE_$(PASS)) $(MAKEFILES_BEFORE_$(PASS).$(BUILD_TARGET)) $(MAKEFILES_BEFORE_$(PASS).$(BUILD_TARGET).$(BUILD_TARGET_ARCH)),$(eval $(def_pass_makefile)))
2371
2372$(eval tag:=_after)
2373$(eval dep:=pass_$(pass)_doit)
2374$(foreach subdir,$(SUBDIRS_AFTER_$(PASS)) $(SUBDIRS_AFTER_$(PASS).$(BUILD_TARGET)) $(SUBDIRS_AFTER_$(PASS).$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) ,$(eval $(def_pass_subdir)))
2375$(foreach makefile,$(MAKEFILES_AFTER_$(PASS)) $(MAKEFILES_AFTER_$(PASS).$(BUILD_TARGET)) $(MAKEFILES_AFTER_$(PASS).$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) ,$(eval $(def_pass_makefile)))
2376
2377ifdef KBUILD_SAFE_PARALLEL
2378.NOTPARALLEL: pass_$(pass) pass_$(pass)_before pass_$(pass)_after pass_$(pass)_this
2379.PHONY: pass_$(pass) pass_$(pass)_before pass_$(pass)_after pass_$(pass)_this pass_$(pass)_doit
2380pass_$(pass)_doit: $(PASS_$(PASS)_trgs) $(foreach var,$(PASS_$(PASS)_vars),$(var))
2381pass_$(pass)_this: pass_$(pass)_before
2382 + $$(QUIET)$$(MAKE) -f $$(MAKEFILE) pass_$(pass)_doit
2383pass_$(pass)_after:: pass_$(pass)_this
2384pass_$(pass): pass_$(pass)_after
2385else
2386.NOTPARALLEL: pass_$(pass) pass_$(pass)_before pass_$(pass)_after pass_$(pass)_doit
2387.PHONY: pass_$(pass) pass_$(pass)_before pass_$(pass)_after pass_$(pass)_doit
2388pass_$(pass)_doit: pass_$(pass)_before \
2389 $(PASS_$(PASS)_trgs) $(foreach var,$(PASS_$(PASS)_vars),$($(var)))
2390pass_$(pass): \
2391 pass_$(pass)_before \
2392 pass_$(pass)_doit \
2393 pass_$(pass)_after
2394endif
2395
2396#$ (warning pass=$(pass) PASS=$(PASS): $(PASS_$(PASS)_trgs) $(PASS_$(PASS)_trgs) $(foreach var,$(PASS_$(PASS)_vars),$($(var))))
2397endef
2398
2399# Generate the defined passes.
2400$(foreach PASS, $(PASSES), \
2401 $(eval pass := $(PASS_$(PASS)_pass)) \
2402 $(eval $(def_pass)))
2403
2404## Pass order
2405# @param $(pass) Current pass name.
2406# @param $(prev_pass) The previous pass name.
2407define def_pass_order
2408ifdef KBUILD_SAFE_PARALLEL
2409.NOTPARALLEL: pass_$(pass)_order
2410.PHONY: pass_$(pass)_order
2411pass_$(pass)_order: $(pass_prev)
2412 $$(call MSG_PASS,$$(if $$(PASS_$(PASS)),$$(PASS_$(PASS)),$(pass)))
2413 + $$(QUIET)$$(MAKE) -f $$(MAKEFILE) pass_$(pass)
2414else
2415.NOTPARALLEL: pass_$(pass)_order pass_$(pass)_banner
2416.PHONY: pass_$(pass)_order pass_$(pass)_banner
2417pass_$(pass)_banner:
2418 $$(call MSG_PASS,$$(if $$(PASS_$(PASS)),$$(PASS_$(PASS)),$(pass)))
2419pass_$(pass)_order: \
2420 $(pass_prev) \
2421 pass_$(pass)_banner \
2422 pass_$(pass)
2423endif
2424$(eval pass_prev := pass_$(pass)_order)
2425endef
2426
2427## PASS: order
2428# Use dependencies to ensure correct pass order.
2429pass_prev :=
2430$(foreach PASS,$(DEFAULT_PASSES),\
2431 $(eval pass := $(PASS_$(PASS)_pass)) \
2432 $(eval $(def_pass_order)))
2433
2434
2435#
2436# THE MAIN RULES
2437#
2438all_recursive: $(pass_prev)
2439
2440rebuild: clean
2441 + $(MAKE) -f $(firstword $(MAKEFILE_LIST)) all_recursive
2442
2443# @todo make this a non-default pass!
2444uninstall:
2445 $(RM) -f $(_INSTALLS_FILES)
2446
2447install: pass_installs
2448
2449# misc shortcuts.
2450targets: bldprogs libraries dlls programs sysmods others installs
2451objects: $(_OBJS)
2452bldprogs: $(_BLDPROGS)
2453libraries: $(_LIBS) $(_IMPORT_LIBS) $(_OTHER_LIBRARIES)
2454dlls: $(_DLLS)
2455programs: $(_PROGRAMS)
2456sysmods: $(_SYSMODS)
2457others: $(_OTHERS)
2458installs: $(_INSTALLS) $(_INSTALLS_DIRS) $(_INSTALLS_FILES)
2459
2460
2461#
2462# kBuild debugging stuff.
2463#
2464_SPACE := $(subst ., ,.)
2465_TAB := $(subst ., ,.)
2466define _NEWLINE
2467
2468
2469endef
2470NLTAB = $(_NEWLINE)$(TAB)
2471show_targets:
2472 @$(foreach target, $(ALL_TARGETS),\
2473 @$(ECHO) "target: $(target)" $(NLTAB)\
2474 @$(ECHO) " PATH_$(target)=$(PATH_$(target))" $(NLTAB)\
2475 @$(ECHO) " TARGET_$(target)=$(TARGET_$(target))" $(NLTAB)\
2476 @$(ECHO) " INSTARGET_$(target)=$(INSTARGET_$(target))" $(NLTAB)\
2477$(foreach prop,$(PROPS_SINGLE) $(PROPS_ACCUMULATE_L) $(PROPS_ACCUMULATE_R) OBJS_ CLEAN, \
2478 $(eval _tmp:=$(firstword $($(target)_BLD_TRG) $(BUILD_TARGET))) \
2479 $(if $($(target)_$(prop).$(_tmp)),\
2480 @$(ECHO) " $(target)_$(prop).$(_tmp)=$($(target)_$(prop).$(_tmp))" $(NLTAB)) \
2481 $(if $($(target)_$(prop)), $(NLTAB)@$(ECHO) " $(target)_$(prop)=$($(target)_$(prop))" $(NLTAB)) \
2482)\
2483$(foreach prop,$(PROPS_DEFERRED), \
2484 $(eval _tmp:=$(firstword $($(target)_BLD_TRG) $(BUILD_TARGET))) \
2485 $(if $(value $(target)_$(prop).$(_tmp)),\
2486 @$(ECHO) ' $(target)_$(prop).$(_tmp)=$(value $(TARGET)_$(prop).$(_tmp))' $(NLTAB)) \
2487 $(if $(value $(target)_$(prop)), $(NLTAB)@$(ECHO) ' $(target)_$(prop)=$(value $(target)_$(prop))' $(NLTAB)) \
2488))
2489
2490
2491
2492#
2493# Include dependency files.
2494#
2495ifneq ($(_DEPFILES),)
2496 includedep $(_DEPFILES)
2497endif
2498
2499
2500# end-of-file-content
2501__footer_kmk__ := target
2502endif # __footer_kmk__
2503
2504
Note: See TracBrowser for help on using the repository browser.