source: trunk/kBuild/footer.kmk@ 984

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

enabled the multi target rules. added some PORTME hints.

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