source: trunk/kBuild/footer.kmk@ 2430

Last change on this file since 2430 was 2429, checked in by bird, 15 years ago

footer.kmk: Workaround for ticket #99. Ref #99.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 124.7 KB
Line 
1# $Id: footer.kmk 2429 2010-11-16 15:20:59Z bird $
2## @file
3# kBuild - File included at top of makefile.
4#
5
6#
7# Copyright (c) 2004-2010 knut st. osmundsen <bird-kBuild-spamx@anduin.net>
8#
9# This file is part of kBuild.
10#
11# kBuild is free software; you can redistribute it and/or modify
12# it under the terms of the GNU General Public License as published by
13# the Free Software Foundation; either version source of the License, or
14# (at your option) any later version.
15#
16# kBuild is distributed in the hope that it will be useful,
17# but WITHOUT ANY WARRANTY; without even the implied warranty of
18# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19# GNU General Public License for more details.
20#
21# You should have received a copy of the GNU General Public License
22# along with kBuild; if not, write to the Free Software
23# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24#
25#
26# As a special exception you are granted permission to include this file, via
27# the kmk include directive, as you wish without this in itself causing the
28# resulting makefile, program or whatever to be covered by the GPL license.
29# This exception does not however invalidate any other reasons why the makefile,
30# program, whatever should not be covered the GPL.
31#
32#
33
34ifndef __footer_kmk__
35# start-of-file-content
36ifdef KBUILD_PROFILE_SELF
37 $(evalcall def_profile_self, start of footer.kmk)
38 _KBUILD_TS_FOOTER_START := $(_KBUILD_TS_PREV)
39endif
40
41#
42# Variables.
43# (Some of these need initialization before including definitions using them.)
44#
45
46# All targets of each types.
47_ALL_BLDPROGS := $(BLDPROGS) $(BLDPROGS.$(KBUILD_HOST)) $(BLDPROGS.$(KBUILD_HOST).$(KBUILD_HOST_ARCH)) $(BLDPROGS.$(KBUILD_HOST_ARCH)) $(BLDPROGS.$(KBUILD_HOST_CPU)) $(BLDPROGS.$(KBUILD_TYPE))
48_ALL_LIBRARIES := $(LIBRARIES) $(LIBRARIES.$(KBUILD_TARGET)) $(LIBRARIES.$(KBUILD_TARGET).$(KBUILD_TARGET_ARCH)) $(LIBRARIES.$(KBUILD_TARGET_ARCH)) $(LIBRARIES.$(KBUILD_TARGET_CPU)) $(LIBRARIES.$(KBUILD_TYPE))
49_ALL_IMPORT_LIBS := $(IMPORT_LIBS) $(IMPORT_LIBS.$(KBUILD_TARGET)) $(IMPORT_LIBS.$(KBUILD_TARGET).$(KBUILD_TARGET_ARCH)) $(IMPORT_LIBS.$(KBUILD_TARGET_ARCH)) $(IMPORT_LIBS.$(KBUILD_TARGET_CPU)) $(IMPORT_LIBS.$(KBUILD_TYPE))
50_ALL_DLLS := $(DLLS) $(DLLS.$(KBUILD_TARGET)) $(DLLS.$(KBUILD_TARGET).$(KBUILD_TARGET_ARCH)) $(DLLS.$(KBUILD_TARGET_ARCH)) $(DLLS.$(KBUILD_TARGET_CPU)) $(DLLS.$(KBUILD_TYPE))
51_ALL_PROGRAMS := $(PROGRAMS) $(PROGRAMS.$(KBUILD_TARGET)) $(PROGRAMS.$(KBUILD_TARGET).$(KBUILD_TARGET_ARCH)) $(PROGRAMS.$(KBUILD_TARGET_ARCH)) $(PROGRAMS.$(KBUILD_TARGET_CPU)) $(PROGRAMS.$(KBUILD_TYPE))
52_ALL_SYSMODS := $(SYSMODS) $(SYSMODS.$(KBUILD_TARGET)) $(SYSMODS.$(KBUILD_TARGET).$(KBUILD_TARGET_ARCH)) $(SYSMODS.$(KBUILD_TARGET_ARCH)) $(SYSMODS.$(KBUILD_TARGET_CPU)) $(SYSMODS.$(KBUILD_TYPE))
53_ALL_MISCBINS := $(MISCBINS) $(MISCBINS.$(KBUILD_TARGET)) $(MISCBINS.$(KBUILD_TARGET).$(KBUILD_TARGET_ARCH)) $(MISCBINS.$(KBUILD_TARGET_ARCH)) $(MISCBINS.$(KBUILD_TARGET_CPU)) $(MISCBINS.$(KBUILD_TYPE))
54_ALL_OTHERS := $(OTHERS) $(OTHERS.$(KBUILD_TARGET)) $(OTHERS.$(KBUILD_TARGET).$(KBUILD_TARGET_ARCH)) $(OTHERS.$(KBUILD_TARGET_ARCH)) $(OTHERS.$(KBUILD_TARGET_CPU)) $(OTHERS.$(KBUILD_TYPE))
55_ALL_INSTALLS := $(INSTALLS) $(INSTALLS.$(KBUILD_TARGET)) $(INSTALLS.$(KBUILD_TARGET).$(KBUILD_TARGET_ARCH)) $(INSTALLS.$(KBUILD_TARGET_ARCH)) $(INSTALLS.$(KBUILD_TARGET_CPU)) $(INSTALLS.$(KBUILD_TYPE))
56_ALL_FETCHES := $(FETCHES) $(FETCHES.$(KBUILD_TARGET)) $(FETCHES.$(KBUILD_TARGET).$(KBUILD_TARGET_ARCH)) $(FETCHES.$(KBUILD_TARGET_ARCH)) $(FETCHES.$(KBUILD_TARGET_CPU)) $(FETCHES.$(KBUILD_TYPE))
57_ALL_PATCHES := $(PATCHES) $(PATCHES.$(KBUILD_TARGET)) $(PATCHES.$(KBUILD_TARGET).$(KBUILD_TARGET_ARCH)) $(PATCHES.$(KBUILD_TARGET_ARCH)) $(PATCHES.$(KBUILD_TARGET_CPU)) $(PATCHES.$(KBUILD_TYPE))
58
59# all targets.
60_ALL_TARGETS = \
61 $(_ALL_FETCHES) \
62 $(_ALL_PATCHES) \
63 $(_ALL_BLDPROGS) \
64 $(_ALL_LIBRARIES) \
65 $(_ALL_IMPORT_LIBS) \
66 $(_ALL_DLLS) \
67 $(_ALL_PROGRAMS) \
68 $(_ALL_SYSMODS) \
69 $(_ALL_MISCBINS) \
70 $(_ALL_INSTALLS) \
71 $(_ALL_OTHERS)
72
73# all $(KBUILD_TARGET) targets.
74_ALL_TARGET_TARGETS = \
75 $(_ALL_FETCHES) \
76 $(_ALL_PATCHES) \
77 $(_ALL_LIBRARIES) \
78 $(_ALL_IMPORT_LIBS) \
79 $(_ALL_DLLS) \
80 $(_ALL_PROGRAMS) \
81 $(_ALL_SYSMODS) \
82 $(_ALL_MISCBINS) \
83 $(_ALL_INSTALLS) \
84 $(_ALL_OTHERS)
85
86# all $(KBUILD_HOST) targets.
87_ALL_HOST_TARGETS = \
88 $(_ALL_BLDPROGS)
89
90# all targets making use of srcname.
91_ALL_SRCNAME_TARGETS = \
92 $(_ALL_FETCHES) \
93 $(_ALL_PATCHES)
94
95# Dependency files. (currently not on target level, only this global stuff)
96_DEPFILES := $(DEPFILES) $(DEPFILES.$(KBUILD_TARGET)) $(DEPFILES.$(KBUILD_TARGET).$(KBUILD_TARGET_ARCH)) $(DEPFILES.$(KBUILD_TARGET_ARCH)) $(DEPFILES.$(KBUILD_TARGET_CPU)) $(DEPFILES.$(KBUILD_TYPE))
97
98# included dependency files.
99_DEPFILES_INCLUDED :=
100
101
102# All kind of output files except for _OBJS and _DEPFILES.
103# Compiling or linking definition outputting other things that $@ and any
104# required dependency file must add those output files to this variable.
105_OUT_FILES :=
106
107# Files which only requires cleaning up.
108_CLEAN_FILES :=
109
110# all of a type
111_OBJS :=
112_FETCHES :=
113_DOWNLOADS:=
114_UNPACKS :=
115_PATCHES :=
116_UNFETCHES:=
117_BLDPROGS :=
118_LIBS :=
119_DLLS :=
120_PROGRAMS :=
121_SYSMODS :=
122_MISCBINS :=
123_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
988define def_inherit_template_workaround_target
989local _tmpl := $(firstword $($(target)_TEMPLATE) $(TEMPLATE))
990local _bld_type := $(firstword $($(target)_BLD_TYPE) $(TEMPLATE_$(tmpl)_BLD_TYPE) $(KBUILD_TYPE))
991local _bld_trg := $(firstword $($(target)_BLD_TRG) $(TEMPLATE_$(tmpl)_BLD_TRG) $(KBUILD_TARGET))
992local _bld_trg_arch := $(firstword $($(target)_BLD_TRG_ARCH) $(TEMPLATE_$(tmpl)_BLD_TRG_ARCH) $(KBUILD_TARGET_ARCH))
993local _bld_trg_cpu := $(firstword $($(target)_BLD_TRG_CPU) $(TEMPLATE_$(tmpl)_BLD_TRG_CPU) $(KBUILD_TARGET_CPU))
994$(kb-exp-tmpl 1,$(target),$(_bld_trg),$(_bld_trg_arch),$(_bld_trg_cpu),$(_bld_type))
995endef # def_inherit_template_workaround_target
996#$(kb-exp-tmpl 1,$(_ALL_TARGET_TARGETS),$(KBUILD_TARGET),$(KBUILD_TARGET_ARCH),$(KBUILD_TARGET_CPU),$(KBUILD_TYPE))
997$(foreach target,$(_ALL_TARGET_TARGETS),$(evalval def_inherit_template_workaround_target))
998
999define def_inherit_template_workaround_host
1000local _tmpl := $(firstword $($(target)_TEMPLATE) $(TEMPLATE))
1001local _bld_type := $(firstword $($(target)_BLD_TYPE) $(TEMPLATE_$(tmpl)_BLD_TYPE) $(KBUILD_TYPE))
1002local _bld_trg := $(firstword $($(target)_BLD_TRG) $(TEMPLATE_$(tmpl)_BLD_TRG) $(KBUILD_HOST))
1003local _bld_trg_arch := $(firstword $($(target)_BLD_TRG_ARCH) $(TEMPLATE_$(tmpl)_BLD_TRG_ARCH) $(KBUILD_HOST_ARCH))
1004local _bld_trg_cpu := $(firstword $($(target)_BLD_TRG_CPU) $(TEMPLATE_$(tmpl)_BLD_TRG_CPU) $(KBUILD_HOST_CPU))
1005$(kb-exp-tmpl 1,$(target),$(_bld_trg),$(_bld_trg_arch),$(_bld_trg_cpu),$(_bld_type))
1006endef # def_inherit_template_workaround_target
1007#$(kb-exp-tmpl 1,$(_ALL_HOST_TARGETS),$(KBUILD_HOST),$(KBUILD_HOST_ARCH),$(KBUILD_HOST_CPU),$(KBUILD_TYPE))
1008$(foreach target,$(_ALL_HOST_TARGETS),$(evalval def_inherit_template_workaround_host))
1009
1010ifdef KBUILD_PROFILE_SELF
1011 $(evalcall def_profile_self, done template/target expansion)
1012endif
1013
1014
1015#
1016# Include tools, sdks and units.
1017#
1018# The first part of this exercise is to figure out which TOOLS and SDKS
1019# that should be included.
1020#
1021_TOOLS := $(TOOL.$(KBUILD_TARGET)) $(TOOL.$(KBUILD_TARGET_ARCH)) $(TOOL.$(KBUILD_TARGET).$(KBUILD_TARGET_ARCH)) \
1022 $(TOOL.$(KBUILD_HOST)) $(TOOL.$(KBUILD_HOST_ARCH)) $(TOOL.$(KBUILD_HOST).$(KBUILD_HOST_ARCH)) \
1023 $(TOOL)
1024_SDKS := $(SDKS.$(KBUILD_TARGET)) $(SDKS.$(KBUILD_TARGET_ARCH)) $(SDKS.$(KBUILD_TARGET).$(KBUILD_TARGET_ARCH)) \
1025 $(SDKS.$(KBUILD_HOST)) $(SDKS.$(KBUILD_HOST_ARCH)) $(SDKS.$(KBUILD_HOST).$(KBUILD_HOST_ARCH)) \
1026 $(SDKS.$(KBUILD_TYPE)) \
1027 $(SDKS)
1028_USES := $(USES.$(KBUILD_TARGET)) $(USES.$(KBUILD_TARGET_ARCH)) $(USES.$(KBUILD_TARGET).$(KBUILD_TARGET_ARCH)) \
1029 $(USES.$(KBUILD_HOST)) $(USES.$(KBUILD_HOST_ARCH)) $(USES.$(KBUILD_HOST).$(KBUILD_HOST_ARCH)) \
1030 $(USES.$(KBUILD_TYPE)) \
1031 $(USES)
1032define def_tools_sdks_target_source
1033$(eval _TOOLS += $(foreach prop, $(PROPS_TOOLS), \
1034 $($(source)_$(prop).$(_bld_trg)) \
1035 $($(target)_$(source)_$(prop).$(_bld_trg)) \
1036 $($(source)_$(prop).$(_bld_trg).$(_bld_trg_arch)) \
1037 $($(target)_$(source)_$(prop).$(_bld_trg).$(_bld_trg_arch)) \
1038 $($(source)_$(prop).$(_bld_trg_arch)) \
1039 $($(target)_$(source)_$(prop).$(_bld_trg_arch)) \
1040 $($(source)_$(prop)) \
1041 $($(target)_$(source)_$(prop))))
1042$(eval _SDKS += \
1043 $($(source)_SDKS.$(_bld_trg)) \
1044 $($(target)_$(source)_SDKS.$(_bld_trg)) \
1045 $($(source)_SDKS.$(_bld_trg).$(_bld_trg_arch)) \
1046 $($(target)_$(source)_SDKS.$(_bld_trg).$(_bld_trg_arch)) \
1047 $($(source)_SDKS.$(_bld_trg_arch)) \
1048 $($(target)_$(source)_SDKS.$(_bld_trg_arch)) \
1049 $($(source)_SDKS.$(KBUILD_TYPE)) \
1050 $($(target)_$(source)_SDKS.$(KBUILD_TYPE)) \
1051 $($(source)_SDKS) \
1052 $($(target)_$(source)_SDKS))
1053$(eval _USES += \
1054 $($(source)_USES.$(_bld_trg)) \
1055 $($(target)_$(source)_USES.$(_bld_trg)) \
1056 $($(source)_USES.$(_bld_trg).$(_bld_trg_arch)) \
1057 $($(target)_$(source)_USES.$(_bld_trg).$(_bld_trg_arch)) \
1058 $($(source)_USES.$(_bld_trg_arch)) \
1059 $($(target)_$(source)_USES.$(_bld_trg_arch)) \
1060 $($(source)_USES.$(KBUILD_TYPE)) \
1061 $($(target)_$(source)_USES.$(KBUILD_TYPE)) \
1062 $($(source)_USES) \
1063 $($(target)_$(source)_USES))
1064endef # def_tools_sdks_target_source
1065$(eval-opt-var def_tools_sdks_target_source)
1066
1067define def_tools_sdks_target
1068local _bld_type := $(firstword $($(target)_BLD_TYPE) $(KBUILD_TYPE))
1069local _bld_trg := $(firstword $($(target)_BLD_TRG) $(bld_trg))
1070local _bld_trg_arch := $(firstword $($(target)_BLD_TRG_ARCH) $(bld_trg_arch))
1071local _bld_trg_cpu := $(firstword $($(target)_BLD_TRG_CPU) $(bld_trg_cpu))
1072
1073$(eval _TOOLS += $(foreach prop, $(PROPS_TOOLS), \
1074 $($(target)_$(prop).$(_bld_trg)) \
1075 $($(target)_$(prop).$(_bld_trg_arch)) \
1076 $($(target)_$(prop).$(_bld_trg).$(_bld_trg_arch)) \
1077 $($(target)_$(prop))))
1078$(eval _SDKS += \
1079 $($(target)_SDKS.$(_bld_trg)) \
1080 $($(target)_SDKS.$(_bld_trg_arch)) \
1081 $($(target)_SDKS.$(_bld_trg).$(_bld_trg_arch)) \
1082 $($(target)_SDKS))
1083$(eval _USES += \
1084 $($(target)_USES.$(_bld_trg)) \
1085 $($(target)_USES.$(_bld_trg_arch)) \
1086 $($(target)_USES.$(_bld_trg).$(_bld_trg_arch)) \
1087 $($(target)_USES))
1088$(foreach source, \
1089 $($(target)_SOURCES.$(_bld_trg)) \
1090 $($(target)_SOURCES.$(_bld_trg_arch)) \
1091 $($(target)_SOURCES.$(_bld_trg).$(_bld_trg_arch)) \
1092 $($(target)_SOURCES.$(_bld_trg_cpu)) \
1093 $($(target)_SOURCES.$(_bld_type)) \
1094 $($(target)_SOURCES) \
1095 , $(evalval def_tools_sdks_target_source))
1096endef # def_tools_sdks_target
1097$(eval-opt-var def_tools_sdks_target)
1098
1099define def_tools_srcname_target
1100local _bld_type := $(firstword $($(target)_BLD_TYPE) $(KBUILD_TYPE))
1101local _bld_trg := $(firstword $($(target)_BLD_TRG) $(bld_trg))
1102local _bld_trg_arch := $(firstword $($(target)_BLD_TRG_ARCH) $(bld_trg_arch))
1103local _bld_trg_cpu := $(firstword $($(target)_BLD_TRG_CPU) $(bld_trg_cpu))
1104
1105$(foreach source, $(notdir\
1106 $($(target)_SOURCES.$(_bld_trg)) \
1107 $($(target)_SOURCES.$(_bld_trg_arch)) \
1108 $($(target)_SOURCES.$(_bld_trg).$(_bld_trg_arch)) \
1109 $($(target)_SOURCES.$(_bld_trg_cpu)) \
1110 $($(target)_SOURCES.$(_bld_type)) \
1111 $($(target)_SOURCES) \
1112 ), $(evalval def_tools_sdks_target_source))
1113endef # def_tools_srcname_target
1114$(eval-opt-var def_tools_srcname_target)
1115
1116bld_trg := $(KBUILD_TARGET)
1117bld_trg_arch := $(KBUILD_TARGET_ARCH)
1118bld_trg_cpu := $(KBUILD_TARGET_CPU)
1119$(foreach target, $(_ALL_TARGET_TARGETS), $(evalval def_tools_sdks_target))
1120$(foreach target, $(_ALL_SRCNAME_TARGETS), $(evalval def_tools_srcname_target))
1121
1122bld_trg := $(KBUILD_HOST)
1123bld_trg_arch := $(KBUILD_HOST_ARCH)
1124bld_trg_cpu := $(KBUILD_HOST_CPU)
1125$(foreach target, $(_ALL_HOST_TARGETS), $(evalval def_tools_sdks_target))
1126
1127_TOOLS := $(sort $(_TOOLS))
1128_SDKS := $(sort $(_SDKS))
1129
1130## Tool load function.
1131# @param loading The tool name
1132define def_tools_load_function
1133ifndef TOOL_$(loading)
1134 TOOL_$(loading)_KMK_FILE := $(firstword $(foreach path, $(KBUILD_TOOL_PATHS) $(KBUILD_PATH)/tools $(KBUILD_DEFAULT_PATHS), $(wildcard $(path)/$(loading).kmk)))
1135 ifeq ($(TOOL_$(loading)_KMK_FILE),)
1136 $(error kBuild: Cannot find include file for the tool '$(loading)'! Searched: $(KBUILD_TOOL_PATHS) $(KBUILD_PATH)/tools $(KBUILD_DEFAULT_PATHS))
1137 endif
1138 include $(TOOL_$(loading)_KMK_FILE)
1139 ifndef TOOL_$(loading)
1140 $(warning kBuild: TOOL_$(loading) was not defined by $(TOOL_$(loading)_KMK_FILE)!)
1141 endif
1142endif
1143endef # def_tools_include
1144
1145## SDK load function.
1146# @param loading The tool name
1147define def_sdk_load_function
1148ifndef SDK_$(loading)
1149 SDK_$(loading)_KMK_FILE := $(firstword $(foreach path, $(KBUILD_SDK_PATHS) $(KBUILD_PATH)/sdks $(KBUILD_DEFAULT_PATHS), $(wildcard $(path)/$(loading).kmk)))
1150 ifeq ($(SDK_$(loading)_KMK_FILE),)
1151 $(error kBuild: Cannot find include file for the SDK '$(loading)'! Searched: $(KBUILD_SDK_PATHS) $(KBUILD_PATH)/sdks $(KBUILD_DEFAULT_PATHS))
1152 endif
1153 include $(SDK_$(loading)_KMK_FILE)
1154 ifndef SDK_$(loading)
1155 $(warning kBuild: SDK_$(loading) was not defined by $(SDK_$(loading)_KMK_FILE)!)
1156 endif
1157endif
1158endef # def_sdk_load_function
1159
1160
1161properties :=
1162properties_now_l :=
1163properties_now_r :=
1164properties_deferred := $(PROPS_SINGLE) $(PROPS_DEFERRED)
1165properties_deferred_l := $(PROPS_ACCUMULATE_L)
1166properties_deferred_r := $(PROPS_ACCUMULATE_R)
1167
1168src_prefix := SDK_
1169load_function := def_sdk_load_function
1170$(foreach trg, $(addprefix SDK_,$(_SDKS)), $(evalval def_inherit))
1171
1172properties_deferred := $(PROPS_SINGLE) $(PROPS_DEFERRED) $(PROPS_TOOLS_ONLY)
1173src_prefix := TOOL_
1174load_function := def_tools_load_function
1175$(foreach trg, $(addprefix TOOL_,$(_TOOLS)), $(evalval def_inherit))
1176
1177# done inheriting.
1178src_prefix :=
1179load_function :=
1180properties :=
1181properties_now_l :=
1182properties_now_r :=
1183properties_deferred :=
1184properties_deferred_l :=
1185properties_deferred_r :=
1186
1187# No inheriting for the uses, they're just global 'code'.
1188$(foreach loading, $(_USES), $(evalval def_unit_load_function))
1189
1190
1191ifdef KBUILD_PROFILE_SELF
1192 $(evalcall def_profile_self, done tools + sdks + units)
1193endif
1194
1195
1196
1197#
1198#
1199# Target lists - Pass 1
1200#
1201# This pass is for defining variables that might be referenced in
1202# properties of other targets.
1203#
1204#
1205
1206# Don't do anything for fetch targets (yet).
1207
1208##
1209# Link prolog for Pass 1.
1210#
1211# @param $(target) Normalized target name.
1212# @param $(EXT) EXE,DLL,SYS,LIB.
1213# @param $(EXTPRE) HOST or nothing.
1214# @param $(definst) The default _INST value.
1215# @param $(tool_prefix) LD or AR.
1216# @param $(bld_trg_base_var) TARGET or PLATFORM.
1217define def_pass1_link_common
1218
1219local bld_type := $(firstword $($(target)_BLD_TYPE) $(KBUILD_TYPE))
1220local bld_trg := $(firstword $($(target)_BLD_TRG) $(BUILD_$(bld_trg_base_var)))
1221local bld_trg_arch:= $(firstword $($(target)_BLD_TRG_ARCH) $(BUILD_$(bld_trg_base_var)_ARCH))
1222local bld_trg_cpu := $(firstword $($(target)_BLD_TRG_CPU) $(BUILD_$(bld_trg_base_var)_CPU))
1223
1224local tool := $(call _TARGET_TOOL,$(target),$(tool_prefix))
1225local name := $(firstword\
1226 $($(target)_NAME.$(bld_trg).$(bld_trg_arch))\
1227 $($(target)_NAME.$(bld_trg_arch))\
1228 $($(target)_NAME.$(bld_trg))\
1229 $($(target)_NAME.$(bld_type))\
1230 $($(target)_NAME)\
1231 $(target))
1232local outbase := $(call TARGET_BASE,$(name),$(target))
1233$(target)_0_OUTDIR:= $(patsubst %/,%,$(dir $(outbase)))
1234PATH_$(target) := $($(target)_0_OUTDIR)
1235## @todo fix the fun at the last line (AR != LIB => mess).
1236local suff := $(firstword \
1237 $($(target)_$(EXT)SUFF.$(bld_trg).$(bld_trg_arch))\
1238 $($(target)_$(EXT)SUFF.$(bld_trg))\
1239 $($(target)_$(EXT)SUFF)\
1240 $(TOOL_$(tool)_$(tool_prefix)$(EXT)SUFF.$(bld_trg).$(bld_trg_arch))\
1241 $(TOOL_$(tool)_$(tool_prefix)$(EXT)SUFF.$(bld_trg))\
1242 $(TOOL_$(tool)_$(tool_prefix)$(EXT)SUFF)\
1243 $(if $(eq $(tool_prefix),AR),$(SUFF_LIB),$($(EXTPRE)SUFF_$(EXT))) )
1244local out := $(outbase)$(suff)
1245
1246# TARGET_*
1247TARGET_$(target) := $(out)
1248$(target)_1_TARGET := $(out)
1249
1250# INSTARGET_*
1251ifeq ($(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))),)
1252 ifneq ($(strip $($(target)_INST.$(bld_trg).$(bld_trg_arch).$(bld_type))),)
1253 local inst := $(addprefix $(PATH_INS)/,$($(target)_INST.$(bld_trg).$(bld_trg_arch).$(bld_type)))
1254 else ifneq ($(strip $($(target)_INST.$(bld_trg).$(bld_trg_arch))),)
1255 local inst := $(addprefix $(PATH_INS)/,$($(target)_INST.$(bld_trg).$(bld_trg_arch)))
1256 else ifneq ($(strip $($(target)_INST.$(bld_trg).$(bld_type))),)
1257 local inst := $(addprefix $(PATH_INS)/,$($(target)_INST.$(bld_trg).$(bld_type)))
1258 else ifneq ($(strip $($(target)_INST.$(bld_trg_arch))),)
1259 local inst := $(addprefix $(PATH_INS)/,$($(target)_INST.$(bld_trg_arch)))
1260 else ifneq ($(strip $($(target)_INST.$(bld_trg))),)
1261 local inst := $(addprefix $(PATH_INS)/,$($(target)_INST.$(bld_trg)))
1262 else ifneq ($(strip $($(target)_INST.$(bld_type))),)
1263 local inst := $(addprefix $(PATH_INS)/,$($(target)_INST.$(bld_type)))
1264 else ifneq ($(strip $($(target)_INST)),)
1265 local inst := $(addprefix $(PATH_INS)/,$($(target)_INST))
1266 else
1267 local inst := $(definst)/
1268 endif
1269 INSTARGET_$(target) := $(patsubst %/,%/$(notdir $(out)),$(inst))
1270
1271else # NOINST
1272 INSTARGET_$(target) :=
1273endif # NOINST
1274
1275endef
1276$(eval-opt-var def_pass1_link_common)
1277
1278
1279#
1280# BLDPROGS (Pass 1)
1281#
1282define def_pass1_bldprog
1283# set NOINST if not forced installation before doing the usual stuff.
1284ifndef $(target)_INST
1285$(target)_NOINST := 1
1286endif
1287$(evalval def_pass1_link_common)
1288endef
1289
1290EXT := EXE
1291EXTPRE := HOST
1292definst := $(PATH_BIN)
1293tool_prefix := LD
1294bld_trg_base_var := PLATFORM
1295$(foreach target, $(_ALL_BLDPROGS), \
1296 $(evalval def_pass1_bldprog))
1297
1298
1299#
1300# LIBRARIES (Pass 1)
1301#
1302EXT := LIB
1303EXTPRE :=
1304definst := $(PATH_LIB)
1305tool_prefix := AR
1306bld_trg_base_var := TARGET
1307$(foreach target, $(_ALL_LIBRARIES), \
1308 $(evalval def_pass1_link_common))
1309
1310
1311#
1312# DLLS (Pass 1)
1313#
1314EXT := DLL
1315EXTPRE :=
1316definst := $(PATH_DLL)
1317tool_prefix := LD
1318bld_trg_base_var := TARGET
1319$(foreach target, $(_ALL_DLLS), \
1320 $(evalval def_pass1_link_common))
1321
1322
1323#
1324# IMPORT LIBRARIES (Pass 1)
1325#
1326# - On OS/2 and windows these are libraries.
1327# - On other platforms they are fake DLLs.
1328#
1329if1of ($(KBUILD_TARGET), nt os2 win win64 win32)
1330 EXT := LIB
1331 EXTPRE :=
1332 definst := $(PATH_LIB)
1333 tool_prefix := AR
1334 bld_trg_base_var := TARGET
1335 $(foreach target, $(_ALL_IMPORT_LIBS), \
1336 $(evalval def_pass1_link_common))
1337else
1338 EXT := DLL
1339 EXTPRE :=
1340 definst := $(PATH_DLL)
1341 tool_prefix := LD
1342 bld_trg_base_var := TARGET
1343 $(foreach target, $(_ALL_IMPORT_LIBS), \
1344 $(evalval def_pass1_link_common))
1345endif
1346
1347
1348#
1349# PROGRAMS (Pass 1)
1350#
1351EXT := EXE
1352EXTPRE :=
1353definst := $(PATH_BIN)
1354tool_prefix := LD
1355bld_trg_base_var := TARGET
1356$(foreach target, $(_ALL_PROGRAMS), \
1357 $(evalval def_pass1_link_common))
1358
1359
1360#
1361# SYSMODS (Pass 1)
1362#
1363EXT := SYS
1364EXTPRE :=
1365definst := $(PATH_SYS)
1366tool_prefix := LD
1367bld_trg_base_var := TARGET
1368$(foreach target, $(_ALL_SYSMODS), \
1369 $(evalval def_pass1_link_common))
1370
1371
1372#
1373# MISCBINS (Pass 1)
1374#
1375EXT := BIN
1376EXTPRE :=
1377definst := $(PATH_BIN)
1378tool_prefix := LD
1379bld_trg_base_var := TARGET
1380$(foreach target, $(_ALL_MISCBINS), \
1381 $(evalval def_pass1_link_common))
1382
1383
1384#
1385# INSTALLS (Pass 1)
1386# Note! INSTARGET_* for INSTALLS aren't available until later.
1387#
1388define def_pass1_install
1389local bld_type := $(firstword $($(target)_BLD_TYPE) $(KBUILD_TYPE))
1390local bld_trg := $(firstword $($(target)_BLD_TRG) $(KBUILD_TARGET))
1391local bld_trg_arch := $(firstword $($(target)_BLD_TRG_ARCH) $(KBUILD_TARGET_ARCH))
1392local bld_trg_cpu := $(firstword $($(target)_BLD_TRG_CPU) $(KBUILD_TARGET_CPU))
1393# TARGET_*
1394$(target)_1_TARGET := $(PATH_TARGET)/$(target).ins
1395TARGET_$(target) := $($(target)_1_TARGET)
1396
1397# INSTARGET_ later.
1398# PATH_*
1399local outbase := $(call TARGET_BASE,$(target),$(target))
1400$(target)_0_OUTDIR := $(patsubst %/,%,$(dir $(outbase)))
1401PATH_$(target) := $($(target)_0_OUTDIR)
1402endef # def_pass1_install
1403$(eval-opt-var def_pass1_install)
1404$(foreach target, $(_ALL_INSTALLS), \
1405 $(evalval def_pass1_install))
1406
1407ifdef KBUILD_PROFILE_SELF
1408 $(evalcall def_profile_self, done pass 1)
1409endif
1410
1411
1412
1413
1414#
1415#
1416# Target lists - Pass 2
1417#
1418#
1419
1420
1421## @page pg_fetches Fetching Tools, Sources and Similar.
1422#
1423# The targets listed in the the FETCHES target list have the following attributes:
1424# SOURCES
1425# INST
1426# FETCHTOOL
1427# FETCHFLAGS
1428# FETCHDIR
1429# UNPACKTOOL
1430# UNPACKFLAGS
1431#
1432# As usual the target name is an alias for 'creating' the target. Other
1433# aliases are:
1434# pass_fetches
1435# fetch
1436# unfetch
1437# download
1438# unpack
1439#
1440# @remark
1441#
1442# This is a little bit complex because we must guarantee that if a source file
1443# changes only sligtly we must refetch it and to a proper unpacking of it. It
1444# is also a desire that fetched archives and unpacked files can be deleted to
1445# save space.
1446#
1447# Thus, we must be able to cleanup what we've unpacked should any of the
1448# sources be removed. We do this by maintaining a file listing the files
1449# and directories that was unpacked. This operation is named 'unfetch'.
1450#
1451# We make use of the SIZE and MD5 attributes for each of the sources to
1452# create a digest that is stored in the primary target file. Subsequent
1453# runswill compare their digest with it to decide if a refetch is required.
1454# When a refetch is found necessary, an 'unfetch' is performed first to
1455# clean out old files and directores. Note even changes in source order
1456# will cause a refetch due to the way the digest is constructed and
1457# evaluated.
1458#
1459# By not depending directly on the archives (nor on any unpacked files)
1460# but on a goal made up from the archive name, size and md5, we allow
1461# the user to delete the archives. Naturally, this means we'll have to
1462# check and fetch missing archives before attempting to unpack them.
1463#
1464# @remark
1465#
1466# This feature will *NOT* work correctly with vanilla GNU make becuase
1467# it makes use of includedep to avoid too many unnecessary files.
1468#
1469# @todo
1470# 0. Move the fetches out into a unit.
1471# 1. Download corruption / continuation.
1472# 2. It's quite possible that there is one too many indirect dependency now...
1473#
1474
1475## generates the fetch rule
1476define def_fetch_src_fetch_rule
1477# Indirect goal for downloading something.
1478.PRECIOUS: $(out)
1479$(out) + $($(target)_$(srcname)_FETCH_2_OUTPUT) +| $($(target)_$(srcname)_FETCH_2_OUTPUT_MAYBE) : \
1480 | $($(target)_$(srcname)_FETCH_2_DEPORD)
1481 %$$(call MSG_FETCH_DL,$(target),$(source),$(out))
1482 @## @todo do fancy stuff like download continuation.
1483 $$(QUIET)$$(RM) -f -- $(out)
1484 $(cmds)
1485 $$(QUIET)$(if $(md5),$$(MD5SUM_EXT) -b -C $(md5) $(out))
1486
1487
1488
1489# Intermediate goal for making sure the md5 and size matches. it will (re) fetch the archive if necessary.
1490$(out).checked_$(md5)_$(size): $($(target)_$(srcname)_FETCH_2_DEPEND) | $($(target)_$(srcname)_FETCH_2_DEPORD)
1491 %$$(call MSG_FETCH_CHK,$(target),$(source),$(out))
1492 $$(QUIET)$$(RM) -f -- $$@
1493 @# (re)fetch the file if it doesn't exist or if it doesn't matches the md5.
1494 @## @todo do fancy stuff like download continuation.
1495 $$(QUIET)( test -f $(out) && $(if $(md5),$$(MD5SUM_EXT) -b -C $(md5) $(out), true) ) \
1496 || ( $$(RM_EXT) -f $(out) \
1497 && $$(MAKE) $(out) -f $(MAKEFILE) --no-print-directory )
1498 $$(QUIET2)$$(APPEND) $$@
1499
1500_TARGET_$(target)_FETCHED += $(out) $(out).checked_$(md5)_$(size)
1501
1502# Just a little precaution.
1503.NOTPARALLEL: $(out) $(out).checked_$(md5)_$(size)
1504
1505endef # def_fetch_src_fetch_rule
1506$(eval-opt-var def_fetch_src_fetch_rule)
1507
1508## generates the unpack rule
1509define def_fetch_src_unpack_rule
1510# This is the unpack rule. it has an order-only dependency on the download check.
1511$(out) + $($(target)_$(srcname)_UNPACK_2_OUTPUT) +| $($(target)_$(srcname)_UNPACK_2_OUTPUT_MAYBE) : \
1512 $($(target)_$(srcname)_UNPACK_2_DEPEND) \
1513 | $($(target)_$(srcname)_UNPACK_2_DEPORD) \
1514 $(archive).checked_$(md5)_$(size) \
1515 $(dir $(out))
1516 %$$(call MSG_FETCH_UP,$(target),$(archive),$(inst))
1517 $$(QUIET)$$(RM) -f -- $(out)
1518 $$(QUIET)$$(MKDIR) -p -- $(dir $(out))
1519 @# if the source archive doesn't exist fetch it (may have been deleted to save space).
1520 $$(QUIET)test -f $(archive) \
1521 || ( $$(RM_EXT) -f $(archive).checked_$(md5)_$(size) \
1522 && $$(MAKE) $(archive).checked_$(md5)_$(size) -f $(MAKEFILE) --no-print-directory )
1523 $(cmds)
1524 $$(QUIET2)$$(APPEND) $(out) $(notdir $(archive).checked_$(md5)_$(size))
1525 $$(QUIET2)$$(APPEND) $(out) $(notdir $(out))
1526
1527$(eval _TARGET_$(target)_UNPACKED += $(out))
1528_TARGET_$(target)_DIGEST := $(_TARGET_$(target)_DIGEST)-$(srcname)_$(md5)_$(size)
1529
1530.NOTPARALLEL: $(out)
1531
1532endef # def_fetch_src_unpack_rule
1533$(eval-opt-var def_fetch_src_unpack_rule)
1534
1535## Processes a fetch source
1536#
1537define def_fetch_src
1538#$ (warning dbg: def_fetch_src: source='$(source)' target='$(target)')
1539
1540# common
1541local srcname := $(notdir $(source))
1542local inst := $(firstword \
1543 $($(target)_$(source)_INST)\
1544 $($(target)_$(srcname)_INST)\
1545 $($(source)_INST)\
1546 $($(srcname)_INST)\
1547 $($(target)_INST)\
1548)
1549ifneq ($(patsubst %/,ok,$(inst)),ok)
1550$(error kBuild: Bad or missing INST property for source '$(source)' in target '$(target)': $(inst))
1551endif
1552INSTARGET_$(target)_$(srcname) := $(inst)
1553local fetchdir := $(firstword \
1554 $($(target)_$(source)_FETCHDIR)\
1555 $($(target)_$(srcname)_FETCHDIR)\
1556 $($(source)_FETCHDIR)\
1557 $($(srcname)_FETCHDIR)\
1558 $($(target)_FETCHDIR)\
1559 $(FETCHDIR)\
1560 $(PATH_TARGET)\
1561)
1562local deps := \
1563 $($(target)_$(source)_DEPS)\
1564 $($(target)_$(srcname)_DEPS)\
1565 $($(source)_DEPS)\
1566 $($(srcname)_DEPS)\
1567 $($(target)_DEPS)
1568local orderdeps := \
1569 $($(target)_$(source)_ORDERDEPS)\
1570 $($(target)_$(srcname)_ORDERDEPS)\
1571 $($(source)_ORDERDEPS)\
1572 $($(srcname)_ORDERDEPS)\
1573 $($(target)_ORDERDEPS)
1574local md5 := $(firstword \
1575 $($(target)_$(source)_MD5)\
1576 $($(target)_$(srcname)_MD5)\
1577 $($(source)_MD5)\
1578 $($(srcname)_MD5)\
1579 $($(target)_MD5)\
1580)
1581local size := $(firstword \
1582 $($(target)_$(source)_SIZE)\
1583 $($(target)_$(srcname)_SIZE)\
1584 $($(source)_SIZE)\
1585 $($(srcname)_SIZE)\
1586 $($(target)_SIZE)\
1587)
1588clean_files += \
1589 $($(target)_$(source)_CLEAN)\
1590 $($(target)_$(srcname)_CLEAN)\
1591 $($(source)_CLEAN)\
1592 $($(srcname)_CLEAN)
1593local dep := # not legal for fetch and unpack tools
1594
1595
1596#
1597# The fetching.
1598#
1599local out := $(fetchdir)/$(srcname)
1600local archive := $(out)
1601TARGET_$(target)_$(srcname) := $(out)
1602$(target)_$(srcname)_1_TARGET = $(TARGET_$(target)_$(srcname))
1603local dirdep := $(call DIRDEP,$(fetchdir))
1604local tool := $(firstword \
1605 $($(target)_$(source)_FETCHTOOL)\
1606 $($(target)_$(srcname)_FETCHTOOL)\
1607 $($(target)_$(source)_TOOL)\
1608 $($(target)_$(srcname)_TOOL)\
1609 $($(source)_FETCHTOOL)\
1610 $($(srcname)_FETCHTOOL)\
1611 $($(source)_TOOL)\
1612 $($(srcname)_TOOL)\
1613 $($(target)_FETCHTOOL)\
1614 $($(target)_TOOL)\
1615 )
1616local flags :=\
1617 $(TOOL_$(tool)_FETCHFLAGS)\
1618 $(FETCHFLAGS)\
1619 $($(target)_FETCHFLAGS)\
1620 $($(srcname)_FETCHFLAGS)\
1621 $($(source)_FETCHFLAGS)\
1622 $($(target)_$(srcname)_FETCHFLAGS)\
1623 $($(target)_$(source)_FETCHFLAGS)
1624
1625#$ (warning dbg: target=$(target) source=$(source) $(srcname)=$(srcname) tool=$(tool) out=$(out) flags=$(flags) dirdep=$(dirdep) fetchdir=$(fetchdir) md5=$(md5) size=$(size))
1626
1627ifndef TOOL_$(tool)_FETCH_CMDS
1628$(warning kBuild: tools: \
1629 1 $($(target)_$(source)_FETCHTOOL)\
1630 2 $($(target)_$(srcname)_FETCHTOOL)\
1631 3 $($(target)_$(source)_TOOL)\
1632 4 $($(target)_$(srcname)_TOOL)\
1633 5 $($(source)_FETCHTOOL)\
1634 6 $($(srcname)_FETCHTOOL)\
1635 7 $($(source)_TOOL)\
1636 8 $($(srcname)_TOOL)\
1637 9 $($(target)_FETCHTOOL)\
1638 10 $($(target)_TOOL) )
1639$(error kBuild: TOOL_$(tool)_FETCH_CMDS is not defined. source=$(source) target=$(target) )
1640endif
1641
1642# call the tool
1643local cmds := $(TOOL_$(tool)_FETCH_CMDS)
1644$(target)_$(srcname)_FETCH_2_OUTPUT := $(TOOL_$(tool)_FETCH_OUTPUT)
1645$(target)_$(srcname)_FETCH_2_OUTPUT_MAYBE := $(TOOL_$(tool)_FETCH_OUTPUT_MAYBE)
1646$(target)_$(srcname)_FETCH_2_DEPEND := $(TOOL_$(tool)_FETCH_DEPEND) $(deps)
1647$(target)_$(srcname)_FETCH_2_DEPORD := $(TOOL_$(tool)_FETCH_DEPORD) $(dirdep) $(orderdeps)
1648
1649# generate the fetch rule.
1650$(eval $(def_fetch_src_fetch_rule))
1651
1652
1653#
1654# The unpacking / installing.
1655#
1656local out := $(inst)_kBuild_$(target)_$(srcname)_unpacked.lst
1657local dirdep := $(call DIRDEP,$(inst))
1658local tool := $(firstword \
1659 $($(target)_$(source)_UNPACKTOOL)\
1660 $($(target)_$(srcname)_UNPACKTOOL)\
1661 $($(target)_$(source)_TOOL)\
1662 $($(target)_$(srcname)_TOOL)\
1663 $($(source)_UNPACKTOOL)\
1664 $($(srcname)_UNPACKTOOL)\
1665 $($(source)_TOOL)\
1666 $($(srcname)_TOOL)\
1667 $($(target)_UNPACKTOOL)\
1668 $($(target)_TOOL) \
1669 )
1670ifeq ($(tool),)
1671local tool := $(toupper $(subst .,,$(suffix $(subst tar.,TAR,$(srcname)))))
1672$(evalval def_tools_include)
1673endif
1674local flags :=\
1675 $(TOOL_$(tool)_UNPACKFLAGS)\
1676 $(UNPACKFLAGS)\
1677 $($(target)_UNPACKFLAGS)\
1678 $($(srcname)_UNPACKFLAGS)\
1679 $($(source)_UNPACKFLAGS)\
1680 $($(target)_$(srcname)_UNPACKFLAGS)\
1681 $($(target)_$(source)_UNPACKFLAGS)
1682
1683#$ (warning dbg: target=$(target) source=$(source) $(srcname)=$(srcname) tool=$(tool) out=$(out) flags=$(flags) dirdep=$(dirdep) inst=$(inst) md5=$(md5) size=$(size))
1684ifndef TOOL_$(tool)_UNPACK_CMDS
1685$(warning kBuild: tools: \
1686 1 $($(target)_$(source)_UNPACKTOOL)\
1687 2 $($(target)_$(srcname)_UNPACKTOOL)\
1688 3 $($(target)_$(source)_TOOL)\
1689 4 $($(target)_$(srcname)_TOOL)\
1690 5 $($(source)_UNPACKTOOL)\
1691 6 $($(srcname)_UNPACKTOOL)\
1692 7 $($(source)_TOOL)\
1693 8 $($(srcname)_TOOL)\
1694 9 $($(target)_UNPACKTOOL)\
1695 10 $($(target)_TOOL) \
1696 11 $(toupper $(subst tar.,TAR,$(ext $(srcname)))) \
1697 )
1698$(error kBuild: TOOL_$(tool)_UNPACK_CMDS is not defined. source=$(source) target=$(target) )
1699endif
1700
1701# call the tool
1702local cmds := $(TOOL_$(tool)_UNPACK_CMDS)
1703$(target)_$(srcname)_UNPACK_2_OUTPUT := $(TOOL_$(tool)_UNPACK_OUTPUT)
1704$(target)_$(srcname)_UNPACK_2_OUTPUT_MAYBE := $(TOOL_$(tool)_UNPACK_OUTPUT_MAYBE)
1705$(target)_$(srcname)_UNPACK_2_DEPEND := $(TOOL_$(tool)_UNPACK_DEPEND) $(deps)
1706$(target)_$(srcname)_UNPACK_2_DEPORD := $(TOOL_$(tool)_UNPACK_DEPORD) $(dirdep) $(orderdeps)
1707
1708# generate the fetch rule.
1709$(eval $(def_fetch_src_unpack_rule))
1710
1711_DIRS += $(inst) $(fetchdir)
1712
1713endef # def_fetch_src
1714$(eval-opt-var def_fetch_src)
1715
1716
1717##
1718# Define the target level rules for a fetch.
1719# @param target
1720# @param out
1721# @param inst
1722# @param _TARGET_$(target)_UNPACKED
1723# @param _TARGET_$(target)_DIGEST
1724# @param bld_trg
1725# @param bld_trg_arch
1726define def_fetch_rules
1727
1728$(out).lst: $(_TARGET_$(target)_UNPACKED) | $(call DIRDEP,$(inst))
1729 %$$(call MSG_FETCH_OK,$(target))
1730 $$(QUIET)$$(RM) -f -- $$@ $$@.tmp
1731 $$(QUIET2)$$(APPEND) $$@.tmp '$(notdir $(out))'
1732 $$(QUIET)$(if $(_TARGET_$(target)_UNPACKED),$$(CAT_EXT) $(_TARGET_$(target)_UNPACKED) >> $$@.tmp)
1733 $$(QUIET)$$(MV) -f -- $$@.tmp $$@
1734
1735$(out)_unfetched:
1736 %$$(call MSG_UNFETCH,$(target))
1737 $$(QUIET)$$(RM) -f -- $$(addprefix $(inst),$$(shell $$(CAT_EXT) $(out).lst 2> /dev/null | $$(SED) -e '/\/$$$$/d'))
1738 $$(QUIET)$$(RMDIR) -p --ignore-fail-on-non-empty --ignore-fail-on-not-exist -- $$(dir $$@) \
1739 $$(addprefix $(inst),$$(sort $$(dir $$(shell $$(CAT_EXT) $(out).lst 2> /dev/null))))
1740 $$(QUIET)$$(RM) -f -- $(out).lst $(out)
1741 $$(QUIET)$$(RMDIR) -p --ignore-fail-on-non-empty --ignore-fail-on-not-exist -- $$(dir $$@)
1742
1743$(out): $(comp-vars _TARGET_$(target)_DIGEST_PREV,_TARGET_$(target)_DIGEST,FORCE) | $(call DIRDEP,$(inst))
1744 $$(QUIET)$$(RM) -f -- $$@
1745 %$$(if $$(_TARGET_$(target)_DIGEST),$$(if $$(eq $$(file-size $(out).lst),-1)\
1746 ,$$(call MSG_REFETCH,$(target)),$$(call MSG_FETCH,$(target))),$$(call MSG_UNFETCH,$(target)))
1747 $$(QUIET)$(TEST_EXT) -f $(out).lst -- $$(MAKE) -f $(MAKEFILE) --no-print-directory $(out)_unfetched
1748 $$(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 $$@))
1749 $$(QUIET2)$$(if $$(_TARGET_$(target)_DIGEST),$$(APPEND) $$@ "_TARGET_$(target)_DIGEST_PREV := $(_TARGET_$(target)_DIGEST)")
1750
1751.NOTPARALLEL: $(out).lst $(out)_unfetched $(out)
1752
1753endef
1754
1755
1756##
1757# Deal with one fetch target.
1758# @param target
1759# @param bld_trg
1760# @param bld_trg_arch
1761define def_fetch
1762# common
1763INSTARGET_$(target) := $($(target)_INST)
1764ifneq ($(patsubst %/,ok,$(INSTARGET_$(target))),ok)
1765$(error kBuild: Bad or missing INST property for target '$(target)'. \
1766 $(target)_INST='$($(target)_INST)' ($(origin $(target)_INST)))
1767endif
1768_TARGET_$(target)_FETCHED :=
1769_TARGET_$(target)_UNPACKED :=
1770_TARGET_$(target)_DIGEST :=
1771local clean_files := $($(target)_CLEAN) $($(target)_CLEAN.$(bld_trg)) $($(target)_CLEAN.$(bld_trg).$(bld_trg_arch)) $($(target)_CLEAN.$(bld_trg_arch)) $($(target)_CLEAN.$(KBUILD_TYPE))
1772
1773# The 'sources'.
1774#$ (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)))
1775$(foreach source,$($(target)_SOURCES) $($(target)_SOURCES.$(KBUILD_TYPE)) $($(target)_SOURCES.$(bld_trg)) $($(target)_SOURCES.$(bld_trg_arch)) $($(target)_SOURCES.$(bld_trg).$(bld_trg_arch)),\
1776 $(evalval def_fetch_src))
1777
1778# The target.
1779local inst := $(INSTARGET_$(target))
1780local out := $(inst)_kBuild_fetch_$(target)
1781
1782$(eval includedep $(out))
1783
1784$(eval $(def_fetch_rules))
1785
1786# Define the aliases here (doesn't work if defined in def_fetch_rules, just like includedep).
1787$(target): $(out)
1788$(target)_unfetch: $(out)_unfetched
1789
1790_FETCHES += $(out)
1791_DOWNLOADS += $(_TARGET_$(target)_FETCHED)
1792_UNPACKS += $(_TARGET_$(target)_UNPACKED)
1793_UNFETCHES += $(out)_unfetched
1794_DIRS += $(inst)
1795_CLEAN_FILES += $(clean_files)
1796
1797endef
1798$(eval-opt-var def_fetch)
1799
1800# Walk the FETCH target lists.
1801bld_trg := $(KBUILD_TARGET)
1802bld_trg_arch := $(KBUILD_TARGET_ARCH)
1803$(foreach target, $(_ALL_FETCHES), \
1804 $(evalvalctx def_fetch))
1805
1806# some aliases.
1807download: $(_DOWNLOADS)
1808unpack: $(_UNPACKS)
1809fetch: $(_FETCHES)
1810unfetch: $(_UNFETCHES)
1811
1812ifdef KBUILD_PROFILE_SELF
1813 $(evalcall def_profile_self, done fetching targets)
1814endif
1815
1816
1817
1818##
1819## Patching.
1820##
1821##
1822#define def_patch_src
1823#
1824#endef
1825#
1826#
1827## Deal with one patch target.
1828#define def_patch
1829#
1830#$(foreach source,$($(target)_SOURCES) $($(target)_SOURCES.$(KBUILD_TYPE)) $($(target)_SOURCES.$(KBUILD_TARGET)) $($(target)_SOURCES.$(KBUILD_TARGET_ARCH)) $($(target)_SOURCES.$(KBUILD_TARGET).$(KBUILD_TARGET_ARCH)),\
1831# $(evalval def_patch_src))
1832#
1833#_PATCHES +=
1834#endef
1835#
1836#$(foreach target, $(_ALL_PATCHES), \
1837# $(evalval def_patch))
1838#
1839
1840
1841#
1842# Object processing.
1843#
1844
1845## wrapper the compile command dependency check.
1846ifndef NO_COMPILE_CMDS_DEPS
1847 if1of ($(KMK_FEATURES),dot-must-make)
1848 _DEP_COMPILE_CMDS =
1849 # for debugging: $$(warning MUST_MAKE=$$$$(comp-cmds-ex $$$$($(target)_$(subst :,_,$(source))_CMDS_PREV_), $$$$(commands $$@)) -> $$(comp-cmds-ex $$($(target)_$(subst :,_,$(source))_CMDS_PREV_),$$(commands $$@),FORCE))
1850 else
1851 _DEP_COMPILE_CMDS = $$(comp-cmds-ex $$($(target)_$(subst :,_,$(source))_CMDS_PREV_),$$(commands $(obj)),FORCE)
1852 endif
1853else
1854 _DEP_COMPILE_CMDS =
1855endif
1856
1857
1858## Generates the rules for building a specific object, and the aliases
1859# for building a source file.
1860# @param $(obj) The object file.
1861define def_target_source_rule
1862ifndef NO_COMPILE_CMDS_DEPS
1863$(obj): .MUST_MAKE = $$(comp-cmds-ex $$($(target)_$(subst :,_,$(source))_CMDS_PREV_),$$(commands $$@),FORCE)
1864endif
1865ifdef TOOL_$(tool)_COMPILE_$(type)_USES_KOBJCACHE
1866_OUT_FILES += $(outbase).koc
1867$(outbase).koc +| $(obj) $($(target)_$(source)_OUTPUT_) $($(target)_$(source)_OUTPUT_MAYBE_) : \
1868 $($(target)_$(source)_DEPEND_) \
1869 $(value _DEP_COMPILE_CMDS) \
1870 | \
1871 $($(target)_$(source)_DEPORD_) \
1872 $$$$($(target)_INTERMEDIATES) \
1873 $$$$($(target)_INTERMEDIATES.$(bld_trg)) \
1874 $$$$($(target)_INTERMEDIATES.$(bld_trg).$(bld_trg_arch)) \
1875 $$$$($(target)_INTERMEDIATES.$(bld_trg_arch)) \
1876 $$$$($(target)_INTERMEDIATES.$(bld_trg_cpu)) \
1877 $$$$($(target)_INTERMEDIATES.$(bld_type))
1878 %$$(call MSG_COMPILE,$(target),$(source),$$@,$(type))
1879else
1880$(obj) + $($(target)_$(source)_OUTPUT_) +| $($(target)_$(source)_OUTPUT_MAYBE_) : \
1881 $($(target)_$(source)_DEPEND_) \
1882 $(value _DEP_COMPILE_CMDS) \
1883 | \
1884 $($(target)_$(source)_DEPORD_) \
1885 $$$$($(target)_INTERMEDIATES) \
1886 $$$$($(target)_INTERMEDIATES.$(bld_trg)) \
1887 $$$$($(target)_INTERMEDIATES.$(bld_trg).$(bld_trg_arch)) \
1888 $$$$($(target)_INTERMEDIATES.$(bld_trg_arch)) \
1889 $$$$($(target)_INTERMEDIATES.$(bld_trg_cpu)) \
1890 $$$$($(target)_INTERMEDIATES.$(bld_type))
1891 %$$(call MSG_COMPILE,$(target),$(source),$$@,$(type))
1892ifdef TOOL_$(tool)_COMPILE_$(type)_DONT_PURGE_OUTPUT
1893 $$(QUIET)$$(RM) -f -- $(dep) $(obj) $($(target)_$(source)_OUTPUT_) $($(target)_OUTPUT_MAYBE_)
1894endif
1895endif
1896
1897$($(target)_$(source)_CMDS_)
1898
1899ifndef NO_COMPILE_CMDS_DEPS
1900 %$$(QUIET2)$$(APPEND) '$(dep)'
1901 %$$(QUIET2)$$(APPEND) '$(dep)' 'define $(target)_$(subst :,_,$(source))_CMDS_PREV_'
1902 %$$(QUIET2)$$(APPEND) -c '$(dep)' '$(obj)'
1903 %$$(QUIET2)$$(APPEND) '$(dep)' 'endef'
1904endif
1905
1906$(basename $(notdir $(obj))).o: $(obj)
1907$(basename $(notdir $(obj))).obj: $(obj)
1908
1909## @todo make this 'local cmds,output,output_maybe,depend and depord' in 0.2.x or when a new kb-src-one is added.
1910$(target)_$(source)_CMDS_ :=
1911$(target)_$(source)_OUTPUT_ :=
1912$(target)_$(source)_OUTPUT_MAYBE_ :=
1913$(target)_$(source)_DEPEND_ :=
1914$(target)_$(source)_DEPORD_ :=
1915endef # def_target_source_rule
1916$(eval-opt-var def_target_source_rule)
1917
1918
1919## wrapper the link command dependency check.
1920ifndef NO_LINK_CMDS_DEPS
1921 if1of ($(KMK_FEATURES),dot-must-make)
1922 _DEP_LINK_CMDS =
1923 else
1924 _DEP_LINK_CMDS = $$(comp-cmds-ex $$($(target)_CMDS_PREV_),$$(commands $(out)),FORCE)
1925 endif
1926else
1927 _DEP_LINK_CMDS =
1928endif
1929
1930## Generate the link rule for a target.
1931# @param $(target) The normalized target name.
1932# @param $(dirdep) Directories we depend upon begin created before linking.
1933# @param $(dep) The name of the dependency file.
1934# @param $(out)
1935# @param $($(target)_2_OUTPUT) Output files from the link.
1936# @param $($(target)_2_OUTPUT_MAYBE) Output files that the link may perhaps create.
1937# @param $($(target)_2_DEPEND) Dependencies.
1938# @param $($(target)_2_DEPORD) Dependencies which should only affect build order.
1939# @param $(cmds) The link commands.
1940# @param $($(target)_CMDS_PREV_) The link commands from the previous run.
1941define def_link_rule
1942ifndef NO_LINK_CMDS_DEPS
1943$(out): .MUST_MAKE = $$(comp-cmds-ex $$($(target)_CMDS_PREV_),$$(commands $$@),FORCE)
1944endif
1945$(out) + $($(target)_2_OUTPUT) +| $($(target)_2_OUTPUT_MAYBE) : \
1946 $$$$($(target)_2_DEPEND) \
1947 $(value _DEP_LINK_CMDS) \
1948 | \
1949 $$$$($(target)_2_DEPORD)
1950 %$$(call MSG_LINK,$(target),$$@,$(tool_do))
1951 $$(QUIET)$$(RM) -f -- $(dep) $(out) $($(target)_2_OUTPUT) $($(target)_2_OUTPUT_MAYBE)
1952
1953$(cmds)
1954
1955ifndef NO_LINK_CMDS_DEPS
1956 %$$(QUIET2)$$(APPEND) '$(dep)' 'define $(target)_CMDS_PREV_'
1957 %$$(QUIET2)$$(APPEND) -c '$(dep)' '$(out)'
1958 %$$(QUIET2)$$(APPEND) '$(dep)' 'endef'
1959endif
1960
1961$(basename $(notdir $(out))):: $(out)
1962
1963endef # def_link_rule
1964$(eval-opt-var def_link_rule)
1965
1966
1967## Generate the link & lib install rule
1968# @param $(target) Normalized target name.
1969# @param $(out) The build target.
1970# @param $(INSTARGET_$(target)) The installation targets.
1971# @param $(mode) The file mode (optional)
1972define def_link_install_rule
1973$(INSTARGET_$(target)) : $(out) | $(call DIRDEP,$(dir $(INSTARGET_$(target))))
1974 %$$(call MSG_INST_TRG,$(target),$(out),$$@)
1975 $$(QUIET)$$(INSTALL) $(if $(mode),-m $(mode)) $(if $(uid),-o $(uid)) $(if $(gid),-g $(gid)) -- $(out) $$@
1976
1977ifdef KBUILD_DO_AUTO_INSTALL
1978$(basename $(notdir $(out))):: $(INSTARGET_$(target))
1979endif
1980endef # def_link_install_rule
1981
1982
1983## def_src_handler_*
1984#
1985# @{
1986define def_src_handler_c
1987local type := C
1988 $(kb-src-one 2)
1989endef
1990
1991define def_src_handler_cxx
1992local type := CXX
1993 $(kb-src-one 2)
1994endef
1995
1996define def_src_handler_objc
1997local type := OBJC
1998 $(kb-src-one 2)
1999endef
2000
2001define def_src_handler_objcxx
2002local type := OBJCXX
2003 $(kb-src-one 2)
2004endef
2005
2006define def_src_handler_asm
2007local type := AS
2008 $(kb-src-one 2)
2009endef
2010
2011define def_src_handler_rc
2012local type := RC
2013 $(kb-src-one 2)
2014endef
2015
2016define def_src_handler_obj
2017ifeq ($(defpath),)
2018 $(target)_2_OBJS += $(source)
2019else
2020 $(target)_2_OBJS += $(abspathex $(source), $(defpath))
2021endif
2022endef
2023## @}
2024
2025## Handle one source.
2026# .
2027define def_src_handler_one
2028local suff := $(suffix $(source))
2029local src_handler := $(firstword $(filter $(suff):%, $($(target)_$(source)_SRC_HANDLERS) $($(source)_SRC_HANDLERS) $(target_src_handlers) ))
2030local handler := $(patsubst $(suff):%,%,$(src_handler))
2031ifneq ($(handler),)
2032 $(evalvalctx $(handler))
2033else
2034 othersrc += $(source)
2035endif
2036endef
2037
2038## Generic macro for processing all target sources.
2039# @param $(target) Normalized target name.
2040# @param $(defpath)
2041# @param much-more...
2042# @returns othersrc, $(target)_2_OBJS, ++
2043define def_target_sources
2044local target_src_handlers := $($(target)_SRC_HANDLERS) $(KBUILD_SRC_HANDLERS)
2045$(foreach source,\
2046 $($(target)_SOURCES)\
2047 $($(target)_SOURCES.$(bld_trg))\
2048 $($(target)_SOURCES.$(bld_trg).$(bld_trg_arch))\
2049 $($(target)_SOURCES.$(bld_trg_arch))\
2050 $($(target)_SOURCES.$(bld_trg_cpu))\
2051 $($(target)_SOURCES.$(bld_type))\
2052 ,$(evalval def_src_handler_one) )
2053
2054$(foreach source,\
2055 $($(target)_GEN_SOURCES_)\
2056 $($(target)_GEN_SOURCES_.$(bld_trg))\
2057 $($(target)_GEN_SOURCES_.$(bld_trg).$(bld_trg_arch))\
2058 $($(target)_GEN_SOURCES_.$(bld_trg_arch))\
2059 $($(target)_GEN_SOURCES_.$(bld_trg_cpu))\
2060 $($(target)_GEN_SOURCES_.$(bld_type))\
2061 ,$(evalval def_src_handler_one) )
2062endef # def_target_sources
2063$(eval-opt-var def_target_sources)
2064
2065
2066
2067## Generic macro for generating the install rule(s) for a target
2068# and update the globals with default out.
2069#
2070# @param $(target) Normalized target name.
2071# @param $(out) The output file.
2072# @param $(definst) The default _INST value.
2073# @param $(typevar) The name of the variable with all the root targets of its type.
2074# @remark Only library uses this now.
2075define def_target_install_pluss
2076ifeq ($(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))),)
2077 ifneq ($(strip $($(target)_INST.$(bld_trg).$(bld_trg_arch).$(bld_type))),)
2078 local inst := $(addprefix $(PATH_INS)/,$($(target)_INST.$(bld_trg).$(bld_trg_arch).$(bld_type)))
2079 else ifneq ($(strip $($(target)_INST.$(bld_trg).$(bld_trg_arch))),)
2080 local inst := $(addprefix $(PATH_INS)/,$($(target)_INST.$(bld_trg).$(bld_trg_arch)))
2081 else ifneq ($(strip $($(target)_INST.$(bld_trg).$(bld_type))),)
2082 local inst := $(addprefix $(PATH_INS)/,$($(target)_INST.$(bld_trg).$(bld_type)))
2083 else ifneq ($(strip $($(target)_INST.$(bld_trg_arch))),)
2084 local inst := $(addprefix $(PATH_INS)/,$($(target)_INST.$(bld_trg_arch)))
2085 else ifneq ($(strip $($(target)_INST.$(bld_trg))),)
2086 local inst := $(addprefix $(PATH_INS)/,$($(target)_INST.$(bld_trg)))
2087 else ifneq ($(strip $($(target)_INST.$(bld_type))),)
2088 local inst := $(addprefix $(PATH_INS)/,$($(target)_INST.$(bld_type)))
2089 else ifneq ($(strip $($(target)_INST)),)
2090 local inst := $(addprefix $(PATH_INS)/,$($(target)_INST))
2091 else
2092 local inst := $(definst)/
2093 endif
2094 INSTARGET_$(target) := $(patsubst %/,%/$(notdir $(out)),$(inst))
2095 local mode := $(firstword \
2096 $($(target)_MODE.$(bld_trg).$(bld_trg_arch).$(bld_type)) \
2097 $($(target)_MODE.$(bld_trg).$(bld_trg_arch)) \
2098 $($(target)_MODE.$(bld_trg).$(bld_type)) \
2099 $($(target)_MODE.$(bld_trg_arch)) \
2100 $($(target)_MODE.$(bld_trg)) \
2101 $($(target)_MODE.$(bld_type)) \
2102 $($(target)_MODE) )
2103 local uid := $(firstword \
2104 $($(target)_UID.$(bld_trg).$(bld_trg_arch).$(bld_type)) \
2105 $($(target)_UID.$(bld_trg).$(bld_trg_arch)) \
2106 $($(target)_UID.$(bld_trg).$(bld_type)) \
2107 $($(target)_UID.$(bld_trg_arch)) \
2108 $($(target)_UID.$(bld_trg)) \
2109 $($(target)_UID.$(bld_type)) \
2110 $($(target)_UID) )
2111 local gid := $(firstword \
2112 $($(target)_GID.$(bld_trg).$(bld_trg_arch).$(bld_type)) \
2113 $($(target)_GID.$(bld_trg).$(bld_trg_arch)) \
2114 $($(target)_GID.$(bld_trg).$(bld_type)) \
2115 $($(target)_GID.$(bld_trg_arch)) \
2116 $($(target)_GID.$(bld_trg)) \
2117 $($(target)_GID.$(bld_type)) \
2118 $($(target)_GID) )
2119
2120 # generate the install rule
2121$(eval $(def_link_install_rule))
2122
2123 _INSTALLS_FILES += $(INSTARGET_$(target))
2124
2125 ifdef KBUILD_DO_AUTO_INSTALL
2126 $(typevar) += $(INSTARGET_$(target))
2127 else
2128 $(typevar) += $(out)
2129 endif
2130else # _NOINST
2131 $(typevar) += $(out)
2132endif
2133
2134_OUT_FILES += $($(target)_2_OUTPUT) $($(target)_2_OUTPUT_MAYBE) $(out)
2135_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))
2136_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))
2137_OBJS += $($(target)_2_OBJS)
2138
2139endef # def_target_install_pluss
2140
2141
2142
2143#
2144# LIBRARIES
2145#
2146
2147## Library (one).
2148# @param $(target) Normalized library (target) name.
2149define def_lib
2150# library basics
2151## @todo prefix
2152local bld_type := $(firstword $($(target)_BLD_TYPE) $(KBUILD_TYPE))
2153local bld_trg := $(firstword $($(target)_BLD_TRG) $(KBUILD_TARGET))
2154local bld_trg_arch:= $(firstword $($(target)_BLD_TRG_ARCH) $(KBUILD_TARGET_ARCH))
2155local bld_trg_cpu := $(firstword $($(target)_BLD_TRG_CPU) $(KBUILD_TARGET_CPU))
2156local tool := $(call _TARGET_TOOL,$(target),AR)
2157ifeq ($(tool),)
2158$(error kBuild: Library target $(target) does not have a tool defined!)
2159endif
2160local name := $(firstword\
2161 $($(target)_NAME.$(bld_trg).$(bld_trg_arch))\
2162 $($(target)_NAME.$(bld_trg_arch))\
2163 $($(target)_NAME.$(bld_trg))\
2164 $($(target)_NAME.$(bld_type))\
2165 $($(target)_NAME)\
2166 $(target))
2167local outbase := $(call TARGET_BASE,$(name),$(target))
2168$(target)_0_OUTDIR:= $(patsubst %/,%,$(dir $(outbase)))
2169PATH_$(target) := $($(target)_0_OUTDIR)
2170local suff := $(firstword\
2171 $($(target)_LIBSUFF.$(bld_trg).$(bld_trg_arch))\
2172 $($(target)_LIBSUFF.$(bld_trg))\
2173 $($(target)_LIBSUFF)\
2174 $(TOOL_$(tool)_ARLIBSUFF.$(bld_trg).$(bld_trg_arch))\
2175 $(TOOL_$(tool)_ARLIBSUFF.$(bld_trg))\
2176 $(TOOL_$(tool)_ARLIBSUFF)\
2177 $(SUFF_LIB))
2178local out := $(outbase)$(suff)
2179local defpath := $(firstword $($(target)_PATH) $($(target)_DEFPATH))
2180TARGET_$(target) := $(out)
2181$(target)_1_TARGET:= $(out)
2182# no local here - must be writable across some foreachs.
2183othersrc :=
2184$(target)_2_OBJS :=
2185
2186# Do units pre source callouts.
2187local units := \
2188 $($(target)_USES.$(bld_trg).$(bld_trg_arch))\
2189 $($(target)_USES.$(bld_trg_arch))\
2190 $($(target)_USES.$(bld_trg))\
2191 $($(target)_USES.$(bld_type))\
2192 $($(target)_USES)
2193$(foreach unit,$(units),$(evalval def_unit_$(unit)_target_pre))
2194
2195# source -> object
2196$(evalval def_target_sources)
2197
2198# library linking
2199local tool := $(call _TARGET_TOOL,$(target),AR)
2200local name := $(firstword\
2201 $($(target)_NAME.$(bld_trg).$(bld_trg_arch))\
2202 $($(target)_NAME.$(bld_trg_arch))\
2203 $($(target)_NAME.$(bld_trg))\
2204 $($(target)_NAME.$(bld_type))\
2205 $($(target)_NAME)\
2206 $(target))
2207local outbase := $(call TARGET_BASE,$(name),$(target))
2208local flags :=\
2209 $(TOOL_$(tool)_ARFLAGS)\
2210 $(TOOL_$(tool)_ARFLAGS.$(bld_type))\
2211 $(ARFLAGS)\
2212 $(ARFLAGS.$(bld_type))\
2213 $($(target)_ARFLAGS)\
2214 $($(target)_ARFLAGS.$(bld_type)) \
2215 $($(target)_ARFLAGS.$(bld_trg)) \
2216 $($(target)_ARFLAGS.$(bld_trg_arch)) \
2217 $($(target)_ARFLAGS.$(bld_trg).$(bld_trg_arch)) \
2218 $($(target)_ARFLAGS.$(bld_trg_cpu))
2219local dirdep := $(call DIRDEP,$(dir $(out)))
2220local deps := \
2221 $($(target)_DEPS.$(bld_trg_cpu)) \
2222 $($(target)_DEPS.$(bld_trg).$(bld_trg_arch).$(bld_type)) \
2223 $($(target)_DEPS.$(bld_trg).$(bld_trg_arch)) \
2224 $($(target)_DEPS.$(bld_trg).$(bld_type)) \
2225 $($(target)_DEPS.$(bld_trg_arch)) \
2226 $($(target)_DEPS.$(bld_trg)) \
2227 $($(target)_DEPS.$(bld_type)) \
2228 $($(target)_DEPS) \
2229 $($(target)_LNK_DEPS.$(bld_trg_cpu)) \
2230 $($(target)_LNK_DEPS.$(bld_trg).$(bld_trg_arch).$(bld_type)) \
2231 $($(target)_LNK_DEPS.$(bld_trg).$(bld_trg_arch)) \
2232 $($(target)_LNK_DEPS.$(bld_trg).$(bld_type)) \
2233 $($(target)_LNK_DEPS.$(bld_trg_arch)) \
2234 $($(target)_LNK_DEPS.$(bld_trg)) \
2235 $($(target)_LNK_DEPS.$(bld_type)) \
2236 $($(target)_LNK_DEPS)
2237local orderdeps := \
2238 $($(target)_ORDERDEPS.$(bld_trg_cpu)) \
2239 $($(target)_ORDERDEPS.$(bld_trg).$(bld_trg_arch).$(bld_type)) \
2240 $($(target)_ORDERDEPS.$(bld_trg).$(bld_trg_arch)) \
2241 $($(target)_ORDERDEPS.$(bld_trg).$(bld_type)) \
2242 $($(target)_ORDERDEPS.$(bld_trg_arch)) \
2243 $($(target)_ORDERDEPS.$(bld_trg)) \
2244 $($(target)_ORDERDEPS.$(bld_type)) \
2245 $($(target)_ORDERDEPS) \
2246 $($(target)_LNK_ORDERDEPS.$(bld_trg_cpu)) \
2247 $($(target)_LNK_ORDERDEPS.$(bld_trg).$(bld_trg_arch).$(bld_type)) \
2248 $($(target)_LNK_ORDERDEPS.$(bld_trg).$(bld_trg_arch)) \
2249 $($(target)_LNK_ORDERDEPS.$(bld_trg).$(bld_type)) \
2250 $($(target)_LNK_ORDERDEPS.$(bld_trg_arch)) \
2251 $($(target)_LNK_ORDERDEPS.$(bld_trg)) \
2252 $($(target)_LNK_ORDERDEPS.$(bld_type)) \
2253 $($(target)_LNK_ORDERDEPS)
2254
2255# Adjust paths if we got a default path.
2256ifneq ($(defpath),)
2257 local deps := $(abspathex $(deps),$(defpath))
2258 local orderdeps := $(abspathex $(orderdeps),$(defpath))
2259 othersrc := $(abspathex $(othersrc),$(defpath))
2260endif
2261
2262
2263# Custom pre-link actions.
2264## @todo bld_trg_cpu is missing here.
2265ifdef $(target)_PRE_CMDS.$(bld_trg).$(bld_trg_arch).$(bld_type)
2266 local pre_cmds := $($(target)_PRE_CMDS.$(bld_trg).$(bld_trg_arch).$(bld_type))
2267else ifdef $(target)_PRE_CMDS.$(bld_trg).$(bld_trg_arch)
2268 local pre_cmds := $($(target)_PRE_CMDS.$(bld_trg).$(bld_trg_arch))
2269else ifdef $(target)_PRE_CMDS.$(bld_trg).$(bld_type)
2270 local pre_cmds := $($(target)_PRE_CMDS.$(bld_trg).$(bld_type))
2271else ifdef $(target)_PRE_CMDS.$(bld_trg_arch)
2272 local pre_cmds := $($(target)_PRE_CMDS.$(bld_trg_arch))
2273else ifdef $(target)_PRE_CMDS.$(bld_trg)
2274 local pre_cmds := $($(target)_PRE_CMDS.$(bld_trg))
2275else ifdef $(target)_PRE_CMDS.$(bld_type)
2276 local pre_cmds := $($(target)_PRE_CMDS.$(bld_type))
2277else ifdef $(target)_PRE_CMDS
2278 local pre_cmds := $($(target)_PRE_CMDS)
2279else ifdef PRE_CMDS.$(bld_trg).$(bld_trg_arch).$(bld_type)
2280 local pre_cmds := $(PRE_CMDS.$(bld_trg).$(bld_trg_arch).$(bld_type))
2281else ifdef PRE_CMDS.$(bld_trg).$(bld_trg_arch)
2282 local pre_cmds := $(PRE_CMDS.$(bld_trg).$(bld_trg_arch))
2283else ifdef PRE_CMDS.$(bld_trg).$(bld_type)
2284 local pre_cmds := $(PRE_CMDS.$(bld_trg).$(bld_type))
2285else ifdef PRE_CMDS.$(bld_trg_arch)
2286 local pre_cmds := $(PRE_CMDS.$(bld_trg_arch))
2287else ifdef PRE_CMDS.$(bld_trg)
2288 local pre_cmds := $(PRE_CMDS.$(bld_trg))
2289else ifdef PRE_CMDS.$(bld_type)
2290 local pre_cmds := $(PRE_CMDS.$(bld_type))
2291else
2292 local pre_cmds := $(PRE_CMDS)
2293endif
2294
2295# Custom post-link actions.
2296ifdef $(target)_POST_CMDS.$(bld_trg).$(bld_trg_arch).$(bld_type)
2297 local post_cmds := $($(target)_POST_CMDS.$(bld_trg).$(bld_trg_arch).$(bld_type))
2298else ifdef $(target)_POST_CMDS.$(bld_trg).$(bld_trg_arch)
2299 local post_cmds := $($(target)_POST_CMDS.$(bld_trg).$(bld_trg_arch))
2300else ifdef $(target)_POST_CMDS.$(bld_trg).$(bld_type)
2301 local post_cmds := $($(target)_POST_CMDS.$(bld_trg).$(bld_type))
2302else ifdef $(target)_POST_CMDS.$(bld_trg_arch)
2303 local post_cmds := $($(target)_POST_CMDS.$(bld_trg_arch))
2304else ifdef $(target)_POST_CMDS.$(bld_trg)
2305 local post_cmds := $($(target)_POST_CMDS.$(bld_trg))
2306else ifdef $(target)_POST_CMDS.$(bld_type)
2307 local post_cmds := $($(target)_POST_CMDS.$(bld_type))
2308else ifdef $(target)_POST_CMDS
2309 local post_cmds := $($(target)_POST_CMDS)
2310else ifdef POST_CMDS.$(bld_trg).$(bld_trg_arch).$(bld_type)
2311 local post_cmds := $(POST_CMDS.$(bld_trg).$(bld_trg_arch).$(bld_type))
2312else ifdef POST_CMDS.$(bld_trg).$(bld_trg_arch)
2313 local post_cmds := $(POST_CMDS.$(bld_trg).$(bld_trg_arch))
2314else ifdef POST_CMDS.$(bld_trg).$(bld_type)
2315 local post_cmds := $(POST_CMDS.$(bld_trg).$(bld_type))
2316else ifdef POST_CMDS.$(bld_trg_arch)
2317 local post_cmds := $(POST_CMDS.$(bld_trg_arch))
2318else ifdef POST_CMDS.$(bld_trg)
2319 local post_cmds := $(POST_CMDS.$(bld_trg))
2320else ifdef POST_CMDS.$(bld_type)
2321 local post_cmds := $(POST_CMDS.$(bld_type))
2322else
2323 local post_cmds := $(POST_CMDS)
2324endif
2325
2326# eliminate this guy?
2327local objs = $($(target)_2_OBJS)
2328
2329# dependency file
2330local dep := $(out)$(SUFF_DEP)
2331ifndef NO_LINK_CMDS_DEPS
2332 _DEPFILES_INCLUDED += $(dep)
2333 ifdef KB_HAVE_INCLUDEDEP_QUEUE
2334 includedep-queue $(dep)
2335 else
2336 includedep $(dep)
2337 endif
2338endif
2339
2340# check that the tool is defined.
2341ifndef TOOL_$(tool)_LINK_LIBRARY_CMDS
2342$(warning kBuild: tools: \
2343 1 $($(target)_$(source)TOOL.$(bld_trg).$(bld_trg_arch)) \
2344 2 $($(target)_$(source)TOOL.$(bld_trg)) \
2345 3 $($(target)_$(source)TOOL) \
2346 4 $($(target)_TOOL.$(bld_trg).$(bld_trg_arch)) \
2347 5 $($(target)_TOOL.$(bld_trg)) \
2348 6 $($(target)_TOOL) \
2349 7 $($(source)TOOL) \
2350 8 $($(source)TOOL.$(bld_trg).$(bld_trg_arch)) \
2351 9 $($(source)TOOL.$(bld_trg)) \
2352 10 $(TOOL.$(bld_trg).$(bld_trg_arch)) \
2353 11 $(TOOL.$(bld_trg)) \
2354 12 $(TOOL) )
2355$(error kBuild: TOOL_$(tool)_LINK_LIBRARY_CMDS isn't defined! target=$(target) )
2356endif
2357
2358# call the tool
2359local cmds := $(TOOL_$(tool)_LINK_LIBRARY_CMDS)
2360ifneq ($(pre_cmds),)
2361 local cmds := $(TAB)$(pre_cmds)$(NL)$(TAB)$(cmds)
2362endif
2363ifneq ($(post_cmds),)
2364 local cmds := $(cmds)$(NL)$(TAB)$(post_cmds)
2365endif
2366$(target)_2_OUTPUT := $(TOOL_$(tool)_LINK_LIBRARY_OUTPUT)
2367$(target)_2_OUTPUT_MAYBE := $(TOOL_$(tool)_LINK_LIBRARY_OUTPUT_MAYBE)
2368$(target)_2_DEPEND := $(TOOL_$(tool)_LINK_LIBRARY_DEPEND) $(deps) $($(target)_2_OBJS)
2369$(target)_2_DEPORD := $(TOOL_$(tool)_LINK_LIBRARY_DEPORD) $(dirdep) $(orderdeps)
2370
2371# generate the link rule.
2372$(eval $(def_link_rule))
2373
2374# installing and globals
2375$(evalval def_target_install_pluss)
2376endef
2377$(eval-opt-var def_lib)
2378
2379# Process libraries
2380definst := $(PATH_LIB)
2381typevar := _LIBS
2382tool_do := LINK_LIBRARY
2383mode := 0644
2384$(foreach target, $(_ALL_LIBRARIES), $(evalval def_lib))
2385
2386ifdef KBUILD_PROFILE_SELF
2387 $(evalcall def_profile_self, done library targets)
2388endif
2389
2390
2391#
2392# Link operations.
2393#
2394
2395##
2396# Link prolog
2397#
2398# @param $(target) Normalized target name.
2399# @param $(EXT) EXE,DLL,SYS.
2400# @param $(definst) The default _INST value.
2401# @param $(typevar) The name of the variable with all the root targets of its type.
2402define def_link_common
2403# basics
2404local bld_type := $(firstword $($(target)_BLD_TYPE) $(KBUILD_TYPE))
2405local bld_trg := $(firstword $($(target)_BLD_TRG) $(BUILD_$(bld_trg_base_var)))
2406local bld_trg_arch:= $(firstword $($(target)_BLD_TRG_ARCH) $(BUILD_$(bld_trg_base_var)_ARCH))
2407local bld_trg_cpu := $(firstword $($(target)_BLD_TRG_CPU) $(BUILD_$(bld_trg_base_var)_CPU))
2408
2409local tool := $(call _TARGET_TOOL,$(target),LD)
2410local name := $(firstword\
2411 $($(target)_NAME.$(bld_trg).$(bld_trg_arch))\
2412 $($(target)_NAME.$(bld_trg_arch))\
2413 $($(target)_NAME.$(bld_trg))\
2414 $($(target)_NAME.$(bld_type))\
2415 $($(target)_NAME)\
2416 $(target))
2417local outbase := $(call TARGET_BASE,$(name),$(target))
2418$(target)_0_OUTDIR:= $(patsubst %/,%,$(dir $(outbase)))
2419PATH_$(target) := $($(target)_0_OUTDIR)
2420local suff := $(firstword \
2421 $($(target)_$(EXT)SUFF.$(bld_trg).$(bld_trg_arch))\
2422 $($(target)_$(EXT)SUFF.$(bld_trg))\
2423 $($(target)_$(EXT)SUFF)\
2424 $(TOOL_$(tool)_LD$(EXT)SUFF.$(bld_trg).$(bld_trg_arch))\
2425 $(TOOL_$(tool)_LD$(EXT)SUFF.$(bld_trg))\
2426 $(TOOL_$(tool)_LD$(EXT)SUFF)\
2427 $($(EXTPRE)SUFF_$(EXT)) )
2428local out := $(outbase)$(suff)
2429TARGET_$(target) := $(out)
2430$(target)_1_TARGET:= $(out)
2431local defpath := $(firstword $($(target)_PATH) $($(target)_DEFPATH))
2432# no local here - must be writable across some foreachs.
2433othersrc :=
2434$(target)_2_OBJS :=
2435
2436# Do units pre source callouts.
2437local units := \
2438 $($(target)_USES.$(bld_trg).$(bld_trg_arch))\
2439 $($(target)_USES.$(bld_trg_arch))\
2440 $($(target)_USES.$(bld_trg))\
2441 $($(target)_USES.$(bld_type))\
2442 $($(target)_USES)
2443$(foreach unit,$(units),$(evalval def_unit_$(unit)_target_pre))
2444
2445# source -> object
2446$(evalval def_target_sources)
2447
2448# more link stuff.
2449local tool := $(call _TARGET_TOOL,$(target),LD)
2450local name := $(firstword\
2451 $($(target)_NAME.$(bld_trg).$(bld_trg_arch))\
2452 $($(target)_NAME.$(bld_trg_arch))\
2453 $($(target)_NAME.$(bld_trg))\
2454 $($(target)_NAME.$(bld_type))\
2455 $($(target)_NAME)\
2456 $(target))
2457local outbase := $(call TARGET_BASE,$(name),$(target))
2458local flags :=\
2459 $(TOOL_$(tool)_LDFLAGS)\
2460 $(TOOL_$(tool)_LDFLAGS.$(bld_type))\
2461 $(TOOL_$(tool)_LDFLAGS.$(bld_trg))\
2462 $(TOOL_$(tool)_LDFLAGS.$(bld_trg_arch))\
2463 $(TOOL_$(tool)_LDFLAGS.$(bld_trg).$(bld_trg_arch))\
2464 $(TOOL_$(tool)_LDFLAGS.$(bld_trg_cpu))\
2465 $(foreach sdk, $(SDKS) \
2466 $(SDKS.$(bld_type)) \
2467 $(SDKS.$(bld_trg)) \
2468 $(SDKS.$(bld_trg_arch)) \
2469 $(SDKS.$(bld_trg).$(bld_trg_arch)),\
2470 $(SDK_$(sdk)_LDFLAGS)\
2471 $(SDK_$(sdk)_LDFLAGS.$(bld_type))\
2472 $(SDK_$(sdk)_LDFLAGS.$(bld_trg))\
2473 $(SDK_$(sdk)_LDFLAGS.$(bld_trg_arch))\
2474 $(SDK_$(sdk)_LDFLAGS.$(bld_trg).$(bld_trg_arch))\
2475 $(SDK_$(sdk)_LDFLAGS.$(bld_trg_cpu)))\
2476 $(LDFLAGS)\
2477 $(LDFLAGS.$(bld_type))\
2478 $(LDFLAGS.$(bld_trg))\
2479 $(LDFLAGS.$(bld_trg_arch))\
2480 $(LDFLAGS.$(bld_trg).$(bld_trg_arch))\
2481 $(LDFLAGS.$(bld_trg_cpu))\
2482 $(foreach sdk, $($(target)_SDKS) \
2483 $($(target)_SDKS.$(bld_type)) \
2484 $($(target)_SDKS.$(bld_trg)) \
2485 $($(target)_SDKS.$(bld_trg_arch)) \
2486 $($(target)_SDKS.$(bld_trg).$(bld_trg_arch)),\
2487 $(SDK_$(sdk)_LDFLAGS)\
2488 $(SDK_$(sdk)_LDFLAGS.$(bld_type))\
2489 $(SDK_$(sdk)_LDFLAGS.$(bld_trg))\
2490 $(SDK_$(sdk)_LDFLAGS.$(bld_trg_arch))\
2491 $(SDK_$(sdk)_LDFLAGS.$(bld_trg).$(bld_trg_arch))\
2492 $(SDK_$(sdk)_LDFLAGS.$(bld_trg_cpu)))\
2493 $($(target)_LDFLAGS)\
2494 $($(target)_LDFLAGS.$(bld_type))\
2495 $($(target)_LDFLAGS.$(bld_trg))\
2496 $($(target)_LDFLAGS.$(bld_trg_arch))\
2497 $($(target)_LDFLAGS.$(bld_trg).$(bld_trg_arch))\
2498 $($(target)_LDFLAGS.$(bld_trg_cpu))
2499local libs :=\
2500 $($(target)_LIBS.$(bld_trg_cpu))\
2501 $($(target)_LIBS.$(bld_trg).$(bld_trg_arch))\
2502 $($(target)_LIBS.$(bld_trg_arch))\
2503 $($(target)_LIBS.$(bld_trg))\
2504 $($(target)_LIBS.$(bld_type))\
2505 $($(target)_LIBS)\
2506 $(foreach sdk, $($(target)_SDKS.$(bld_trg).$(bld_trg_arch)) \
2507 $($(target)_SDKS.$(bld_trg_arch)) \
2508 $($(target)_SDKS.$(bld_trg)) \
2509 $($(target)_SDKS.$(bld_type)) \
2510 $($(target)_SDKS),\
2511 $(SDK_$(sdk)_LIBS.$(bld_trg_cpu))\
2512 $(SDK_$(sdk)_LIBS.$(bld_trg).$(bld_trg_arch))\
2513 $(SDK_$(sdk)_LIBS.$(bld_trg_arch))\
2514 $(SDK_$(sdk)_LIBS.$(bld_trg))\
2515 $(SDK_$(sdk)_LIBS.$(bld_type))\
2516 $(SDK_$(sdk)_LIBS))\
2517 $(LIBS.$(bld_trg_cpu))\
2518 $(LIBS.$(bld_trg).$(bld_trg_arch))\
2519 $(LIBS.$(bld_trg_arch))\
2520 $(LIBS.$(bld_trg))\
2521 $(LIBS.$(bld_type))\
2522 $(LIBS)\
2523 $(foreach sdk, $(SDKS.$(bld_trg).$(bld_trg_arch)) \
2524 $(SDKS.$(bld_trg_arch)) \
2525 $(SDKS.$(bld_trg)) \
2526 $(SDKS.$(bld_type)) \
2527 $(SDKS),\
2528 $(SDK_$(sdk)_LIBS.$(bld_trg_cpu))\
2529 $(SDK_$(sdk)_LIBS.$(bld_trg).$(bld_trg_arch))\
2530 $(SDK_$(sdk)_LIBS.$(bld_trg_arch))\
2531 $(SDK_$(sdk)_LIBS.$(bld_trg))\
2532 $(SDK_$(sdk)_LIBS.$(bld_type))\
2533 $(SDK_$(sdk)_LIBS))\
2534 $(TOOL_$(tool)_LIBS.$(bld_trg_cpu))\
2535 $(TOOL_$(tool)_LIBS.$(bld_trg).$(bld_trg_arch))\
2536 $(TOOL_$(tool)_LIBS.$(bld_trg_arch))\
2537 $(TOOL_$(tool)_LIBS.$(bld_trg))\
2538 $(TOOL_$(tool)_LIBS.$(bld_type))\
2539 $(TOOL_$(tool)_LIBS)
2540local libpath :=\
2541 $($(target)_LIBPATH.$(bld_trg_cpu))\
2542 $($(target)_LIBPATH.$(bld_trg).$(bld_trg_arch))\
2543 $($(target)_LIBPATH.$(bld_trg_arch))\
2544 $($(target)_LIBPATH.$(bld_trg))\
2545 $($(target)_LIBPATH.$(bld_type))\
2546 $($(target)_LIBPATH)\
2547 $(foreach sdk, $($(target)_SDKS.$(bld_trg).$(bld_trg_arch)) \
2548 $($(target)_SDKS.$(bld_trg_arch)) \
2549 $($(target)_SDKS.$(bld_trg)) \
2550 $($(target)_SDKS.$(bld_type)) \
2551 $($(target)_SDKS),\
2552 $(SDK_$(sdk)_LIBPATH.$(bld_trg_cpu))\
2553 $(SDK_$(sdk)_LIBPATH.$(bld_trg).$(bld_trg_arch))\
2554 $(SDK_$(sdk)_LIBPATH.$(bld_trg_arch))\
2555 $(SDK_$(sdk)_LIBPATH.$(bld_trg))\
2556 $(SDK_$(sdk)_LIBPATH.$(bld_type))\
2557 $(SDK_$(sdk)_LIBPATH))\
2558 $(LIBPATH.$(bld_trg_cpu))\
2559 $(LIBPATH.$(bld_trg).$(bld_trg_arch))\
2560 $(LIBPATH.$(bld_trg_arch))\
2561 $(LIBPATH.$(bld_trg))\
2562 $(LIBPATH.$(bld_type))\
2563 $(LIBPATH)\
2564 $(foreach sdk, $(SDKS.$(bld_trg).$(bld_trg_arch)) \
2565 $(SDKS.$(bld_trg_arch)) \
2566 $(SDKS.$(bld_trg)) \
2567 $(SDKS.$(bld_type)) \
2568 $(SDKS),\
2569 $(SDK_$(sdk)_LIBPATH.$(bld_trg_cpu))\
2570 $(SDK_$(sdk)_LIBPATH.$(bld_trg).$(bld_trg_arch))\
2571 $(SDK_$(sdk)_LIBPATH.$(bld_trg_arch))\
2572 $(SDK_$(sdk)_LIBPATH.$(bld_trg))\
2573 $(SDK_$(sdk)_LIBPATH.$(bld_type))\
2574 $(SDK_$(sdk)_LIBPATH))\
2575 $(TOOL_$(tool)_LIBPATH.$(bld_trg_cpu))\
2576 $(TOOL_$(tool)_LIBPATH.$(bld_trg).$(bld_trg_arch))\
2577 $(TOOL_$(tool)_LIBPATH.$(bld_trg_arch))\
2578 $(TOOL_$(tool)_LIBPATH.$(bld_trg))\
2579 $(TOOL_$(tool)_LIBPATH.$(bld_type))\
2580 $(TOOL_$(tool)_LIBPATH)
2581local dirdep := $(call DIRDEP,$(dir $(out)))
2582local deps := \
2583 $($(target)_DEPS.$(bld_trg_cpu)) \
2584 $($(target)_DEPS.$(bld_trg).$(bld_trg_arch).$(bld_type)) \
2585 $($(target)_DEPS.$(bld_trg).$(bld_trg_arch)) \
2586 $($(target)_DEPS.$(bld_trg).$(bld_type)) \
2587 $($(target)_DEPS.$(bld_trg_arch)) \
2588 $($(target)_DEPS.$(bld_trg)) \
2589 $($(target)_DEPS.$(bld_type)) \
2590 $($(target)_DEPS) \
2591 $($(target)_LNK_DEPS.$(bld_trg_cpu)) \
2592 $($(target)_LNK_DEPS.$(bld_trg).$(bld_trg_arch).$(bld_type)) \
2593 $($(target)_LNK_DEPS.$(bld_trg).$(bld_trg_arch)) \
2594 $($(target)_LNK_DEPS.$(bld_trg).$(bld_type)) \
2595 $($(target)_LNK_DEPS.$(bld_trg_arch)) \
2596 $($(target)_LNK_DEPS.$(bld_trg)) \
2597 $($(target)_LNK_DEPS.$(bld_type)) \
2598 $($(target)_LNK_DEPS)
2599local orderdeps := \
2600 $($(target)_ORDERDEPS.$(bld_trg_cpu)) \
2601 $($(target)_ORDERDEPS.$(bld_trg).$(bld_trg_arch).$(bld_type)) \
2602 $($(target)_ORDERDEPS.$(bld_trg).$(bld_trg_arch)) \
2603 $($(target)_ORDERDEPS.$(bld_trg).$(bld_type)) \
2604 $($(target)_ORDERDEPS.$(bld_trg_arch)) \
2605 $($(target)_ORDERDEPS.$(bld_trg)) \
2606 $($(target)_ORDERDEPS.$(bld_type)) \
2607 $($(target)_ORDERDEPS) \
2608 $($(target)_LNK_ORDERDEPS.$(bld_trg_cpu)) \
2609 $($(target)_LNK_ORDERDEPS.$(bld_trg).$(bld_trg_arch).$(bld_type)) \
2610 $($(target)_LNK_ORDERDEPS.$(bld_trg).$(bld_trg_arch)) \
2611 $($(target)_LNK_ORDERDEPS.$(bld_trg).$(bld_type)) \
2612 $($(target)_LNK_ORDERDEPS.$(bld_trg_arch)) \
2613 $($(target)_LNK_ORDERDEPS.$(bld_trg)) \
2614 $($(target)_LNK_ORDERDEPS.$(bld_type)) \
2615 $($(target)_LNK_ORDERDEPS)
2616
2617# Adjust paths if we got a default path.
2618ifneq ($(defpath),)
2619 local libpath := $(abspathex $(libpath),$(defpath))
2620 local deps := $(abspathex $(deps),$(defpath))
2621 local orderdeps := $(abspathex $(orderdeps),$(defpath))
2622 othersrc := $(abspathex $(othersrc),$(defpath))
2623 # libs are not subject to this because of the the -l<lib> stuff. Use $(<target>_DEFPATH)/lib if relative to current dir!
2624endif
2625
2626# Custom pre-link actions.
2627ifdef $(target)_PRE_CMDS.$(bld_trg).$(bld_trg_arch).$(bld_type)
2628 local pre_cmds := $($(target)_PRE_CMDS.$(bld_trg).$(bld_trg_arch).$(bld_type))
2629else ifdef $(target)_PRE_CMDS.$(bld_trg).$(bld_trg_arch)
2630 local pre_cmds := $($(target)_PRE_CMDS.$(bld_trg).$(bld_trg_arch))
2631else ifdef $(target)_PRE_CMDS.$(bld_trg).$(bld_type)
2632 local pre_cmds := $($(target)_PRE_CMDS.$(bld_trg).$(bld_type))
2633else ifdef $(target)_PRE_CMDS.$(bld_trg_arch)
2634 local pre_cmds := $($(target)_PRE_CMDS.$(bld_trg_arch))
2635else ifdef $(target)_PRE_CMDS.$(bld_trg)
2636 local pre_cmds := $($(target)_PRE_CMDS.$(bld_trg))
2637else ifdef $(target)_PRE_CMDS.$(bld_type)
2638 local pre_cmds := $($(target)_PRE_CMDS.$(bld_type))
2639else ifdef $(target)_PRE_CMDS
2640 local pre_cmds := $($(target)_PRE_CMDS)
2641else ifdef PRE_CMDS.$(bld_trg).$(bld_trg_arch).$(bld_type)
2642 local pre_cmds := $(PRE_CMDS.$(bld_trg).$(bld_trg_arch).$(bld_type))
2643else ifdef PRE_CMDS.$(bld_trg).$(bld_trg_arch)
2644 local pre_cmds := $(PRE_CMDS.$(bld_trg).$(bld_trg_arch))
2645else ifdef PRE_CMDS.$(bld_trg).$(bld_type)
2646 local pre_cmds := $(PRE_CMDS.$(bld_trg).$(bld_type))
2647else ifdef PRE_CMDS.$(bld_trg_arch)
2648 local pre_cmds := $(PRE_CMDS.$(bld_trg_arch))
2649else ifdef PRE_CMDS.$(bld_trg)
2650 local pre_cmds := $(PRE_CMDS.$(bld_trg))
2651else ifdef PRE_CMDS.$(bld_type)
2652 local pre_cmds := $(PRE_CMDS.$(bld_type))
2653else
2654 local pre_cmds := $(PRE_CMDS)
2655endif
2656
2657# Custom post-link actions.
2658ifdef $(target)_POST_CMDS.$(bld_trg).$(bld_trg_arch).$(bld_type)
2659 local post_cmds := $($(target)_POST_CMDS.$(bld_trg).$(bld_trg_arch).$(bld_type))
2660else ifdef $(target)_POST_CMDS.$(bld_trg).$(bld_trg_arch)
2661 local post_cmds := $($(target)_POST_CMDS.$(bld_trg).$(bld_trg_arch))
2662else ifdef $(target)_POST_CMDS.$(bld_trg).$(bld_type)
2663 local post_cmds := $($(target)_POST_CMDS.$(bld_trg).$(bld_type))
2664else ifdef $(target)_POST_CMDS.$(bld_trg_arch)
2665 local post_cmds := $($(target)_POST_CMDS.$(bld_trg_arch))
2666else ifdef $(target)_POST_CMDS.$(bld_trg)
2667 local post_cmds := $($(target)_POST_CMDS.$(bld_trg))
2668else ifdef $(target)_POST_CMDS.$(bld_type)
2669 local post_cmds := $($(target)_POST_CMDS.$(bld_type))
2670else ifdef $(target)_POST_CMDS
2671 local post_cmds := $($(target)_POST_CMDS)
2672else ifdef POST_CMDS.$(bld_trg).$(bld_trg_arch).$(bld_type)
2673 local post_cmds := $(POST_CMDS.$(bld_trg).$(bld_trg_arch).$(bld_type))
2674else ifdef POST_CMDS.$(bld_trg).$(bld_trg_arch)
2675 local post_cmds := $(POST_CMDS.$(bld_trg).$(bld_trg_arch))
2676else ifdef POST_CMDS.$(bld_trg).$(bld_type)
2677 local post_cmds := $(POST_CMDS.$(bld_trg).$(bld_type))
2678else ifdef POST_CMDS.$(bld_trg_arch)
2679 local post_cmds := $(POST_CMDS.$(bld_trg_arch))
2680else ifdef POST_CMDS.$(bld_trg)
2681 local post_cmds := $(POST_CMDS.$(bld_trg))
2682else ifdef POST_CMDS.$(bld_type)
2683 local post_cmds := $(POST_CMDS.$(bld_type))
2684else
2685 local post_cmds := $(POST_CMDS)
2686endif
2687
2688# eliminate this guy?
2689local objs = $($(target)_2_OBJS)
2690
2691# installation targets
2692ifeq ($(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))),)
2693 ifneq ($(strip $($(target)_INST.$(bld_trg).$(bld_trg_arch).$(bld_type))),)
2694 local inst := $(addprefix $(PATH_INS)/,$($(target)_INST.$(bld_trg).$(bld_trg_arch).$(bld_type)))
2695 else ifneq ($(strip $($(target)_INST.$(bld_trg).$(bld_trg_arch))),)
2696 local inst := $(addprefix $(PATH_INS)/,$($(target)_INST.$(bld_trg).$(bld_trg_arch)))
2697 else ifneq ($(strip $($(target)_INST.$(bld_trg).$(bld_type))),)
2698 local inst := $(addprefix $(PATH_INS)/,$($(target)_INST.$(bld_trg).$(bld_type)))
2699 else ifneq ($(strip $($(target)_INST.$(bld_trg_arch))),)
2700 local inst := $(addprefix $(PATH_INS)/,$($(target)_INST.$(bld_trg_arch)))
2701 else ifneq ($(strip $($(target)_INST.$(bld_trg))),)
2702 local inst := $(addprefix $(PATH_INS)/,$($(target)_INST.$(bld_trg)))
2703 else ifneq ($(strip $($(target)_INST.$(bld_type))),)
2704 local inst := $(addprefix $(PATH_INS)/,$($(target)_INST.$(bld_type)))
2705 else ifneq ($(strip $($(target)_INST)),)
2706 local inst := $(addprefix $(PATH_INS)/,$($(target)_INST))
2707 else
2708 local inst := $(definst)/
2709 endif
2710 INSTARGET_$(target) := $(patsubst %/,%/$(notdir $(out)),$(inst))
2711 ifdef KBUILD_DO_AUTO_INSTALL
2712 $(typevar) += $(INSTARGET_$(target))
2713 else
2714 $(typevar) += $(out)
2715 endif
2716 local mode := $(firstword \
2717 $($(target)_MODE.$(bld_trg).$(bld_trg_arch).$(bld_type)) \
2718 $($(target)_MODE.$(bld_trg).$(bld_trg_arch)) \
2719 $($(target)_MODE.$(bld_trg).$(bld_type)) \
2720 $($(target)_MODE.$(bld_trg_arch)) \
2721 $($(target)_MODE.$(bld_trg)) \
2722 $($(target)_MODE.$(bld_type)) \
2723 $($(target)_MODE) )
2724 local uid := $(firstword \
2725 $($(target)_UID.$(bld_trg).$(bld_trg_arch).$(bld_type)) \
2726 $($(target)_UID.$(bld_trg).$(bld_trg_arch)) \
2727 $($(target)_UID.$(bld_trg).$(bld_type)) \
2728 $($(target)_UID.$(bld_trg_arch)) \
2729 $($(target)_UID.$(bld_trg)) \
2730 $($(target)_UID.$(bld_type)) \
2731 $($(target)_UID) )
2732 local gid := $(firstword \
2733 $($(target)_GID.$(bld_trg).$(bld_trg_arch).$(bld_type)) \
2734 $($(target)_GID.$(bld_trg).$(bld_trg_arch)) \
2735 $($(target)_GID.$(bld_trg).$(bld_type)) \
2736 $($(target)_GID.$(bld_trg_arch)) \
2737 $($(target)_GID.$(bld_trg)) \
2738 $($(target)_GID.$(bld_type)) \
2739 $($(target)_GID) )
2740
2741 # generate the install rule
2742$(eval $(def_link_install_rule))
2743
2744else # NOINST
2745 INSTARGET_$(target) :=
2746 $(typevar) += $(out)
2747endif # NOINST
2748
2749# dependency file
2750local dep := $(outbase)$(SUFF_DEP)
2751ifndef NO_LINK_CMDS_DEPS
2752 _DEPFILES_INCLUDED += $(dep)
2753 ifdef KB_HAVE_INCLUDEDEP_QUEUE
2754 includedep-queue $(dep)
2755 else
2756 includedep $(dep)
2757 endif
2758endif
2759
2760# check that the tool is defined.
2761ifndef TOOL_$(tool)_$(tool_do)_CMDS
2762$(warning kBuild: tools: \
2763 1 $($(target)_$(source)TOOL.$(bld_trg).$(bld_trg_arch)) \
2764 2 $($(target)_$(source)TOOL.$(bld_trg)) \
2765 3 $($(target)_$(source)TOOL) \
2766 4 $($(target)_TOOL.$(bld_trg).$(bld_trg_arch)) \
2767 5 $($(target)_TOOL.$(bld_trg)) \
2768 6 $($(target)_TOOL) \
2769 7 $($(source)TOOL.$(bld_trg).$(bld_trg_arch)) \
2770 8 $($(source)TOOL.$(bld_trg)) \
2771 9 $($(source)TOOL) \
2772 10 $(TOOL.$(bld_trg).$(bld_trg_arch)) \
2773 11 $(TOOL.$(bld_trg)) \
2774 12 $(TOOL) )
2775$(error kBuild: TOOL_$(tool)_$(tool_do)_CMDS isn't defined! target=$(target) )
2776endif
2777
2778# call the tool
2779local cmds := $(TOOL_$(tool)_$(tool_do)_CMDS)
2780ifneq ($(pre_cmds),)
2781 local cmds := $(TAB)$(pre_cmds)$(NL)$(TAB)$(cmds)
2782endif
2783ifneq ($(post_cmds),)
2784 local cmds := $(cmds)$(NL)$(TAB)$(post_cmds)
2785endif
2786$(target)_2_OUTPUT := $(TOOL_$(tool)_$(tool_do)_OUTPUT)
2787$(target)_2_OUTPUT_MAYBE := $(TOOL_$(tool)_$(tool_do)_OUTPUT_MAYBE)
2788$(target)_2_DEPEND := $(TOOL_$(tool)_$(tool_do)_DEPEND) $(deps) $($(target)_2_OBJS)
2789$(target)_2_DEPORD := $(TOOL_$(tool)_$(tool_do)_DEPORD) $(dirdep) $(orderdeps)
2790
2791# generate the link rule.
2792$(eval $(def_link_rule))
2793
2794
2795# Update globals.
2796_OBJS += $($(target)_2_OBJS)
2797_OUT_FILES += $($(target)_2_OUTPUT) $($(target)_2_OUTPUT_MAYBE) $(out)
2798_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))
2799_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))
2800_INSTALLS_FILES += $(INSTARGET_$(target))
2801
2802endef # def_link_common
2803$(eval-opt-var def_link_common)
2804
2805
2806#
2807# BLDPROGS
2808#
2809
2810## Build program (one).
2811# @param $(target) Normalized target (program) name.
2812define def_bldprog
2813
2814# set NOINST if not forced installation.
2815ifndef $(target)_INST
2816$(target)_NOINST := 1
2817endif
2818
2819# do the usual stuff.
2820$(evalval def_link_common)
2821
2822endef
2823
2824# Process build programs.
2825EXT := EXE
2826EXTPRE := HOST
2827tool_do := LINK_PROGRAM
2828definst := $(PATH_BIN)
2829typevar := _BLDPROGS
2830mode := 0755
2831bld_trg_base_var := PLATFORM
2832$(foreach target, $(_ALL_BLDPROGS), $(evalval def_bldprog))
2833
2834ifdef KBUILD_PROFILE_SELF
2835 $(evalcall def_profile_self, done build program targets)
2836endif
2837
2838
2839#
2840# DLLS
2841#
2842
2843# Process dlls
2844EXT := DLL
2845EXTPRE :=
2846tool_do := LINK_DLL
2847definst := $(PATH_DLL)
2848typevar := _DLLS
2849mode := 0644
2850bld_trg_base_var := TARGET
2851$(foreach target, $(_ALL_DLLS), $(evalval def_link_common))
2852
2853ifdef KBUILD_PROFILE_SELF
2854 $(evalcall def_profile_self, done dll targets)
2855endif
2856
2857
2858#
2859# IMPORT LIBRARIES
2860#
2861# - On OS/2 and windows these are libraries.
2862# - On other platforms they are fake DLLs.
2863#
2864EXTPRE :=
2865typevar := _IMPORT_LIBS
2866mode := 0644
2867bld_trg_base_var := TARGET
2868ifeq ($(filter-out nt os2 win win64 win32,$(KBUILD_TARGET)),)
2869 EXT := LIB
2870 tool_do := LINK_LIBRARY
2871 definst := $(PATH_LIB)
2872 $(foreach target, $(_ALL_IMPORT_LIBS), $(evalval def_lib))
2873else
2874 EXT := DLL
2875 tool_do := LINK_DLL
2876 definst := $(PATH_DLL)
2877 $(foreach target, $(_ALL_IMPORT_LIBS), $(evalval def_link_common))
2878endif
2879
2880ifdef KBUILD_PROFILE_SELF
2881 $(evalcall def_profile_self, done import library targets)
2882endif
2883
2884
2885#
2886# PROGRAMS
2887#
2888
2889# Process programs
2890EXT := EXE
2891EXTPRE :=
2892tool_do := LINK_PROGRAM
2893definst := $(PATH_BIN)
2894typevar := _PROGRAMS
2895mode := 0755
2896bld_trg_base_var := TARGET
2897$(foreach target, $(_ALL_PROGRAMS), $(evalval def_link_common))
2898
2899ifdef KBUILD_PROFILE_SELF
2900 $(evalcall def_profile_self, done program targets)
2901endif
2902
2903
2904#
2905# SYSMODS
2906#
2907
2908# Process sysmods
2909EXT := SYS
2910EXTPRE :=
2911tool_do := LINK_SYSMOD
2912definst := $(PATH_SYS)
2913typevar := _SYSMODS
2914mode := 0644
2915bld_trg_base_var := TARGET
2916$(foreach target, $(_ALL_SYSMODS), $(evalval def_link_common))
2917
2918ifdef KBUILD_PROFILE_SELF
2919 $(evalcall def_profile_self, done sysmod targets)
2920endif
2921
2922
2923#
2924# MISCBINS
2925#
2926
2927# Process MISCBINS
2928EXT := BIN
2929EXTPRE :=
2930tool_do := LINK_MISCBIN
2931definst := $(PATH_BIN)
2932typevar := _MISCBINS
2933mode := 0644
2934bld_trg_base_var := TARGET
2935$(foreach target, $(_ALL_MISCBINS), $(evalval def_link_common))
2936
2937ifdef KBUILD_PROFILE_SELF
2938 $(evalcall def_profile_self, done misc binary targets)
2939endif
2940
2941
2942#
2943# OTHERS
2944#
2945_OTHERS = $(OTHERS) $(OTHERS.$(KBUILD_TARGET)) $(OTHERS.$(KBUILD_TARGET).$(KBUILD_TARGET_ARCH))
2946
2947
2948#
2949# INSTALLS
2950#
2951
2952## generate the install rule
2953define def_install_src_rule
2954# the install rule
2955$(insdst) : $(srcsrc) | $(call DIRDEP,$(dir $(insdst)))
2956 %$$(call MSG_INST_FILE,$(srcsrc),$(insdst))
2957 $$(QUIET)$(inscmd)
2958endef
2959$(eval-opt-var def_install_src_rule)
2960
2961## install one file
2962define def_install_src
2963
2964# deal with '=>' in the source file name.
2965ifeq ($(src),=>)
2966 $(error kBuild: Install target '$(target)' has a bad source specifier containing '=>' without any file names)
2967endif
2968ifeq ($(substr $(src),1,2),=>)
2969 $(warning kBuild: Install target '$(target)' has a bad source specifier: $(src))
2970endif
2971ifeq ($(substr $(src),-2),=>)
2972 $(warning kBuild: Install target '$(target)' has a bad source specifier: $(src))
2973endif
2974local srcdst := $(subst =>, ,$(src))
2975local srcsrc := $(firstword $(srcdst))
2976local srcdstdir := $(dir $(word 2,$(srcdst)))
2977local srcdst := $(word $(words $(srcdst)),$(srcdst))
2978
2979# _INSTFUN
2980ifdef $(srcsrc)_INSTFUN
2981 local instfun := $(srcsrc)_INSTFUN
2982else ifdef $(target)_INSTFUN
2983 local instfun := $(target)_INSTFUN
2984else
2985 local instfun := _INSTALL_FILE
2986endif
2987
2988# _INST
2989ifdef $(srcsrc)_INST
2990 local inst := $(patsubst %/,%,$($(srcsrc)_INST))/$(dir $(srcdstdir))
2991else ifdef $(target)_INST
2992 local inst := $(patsubst %/,%,$($(target)_INST))/$(dir $(srcdstdir))
2993else
2994 local inst := $(dir $(srcdstdir))
2995endif
2996
2997# calc target
2998local insdst := $(call $(instfun),$(srcdst),$(target),$(inst),$(PATH_INS))
2999#$(warning instfun=$(instfun) srcdst=$(srcdst) target=$(target) inst=$(inst) => insdst=$(insdst))
3000
3001# mode, uid and gid
3002local mode := $(firstword \
3003 $($(target)_$(srcsrc)_MODE.$(bld_trg).$(bld_trg_arch)) \
3004 $($(target)_$(srcsrc)_MODE.$(bld_trg)) \
3005 $($(target)_$(srcsrc)_MODE) \
3006 $($(target)_$(srcdst)_MODE.$(bld_trg).$(bld_trg_arch)) \
3007 $($(target)_$(srcdst)_MODE.$(bld_trg)) \
3008 $($(target)_$(srcdst)_MODE) \
3009 $($(srcsrc)_MODE.$(bld_trg).$(bld_trg_arch)) \
3010 $($(srcsrc)_MODE.$(bld_trg)) \
3011 $($(srcsrc)_MODE) \
3012 $($(srcdst)_MODE.$(bld_trg).$(bld_trg_arch)) \
3013 $($(srcdst)_MODE.$(bld_trg)) \
3014 $($(srcdst)_MODE) \
3015 $($(target)_MODE.$(bld_trg).$(bld_trg_arch)) \
3016 $($(target)_MODE.$(bld_trg)) \
3017 $($(target)_MODE))
3018local uid := $(firstword \
3019 $($(target)_$(srcsrc)_UID.$(bld_trg).$(bld_trg_arch)) \
3020 $($(target)_$(srcsrc)_UID.$(bld_trg)) \
3021 $($(target)_$(srcsrc)_UID) \
3022 $($(target)_$(srcdst)_UID.$(bld_trg).$(bld_trg_arch)) \
3023 $($(target)_$(srcdst)_UID.$(bld_trg)) \
3024 $($(target)_$(srcdst)_UID) \
3025 $($(srcsrc)_UID.$(bld_trg).$(bld_trg_arch)) \
3026 $($(srcsrc)_UID.$(bld_trg)) \
3027 $($(srcsrc)_UID) \
3028 $($(srcdst)_UID.$(bld_trg).$(bld_trg_arch)) \
3029 $($(srcdst)_UID.$(bld_trg)) \
3030 $($(srcdst)_UID) \
3031 $($(target)_UID.$(bld_trg).$(bld_trg_arch)) \
3032 $($(target)_UID.$(bld_trg)) \
3033 $($(target)_UID))
3034local gid := $(firstword \
3035 $($(target)_$(srcsrc)_GID.$(bld_trg).$(bld_trg_arch)) \
3036 $($(target)_$(srcsrc)_GID.$(bld_trg)) \
3037 $($(target)_$(srcsrc)_GID) \
3038 $($(target)_$(srcdst)_GID.$(bld_trg).$(bld_trg_arch)) \
3039 $($(target)_$(srcdst)_GID.$(bld_trg)) \
3040 $($(target)_$(srcdst)_GID) \
3041 $($(srcsrc)_GID.$(bld_trg).$(bld_trg_arch)) \
3042 $($(srcsrc)_GID.$(bld_trg)) \
3043 $($(srcsrc)_GID) \
3044 $($(srcdst)_GID.$(bld_trg).$(bld_trg_arch)) \
3045 $($(srcdst)_GID.$(bld_trg)) \
3046 $($(srcdst)_GID) \
3047 $($(target)_GID.$(bld_trg).$(bld_trg_arch)) \
3048 $($(target)_GID.$(bld_trg)) \
3049 $($(target)_GID))
3050local flags := \
3051 $($(target)_IFFLAGS) \
3052 $($(target)_IFFLAGS.$(bld_trg)) \
3053 $($(target)_IFFLAGS.$(bld_trg).$(bld_trg_arch)) \
3054 $($(srcdst)_IFFLAGS) \
3055 $($(srcdst)_IFFLAGS.$(bld_trg)) \
3056 $($(srcdst)_IFFLAGS.$(bld_trg).$(bld_trg_arch)) \
3057 $($(srcsrc)_IFFLAGS) \
3058 $($(srcsrc)_IFFLAGS.$(bld_trg)) \
3059 $($(srcsrc)_IFFLAGS.$(bld_trg).$(bld_trg_arch)) \
3060 $($(target)_$(srcdst)_IFFLAGS) \
3061 $($(target)_$(srcdst)_IFFLAGS.$(bld_trg)) \
3062 $($(target)_$(srcdst)_IFFLAGS.$(bld_trg).$(bld_trg_arch)) \
3063 $($(target)_$(srcsrc)_IFFLAGS) \
3064 $($(target)_$(srcsrc)_IFFLAGS.$(bld_trg)) \
3065 $($(target)_$(srcsrc)_IFFLAGS.$(bld_trg).$(bld_trg_arch))
3066clean_files += \
3067 $($(srcdst)_CLEAN) \
3068 $($(srcdst)_CLEAN.$(bld_trg)) \
3069 $($(srcdst)_CLEAN.$(bld_trg).$(bld_trg_arch)) \
3070 $($(srcsrc)_CLEAN) \
3071 $($(srcsrc)_CLEAN.$(bld_trg)) \
3072 $($(srcsrc)_CLEAN.$(bld_trg).$(bld_trg_arch)) \
3073 $($(target)_$(srcdst)_CLEAN) \
3074 $($(target)_$(srcdst)_CLEAN.$(bld_trg)) \
3075 $($(target)_$(srcdst)_CLEAN.$(bld_trg).$(bld_trg_arch)) \
3076 $($(target)_$(srcsrc)_CLEAN) \
3077 $($(target)_$(srcsrc)_CLEAN.$(bld_trg)) \
3078 $($(target)_$(srcsrc)_CLEAN.$(bld_trg).$(bld_trg_arch))
3079
3080
3081# Adjust the source if we got a default PATH. (This must be done this late!)
3082local defpath := $(firstword $($(target)_PATH) $($(target)_DEFPATH))
3083ifneq ($(defpath),)
3084 local srcsrc := $(abspathex $(srcsrc),$(defpath))
3085endif
3086
3087# create the command
3088ifdef $(srcsrc)_INSTALLER
3089 local inscmd := $(call $(srcsrc)_INSTALLER,$(srcsrc),$(insdst),$(target),$(flags))
3090else ifdef $(target)_INSTALLER
3091 local inscmd := $(call $(target)_INSTALLER,$(srcsrc),$(insdst),$(target),$(flags))
3092else
3093 local inscmd := $$(INSTALL)\
3094 $(if $(uid),-o $(uid))\
3095 $(if $(gid),-g $(gid))\
3096 $(if $(mode),-m $(mode))\
3097 $(flags) -- \
3098 $(srcsrc) $(insdst)
3099endif
3100
3101# generate the rule (need double evaluation here)
3102$(eval $(def_install_src_rule))
3103
3104INSTARGET_$(target) += $(insdst)
3105endef # def_install_src
3106$(eval-opt-var def_install_src)
3107
3108
3109## generate the symlink rule
3110define def_install_symlink_rule
3111# the install rule
3112$(insdst) : | $(call DIRDEP,$(dir $(insdst)))
3113 %$$(call MSG_INST_SYM,$(insdst),$(symdst))
3114 $$(QUIET)$$(RM) -f -- $$@
3115 $$(QUIET)$$(LN_SYMLINK) $(symdst) $(insdst)
3116endef # def_install_symlink_rule
3117$(eval-opt-var def_install_symlink_rule)
3118
3119## create one symlink
3120define def_install_symlink
3121
3122# deal with '=>' in the source file name.
3123local symdst := $(subst =>, ,$(src))
3124local symlnk := $(firstword $(symdst))
3125local symdst := $(word $(words $(symdst)),$(symdst))
3126
3127# _INSTFUN
3128ifdef $(symlnk)_INSTFUN
3129 local instfun := $(symlnk)_INSTFUN
3130else ifdef $(target)_INSTFUN
3131 local instfun := $(target)_INSTFUN
3132else
3133 local instfun := _INSTALL_FILE
3134endif
3135
3136# _INST
3137ifdef $(symlnk)_INST
3138 local inst := $(patsubst %/,%,$($(symlnk)_INST))/$(dir $(symlnk))
3139else ifdef $(target)_INST
3140 local inst := $(patsubst %/,%,$($(target)_INST))/$(dir $(symlnk))
3141else
3142 local inst := $(dir $(symlnk))
3143endif
3144
3145# calc target
3146local insdst := $(call $(instfun),$(symlnk),$(target),$(inst),$(PATH_INS))
3147#$(warning symlnk=$(symlnk) symdst=$(symdst) insdst=$(insdst) instfun=$(instfun) inst='$(inst)')
3148
3149# generate the rule (need double evaluation here)
3150$(eval $(def_install_symlink_rule))
3151
3152INSTARGET_$(target) += $(insdst)
3153endef # def_install_symlink
3154$(optmize def_install_symlink)
3155
3156
3157## generate the install rule
3158define def_install_directory_rule
3159# the install rule
3160$(insdst):
3161 %$$(call MSG_INST_DIR,$(insdst))
3162 $$(QUIET)$$(INSTALL) -d \
3163 $(if $(uid),-o $(uid))\
3164 $(if $(gid),-g $(gid))\
3165 $(if $(mode),-m $(mode))\
3166 $(flags) -- \
3167 $(insdst)
3168
3169.NOTPARALLEL: $(insdst)
3170endef # def_install_directory_rule
3171$(eval-opt-var def_install_directory_rule)
3172
3173
3174## create one directory
3175define def_install_directory
3176
3177# _INST
3178ifdef $(directory)_INST
3179 local inst := $(PATH_INS)/$(patsubst %/,%,$($(directory)_INST))
3180else ifdef $(target)_INST
3181 local inst := $(PATH_INS)/$(patsubst %/,%,$($(target)_INST))
3182else
3183 local inst := $(PATH_INS)
3184endif
3185
3186local mode := $(firstword \
3187 $($(target)_$(directory)_MODE.$(bld_trg).$(bld_trg_arch)) \
3188 $($(target)_$(directory)_MODE.$(bld_trg)) \
3189 $($(target)_$(directory)_MODE) \
3190 $($(directory)_MODE.$(bld_trg).$(bld_trg_arch)) \
3191 $($(directory)_MODE.$(bld_trg)) \
3192 $($(directory)_MODE) \
3193 $($(target)_MODE.$(bld_trg).$(bld_trg_arch)) \
3194 $($(target)_MODE.$(bld_trg)) \
3195 $($(target)_MODE))
3196local uid := $(firstword \
3197 $($(target)_$(directory)_UID.$(bld_trg).$(bld_trg_arch)) \
3198 $($(target)_$(directory)_UID.$(bld_trg)) \
3199 $($(target)_$(directory)_UID) \
3200 $($(directory)_UID.$(bld_trg).$(bld_trg_arch)) \
3201 $($(directory)_UID.$(bld_trg)) \
3202 $($(directory)_UID) \
3203 $($(target)_UID.$(bld_trg).$(bld_trg_arch)) \
3204 $($(target)_UID.$(bld_trg)) \
3205 $($(target)_UID))
3206local gid := $(firstword \
3207 $($(target)_$(directory)_GID.$(bld_trg).$(bld_trg_arch)) \
3208 $($(target)_$(directory)_GID.$(bld_trg)) \
3209 $($(target)_$(directory)_GID) \
3210 $($(directory)_GID.$(bld_trg).$(bld_trg_arch)) \
3211 $($(directory)_GID.$(bld_trg)) \
3212 $($(directory)_GID) \
3213 $($(target)_GID.$(bld_trg).$(bld_trg_arch)) \
3214 $($(target)_GID.$(bld_trg)) \
3215 $($(target)_GID))
3216local flags := \
3217 $($(target)_IDFLAGS)\
3218 $($(target)_IDFLAGS.$(bld_trg)) \
3219 $($(target)_IDFLAGS.$(bld_trg).$(bld_trg_arch)) \
3220 $($(directory)_IDFLAGS) \
3221 $($(directory)_IDFLAGS.$(bld_trg)) \
3222 $($(directory)_IDFLAGS.$(bld_trg).$(bld_trg_arch)) \
3223 $($(target)_$(directory)_IDFLAGS) \
3224 $($(target)_$(directory)_IDFLAGS.$(bld_trg)) \
3225 $($(target)_$(directory)_IDFLAGS.$(bld_trg).$(bld_trg_arch))
3226
3227local insdst := $(inst)/$(directory)/
3228#$(warning directory=$(directory) inst=$(inst) insdst=$(insdst) mode=$(mode) gid=$(gid) uid=$(uid))
3229
3230# generate the rule (need double evaluation here)
3231$(eval $(def_install_directory_rule))
3232
3233INSTARGET_DIRS_$(target) += $(insdst)
3234endef # def_install_directory
3235$(eval-opt-var def_install_directory)
3236
3237
3238## process one install target.
3239define def_install
3240# the basics.
3241local bld_type := $(firstword $($(target)_BLD_TYPE) $(KBUILD_TYPE))
3242local bld_trg := $(firstword $($(target)_BLD_TRG) $(KBUILD_TARGET))
3243local bld_trg_arch:= $(firstword $($(target)_BLD_TRG_ARCH) $(KBUILD_TARGET_ARCH))
3244local bld_trg_cpu := $(firstword $($(target)_BLD_TRG_CPU) $(KBUILD_TARGET_CPU))
3245
3246INSTARGET_$(target) := $($(target)_GOALS)
3247INSTARGET_DIRS_$(target) :=
3248local outbase := $(call TARGET_BASE,$(target),$(target))
3249$(target)_0_OUTDIR := $(patsubst %/,%,$(dir $(outbase)))
3250PATH_$(target) := $($(target)_0_OUTDIR)
3251
3252local 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))
3253
3254$(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)), \
3255 $(evalval def_install_directory))
3256
3257$(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)), \
3258 $(evalval def_install_src))
3259
3260$(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)), \
3261 $(evalval def_install_symlink))
3262
3263# the collection target
3264local clean_files += $(PATH_TARGET)/$(target).ins
3265$(target)_1_TARGET := $(PATH_TARGET)/$(target).ins
3266TARGET_$(target) := $($(target)_1_TARGET)
3267$($(target)_1_TARGET): $$(INSTARGET_$(target)) | $$(INSTARGET_DIRS_$(target)) $(call DIRDEP,$(PATH_TARGET))
3268 @$(QUIET2)$(APPEND) $@
3269
3270$(target): $$($(target)_1_TARGET)
3271
3272_INSTALLS += $($(target)_1_TARGET)
3273_INSTALLS_FILES += $(INSTARGET_$(target))
3274_INSTALLS_DIRS += $(INSTARGET_DIRS_$(target))
3275_CLEAN_FILES += $(clean_files)
3276_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))
3277endef # def_install
3278$(eval-opt-var def_install)
3279
3280## process all install targets
3281$(foreach target, $(_ALL_INSTALLS), \
3282 $(evalvalctx def_install))
3283
3284ifdef KBUILD_PROFILE_SELF
3285 $(evalcall def_profile_self, done install targets)
3286endif
3287
3288# Some introspection targets that can be useful for package maintainers.
3289.PHONY: kbuild-show-install-files kbuild-show-install-dirs
3290kbuild-show-install-files::
3291 $(addprefix $(NL)$(TAB)$(QUIET)$(ECHO) , $(subst $(PATH_INS)/,,$(_INSTALLS_FILES)))
3292
3293kbuild-show-install-dirs::
3294 $(addprefix $(NL)$(TAB)$(QUIET)$(ECHO) , $(subst $(PATH_INS)/,,$(_INSTALLS_DIRS)))
3295
3296
3297#
3298# TESTING
3299#
3300_TESTING += $(TESTING) $(TESTING.$(KBUILD_TARGET)) $(TESTING.$(KBUILD_TARGET).$(KBUILD_TARGET_ARCH)) $(TESTING.$(KBUILD_TARGET_ARCH)) $(TESTING.$(KBUILD_TARGET_CPU))
3301
3302
3303#
3304# PACKING
3305#
3306_PACKING += $(PACKING) $(PACKING.$(KBUILD_TARGET)) $(PACKING.$(KBUILD_TARGET).$(KBUILD_TARGET_ARCH)) $(PACKING.$(KBUILD_TARGET_ARCH)) $(PACKING.$(KBUILD_TARGET_CPU))
3307
3308
3309#
3310# DOCS
3311#
3312
3313
3314#
3315# DIRECTORIES
3316#
3317_DIR_ALL := $(sort $(addsuffix /,$(patsubst %/,%,$(_DIRS))) $(dir $(_OUT_FILES) $(_OBJS) $(_INSTALLS_FILES)))
3318$(foreach directory,$(_INSTALLS_DIRS), $(eval _DIR_ALL := $(filter-out $(directory),$(_DIR_ALL))))
3319
3320
3321define def_mkdir_rule
3322$(directory):
3323 %$$(call MSG_MKDIR,$$@)
3324 $$(QUIET)$$(MKDIR) -p -- $$@
3325endef
3326
3327$(foreach directory,$(_DIR_ALL),$(eval $(def_mkdir_rule)))
3328
3329ifdef KBUILD_PROFILE_SELF
3330 $(evalcall def_profile_self, done directories)
3331endif
3332
3333
3334#
3335# NOTHING
3336#
3337do-nothing:
3338 %$(call MSG_NOTHING)
3339ifdef KBUILD_PROFILE_SELF
3340 @$(ECHO) 'prof: $(call _KBUILD_FMT_ELAPSED_EX, $(nanots ), $(_KBUILD_TS_HEADER_START)) - $(call _KBUILD_FMT_ELAPSED_EX, $(nanots ), $(_KBUILD_TS_PREV)) - executing $@'
3341 ifeq ($(KBUILD_PROFILE_SELF),2)
3342 @$(ECHO) 'stat: $(make-stats )'
3343 endif
3344endif
3345
3346
3347#
3348# CLEAN UP
3349#
3350do-clean:
3351 %$(call MSG_CLEAN)
3352 $(QUIET)$(RM) -f -- $(_OUT_FILES) $(_OBJS) $(_DEPFILES) $(_DEPFILES_INCLUDED) $(_CLEAN_FILES) $(OTHER_CLEAN)
3353 $(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)))
3354
3355
3356
3357#
3358# PASSES (including directory and makefile walking)
3359#
3360
3361#
3362# First, check whether we need to order the passes explicitly or not.
3363# This depends on whether we're a leaf makefile or not. A leaf will
3364# know all its dependencies, while a recursive one relies on the
3365# order sub-directories and other makefiles are executed it.
3366#
3367
3368## Setup a pass and check for optimizations.
3369# @param $(PASS) Uppercase pass name.
3370define def_pass_setup_and_optimize
3371
3372# The setup. ## @todo This is looks a bit weird...
3373ifndef SUBDIRS_$(PASS)
3374 SUBDIRS_$(PASS) := $(SUBDIRS) $(SUBDIRS.$(KBUILD_TARGET)) $(SUBDIRS.$(KBUILD_TARGET).$(KBUILD_TARGET_ARCH))
3375endif
3376ifndef SUBDIRS_AFTER_$(PASS)
3377 SUBDIRS_AFTER_$(PASS) := $(SUBDIRS_AFTER) $(SUBDIRS_AFTER.$(KBUILD_TARGET)) $(SUBDIRS_AFTER.$(KBUILD_TARGET).$(KBUILD_TARGET_ARCH))
3378endif
3379ifndef MAKEFILES_BEFORE_$(PASS)
3380 MAKEFILES_BEFORE_$(PASS) := $(MAKEFILES_BEFORE) $(MAKEFILES_BEFORE.$(KBUILD_TARGET)) $(MAKEFILES_BEFORE.$(KBUILD_TARGET).$(KBUILD_TARGET_ARCH))
3381endif
3382ifndef MAKEFILES_AFTER_$(PASS)
3383 MAKEFILES_AFTER_$(PASS) := $(MAKEFILES_AFTER) $(MAKEFILES_AFTER.$(KBUILD_TARGET)) $(MAKEFILES_AFTER.$(KBUILD_TARGET).$(KBUILD_TARGET_ARCH))
3384endif
3385
3386# The check.
3387ifeq ($(_KBUILD_STRICT_PASS_ORDER),nonstrict)
3388 ifneq ($(strip \
3389 $(SUBDIRS_$(PASS)) $(SUBDIRS_$(PASS).$(KBUILD_TARGET)) $(SUBDIRS_$(PASS).$(KBUILD_TARGET).$(KBUILD_TARGET_ARCH)) \
3390 $(MAKEFILES_BEFORE_$(PASS)) $(MAKEFILES_BEFORE_$(PASS).$(KBUILD_TARGET)) $(MAKEFILES_BEFORE_$(PASS).$(KBUILD_TARGET).$(KBUILD_TARGET_ARCH)) \
3391 $(SUBDIRS_AFTER_$(PASS)) $(SUBDIRS_AFTER_$(PASS).$(KBUILD_TARGET)) $(SUBDIRS_AFTER_$(PASS).$(KBUILD_TARGET).$(KBUILD_TARGET_ARCH)) \
3392 $(MAKEFILES_AFTER_$(PASS)) $(MAKEFILES_AFTER_$(PASS).$(KBUILD_TARGET)) $(MAKEFILES_AFTER_$(PASS).$(KBUILD_TARGET).$(KBUILD_TARGET_ARCH)) \
3393 ),)
3394 _KBUILD_STRICT_PASS_ORDER := strict
3395 endif
3396endif # _KBUILD_STRICT_PASS_ORDER == nonstrict
3397endef # def_pass_setup_and_optimize
3398$(eval-opt-var def_pass_setup_and_optimize)
3399
3400## PASS: Setup & optimization.
3401# Check if we can apply the non-strict pass order optimzation (no SUBDIRS_* and MAKEFILES_*),
3402# and set up the pass specific variables as we go along.
3403_KBUILD_STRICT_PASS_ORDER := nonstrict
3404$(foreach PASS, $(PASSES), $(evalval def_pass_setup_and_optimize))
3405#$ (error _KBUILD_STRICT_PASS_ORDER=$(_KBUILD_STRICT_PASS_ORDER))
3406
3407ifeq ($(_KBUILD_STRICT_PASS_ORDER),strict)
3408 if !defined(KBUILD_SAFE_PARALLEL) || "$(KMK_OPT_JOBS)" == "1"
3409_KBUILD_STRICT_PASS_ORDER := strict_unsafe
3410 endif
3411endif
3412
3413
3414## Subdir
3415# @param $(pass) Lowercase pass name.
3416# @param $(PASS) Uppercase pass name.
3417# @param $(subdir) Subdirectory
3418# @param $(tag) tag to attach to the rule name.
3419define def_pass_subdir
3420pass_$(pass)$(tag):: $(dep)
3421 + $$(QUIET)$$(MAKE) -C $(subdir) -f $$(notdir $$(firstword $$(wildcard $$(addprefix $(subdir)/,$$(DEFAULT_MAKEFILE))))) pass_$(pass)
3422endef
3423
3424## Submakefile
3425# @param $(pass) Lowercase pass name.
3426# @param $(PASS) Uppercase pass name.
3427# @param $(makefile) Makefile.
3428# @param $(tag) tag to attach to the rule name.
3429define def_pass_makefile
3430pass_$(pass)$(tag):: $(dep)
3431 + $$(QUIET)$$(MAKE) -C $(patsubst %/,%,$(dir $(makefile))) -f $(notdir $(makefile)) pass_$(pass)
3432endef
3433
3434## Execute a pass, strict order.
3435# @param $(pass) Lowercase pass name.
3436# @param $(PASS) Uppercase pass name.
3437define def_pass_strict
3438$(eval tag:=_before)
3439$(eval dep:= )
3440$(foreach subdir, $(SUBDIRS_$(PASS)) $(SUBDIRS_$(PASS).$(KBUILD_TARGET)) $(SUBDIRS_$(PASS).$(KBUILD_TARGET).$(KBUILD_TARGET_ARCH)) ,$(eval $(def_pass_subdir)))
3441$(foreach makefile,$(MAKEFILES_BEFORE_$(PASS)) $(MAKEFILES_BEFORE_$(PASS).$(KBUILD_TARGET)) $(MAKEFILES_BEFORE_$(PASS).$(KBUILD_TARGET).$(KBUILD_TARGET_ARCH)),$(eval $(def_pass_makefile)))
3442
3443$(eval tag:=_after)
3444$(eval dep:=pass_$(pass)_doit)
3445$(foreach subdir, $(SUBDIRS_AFTER_$(PASS)) $(SUBDIRS_AFTER_$(PASS).$(KBUILD_TARGET)) $(SUBDIRS_AFTER_$(PASS).$(KBUILD_TARGET).$(KBUILD_TARGET_ARCH)) ,$(eval $(def_pass_subdir)))
3446$(foreach makefile,$(MAKEFILES_AFTER_$(PASS)) $(MAKEFILES_AFTER_$(PASS).$(KBUILD_TARGET)) $(MAKEFILES_AFTER_$(PASS).$(KBUILD_TARGET).$(KBUILD_TARGET_ARCH)) ,$(eval $(def_pass_makefile)))
3447
3448.NOTPARALLEL: pass_$(pass) pass_$(pass)_before pass_$(pass)_after pass_$(pass)_this
3449.PHONY: pass_$(pass) pass_$(pass)_before pass_$(pass)_after pass_$(pass)_this pass_$(pass)_doit
3450pass_$(pass)_doit: $(PASS_$(PASS)_trgs) $(foreach var,$(PASS_$(PASS)_vars),$($(var)))
3451pass_$(pass)_this: pass_$(pass)_before
3452 + $$(QUIET)$$(MAKE) -f $$(MAKEFILE) pass_$(pass)_doit
3453pass_$(pass)_after:: pass_$(pass)_this
3454pass_$(pass): pass_$(pass)_after
3455#$ (warning pass=$(pass) PASS=$(PASS): $(PASS_$(PASS)_trgs) $(PASS_$(PASS)_trgs) $(foreach var,$(PASS_$(PASS)_vars),$($(var))))
3456endef # def_pass_strict
3457$(eval-opt-var def_pass_strict)
3458
3459## Execute a pass, strict order.
3460# @param $(pass) Lowercase pass name.
3461# @param $(PASS) Uppercase pass name.
3462define def_pass_strict_unsafe
3463$(eval tag:=_before)
3464$(eval dep:= )
3465$(foreach subdir, $(SUBDIRS_$(PASS)) $(SUBDIRS_$(PASS).$(KBUILD_TARGET)) $(SUBDIRS_$(PASS).$(KBUILD_TARGET).$(KBUILD_TARGET_ARCH)) ,$(eval $(def_pass_subdir)))
3466$(foreach makefile,$(MAKEFILES_BEFORE_$(PASS)) $(MAKEFILES_BEFORE_$(PASS).$(KBUILD_TARGET)) $(MAKEFILES_BEFORE_$(PASS).$(KBUILD_TARGET).$(KBUILD_TARGET_ARCH)),$(eval $(def_pass_makefile)))
3467
3468$(eval tag:=_after)
3469$(eval dep:=pass_$(pass)_doit)
3470$(foreach subdir, $(SUBDIRS_AFTER_$(PASS)) $(SUBDIRS_AFTER_$(PASS).$(KBUILD_TARGET)) $(SUBDIRS_AFTER_$(PASS).$(KBUILD_TARGET).$(KBUILD_TARGET_ARCH)) ,$(eval $(def_pass_subdir)))
3471$(foreach makefile,$(MAKEFILES_AFTER_$(PASS)) $(MAKEFILES_AFTER_$(PASS).$(KBUILD_TARGET)) $(MAKEFILES_AFTER_$(PASS).$(KBUILD_TARGET).$(KBUILD_TARGET_ARCH)) ,$(eval $(def_pass_makefile)))
3472
3473.PHONY: pass_$(pass) pass_$(pass)_before pass_$(pass)_after pass_$(pass)_doit
3474.NOTPARALLEL: pass_$(pass) pass_$(pass)_before pass_$(pass)_after pass_$(pass)_doit
3475pass_$(pass)_doit: pass_$(pass)_before \
3476 $(PASS_$(PASS)_trgs) $(foreach var,$(PASS_$(PASS)_vars),$($(var)))
3477pass_$(pass): \
3478 pass_$(pass)_before \
3479 pass_$(pass)_doit \
3480 pass_$(pass)_after
3481#$ (warning pass=$(pass) PASS=$(PASS): $(PASS_$(PASS)_trgs) $(PASS_$(PASS)_trgs) $(foreach var,$(PASS_$(PASS)_vars),$($(var))))
3482endef # def_pass_strict_unsafe
3483$(eval-opt-var def_pass_strict_unsafe)
3484
3485## Execute a pass, non-strict pass ordering.
3486# @param $(pass) Lowercase pass name.
3487# @param $(PASS) Uppercase pass name.
3488define def_pass_nonstrict
3489.PHONY: pass_$(pass) pass_$(pass)_before pass_$(pass)_after pass_$(pass)_doit
3490pass_$(pass)_doit: $(PASS_$(PASS)_trgs) $(foreach var,$(PASS_$(PASS)_vars),$$$$($(var)))
3491pass_$(pass): pass_$(pass)_doit
3492endef # def_pass_nonstrict
3493
3494## PASS: rules
3495# Generate the rules for the defined passes.
3496$(foreach PASS, $(PASSES), \
3497 $(eval pass := $(PASS_$(PASS)_pass)) \
3498 $(eval $(def_pass_$(_KBUILD_STRICT_PASS_ORDER))))
3499
3500
3501## Pass order, strict.
3502# @param $(pass) Current pass name.
3503# @param $(prev_pass) The previous pass name.
3504define def_pass_order_strict
3505.PHONY: pass_$(pass)_order
3506.NOTPARALLEL: pass_$(pass)_order
3507pass_$(pass)_order: $(pass_prev)
3508 %$$(call MSG_PASS,$$(if $$(PASS_$(PASS)),$$(PASS_$(PASS)),$(pass)))
3509 + $$(QUIET)$$(MAKE) -f $$(MAKEFILE) pass_$(pass)
3510$(eval pass_prev := pass_$(pass)_order)
3511endef # def_pass_order_strict
3512$(eval-opt-var def_pass_order_strict)
3513
3514## Pass order, strict unsafe.
3515# @param $(pass) Current pass name.
3516# @param $(prev_pass) The previous pass name.
3517define def_pass_order_strict_unsafe
3518.NOTPARALLEL: pass_$(pass)_order pass_$(pass)_banner
3519.PHONY: pass_$(pass)_order pass_$(pass)_banner
3520pass_$(pass)_banner: $(pass_prev)
3521 %$$(call MSG_PASS,$$(if $$(PASS_$(PASS)),$$(PASS_$(PASS)),$(pass)))
3522pass_$(pass)_order: $(pass_prev) \
3523 pass_$(pass)_banner \
3524 pass_$(pass)
3525$(eval pass_prev := pass_$(pass)_order)
3526endef # def_pass_order_strict_unsafe
3527$(eval-opt-var def_pass_order_strict_unsafe)
3528
3529## Pass order, non-strict.
3530# @param $(pass) Current pass name.
3531# @param $(prev_pass) The previous pass name.
3532define def_pass_order_nonstrict
3533.PHONY: pass_$(pass)_order pass_$(pass)_banner
3534pass_$(pass)_banner:
3535 %$$(call MSG_PASS,$$(if $$(PASS_$(PASS)),$$(PASS_$(PASS)),$(pass)))
3536pass_$(pass)_order: \
3537 $(pass_prev) \
3538 pass_$(pass)_banner \
3539 pass_$(pass)
3540$(eval pass_prev := pass_$(pass)_order)
3541endef # def_pass_order_nonstrict
3542$(eval-opt-var def_pass_order_nonstrict)
3543
3544## PASS: order
3545# Use dependencies to ensure correct pass order.
3546pass_prev :=
3547$(foreach PASS,$(DEFAULT_PASSES),\
3548 $(eval pass := $(PASS_$(PASS)_pass)) \
3549 $(eval $(def_pass_order_$(_KBUILD_STRICT_PASS_ORDER))))
3550
3551ifdef KBUILD_PROFILE_SELF
3552 $(evalcall def_profile_self, done passes)
3553endif
3554
3555# Some common pass aliases
3556ifndef KBUILD_NO_PASS_ALIASES
3557.PHONY: clean
3558clean: pass_clean
3559
3560.PHONY: nothing
3561nothing: pass_nothing
3562
3563.PHONY: packing
3564packing: pass_packing
3565
3566 ifndef KBUILD_NO_TESTING_PASS_ALIASES
3567.PHONY: check
3568check:: pass_testing
3569
3570.PHONY: test
3571test:: pass_testing
3572 endif # KBUILD_NO_TESTING_PASS_ALIASES
3573endif # KBUILD_NO_PASS_ALIASES
3574
3575
3576#
3577# THE MAIN RULES
3578#
3579all_recursive: $(pass_prev)
3580
3581rebuild: clean
3582 + $(MAKE) -f $(firstword $(MAKEFILE_LIST)) all_recursive
3583
3584# @todo make this a non-default pass!
3585uninstall::
3586 $(RM) -f -- $(_INSTALLS_FILES)
3587
3588install:: pass_installs
3589
3590# misc shortcuts (use secondary expansion here to save strcache[file] space).
3591targets: bldprogs libraries dlls programs sysmods miscbins others installs
3592objects: $$(_OBJS)
3593bldprogs: $$(_BLDPROGS)
3594libraries: $$(_LIBS) $$(_IMPORT_LIBS) $$(_OTHER_LIBRARIES)
3595dlls: $$(_DLLS)
3596programs: $$(_PROGRAMS)
3597sysmods: $$(_SYSMODS)
3598miscbins: $$(_MISCBINS)
3599others: $$(_OTHERS)
3600installs: $$(_INSTALLS) $$(_INSTALLS_DIRS) $$(_INSTALLS_FILES)
3601
3602
3603
3604#
3605# kBuild debugging stuff.
3606#
3607## @todo this doesn't work. Move to a debug unit and expand it.
3608show_targets:
3609 @$(foreach target, $(_ALL_TARGETS),\
3610 @$(ECHO) "target: $(target)" $(NLTAB)\
3611 @$(ECHO) " $(target)_0_OUTDIR=$($(target)_0_OUTDIR)" $(NLTAB)\
3612 @$(ECHO) " $(target)_1_TARGET=$($(target)_1_TARGET)" $(NLTAB)\
3613 @$(ECHO) " INSTARGET_$(target)=$(INSTARGET_$(target))" $(NLTAB)\
3614$(foreach prop,$(PROPS_SINGLE) $(PROPS_ACCUMULATE_L) $(PROPS_ACCUMULATE_R) 2_OBJS CLEAN, \
3615 $(eval _tmp:=$(firstword $($(target)_BLD_TRG) $(KBUILD_TARGET))) \
3616 $(if $($(target)_$(prop).$(_tmp)),\
3617 @$(ECHO) " $(target)_$(prop).$(_tmp)=$($(target)_$(prop).$(_tmp))" $(NLTAB)) \
3618 $(if $($(target)_$(prop)), $(NLTAB)@$(ECHO) " $(target)_$(prop)=$($(target)_$(prop))" $(NLTAB)) \
3619)\
3620$(foreach prop,$(PROPS_DEFERRED), \
3621 $(eval _tmp:=$(firstword $($(target)_BLD_TRG) $(KBUILD_TARGET))) \
3622 $(if $(value $(target)_$(prop).$(_tmp)),\
3623 @$(ECHO) ' $(target)_$(prop).$(_tmp)=$(value $(TARGET)_$(prop).$(_tmp))' $(NLTAB)) \
3624 $(if $(value $(target)_$(prop)), $(NLTAB)@$(ECHO) ' $(target)_$(prop)=$(value $(target)_$(prop))' $(NLTAB)) \
3625))
3626
3627
3628
3629#
3630# Include dependency files.
3631#
3632ifdef _DEPFILES
3633 # TODO: first works the second doesn't, provided _KB_INCLUDE_DEPS is undefined:
3634 # if "$(_KB_INCLUDE_DEPS)" == "1"
3635 # if $(_KB_INCLUDE_DEPS) == "1"
3636
3637 ifdef KB_HAVE_INCLUDEDEP_QUEUE
3638 includedep-queue $(_DEPFILES)
3639 else
3640 $(foreach dep, $(_DEPFILES), $(eval includedep $(dep)))
3641 endif
3642endif
3643
3644
3645ifdef KBUILD_PROFILE_SELF
3646 $(evalcall def_profile_self, end of footer.kmk)
3647 _KBUILD_TS_FOOTER_END := $(_KBUILD_TS_PREV)
3648
3649 ifneq ($(KBUILD_PROFILE_SELF),0)
3650 $(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)) )
3651 $(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)) )
3652 $(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)) )
3653 $(info prof: DEPFILES_INCLUDED=$(words $(_DEPFILES_INCLUDED)) DEPFILES=$(words $(_DEPFILES)) MAKEFILES=$(words $(MAKEFILE_LIST)) )
3654 endif
3655endif
3656
3657
3658# end-of-file-content
3659__footer_kmk__ := target
3660endif # __footer_kmk__
3661
Note: See TracBrowser for help on using the repository browser.