source: trunk/kBuild/footer.kmk@ 1465

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

Fixed another template loading bug.

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