source: trunk/kBuild/footer.kmk@ 2026

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

footer.kmk: Use .MUST_MAKE when available.

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