source: trunk/kBuild/footer.kmk@ 2007

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

footer.kmk,tests: Convert simple variables into recursive ones by means of a helper variable during inheritance. This fixes the problem with forward references in a template when the target defined the property(.keyword) using a simple assignmnet. Fixes #51.

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