source: trunk/kBuild/footer.kmk@ 1441

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

output make-stats when KBUILD_PROFILE_SELF is active.

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