source: trunk/kBuild/footer.kmk@ 1408

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

EXPAND_BY = overriding (the default) | appending | prepending; mostly untested, but doesn't seem to break anything.

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