source: trunk/kBuild/footer.kmk@ 2240

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

footer.kmk,subheader.kmk,subfooter.kmk,qt3.kmk,qt4.kmk: PATH_$(target) -> $(target)_0_OUTDIR, old variable is still valid for a while. References #57.

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