source: trunk/kBuild/footer.kmk@ 1413

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

keyword inheritance.

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