source: trunk/kBuild/footer.kmk@ 1441

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

output make-stats when KBUILD_PROFILE_SELF is active.

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