source: trunk/kBuild/footer.kmk@ 2273

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

footer.kmk: some fetch/unpack todos and spaces.

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