source: trunk/kBuild/footer.kmk@ 2511

Last change on this file since 2511 was 2511, checked in by bird, 14 years ago

footer.kmk: Another link target install fix.

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