Fixed warnings when using the NAME property and ending up with output where only...
[kbuild-mirror.git] / kBuild / footer.kmk
blob78859f2eb016948282e70b063a4f8ad9c9b5a8bd
1 # $Id$
2 ## @file
3 # kBuild - File included at top of makefile.
7 # Copyright (c) 2004-2008 knut st. osmundsen <bird-kBuild-spam@anduin.net>
9 # This file is part of kBuild.
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.
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.
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
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.
34 ifndef __footer_kmk__
35 # start-of-file-content
36 ifdef 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)
41 endif
44 # Variables.
45 # (Some of these need initialization before including definitions using them.)
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))
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)
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)
85 # all $(KBUILD_HOST) targets.
86 _ALL_HOST_TARGETS = \
87 $(_ALL_BLDPROGS)
89 # all targets making use of srcname.
90 _ALL_SRCNAME_TARGETS = \
91 $(_ALL_FETCHES) \
92 $(_ALL_PATCHES)
94 # dependency files.
95 _DEPFILES :=
97 # included dependency files.
98 _DEPFILES_INCLUDED :=
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 :=
106 # Files which only requires cleaning up.
107 _CLEAN_FILES :=
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 :=
129 # misc
130 pass_prev :=
135 # Footer macros
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) \
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)/))
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.
172 define def_inherit_one_keyword
173 ifdef $(trg)_$(prop).$(src_key)
174 ifndef $(trg)_$(prop).$(trg_key)
175 $(trg)_$(prop).$(trg_key) = $($(trg)_$(prop).$(src_key))
176 endif
177 endif
178 endef
181 # EXPAND_BY = overriding
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.
188 define def_inherit_one_keyword_overriding_now_l
189 ifdef $(trg)_$(prop).$(src_key)
190 ifndef $(trg)_$(prop).$(trg_key)
191 $(trg)_$(prop).$(trg_key) := $($(trg)_$(prop).$(src_key))
192 endif
193 endif
194 endef
196 ## @copydoc def_inherit_one_overriding_now_l
197 define def_inherit_one_keyword_overriding_now_r
198 ifdef $(trg)_$(prop).$(src_key)
199 ifndef $(trg)_$(prop).$(trg_key)
200 $(trg)_$(prop).$(trg_key) := $($(trg)_$(prop).$(src_key))
201 endif
202 endif
203 endef
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
211 define def_inherit_one_keyword_overriding_deferred
212 ifdef $(trg)_$(prop).$(src_key)
213 ifndef $(trg)_$(prop).$(trg_key)
214 $(trg)_$(prop).$(trg_key) = $$($(trg)_$(prop).$(src_key))
215 endif
216 endif
217 endef
219 ## @copydoc def_inherit_one_overriding_deferred
220 define def_inherit_one_keyword_overriding_deferred_l
221 ifdef $(trg)_$(prop).$(src_key)
222 ifndef $(trg)_$(prop).$(trg_key)
223 $(trg)_$(prop).$(trg_key) = $$($(trg)_$(prop).$(src_key))
224 endif
225 endif
226 endef
228 ## @copydoc def_inherit_one_overriding_deferred
229 define def_inherit_one_keyword_overriding_deferred_r
230 ifdef $(trg)_$(prop).$(src_key)
231 ifndef $(trg)_$(prop).$(trg_key)
232 $(trg)_$(prop).$(trg_key) = $$($(trg)_$(prop).$(src_key))
233 endif
234 endif
235 endef
238 # EXPAND_BY = prepending
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.
245 define def_inherit_one_keyword_prepending_now_l
246 ifdef $(trg)_$(prop).$(src_key)
247 $(trg)_$(prop).$(trg_key) := $($(trg)_$(prop).$(src_key)) $($(trg)_$(prop).$(trg_key))
248 endif
249 endef
251 ## @copydoc def_inherit_one_prepending_now_l
252 define def_inherit_one_keyword_prepending_now_r
253 ifdef $(trg)_$(prop).$(src_key)
254 $(trg)_$(prop).$(trg_key) := $($(trg)_$(prop).$(trg_key)) $($(trg)_$(prop).$(src_key))
255 endif
256 endef
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
264 define def_inherit_one_keyword_prepending_deferred
265 ifdef $(trg)_$(prop).$(src_key)
266 ifndef $(trg)_$(prop).$(trg_key)
267 $(trg)_$(prop).$(trg_key) = $$($(trg)_$(prop).$(src_key))
268 endif
269 endif
270 endef
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.
277 define def_inherit_one_keyword_prepending_deferred_l
278 ifdef $(trg)_$(prop).$(src_key)
279 $(trg)_$(prop).$(trg_key) <= $$($(trg)_$(prop).$(src_key))
280 endif
281 endef
283 ## @copydoc def_inherit_one_prepending_deferred_l
284 define def_inherit_one_keyword_prepending_deferred_r
285 ifdef $(trg)_$(prop).$(src_key)
286 $(trg)_$(prop).$(trg_key) += $$($(trg)_$(prop).$(src_key))
287 endif
288 endef
291 # EXPAND_BY = appending
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.
298 define def_inherit_one_keyword_appending_now_l
299 ifdef $(trg)_$(prop).$(src_key)
300 $(trg)_$(prop).$(trg_key) := $($(trg)_$(prop).$(trg_key)) $($(trg)_$(prop).$(src_key))
301 endif
302 endef
304 ## @copydoc def_inherit_one_appending_now_l
305 define def_inherit_one_keyword_appending_now_r
306 ifdef $(trg)_$(prop).$(src_key)
307 $(trg)_$(prop).$(trg_key) := $($(trg)_$(prop).$(src_key)) $($(trg)_$(prop).$(trg_key))
308 endif
309 endef
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
317 define def_inherit_one_keyword_appending_deferred
318 ifdef $(trg)_$(prop).$(src_key)
319 ifndef $(trg)_$(prop).$(trg_key)
320 $(trg)_$(prop).$(trg_key) = $$($(trg)_$(prop).$(src_key))
321 endif
322 endif
323 endef
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.
330 define def_inherit_one_keyword_appending_deferred_l
331 ifdef $(trg)_$(prop).$(src_key)
332 $(trg)_$(prop).$(trg_key) += $$($(trg)_$(prop).$(src_key))
333 endif
334 endef
336 ## @copydoc def_inherit_one_appending_deferred_l
337 define def_inherit_one_keyword_appending_deferred_r
338 ifdef $(trg)_$(prop).$(src_key)
339 $(trg)_$(prop).$(trg_key) <= $$($(trg)_$(prop).$(src_key))
340 endif
341 endef
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.
354 define def_inherit_keyword
355 local prefix := $(word 1,$(subst :, ,$(prefix_keyword)))
356 local trg_key := $(word 2,$(subst :, ,$(prefix_keyword)))
357 local src_key := $($(prefix)_$(trg_key)_EXTENDS)
358 local by := $($(prefix)_$(trg_key)_EXTENDS_BY)
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)))
368 endef # def_inherit_keyword
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.
375 define def_inherit_one
376 ifdef $(src)_$(prop)
377 ifndef $(trg)_$(prop)
378 $(trg)_$(prop) = $($(src)_$(prop))
379 endif
380 endif
381 endef
384 # EXPAND_BY = overriding
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.
390 define def_inherit_one_overriding_now_l
391 ifdef $(src)_$(prop)
392 ifndef $(trg)_$(prop)
393 $(trg)_$(prop) := $($(src)_$(prop))
394 endif
395 endif
396 endef
398 ## @copydoc def_inherit_one_overriding_now_l
399 define def_inherit_one_overriding_now_r
400 ifdef $(src)_$(prop)
401 ifndef $(trg)_$(prop)
402 $(trg)_$(prop) := $($(src)_$(prop))
403 endif
404 endif
405 endef
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
412 define def_inherit_one_overriding_deferred
413 ifdef $(src)_$(prop)
414 ifndef $(trg)_$(prop)
415 $(trg)_$(prop) = $$($(src)_$(prop))
416 endif
417 endif
418 endef
420 ## @copydoc def_inherit_one_overriding_deferred
421 define def_inherit_one_overriding_deferred_l
422 ifdef $(src)_$(prop)
423 ifndef $(trg)_$(prop)
424 $(trg)_$(prop) = $$($(src)_$(prop))
425 endif
426 endif
427 endef
429 ## @copydoc def_inherit_one_overriding_deferred
430 define def_inherit_one_overriding_deferred_r
431 ifdef $(src)_$(prop)
432 ifndef $(trg)_$(prop)
433 $(trg)_$(prop) = $$($(src)_$(prop))
434 endif
435 endif
436 endef
439 # EXPAND_BY = prepending
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.
445 define def_inherit_one_prepending_now_l
446 ifdef $(src)_$(prop)
447 $(trg)_$(prop) := $($(src)_$(prop)) $($(trg)_$(prop))
448 endif
449 endef
451 ## @copydoc def_inherit_one_prepending_now_l
452 define def_inherit_one_prepending_now_r
453 ifdef $(src)_$(prop)
454 $(trg)_$(prop) := $($(trg)_$(prop)) $($(src)_$(prop))
455 endif
456 endef
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
463 define def_inherit_one_prepending_deferred
464 ifdef $(src)_$(prop)
465 ifndef $(trg)_$(prop)
466 $(trg)_$(prop) = $$($(src)_$(prop))
467 endif
468 endif
469 endef
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.
475 define def_inherit_one_prepending_deferred_l
476 ifdef $(src)_$(prop)
477 $(trg)_$(prop) <= $$($(src)_$(prop))
478 endif
479 endef
481 ## @copydoc def_inherit_one_prepending_deferred_l
482 define def_inherit_one_prepending_deferred_r
483 ifdef $(src)_$(prop)
484 $(trg)_$(prop) += $$($(src)_$(prop))
485 endif
486 endef
489 # EXPAND_BY = appending
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.
495 define def_inherit_one_appending_now_l
496 ifdef $(src)_$(prop)
497 $(trg)_$(prop) := $($(trg)_$(prop)) $($(src)_$(prop))
498 endif
499 endef
501 ## @copydoc def_inherit_one_appending_now_l
502 define def_inherit_one_appending_now_r
503 ifdef $(src)_$(prop)
504 $(trg)_$(prop) := $($(src)_$(prop)) $($(trg)_$(prop))
505 endif
506 endef
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
513 define def_inherit_one_appending_deferred
514 ifdef $(src)_$(prop)
515 ifndef $(trg)_$(prop)
516 $(trg)_$(prop) = $$($(src)_$(prop))
517 endif
518 endif
519 endef
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.
525 define def_inherit_one_appending_deferred_l
526 ifdef $(src)_$(prop)
527 $(trg)_$(prop) += $$($(src)_$(prop))
528 endif
529 endef
531 ## @copydoc def_inherit_one_appending_deferred_l
532 define def_inherit_one_appending_deferred_r
533 ifdef $(src)_$(prop)
534 $(trg)_$(prop) <= $$($(src)_$(prop))
535 endif
536 endef
539 ## combines the specified properties $(1) with the $(_KEYWORDS) list.
540 _INHERIT_JOIN_KEYWORDS = $(1) $(foreach keyword,$(_KEYWORDS), $(addsuffix .$(keyword), $(1)))
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.
553 define def_inherit
555 # Load it - loading is a mess, fix.
556 ifneq ($(load_function),)
557 local loading := $(patsubst $(src_prefix)%,%,$(trg))
558 $(evalvalctx $(load_function))
559 endif
561 local src := $(strip $($(trg)_EXTENDS))
562 ifneq ($(src),)
563 ifndef $(trg)_EXTENDS_STATUS_
564 $(trg)_EXTENDS_STATUS_ := 0
566 # Load the source.
567 ifneq ($(load_function),)
568 local loading := $(src)
569 $(evalvalctx $(load_function))
570 endif
572 # less typing.
573 local src := $(src_prefix)$(src)
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
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
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)))
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
609 endif
611 # Keyword inheritance.
612 $(foreach prefix_keyword, $(join $(_KEYWORDS_PREFIX), $(addprefix :,$(_KEYWORDS_EXTENDS))), $(evalval def_inherit_keyword))
614 endef # def_inherit
618 # Load global units before doing any inheriting so they can add new properties.
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.
627 ## Unit load function.
628 # @param loading The unit name
629 define def_unit_load_function
630 ifndef 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
639 endif
640 endef # def_unit_load_function
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))
656 # Determin all the templates that is being used and make
657 # sure they are present before we try collect keywords.
659 _TEMPLATES := $(TEMPLATE)
660 define def_templates
661 ifdef $(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)
666 endif
667 endef # def_templates
668 $(foreach target, $(_ALL_TARGETS), $(eval $(def_templates)))
669 _TEMPLATES := $(sort $(_TEMPLATES))
671 ## Template load function.
672 # @param loading The template name. This is prefixed.
673 define def_templates_load_function
674 ifndef 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
683 endif
684 endef # def_templates_load_function
685 $(foreach loading, $(_TEMPLATES), $(evalval def_templates_load_function))
689 # Determin the keywords required for correct inherting and setup keyword inheritance.
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... :-/
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)
701 define def_collect_bld_xyz
702 ifdef $(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)
707 endif
708 ifdef $(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)
713 endif
714 ifdef $(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)
719 endif
720 ifdef $(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)
725 endif
726 endef # def_collect_bld_xyz
727 $(foreach src, $(addprefix TEMPLATE_, $(_TEMPLATES)) $(_ALL_TARGETS) \
728 ,$(evalval def_collect_bld_xyz))
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))
737 ## Look for keywords which extends others and order them.
738 # @param keyword
739 # @param prefix
740 # @param valid
741 define def_keyword_ordering
742 # Check for EXTENDS, fix and validate it if found.
743 local src := $(strip $($(prefix)_$(keyword)_EXTENDS))
744 ifneq ($(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
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
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
767 # Update the attributes with stripped
768 $(prefix)_$(keyword)_EXTENDS_BY := $(by)
769 $(prefix)_$(keyword)_EXTENDS := $(src)
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
781 else
782 # Add it to the ordered list and mark it as done.
783 _KEYWORDS_ORDERED += $(keyword)
784 $(prefix)_$(src)_EXTENDS_STATUS_ := 42
785 endif
786 endef # def_keyword_ordering
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 :=
794 prefix := BLD_TYPE
795 valid := $(KBUILD_BLD_TYPES)
796 $(foreach keyword, $(_BLD_TYPES) , $(evalval def_keyword_ordering))
798 prefix := BLD_TRG
799 valid := $(KBUILD_OSES)
800 $(foreach keyword, $(_BLD_TARGETS), $(evalval def_keyword_ordering))
802 prefix := BLD_ARCH
803 valid := $(KBUILD_ARCHES)
804 $(foreach keyword, $(_BLD_ARCHES) , $(evalval def_keyword_ordering))
806 prefix := BLD_CPU
807 valid := $(KBUILD_CPUS)
808 $(foreach keyword, $(_BLD_CPUS) , $(evalval def_keyword_ordering))
810 ## @todo Inherit bld_trg.bld_arch for too?
812 # Construct all the possible keywords.
813 _KEYWORDS := $(_KEYWORDS_ORDERED) $(_KEYWORDS_EXTENDS) \
814 $(foreach bld_trg,$(_BLD_TARGETS),$(addprefix $(bld_trg).,$(_BLD_ARCHES)))
816 ifdef 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)
821 endif
825 # Target inheritance.
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.
835 src_prefix :=
836 load_function :=
837 properties_deferred_l :=
838 properties_deferred_r :=
840 # Fetches.
841 properties := $(PROPS_FETCHES_SINGLE)
842 properties_now_l := $(PROPS_FETCHES_ACCUMULATE_L)
843 properties_now_r := $(PROPS_FETCHES_ACCUMULATE_R)
844 properties_deferred := $(PROPS_FETCHES_DEFERRED)
845 $(foreach trg, $(_ALL_FETCHES),$(evalval def_inherit))
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))
854 # Programs and build programs.
855 properties := $(PROPS_PROGRAMS_SINGLE)
856 properties_now_l := $(PROPS_PROGRAMS_ACCUMULATE_L)
857 properties_now_r := $(PROPS_PROGRAMS_ACCUMULATE_R)
858 properties_deferred := $(PROPS_PROGRAMS_DEFERRED)
859 $(foreach trg, $(_ALL_BLDPROGS) $(_ALL_PROGRAMS),$(evalval def_inherit))
861 # Libraries and import libraries.
862 properties := $(PROPS_LIBRARIES_SINGLE)
863 properties_now_l := $(PROPS_LIBRARIES_ACCUMULATE_L)
864 properties_now_r := $(PROPS_LIBRARIES_ACCUMULATE_R)
865 properties_deferred := $(PROPS_LIBRARIES_DEFERRED)
866 if1of ($(KBUILD_TARGET), nt os2 win)
867 $(foreach trg, $(_ALL_LIBRARIES) $(_ALL_IMPORT_LIBS),$(evalval def_inherit))
868 else
869 $(foreach trg, $(_ALL_LIBRARIES),$(evalval def_inherit))
870 endif
872 # DLLs.
873 properties := $(PROPS_DLLS_SINGLE)
874 properties_now_l := $(PROPS_DLLS_ACCUMULATE_L)
875 properties_now_r := $(PROPS_DLLS_ACCUMULATE_R)
876 properties_deferred := $(PROPS_DLLS_DEFERRED)
877 if1of ($(KBUILD_TARGET), nt os2 win)
878 $(foreach trg, $(_ALL_DLLS),$(evalval def_inherit))
879 else
880 $(foreach trg, $(_ALL_DLLS) $(_ALL_IMPORT_LIBS),$(evalval def_inherit))
881 endif
883 # System modules.
884 properties := $(PROPS_SYSMODS_SINGLE)
885 properties_now_l := $(PROPS_SYSMODS_ACCUMULATE_L)
886 properties_now_r := $(PROPS_SYSMODS_ACCUMULATE_R)
887 properties_deferred := $(PROPS_SYSMODS_DEFERRED)
888 $(foreach trg, $(_ALL_SYSMODS),$(evalval def_inherit))
890 # Installs.
891 properties := $(PROPS_INSTALLS_SINGLE)
892 properties_now_l := $(PROPS_INSTALLS_ACCUMULATE_L)
893 properties_now_r := $(PROPS_INSTALLS_ACCUMULATE_R)
894 properties_deferred := $(PROPS_INSTALLS_DEFERRED)
895 $(foreach trg, $(_ALL_INSTALLS),$(evalval def_inherit))
897 ifdef 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)
902 endif
906 # Template Inheritance.
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.
916 src_prefix := TEMPLATE_
917 load_function := def_templates_load_function
918 properties :=
919 properties_now_l :=
920 properties_now_r :=
921 properties_deferred := $(PROPS_SINGLE) $(PROPS_DEFERRED)
922 properties_deferred_l := $(PROPS_ACCUMULATE_L)
923 properties_deferred_r := $(PROPS_ACCUMULATE_R)
924 $(foreach trg, $(addprefix TEMPLATE_,$(_TEMPLATES)),$(evalval def_inherit))
926 # done inheriting.
927 src_prefix :=
928 load_function :=
929 properties :=
930 properties_now_l :=
931 properties_now_r :=
932 properties_deferred :=
933 properties_deferred_l :=
934 properties_deferred_r :=
936 ifdef 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)
941 endif
947 # Template/Target Expansion.
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.
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.
958 define def_inherit_template_one
959 ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop)
960 ifndef $(target)_$(prop)
961 $(target)_$(prop) := $(TEMPLATE_$($(target)_TEMPLATE)_$(prop))
962 endif
963 endif
964 ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg)
965 ifndef $(target)_$(prop).$(bld_trg)
966 $(target)_$(prop).$(bld_trg) := $(TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg))
967 endif
968 endif
969 ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg).$(bld_trg_arch)
970 ifndef $(target)_$(prop).$(bld_trg).$(bld_trg_arch)
971 $(target)_$(prop).$(bld_trg).$(bld_trg_arch) := $(TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg).$(bld_trg_arch))
972 endif
973 endif
974 ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_arch)
975 ifndef $(target)_$(prop).$(bld_trg_arch)
976 $(target)_$(prop).$(bld_trg_arch) := $(TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_arch))
977 endif
978 endif
979 ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_cpu)
980 ifndef $(target)_$(prop).$(bld_trg_cpu)
981 $(target)_$(prop).$(bld_trg_cpu) := $(TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_cpu))
982 endif
983 endif
984 endef
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
991 define def_inherit_template_one_deferred
992 ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop)
993 ifndef $(target)_$(prop)
994 $(target)_$(prop) = $$(TEMPLATE_$($(target)_TEMPLATE)_$(prop))
995 endif
996 endif
997 ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg)
998 ifndef $(target)_$(prop).$(bld_trg)
999 $(target)_$(prop).$(bld_trg) = $$(TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg))
1000 endif
1001 endif
1002 ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg).$(bld_trg_arch)
1003 ifndef $(target)_$(prop).$(bld_trg).$(bld_trg_arch)
1004 $(target)_$(prop).$(bld_trg).$(bld_trg_arch) = $$(TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg).$(bld_trg_arch))
1005 endif
1006 endif
1007 ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_arch)
1008 ifndef $(target)_$(prop).$(bld_trg_arch)
1009 $(target)_$(prop).$(bld_trg_arch) = $$(TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_arch))
1010 endif
1011 endif
1012 ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_cpu)
1013 ifndef $(target)_$(prop).$(bld_trg_cpu)
1014 $(target)_$(prop).$(bld_trg_cpu) = $$(TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_cpu))
1015 endif
1016 endif
1017 endef
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
1022 define def_inherit_template_one_accumulate_l
1023 ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop)
1024 $(target)_$(prop) += $$(TEMPLATE_$($(target)_TEMPLATE)_$(prop))
1025 endif
1026 ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(KBUILD_TYPE)
1027 $(target)_$(prop).$(KBUILD_TYPE) += $$(TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(KBUILD_TYPE))
1028 endif
1029 ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg)
1030 $(target)_$(prop).$(bld_trg) += $$(TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg))
1031 endif
1032 ifdef 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))
1034 endif
1035 ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_cpu)
1036 $(target)_$(prop).$(bld_trg_cpu) += $$(TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_cpu))
1037 endif
1038 ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_arch)
1039 $(target)_$(prop).$(bld_trg_arch) += $$(TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_arch))
1040 endif
1041 endef
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
1046 define def_inherit_template_one_accumulate_r
1047 ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop)
1048 $(target)_$(prop) <=$$(TEMPLATE_$($(target)_TEMPLATE)_$(prop))
1049 endif
1050 ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(KBUILD_TYPE)
1051 $(target)_$(prop).$(KBUILD_TYPE) <=$$(TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(KBUILD_TYPE))
1052 endif
1053 ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg)
1054 $(target)_$(prop).$(bld_trg) <=$$(TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg))
1055 endif
1056 ifdef 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))
1058 endif
1059 ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_cpu)
1060 $(target)_$(prop).$(bld_trg_cpu) <=$$(TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_cpu))
1061 endif
1062 ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_arch)
1063 $(target)_$(prop).$(bld_trg_arch) <=$$(TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_arch))
1064 endif
1065 endef
1068 ## Inherit template properties for on target.
1069 # @param $(target) Target name.
1070 define def_inherit_template
1071 # sanity check.
1072 ifdef _$(target)_ALREADY_PROCESSED
1073 $(error kBuild: The target $(target) appears more than once in the target lists! Please correct the makefile(s))
1074 endif
1075 _$(target)_ALREADY_PROCESSED := 1
1077 # Inherit any default template.
1078 ifdef TEMPLATE
1079 ifeq ($($(target)_TEMPLATE),)
1080 $(eval $(target)_TEMPLATE:=$(TEMPLATE))
1081 endif
1082 endif
1083 # Expand the template if specified.
1084 ifneq ($($(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)
1089 endif
1090 endef
1092 # Inherit template properties
1093 bld_trg := $(KBUILD_TARGET)
1094 bld_trg_arch := $(KBUILD_TARGET_ARCH)
1095 bld_trg_cpu := $(KBUILD_TARGET_CPU)
1096 $(foreach target, $(_ALL_TARGET_TARGETS),$(evalval def_inherit_template))
1098 bld_trg := $(KBUILD_HOST)
1099 bld_trg_arch := $(KBUILD_HOST_ARCH)
1100 bld_trg_cpu := $(KBUILD_HOST_CPU)
1101 $(foreach target, $(_ALL_HOST_TARGETS),$(evalval def_inherit_template))
1103 ifdef 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)
1108 endif
1112 # Include tools, sdks and units.
1114 # The first part of this exercise is to figure out which TOOLS and SDKS
1115 # that should be included.
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)
1128 define 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))
1160 endef # def_tools_sdks_target_source
1162 define def_tools_sdks_target
1163 local _bld_type := $(firstword $($(target)_BLD_TYPE) $(KBUILD_TYPE))
1164 local _bld_trg := $(firstword $($(target)_BLD_TRG) $(bld_trg))
1165 local _bld_trg_arch := $(firstword $($(target)_BLD_TRG_ARCH) $(bld_trg_arch))
1166 local _bld_trg_cpu := $(firstword $($(target)_BLD_TRG_CPU) $(bld_trg_cpu))
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))
1191 endef # def_tools_sdks_target
1193 define def_tools_srcname_target
1194 local _bld_type := $(firstword $($(target)_BLD_TYPE) $(KBUILD_TYPE))
1195 local _bld_trg := $(firstword $($(target)_BLD_TRG) $(bld_trg))
1196 local _bld_trg_arch := $(firstword $($(target)_BLD_TRG_ARCH) $(bld_trg_arch))
1197 local _bld_trg_cpu := $(firstword $($(target)_BLD_TRG_CPU) $(bld_trg_cpu))
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))
1207 endef # def_tools_srcname_target
1209 bld_trg := $(KBUILD_TARGET)
1210 bld_trg_arch := $(KBUILD_TARGET_ARCH)
1211 bld_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))
1215 bld_trg := $(KBUILD_HOST)
1216 bld_trg_arch := $(KBUILD_HOST_ARCH)
1217 bld_trg_cpu := $(KBUILD_HOST_CPU)
1218 $(foreach target, $(_ALL_HOST_TARGETS), $(evalval def_tools_sdks_target))
1220 _TOOLS := $(sort $(_TOOLS))
1221 _SDKS := $(sort $(_SDKS))
1223 ## Tool load function.
1224 # @param loading The tool name
1225 define def_tools_load_function
1226 ifndef 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
1235 endif
1236 endef # def_tools_include
1238 ## SDK load function.
1239 # @param loading The tool name
1240 define def_sdk_load_function
1241 ifndef 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
1250 endif
1251 endef # def_sdk_load_function
1254 properties :=
1255 properties_now_l :=
1256 properties_now_r :=
1257 properties_deferred := $(PROPS_SINGLE) $(PROPS_DEFERRED)
1258 properties_deferred_l := $(PROPS_ACCUMULATE_L)
1259 properties_deferred_r := $(PROPS_ACCUMULATE_R)
1261 src_prefix := TOOL_
1262 load_function := def_tools_load_function
1263 $(foreach trg, $(addprefix TOOL_,$(_TOOLS)), $(evalval def_inherit))
1265 src_prefix := SDK_
1266 load_function := def_sdk_load_function
1267 $(foreach trg, $(addprefix SDK_,$(_SDKS)), $(evalval def_inherit))
1269 # done inheriting.
1270 src_prefix :=
1271 load_function :=
1272 properties :=
1273 properties_now_l :=
1274 properties_now_r :=
1275 properties_deferred :=
1276 properties_deferred_l :=
1277 properties_deferred_r :=
1279 # No inheriting for the uses, they're just global 'code'.
1280 $(foreach loading, $(_USES), $(evalval def_unit_load_function))
1283 ifdef 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)
1288 endif
1294 # Target lists - Pass 1
1296 # This pass is for defining variables that might be referenced in
1297 # properties of other targets.
1301 # Don't do anything for fetch targets (yet).
1304 # Link prolog for Pass 1.
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.
1312 define def_pass1_link_common
1314 local bld_type := $(firstword $($(target)_BLD_TYPE) $(KBUILD_TYPE))
1315 local bld_trg := $(firstword $($(target)_BLD_TRG) $(BUILD_$(bld_trg_base_var)))
1316 local bld_trg_arch:= $(firstword $($(target)_BLD_TRG_ARCH) $(BUILD_$(bld_trg_base_var)_ARCH))
1317 local bld_trg_cpu := $(firstword $($(target)_BLD_TRG_CPU) $(BUILD_$(bld_trg_base_var)_CPU))
1319 local tool := $(call _TARGET_TOOL,$(target),$(tool_prefix))
1320 local 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))
1327 local outbase := $(call TARGET_BASE,$(name),$(target))
1328 ifndef PATH_$(target)
1329 PATH_$(target) := $(patsubst %/,%,$(dir $(outbase)))
1330 else ifneq ($(PATH_$(target)),$(patsubst %/,%,$(dir $(outbase))))
1331 $(error kBuild internal error: PATH_$(target)=$(PATH_$(target)) expected $(patsubst %/,%,$(dir $(outbase))))
1332 endif
1333 ifeq ($(tool_prefix),AR) ## @todo fix this mess!
1334 local 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))
1342 else
1343 local suff := $(firstword \
1344 $($(target)_$(EXT)SUFF) \
1345 $($(target)_$(EXT)SUFF) \
1346 $(TOOL_$(tool)_$(tool_prefix)$(EXT)SUFF) \
1347 $($(EXTPRE)SUFF_$(EXT)))
1348 endif
1349 local out := $(outbase)$(suff)
1351 # TARGET_*
1352 TARGET_$(target) := $(out)
1354 # INSTARGET_*
1355 ifndef $(target)_NOINST
1356 INSTARGET_$(target) := $(patsubst %/,%/$(notdir $(out)), \
1357 $(if $($(target)_INST), $(addprefix $(PATH_INS)/,$($(target)_INST)), $(definst)/))
1359 else # NOINST
1360 INSTARGET_$(target) :=
1361 endif # NOINST
1363 endef
1367 # BLDPROGS (Pass 1)
1369 define def_pass1_bldprog
1370 # set NOINST if not forced installation before doing the usual stuff.
1371 ifndef $(target)_INST
1372 $(target)_NOINST := 1
1373 endif
1374 $(evalval def_pass1_link_common)
1375 endef
1377 EXT := EXE
1378 EXTPRE := HOST
1379 definst := $(PATH_BIN)
1380 tool_prefix := LD
1381 bld_trg_base_var := PLATFORM
1382 $(foreach target, $(_ALL_BLDPROGS), \
1383 $(evalval def_pass1_bldprog))
1387 # LIBRARIES (Pass 1)
1389 EXT := LIB
1390 EXTPRE :=
1391 definst := $(PATH_LIB)
1392 tool_prefix := AR
1393 bld_trg_base_var := TARGET
1394 $(foreach target, $(_ALL_LIBRARIES), \
1395 $(evalval def_pass1_link_common))
1399 # DLLS (Pass 1)
1401 EXT := DLL
1402 EXTPRE :=
1403 definst := $(PATH_DLL)
1404 tool_prefix := LD
1405 bld_trg_base_var := TARGET
1406 $(foreach target, $(_ALL_DLLS), \
1407 $(evalval def_pass1_link_common))
1411 # IMPORT LIBRARIES (Pass 1)
1413 # - On OS/2 and windows these are libraries.
1414 # - On other platforms they are fake DLLs.
1416 if1of ($(KBUILD_TARGET), nt os2 win win64 win32)
1417 EXT := LIB
1418 EXTPRE :=
1419 definst := $(PATH_LIB)
1420 tool_prefix := AR
1421 bld_trg_base_var := TARGET
1422 $(foreach target, $(_ALL_IMPORT_LIBS), \
1423 $(evalval def_pass1_link_common))
1424 else
1425 EXT := DLL
1426 EXTPRE :=
1427 definst := $(PATH_DLL)
1428 tool_prefix := LD
1429 bld_trg_base_var := TARGET
1430 $(foreach target, $(_ALL_IMPORT_LIBS), \
1431 $(evalval def_pass1_link_common))
1432 endif
1436 # PROGRAMS (Pass 1)
1438 EXT := EXE
1439 EXTPRE :=
1440 definst := $(PATH_BIN)
1441 tool_prefix := LD
1442 bld_trg_base_var := TARGET
1443 $(foreach target, $(_ALL_PROGRAMS), \
1444 $(evalval def_pass1_link_common))
1448 # SYSMODS (Pass 1)
1450 EXT := SYS
1451 EXTPRE :=
1452 definst := $(PATH_SYS)
1453 tool_prefix := LD
1454 bld_trg_base_var := TARGET
1455 $(foreach target, $(_ALL_SYSMODS), \
1456 $(evalval def_pass1_link_common))
1460 # INSTALLS (Pass 1)
1461 # Note! INSTARGET_* for INSTALLS aren't available until later.
1463 define def_pass1_install
1464 local bld_type := $(firstword $($(target)_BLD_TYPE) $(KBUILD_TYPE))
1465 local bld_trg := $(firstword $($(target)_BLD_TRG) $(KBUILD_TARGET))
1466 local bld_trg_arch:= $(firstword $($(target)_BLD_TRG_ARCH) $(KBUILD_TARGET_ARCH))
1467 local bld_trg_cpu := $(firstword $($(target)_BLD_TRG_CPU) $(KBUILD_TARGET_CPU))
1468 # TARGET_*
1469 TARGET_$(target) := $(PATH_TARGET)/$(target).ins
1470 # INSTARGET_ later.
1471 endef
1472 $(foreach target, $(_ALL_INSTALLS), \
1473 $(evalval def_pass1_install))
1475 ifdef KBUILD_PROFILE_SELF
1476 _KBUILD_TS_NOW := $(nanots )
1477 $(info prof: $(int-sub $(_KBUILD_TS_NOW), $(_KBUILD_TS_HEADER_START)) - $(int-sub $(_KBUILD_TS_NOW), $(_KBUILD_TS_PREV)) - done pass 1)
1478 $(info stat: $(make-stats ))
1479 _KBUILD_TS_PREV := $(_KBUILD_TS_NOW)
1480 endif
1487 # Target lists - Pass 2
1492 ## @page pg_fetches Fetching Tools, Sources and Similar.
1494 # The targets listed in the the FETCHES target list have the following attributes:
1495 # SOURCES
1496 # INST
1497 # FETCHTOOL
1498 # FETCHFLAGS
1499 # FETCHDIR
1500 # UNPACKTOOL
1501 # UNPACKFLAGS
1503 # As usual the target name is an alias for 'creating' the target. Other
1504 # aliases are:
1505 # pass_fetches
1506 # fetch
1507 # unfetch
1508 # download
1509 # unpack
1511 # @remark
1513 # This is a little bit complex because we must guarantee that if a source file
1514 # changes only sligtly we must refetch it and to a proper unpacking of it. It
1515 # is also a desire that fetched archives and unpacked files can be deleted to
1516 # save space.
1518 # Thus, we must be able to cleanup what we've unpacked should any of the
1519 # sources be removed. We do this by maintaining a file listing the files
1520 # and directories that was unpacked. This operation is named 'unfetch'.
1522 # We make use of the SIZE and MD5 attributes for each of the sources to
1523 # create a digest that is stored in the primary target file. Subsequent
1524 # runswill compare their digest with it to decide if a refetch is required.
1525 # When a refetch is found necessary, an 'unfetch' is performed first to
1526 # clean out old files and directores. Note even changes in source order
1527 # will cause a refetch due to the way the digest is constructed and
1528 # evaluated.
1530 # By not depending directly on the archives (nor on any unpacked files)
1531 # but on a goal made up from the archive name, size and md5, we allow
1532 # the user to delete the archives. Naturally, this means we'll have to
1533 # check and fetch missing archives before attempting to unpack them.
1535 # @remark
1537 # This feature will *NOT* work correctly with vanilla GNU make becuase
1538 # it makes use of includedep to avoid too many unnecessary files.
1540 # @todo
1541 # 1. Download corruption / continuation.
1542 # 2. It's quite possible that there is one too many indirect dependency now...
1545 ## generates the fetch rule
1546 define def_fetch_src_fetch_rule
1547 # Indirect goal for downloading something.
1548 .PRECIOUS: $(out)
1549 $(out) + $($(target)_$(srcname)_FETCH_OUTPUT_) +| $($(target)_$(srcname)_FETCH_OUTPUT_MAYBE_) : \
1550 | $($(target)_$(srcname)_FETCH_DEPORD_)
1551 %$$(call MSG_FETCH_DL,$(target),$(source),$(out))
1552 @## @todo do fancy stuff like download continuation.
1553 $$(QUIET)$$(RM) -f -- $(out)
1554 $($(target)_$(srcname)_FETCH_CMDS_)
1555 $$(QUIET)$(if $(md5),$$(MD5SUM_EXT) -b -C $(md5) $(out))
1559 # Intermediate goal for making sure the md5 and size matches. it will (re) fetch the archive if necessary.
1560 $(out).checked_$(md5)_$(size): $($(target)_$(srcname)_FETCH_DEPEND_) | $($(target)_$(srcname)_FETCH_DEPORD_)
1561 %$$(call MSG_FETCH_CHK,$(target),$(source),$(out))
1562 $$(QUIET)$$(RM) -f -- $$@
1563 @# (re)fetch the file if it doesn't exist or if it doesn't matches the md5.
1564 @## @todo do fancy stuff like download continuation.
1565 $$(QUIET)( test -f $(out) && $(if $(md5),$$(MD5SUM_EXT) -b -C $(md5) $(out), true) ) \
1566 || ( $$(RM_EXT) -f $(out) \
1567 && $$(MAKE) $(out) -f $(MAKEFILE) --no-print-directory )
1568 $$(QUIET2)$$(APPEND) $$@
1570 _TARGET_$(target)_FETCHED += $(out) $(out).checked_$(md5)_$(size)
1572 # Just a little precaution.
1573 .NOTPARALLEL: $(out) $(out).checked_$(md5)_$(size)
1575 endef
1577 ## generates the unpack rule
1578 define def_fetch_src_unpack_rule
1579 # This is the unpack rule. it has an order-only dependency on the download check.
1580 $(out) + $($(target)_$(srcname)_UNPACK_OUTPUT_) +| $($(target)_$(srcname)_UNPACK_OUTPUT_MAYBE_) : \
1581 $($(target)_$(srcname)_UNPACK_DEPEND_) \
1582 | $($(target)_$(srcname)_UNPACK_DEPORD_) $(archive).checked_$(md5)_$(size)
1583 %$$(call MSG_FETCH_UP,$(target),$(archive),$(inst))
1584 $$(QUIET)$$(RM) -f -- $(out)
1585 @# if the source archive doesn't exist fetch it (can have been deleted to save space).
1586 $$(QUIET)test -f $(archive) \
1587 || ( $$(RM_EXT) -f $(archive).checked_$(md5)_$(size) \
1588 && $$(MAKE) $(archive).checked_$(md5)_$(size) -f $(MAKEFILE) --no-print-directory )
1589 $($(target)_$(srcname)_UNPACK_CMDS_)
1590 $$(QUIET2)$$(APPEND) $(out) $(notdir $(archive).checked_$(md5)_$(size))
1591 $$(QUIET2)$$(APPEND) $(out) $(notdir $(out))
1593 $(eval _TARGET_$(target)_UNPACKED += $(out))
1594 _TARGET_$(target)_DIGEST := $(_TARGET_$(target)_DIGEST)-$(srcname)_$(md5)_$(size)
1596 .NOTPARALLEL: $(out)
1598 endef
1600 ## Processes a fetch source
1602 define def_fetch_src
1603 #$ (warning dbg: def_fetch_src: source='$(source)' target='$(target)')
1605 # common
1606 local srcname := $(notdir $(source))
1607 local inst := $(firstword \
1608 $($(target)_$(source)_INST)\
1609 $($(target)_$(srcname)_INST)\
1610 $($(source)_INST)\
1611 $($(srcname)_INST)\
1612 $($(target)_INST)\
1614 ifneq ($(patsubst %/,ok,$(inst)),ok)
1615 $(error kBuild: Bad or missing INST property for source '$(source)' in target '$(target)': $(inst))
1616 endif
1617 INSTARGET_$(target)_$(srcname) := $(inst)
1618 local fetchdir := $(firstword \
1619 $($(target)_$(source)_FETCHDIR)\
1620 $($(target)_$(srcname)_FETCHDIR)\
1621 $($(source)_FETCHDIR)\
1622 $($(srcname)_FETCHDIR)\
1623 $($(target)_FETCHDIR)\
1624 $(FETCHDIR)\
1625 $(PATH_TARGET)\
1627 local deps := \
1628 $($(target)_$(source)_DEPS)\
1629 $($(target)_$(srcname)_DEPS)\
1630 $($(source)_DEPS)\
1631 $($(srcname)_DEPS)\
1632 $($(target)_DEPS)
1633 local orderdeps := \
1634 $($(target)_$(source)_ORDERDEPS)\
1635 $($(target)_$(srcname)_ORDERDEPS)\
1636 $($(source)_ORDERDEPS)\
1637 $($(srcname)_ORDERDEPS)\
1638 $($(target)_ORDERDEPS)
1639 local md5 := $(firstword \
1640 $($(target)_$(source)_MD5)\
1641 $($(target)_$(srcname)_MD5)\
1642 $($(source)_MD5)\
1643 $($(srcname)_MD5)\
1644 $($(target)_MD5)\
1646 local size := $(firstword \
1647 $($(target)_$(source)_SIZE)\
1648 $($(target)_$(srcname)_SIZE)\
1649 $($(source)_SIZE)\
1650 $($(srcname)_SIZE)\
1651 $($(target)_SIZE)\
1653 clean_files += \
1654 $($(target)_$(source)_CLEAN)\
1655 $($(target)_$(srcname)_CLEAN)\
1656 $($(source)_CLEAN)\
1657 $($(srcname)_CLEAN)
1658 local dep := # not legal for fetch and unpack tools
1662 # The fetching.
1664 local out := $(fetchdir)/$(srcname)
1665 local archive := $(out)
1666 TARGET_$(target)_$(srcname) := $(out)
1667 local dirdep := $(call DIRDEP,$(fetchdir))
1668 local tool := $(firstword \
1669 $($(target)_$(source)_FETCHTOOL)\
1670 $($(target)_$(srcname)_FETCHTOOL)\
1671 $($(target)_$(source)_TOOL)\
1672 $($(target)_$(srcname)_TOOL)\
1673 $($(source)_FETCHTOOL)\
1674 $($(srcname)_FETCHTOOL)\
1675 $($(source)_TOOL)\
1676 $($(srcname)_TOOL)\
1677 $($(target)_FETCHTOOL)\
1678 $($(target)_TOOL)\
1680 local flags :=\
1681 $(TOOL_$(tool)_FETCHFLAGS)\
1682 $(FETCHFLAGS)\
1683 $($(target)_FETCHFLAGS)\
1684 $($(srcname)_FETCHFLAGS)\
1685 $($(source)_FETCHFLAGS)\
1686 $($(target)_$(srcname)_FETCHFLAGS)\
1687 $($(target)_$(source)_FETCHFLAGS)
1689 #$ (warning dbg: target=$(target) source=$(source) $(srcname)=$(srcname) tool=$(tool) out=$(out) flags=$(flags) dirdep=$(dirdep) fetchdir=$(fetchdir) md5=$(md5) size=$(size))
1691 ifndef TOOL_$(tool)_FETCH_CMDS
1692 $(warning kBuild: tools: \
1693 1 $($(target)_$(source)_FETCHTOOL)\
1694 2 $($(target)_$(srcname)_FETCHTOOL)\
1695 3 $($(target)_$(source)_TOOL)\
1696 4 $($(target)_$(srcname)_TOOL)\
1697 5 $($(source)_FETCHTOOL)\
1698 6 $($(srcname)_FETCHTOOL)\
1699 7 $($(source)_TOOL)\
1700 8 $($(srcname)_TOOL)\
1701 9 $($(target)_FETCHTOOL)\
1702 10 $($(target)_TOOL) )
1703 $(error kBuild: TOOL_$(tool)_FETCH_CMDS is not defined. source=$(source) target=$(target) )
1704 endif
1706 # call the tool
1707 $(target)_$(srcname)_FETCH_CMDS_ := $(TOOL_$(tool)_FETCH_CMDS)
1708 $(target)_$(srcname)_FETCH_OUTPUT_ := $(TOOL_$(tool)_FETCH_OUTPUT)
1709 $(target)_$(srcname)_FETCH_OUTPUT_MAYBE_ := $(TOOL_$(tool)_FETCH_OUTPUT_MAYBE)
1710 $(target)_$(srcname)_FETCH_DEPEND_ := $(TOOL_$(tool)_FETCH_DEPEND) $(deps)
1711 $(target)_$(srcname)_FETCH_DEPORD_ := $(TOOL_$(tool)_FETCH_DEPORD) $(dirdep) $(orderdeps)
1713 # generate the fetch rule.
1714 $(eval $(def_fetch_src_fetch_rule))
1718 # The unpacking / installing.
1720 local out := $(inst)_kBuild_$(target)_$(srcname)_unpacked.lst
1721 local dirdep := $(call DIRDEP,$(inst))
1722 local tool := $(firstword \
1723 $($(target)_$(source)_UNPACKTOOL)\
1724 $($(target)_$(srcname)_UNPACKTOOL)\
1725 $($(target)_$(source)_TOOL)\
1726 $($(target)_$(srcname)_TOOL)\
1727 $($(source)_UNPACKTOOL)\
1728 $($(srcname)_UNPACKTOOL)\
1729 $($(source)_TOOL)\
1730 $($(srcname)_TOOL)\
1731 $($(target)_UNPACKTOOL)\
1732 $($(target)_TOOL) \
1734 ifeq ($(tool),)
1735 local tool := $(toupper $(subst .,,$(suffix $(subst tar.,TAR,$(srcname)))))
1736 $(evalval def_tools_include)
1737 endif
1738 local flags :=\
1739 $(TOOL_$(tool)_UNPACKFLAGS)\
1740 $(UNPACKFLAGS)\
1741 $($(target)_UNPACKFLAGS)\
1742 $($(srcname)_UNPACKFLAGS)\
1743 $($(source)_UNPACKFLAGS)\
1744 $($(target)_$(srcname)_UNPACKFLAGS)\
1745 $($(target)_$(source)_UNPACKFLAGS)
1747 #$ (warning dbg: target=$(target) source=$(source) $(srcname)=$(srcname) tool=$(tool) out=$(out) flags=$(flags) dirdep=$(dirdep) inst=$(inst) md5=$(md5) size=$(size))
1748 ifndef TOOL_$(tool)_UNPACK_CMDS
1749 $(warning kBuild: tools: \
1750 1 $($(target)_$(source)_UNPACKTOOL)\
1751 2 $($(target)_$(srcname)_UNPACKTOOL)\
1752 3 $($(target)_$(source)_TOOL)\
1753 4 $($(target)_$(srcname)_TOOL)\
1754 5 $($(source)_UNPACKTOOL)\
1755 6 $($(srcname)_UNPACKTOOL)\
1756 7 $($(source)_TOOL)\
1757 8 $($(srcname)_TOOL)\
1758 9 $($(target)_UNPACKTOOL)\
1759 10 $($(target)_TOOL) \
1760 11 $(toupper $(subst tar.,TAR,$(ext $(srcname)))) \
1762 $(error kBuild: TOOL_$(tool)_UNPACK_CMDS is not defined. source=$(source) target=$(target) )
1763 endif
1765 # call the tool
1766 $(target)_$(srcname)_UNPACK_CMDS_ := $(TOOL_$(tool)_UNPACK_CMDS)
1767 $(target)_$(srcname)_UNPACK_OUTPUT_ := $(TOOL_$(tool)_UNPACK_OUTPUT)
1768 $(target)_$(srcname)_UNPACK_OUTPUT_MAYBE_ := $(TOOL_$(tool)_UNPACK_OUTPUT_MAYBE)
1769 $(target)_$(srcname)_UNPACK_DEPEND_ := $(TOOL_$(tool)_UNPACK_DEPEND) $(deps)
1770 $(target)_$(srcname)_UNPACK_DEPORD_ := $(TOOL_$(tool)_UNPACK_DEPORD) $(dirdep) $(orderdeps)
1772 # generate the fetch rule.
1773 $(eval $(def_fetch_src_unpack_rule))
1775 _DIRS += $(inst) $(fetchdir)
1777 endef
1781 # Define the target level rules for a fetch.
1782 # @param target
1783 # @param out
1784 # @param inst
1785 # @param _TARGET_$(target)_UNPACKED
1786 # @param _TARGET_$(target)_DIGEST
1787 # @param bld_trg
1788 # @param bld_trg_arch
1789 define def_fetch_rules
1791 $(out).lst: $(_TARGET_$(target)_UNPACKED) | $(call DIRDEP,$(inst))
1792 %$$(call MSG_FETCH_OK,$(target))
1793 $$(QUIET)$$(RM) -f -- $$@ $$@.tmp
1794 $$(QUIET2)$$(APPEND) $$@.tmp '$(notdir $(out))'
1795 $$(QUIET)$(if $(_TARGET_$(target)_UNPACKED),$$(CAT_EXT) $(_TARGET_$(target)_UNPACKED) >> $$@.tmp)
1796 $$(QUIET)$$(MV) -f -- $$@.tmp $$@
1798 $(out)_unfetched:
1799 %$$(call MSG_UNFETCH,$(target))
1800 $$(QUIET)$$(RM) -f -- $$(addprefix $(inst),$$(shell $$(CAT_EXT) $(out).lst 2> /dev/null | $$(SED) -e '/\/$$$$/d'))
1801 $$(QUIET)$$(RMDIR) -p --ignore-fail-on-non-empty --ignore-fail-on-not-exist -- $$(dir $$@) \
1802 $$(addprefix $(inst),$$(sort $$(dir $$(shell $$(CAT_EXT) $(out).lst 2> /dev/null))))
1803 $$(QUIET)$$(RM) -f -- $(out).lst $(out)
1804 $$(QUIET)$$(RMDIR) -p --ignore-fail-on-non-empty --ignore-fail-on-not-exist -- $$(dir $$@)
1806 $(out): $(comp-vars _TARGET_$(target)_DIGEST_PREV,_TARGET_$(target)_DIGEST,FORCE) | $(call DIRDEP,$(inst))
1807 $$(QUIET)$$(RM) -f -- $$@
1808 %$$(if $$(_TARGET_$(target)_DIGEST),$$(if $$(wildcard $(out).lst)\
1809 ,$$(call MSG_REFETCH,$(target)),$$(call MSG_FETCH,$(target))),$$(call MSG_UNFETCH,$(target)))
1810 $$(QUIET)$$(if $$(wildcard $(out).lst ),$$(MAKE) -f $(MAKEFILE) --no-print-directory $(out)_unfetched)
1811 $$(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 $$@))
1812 $$(QUIET2)$$(if $$(_TARGET_$(target)_DIGEST),$$(APPEND) $$@ "_TARGET_$(target)_DIGEST_PREV := $(_TARGET_$(target)_DIGEST)")
1814 .NOTPARALLEL: $(out).lst $(out)_unfetched $(out)
1816 endef
1820 # Deal with one fetch target.
1821 # @param target
1822 # @param bld_trg
1823 # @param bld_trg_arch
1824 define def_fetch
1825 # common
1826 INSTARGET_$(target) := $($(target)_INST)
1827 ifneq ($(patsubst %/,ok,$(INSTARGET_$(target))),ok)
1828 $(error kBuild: Bad or missing INST property for target '$(target)'. \
1829 $(target)_INST='$($(target)_INST)' ($(origin $(target)_INST)))
1830 endif
1831 _TARGET_$(target)_FETCHED :=
1832 _TARGET_$(target)_UNPACKED :=
1833 _TARGET_$(target)_DIGEST :=
1834 local clean_files := $($(target)_CLEAN) $($(target)_CLEAN.$(bld_trg)) $($(target)_CLEAN.$(bld_trg).$(bld_trg_arch)) $($(target)_CLEAN.$(bld_trg_arch)) $($(target)_CLEAN.$(KBUILD_TYPE))
1836 # The 'sources'.
1837 #$ (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)))
1838 $(foreach source,$($(target)_SOURCES) $($(target)_SOURCES.$(KBUILD_TYPE)) $($(target)_SOURCES.$(bld_trg)) $($(target)_SOURCES.$(bld_trg_arch)) $($(target)_SOURCES.$(bld_trg).$(bld_trg_arch)),\
1839 $(evalval def_fetch_src))
1841 # The target.
1842 local inst := $(INSTARGET_$(target))
1843 local out := $(inst)_kBuild_fetch_$(target)
1845 $(eval includedep $(out))
1847 $(eval $(def_fetch_rules))
1849 # Define the aliases here (doesn't work if defined in def_fetch_rules, just like includedep).
1850 $(target): $(out)
1851 $(target)_unfetch: $(out)_unfetched
1853 _FETCHES += $(out)
1854 _DOWNLOADS += $(_TARGET_$(target)_FETCHED)
1855 _UNPACKS += $(_TARGET_$(target)_UNPACKED)
1856 _UNFETCHES += $(out)_unfetched
1857 _DIRS += $(inst)
1858 _CLEAN_FILES += $(clean_files)
1860 endef
1862 # Walk the FETCH target lists.
1863 bld_trg := $(KBUILD_TARGET)
1864 bld_trg_arch := $(KBUILD_TARGET_ARCH)
1865 $(foreach target, $(_ALL_FETCHES), \
1866 $(evalvalctx def_fetch))
1868 # some aliases.
1869 download: $(_DOWNLOADS)
1870 unpack: $(_UNPACKS)
1871 fetch: $(_FETCHES)
1872 unfetch: $(_UNFETCHES)
1874 ifdef KBUILD_PROFILE_SELF
1875 _KBUILD_TS_NOW := $(nanots )
1876 $(info prof: $(int-sub $(_KBUILD_TS_NOW), $(_KBUILD_TS_HEADER_START)) - $(int-sub $(_KBUILD_TS_NOW), $(_KBUILD_TS_PREV)) - done fetching targets)
1877 $(info stat: $(make-stats ))
1878 _KBUILD_TS_PREV := $(_KBUILD_TS_NOW)
1879 endif
1884 ## Patching.
1887 #define def_patch_src
1889 #endef
1892 ## Deal with one patch target.
1893 #define def_patch
1895 #$(foreach source,$($(target)_SOURCES) $($(target)_SOURCES.$(KBUILD_TYPE)) $($(target)_SOURCES.$(KBUILD_TARGET)) $($(target)_SOURCES.$(KBUILD_TARGET_ARCH)) $($(target)_SOURCES.$(KBUILD_TARGET).$(KBUILD_TARGET_ARCH)),\
1896 # $(evalval def_patch_src))
1898 #_PATCHES +=
1899 #endef
1901 #$(foreach target, $(_ALL_PATCHES), \
1902 # $(evalval def_patch))
1907 # Object processing.
1910 ## wrapper the compile command dependency check.
1911 ifndef NO_COMPILE_CMDS_DEPS
1912 _DEP_COMPILE_CMDS = $$(comp-cmds-ex $$($(target)_$(subst :,_,$(source))_CMDS_PREV_),$$(commands $(obj)),FORCE)
1913 else
1914 _DEP_COMPILE_CMDS =
1915 endif
1917 ## Generates the rules for building a specific object, and the aliases
1918 # for building a source file.
1919 # @param $(obj) The object file.
1920 define def_target_source_rule
1921 ifdef TOOL_$(tool)_COMPILE_$(type)_USES_KOBJCACHE
1922 $(outbase).koc +| $(obj) $($(target)_$(source)_OUTPUT_) $($(target)_$(source)_OUTPUT_MAYBE_) : \
1923 $($(target)_$(source)_DEPEND_) \
1924 $(value _DEP_COMPILE_CMDS) \
1926 $($(target)_$(source)_DEPORD_) \
1927 $$$$($(target)_INTERMEDIATES)
1928 %$$(call MSG_COMPILE,$(target),$(source),$$@,$(type))
1929 else
1930 $(obj) + $($(target)_$(source)_OUTPUT_) +| $($(target)_$(source)_OUTPUT_MAYBE_) : \
1931 $($(target)_$(source)_DEPEND_) \
1932 $(value _DEP_COMPILE_CMDS) \
1934 $($(target)_$(source)_DEPORD_) \
1935 $$$$($(target)_INTERMEDIATES)
1936 %$$(call MSG_COMPILE,$(target),$(source),$$@,$(type))
1937 ifdef TOOL_$(tool)_COMPILE_$(type)_DONT_PURGE_OUTPUT
1938 $$(QUIET)$$(RM) -f -- $(dep) $(obj) $($(target)_$(source)_OUTPUT_) $($(target)_OUTPUT_MAYBE_)
1939 endif
1940 endif
1942 $($(target)_$(source)_CMDS_)
1944 ifndef NO_COMPILE_CMDS_DEPS
1945 %$$(QUIET2)$$(APPEND) '$(dep)'
1946 %$$(QUIET2)$$(APPEND) '$(dep)' 'define $(target)_$(subst :,_,$(source))_CMDS_PREV_'
1947 %$$(QUIET2)$$(APPEND) -c '$(dep)' '$(obj)'
1948 %$$(QUIET2)$$(APPEND) '$(dep)' 'endef'
1949 endif
1951 $(basename $(notdir $(obj))).o: $(obj)
1952 $(basename $(notdir $(obj))).obj: $(obj)
1954 ## @todo make this 'local cmds' in 0.2.x or when a new kb-src-one is added.
1955 $(target)_$(source)_CMDS_ :=
1956 endef
1959 ## wrapper the link command dependency check.
1960 ifndef NO_LINK_CMDS_DEPS
1961 _DEP_LINK_CMDS = $$(comp-cmds-ex $$($(target)_CMDS_PREV_),$$(commands $(out)),FORCE)
1962 else
1963 _DEP_LINK_CMDS =
1964 endif
1966 ## Generate the link rule for a target.
1967 # @param $(target) The normalized target name.
1968 # @param $(dirdep) Directories we depend upon begin created before linking.
1969 # @param $(dep) The name of the dependency file.
1970 # @param $(out)
1971 # @param $($(target)_OUTPUT_) Output files from the link.
1972 # @param $($(target)_OUTPUT_MAYBE_) Output files that the link may perhaps create.
1973 # @param $($(target)_DEPEND_) Dependencies.
1974 # @param $($(target)_DEPORD_) Dependencies which should only affect build order.
1975 # @param $(cmds) The link commands.
1976 # @param $($(target)_CMDS_PREV_) The link commands from the previous run.
1977 define def_link_rule
1978 $(out) + $($(target)_OUTPUT_) +| $($(target)_OUTPUT_MAYBE_) : \
1979 $($(target)_DEPEND_) \
1980 $(value _DEP_LINK_CMDS) \
1982 $($(target)_DEPORD_)
1983 %$$(call MSG_LINK,$(target),$$@,$(tool_do))
1984 $$(QUIET)$$(RM) -f -- $(dep) $(out) $($(target)_OUTPUT_) $($(target)_OUTPUT_MAYBE_)
1986 $(cmds)
1988 ifndef NO_LINK_CMDS_DEPS
1989 %$$(QUIET2)$$(APPEND) '$(dep)' 'define $(target)_CMDS_PREV_'
1990 %$$(QUIET2)$$(APPEND) -c '$(dep)' '$(out)'
1991 %$$(QUIET2)$$(APPEND) '$(dep)' 'endef'
1992 endif
1994 $(basename $(notdir $(out))):: $(out)
1996 endef
1999 ## Generate the link & lib install rule
2000 # @param $(target) Normalized target name.
2001 # @param $(out) The build target.
2002 # @param $(INSTARGET_$(target)) The installation targets.
2003 # @param $(mode) The file mode (optional)
2004 define def_link_install_rule
2005 $(INSTARGET_$(target)) : $(out) | $(call DIRDEP,$(dir $(INSTARGET_$(target))))
2006 %$$(call MSG_INST_TRG,$(target),$(out),$$@)
2007 $$(QUIET)$$(INSTALL) $$(if $(mode),-m $(mode)) -- $(out) $$@
2009 ifdef KBUILD_DO_AUTO_INSTALL
2010 $(basename $(notdir $(out))):: $(INSTARGET_$(target))
2011 endif
2012 endef
2015 ## def_src_handler_*
2017 # @{
2018 define def_src_handler_c
2019 local type := C
2020 $(kb-src-one )
2021 endef
2023 define def_src_handler_cxx
2024 local type := CXX
2025 $(kb-src-one )
2026 endef
2028 define def_src_handler_objc
2029 local type := OBJC
2030 $(kb-src-one )
2031 endef
2033 define def_src_handler_asm
2034 local type := AS
2035 $(kb-src-one )
2036 endef
2038 define def_src_handler_rc
2039 local type := RC
2040 $(kb-src-one )
2041 endef
2043 define def_src_handler_obj
2044 ifeq ($(defpath),)
2045 $(target)_OBJS_ += $(source)
2046 else
2047 $(target)_OBJS_ += $(abspathex $(source), $(defpath))
2048 endif
2049 endef
2050 ## @}
2052 ## Handle one source.
2054 define def_src_handler_one
2055 local suff := $(suffix $(source))
2056 local src_handler := $(firstword $(filter $(suff):%, $($(target)_$(source)_SRC_HANDLERS) $($(source)_SRC_HANDLERS) $(target_src_handlers) ))
2057 local handler := $(patsubst $(suff):%,%,$(src_handler))
2058 ifneq ($(handler),)
2059 $(evalvalctx $(handler))
2060 else
2061 othersrc += $(source)
2062 endif
2063 endef
2065 ## Generic macro for processing all target sources.
2066 # @param $(target) Normalized target name.
2067 # @param $(defpath)
2068 # @param much-more...
2069 # @returns othersrc, $(target)_OBJS_, ++
2070 define def_target_sources
2071 local target_src_handlers := $($(target)_SRC_HANDLERS) $(KBUILD_SRC_HANDLERS)
2072 $(foreach source,\
2073 $($(target)_SOURCES)\
2074 $($(target)_SOURCES.$(bld_trg))\
2075 $($(target)_SOURCES.$(bld_trg).$(bld_trg_arch))\
2076 $($(target)_SOURCES.$(bld_trg_arch))\
2077 $($(target)_SOURCES.$(bld_trg_cpu))\
2078 $($(target)_SOURCES.$(bld_type))\
2079 ,$(evalval def_src_handler_one) )
2081 $(foreach source,\
2082 $($(target)_GEN_SOURCES_)\
2083 $($(target)_GEN_SOURCES_.$(bld_trg))\
2084 $($(target)_GEN_SOURCES_.$(bld_trg).$(bld_trg_arch))\
2085 $($(target)_GEN_SOURCES_.$(bld_trg_arch))\
2086 $($(target)_GEN_SOURCES_.$(bld_trg_cpu))\
2087 $($(target)_GEN_SOURCES_.$(bld_type))\
2088 ,$(evalval def_src_handler_one) )
2089 endef
2093 ## Generic macro for generating the install rule(s) for a target
2094 # and update the globals with default out.
2096 # @param $(target) Normalized target name.
2097 # @param $(out) The output file.
2098 # @param $(definst) The default _INST value.
2099 # @param $(typevar) The name of the variable with all the root targets of its type.
2100 # @remark Only library uses this now.
2101 define def_target_install_pluss
2102 ifndef $(target)_NOINST
2103 INSTARGET_$(target) := $(patsubst %/,%/$(notdir $(out)), \
2104 $(if $($(target)_INST), $(addprefix $(PATH_INS)/,$($(target)_INST)), $(definst)/))
2106 $(eval $(def_link_install_rule))
2108 _INSTALLS_FILES += $(INSTARGET_$(target))
2110 ifdef KBUILD_DO_AUTO_INSTALL
2111 $(typevar) += $(INSTARGET_$(target))
2112 else
2113 $(typevar) += $(out)
2114 endif
2115 else # _NOINST
2116 $(typevar) += $(out)
2117 endif
2119 _OUT_FILES += $($(target)_OUTPUT_) $($(target)_OUTPUT_MAYBE_) $(out)
2120 _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))
2121 _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))
2122 _OBJS += $($(target)_OBJS_)
2124 endef
2129 # LIBRARIES
2132 ## Library (one).
2133 # @param $(target) Normalized library (target) name.
2134 define def_lib
2135 # library basics
2136 ## @todo prefix
2137 local bld_type := $(firstword $($(target)_BLD_TYPE) $(KBUILD_TYPE))
2138 local bld_trg := $(firstword $($(target)_BLD_TRG) $(KBUILD_TARGET))
2139 local bld_trg_arch:= $(firstword $($(target)_BLD_TRG_ARCH) $(KBUILD_TARGET_ARCH))
2140 local bld_trg_cpu := $(firstword $($(target)_BLD_TRG_CPU) $(KBUILD_TARGET_CPU))
2141 local tool := $(call _TARGET_TOOL,$(target),AR)
2142 ifeq ($(tool),)
2143 $(error kBuild: Library target $(target) does not have a tool defined!)
2144 endif
2145 local name := $(firstword\
2146 $($(target)_NAME.$(bld_trg).$(bld_trg_arch))\
2147 $($(target)_NAME.$(bld_trg_arch))\
2148 $($(target)_NAME.$(bld_trg))\
2149 $($(target)_NAME.$(bld_type))\
2150 $($(target)_NAME)\
2151 $(target))
2152 local outbase := $(call TARGET_BASE,$(name),$(target))
2153 ifndef PATH_$(target)
2154 PATH_$(target) := $(patsubst %/,%,$(dir $(outbase)))
2155 else ifneq ($(PATH_$(target)),$(patsubst %/,%,$(dir $(outbase))))
2156 $(error kBuild internal error: PATH_$(target)=$(PATH_$(target)) expected $(patsubst %/,%,$(dir $(outbase))))
2157 endif
2158 local suff := $(firstword\
2159 $($(target)_LIBSUFF.$(bld_trg).$(bld_trg_arch))\
2160 $($(target)_LIBSUFF.$(bld_trg))\
2161 $($(target)_LIBSUFF)\
2162 $(TOOL_$(tool)_ARLIBSUFF.$(bld_trg).$(bld_trg_arch))\
2163 $(TOOL_$(tool)_ARLIBSUFF.$(bld_trg))\
2164 $(TOOL_$(tool)_ARLIBSUFF)\
2165 $(SUFF_LIB))
2166 local out := $(outbase)$(suff)
2167 local defpath := $($(target)_PATH)
2168 TARGET_$(target) := $(out)
2169 # no local here - must be writable across some foreachs.
2170 othersrc :=
2171 $(target)_OBJS_ :=
2173 # Do units pre source callouts.
2174 local units := \
2175 $($(target)_USES.$(bld_trg).$(bld_trg_arch))\
2176 $($(target)_USES.$(bld_trg_arch))\
2177 $($(target)_USES.$(bld_trg))\
2178 $($(target)_USES.$(bld_type))\
2179 $($(target)_USES)
2180 $(foreach unit,$(units),$(evalval def_unit_$(unit)_target_pre))
2182 # source -> object
2183 $(evalval def_target_sources)
2185 # library linking
2186 local tool := $(call _TARGET_TOOL,$(target),AR)
2187 local name := $(firstword\
2188 $($(target)_NAME.$(bld_trg).$(bld_trg_arch))\
2189 $($(target)_NAME.$(bld_trg_arch))\
2190 $($(target)_NAME.$(bld_trg))\
2191 $($(target)_NAME.$(bld_type))\
2192 $($(target)_NAME)\
2193 $(target))
2194 local outbase := $(call TARGET_BASE,$(name),$(target))
2195 local flags :=\
2196 $(TOOL_$(tool)_ARFLAGS)\
2197 $(TOOL_$(tool)_ARFLAGS.$(bld_type))\
2198 $(ARFLAGS)\
2199 $(ARFLAGS.$(bld_type))\
2200 $($(target)_ARFLAGS)\
2201 $($(target)_ARFLAGS.$(bld_type)) \
2202 $($(target)_ARFLAGS.$(bld_trg)) \
2203 $($(target)_ARFLAGS.$(bld_trg_arch)) \
2204 $($(target)_ARFLAGS.$(bld_trg).$(bld_trg_arch)) \
2205 $($(target)_ARFLAGS.$(bld_trg_cpu))
2206 local dirdep := $(call DIRDEP,$(dir $(out)))
2207 local deps := $($(target)_DEPS)
2208 local orderdeps := $($(target)_ORDERDEPS)
2210 # Adjust paths if we got a default path.
2211 ifneq ($(defpath),)
2212 $(target)_OBJS_ := $(abspathex $($(target)_OBJS_),$(defpath))
2213 local deps := $(abspathex $(deps),$(defpath))
2214 local orderdeps := $(abspathex $(orderdeps),$(defpath))
2215 othersrc := $(abspathex $(othersrc),$(defpath))
2216 endif
2219 # Custom pre-link actions.
2220 ifdef $(target)_PRE_CMDS.$(bld_trg).$(bld_trg_arch).$(bld_type)
2221 local pre_cmds := $($(target)_PRE_CMDS.$(bld_trg).$(bld_trg_arch).$(bld_type))
2222 else ifdef $(target)_PRE_CMDS.$(bld_trg).$(bld_trg_arch)
2223 local pre_cmds := $($(target)_PRE_CMDS.$(bld_trg).$(bld_trg_arch))
2224 else ifdef $(target)_PRE_CMDS.$(bld_trg).$(bld_type)
2225 local pre_cmds := $($(target)_PRE_CMDS.$(bld_trg).$(bld_type))
2226 else ifdef $(target)_PRE_CMDS.$(bld_trg_arch)
2227 local pre_cmds := $($(target)_PRE_CMDS.$(bld_trg_arch))
2228 else ifdef $(target)_PRE_CMDS.$(bld_trg)
2229 local pre_cmds := $($(target)_PRE_CMDS.$(bld_trg))
2230 else ifdef $(target)_PRE_CMDS.$(bld_type)
2231 local pre_cmds := $($(target)_PRE_CMDS.$(bld_type))
2232 else ifdef $(target)_PRE_CMDS
2233 local pre_cmds := $($(target)_PRE_CMDS)
2234 else ifdef PRE_CMDS.$(bld_trg).$(bld_trg_arch).$(bld_type)
2235 local pre_cmds := $(PRE_CMDS.$(bld_trg).$(bld_trg_arch).$(bld_type))
2236 else ifdef PRE_CMDS.$(bld_trg).$(bld_trg_arch)
2237 local pre_cmds := $(PRE_CMDS.$(bld_trg).$(bld_trg_arch))
2238 else ifdef PRE_CMDS.$(bld_trg).$(bld_type)
2239 local pre_cmds := $(PRE_CMDS.$(bld_trg).$(bld_type))
2240 else ifdef PRE_CMDS.$(bld_trg_arch)
2241 local pre_cmds := $(PRE_CMDS.$(bld_trg_arch))
2242 else ifdef PRE_CMDS.$(bld_trg)
2243 local pre_cmds := $(PRE_CMDS.$(bld_trg))
2244 else ifdef PRE_CMDS.$(bld_type)
2245 local pre_cmds := $(PRE_CMDS.$(bld_type))
2246 else
2247 local pre_cmds := $(PRE_CMDS)
2248 endif
2250 # Custom post-link actions.
2251 ifdef $(target)_POST_CMDS.$(bld_trg).$(bld_trg_arch).$(bld_type)
2252 local post_cmds := $($(target)_POST_CMDS.$(bld_trg).$(bld_trg_arch).$(bld_type))
2253 else ifdef $(target)_POST_CMDS.$(bld_trg).$(bld_trg_arch)
2254 local post_cmds := $($(target)_POST_CMDS.$(bld_trg).$(bld_trg_arch))
2255 else ifdef $(target)_POST_CMDS.$(bld_trg).$(bld_type)
2256 local post_cmds := $($(target)_POST_CMDS.$(bld_trg).$(bld_type))
2257 else ifdef $(target)_POST_CMDS.$(bld_trg_arch)
2258 local post_cmds := $($(target)_POST_CMDS.$(bld_trg_arch))
2259 else ifdef $(target)_POST_CMDS.$(bld_trg)
2260 local post_cmds := $($(target)_POST_CMDS.$(bld_trg))
2261 else ifdef $(target)_POST_CMDS.$(bld_type)
2262 local post_cmds := $($(target)_POST_CMDS.$(bld_type))
2263 else ifdef $(target)_POST_CMDS
2264 local post_cmds := $($(target)_POST_CMDS)
2265 else ifdef POST_CMDS.$(bld_trg).$(bld_trg_arch).$(bld_type)
2266 local post_cmds := $(POST_CMDS.$(bld_trg).$(bld_trg_arch).$(bld_type))
2267 else ifdef POST_CMDS.$(bld_trg).$(bld_trg_arch)
2268 local post_cmds := $(POST_CMDS.$(bld_trg).$(bld_trg_arch))
2269 else ifdef POST_CMDS.$(bld_trg).$(bld_type)
2270 local post_cmds := $(POST_CMDS.$(bld_trg).$(bld_type))
2271 else ifdef POST_CMDS.$(bld_trg_arch)
2272 local post_cmds := $(POST_CMDS.$(bld_trg_arch))
2273 else ifdef POST_CMDS.$(bld_trg)
2274 local post_cmds := $(POST_CMDS.$(bld_trg))
2275 else ifdef POST_CMDS.$(bld_type)
2276 local post_cmds := $(POST_CMDS.$(bld_type))
2277 else
2278 local post_cmds := $(POST_CMDS)
2279 endif
2281 # eliminate this guy?
2282 local objs = $($(target)_OBJS_)
2284 # dependency file
2285 local dep := $(out)$(SUFF_DEP)
2286 ifndef NO_LINK_CMDS_DEPS
2287 _DEPFILES_INCLUDED += $(dep)
2288 $(eval includedep $(dep))
2289 endif
2291 # check that the tool is defined.
2292 ifndef TOOL_$(tool)_LINK_LIBRARY_CMDS
2293 $(warning kBuild: tools: \
2294 1 $($(target)_$(source)TOOL.$(bld_trg).$(bld_trg_arch)) \
2295 2 $($(target)_$(source)TOOL.$(bld_trg)) \
2296 3 $($(target)_$(source)TOOL) \
2297 4 $($(target)_TOOL.$(bld_trg).$(bld_trg_arch)) \
2298 5 $($(target)_TOOL.$(bld_trg)) \
2299 6 $($(target)_TOOL) \
2300 7 $($(source)TOOL) \
2301 8 $($(source)TOOL.$(bld_trg).$(bld_trg_arch)) \
2302 9 $($(source)TOOL.$(bld_trg)) \
2303 10 $(TOOL.$(bld_trg).$(bld_trg_arch)) \
2304 11 $(TOOL.$(bld_trg)) \
2305 12 $(TOOL) )
2306 $(error kBuild: TOOL_$(tool)_LINK_LIBRARY_CMDS isn't defined! target=$(target) )
2307 endif
2309 # call the tool
2310 local cmds := $(TOOL_$(tool)_LINK_LIBRARY_CMDS)
2311 ifneq ($(pre_cmds),)
2312 local cmds := $(TAB)$(pre_cmds)$(NL)$(TAB)$(cmds)
2313 endif
2314 ifneq ($(post_cmds),)
2315 local cmds := $(cmds)$(NL)$(TAB)$(post_cmds)
2316 endif
2317 $(target)_OUTPUT_ := $(TOOL_$(tool)_LINK_LIBRARY_OUTPUT)
2318 $(target)_OUTPUT_MAYBE_ := $(TOOL_$(tool)_LINK_LIBRARY_OUTPUT_MAYBE)
2319 $(target)_DEPEND_ := $(TOOL_$(tool)_LINK_LIBRARY_DEPEND) $(deps) $($(target)_OBJS_)
2320 $(target)_DEPORD_ := $(TOOL_$(tool)_LINK_LIBRARY_DEPORD) $(dirdep) $(orderdeps)
2322 # generate the link rule.
2323 $(eval $(def_link_rule))
2325 # installing and globals
2326 $(evalval def_target_install_pluss)
2327 endef
2329 # Process libraries
2330 definst := $(PATH_LIB)
2331 typevar := _LIBS
2332 tool_do := LINK_LIBRARY
2333 mode := 0644
2334 $(foreach target, $(_ALL_LIBRARIES), $(evalval def_lib))
2336 ifdef KBUILD_PROFILE_SELF
2337 _KBUILD_TS_NOW := $(nanots )
2338 $(info prof: $(int-sub $(_KBUILD_TS_NOW), $(_KBUILD_TS_HEADER_START)) - $(int-sub $(_KBUILD_TS_NOW), $(_KBUILD_TS_PREV)) - done library targets)
2339 $(info stat: $(make-stats ))
2340 _KBUILD_TS_PREV := $(_KBUILD_TS_NOW)
2341 endif
2345 # Link operations.
2349 # Link prolog
2351 # @param $(target) Normalized target name.
2352 # @param $(EXT) EXE,DLL,SYS.
2353 # @param $(definst) The default _INST value.
2354 # @param $(typevar) The name of the variable with all the root targets of its type.
2355 define def_link_common
2356 # basics
2357 local bld_type := $(firstword $($(target)_BLD_TYPE) $(KBUILD_TYPE))
2358 local bld_trg := $(firstword $($(target)_BLD_TRG) $(BUILD_$(bld_trg_base_var)))
2359 local bld_trg_arch:= $(firstword $($(target)_BLD_TRG_ARCH) $(BUILD_$(bld_trg_base_var)_ARCH))
2360 local bld_trg_cpu := $(firstword $($(target)_BLD_TRG_CPU) $(BUILD_$(bld_trg_base_var)_CPU))
2362 local tool := $(call _TARGET_TOOL,$(target),LD)
2363 local name := $(firstword\
2364 $($(target)_NAME.$(bld_trg).$(bld_trg_arch))\
2365 $($(target)_NAME.$(bld_trg_arch))\
2366 $($(target)_NAME.$(bld_trg))\
2367 $($(target)_NAME.$(bld_type))\
2368 $($(target)_NAME)\
2369 $(target))
2370 local outbase := $(call TARGET_BASE,$(name),$(target))
2371 ifndef PATH_$(target)
2372 PATH_$(target) := $(patsubst %/,%,$(dir $(outbase)))
2373 else ifneq ($(PATH_$(target)),$(patsubst %/,%,$(dir $(outbase))))
2374 $(error kBuild internal error: PATH_$(target)=$(PATH_$(target)) expected $(patsubst %/,%,$(dir $(outbase))))
2375 endif
2376 local suff := $(firstword \
2377 $($(target)_$(EXT)SUFF) \
2378 $($(target)_$(EXT)SUFF) \
2379 $(TOOL_$(tool)_LD$(EXT)SUFF) \
2380 $($(EXTPRE)SUFF_$(EXT)))
2381 local out := $(outbase)$(suff)
2382 TARGET_$(target) := $(out)
2383 local defpath := $($(target)_PATH)
2384 # no local here - must be writable across some foreachs.
2385 othersrc :=
2386 $(target)_OBJS_ :=
2388 # Do units pre source callouts.
2389 local units := \
2390 $($(target)_USES.$(bld_trg).$(bld_trg_arch))\
2391 $($(target)_USES.$(bld_trg_arch))\
2392 $($(target)_USES.$(bld_trg))\
2393 $($(target)_USES.$(bld_type))\
2394 $($(target)_USES)
2395 $(foreach unit,$(units),$(evalval def_unit_$(unit)_target_pre))
2397 # source -> object
2398 $(evalval def_target_sources)
2400 # more link stuff.
2401 local tool := $(call _TARGET_TOOL,$(target),LD)
2402 local name := $(firstword\
2403 $($(target)_NAME.$(bld_trg).$(bld_trg_arch))\
2404 $($(target)_NAME.$(bld_trg_arch))\
2405 $($(target)_NAME.$(bld_trg))\
2406 $($(target)_NAME.$(bld_type))\
2407 $($(target)_NAME)\
2408 $(target))
2409 local outbase := $(call TARGET_BASE,$(name),$(target))
2410 local flags :=\
2411 $(TOOL_$(tool)_LDFLAGS)\
2412 $(TOOL_$(tool)_LDFLAGS.$(bld_type))\
2413 $(TOOL_$(tool)_LDFLAGS.$(bld_trg))\
2414 $(TOOL_$(tool)_LDFLAGS.$(bld_trg_arch))\
2415 $(TOOL_$(tool)_LDFLAGS.$(bld_trg).$(bld_trg_arch))\
2416 $(TOOL_$(tool)_LDFLAGS.$(bld_trg_cpu))\
2417 $(foreach sdk, $(SDKS) \
2418 $(SDKS.$(bld_type)) \
2419 $(SDKS.$(bld_trg)) \
2420 $(SDKS.$(bld_trg_arch)) \
2421 $(SDKS.$(bld_trg).$(bld_trg_arch)),\
2422 $(SDK_$(sdk)_LDFLAGS)\
2423 $(SDK_$(sdk)_LDFLAGS.$(bld_type))\
2424 $(SDK_$(sdk)_LDFLAGS.$(bld_trg))\
2425 $(SDK_$(sdk)_LDFLAGS.$(bld_trg_arch))\
2426 $(SDK_$(sdk)_LDFLAGS.$(bld_trg).$(bld_trg_arch))\
2427 $(SDK_$(sdk)_LDFLAGS.$(bld_trg_cpu)))\
2428 $(LDFLAGS)\
2429 $(LDFLAGS.$(bld_type))\
2430 $(LDFLAGS.$(bld_trg))\
2431 $(LDFLAGS.$(bld_trg_arch))\
2432 $(LDFLAGS.$(bld_trg).$(bld_trg_arch))\
2433 $(LDFLAGS.$(bld_trg_cpu))\
2434 $(foreach sdk, $($(target)_SDKS) \
2435 $($(target)_SDKS.$(bld_type)) \
2436 $($(target)_SDKS.$(bld_trg)) \
2437 $($(target)_SDKS.$(bld_trg_arch)) \
2438 $($(target)_SDKS.$(bld_trg).$(bld_trg_arch)),\
2439 $(SDK_$(sdk)_LDFLAGS)\
2440 $(SDK_$(sdk)_LDFLAGS.$(bld_type))\
2441 $(SDK_$(sdk)_LDFLAGS.$(bld_trg))\
2442 $(SDK_$(sdk)_LDFLAGS.$(bld_trg_arch))\
2443 $(SDK_$(sdk)_LDFLAGS.$(bld_trg).$(bld_trg_arch))\
2444 $(SDK_$(sdk)_LDFLAGS.$(bld_trg_cpu)))\
2445 $($(target)_LDFLAGS)\
2446 $($(target)_LDFLAGS.$(bld_type))\
2447 $($(target)_LDFLAGS.$(bld_trg))\
2448 $($(target)_LDFLAGS.$(bld_trg_arch))\
2449 $($(target)_LDFLAGS.$(bld_trg).$(bld_trg_arch))\
2450 $($(target)_LDFLAGS.$(bld_trg_cpu))
2451 local libs :=\
2452 $($(target)_LIBS.$(bld_trg_cpu))\
2453 $($(target)_LIBS.$(bld_trg).$(bld_trg_arch))\
2454 $($(target)_LIBS.$(bld_trg_arch))\
2455 $($(target)_LIBS.$(bld_trg))\
2456 $($(target)_LIBS.$(bld_type))\
2457 $($(target)_LIBS)\
2458 $(foreach sdk, $($(target)_SDKS.$(bld_trg).$(bld_trg_arch)) \
2459 $($(target)_SDKS.$(bld_trg_arch)) \
2460 $($(target)_SDKS.$(bld_trg)) \
2461 $($(target)_SDKS.$(bld_type)) \
2462 $($(target)_SDKS),\
2463 $(SDK_$(sdk)_LIBS.$(bld_trg_cpu))\
2464 $(SDK_$(sdk)_LIBS.$(bld_trg).$(bld_trg_arch))\
2465 $(SDK_$(sdk)_LIBS.$(bld_trg_arch))\
2466 $(SDK_$(sdk)_LIBS.$(bld_trg))\
2467 $(SDK_$(sdk)_LIBS.$(bld_type))\
2468 $(SDK_$(sdk)_LIBS))\
2469 $(LIBS.$(bld_trg_cpu))\
2470 $(LIBS.$(bld_trg).$(bld_trg_arch))\
2471 $(LIBS.$(bld_trg_arch))\
2472 $(LIBS.$(bld_trg))\
2473 $(LIBS.$(bld_type))\
2474 $(LIBS)\
2475 $(foreach sdk, $(SDKS.$(bld_trg).$(bld_trg_arch)) \
2476 $(SDKS.$(bld_trg_arch)) \
2477 $(SDKS.$(bld_trg)) \
2478 $(SDKS.$(bld_type)) \
2479 $(SDKS),\
2480 $(SDK_$(sdk)_LIBS.$(bld_trg_cpu))\
2481 $(SDK_$(sdk)_LIBS.$(bld_trg).$(bld_trg_arch))\
2482 $(SDK_$(sdk)_LIBS.$(bld_trg_arch))\
2483 $(SDK_$(sdk)_LIBS.$(bld_trg))\
2484 $(SDK_$(sdk)_LIBS.$(bld_type))\
2485 $(SDK_$(sdk)_LIBS))\
2486 $(TOOL_$(tool)_LIBS.$(bld_trg_cpu))\
2487 $(TOOL_$(tool)_LIBS.$(bld_trg).$(bld_trg_arch))\
2488 $(TOOL_$(tool)_LIBS.$(bld_trg_arch))\
2489 $(TOOL_$(tool)_LIBS.$(bld_trg))\
2490 $(TOOL_$(tool)_LIBS.$(bld_type))\
2491 $(TOOL_$(tool)_LIBS)
2492 local libpath :=\
2493 $($(target)_LIBPATH.$(bld_trg_cpu))\
2494 $($(target)_LIBPATH.$(bld_trg).$(bld_trg_arch))\
2495 $($(target)_LIBPATH.$(bld_trg_arch))\
2496 $($(target)_LIBPATH.$(bld_trg))\
2497 $($(target)_LIBPATH.$(bld_type))\
2498 $($(target)_LIBPATH)\
2499 $(foreach sdk, $($(target)_SDKS.$(bld_trg).$(bld_trg_arch)) \
2500 $($(target)_SDKS.$(bld_trg_arch)) \
2501 $($(target)_SDKS.$(bld_trg)) \
2502 $($(target)_SDKS.$(bld_type)) \
2503 $($(target)_SDKS),\
2504 $(SDK_$(sdk)_LIBPATH.$(bld_trg_cpu))\
2505 $(SDK_$(sdk)_LIBPATH.$(bld_trg).$(bld_trg_arch))\
2506 $(SDK_$(sdk)_LIBPATH.$(bld_trg_arch))\
2507 $(SDK_$(sdk)_LIBPATH.$(bld_trg))\
2508 $(SDK_$(sdk)_LIBPATH.$(bld_type))\
2509 $(SDK_$(sdk)_LIBPATH))\
2510 $(LIBPATH.$(bld_trg_cpu))\
2511 $(LIBPATH.$(bld_trg).$(bld_trg_arch))\
2512 $(LIBPATH.$(bld_trg_arch))\
2513 $(LIBPATH.$(bld_trg))\
2514 $(LIBPATH.$(bld_type))\
2515 $(LIBPATH)\
2516 $(foreach sdk, $(SDKS.$(bld_trg).$(bld_trg_arch)) \
2517 $(SDKS.$(bld_trg_arch)) \
2518 $(SDKS.$(bld_trg)) \
2519 $(SDKS.$(bld_type)) \
2520 $(SDKS),\
2521 $(SDK_$(sdk)_LIBPATH.$(bld_trg_cpu))\
2522 $(SDK_$(sdk)_LIBPATH.$(bld_trg).$(bld_trg_arch))\
2523 $(SDK_$(sdk)_LIBPATH.$(bld_trg_arch))\
2524 $(SDK_$(sdk)_LIBPATH.$(bld_trg))\
2525 $(SDK_$(sdk)_LIBPATH.$(bld_type))\
2526 $(SDK_$(sdk)_LIBPATH))\
2527 $(TOOL_$(tool)_LIBPATH.$(bld_trg_cpu))\
2528 $(TOOL_$(tool)_LIBPATH.$(bld_trg).$(bld_trg_arch))\
2529 $(TOOL_$(tool)_LIBPATH.$(bld_trg_arch))\
2530 $(TOOL_$(tool)_LIBPATH.$(bld_trg))\
2531 $(TOOL_$(tool)_LIBPATH.$(bld_type))\
2532 $(TOOL_$(tool)_LIBPATH)
2533 local dirdep := $(call DIRDEP,$(dir $(out)))
2534 local deps := $($(target)_DEPS)
2535 local orderdeps := $($(target)_ORDERDEPS)
2537 # Adjust paths if we got a default path.
2538 ifneq ($(defpath),)
2539 local libpath := $(abspathex $(libpath),$(defpath))
2540 $(target)_OBJS_ := $(abspathex $($(target)_OBJS_),$(defpath))
2541 local deps := $(abspathex $(deps),$(defpath))
2542 local orderdeps := $(abspathex $(orderdeps),$(defpath))
2543 othersrc := $(abspathex $(othersrc),$(defpath))
2544 # libs are not subject to this because of the the -l<lib> stuff. Use $(<target>_PATH)/lib if relative to current dir!
2545 endif
2547 # Custom pre-link actions.
2548 ifdef $(target)_PRE_CMDS.$(bld_trg).$(bld_trg_arch).$(bld_type)
2549 local pre_cmds := $($(target)_PRE_CMDS.$(bld_trg).$(bld_trg_arch).$(bld_type))
2550 else ifdef $(target)_PRE_CMDS.$(bld_trg).$(bld_trg_arch)
2551 local pre_cmds := $($(target)_PRE_CMDS.$(bld_trg).$(bld_trg_arch))
2552 else ifdef $(target)_PRE_CMDS.$(bld_trg).$(bld_type)
2553 local pre_cmds := $($(target)_PRE_CMDS.$(bld_trg).$(bld_type))
2554 else ifdef $(target)_PRE_CMDS.$(bld_trg_arch)
2555 local pre_cmds := $($(target)_PRE_CMDS.$(bld_trg_arch))
2556 else ifdef $(target)_PRE_CMDS.$(bld_trg)
2557 local pre_cmds := $($(target)_PRE_CMDS.$(bld_trg))
2558 else ifdef $(target)_PRE_CMDS.$(bld_type)
2559 local pre_cmds := $($(target)_PRE_CMDS.$(bld_type))
2560 else ifdef $(target)_PRE_CMDS
2561 local pre_cmds := $($(target)_PRE_CMDS)
2562 else ifdef PRE_CMDS.$(bld_trg).$(bld_trg_arch).$(bld_type)
2563 local pre_cmds := $(PRE_CMDS.$(bld_trg).$(bld_trg_arch).$(bld_type))
2564 else ifdef PRE_CMDS.$(bld_trg).$(bld_trg_arch)
2565 local pre_cmds := $(PRE_CMDS.$(bld_trg).$(bld_trg_arch))
2566 else ifdef PRE_CMDS.$(bld_trg).$(bld_type)
2567 local pre_cmds := $(PRE_CMDS.$(bld_trg).$(bld_type))
2568 else ifdef PRE_CMDS.$(bld_trg_arch)
2569 local pre_cmds := $(PRE_CMDS.$(bld_trg_arch))
2570 else ifdef PRE_CMDS.$(bld_trg)
2571 local pre_cmds := $(PRE_CMDS.$(bld_trg))
2572 else ifdef PRE_CMDS.$(bld_type)
2573 local pre_cmds := $(PRE_CMDS.$(bld_type))
2574 else
2575 local pre_cmds := $(PRE_CMDS)
2576 endif
2578 # Custom post-link actions.
2579 ifdef $(target)_POST_CMDS.$(bld_trg).$(bld_trg_arch).$(bld_type)
2580 local post_cmds := $($(target)_POST_CMDS.$(bld_trg).$(bld_trg_arch).$(bld_type))
2581 else ifdef $(target)_POST_CMDS.$(bld_trg).$(bld_trg_arch)
2582 local post_cmds := $($(target)_POST_CMDS.$(bld_trg).$(bld_trg_arch))
2583 else ifdef $(target)_POST_CMDS.$(bld_trg).$(bld_type)
2584 local post_cmds := $($(target)_POST_CMDS.$(bld_trg).$(bld_type))
2585 else ifdef $(target)_POST_CMDS.$(bld_trg_arch)
2586 local post_cmds := $($(target)_POST_CMDS.$(bld_trg_arch))
2587 else ifdef $(target)_POST_CMDS.$(bld_trg)
2588 local post_cmds := $($(target)_POST_CMDS.$(bld_trg))
2589 else ifdef $(target)_POST_CMDS.$(bld_type)
2590 local post_cmds := $($(target)_POST_CMDS.$(bld_type))
2591 else ifdef $(target)_POST_CMDS
2592 local post_cmds := $($(target)_POST_CMDS)
2593 else ifdef POST_CMDS.$(bld_trg).$(bld_trg_arch).$(bld_type)
2594 local post_cmds := $(POST_CMDS.$(bld_trg).$(bld_trg_arch).$(bld_type))
2595 else ifdef POST_CMDS.$(bld_trg).$(bld_trg_arch)
2596 local post_cmds := $(POST_CMDS.$(bld_trg).$(bld_trg_arch))
2597 else ifdef POST_CMDS.$(bld_trg).$(bld_type)
2598 local post_cmds := $(POST_CMDS.$(bld_trg).$(bld_type))
2599 else ifdef POST_CMDS.$(bld_trg_arch)
2600 local post_cmds := $(POST_CMDS.$(bld_trg_arch))
2601 else ifdef POST_CMDS.$(bld_trg)
2602 local post_cmds := $(POST_CMDS.$(bld_trg))
2603 else ifdef POST_CMDS.$(bld_type)
2604 local post_cmds := $(POST_CMDS.$(bld_type))
2605 else
2606 local post_cmds := $(POST_CMDS)
2607 endif
2609 # eliminate this guy?
2610 local objs = $($(target)_OBJS_)
2612 # installation targets
2613 ifndef $(target)_NOINST
2614 INSTARGET_$(target) := $(patsubst %/,%/$(notdir $(out)), \
2615 $(if $($(target)_INST), $(addprefix $(PATH_INS)/,$($(target)_INST)), $(definst)/))
2616 ifdef KBUILD_DO_AUTO_INSTALL
2617 $(typevar) += $(INSTARGET_$(target))
2618 else
2619 $(typevar) += $(out)
2620 endif
2621 # generate the install rule
2622 $(eval $(def_link_install_rule))
2624 else # NOINST
2625 INSTARGET_$(target) :=
2626 $(typevar) += $(out)
2627 endif # NOINST
2629 # dependency file
2630 local dep := $(outbase)$(SUFF_DEP)
2631 ifndef NO_LINK_CMDS_DEPS
2632 _DEPFILES_INCLUDED += $(dep)
2633 $(eval includedep $(dep))
2634 endif
2636 # check that the tool is defined.
2637 ifndef TOOL_$(tool)_$(tool_do)_CMDS
2638 $(warning kBuild: tools: \
2639 1 $($(target)_$(source)TOOL.$(bld_trg).$(bld_trg_arch)) \
2640 2 $($(target)_$(source)TOOL.$(bld_trg)) \
2641 3 $($(target)_$(source)TOOL) \
2642 4 $($(target)_TOOL.$(bld_trg).$(bld_trg_arch)) \
2643 5 $($(target)_TOOL.$(bld_trg)) \
2644 6 $($(target)_TOOL) \
2645 7 $($(source)TOOL.$(bld_trg).$(bld_trg_arch)) \
2646 8 $($(source)TOOL.$(bld_trg)) \
2647 9 $($(source)TOOL) \
2648 10 $(TOOL.$(bld_trg).$(bld_trg_arch)) \
2649 11 $(TOOL.$(bld_trg)) \
2650 12 $(TOOL) )
2651 $(error kBuild: TOOL_$(tool)_$(tool_do)_CMDS isn't defined! target=$(target) )
2652 endif
2654 # call the tool
2655 local cmds := $(TOOL_$(tool)_$(tool_do)_CMDS)
2656 ifneq ($(pre_cmds),)
2657 local cmds := $(TAB)$(pre_cmds)$(NL)$(TAB)$(cmds)
2658 endif
2659 ifneq ($(post_cmds),)
2660 local cmds := $(cmds)$(NL)$(TAB)$(post_cmds)
2661 endif
2662 $(target)_OUTPUT_ := $(TOOL_$(tool)_$(tool_do)_OUTPUT)
2663 $(target)_OUTPUT_MAYBE_ := $(TOOL_$(tool)_$(tool_do)_OUTPUT_MAYBE)
2664 $(target)_DEPEND_ := $(TOOL_$(tool)_$(tool_do)_DEPEND) $(deps) $($(target)_OBJS_)
2665 $(target)_DEPORD_ := $(TOOL_$(tool)_$(tool_do)_DEPORD) $(dirdep) $(orderdeps)
2667 # generate the link rule.
2668 $(eval $(def_link_rule))
2671 # Update globals.
2672 _OBJS += $($(target)_OBJS_)
2673 _OUT_FILES += $($(target)_OUTPUT_) $(out)
2674 _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))
2675 _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))
2676 _INSTALLS_FILES += $(INSTARGET_$(target))
2678 endef
2682 # BLDPROGS
2685 ## Build program (one).
2686 # @param $(target) Normalized target (program) name.
2687 define def_bldprog
2689 # set NOINST if not forced installation.
2690 ifndef $(target)_INST
2691 $(target)_NOINST := 1
2692 endif
2694 # do the usual stuff.
2695 $(evalval def_link_common)
2697 endef
2699 # Process build programs.
2700 EXT := EXE
2701 EXTPRE := HOST
2702 tool_do := LINK_PROGRAM
2703 definst := $(PATH_BIN)
2704 typevar := _BLDPROGS
2705 mode := 0755
2706 bld_trg_base_var := PLATFORM
2707 $(foreach target, $(_ALL_BLDPROGS), $(evalval def_bldprog))
2709 ifdef KBUILD_PROFILE_SELF
2710 _KBUILD_TS_NOW := $(nanots )
2711 $(info prof: $(int-sub $(_KBUILD_TS_NOW), $(_KBUILD_TS_HEADER_START)) - $(int-sub $(_KBUILD_TS_NOW), $(_KBUILD_TS_PREV)) - done build program targets)
2712 $(info stat: $(make-stats ))
2713 _KBUILD_TS_PREV := $(_KBUILD_TS_NOW)
2714 endif
2718 # DLLS
2721 # Process dlls
2722 EXT := DLL
2723 EXTPRE :=
2724 tool_do := LINK_DLL
2725 definst := $(PATH_DLL)
2726 typevar := _DLLS
2727 mode := 0644
2728 bld_trg_base_var := TARGET
2729 $(foreach target, $(_ALL_DLLS), $(evalval def_link_common))
2731 ifdef KBUILD_PROFILE_SELF
2732 _KBUILD_TS_NOW := $(nanots )
2733 $(info prof: $(int-sub $(_KBUILD_TS_NOW), $(_KBUILD_TS_HEADER_START)) - $(int-sub $(_KBUILD_TS_NOW), $(_KBUILD_TS_PREV)) - done dll targets)
2734 $(info stat: $(make-stats ))
2735 _KBUILD_TS_PREV := $(_KBUILD_TS_NOW)
2736 endif
2740 # IMPORT LIBRARIES
2742 # - On OS/2 and windows these are libraries.
2743 # - On other platforms they are fake DLLs.
2745 EXTPRE :=
2746 typevar := _IMPORT_LIBS
2747 mode := 0644
2748 bld_trg_base_var := TARGET
2749 ifeq ($(filter-out nt os2 win win64 win32,$(KBUILD_TARGET)),)
2750 EXT := LIB
2751 tool_do := LINK_LIBRARY
2752 definst := $(PATH_LIB)
2753 $(foreach target, $(_ALL_IMPORT_LIBS), $(evalval def_lib))
2754 else
2755 EXT := DLL
2756 tool_do := LINK_DLL
2757 definst := $(PATH_DLL)
2758 $(foreach target, $(_ALL_IMPORT_LIBS), $(evalval def_link_common))
2759 endif
2761 ifdef KBUILD_PROFILE_SELF
2762 _KBUILD_TS_NOW := $(nanots )
2763 $(info prof: $(int-sub $(_KBUILD_TS_NOW), $(_KBUILD_TS_HEADER_START)) - $(int-sub $(_KBUILD_TS_NOW), $(_KBUILD_TS_PREV)) - done import library targets)
2764 $(info stat: $(make-stats ))
2765 _KBUILD_TS_PREV := $(_KBUILD_TS_NOW)
2766 endif
2770 # PROGRAMS
2773 # Process programs
2774 EXT := EXE
2775 EXTPRE :=
2776 tool_do := LINK_PROGRAM
2777 definst := $(PATH_BIN)
2778 typevar := _PROGRAMS
2779 mode := 0755
2780 bld_trg_base_var := TARGET
2781 $(foreach target, $(_ALL_PROGRAMS), $(evalval def_link_common))
2783 ifdef KBUILD_PROFILE_SELF
2784 _KBUILD_TS_NOW := $(nanots )
2785 $(info prof: $(int-sub $(_KBUILD_TS_NOW), $(_KBUILD_TS_HEADER_START)) - $(int-sub $(_KBUILD_TS_NOW), $(_KBUILD_TS_PREV)) - done program targets)
2786 $(info stat: $(make-stats ))
2787 _KBUILD_TS_PREV := $(_KBUILD_TS_NOW)
2788 endif
2792 # SYSMODS
2795 # Process sysmods
2796 EXT := SYS
2797 EXTPRE :=
2798 tool_do := LINK_SYSMOD
2799 definst := $(PATH_SYS)
2800 typevar := _SYSMODS
2801 mode := 0644
2802 bld_trg_base_var := TARGET
2803 $(foreach target, $(_ALL_SYSMODS), $(evalval def_link_common))
2805 ifdef KBUILD_PROFILE_SELF
2806 _KBUILD_TS_NOW := $(nanots )
2807 $(info prof: $(int-sub $(_KBUILD_TS_NOW), $(_KBUILD_TS_HEADER_START)) - $(int-sub $(_KBUILD_TS_NOW), $(_KBUILD_TS_PREV)) - done sysmod targets)
2808 $(info stat: $(make-stats ))
2809 _KBUILD_TS_PREV := $(_KBUILD_TS_NOW)
2810 endif
2814 # OTHERS
2816 _OTHERS = $(OTHERS) $(OTHERS.$(KBUILD_TARGET)) $(OTHERS.$(KBUILD_TARGET).$(KBUILD_TARGET_ARCH))
2820 # INSTALLS
2823 ## generate the install rule
2824 define def_install_src_rule
2825 # the install rule
2826 $(insdst) : $(srcsrc) | $(call DIRDEP,$(dir $(insdst)))
2827 %$$(call MSG_INST_FILE,$(srcsrc),$(insdst))
2828 $$(QUIET)$(inscmd)
2829 endef
2831 ## install one file
2832 define def_install_src
2834 # deal with '=>' in the source file name.
2835 local srcdst := $(subst =>, ,$(src))
2836 local srcsrc := $(firstword $(srcdst))
2837 local srcdstdir := $(dir $(word 2,$(srcdst)))
2838 local srcdst := $(word $(words $(srcdst)),$(srcdst))
2840 # _INSTFUN
2841 ifdef $(srcsrc)_INSTFUN
2842 local instfun := $(srcsrc)_INSTFUN
2843 else ifdef $(target)_INSTFUN
2844 local instfun := $(target)_INSTFUN
2845 else
2846 local instfun := _INSTALL_FILE
2847 endif
2849 # _INST
2850 ifdef $(srcsrc)_INST
2851 local inst := $(patsubst %/,%,$($(srcsrc)_INST))/$(dir $(srcdstdir))
2852 else ifdef $(target)_INST
2853 local inst := $(patsubst %/,%,$($(target)_INST))/$(dir $(srcdstdir))
2854 else
2855 local inst := $(dir $(srcdstdir))
2856 endif
2858 # calc target
2859 local insdst := $(call $(instfun),$(srcdst),$(target),$(inst),$(PATH_INS))
2860 #$(warning instfun=$(instfun) srcdst=$(srcdst) target=$(target) inst=$(inst) => insdst=$(insdst))
2862 # mode, uid and gid
2863 local mode := $(firstword \
2864 $($(target)_$(srcsrc)_MODE.$(bld_trg).$(bld_trg_arch)) \
2865 $($(target)_$(srcsrc)_MODE.$(bld_trg)) \
2866 $($(target)_$(srcsrc)_MODE) \
2867 $($(target)_$(srcdst)_MODE.$(bld_trg).$(bld_trg_arch)) \
2868 $($(target)_$(srcdst)_MODE.$(bld_trg)) \
2869 $($(target)_$(srcdst)_MODE) \
2870 $($(srcsrc)_MODE.$(bld_trg).$(bld_trg_arch)) \
2871 $($(srcsrc)_MODE.$(bld_trg)) \
2872 $($(srcsrc)_MODE) \
2873 $($(srcdst)_MODE.$(bld_trg).$(bld_trg_arch)) \
2874 $($(srcdst)_MODE.$(bld_trg)) \
2875 $($(srcdst)_MODE) \
2876 $($(target)_MODE.$(bld_trg).$(bld_trg_arch)) \
2877 $($(target)_MODE.$(bld_trg)) \
2878 $($(target)_MODE))
2879 local uid := $(firstword \
2880 $($(target)_$(srcsrc)_UID.$(bld_trg).$(bld_trg_arch)) \
2881 $($(target)_$(srcsrc)_UID.$(bld_trg)) \
2882 $($(target)_$(srcsrc)_UID) \
2883 $($(target)_$(srcdst)_UID.$(bld_trg).$(bld_trg_arch)) \
2884 $($(target)_$(srcdst)_UID.$(bld_trg)) \
2885 $($(target)_$(srcdst)_UID) \
2886 $($(srcsrc)_UID.$(bld_trg).$(bld_trg_arch)) \
2887 $($(srcsrc)_UID.$(bld_trg)) \
2888 $($(srcsrc)_UID) \
2889 $($(srcdst)_UID.$(bld_trg).$(bld_trg_arch)) \
2890 $($(srcdst)_UID.$(bld_trg)) \
2891 $($(srcdst)_UID) \
2892 $($(target)_UID.$(bld_trg).$(bld_trg_arch)) \
2893 $($(target)_UID.$(bld_trg)) \
2894 $($(target)_UID))
2895 local gid := $(firstword \
2896 $($(target)_$(srcsrc)_GID.$(bld_trg).$(bld_trg_arch)) \
2897 $($(target)_$(srcsrc)_GID.$(bld_trg)) \
2898 $($(target)_$(srcsrc)_GID) \
2899 $($(target)_$(srcdst)_GID.$(bld_trg).$(bld_trg_arch)) \
2900 $($(target)_$(srcdst)_GID.$(bld_trg)) \
2901 $($(target)_$(srcdst)_GID) \
2902 $($(srcsrc)_GID.$(bld_trg).$(bld_trg_arch)) \
2903 $($(srcsrc)_GID.$(bld_trg)) \
2904 $($(srcsrc)_GID) \
2905 $($(srcdst)_GID.$(bld_trg).$(bld_trg_arch)) \
2906 $($(srcdst)_GID.$(bld_trg)) \
2907 $($(srcdst)_GID) \
2908 $($(target)_GID.$(bld_trg).$(bld_trg_arch)) \
2909 $($(target)_GID.$(bld_trg)) \
2910 $($(target)_GID))
2911 local flags := \
2912 $($(target)_IFFLAGS) \
2913 $($(target)_IFFLAGS.$(bld_trg)) \
2914 $($(target)_IFFLAGS.$(bld_trg).$(bld_trg_arch)) \
2915 $($(srcdst)_IFFLAGS) \
2916 $($(srcdst)_IFFLAGS.$(bld_trg)) \
2917 $($(srcdst)_IFFLAGS.$(bld_trg).$(bld_trg_arch)) \
2918 $($(srcsrc)_IFFLAGS) \
2919 $($(srcsrc)_IFFLAGS.$(bld_trg)) \
2920 $($(srcsrc)_IFFLAGS.$(bld_trg).$(bld_trg_arch)) \
2921 $($(target)_$(srcdst)_IFFLAGS) \
2922 $($(target)_$(srcdst)_IFFLAGS.$(bld_trg)) \
2923 $($(target)_$(srcdst)_IFFLAGS.$(bld_trg).$(bld_trg_arch)) \
2924 $($(target)_$(srcsrc)_IFFLAGS) \
2925 $($(target)_$(srcsrc)_IFFLAGS.$(bld_trg)) \
2926 $($(target)_$(srcsrc)_IFFLAGS.$(bld_trg).$(bld_trg_arch))
2927 clean_files += \
2928 $($(srcdst)_CLEAN) \
2929 $($(srcdst)_CLEAN.$(bld_trg)) \
2930 $($(srcdst)_CLEAN.$(bld_trg).$(bld_trg_arch)) \
2931 $($(srcsrc)_CLEAN) \
2932 $($(srcsrc)_CLEAN.$(bld_trg)) \
2933 $($(srcsrc)_CLEAN.$(bld_trg).$(bld_trg_arch)) \
2934 $($(target)_$(srcdst)_CLEAN) \
2935 $($(target)_$(srcdst)_CLEAN.$(bld_trg)) \
2936 $($(target)_$(srcdst)_CLEAN.$(bld_trg).$(bld_trg_arch)) \
2937 $($(target)_$(srcsrc)_CLEAN) \
2938 $($(target)_$(srcsrc)_CLEAN.$(bld_trg)) \
2939 $($(target)_$(srcsrc)_CLEAN.$(bld_trg).$(bld_trg_arch))
2942 # Adjust the source if we got a default PATH. (This must be done this late!)
2943 ifdef $(target)_PATH
2944 local srcsrc := $(abspathex $(srcsrc),$($(target)_PATH))
2945 endif
2947 # create the command
2948 ifdef $(srcsrc)_INSTALLER
2949 local inscmd := $(call $(srcsrc)_INSTALLER,$(srcsrc),$(insdst),$(target),$(flags))
2950 else ifdef $(target)_INSTALLER
2951 local inscmd := $(call $(target)_INSTALLER,$(srcsrc),$(insdst),$(target),$(flags))
2952 else
2953 local inscmd := $$(INSTALL)\
2954 $(if $(uid),-o $(uid))\
2955 $(if $(gid),-g $(gid))\
2956 $(if $(mode),-m $(mode))\
2957 $(flags) -- \
2958 $(srcsrc) $(insdst)
2959 endif
2961 # generate the rule (need double evaluation here)
2962 $(eval $(def_install_src_rule))
2964 INSTARGET_$(target) += $(insdst)
2965 endef
2968 ## generate the symlink rule
2969 define def_install_symlink_rule
2970 # the install rule
2971 $(insdst) : | $(call DIRDEP,$(dir $(insdst)))
2972 %$$(call MSG_INST_SYM,$(insdst),$(symdst))
2973 $$(QUIET)$$(RM) -f -- $$@
2974 $$(QUIET)$$(LN_SYMLINK) $(symdst) $(insdst)
2975 endef
2977 ## create one symlink
2978 define def_install_symlink
2980 # deal with '=>' in the source file name.
2981 local symdst := $(subst =>, ,$(src))
2982 local symlnk := $(firstword $(symdst))
2983 local symdst := $(word $(words $(symdst)),$(symdst))
2985 # _INSTFUN
2986 ifdef $(symlnk)_INSTFUN
2987 local instfun := $(symlnk)_INSTFUN
2988 else ifdef $(target)_INSTFUN
2989 local instfun := $(target)_INSTFUN
2990 else
2991 local instfun := _INSTALL_FILE
2992 endif
2994 # _INST
2995 ifdef $(symlnk)_INST
2996 local inst := $(patsubst %/,%,$($(symlnk)_INST))/$(dir $(symlnk))
2997 else ifdef $(target)_INST
2998 local inst := $(patsubst %/,%,$($(target)_INST))/$(dir $(symlnk))
2999 else
3000 local inst := $(dir $(symlnk))
3001 endif
3003 # calc target
3004 local insdst := $(call $(instfun),$(symlnk),$(target),$(inst),$(PATH_INS))
3005 #$(warning symlnk=$(symlnk) symdst=$(symdst) insdst=$(insdst) instfun=$(instfun) inst='$(inst)')
3007 # generate the rule (need double evaluation here)
3008 $(eval $(def_install_symlink_rule))
3010 INSTARGET_$(target) += $(insdst)
3011 endef
3014 ## generate the install rule
3015 define def_install_directory_rule
3016 # the install rule
3017 $(insdst):
3018 %$$(call MSG_INST_DIR,$(insdst))
3019 $$(QUIET)$$(INSTALL) -d \
3020 $(if $(uid),-o $(uid))\
3021 $(if $(gid),-g $(gid))\
3022 $(if $(mode),-m $(mode))\
3023 $(flags) -- \
3024 $(insdst)
3026 .NOTPARALLEL: $(insdst)
3027 endef
3030 ## create one directory
3031 define def_install_directory
3033 # _INST
3034 ifdef $(directory)_INST
3035 local inst := $(PATH_INS)/$(patsubst %/,%,$($(directory)_INST))
3036 else ifdef $(target)_INST
3037 local inst := $(PATH_INS)/$(patsubst %/,%,$($(target)_INST))
3038 else
3039 local inst := $(PATH_INS)
3040 endif
3042 local mode := $(firstword \
3043 $($(target)_$(directory)_MODE.$(bld_trg).$(bld_trg_arch)) \
3044 $($(target)_$(directory)_MODE.$(bld_trg)) \
3045 $($(target)_$(directory)_MODE) \
3046 $($(directory)_MODE.$(bld_trg).$(bld_trg_arch)) \
3047 $($(directory)_MODE.$(bld_trg)) \
3048 $($(directory)_MODE) \
3049 $($(target)_MODE.$(bld_trg).$(bld_trg_arch)) \
3050 $($(target)_MODE.$(bld_trg)) \
3051 $($(target)_MODE))
3052 local uid := $(firstword \
3053 $($(target)_$(directory)_UID.$(bld_trg).$(bld_trg_arch)) \
3054 $($(target)_$(directory)_UID.$(bld_trg)) \
3055 $($(target)_$(directory)_UID) \
3056 $($(directory)_UID.$(bld_trg).$(bld_trg_arch)) \
3057 $($(directory)_UID.$(bld_trg)) \
3058 $($(directory)_UID) \
3059 $($(target)_UID.$(bld_trg).$(bld_trg_arch)) \
3060 $($(target)_UID.$(bld_trg)) \
3061 $($(target)_UID))
3062 local gid := $(firstword \
3063 $($(target)_$(directory)_GID.$(bld_trg).$(bld_trg_arch)) \
3064 $($(target)_$(directory)_GID.$(bld_trg)) \
3065 $($(target)_$(directory)_GID) \
3066 $($(directory)_GID.$(bld_trg).$(bld_trg_arch)) \
3067 $($(directory)_GID.$(bld_trg)) \
3068 $($(directory)_GID) \
3069 $($(target)_GID.$(bld_trg).$(bld_trg_arch)) \
3070 $($(target)_GID.$(bld_trg)) \
3071 $($(target)_GID))
3072 local flags := \
3073 $($(target)_IDFLAGS)\
3074 $($(target)_IDFLAGS.$(bld_trg)) \
3075 $($(target)_IDFLAGS.$(bld_trg).$(bld_trg_arch)) \
3076 $($(directory)_IDFLAGS) \
3077 $($(directory)_IDFLAGS.$(bld_trg)) \
3078 $($(directory)_IDFLAGS.$(bld_trg).$(bld_trg_arch)) \
3079 $($(target)_$(directory)_IDFLAGS) \
3080 $($(target)_$(directory)_IDFLAGS.$(bld_trg)) \
3081 $($(target)_$(directory)_IDFLAGS.$(bld_trg).$(bld_trg_arch))
3083 local insdst := $(inst)/$(directory)/
3084 #$(warning directory=$(directory) inst=$(inst) insdst=$(insdst) mode=$(mode) gid=$(gid) uid=$(uid))
3086 # generate the rule (need double evaluation here)
3087 $(eval $(def_install_directory_rule))
3089 INSTARGET_DIRS_$(target) += $(insdst)
3090 endef
3093 ## process one install target.
3094 define def_install
3095 # the basics.
3096 local bld_type := $(firstword $($(target)_BLD_TYPE) $(KBUILD_TYPE))
3097 local bld_trg := $(firstword $($(target)_BLD_TRG) $(KBUILD_TARGET))
3098 local bld_trg_arch:= $(firstword $($(target)_BLD_TRG_ARCH) $(KBUILD_TARGET_ARCH))
3099 local bld_trg_cpu := $(firstword $($(target)_BLD_TRG_CPU) $(KBUILD_TARGET_CPU))
3101 INSTARGET_$(target) := $($(target)_GOALS)
3102 INSTARGET_DIRS_$(target) :=
3104 local 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))
3106 $(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)), \
3107 $(evalval def_install_directory))
3109 $(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)), \
3110 $(evalval def_install_src))
3112 $(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)), \
3113 $(evalval def_install_symlink))
3115 # the collection target
3116 TARGET_$(target) := $(PATH_TARGET)/$(target).ins
3117 $(TARGET_$(target)): $(INSTARGET_$(target)) | $(INSTARGET_DIRS_$(target)) $(call DIRDEP,$(PATH_TARGET))
3118 @$(QUIET2)$(APPEND) $@
3120 $(target): $(TARGET_$(target))
3122 _INSTALLS += $(TARGET_$(target))
3123 _INSTALLS_FILES += $(INSTARGET_$(target))
3124 _INSTALLS_DIRS += $(INSTARGET_DIRS_$(target))
3125 _CLEAN_FILES += $(clean_files)
3126 _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))
3127 endef
3129 ## process all install targets
3130 $(foreach target, $(_ALL_INSTALLS), \
3131 $(evalvalctx def_install))
3133 ifdef KBUILD_PROFILE_SELF
3134 _KBUILD_TS_NOW := $(nanots )
3135 $(info prof: $(int-sub $(_KBUILD_TS_NOW), $(_KBUILD_TS_HEADER_START)) - $(int-sub $(_KBUILD_TS_NOW), $(_KBUILD_TS_PREV)) - done install targets)
3136 $(info stat: $(make-stats ))
3137 _KBUILD_TS_PREV := $(_KBUILD_TS_NOW)
3138 endif
3141 # TESTING
3143 _TESTING += $(TESTING) $(TESTING.$(KBUILD_TARGET)) $(TESTING.$(KBUILD_TARGET).$(KBUILD_TARGET_ARCH)) $(TESTING.$(KBUILD_TARGET_ARCH)) $(TESTING.$(KBUILD_TARGET_CPU))
3147 # PACKING
3149 _PACKING += $(PACKING) $(PACKING.$(KBUILD_TARGET)) $(PACKING.$(KBUILD_TARGET).$(KBUILD_TARGET_ARCH)) $(PACKING.$(KBUILD_TARGET_ARCH)) $(PACKING.$(KBUILD_TARGET_CPU))
3153 # DOCS
3158 # DIRECTORIES
3160 _DIR_ALL := $(sort $(addsuffix /,$(patsubst %/,%,$(_DIRS))) $(dir $(_OUT_FILES) $(_OBJS) $(_INSTALLS_FILES)))
3161 $(foreach directory,$(_INSTALLS_DIRS), $(eval _DIR_ALL := $(filter-out $(directory),$(_DIR_ALL))))
3164 define def_mkdir_rule
3165 $(directory):
3166 %$$(call MSG_MKDIR,$$@)
3167 $$(QUIET)$$(MKDIR) -p -- $$@
3168 endef
3170 $(foreach directory,$(_DIR_ALL),$(eval $(def_mkdir_rule)))
3172 ifdef KBUILD_PROFILE_SELF
3173 _KBUILD_TS_NOW := $(nanots )
3174 $(info prof: $(int-sub $(_KBUILD_TS_NOW), $(_KBUILD_TS_HEADER_START)) - $(int-sub $(_KBUILD_TS_NOW), $(_KBUILD_TS_PREV)) - done directories)
3175 $(info stat: $(make-stats ))
3176 _KBUILD_TS_PREV := $(_KBUILD_TS_NOW)
3177 endif
3181 # NOTHING
3183 do-nothing:
3184 ifdef KBUILD_PROFILE_SELF
3185 @$(ECHO) 'prof: $(int-sub $(nanots ), $(_KBUILD_TS_HEADER_START)) - $(int-sub $(nanots ), $(_KBUILD_TS_PREV)) - executing $@'
3186 @$(ECHO) 'stat: $(make-stats )'
3187 endif
3188 %$(call MSG_NOTHING)
3192 # CLEAN UP
3194 do-clean:
3195 %$(call MSG_CLEAN)
3196 $(QUIET)$(RM) -f -- $(_OUT_FILES) $(_OBJS) $(_DEPFILES) $(_DEPFILES_INCLUDED) $(_CLEAN_FILES) $(OTHER_CLEAN)
3197 $(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)))
3202 # PASSES (including directory and makefile walking)
3206 # First, check whether we need to order the passes explicitly or not.
3207 # This depends on whether we're a leaf makefile or not. A leaf will
3208 # know all its dependencies, while a recursive one relies on the
3209 # order sub-directories and other makefiles are executed it.
3212 ## Setup a pass and check for optimizations.
3213 # @param $(PASS) Uppercase pass name.
3214 define def_pass_setup_and_optimize
3216 # The setup. ## @todo This is looks a bit weird...
3217 ifndef SUBDIRS_$(PASS)
3218 SUBDIRS_$(PASS) := $(SUBDIRS) $(SUBDIRS.$(KBUILD_TARGET)) $(SUBDIRS.$(KBUILD_TARGET.$(KBUILD_TARGET_ARCH)))
3219 endif
3220 ifndef SUBDIRS_AFTER_$(PASS)
3221 SUBDIRS_AFTER_$(PASS) := $(SUBDIRS_AFTER) $(SUBDIRS_AFTER.$(KBUILD_TARGET)) $(SUBDIRS_AFTER.$(KBUILD_TARGET).$(KBUILD_TARGET_ARCH))
3222 endif
3223 ifndef MAKEFILES_BEFORE_$(PASS)
3224 MAKEFILES_BEFORE_$(PASS) := $(MAKEFILES_BEFORE) $(MAKEFILES_BEFORE.$(KBUILD_TARGET)) $(MAKEFILES_BEFORE.$(KBUILD_TARGET).$(KBUILD_TARGET_ARCH))
3225 endif
3226 ifndef MAKEFILES_AFTER_$(PASS)
3227 MAKEFILES_AFTER_$(PASS) := $(MAKEFILES_AFTER) $(MAKEFILES_AFTER.$(KBUILD_TARGET)) $(MAKEFILES_AFTER.$(KBUILD_TARGET).$(KBUILD_TARGET_ARCH))
3228 endif
3230 # The check.
3231 ifeq ($(_KBUILD_STRICT_PASS_ORDER),nonstrict)
3232 ifneq ($(strip \
3233 $(SUBDIRS_$(PASS)) $(SUBDIRS_$(PASS).$(KBUILD_TARGET)) $(SUBDIRS_$(PASS).$(KBUILD_TARGET).$(KBUILD_TARGET_ARCH)) \
3234 $(MAKEFILES_BEFORE_$(PASS)) $(MAKEFILES_BEFORE_$(PASS).$(KBUILD_TARGET)) $(MAKEFILES_BEFORE_$(PASS).$(KBUILD_TARGET).$(KBUILD_TARGET_ARCH)) \
3235 $(SUBDIRS_AFTER_$(PASS)) $(SUBDIRS_AFTER_$(PASS).$(KBUILD_TARGET)) $(SUBDIRS_AFTER_$(PASS).$(KBUILD_TARGET).$(KBUILD_TARGET_ARCH)) \
3236 $(MAKEFILES_AFTER_$(PASS)) $(MAKEFILES_AFTER_$(PASS).$(KBUILD_TARGET)) $(MAKEFILES_AFTER_$(PASS).$(KBUILD_TARGET).$(KBUILD_TARGET_ARCH)) \
3238 _KBUILD_STRICT_PASS_ORDER := strict
3239 endif
3240 endif # _KBUILD_STRICT_PASS_ORDER == nonstrict
3241 endef # def_pass_setup_and_optimize
3243 ## PASS: Setup & optimization.
3244 # Check if we can apply the non-strict pass order optimzation (no SUBDIRS_* and MAKEFILES_*),
3245 # and set up the pass specific variables as we go along.
3246 _KBUILD_STRICT_PASS_ORDER := nonstrict
3247 $(foreach PASS, $(PASSES), $(evalval def_pass_setup_and_optimize))
3248 #$ (error _KBUILD_STRICT_PASS_ORDER=$(_KBUILD_STRICT_PASS_ORDER))
3251 ## Subdir
3252 # @param $(pass) Lowercase pass name.
3253 # @param $(PASS) Uppercase pass name.
3254 # @param $(subdir) Subdirectory
3255 # @param $(tag) tag to attach to the rule name.
3256 define def_pass_subdir
3257 pass_$(pass)$(tag):: $(dep)
3258 + $$(QUIET)$$(MAKE) -C $(subdir) -f $$(notdir $$(firstword $$(wildcard $$(addprefix $(subdir)/,$$(DEFAULT_MAKEFILE))))) pass_$(pass)
3259 endef
3261 ## Submakefile
3262 # @param $(pass) Lowercase pass name.
3263 # @param $(PASS) Uppercase pass name.
3264 # @param $(makefile) Makefile.
3265 # @param $(tag) tag to attach to the rule name.
3266 define def_pass_makefile
3267 pass_$(pass)$(tag):: $(dep)
3268 + $$(QUIET)$$(MAKE) -C $(patsubst %/,%,$(dir $(makefile))) -f $(notdir $(makefile)) pass_$(pass)
3269 endef
3271 ## Execute a pass, strict order.
3272 # @param $(pass) Lowercase pass name.
3273 # @param $(PASS) Uppercase pass name.
3274 define def_pass_strict
3275 $(eval tag:=_before)
3276 $(eval dep:=)
3277 $(foreach subdir, $(SUBDIRS_$(PASS)) $(SUBDIRS_$(PASS).$(KBUILD_TARGET)) $(SUBDIRS_$(PASS).$(KBUILD_TARGET).$(KBUILD_TARGET_ARCH)) ,$(eval $(def_pass_subdir)))
3278 $(foreach makefile,$(MAKEFILES_BEFORE_$(PASS)) $(MAKEFILES_BEFORE_$(PASS).$(KBUILD_TARGET)) $(MAKEFILES_BEFORE_$(PASS).$(KBUILD_TARGET).$(KBUILD_TARGET_ARCH)),$(eval $(def_pass_makefile)))
3280 $(eval tag:=_after)
3281 $(eval dep:=pass_$(pass)_doit)
3282 $(foreach subdir, $(SUBDIRS_AFTER_$(PASS)) $(SUBDIRS_AFTER_$(PASS).$(KBUILD_TARGET)) $(SUBDIRS_AFTER_$(PASS).$(KBUILD_TARGET).$(KBUILD_TARGET_ARCH)) ,$(eval $(def_pass_subdir)))
3283 $(foreach makefile,$(MAKEFILES_AFTER_$(PASS)) $(MAKEFILES_AFTER_$(PASS).$(KBUILD_TARGET)) $(MAKEFILES_AFTER_$(PASS).$(KBUILD_TARGET).$(KBUILD_TARGET_ARCH)) ,$(eval $(def_pass_makefile)))
3285 ifdef KBUILD_SAFE_PARALLEL
3286 .NOTPARALLEL: pass_$(pass) pass_$(pass)_before pass_$(pass)_after pass_$(pass)_this
3287 .PHONY: pass_$(pass) pass_$(pass)_before pass_$(pass)_after pass_$(pass)_this pass_$(pass)_doit
3288 pass_$(pass)_doit: $(PASS_$(PASS)_trgs) $(foreach var,$(PASS_$(PASS)_vars),$(var))
3289 pass_$(pass)_this: pass_$(pass)_before
3290 + $$(QUIET)$$(MAKE) -f $$(MAKEFILE) pass_$(pass)_doit
3291 pass_$(pass)_after:: pass_$(pass)_this
3292 pass_$(pass): pass_$(pass)_after
3293 else # !KBUILD_SAFE_PARALLEL
3294 .PHONY: pass_$(pass) pass_$(pass)_before pass_$(pass)_after pass_$(pass)_doit
3295 .NOTPARALLEL: pass_$(pass) pass_$(pass)_before pass_$(pass)_after pass_$(pass)_doit
3296 pass_$(pass)_doit: pass_$(pass)_before \
3297 $(PASS_$(PASS)_trgs) $(foreach var,$(PASS_$(PASS)_vars),$($(var)))
3298 pass_$(pass): \
3299 pass_$(pass)_before \
3300 pass_$(pass)_doit \
3301 pass_$(pass)_after
3302 endif # !KBUILD_SAFE_PARALLEL
3304 #$ (warning pass=$(pass) PASS=$(PASS): $(PASS_$(PASS)_trgs) $(PASS_$(PASS)_trgs) $(foreach var,$(PASS_$(PASS)_vars),$($(var))))
3305 endef # def_pass_strict
3307 ## Execute a pass, non-strict pass ordering.
3308 # @param $(pass) Lowercase pass name.
3309 # @param $(PASS) Uppercase pass name.
3310 define def_pass_nonstrict
3311 .PHONY: pass_$(pass) pass_$(pass)_before pass_$(pass)_after pass_$(pass)_doit
3312 pass_$(pass)_doit: $(PASS_$(PASS)_trgs) $(foreach var,$(PASS_$(PASS)_vars),$($(var)))
3313 pass_$(pass): pass_$(pass)_doit
3314 endef # def_pass_nonstrict
3316 ## PASS: rules
3317 # Generate the rules for the defined passes.
3318 $(foreach PASS, $(PASSES), \
3319 $(eval pass := $(PASS_$(PASS)_pass)) \
3320 $(eval $(def_pass_$(_KBUILD_STRICT_PASS_ORDER))))
3323 ## Pass order, strict.
3324 # @param $(pass) Current pass name.
3325 # @param $(prev_pass) The previous pass name.
3326 define def_pass_order_strict
3327 ifdef KBUILD_SAFE_PARALLEL
3328 .PHONY: pass_$(pass)_order
3329 .NOTPARALLEL: pass_$(pass)_order
3330 pass_$(pass)_order: $(pass_prev)
3331 %$$(call MSG_PASS,$$(if $$(PASS_$(PASS)),$$(PASS_$(PASS)),$(pass)))
3332 + $$(QUIET)$$(MAKE) -f $$(MAKEFILE) pass_$(pass)
3333 else # !KBUILD_SAFE_PARALLEL
3334 .NOTPARALLEL: pass_$(pass)_order pass_$(pass)_banner
3335 .PHONY: pass_$(pass)_order pass_$(pass)_banner
3336 pass_$(pass)_banner:
3337 %$$(call MSG_PASS,$$(if $$(PASS_$(PASS)),$$(PASS_$(PASS)),$(pass)))
3338 pass_$(pass)_order: \
3339 $(pass_prev) \
3340 pass_$(pass)_banner \
3341 pass_$(pass)
3342 endif # !KBUILD_SAFE_PARALLEL
3343 $(eval pass_prev := pass_$(pass)_order)
3344 endef # def_pass_order_strict
3346 ## Pass order, non-strict.
3347 # @param $(pass) Current pass name.
3348 # @param $(prev_pass) The previous pass name.
3349 define def_pass_order_nonstrict
3350 .PHONY: pass_$(pass)_order pass_$(pass)_banner
3351 pass_$(pass)_banner:
3352 %$$(call MSG_PASS,$$(if $$(PASS_$(PASS)),$$(PASS_$(PASS)),$(pass)))
3353 pass_$(pass)_order: \
3354 $(pass_prev) \
3355 pass_$(pass)_banner \
3356 pass_$(pass)
3357 $(eval pass_prev := pass_$(pass)_order)
3358 endef # def_pass_order_nonstrict
3360 ## PASS: order
3361 # Use dependencies to ensure correct pass order.
3362 pass_prev :=
3363 $(foreach PASS,$(DEFAULT_PASSES),\
3364 $(eval pass := $(PASS_$(PASS)_pass)) \
3365 $(eval $(def_pass_order_$(_KBUILD_STRICT_PASS_ORDER))))
3367 ifdef KBUILD_PROFILE_SELF
3368 _KBUILD_TS_NOW := $(nanots )
3369 $(info prof: $(int-sub $(_KBUILD_TS_NOW), $(_KBUILD_TS_HEADER_START)) - $(int-sub $(_KBUILD_TS_NOW), $(_KBUILD_TS_PREV)) - done passes)
3370 $(info stat: $(make-stats ))
3371 _KBUILD_TS_PREV := $(_KBUILD_TS_NOW)
3372 endif
3376 # THE MAIN RULES
3378 all_recursive: $(pass_prev)
3380 rebuild: clean
3381 + $(MAKE) -f $(firstword $(MAKEFILE_LIST)) all_recursive
3383 # @todo make this a non-default pass!
3384 uninstall:
3385 $(RM) -f -- $(_INSTALLS_FILES)
3387 install: pass_installs
3389 # misc shortcuts.
3390 targets: bldprogs libraries dlls programs sysmods others installs
3391 objects: $(_OBJS)
3392 bldprogs: $(_BLDPROGS)
3393 libraries: $(_LIBS) $(_IMPORT_LIBS) $(_OTHER_LIBRARIES)
3394 dlls: $(_DLLS)
3395 programs: $(_PROGRAMS)
3396 sysmods: $(_SYSMODS)
3397 others: $(_OTHERS)
3398 installs: $(_INSTALLS) $(_INSTALLS_DIRS) $(_INSTALLS_FILES)
3403 # kBuild debugging stuff.
3405 ## @todo this doesn't work. Move to a debug unit and expand it.
3406 show_targets:
3407 @$(foreach target, $(_ALL_TARGETS),\
3408 @$(ECHO) "target: $(target)" $(NLTAB)\
3409 @$(ECHO) " PATH_$(target)=$(PATH_$(target))" $(NLTAB)\
3410 @$(ECHO) " TARGET_$(target)=$(TARGET_$(target))" $(NLTAB)\
3411 @$(ECHO) " INSTARGET_$(target)=$(INSTARGET_$(target))" $(NLTAB)\
3412 $(foreach prop,$(PROPS_SINGLE) $(PROPS_ACCUMULATE_L) $(PROPS_ACCUMULATE_R) OBJS_ CLEAN, \
3413 $(eval _tmp:=$(firstword $($(target)_BLD_TRG) $(KBUILD_TARGET))) \
3414 $(if $($(target)_$(prop).$(_tmp)),\
3415 @$(ECHO) " $(target)_$(prop).$(_tmp)=$($(target)_$(prop).$(_tmp))" $(NLTAB)) \
3416 $(if $($(target)_$(prop)), $(NLTAB)@$(ECHO) " $(target)_$(prop)=$($(target)_$(prop))" $(NLTAB)) \
3418 $(foreach prop,$(PROPS_DEFERRED), \
3419 $(eval _tmp:=$(firstword $($(target)_BLD_TRG) $(KBUILD_TARGET))) \
3420 $(if $(value $(target)_$(prop).$(_tmp)),\
3421 @$(ECHO) ' $(target)_$(prop).$(_tmp)=$(value $(TARGET)_$(prop).$(_tmp))' $(NLTAB)) \
3422 $(if $(value $(target)_$(prop)), $(NLTAB)@$(ECHO) ' $(target)_$(prop)=$(value $(target)_$(prop))' $(NLTAB)) \
3428 # Include dependency files.
3430 ifneq ($(_DEPFILES),)
3431 includedep $(_DEPFILES)
3432 endif
3435 ifdef KBUILD_PROFILE_SELF
3436 _KBUILD_TS_FOOTER_END := $(nanots )
3437 $(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)
3438 $(info prof: footer.kmk: $(int-sub $(_KBUILD_TS_FOOTER_END), $(_KBUILD_TS_FOOTER_START)))
3439 $(info stat: $(make-stats ))
3440 _KBUILD_TS_PREV := $(_KBUILD_TS_FOOTER_END)
3441 endif
3443 # end-of-file-content
3444 __footer_kmk__ := target
3445 endif # __footer_kmk__