source: trunk/kBuild/footer.kmk@ 1404

Last change on this file since 1404 was 1399, checked in by bird, 17 years ago

Some todos and an untested function.

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