source: trunk/kBuild/footer.kmk@ 873

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

Implemented PRE_CMDS and POST_CMDS for linking.

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