source: trunk/kBuild/footer.kmk@ 1415

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

docs update.

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