source: trunk/kBuild/footer.kmk@ 1282

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

Fixed inheritance bug, incorrect loop detection.

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