source: trunk/kBuild/footer.kmk@ 988

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

kBuild profiling.

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