source: trunk/kBuild/footer.kmk@ 982

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

Use the new prepend operator <= instead of the slow and clumsy _r1/r2 template inheritance stuff.

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