source: trunk/kBuild/footer.kmk@ 1392

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

Fixed buggy check for template existance (def_templates was called instead of def_templates_include).

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