source: trunk/kBuild/footer.kmk@ 1413

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

keyword inheritance.

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