source: trunk/kBuild/footer.kmk@ 1428

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

do defpath transformation of sources before handing them on to the src_handlers.

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