source: trunk/kBuild/footer.kmk@ 1697

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

footer.kmk: Check for all the keyword permutations of NOINST and INST. Fixes #36.

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