source: trunk/kBuild/footer.kmk@ 2510

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

footer.kmk: Link _INST/_STAGE props should be treated as filenames when no trailing slash is present.

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