source: trunk/kBuild/footer.kmk@ 2234

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

footer.kmk: 2_OUTPUT, 2_OUTPUT_MAYBE, 2_DEPEND and 2_DEPORD properties. Ref #57.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 130.8 KB
RevLine 
[72]1# $Id: footer.kmk 2234 2009-01-09 02:49:56Z bird $
2## @file
3# kBuild - File included at top of makefile.
4#
[1547]5
6#
[1504]7# Copyright (c) 2004-2008 knut st. osmundsen <bird-kBuild-spam@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))
[828]1403ifndef PATH_$(target)
1404 PATH_$(target) := $(patsubst %/,%,$(dir $(outbase)))
1405else ifneq ($(PATH_$(target)),$(patsubst %/,%,$(dir $(outbase))))
[1672]1406 $(error kBuild internal error: PATH_$(target)=$(PATH_$(target)) expected $(patsubst %/,%,$(dir $(outbase))))
[828]1407endif
[2143]1408## @todo fix the fun at the last line (AR != LIB => mess).
1409local suff := $(firstword \
[828]1410 $($(target)_$(EXT)SUFF.$(bld_trg).$(bld_trg_arch))\
1411 $($(target)_$(EXT)SUFF.$(bld_trg))\
1412 $($(target)_$(EXT)SUFF)\
1413 $(TOOL_$(tool)_$(tool_prefix)$(EXT)SUFF.$(bld_trg).$(bld_trg_arch))\
1414 $(TOOL_$(tool)_$(tool_prefix)$(EXT)SUFF.$(bld_trg))\
1415 $(TOOL_$(tool)_$(tool_prefix)$(EXT)SUFF)\
[2143]1416 $(if $(eq $(tool_prefix),AR),$(SUFF_LIB),$($(EXTPRE)SUFF_$(EXT))) )
[1496]1417local out := $(outbase)$(suff)
[828]1418
1419# TARGET_*
1420TARGET_$(target) := $(out)
1421
1422# INSTARGET_*
[1697]1423ifeq ($(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))),)
1424 ifneq ($(strip $($(target)_INST.$(bld_trg).$(bld_trg_arch).$(bld_type))),)
1425 local inst := $(addprefix $(PATH_INS)/,$($(target)_INST.$(bld_trg).$(bld_trg_arch).$(bld_type)))
1426 else ifneq ($(strip $($(target)_INST.$(bld_trg).$(bld_trg_arch))),)
1427 local inst := $(addprefix $(PATH_INS)/,$($(target)_INST.$(bld_trg).$(bld_trg_arch)))
1428 else ifneq ($(strip $($(target)_INST.$(bld_trg).$(bld_type))),)
1429 local inst := $(addprefix $(PATH_INS)/,$($(target)_INST.$(bld_trg).$(bld_type)))
1430 else ifneq ($(strip $($(target)_INST.$(bld_trg_arch))),)
1431 local inst := $(addprefix $(PATH_INS)/,$($(target)_INST.$(bld_trg_arch)))
1432 else ifneq ($(strip $($(target)_INST.$(bld_trg))),)
1433 local inst := $(addprefix $(PATH_INS)/,$($(target)_INST.$(bld_trg)))
1434 else ifneq ($(strip $($(target)_INST.$(bld_type))),)
1435 local inst := $(addprefix $(PATH_INS)/,$($(target)_INST.$(bld_type)))
1436 else ifneq ($(strip $($(target)_INST)),)
1437 local inst := $(addprefix $(PATH_INS)/,$($(target)_INST))
1438 else
1439 local inst := $(definst)/
1440 endif
1441 INSTARGET_$(target) := $(patsubst %/,%/$(notdir $(out)),$(inst))
[828]1442
1443else # NOINST
[1697]1444 INSTARGET_$(target) :=
[828]1445endif # NOINST
1446
1447endef
[1936]1448$(eval-opt-var def_pass1_link_common)
[828]1449
1450
1451#
1452# BLDPROGS (Pass 1)
1453#
1454define def_pass1_bldprog
1455# set NOINST if not forced installation before doing the usual stuff.
1456ifndef $(target)_INST
1457$(target)_NOINST := 1
1458endif
[1496]1459$(evalval def_pass1_link_common)
[828]1460endef
1461
1462EXT := EXE
1463EXTPRE := HOST
1464definst := $(PATH_BIN)
1465tool_prefix := LD
1466bld_trg_base_var := PLATFORM
[1648]1467$(foreach target, $(_ALL_BLDPROGS), \
[1496]1468 $(evalval def_pass1_bldprog))
[828]1469
1470
1471#
1472# LIBRARIES (Pass 1)
1473#
1474EXT := LIB
1475EXTPRE :=
1476definst := $(PATH_LIB)
1477tool_prefix := AR
1478bld_trg_base_var := TARGET
[1648]1479$(foreach target, $(_ALL_LIBRARIES), \
[1496]1480 $(evalval def_pass1_link_common))
[828]1481
1482
1483#
1484# DLLS (Pass 1)
1485#
1486EXT := DLL
1487EXTPRE :=
1488definst := $(PATH_DLL)
1489tool_prefix := LD
1490bld_trg_base_var := TARGET
[1648]1491$(foreach target, $(_ALL_DLLS), \
[1496]1492 $(evalval def_pass1_link_common))
[828]1493
1494
1495#
1496# IMPORT LIBRARIES (Pass 1)
1497#
1498# - On OS/2 and windows these are libraries.
1499# - On other platforms they are fake DLLs.
1500#
[1504]1501if1of ($(KBUILD_TARGET), nt os2 win win64 win32)
[828]1502 EXT := LIB
1503 EXTPRE :=
1504 definst := $(PATH_LIB)
1505 tool_prefix := AR
1506 bld_trg_base_var := TARGET
[1648]1507 $(foreach target, $(_ALL_IMPORT_LIBS), \
[1496]1508 $(evalval def_pass1_link_common))
[828]1509else
1510 EXT := DLL
1511 EXTPRE :=
1512 definst := $(PATH_DLL)
1513 tool_prefix := LD
1514 bld_trg_base_var := TARGET
[1648]1515 $(foreach target, $(_ALL_IMPORT_LIBS), \
[1496]1516 $(evalval def_pass1_link_common))
[828]1517endif
1518
1519
1520#
1521# PROGRAMS (Pass 1)
1522#
1523EXT := EXE
1524EXTPRE :=
1525definst := $(PATH_BIN)
1526tool_prefix := LD
1527bld_trg_base_var := TARGET
[1648]1528$(foreach target, $(_ALL_PROGRAMS), \
[1496]1529 $(evalval def_pass1_link_common))
[828]1530
1531
1532#
1533# SYSMODS (Pass 1)
1534#
1535EXT := SYS
1536EXTPRE :=
1537definst := $(PATH_SYS)
1538tool_prefix := LD
1539bld_trg_base_var := TARGET
[1648]1540$(foreach target, $(_ALL_SYSMODS), \
[1496]1541 $(evalval def_pass1_link_common))
[828]1542
1543
1544#
[2084]1545# MISCBINS (Pass 1)
1546#
1547EXT := BIN
1548EXTPRE :=
1549definst := $(PATH_BIN)
1550tool_prefix := LD
1551bld_trg_base_var := TARGET
1552$(foreach target, $(_ALL_MISCBINS), \
1553 $(evalval def_pass1_link_common))
1554
1555
1556#
[828]1557# INSTALLS (Pass 1)
1558# Note! INSTARGET_* for INSTALLS aren't available until later.
1559#
1560define def_pass1_install
[1504]1561local bld_type := $(firstword $($(target)_BLD_TYPE) $(KBUILD_TYPE))
1562local bld_trg := $(firstword $($(target)_BLD_TRG) $(KBUILD_TARGET))
1563local bld_trg_arch:= $(firstword $($(target)_BLD_TRG_ARCH) $(KBUILD_TARGET_ARCH))
1564local bld_trg_cpu := $(firstword $($(target)_BLD_TRG_CPU) $(KBUILD_TARGET_CPU))
[828]1565# TARGET_*
[1754]1566TARGET_$(target) := $(PATH_TARGET)/$(target).ins
[828]1567# INSTARGET_ later.
[1754]1568# PATH_*
1569local outbase := $(call TARGET_BASE,$(target),$(target))
1570PATH_$(target) := $(patsubst %/,%,$(dir $(outbase)))
1571endef # def_pass1_install
[1936]1572$(eval-opt-var def_pass1_install)
[1648]1573$(foreach target, $(_ALL_INSTALLS), \
[1496]1574 $(evalval def_pass1_install))
[828]1575
[988]1576ifdef KBUILD_PROFILE_SELF
[2008]1577 $(evalcall def_profile_self, done pass 1)
[988]1578endif
[828]1579
1580
1581
[988]1582
[828]1583#
1584#
1585# Target lists - Pass 2
1586#
1587#
1588
1589
[688]1590## @page pg_fetches Fetching Tools, Sources and Similar.
[73]1591#
[688]1592# The targets listed in the the FETCHES target list have the following attributes:
1593# SOURCES
1594# INST
1595# FETCHTOOL
1596# FETCHFLAGS
1597# FETCHDIR
1598# UNPACKTOOL
1599# UNPACKFLAGS
[640]1600#
[719]1601# As usual the target name is an alias for 'creating' the target. Other
[688]1602# aliases are:
1603# pass_fetches
1604# fetch
1605# unfetch
1606# download
1607# unpack
1608#
1609# @remark
1610#
1611# This is a little bit complex because we must guarantee that if a source file
[719]1612# changes only sligtly we must refetch it and to a proper unpacking of it. It
1613# is also a desire that fetched archives and unpacked files can be deleted to
[688]1614# save space.
1615#
[719]1616# Thus, we must be able to cleanup what we've unpacked should any of the
[688]1617# sources be removed. We do this by maintaining a file listing the files
1618# and directories that was unpacked. This operation is named 'unfetch'.
1619#
[719]1620# We make use of the SIZE and MD5 attributes for each of the sources to
[689]1621# create a digest that is stored in the primary target file. Subsequent
1622# runswill compare their digest with it to decide if a refetch is required.
[719]1623# When a refetch is found necessary, an 'unfetch' is performed first to
[689]1624# clean out old files and directores. Note even changes in source order
[719]1625# will cause a refetch due to the way the digest is constructed and
[689]1626# evaluated.
[688]1627#
1628# By not depending directly on the archives (nor on any unpacked files)
1629# but on a goal made up from the archive name, size and md5, we allow
1630# the user to delete the archives. Naturally, this means we'll have to
1631# check and fetch missing archives before attempting to unpack them.
[689]1632#
1633# @remark
1634#
[719]1635# This feature will *NOT* work correctly with vanilla GNU make becuase
[689]1636# it makes use of includedep to avoid too many unnecessary files.
[719]1637#
[689]1638# @todo
[1255]1639# 1. Download corruption / continuation.
1640# 2. It's quite possible that there is one too many indirect dependency now...
[688]1641#
1642
[640]1643## generates the fetch rule
1644define def_fetch_src_fetch_rule
1645# Indirect goal for downloading something.
[682]1646.PRECIOUS: $(out)
[2234]1647$(out) + $($(target)_$(srcname)_FETCH_2_OUTPUT) +| $($(target)_$(srcname)_FETCH_2_OUTPUT_MAYBE) : \
1648 | $($(target)_$(srcname)_FETCH_2_DEPORD)
[1496]1649 %$$(call MSG_FETCH_DL,$(target),$(source),$(out))
[696]1650 @## @todo do fancy stuff like download continuation.
[1599]1651 $$(QUIET)$$(RM) -f -- $(out)
[2234]1652 $(cmds)
[1255]1653 $$(QUIET)$(if $(md5),$$(MD5SUM_EXT) -b -C $(md5) $(out))
[640]1654
1655
[682]1656
[640]1657# Intermediate goal for making sure the md5 and size matches. it will (re) fetch the archive if necessary.
[2234]1658$(out).checked_$(md5)_$(size): $($(target)_$(srcname)_FETCH_2_DEPEND) | $($(target)_$(srcname)_FETCH_2_DEPORD)
[1496]1659 %$$(call MSG_FETCH_CHK,$(target),$(source),$(out))
[1599]1660 $$(QUIET)$$(RM) -f -- $$@
[688]1661 @# (re)fetch the file if it doesn't exist or if it doesn't matches the md5.
[696]1662 @## @todo do fancy stuff like download continuation.
[1255]1663 $$(QUIET)( test -f $(out) && $(if $(md5),$$(MD5SUM_EXT) -b -C $(md5) $(out), true) ) \
[696]1664 || ( $$(RM_EXT) -f $(out) \
1665 && $$(MAKE) $(out) -f $(MAKEFILE) --no-print-directory )
1666 $$(QUIET2)$$(APPEND) $$@
[640]1667
[719]1668_TARGET_$(target)_FETCHED += $(out) $(out).checked_$(md5)_$(size)
[640]1669
[688]1670# Just a little precaution.
1671.NOTPARALLEL: $(out) $(out).checked_$(md5)_$(size)
1672
[1936]1673endef # def_fetch_src_fetch_rule
1674$(eval-opt-var def_fetch_src_fetch_rule)
[640]1675
1676## generates the unpack rule
1677define def_fetch_src_unpack_rule
1678# This is the unpack rule. it has an order-only dependency on the download check.
[2234]1679$(out) + $($(target)_$(srcname)_UNPACK_2_OUTPUT) +| $($(target)_$(srcname)_UNPACK_2_OUTPUT_MAYBE) : \
1680 $($(target)_$(srcname)_UNPACK_2_DEPEND) \
1681 | $($(target)_$(srcname)_UNPACK_2_DEPORD) \
[2094]1682 $(archive).checked_$(md5)_$(size) \
1683 $(dir $(out))
[1496]1684 %$$(call MSG_FETCH_UP,$(target),$(archive),$(inst))
[1599]1685 $$(QUIET)$$(RM) -f -- $(out)
[2094]1686 $$(QUIET)$$(MKDIR) -p -- $(dir $(out))
1687 @# if the source archive doesn't exist fetch it (may have been deleted to save space).
[696]1688 $$(QUIET)test -f $(archive) \
1689 || ( $$(RM_EXT) -f $(archive).checked_$(md5)_$(size) \
1690 && $$(MAKE) $(archive).checked_$(md5)_$(size) -f $(MAKEFILE) --no-print-directory )
[2234]1691 $(cmds)
[696]1692 $$(QUIET2)$$(APPEND) $(out) $(notdir $(archive).checked_$(md5)_$(size))
1693 $$(QUIET2)$$(APPEND) $(out) $(notdir $(out))
[640]1694
1695$(eval _TARGET_$(target)_UNPACKED += $(out))
1696_TARGET_$(target)_DIGEST := $(_TARGET_$(target)_DIGEST)-$(srcname)_$(md5)_$(size)
1697
[688]1698.NOTPARALLEL: $(out)
1699
[1936]1700endef # def_fetch_src_unpack_rule
1701$(eval-opt-var def_fetch_src_unpack_rule)
[640]1702
1703## Processes a fetch source
1704#
1705define def_fetch_src
1706#$ (warning dbg: def_fetch_src: source='$(source)' target='$(target)')
1707
1708# common
[1496]1709local srcname := $(notdir $(source))
1710local inst := $(firstword \
[640]1711 $($(target)_$(source)_INST)\
1712 $($(target)_$(srcname)_INST)\
1713 $($(source)_INST)\
1714 $($(srcname)_INST)\
1715 $($(target)_INST)\
1716)
1717ifneq ($(patsubst %/,ok,$(inst)),ok)
1718$(error kBuild: Bad or missing INST property for source '$(source)' in target '$(target)': $(inst))
1719endif
1720INSTARGET_$(target)_$(srcname) := $(inst)
[1496]1721local fetchdir := $(firstword \
[640]1722 $($(target)_$(source)_FETCHDIR)\
1723 $($(target)_$(srcname)_FETCHDIR)\
1724 $($(source)_FETCHDIR)\
1725 $($(srcname)_FETCHDIR)\
1726 $($(target)_FETCHDIR)\
1727 $(FETCHDIR)\
1728 $(PATH_TARGET)\
1729)
[1496]1730local deps := \
[640]1731 $($(target)_$(source)_DEPS)\
1732 $($(target)_$(srcname)_DEPS)\
1733 $($(source)_DEPS)\
1734 $($(srcname)_DEPS)\
1735 $($(target)_DEPS)
[1496]1736local orderdeps := \
[827]1737 $($(target)_$(source)_ORDERDEPS)\
1738 $($(target)_$(srcname)_ORDERDEPS)\
1739 $($(source)_ORDERDEPS)\
1740 $($(srcname)_ORDERDEPS)\
1741 $($(target)_ORDERDEPS)
[1496]1742local md5 := $(firstword \
[640]1743 $($(target)_$(source)_MD5)\
1744 $($(target)_$(srcname)_MD5)\
1745 $($(source)_MD5)\
1746 $($(srcname)_MD5)\
1747 $($(target)_MD5)\
1748)
[1496]1749local size := $(firstword \
[640]1750 $($(target)_$(source)_SIZE)\
1751 $($(target)_$(srcname)_SIZE)\
1752 $($(source)_SIZE)\
1753 $($(srcname)_SIZE)\
1754 $($(target)_SIZE)\
1755)
[1613]1756clean_files += \
1757 $($(target)_$(source)_CLEAN)\
1758 $($(target)_$(srcname)_CLEAN)\
1759 $($(source)_CLEAN)\
1760 $($(srcname)_CLEAN)
[1496]1761local dep := # not legal for fetch and unpack tools
[640]1762
1763
1764#
1765# The fetching.
1766#
[1496]1767local out := $(fetchdir)/$(srcname)
1768local archive := $(out)
[640]1769TARGET_$(target)_$(srcname) := $(out)
[1496]1770local dirdep := $(call DIRDEP,$(fetchdir))
1771local tool := $(firstword \
[640]1772 $($(target)_$(source)_FETCHTOOL)\
1773 $($(target)_$(srcname)_FETCHTOOL)\
1774 $($(target)_$(source)_TOOL)\
1775 $($(target)_$(srcname)_TOOL)\
1776 $($(source)_FETCHTOOL)\
1777 $($(srcname)_FETCHTOOL)\
1778 $($(source)_TOOL)\
1779 $($(srcname)_TOOL)\
1780 $($(target)_FETCHTOOL)\
1781 $($(target)_TOOL)\
1782 )
[1496]1783local flags :=\
[640]1784 $(TOOL_$(tool)_FETCHFLAGS)\
1785 $(FETCHFLAGS)\
1786 $($(target)_FETCHFLAGS)\
1787 $($(srcname)_FETCHFLAGS)\
1788 $($(source)_FETCHFLAGS)\
1789 $($(target)_$(srcname)_FETCHFLAGS)\
1790 $($(target)_$(source)_FETCHFLAGS)
1791
1792#$ (warning dbg: target=$(target) source=$(source) $(srcname)=$(srcname) tool=$(tool) out=$(out) flags=$(flags) dirdep=$(dirdep) fetchdir=$(fetchdir) md5=$(md5) size=$(size))
1793
1794ifndef TOOL_$(tool)_FETCH_CMDS
1795$(warning kBuild: tools: \
1796 1 $($(target)_$(source)_FETCHTOOL)\
1797 2 $($(target)_$(srcname)_FETCHTOOL)\
1798 3 $($(target)_$(source)_TOOL)\
1799 4 $($(target)_$(srcname)_TOOL)\
1800 5 $($(source)_FETCHTOOL)\
1801 6 $($(srcname)_FETCHTOOL)\
1802 7 $($(source)_TOOL)\
1803 8 $($(srcname)_TOOL)\
1804 9 $($(target)_FETCHTOOL)\
1805 10 $($(target)_TOOL) )
1806$(error kBuild: TOOL_$(tool)_FETCH_CMDS is not defined. source=$(source) target=$(target) )
1807endif
1808
1809# call the tool
[2234]1810local cmds := $(TOOL_$(tool)_FETCH_CMDS)
1811$(target)_$(srcname)_FETCH_2_OUTPUT := $(TOOL_$(tool)_FETCH_OUTPUT)
1812$(target)_$(srcname)_FETCH_2_OUTPUT_MAYBE := $(TOOL_$(tool)_FETCH_OUTPUT_MAYBE)
1813$(target)_$(srcname)_FETCH_2_DEPEND := $(TOOL_$(tool)_FETCH_DEPEND) $(deps)
1814$(target)_$(srcname)_FETCH_2_DEPORD := $(TOOL_$(tool)_FETCH_DEPORD) $(dirdep) $(orderdeps)
[640]1815
1816# generate the fetch rule.
1817$(eval $(def_fetch_src_fetch_rule))
1818
1819
1820#
1821# The unpacking / installing.
1822#
[1496]1823local out := $(inst)_kBuild_$(target)_$(srcname)_unpacked.lst
1824local dirdep := $(call DIRDEP,$(inst))
1825local tool := $(firstword \
[640]1826 $($(target)_$(source)_UNPACKTOOL)\
1827 $($(target)_$(srcname)_UNPACKTOOL)\
1828 $($(target)_$(source)_TOOL)\
1829 $($(target)_$(srcname)_TOOL)\
1830 $($(source)_UNPACKTOOL)\
1831 $($(srcname)_UNPACKTOOL)\
1832 $($(source)_TOOL)\
1833 $($(srcname)_TOOL)\
1834 $($(target)_UNPACKTOOL)\
1835 $($(target)_TOOL) \
1836 )
1837ifeq ($(tool),)
[1496]1838local tool := $(toupper $(subst .,,$(suffix $(subst tar.,TAR,$(srcname)))))
1839$(evalval def_tools_include)
[640]1840endif
[1496]1841local flags :=\
[640]1842 $(TOOL_$(tool)_UNPACKFLAGS)\
1843 $(UNPACKFLAGS)\
1844 $($(target)_UNPACKFLAGS)\
1845 $($(srcname)_UNPACKFLAGS)\
1846 $($(source)_UNPACKFLAGS)\
1847 $($(target)_$(srcname)_UNPACKFLAGS)\
1848 $($(target)_$(source)_UNPACKFLAGS)
1849
1850#$ (warning dbg: target=$(target) source=$(source) $(srcname)=$(srcname) tool=$(tool) out=$(out) flags=$(flags) dirdep=$(dirdep) inst=$(inst) md5=$(md5) size=$(size))
1851ifndef TOOL_$(tool)_UNPACK_CMDS
1852$(warning kBuild: tools: \
1853 1 $($(target)_$(source)_UNPACKTOOL)\
1854 2 $($(target)_$(srcname)_UNPACKTOOL)\
1855 3 $($(target)_$(source)_TOOL)\
1856 4 $($(target)_$(srcname)_TOOL)\
1857 5 $($(source)_UNPACKTOOL)\
1858 6 $($(srcname)_UNPACKTOOL)\
1859 7 $($(source)_TOOL)\
1860 8 $($(srcname)_TOOL)\
1861 9 $($(target)_UNPACKTOOL)\
1862 10 $($(target)_TOOL) \
1863 11 $(toupper $(subst tar.,TAR,$(ext $(srcname)))) \
1864 )
1865$(error kBuild: TOOL_$(tool)_UNPACK_CMDS is not defined. source=$(source) target=$(target) )
1866endif
1867
1868# call the tool
[2234]1869local cmds := $(TOOL_$(tool)_UNPACK_CMDS)
1870$(target)_$(srcname)_UNPACK_2_OUTPUT := $(TOOL_$(tool)_UNPACK_OUTPUT)
1871$(target)_$(srcname)_UNPACK_2_OUTPUT_MAYBE := $(TOOL_$(tool)_UNPACK_OUTPUT_MAYBE)
1872$(target)_$(srcname)_UNPACK_2_DEPEND := $(TOOL_$(tool)_UNPACK_DEPEND) $(deps)
1873$(target)_$(srcname)_UNPACK_2_DEPORD := $(TOOL_$(tool)_UNPACK_DEPORD) $(dirdep) $(orderdeps)
[640]1874
1875# generate the fetch rule.
1876$(eval $(def_fetch_src_unpack_rule))
1877
1878_DIRS += $(inst) $(fetchdir)
1879
[1936]1880endef # def_fetch_src
1881$(eval-opt-var def_fetch_src)
[640]1882
1883
1884##
1885# Define the target level rules for a fetch.
1886# @param target
1887# @param out
1888# @param inst
[688]1889# @param _TARGET_$(target)_UNPACKED
1890# @param _TARGET_$(target)_DIGEST
[640]1891# @param bld_trg
1892# @param bld_trg_arch
1893define def_fetch_rules
1894
[689]1895$(out).lst: $(_TARGET_$(target)_UNPACKED) | $(call DIRDEP,$(inst))
[1496]1896 %$$(call MSG_FETCH_OK,$(target))
[1599]1897 $$(QUIET)$$(RM) -f -- $$@ $$@.tmp
[1311]1898 $$(QUIET2)$$(APPEND) $$@.tmp '$(notdir $(out))'
[696]1899 $$(QUIET)$(if $(_TARGET_$(target)_UNPACKED),$$(CAT_EXT) $(_TARGET_$(target)_UNPACKED) >> $$@.tmp)
[1599]1900 $$(QUIET)$$(MV) -f -- $$@.tmp $$@
[640]1901
1902$(out)_unfetched:
[1496]1903 %$$(call MSG_UNFETCH,$(target))
[1599]1904 $$(QUIET)$$(RM) -f -- $$(addprefix $(inst),$$(shell $$(CAT_EXT) $(out).lst 2> /dev/null | $$(SED) -e '/\/$$$$/d'))
1905 $$(QUIET)$$(RMDIR) -p --ignore-fail-on-non-empty --ignore-fail-on-not-exist -- $$(dir $$@) \
[689]1906 $$(addprefix $(inst),$$(sort $$(dir $$(shell $$(CAT_EXT) $(out).lst 2> /dev/null))))
[1599]1907 $$(QUIET)$$(RM) -f -- $(out).lst $(out)
1908 $$(QUIET)$$(RMDIR) -p --ignore-fail-on-non-empty --ignore-fail-on-not-exist -- $$(dir $$@)
[640]1909
[689]1910$(out): $(comp-vars _TARGET_$(target)_DIGEST_PREV,_TARGET_$(target)_DIGEST,FORCE) | $(call DIRDEP,$(inst))
[1599]1911 $$(QUIET)$$(RM) -f -- $$@
[2095]1912 %$$(if $$(_TARGET_$(target)_DIGEST),$$(if $$(eq $$(file-size $(out).lst),-1)\
[776]1913 ,$$(call MSG_REFETCH,$(target)),$$(call MSG_FETCH,$(target))),$$(call MSG_UNFETCH,$(target)))
[2094]1914 $$(QUIET)$(TEST_EXT) -f $(out).lst -- $$(MAKE) -f $(MAKEFILE) --no-print-directory $(out)_unfetched
[1599]1915 $$(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]1916 $$(QUIET2)$$(if $$(_TARGET_$(target)_DIGEST),$$(APPEND) $$@ "_TARGET_$(target)_DIGEST_PREV := $(_TARGET_$(target)_DIGEST)")
[760]1917
[689]1918.NOTPARALLEL: $(out).lst $(out)_unfetched $(out)
[688]1919
[640]1920endef
1921
1922
1923##
1924# Deal with one fetch target.
1925# @param target
1926# @param bld_trg
1927# @param bld_trg_arch
1928define def_fetch
1929# common
1930INSTARGET_$(target) := $($(target)_INST)
1931ifneq ($(patsubst %/,ok,$(INSTARGET_$(target))),ok)
[679]1932$(error kBuild: Bad or missing INST property for target '$(target)'. \
1933 $(target)_INST='$($(target)_INST)' ($(origin $(target)_INST)))
[640]1934endif
1935_TARGET_$(target)_FETCHED :=
1936_TARGET_$(target)_UNPACKED :=
1937_TARGET_$(target)_DIGEST :=
[1614]1938local 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]1939
1940# The 'sources'.
[1614]1941#$ (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)))
1942$(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]1943 $(evalval def_fetch_src))
[640]1944
1945# The target.
[1496]1946local inst := $(INSTARGET_$(target))
1947local out := $(inst)_kBuild_fetch_$(target)
[640]1948
[689]1949$(eval includedep $(out))
[690]1950
[640]1951$(eval $(def_fetch_rules))
1952
[690]1953# Define the aliases here (doesn't work if defined in def_fetch_rules, just like includedep).
[749]1954$(target): $(out)
1955$(target)_unfetch: $(out)_unfetched
[690]1956
[689]1957_FETCHES += $(out)
[640]1958_DOWNLOADS += $(_TARGET_$(target)_FETCHED)
1959_UNPACKS += $(_TARGET_$(target)_UNPACKED)
1960_UNFETCHES += $(out)_unfetched
1961_DIRS += $(inst)
[1613]1962_CLEAN_FILES += $(clean_files)
[640]1963
1964endef
[1936]1965$(eval-opt-var def_fetch)
[640]1966
1967# Walk the FETCH target lists.
[1504]1968bld_trg := $(KBUILD_TARGET)
1969bld_trg_arch := $(KBUILD_TARGET_ARCH)
[1648]1970$(foreach target, $(_ALL_FETCHES), \
[1613]1971 $(evalvalctx def_fetch))
[640]1972
1973# some aliases.
1974download: $(_DOWNLOADS)
[688]1975unpack: $(_UNPACKS)
1976fetch: $(_FETCHES)
1977unfetch: $(_UNFETCHES)
[640]1978
[988]1979ifdef KBUILD_PROFILE_SELF
[2008]1980 $(evalcall def_profile_self, done fetching targets)
[988]1981endif
[640]1982
1983
[988]1984
[640]1985##
1986## Patching.
1987##
1988##
[688]1989#define def_patch_src
[640]1990#
1991#endef
1992#
1993#
1994## Deal with one patch target.
1995#define def_patch
1996#
[1504]1997#$(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]1998# $(evalval def_patch_src))
[640]1999#
[719]2000#_PATCHES +=
[640]2001#endef
2002#
[1648]2003#$(foreach target, $(_ALL_PATCHES), \
[1496]2004# $(evalval def_patch))
[640]2005#
2006
2007
2008#
[73]2009# Object processing.
2010#
[72]2011
[380]2012## wrapper the compile command dependency check.
2013ifndef NO_COMPILE_CMDS_DEPS
[2026]2014 if1of ($(KMK_FEATURES),dot-must-make)
2015 _DEP_COMPILE_CMDS =
2016 # for debugging: $$(warning MUST_MAKE=$$$$(comp-cmds-ex $$$$($(target)_$(subst :,_,$(source))_CMDS_PREV_), $$$$(commands $$@)) -> $$(comp-cmds-ex $$($(target)_$(subst :,_,$(source))_CMDS_PREV_),$$(commands $$@),FORCE))
2017 else
2018 _DEP_COMPILE_CMDS = $$(comp-cmds-ex $$($(target)_$(subst :,_,$(source))_CMDS_PREV_),$$(commands $(obj)),FORCE)
2019 endif
[380]2020else
[730]2021 _DEP_COMPILE_CMDS =
[380]2022endif
2023
[2026]2024
[749]2025## Generates the rules for building a specific object, and the aliases
[380]2026# for building a source file.
[353]2027# @param $(obj) The object file.
[380]2028define def_target_source_rule
[2026]2029ifndef NO_COMPILE_CMDS_DEPS
2030$(obj): .MUST_MAKE = $$(comp-cmds-ex $$($(target)_$(subst :,_,$(source))_CMDS_PREV_),$$(commands $$@),FORCE)
2031endif
[1012]2032ifdef TOOL_$(tool)_COMPILE_$(type)_USES_KOBJCACHE
[2196]2033_OUT_FILES += $(outbase).koc
[1030]2034$(outbase).koc +| $(obj) $($(target)_$(source)_OUTPUT_) $($(target)_$(source)_OUTPUT_MAYBE_) : \
[1007]2035 $($(target)_$(source)_DEPEND_) \
[1456]2036 $(value _DEP_COMPILE_CMDS) \
[1007]2037 | \
[1426]2038 $($(target)_$(source)_DEPORD_) \
[1670]2039 $$$$($(target)_INTERMEDIATES)
[1496]2040 %$$(call MSG_COMPILE,$(target),$(source),$$@,$(type))
[1007]2041else
[1030]2042$(obj) + $($(target)_$(source)_OUTPUT_) +| $($(target)_$(source)_OUTPUT_MAYBE_) : \
[380]2043 $($(target)_$(source)_DEPEND_) \
[1456]2044 $(value _DEP_COMPILE_CMDS) \
[380]2045 | \
[1426]2046 $($(target)_$(source)_DEPORD_) \
[1670]2047 $$$$($(target)_INTERMEDIATES)
[1496]2048 %$$(call MSG_COMPILE,$(target),$(source),$$@,$(type))
[1012]2049ifdef TOOL_$(tool)_COMPILE_$(type)_DONT_PURGE_OUTPUT
[1599]2050 $$(QUIET)$$(RM) -f -- $(dep) $(obj) $($(target)_$(source)_OUTPUT_) $($(target)_OUTPUT_MAYBE_)
[1007]2051endif
[1012]2052endif
[412]2053
[380]2054$($(target)_$(source)_CMDS_)
2055
2056ifndef NO_COMPILE_CMDS_DEPS
[1496]2057 %$$(QUIET2)$$(APPEND) '$(dep)'
[1520]2058 %$$(QUIET2)$$(APPEND) '$(dep)' 'define $(target)_$(subst :,_,$(source))_CMDS_PREV_'
[1496]2059 %$$(QUIET2)$$(APPEND) -c '$(dep)' '$(obj)'
2060 %$$(QUIET2)$$(APPEND) '$(dep)' 'endef'
[770]2061endif
[380]2062
[749]2063$(basename $(notdir $(obj))).o: $(obj)
2064$(basename $(notdir $(obj))).obj: $(obj)
[1496]2065
[2234]2066## @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]2067$(target)_$(source)_CMDS_ :=
[2234]2068$(target)_$(source)_OUTPUT_ :=
2069$(target)_$(source)_OUTPUT_MAYBE_ :=
2070$(target)_$(source)_DEPEND_ :=
2071$(target)_$(source)_DEPORD_ :=
[1936]2072endef # def_target_source_rule
2073$(eval-opt-var def_target_source_rule)
[205]2074
[353]2075
[380]2076## wrapper the link command dependency check.
[1502]2077ifndef NO_LINK_CMDS_DEPS
[2026]2078 if1of ($(KMK_FEATURES),dot-must-make)
2079 _DEP_LINK_CMDS =
2080 else
2081 _DEP_LINK_CMDS = $$(comp-cmds-ex $$($(target)_CMDS_PREV_),$$(commands $(out)),FORCE)
2082 endif
[380]2083else
[730]2084 _DEP_LINK_CMDS =
[380]2085endif
2086
2087## Generate the link rule for a target.
2088# @param $(target) The normalized target name.
2089# @param $(dirdep) Directories we depend upon begin created before linking.
2090# @param $(dep) The name of the dependency file.
2091# @param $(out)
[2234]2092# @param $($(target)_2_OUTPUT) Output files from the link.
2093# @param $($(target)_2_OUTPUT_MAYBE) Output files that the link may perhaps create.
2094# @param $($(target)_2_DEPEND) Dependencies.
2095# @param $($(target)_2_DEPORD) Dependencies which should only affect build order.
[1496]2096# @param $(cmds) The link commands.
[380]2097# @param $($(target)_CMDS_PREV_) The link commands from the previous run.
2098define def_link_rule
[2026]2099ifndef NO_LINK_CMDS_DEPS
2100$(out): .MUST_MAKE = $$(comp-cmds-ex $$($(target)_CMDS_PREV_),$$(commands $$@),FORCE)
2101endif
[2234]2102$(out) + $($(target)_2_OUTPUT) +| $($(target)_2_OUTPUT_MAYBE) : \
2103 $$$$($(target)_2_DEPEND) \
[1456]2104 $(value _DEP_LINK_CMDS) \
[380]2105 | \
[2234]2106 $$$$($(target)_2_DEPORD)
[1496]2107 %$$(call MSG_LINK,$(target),$$@,$(tool_do))
[2234]2108 $$(QUIET)$$(RM) -f -- $(dep) $(out) $($(target)_2_OUTPUT) $($(target)_2_OUTPUT_MAYBE)
[412]2109
[1496]2110$(cmds)
[380]2111
[524]2112ifndef NO_LINK_CMDS_DEPS
[1496]2113 %$$(QUIET2)$$(APPEND) '$(dep)' 'define $(target)_CMDS_PREV_'
2114 %$$(QUIET2)$$(APPEND) -c '$(dep)' '$(out)'
2115 %$$(QUIET2)$$(APPEND) '$(dep)' 'endef'
[770]2116endif
[380]2117
[1686]2118$(basename $(notdir $(out))):: $(out)
[719]2119
[1936]2120endef # def_link_rule
2121$(eval-opt-var def_link_rule)
[380]2122
2123
2124## Generate the link & lib install rule
2125# @param $(target) Normalized target name.
2126# @param $(out) The build target.
2127# @param $(INSTARGET_$(target)) The installation targets.
2128# @param $(mode) The file mode (optional)
2129define def_link_install_rule
2130$(INSTARGET_$(target)) : $(out) | $(call DIRDEP,$(dir $(INSTARGET_$(target))))
[1496]2131 %$$(call MSG_INST_TRG,$(target),$(out),$$@)
[2225]2132 $$(QUIET)$$(INSTALL) $(if $(mode),-m $(mode)) $(if $(uid),-o $(uid)) $(if $(gid),-g $(gid)) -- $(out) $$@
[719]2133
2134ifdef KBUILD_DO_AUTO_INSTALL
[1686]2135$(basename $(notdir $(out))):: $(INSTARGET_$(target))
[719]2136endif
[1936]2137endef # def_link_install_rule
[380]2138
2139
[1424]2140## def_src_handler_*
2141#
2142# @{
2143define def_src_handler_c
[1496]2144local type := C
[1795]2145 $(kb-src-one 2)
[1424]2146endef
[73]2147
[1424]2148define def_src_handler_cxx
[1496]2149local type := CXX
[1795]2150 $(kb-src-one 2)
[1424]2151endef
[73]2152
[1424]2153define def_src_handler_objc
[1496]2154local type := OBJC
[1795]2155 $(kb-src-one 2)
[1424]2156endef
[1256]2157
[1424]2158define def_src_handler_asm
[1496]2159local type := AS
[1795]2160 $(kb-src-one 2)
[1424]2161endef
[353]2162
[1424]2163define def_src_handler_rc
[1496]2164local type := RC
[1795]2165 $(kb-src-one 2)
[1424]2166endef
[641]2167
[2080]2168if $(KBUILD_VERSION_PATCH) != 4
[1424]2169define def_src_handler_obj
[1434]2170ifeq ($(defpath),)
[2080]2171 $(target)_2_OBJS += $(source)
2172else
2173 $(target)_2_OBJS += $(abspathex $(source), $(defpath))
2174endif
2175endef
2176else # legacy - remove
2177define def_src_handler_obj
2178ifeq ($(defpath),)
[1434]2179 $(target)_OBJS_ += $(source)
2180else
2181 $(target)_OBJS_ += $(abspathex $(source), $(defpath))
2182endif
[73]2183endef
[2080]2184endif # legacy - remove
[1424]2185## @}
[73]2186
[1424]2187## Handle one source.
2188# .
2189define def_src_handler_one
[1496]2190local suff := $(suffix $(source))
2191local src_handler := $(firstword $(filter $(suff):%, $($(target)_$(source)_SRC_HANDLERS) $($(source)_SRC_HANDLERS) $(target_src_handlers) ))
2192local handler := $(patsubst $(suff):%,%,$(src_handler))
[1424]2193ifneq ($(handler),)
[1625]2194 $(evalvalctx $(handler))
[1424]2195else
[1434]2196 othersrc += $(source)
[1424]2197endif
2198endef
[73]2199
[1424]2200## Generic macro for processing all target sources.
2201# @param $(target) Normalized target name.
2202# @param $(defpath)
2203# @param much-more...
[1472]2204# @returns othersrc, $(target)_OBJS_, ++
[1424]2205define def_target_sources
[1496]2206local target_src_handlers := $($(target)_SRC_HANDLERS) $(KBUILD_SRC_HANDLERS)
[1424]2207$(foreach source,\
[1429]2208 $($(target)_SOURCES)\
2209 $($(target)_SOURCES.$(bld_trg))\
2210 $($(target)_SOURCES.$(bld_trg).$(bld_trg_arch))\
2211 $($(target)_SOURCES.$(bld_trg_arch))\
2212 $($(target)_SOURCES.$(bld_trg_cpu))\
2213 $($(target)_SOURCES.$(bld_type))\
[1496]2214 ,$(evalval def_src_handler_one) )
[1621]2215
2216$(foreach source,\
2217 $($(target)_GEN_SOURCES_)\
2218 $($(target)_GEN_SOURCES_.$(bld_trg))\
2219 $($(target)_GEN_SOURCES_.$(bld_trg).$(bld_trg_arch))\
2220 $($(target)_GEN_SOURCES_.$(bld_trg_arch))\
2221 $($(target)_GEN_SOURCES_.$(bld_trg_cpu))\
2222 $($(target)_GEN_SOURCES_.$(bld_type))\
2223 ,$(evalval def_src_handler_one) )
[1936]2224endef # def_target_sources
2225$(eval-opt-var def_target_sources)
[1424]2226
2227
2228
[353]2229## Generic macro for generating the install rule(s) for a target
2230# and update the globals with default out.
[219]2231#
[353]2232# @param $(target) Normalized target name.
2233# @param $(out) The output file.
2234# @param $(definst) The default _INST value.
2235# @param $(typevar) The name of the variable with all the root targets of its type.
[729]2236# @remark Only library uses this now.
[353]2237define def_target_install_pluss
[1697]2238ifeq ($(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))),)
2239 ifneq ($(strip $($(target)_INST.$(bld_trg).$(bld_trg_arch).$(bld_type))),)
2240 local inst := $(addprefix $(PATH_INS)/,$($(target)_INST.$(bld_trg).$(bld_trg_arch).$(bld_type)))
2241 else ifneq ($(strip $($(target)_INST.$(bld_trg).$(bld_trg_arch))),)
2242 local inst := $(addprefix $(PATH_INS)/,$($(target)_INST.$(bld_trg).$(bld_trg_arch)))
2243 else ifneq ($(strip $($(target)_INST.$(bld_trg).$(bld_type))),)
2244 local inst := $(addprefix $(PATH_INS)/,$($(target)_INST.$(bld_trg).$(bld_type)))
2245 else ifneq ($(strip $($(target)_INST.$(bld_trg_arch))),)
2246 local inst := $(addprefix $(PATH_INS)/,$($(target)_INST.$(bld_trg_arch)))
2247 else ifneq ($(strip $($(target)_INST.$(bld_trg))),)
2248 local inst := $(addprefix $(PATH_INS)/,$($(target)_INST.$(bld_trg)))
2249 else ifneq ($(strip $($(target)_INST.$(bld_type))),)
2250 local inst := $(addprefix $(PATH_INS)/,$($(target)_INST.$(bld_type)))
2251 else ifneq ($(strip $($(target)_INST)),)
2252 local inst := $(addprefix $(PATH_INS)/,$($(target)_INST))
2253 else
2254 local inst := $(definst)/
2255 endif
2256 INSTARGET_$(target) := $(patsubst %/,%/$(notdir $(out)),$(inst))
[2225]2257 local mode := $(firstword \
2258 $($(target)_MODE.$(bld_trg).$(bld_trg_arch).$(bld_type)) \
2259 $($(target)_MODE.$(bld_trg).$(bld_trg_arch)) \
2260 $($(target)_MODE.$(bld_trg).$(bld_type)) \
2261 $($(target)_MODE.$(bld_trg_arch)) \
2262 $($(target)_MODE.$(bld_trg)) \
2263 $($(target)_MODE.$(bld_type)) \
2264 $($(target)_MODE) )
2265 local uid := $(firstword \
2266 $($(target)_UID.$(bld_trg).$(bld_trg_arch).$(bld_type)) \
2267 $($(target)_UID.$(bld_trg).$(bld_trg_arch)) \
2268 $($(target)_UID.$(bld_trg).$(bld_type)) \
2269 $($(target)_UID.$(bld_trg_arch)) \
2270 $($(target)_UID.$(bld_trg)) \
2271 $($(target)_UID.$(bld_type)) \
2272 $($(target)_UID) )
2273 local gid := $(firstword \
2274 $($(target)_GID.$(bld_trg).$(bld_trg_arch).$(bld_type)) \
2275 $($(target)_GID.$(bld_trg).$(bld_trg_arch)) \
2276 $($(target)_GID.$(bld_trg).$(bld_type)) \
2277 $($(target)_GID.$(bld_trg_arch)) \
2278 $($(target)_GID.$(bld_trg)) \
2279 $($(target)_GID.$(bld_type)) \
2280 $($(target)_GID) )
[219]2281
[2225]2282 # generate the install rule
[353]2283$(eval $(def_link_install_rule))
[239]2284
[1697]2285 _INSTALLS_FILES += $(INSTARGET_$(target))
[272]2286
[1697]2287 ifdef KBUILD_DO_AUTO_INSTALL
2288 $(typevar) += $(INSTARGET_$(target))
2289 else
2290 $(typevar) += $(out)
2291 endif
[353]2292else # _NOINST
[1697]2293 $(typevar) += $(out)
[353]2294endif
2295
[2234]2296_OUT_FILES += $($(target)_2_OUTPUT) $($(target)_2_OUTPUT_MAYBE) $(out)
[905]2297_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))
2298_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))
[353]2299_OBJS += $($(target)_OBJS_)
2300
[1936]2301endef # def_target_install_pluss
[219]2302
2303
2304
2305#
[72]2306# LIBRARIES
[73]2307#
[72]2308
2309## Library (one).
[74]2310# @param $(target) Normalized library (target) name.
[72]2311define def_lib
[145]2312# library basics
[222]2313## @todo prefix
[1504]2314local bld_type := $(firstword $($(target)_BLD_TYPE) $(KBUILD_TYPE))
2315local bld_trg := $(firstword $($(target)_BLD_TRG) $(KBUILD_TARGET))
2316local bld_trg_arch:= $(firstword $($(target)_BLD_TRG_ARCH) $(KBUILD_TARGET_ARCH))
2317local bld_trg_cpu := $(firstword $($(target)_BLD_TRG_CPU) $(KBUILD_TARGET_CPU))
[1496]2318local tool := $(call _TARGET_TOOL,$(target),AR)
[78]2319ifeq ($(tool),)
[353]2320$(error kBuild: Library target $(target) does not have a tool defined!)
[78]2321endif
[1496]2322local name := $(firstword\
[889]2323 $($(target)_NAME.$(bld_trg).$(bld_trg_arch))\
2324 $($(target)_NAME.$(bld_trg_arch))\
2325 $($(target)_NAME.$(bld_trg))\
2326 $($(target)_NAME.$(bld_type))\
2327 $($(target)_NAME)\
2328 $(target))
[1496]2329local outbase := $(call TARGET_BASE,$(name),$(target))
[743]2330ifndef PATH_$(target)
[1496]2331 PATH_$(target) := $(patsubst %/,%,$(dir $(outbase)))
[1672]2332else ifneq ($(PATH_$(target)),$(patsubst %/,%,$(dir $(outbase))))
2333 $(error kBuild internal error: PATH_$(target)=$(PATH_$(target)) expected $(patsubst %/,%,$(dir $(outbase))))
[743]2334endif
[1496]2335local suff := $(firstword\
[481]2336 $($(target)_LIBSUFF.$(bld_trg).$(bld_trg_arch))\
[221]2337 $($(target)_LIBSUFF.$(bld_trg))\
[126]2338 $($(target)_LIBSUFF)\
[481]2339 $(TOOL_$(tool)_ARLIBSUFF.$(bld_trg).$(bld_trg_arch))\
[221]2340 $(TOOL_$(tool)_ARLIBSUFF.$(bld_trg))\
[126]2341 $(TOOL_$(tool)_ARLIBSUFF)\
[353]2342 $(SUFF_LIB))
[1496]2343local out := $(outbase)$(suff)
[1755]2344local defpath := $(firstword $($(target)_PATH) $($(target)_DEFPATH))
[1496]2345TARGET_$(target) := $(out)
2346# no local here - must be writable across some foreachs.
2347othersrc :=
2348$(target)_OBJS_ :=
[145]2349
[1672]2350# Do units pre source callouts.
2351local units := \
2352 $($(target)_USES.$(bld_trg).$(bld_trg_arch))\
2353 $($(target)_USES.$(bld_trg_arch))\
2354 $($(target)_USES.$(bld_trg))\
2355 $($(target)_USES.$(bld_type))\
2356 $($(target)_USES)
2357$(foreach unit,$(units),$(evalval def_unit_$(unit)_target_pre))
2358
[145]2359# source -> object
[1496]2360$(evalval def_target_sources)
[145]2361
2362# library linking
[1496]2363local tool := $(call _TARGET_TOOL,$(target),AR)
2364local name := $(firstword\
[889]2365 $($(target)_NAME.$(bld_trg).$(bld_trg_arch))\
2366 $($(target)_NAME.$(bld_trg_arch))\
2367 $($(target)_NAME.$(bld_trg))\
2368 $($(target)_NAME.$(bld_type))\
2369 $($(target)_NAME)\
2370 $(target))
[1496]2371local outbase := $(call TARGET_BASE,$(name),$(target))
2372local flags :=\
[74]2373 $(TOOL_$(tool)_ARFLAGS)\
[221]2374 $(TOOL_$(tool)_ARFLAGS.$(bld_type))\
[74]2375 $(ARFLAGS)\
[221]2376 $(ARFLAGS.$(bld_type))\
[74]2377 $($(target)_ARFLAGS)\
[481]2378 $($(target)_ARFLAGS.$(bld_type)) \
2379 $($(target)_ARFLAGS.$(bld_trg)) \
2380 $($(target)_ARFLAGS.$(bld_trg_arch)) \
2381 $($(target)_ARFLAGS.$(bld_trg).$(bld_trg_arch)) \
2382 $($(target)_ARFLAGS.$(bld_trg_cpu))
[1496]2383local dirdep := $(call DIRDEP,$(dir $(out)))
[1702]2384local deps := \
2385 $($(target)_DEPS.$(bld_trg_cpu)) \
2386 $($(target)_DEPS.$(bld_trg).$(bld_trg_arch).$(bld_type)) \
2387 $($(target)_DEPS.$(bld_trg).$(bld_trg_arch)) \
2388 $($(target)_DEPS.$(bld_trg).$(bld_type)) \
2389 $($(target)_DEPS.$(bld_trg_arch)) \
2390 $($(target)_DEPS.$(bld_trg)) \
2391 $($(target)_DEPS.$(bld_type)) \
2392 $($(target)_DEPS) \
2393 $($(target)_LNK_DEPS.$(bld_trg_cpu)) \
2394 $($(target)_LNK_DEPS.$(bld_trg).$(bld_trg_arch).$(bld_type)) \
2395 $($(target)_LNK_DEPS.$(bld_trg).$(bld_trg_arch)) \
2396 $($(target)_LNK_DEPS.$(bld_trg).$(bld_type)) \
2397 $($(target)_LNK_DEPS.$(bld_trg_arch)) \
2398 $($(target)_LNK_DEPS.$(bld_trg)) \
2399 $($(target)_LNK_DEPS.$(bld_type)) \
2400 $($(target)_LNK_DEPS)
2401local orderdeps := \
2402 $($(target)_ORDERDEPS.$(bld_trg_cpu)) \
2403 $($(target)_ORDERDEPS.$(bld_trg).$(bld_trg_arch).$(bld_type)) \
2404 $($(target)_ORDERDEPS.$(bld_trg).$(bld_trg_arch)) \
2405 $($(target)_ORDERDEPS.$(bld_trg).$(bld_type)) \
2406 $($(target)_ORDERDEPS.$(bld_trg_arch)) \
2407 $($(target)_ORDERDEPS.$(bld_trg)) \
2408 $($(target)_ORDERDEPS.$(bld_type)) \
2409 $($(target)_ORDERDEPS) \
2410 $($(target)_LNK_ORDERDEPS.$(bld_trg_cpu)) \
2411 $($(target)_LNK_ORDERDEPS.$(bld_trg).$(bld_trg_arch).$(bld_type)) \
2412 $($(target)_LNK_ORDERDEPS.$(bld_trg).$(bld_trg_arch)) \
2413 $($(target)_LNK_ORDERDEPS.$(bld_trg).$(bld_type)) \
2414 $($(target)_LNK_ORDERDEPS.$(bld_trg_arch)) \
2415 $($(target)_LNK_ORDERDEPS.$(bld_trg)) \
2416 $($(target)_LNK_ORDERDEPS.$(bld_type)) \
2417 $($(target)_LNK_ORDERDEPS)
[72]2418
[725]2419# Adjust paths if we got a default path.
2420ifneq ($(defpath),)
[1496]2421 $(target)_OBJS_ := $(abspathex $($(target)_OBJS_),$(defpath))
2422 local deps := $(abspathex $(deps),$(defpath))
2423 local orderdeps := $(abspathex $(orderdeps),$(defpath))
[1472]2424 othersrc := $(abspathex $(othersrc),$(defpath))
[725]2425endif
2426
[859]2427
2428# Custom pre-link actions.
[1702]2429## @todo bld_trg_cpu is missing here.
[859]2430ifdef $(target)_PRE_CMDS.$(bld_trg).$(bld_trg_arch).$(bld_type)
[1496]2431 local pre_cmds := $($(target)_PRE_CMDS.$(bld_trg).$(bld_trg_arch).$(bld_type))
[859]2432else ifdef $(target)_PRE_CMDS.$(bld_trg).$(bld_trg_arch)
[1496]2433 local pre_cmds := $($(target)_PRE_CMDS.$(bld_trg).$(bld_trg_arch))
[859]2434else ifdef $(target)_PRE_CMDS.$(bld_trg).$(bld_type)
[1496]2435 local pre_cmds := $($(target)_PRE_CMDS.$(bld_trg).$(bld_type))
[859]2436else ifdef $(target)_PRE_CMDS.$(bld_trg_arch)
[1496]2437 local pre_cmds := $($(target)_PRE_CMDS.$(bld_trg_arch))
[859]2438else ifdef $(target)_PRE_CMDS.$(bld_trg)
[1496]2439 local pre_cmds := $($(target)_PRE_CMDS.$(bld_trg))
[859]2440else ifdef $(target)_PRE_CMDS.$(bld_type)
[1496]2441 local pre_cmds := $($(target)_PRE_CMDS.$(bld_type))
[859]2442else ifdef $(target)_PRE_CMDS
[1496]2443 local pre_cmds := $($(target)_PRE_CMDS)
[859]2444else ifdef PRE_CMDS.$(bld_trg).$(bld_trg_arch).$(bld_type)
[1496]2445 local pre_cmds := $(PRE_CMDS.$(bld_trg).$(bld_trg_arch).$(bld_type))
[859]2446else ifdef PRE_CMDS.$(bld_trg).$(bld_trg_arch)
[1496]2447 local pre_cmds := $(PRE_CMDS.$(bld_trg).$(bld_trg_arch))
[859]2448else ifdef PRE_CMDS.$(bld_trg).$(bld_type)
[1496]2449 local pre_cmds := $(PRE_CMDS.$(bld_trg).$(bld_type))
[859]2450else ifdef PRE_CMDS.$(bld_trg_arch)
[1496]2451 local pre_cmds := $(PRE_CMDS.$(bld_trg_arch))
[859]2452else ifdef PRE_CMDS.$(bld_trg)
[1496]2453 local pre_cmds := $(PRE_CMDS.$(bld_trg))
[859]2454else ifdef PRE_CMDS.$(bld_type)
[1496]2455 local pre_cmds := $(PRE_CMDS.$(bld_type))
[859]2456else
[1496]2457 local pre_cmds := $(PRE_CMDS)
[859]2458endif
2459
2460# Custom post-link actions.
2461ifdef $(target)_POST_CMDS.$(bld_trg).$(bld_trg_arch).$(bld_type)
[1496]2462 local post_cmds := $($(target)_POST_CMDS.$(bld_trg).$(bld_trg_arch).$(bld_type))
[859]2463else ifdef $(target)_POST_CMDS.$(bld_trg).$(bld_trg_arch)
[1496]2464 local post_cmds := $($(target)_POST_CMDS.$(bld_trg).$(bld_trg_arch))
[859]2465else ifdef $(target)_POST_CMDS.$(bld_trg).$(bld_type)
[1496]2466 local post_cmds := $($(target)_POST_CMDS.$(bld_trg).$(bld_type))
[859]2467else ifdef $(target)_POST_CMDS.$(bld_trg_arch)
[1496]2468 local post_cmds := $($(target)_POST_CMDS.$(bld_trg_arch))
[859]2469else ifdef $(target)_POST_CMDS.$(bld_trg)
[1496]2470 local post_cmds := $($(target)_POST_CMDS.$(bld_trg))
[859]2471else ifdef $(target)_POST_CMDS.$(bld_type)
[1496]2472 local post_cmds := $($(target)_POST_CMDS.$(bld_type))
[859]2473else ifdef $(target)_POST_CMDS
[1496]2474 local post_cmds := $($(target)_POST_CMDS)
[859]2475else ifdef POST_CMDS.$(bld_trg).$(bld_trg_arch).$(bld_type)
[1496]2476 local post_cmds := $(POST_CMDS.$(bld_trg).$(bld_trg_arch).$(bld_type))
[859]2477else ifdef POST_CMDS.$(bld_trg).$(bld_trg_arch)
[1496]2478 local post_cmds := $(POST_CMDS.$(bld_trg).$(bld_trg_arch))
[859]2479else ifdef POST_CMDS.$(bld_trg).$(bld_type)
[1496]2480 local post_cmds := $(POST_CMDS.$(bld_trg).$(bld_type))
[859]2481else ifdef POST_CMDS.$(bld_trg_arch)
[1496]2482 local post_cmds := $(POST_CMDS.$(bld_trg_arch))
[859]2483else ifdef POST_CMDS.$(bld_trg)
[1496]2484 local post_cmds := $(POST_CMDS.$(bld_trg))
[859]2485else ifdef POST_CMDS.$(bld_type)
[1496]2486 local post_cmds := $(POST_CMDS.$(bld_type))
[859]2487else
[1496]2488 local post_cmds := $(POST_CMDS)
[859]2489endif
2490
[1424]2491# eliminate this guy?
[1496]2492local objs = $($(target)_OBJS_)
[1424]2493
[380]2494# dependency file
[1496]2495local dep := $(out)$(SUFF_DEP)
[524]2496ifndef NO_LINK_CMDS_DEPS
[1798]2497 _DEPFILES_INCLUDED += $(dep)
2498 ifdef KB_HAVE_INCLUDEDEP_QUEUE
2499 includedep-queue $(dep)
[1795]2500 else
[1798]2501 includedep $(dep)
[1795]2502 endif
[380]2503endif
[72]2504
[380]2505# check that the tool is defined.
2506ifndef TOOL_$(tool)_LINK_LIBRARY_CMDS
2507$(warning kBuild: tools: \
[481]2508 1 $($(target)_$(source)TOOL.$(bld_trg).$(bld_trg_arch)) \
2509 2 $($(target)_$(source)TOOL.$(bld_trg)) \
2510 3 $($(target)_$(source)TOOL) \
2511 4 $($(target)_TOOL.$(bld_trg).$(bld_trg_arch)) \
2512 5 $($(target)_TOOL.$(bld_trg)) \
2513 6 $($(target)_TOOL) \
2514 7 $($(source)TOOL) \
2515 8 $($(source)TOOL.$(bld_trg).$(bld_trg_arch)) \
2516 9 $($(source)TOOL.$(bld_trg)) \
2517 10 $(TOOL.$(bld_trg).$(bld_trg_arch)) \
2518 11 $(TOOL.$(bld_trg)) \
2519 12 $(TOOL) )
[380]2520$(error kBuild: TOOL_$(tool)_LINK_LIBRARY_CMDS isn't defined! target=$(target) )
2521endif
2522
2523# call the tool
[1496]2524local cmds := $(TOOL_$(tool)_LINK_LIBRARY_CMDS)
[859]2525ifneq ($(pre_cmds),)
[1496]2526 local cmds := $(TAB)$(pre_cmds)$(NL)$(TAB)$(cmds)
[859]2527endif
2528ifneq ($(post_cmds),)
[1496]2529 local cmds := $(cmds)$(NL)$(TAB)$(post_cmds)
[859]2530endif
[2234]2531$(target)_2_OUTPUT := $(TOOL_$(tool)_LINK_LIBRARY_OUTPUT)
2532$(target)_2_OUTPUT_MAYBE := $(TOOL_$(tool)_LINK_LIBRARY_OUTPUT_MAYBE)
2533$(target)_2_DEPEND := $(TOOL_$(tool)_LINK_LIBRARY_DEPEND) $(deps) $($(target)_OBJS_)
2534$(target)_2_DEPORD := $(TOOL_$(tool)_LINK_LIBRARY_DEPORD) $(dirdep) $(orderdeps)
[380]2535
[412]2536# generate the link rule.
[380]2537$(eval $(def_link_rule))
2538
[353]2539# installing and globals
[1496]2540$(evalval def_target_install_pluss)
[72]2541endef
[1936]2542$(eval-opt-var def_lib)
[72]2543
2544# Process libraries
[859]2545definst := $(PATH_LIB)
2546typevar := _LIBS
[776]2547tool_do := LINK_LIBRARY
[380]2548mode := 0644
[1648]2549$(foreach target, $(_ALL_LIBRARIES), $(evalval def_lib))
[72]2550
[988]2551ifdef KBUILD_PROFILE_SELF
[2008]2552 $(evalcall def_profile_self, done library targets)
[988]2553endif
[72]2554
[988]2555
[72]2556#
[353]2557# Link operations.
[72]2558#
2559
[353]2560##
2561# Link prolog
2562#
2563# @param $(target) Normalized target name.
2564# @param $(EXT) EXE,DLL,SYS.
2565# @param $(definst) The default _INST value.
2566# @param $(typevar) The name of the variable with all the root targets of its type.
[380]2567define def_link_common
[353]2568# basics
[1504]2569local bld_type := $(firstword $($(target)_BLD_TYPE) $(KBUILD_TYPE))
[1496]2570local bld_trg := $(firstword $($(target)_BLD_TRG) $(BUILD_$(bld_trg_base_var)))
2571local bld_trg_arch:= $(firstword $($(target)_BLD_TRG_ARCH) $(BUILD_$(bld_trg_base_var)_ARCH))
2572local bld_trg_cpu := $(firstword $($(target)_BLD_TRG_CPU) $(BUILD_$(bld_trg_base_var)_CPU))
[145]2573
[1496]2574local tool := $(call _TARGET_TOOL,$(target),LD)
2575local name := $(firstword\
[889]2576 $($(target)_NAME.$(bld_trg).$(bld_trg_arch))\
2577 $($(target)_NAME.$(bld_trg_arch))\
2578 $($(target)_NAME.$(bld_trg))\
2579 $($(target)_NAME.$(bld_type))\
2580 $($(target)_NAME)\
2581 $(target))
[1496]2582local outbase := $(call TARGET_BASE,$(name),$(target))
[743]2583ifndef PATH_$(target)
[1496]2584 PATH_$(target) := $(patsubst %/,%,$(dir $(outbase)))
[1672]2585else ifneq ($(PATH_$(target)),$(patsubst %/,%,$(dir $(outbase))))
2586 $(error kBuild internal error: PATH_$(target)=$(PATH_$(target)) expected $(patsubst %/,%,$(dir $(outbase))))
[743]2587endif
[2143]2588local suff := $(firstword \
2589 $($(target)_$(EXT)SUFF.$(bld_trg).$(bld_trg_arch))\
2590 $($(target)_$(EXT)SUFF.$(bld_trg))\
2591 $($(target)_$(EXT)SUFF)\
2592 $(TOOL_$(tool)_LD$(EXT)SUFF.$(bld_trg).$(bld_trg_arch))\
2593 $(TOOL_$(tool)_LD$(EXT)SUFF.$(bld_trg))\
2594 $(TOOL_$(tool)_LD$(EXT)SUFF)\
2595 $($(EXTPRE)SUFF_$(EXT)) )
[1496]2596local out := $(outbase)$(suff)
2597TARGET_$(target) := $(out)
[1755]2598local defpath := $(firstword $($(target)_PATH) $($(target)_DEFPATH))
[1496]2599# no local here - must be writable across some foreachs.
2600othersrc :=
2601$(target)_OBJS_ :=
[353]2602
[1672]2603# Do units pre source callouts.
2604local units := \
2605 $($(target)_USES.$(bld_trg).$(bld_trg_arch))\
2606 $($(target)_USES.$(bld_trg_arch))\
2607 $($(target)_USES.$(bld_trg))\
2608 $($(target)_USES.$(bld_type))\
2609 $($(target)_USES)
2610$(foreach unit,$(units),$(evalval def_unit_$(unit)_target_pre))
2611
[145]2612# source -> object
[1496]2613$(evalval def_target_sources)
[145]2614
[744]2615# more link stuff.
[1496]2616local tool := $(call _TARGET_TOOL,$(target),LD)
2617local name := $(firstword\
[889]2618 $($(target)_NAME.$(bld_trg).$(bld_trg_arch))\
2619 $($(target)_NAME.$(bld_trg_arch))\
2620 $($(target)_NAME.$(bld_trg))\
2621 $($(target)_NAME.$(bld_type))\
2622 $($(target)_NAME)\
2623 $(target))
[1496]2624local outbase := $(call TARGET_BASE,$(name),$(target))
2625local flags :=\
[74]2626 $(TOOL_$(tool)_LDFLAGS)\
[221]2627 $(TOOL_$(tool)_LDFLAGS.$(bld_type))\
2628 $(TOOL_$(tool)_LDFLAGS.$(bld_trg))\
2629 $(TOOL_$(tool)_LDFLAGS.$(bld_trg_arch))\
[481]2630 $(TOOL_$(tool)_LDFLAGS.$(bld_trg).$(bld_trg_arch))\
[221]2631 $(TOOL_$(tool)_LDFLAGS.$(bld_trg_cpu))\
[1242]2632 $(foreach sdk, $(SDKS) \
2633 $(SDKS.$(bld_type)) \
2634 $(SDKS.$(bld_trg)) \
2635 $(SDKS.$(bld_trg_arch)) \
2636 $(SDKS.$(bld_trg).$(bld_trg_arch)),\
2637 $(SDK_$(sdk)_LDFLAGS)\
2638 $(SDK_$(sdk)_LDFLAGS.$(bld_type))\
2639 $(SDK_$(sdk)_LDFLAGS.$(bld_trg))\
2640 $(SDK_$(sdk)_LDFLAGS.$(bld_trg_arch))\
2641 $(SDK_$(sdk)_LDFLAGS.$(bld_trg).$(bld_trg_arch))\
2642 $(SDK_$(sdk)_LDFLAGS.$(bld_trg_cpu)))\
[74]2643 $(LDFLAGS)\
[221]2644 $(LDFLAGS.$(bld_type))\
2645 $(LDFLAGS.$(bld_trg))\
2646 $(LDFLAGS.$(bld_trg_arch))\
[481]2647 $(LDFLAGS.$(bld_trg).$(bld_trg_arch))\
[221]2648 $(LDFLAGS.$(bld_trg_cpu))\
[1242]2649 $(foreach sdk, $($(target)_SDKS) \
2650 $($(target)_SDKS.$(bld_type)) \
2651 $($(target)_SDKS.$(bld_trg)) \
2652 $($(target)_SDKS.$(bld_trg_arch)) \
2653 $($(target)_SDKS.$(bld_trg).$(bld_trg_arch)),\
2654 $(SDK_$(sdk)_LDFLAGS)\
2655 $(SDK_$(sdk)_LDFLAGS.$(bld_type))\
2656 $(SDK_$(sdk)_LDFLAGS.$(bld_trg))\
2657 $(SDK_$(sdk)_LDFLAGS.$(bld_trg_arch))\
2658 $(SDK_$(sdk)_LDFLAGS.$(bld_trg).$(bld_trg_arch))\
2659 $(SDK_$(sdk)_LDFLAGS.$(bld_trg_cpu)))\
[74]2660 $($(target)_LDFLAGS)\
[221]2661 $($(target)_LDFLAGS.$(bld_type))\
2662 $($(target)_LDFLAGS.$(bld_trg))\
2663 $($(target)_LDFLAGS.$(bld_trg_arch))\
[481]2664 $($(target)_LDFLAGS.$(bld_trg).$(bld_trg_arch))\
[353]2665 $($(target)_LDFLAGS.$(bld_trg_cpu))
[1496]2666local libs :=\
[221]2667 $($(target)_LIBS.$(bld_trg_cpu))\
[481]2668 $($(target)_LIBS.$(bld_trg).$(bld_trg_arch))\
[221]2669 $($(target)_LIBS.$(bld_trg_arch))\
2670 $($(target)_LIBS.$(bld_trg))\
2671 $($(target)_LIBS.$(bld_type))\
[74]2672 $($(target)_LIBS)\
[592]2673 $(foreach sdk, $($(target)_SDKS.$(bld_trg).$(bld_trg_arch)) \
2674 $($(target)_SDKS.$(bld_trg_arch)) \
2675 $($(target)_SDKS.$(bld_trg)) \
2676 $($(target)_SDKS.$(bld_type)) \
2677 $($(target)_SDKS),\
[353]2678 $(SDK_$(sdk)_LIBS.$(bld_trg_cpu))\
[481]2679 $(SDK_$(sdk)_LIBS.$(bld_trg).$(bld_trg_arch))\
[353]2680 $(SDK_$(sdk)_LIBS.$(bld_trg_arch))\
2681 $(SDK_$(sdk)_LIBS.$(bld_trg))\
2682 $(SDK_$(sdk)_LIBS.$(bld_type))\
2683 $(SDK_$(sdk)_LIBS))\
[221]2684 $(LIBS.$(bld_trg_cpu))\
[481]2685 $(LIBS.$(bld_trg).$(bld_trg_arch))\
[221]2686 $(LIBS.$(bld_trg_arch))\
2687 $(LIBS.$(bld_trg))\
2688 $(LIBS.$(bld_type))\
[74]2689 $(LIBS)\
[592]2690 $(foreach sdk, $(SDKS.$(bld_trg).$(bld_trg_arch)) \
2691 $(SDKS.$(bld_trg_arch)) \
2692 $(SDKS.$(bld_trg)) \
2693 $(SDKS.$(bld_type)) \
2694 $(SDKS),\
[353]2695 $(SDK_$(sdk)_LIBS.$(bld_trg_cpu))\
[481]2696 $(SDK_$(sdk)_LIBS.$(bld_trg).$(bld_trg_arch))\
[353]2697 $(SDK_$(sdk)_LIBS.$(bld_trg_arch))\
2698 $(SDK_$(sdk)_LIBS.$(bld_trg))\
2699 $(SDK_$(sdk)_LIBS.$(bld_type))\
2700 $(SDK_$(sdk)_LIBS))\
[221]2701 $(TOOL_$(tool)_LIBS.$(bld_trg_cpu))\
[481]2702 $(TOOL_$(tool)_LIBS.$(bld_trg).$(bld_trg_arch))\
[221]2703 $(TOOL_$(tool)_LIBS.$(bld_trg_arch))\
2704 $(TOOL_$(tool)_LIBS.$(bld_trg))\
2705 $(TOOL_$(tool)_LIBS.$(bld_type))\
[353]2706 $(TOOL_$(tool)_LIBS)
[1496]2707local libpath :=\
[221]2708 $($(target)_LIBPATH.$(bld_trg_cpu))\
[481]2709 $($(target)_LIBPATH.$(bld_trg).$(bld_trg_arch))\
[221]2710 $($(target)_LIBPATH.$(bld_trg_arch))\
2711 $($(target)_LIBPATH.$(bld_trg))\
2712 $($(target)_LIBPATH.$(bld_type))\
[74]2713 $($(target)_LIBPATH)\
[592]2714 $(foreach sdk, $($(target)_SDKS.$(bld_trg).$(bld_trg_arch)) \
2715 $($(target)_SDKS.$(bld_trg_arch)) \
2716 $($(target)_SDKS.$(bld_trg)) \
2717 $($(target)_SDKS.$(bld_type)) \
2718 $($(target)_SDKS),\
[353]2719 $(SDK_$(sdk)_LIBPATH.$(bld_trg_cpu))\
[481]2720 $(SDK_$(sdk)_LIBPATH.$(bld_trg).$(bld_trg_arch))\
[353]2721 $(SDK_$(sdk)_LIBPATH.$(bld_trg_arch))\
2722 $(SDK_$(sdk)_LIBPATH.$(bld_trg))\
2723 $(SDK_$(sdk)_LIBPATH.$(bld_type))\
2724 $(SDK_$(sdk)_LIBPATH))\
[221]2725 $(LIBPATH.$(bld_trg_cpu))\
[481]2726 $(LIBPATH.$(bld_trg).$(bld_trg_arch))\
[221]2727 $(LIBPATH.$(bld_trg_arch))\
2728 $(LIBPATH.$(bld_trg))\
2729 $(LIBPATH.$(bld_type))\
[74]2730 $(LIBPATH)\
[592]2731 $(foreach sdk, $(SDKS.$(bld_trg).$(bld_trg_arch)) \
2732 $(SDKS.$(bld_trg_arch)) \
2733 $(SDKS.$(bld_trg)) \
2734 $(SDKS.$(bld_type)) \
2735 $(SDKS),\
[353]2736 $(SDK_$(sdk)_LIBPATH.$(bld_trg_cpu))\
[481]2737 $(SDK_$(sdk)_LIBPATH.$(bld_trg).$(bld_trg_arch))\
[353]2738 $(SDK_$(sdk)_LIBPATH.$(bld_trg_arch))\
2739 $(SDK_$(sdk)_LIBPATH.$(bld_trg))\
2740 $(SDK_$(sdk)_LIBPATH.$(bld_type))\
2741 $(SDK_$(sdk)_LIBPATH))\
[221]2742 $(TOOL_$(tool)_LIBPATH.$(bld_trg_cpu))\
[481]2743 $(TOOL_$(tool)_LIBPATH.$(bld_trg).$(bld_trg_arch))\
[221]2744 $(TOOL_$(tool)_LIBPATH.$(bld_trg_arch))\
2745 $(TOOL_$(tool)_LIBPATH.$(bld_trg))\
2746 $(TOOL_$(tool)_LIBPATH.$(bld_type))\
[353]2747 $(TOOL_$(tool)_LIBPATH)
[1496]2748local dirdep := $(call DIRDEP,$(dir $(out)))
[1702]2749local deps := \
2750 $($(target)_DEPS.$(bld_trg_cpu)) \
2751 $($(target)_DEPS.$(bld_trg).$(bld_trg_arch).$(bld_type)) \
2752 $($(target)_DEPS.$(bld_trg).$(bld_trg_arch)) \
2753 $($(target)_DEPS.$(bld_trg).$(bld_type)) \
2754 $($(target)_DEPS.$(bld_trg_arch)) \
2755 $($(target)_DEPS.$(bld_trg)) \
2756 $($(target)_DEPS.$(bld_type)) \
2757 $($(target)_DEPS) \
2758 $($(target)_LNK_DEPS.$(bld_trg_cpu)) \
2759 $($(target)_LNK_DEPS.$(bld_trg).$(bld_trg_arch).$(bld_type)) \
2760 $($(target)_LNK_DEPS.$(bld_trg).$(bld_trg_arch)) \
2761 $($(target)_LNK_DEPS.$(bld_trg).$(bld_type)) \
2762 $($(target)_LNK_DEPS.$(bld_trg_arch)) \
2763 $($(target)_LNK_DEPS.$(bld_trg)) \
2764 $($(target)_LNK_DEPS.$(bld_type)) \
2765 $($(target)_LNK_DEPS)
2766local orderdeps := \
2767 $($(target)_ORDERDEPS.$(bld_trg_cpu)) \
2768 $($(target)_ORDERDEPS.$(bld_trg).$(bld_trg_arch).$(bld_type)) \
2769 $($(target)_ORDERDEPS.$(bld_trg).$(bld_trg_arch)) \
2770 $($(target)_ORDERDEPS.$(bld_trg).$(bld_type)) \
2771 $($(target)_ORDERDEPS.$(bld_trg_arch)) \
2772 $($(target)_ORDERDEPS.$(bld_trg)) \
2773 $($(target)_ORDERDEPS.$(bld_type)) \
2774 $($(target)_ORDERDEPS) \
2775 $($(target)_LNK_ORDERDEPS.$(bld_trg_cpu)) \
2776 $($(target)_LNK_ORDERDEPS.$(bld_trg).$(bld_trg_arch).$(bld_type)) \
2777 $($(target)_LNK_ORDERDEPS.$(bld_trg).$(bld_trg_arch)) \
2778 $($(target)_LNK_ORDERDEPS.$(bld_trg).$(bld_type)) \
2779 $($(target)_LNK_ORDERDEPS.$(bld_trg_arch)) \
2780 $($(target)_LNK_ORDERDEPS.$(bld_trg)) \
2781 $($(target)_LNK_ORDERDEPS.$(bld_type)) \
2782 $($(target)_LNK_ORDERDEPS)
[353]2783
[725]2784# Adjust paths if we got a default path.
2785ifneq ($(defpath),)
[1496]2786 local libpath := $(abspathex $(libpath),$(defpath))
2787 $(target)_OBJS_ := $(abspathex $($(target)_OBJS_),$(defpath))
2788 local deps := $(abspathex $(deps),$(defpath))
2789 local orderdeps := $(abspathex $(orderdeps),$(defpath))
[1472]2790 othersrc := $(abspathex $(othersrc),$(defpath))
[1755]2791 # libs are not subject to this because of the the -l<lib> stuff. Use $(<target>_DEFPATH)/lib if relative to current dir!
[725]2792endif
2793
[859]2794# Custom pre-link actions.
2795ifdef $(target)_PRE_CMDS.$(bld_trg).$(bld_trg_arch).$(bld_type)
[1496]2796 local pre_cmds := $($(target)_PRE_CMDS.$(bld_trg).$(bld_trg_arch).$(bld_type))
[859]2797else ifdef $(target)_PRE_CMDS.$(bld_trg).$(bld_trg_arch)
[1496]2798 local pre_cmds := $($(target)_PRE_CMDS.$(bld_trg).$(bld_trg_arch))
[859]2799else ifdef $(target)_PRE_CMDS.$(bld_trg).$(bld_type)
[1496]2800 local pre_cmds := $($(target)_PRE_CMDS.$(bld_trg).$(bld_type))
[859]2801else ifdef $(target)_PRE_CMDS.$(bld_trg_arch)
[1496]2802 local pre_cmds := $($(target)_PRE_CMDS.$(bld_trg_arch))
[859]2803else ifdef $(target)_PRE_CMDS.$(bld_trg)
[1496]2804 local pre_cmds := $($(target)_PRE_CMDS.$(bld_trg))
[859]2805else ifdef $(target)_PRE_CMDS.$(bld_type)
[1496]2806 local pre_cmds := $($(target)_PRE_CMDS.$(bld_type))
[859]2807else ifdef $(target)_PRE_CMDS
[1496]2808 local pre_cmds := $($(target)_PRE_CMDS)
[859]2809else ifdef PRE_CMDS.$(bld_trg).$(bld_trg_arch).$(bld_type)
[1496]2810 local pre_cmds := $(PRE_CMDS.$(bld_trg).$(bld_trg_arch).$(bld_type))
[859]2811else ifdef PRE_CMDS.$(bld_trg).$(bld_trg_arch)
[1496]2812 local pre_cmds := $(PRE_CMDS.$(bld_trg).$(bld_trg_arch))
[859]2813else ifdef PRE_CMDS.$(bld_trg).$(bld_type)
[1496]2814 local pre_cmds := $(PRE_CMDS.$(bld_trg).$(bld_type))
[859]2815else ifdef PRE_CMDS.$(bld_trg_arch)
[1496]2816 local pre_cmds := $(PRE_CMDS.$(bld_trg_arch))
[859]2817else ifdef PRE_CMDS.$(bld_trg)
[1496]2818 local pre_cmds := $(PRE_CMDS.$(bld_trg))
[859]2819else ifdef PRE_CMDS.$(bld_type)
[1496]2820 local pre_cmds := $(PRE_CMDS.$(bld_type))
[859]2821else
[1496]2822 local pre_cmds := $(PRE_CMDS)
[859]2823endif
[72]2824
[859]2825# Custom post-link actions.
2826ifdef $(target)_POST_CMDS.$(bld_trg).$(bld_trg_arch).$(bld_type)
[1496]2827 local post_cmds := $($(target)_POST_CMDS.$(bld_trg).$(bld_trg_arch).$(bld_type))
[859]2828else ifdef $(target)_POST_CMDS.$(bld_trg).$(bld_trg_arch)
[1496]2829 local post_cmds := $($(target)_POST_CMDS.$(bld_trg).$(bld_trg_arch))
[859]2830else ifdef $(target)_POST_CMDS.$(bld_trg).$(bld_type)
[1496]2831 local post_cmds := $($(target)_POST_CMDS.$(bld_trg).$(bld_type))
[859]2832else ifdef $(target)_POST_CMDS.$(bld_trg_arch)
[1496]2833 local post_cmds := $($(target)_POST_CMDS.$(bld_trg_arch))
[859]2834else ifdef $(target)_POST_CMDS.$(bld_trg)
[1496]2835 local post_cmds := $($(target)_POST_CMDS.$(bld_trg))
[859]2836else ifdef $(target)_POST_CMDS.$(bld_type)
[1496]2837 local post_cmds := $($(target)_POST_CMDS.$(bld_type))
[859]2838else ifdef $(target)_POST_CMDS
[1496]2839 local post_cmds := $($(target)_POST_CMDS)
[859]2840else ifdef POST_CMDS.$(bld_trg).$(bld_trg_arch).$(bld_type)
[1496]2841 local post_cmds := $(POST_CMDS.$(bld_trg).$(bld_trg_arch).$(bld_type))
[859]2842else ifdef POST_CMDS.$(bld_trg).$(bld_trg_arch)
[1496]2843 local post_cmds := $(POST_CMDS.$(bld_trg).$(bld_trg_arch))
[859]2844else ifdef POST_CMDS.$(bld_trg).$(bld_type)
[1496]2845 local post_cmds := $(POST_CMDS.$(bld_trg).$(bld_type))
[859]2846else ifdef POST_CMDS.$(bld_trg_arch)
[1496]2847 local post_cmds := $(POST_CMDS.$(bld_trg_arch))
[859]2848else ifdef POST_CMDS.$(bld_trg)
[1496]2849 local post_cmds := $(POST_CMDS.$(bld_trg))
[859]2850else ifdef POST_CMDS.$(bld_type)
[1496]2851 local post_cmds := $(POST_CMDS.$(bld_type))
[859]2852else
[1496]2853 local post_cmds := $(POST_CMDS)
[859]2854endif
2855
[1424]2856# eliminate this guy?
[1496]2857local objs = $($(target)_OBJS_)
[1424]2858
[353]2859# installation targets
[1697]2860ifeq ($(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))),)
2861 ifneq ($(strip $($(target)_INST.$(bld_trg).$(bld_trg_arch).$(bld_type))),)
2862 local inst := $(addprefix $(PATH_INS)/,$($(target)_INST.$(bld_trg).$(bld_trg_arch).$(bld_type)))
2863 else ifneq ($(strip $($(target)_INST.$(bld_trg).$(bld_trg_arch))),)
2864 local inst := $(addprefix $(PATH_INS)/,$($(target)_INST.$(bld_trg).$(bld_trg_arch)))
2865 else ifneq ($(strip $($(target)_INST.$(bld_trg).$(bld_type))),)
2866 local inst := $(addprefix $(PATH_INS)/,$($(target)_INST.$(bld_trg).$(bld_type)))
2867 else ifneq ($(strip $($(target)_INST.$(bld_trg_arch))),)
2868 local inst := $(addprefix $(PATH_INS)/,$($(target)_INST.$(bld_trg_arch)))
2869 else ifneq ($(strip $($(target)_INST.$(bld_trg))),)
2870 local inst := $(addprefix $(PATH_INS)/,$($(target)_INST.$(bld_trg)))
2871 else ifneq ($(strip $($(target)_INST.$(bld_type))),)
2872 local inst := $(addprefix $(PATH_INS)/,$($(target)_INST.$(bld_type)))
2873 else ifneq ($(strip $($(target)_INST)),)
2874 local inst := $(addprefix $(PATH_INS)/,$($(target)_INST))
2875 else
2876 local inst := $(definst)/
2877 endif
2878 INSTARGET_$(target) := $(patsubst %/,%/$(notdir $(out)),$(inst))
2879 ifdef KBUILD_DO_AUTO_INSTALL
2880 $(typevar) += $(INSTARGET_$(target))
2881 else
2882 $(typevar) += $(out)
2883 endif
[2225]2884 local mode := $(firstword \
2885 $($(target)_MODE.$(bld_trg).$(bld_trg_arch).$(bld_type)) \
2886 $($(target)_MODE.$(bld_trg).$(bld_trg_arch)) \
2887 $($(target)_MODE.$(bld_trg).$(bld_type)) \
2888 $($(target)_MODE.$(bld_trg_arch)) \
2889 $($(target)_MODE.$(bld_trg)) \
2890 $($(target)_MODE.$(bld_type)) \
2891 $($(target)_MODE) )
2892 local uid := $(firstword \
2893 $($(target)_UID.$(bld_trg).$(bld_trg_arch).$(bld_type)) \
2894 $($(target)_UID.$(bld_trg).$(bld_trg_arch)) \
2895 $($(target)_UID.$(bld_trg).$(bld_type)) \
2896 $($(target)_UID.$(bld_trg_arch)) \
2897 $($(target)_UID.$(bld_trg)) \
2898 $($(target)_UID.$(bld_type)) \
2899 $($(target)_UID) )
2900 local gid := $(firstword \
2901 $($(target)_GID.$(bld_trg).$(bld_trg_arch).$(bld_type)) \
2902 $($(target)_GID.$(bld_trg).$(bld_trg_arch)) \
2903 $($(target)_GID.$(bld_trg).$(bld_type)) \
2904 $($(target)_GID.$(bld_trg_arch)) \
2905 $($(target)_GID.$(bld_trg)) \
2906 $($(target)_GID.$(bld_type)) \
2907 $($(target)_GID) )
2908
[1697]2909 # generate the install rule
[353]2910$(eval $(def_link_install_rule))
2911
2912else # NOINST
[1697]2913 INSTARGET_$(target) :=
2914 $(typevar) += $(out)
[353]2915endif # NOINST
2916
[380]2917# dependency file
[1496]2918local dep := $(outbase)$(SUFF_DEP)
[524]2919ifndef NO_LINK_CMDS_DEPS
[2188]2920 _DEPFILES_INCLUDED += $(dep)
[1798]2921 ifdef KB_HAVE_INCLUDEDEP_QUEUE
2922 includedep-queue $(dep)
[1795]2923 else
[1798]2924 includedep $(dep)
[1795]2925 endif
[380]2926endif
[353]2927
[380]2928# check that the tool is defined.
2929ifndef TOOL_$(tool)_$(tool_do)_CMDS
2930$(warning kBuild: tools: \
[481]2931 1 $($(target)_$(source)TOOL.$(bld_trg).$(bld_trg_arch)) \
2932 2 $($(target)_$(source)TOOL.$(bld_trg)) \
2933 3 $($(target)_$(source)TOOL) \
2934 4 $($(target)_TOOL.$(bld_trg).$(bld_trg_arch)) \
2935 5 $($(target)_TOOL.$(bld_trg)) \
2936 6 $($(target)_TOOL) \
2937 7 $($(source)TOOL.$(bld_trg).$(bld_trg_arch)) \
2938 8 $($(source)TOOL.$(bld_trg)) \
2939 9 $($(source)TOOL) \
2940 10 $(TOOL.$(bld_trg).$(bld_trg_arch)) \
2941 11 $(TOOL.$(bld_trg)) \
2942 12 $(TOOL) )
[380]2943$(error kBuild: TOOL_$(tool)_$(tool_do)_CMDS isn't defined! target=$(target) )
2944endif
[353]2945
[380]2946# call the tool
[1496]2947local cmds := $(TOOL_$(tool)_$(tool_do)_CMDS)
[859]2948ifneq ($(pre_cmds),)
[1496]2949 local cmds := $(TAB)$(pre_cmds)$(NL)$(TAB)$(cmds)
[859]2950endif
2951ifneq ($(post_cmds),)
[1496]2952 local cmds := $(cmds)$(NL)$(TAB)$(post_cmds)
[859]2953endif
[2234]2954$(target)_2_OUTPUT := $(TOOL_$(tool)_$(tool_do)_OUTPUT)
2955$(target)_2_OUTPUT_MAYBE := $(TOOL_$(tool)_$(tool_do)_OUTPUT_MAYBE)
2956$(target)_2_DEPEND := $(TOOL_$(tool)_$(tool_do)_DEPEND) $(deps) $($(target)_OBJS_)
2957$(target)_2_DEPORD := $(TOOL_$(tool)_$(tool_do)_DEPORD) $(dirdep) $(orderdeps)
[353]2958
[412]2959# generate the link rule.
[380]2960$(eval $(def_link_rule))
2961
[412]2962
[380]2963# Update globals.
[579]2964_OBJS += $($(target)_OBJS_)
[2234]2965_OUT_FILES += $($(target)_2_OUTPUT) $($(target)_2_OUTPUT_MAYBE) $(out)
[905]2966_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))
2967_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]2968_INSTALLS_FILES += $(INSTARGET_$(target))
[353]2969
[1936]2970endef # def_link_common
2971$(eval-opt-var def_link_common)
[353]2972
2973
2974#
2975# BLDPROGS
2976#
2977
2978## Build program (one).
2979# @param $(target) Normalized target (program) name.
2980define def_bldprog
2981
2982# set NOINST if not forced installation.
2983ifndef $(target)_INST
2984$(target)_NOINST := 1
2985endif
2986
[380]2987# do the usual stuff.
[1496]2988$(evalval def_link_common)
[353]2989
2990endef
2991
2992# Process build programs.
2993EXT := EXE
2994EXTPRE := HOST
[380]2995tool_do := LINK_PROGRAM
[353]2996definst := $(PATH_BIN)
2997typevar := _BLDPROGS
[380]2998mode := 0755
[353]2999bld_trg_base_var := PLATFORM
[1648]3000$(foreach target, $(_ALL_BLDPROGS), $(evalval def_bldprog))
[353]3001
[988]3002ifdef KBUILD_PROFILE_SELF
[2008]3003 $(evalcall def_profile_self, done build program targets)
[988]3004endif
[353]3005
3006
3007#
3008# DLLS
3009#
3010
[189]3011# Process dlls
[353]3012EXT := DLL
3013EXTPRE :=
[380]3014tool_do := LINK_DLL
[353]3015definst := $(PATH_DLL)
3016typevar := _DLLS
[830]3017mode := 0644
[353]3018bld_trg_base_var := TARGET
[1648]3019$(foreach target, $(_ALL_DLLS), $(evalval def_link_common))
[74]3020
[988]3021ifdef KBUILD_PROFILE_SELF
[2008]3022 $(evalcall def_profile_self, done dll targets)
[988]3023endif
[74]3024
[988]3025
[72]3026#
[830]3027# IMPORT LIBRARIES
[72]3028#
[219]3029# - On OS/2 and windows these are libraries.
[189]3030# - On other platforms they are fake DLLs.
[830]3031#
3032EXTPRE :=
3033typevar := _IMPORT_LIBS
3034mode := 0644
3035bld_trg_base_var := TARGET
[1504]3036ifeq ($(filter-out nt os2 win win64 win32,$(KBUILD_TARGET)),)
[830]3037 EXT := LIB
3038 tool_do := LINK_LIBRARY
3039 definst := $(PATH_LIB)
[1648]3040 $(foreach target, $(_ALL_IMPORT_LIBS), $(evalval def_lib))
[189]3041else
[830]3042 EXT := DLL
3043 tool_do := LINK_DLL
3044 definst := $(PATH_DLL)
[1648]3045 $(foreach target, $(_ALL_IMPORT_LIBS), $(evalval def_link_common))
[189]3046endif
[72]3047
[988]3048ifdef KBUILD_PROFILE_SELF
[2008]3049 $(evalcall def_profile_self, done import library targets)
[988]3050endif
[189]3051
[988]3052
[189]3053#
3054# PROGRAMS
3055#
3056
[353]3057# Process programs
3058EXT := EXE
3059EXTPRE :=
[380]3060tool_do := LINK_PROGRAM
[353]3061definst := $(PATH_BIN)
3062typevar := _PROGRAMS
[380]3063mode := 0755
[353]3064bld_trg_base_var := TARGET
[1648]3065$(foreach target, $(_ALL_PROGRAMS), $(evalval def_link_common))
[130]3066
[988]3067ifdef KBUILD_PROFILE_SELF
[2008]3068 $(evalcall def_profile_self, done program targets)
[988]3069endif
[130]3070
[189]3071
[72]3072#
[83]3073# SYSMODS
[72]3074#
3075
[130]3076# Process sysmods
[353]3077EXT := SYS
3078EXTPRE :=
[380]3079tool_do := LINK_SYSMOD
[353]3080definst := $(PATH_SYS)
3081typevar := _SYSMODS
[380]3082mode := 0644
[353]3083bld_trg_base_var := TARGET
[1648]3084$(foreach target, $(_ALL_SYSMODS), $(evalval def_link_common))
[83]3085
[988]3086ifdef KBUILD_PROFILE_SELF
[2008]3087 $(evalcall def_profile_self, done sysmod targets)
[988]3088endif
[83]3089
[988]3090
[72]3091#
[2084]3092# MISCBINS
3093#
3094
3095# Process MISCBINS
3096EXT := BIN
3097EXTPRE :=
3098tool_do := LINK_MISCBIN
3099definst := $(PATH_BIN)
3100typevar := _MISCBINS
3101mode := 0644
3102bld_trg_base_var := TARGET
3103$(foreach target, $(_ALL_MISCBINS), $(evalval def_link_common))
3104
3105ifdef KBUILD_PROFILE_SELF
3106 $(evalcall def_profile_self, done misc binary targets)
3107endif
3108
3109
3110#
[72]3111# OTHERS
3112#
[1504]3113_OTHERS = $(OTHERS) $(OTHERS.$(KBUILD_TARGET)) $(OTHERS.$(KBUILD_TARGET).$(KBUILD_TARGET_ARCH))
[72]3114
3115
[353]3116#
3117# INSTALLS
3118#
[72]3119
[353]3120## generate the install rule
3121define def_install_src_rule
3122# the install rule
3123$(insdst) : $(srcsrc) | $(call DIRDEP,$(dir $(insdst)))
[1496]3124 %$$(call MSG_INST_FILE,$(srcsrc),$(insdst))
[696]3125 $$(QUIET)$(inscmd)
[353]3126endef
[1936]3127$(eval-opt-var def_install_src_rule)
[353]3128
3129## install one file
3130define def_install_src
3131
3132# deal with '=>' in the source file name.
[2220]3133ifeq ($(src),=>)
3134 $(error kBuild: Install target '$(target)' has a bad source specifier containing '=>' without any file names)
3135endif
3136ifeq ($(substr $(src),1,2),=>)
3137 $(warning kBuild: Install target '$(target)' has a bad source specifier: $(src))
3138endif
3139ifeq ($(substr $(src),-2),=>)
3140 $(warning kBuild: Install target '$(target)' has a bad source specifier: $(src))
3141endif
[1496]3142local srcdst := $(subst =>, ,$(src))
3143local srcsrc := $(firstword $(srcdst))
3144local srcdstdir := $(dir $(word 2,$(srcdst)))
3145local srcdst := $(word $(words $(srcdst)),$(srcdst))
[353]3146
3147# _INSTFUN
3148ifdef $(srcsrc)_INSTFUN
[1496]3149 local instfun := $(srcsrc)_INSTFUN
[1347]3150else ifdef $(target)_INSTFUN
[1496]3151 local instfun := $(target)_INSTFUN
[353]3152else
[1496]3153 local instfun := _INSTALL_FILE
[353]3154endif
3155
3156# _INST
3157ifdef $(srcsrc)_INST
[1496]3158 local inst := $(patsubst %/,%,$($(srcsrc)_INST))/$(dir $(srcdstdir))
[1347]3159else ifdef $(target)_INST
[1496]3160 local inst := $(patsubst %/,%,$($(target)_INST))/$(dir $(srcdstdir))
[353]3161else
[1496]3162 local inst := $(dir $(srcdstdir))
[353]3163endif
3164
3165# calc target
[1496]3166local insdst := $(call $(instfun),$(srcdst),$(target),$(inst),$(PATH_INS))
[424]3167#$(warning instfun=$(instfun) srcdst=$(srcdst) target=$(target) inst=$(inst) => insdst=$(insdst))
[353]3168
[414]3169# mode, uid and gid
[1496]3170local mode := $(firstword \
[481]3171 $($(target)_$(srcsrc)_MODE.$(bld_trg).$(bld_trg_arch)) \
[414]3172 $($(target)_$(srcsrc)_MODE.$(bld_trg)) \
3173 $($(target)_$(srcsrc)_MODE) \
[481]3174 $($(target)_$(srcdst)_MODE.$(bld_trg).$(bld_trg_arch)) \
[414]3175 $($(target)_$(srcdst)_MODE.$(bld_trg)) \
3176 $($(target)_$(srcdst)_MODE) \
[481]3177 $($(srcsrc)_MODE.$(bld_trg).$(bld_trg_arch)) \
[414]3178 $($(srcsrc)_MODE.$(bld_trg)) \
3179 $($(srcsrc)_MODE) \
[481]3180 $($(srcdst)_MODE.$(bld_trg).$(bld_trg_arch)) \
[414]3181 $($(srcdst)_MODE.$(bld_trg)) \
3182 $($(srcdst)_MODE) \
[481]3183 $($(target)_MODE.$(bld_trg).$(bld_trg_arch)) \
[414]3184 $($(target)_MODE.$(bld_trg)) \
3185 $($(target)_MODE))
[1496]3186local uid := $(firstword \
[481]3187 $($(target)_$(srcsrc)_UID.$(bld_trg).$(bld_trg_arch)) \
[414]3188 $($(target)_$(srcsrc)_UID.$(bld_trg)) \
3189 $($(target)_$(srcsrc)_UID) \
[481]3190 $($(target)_$(srcdst)_UID.$(bld_trg).$(bld_trg_arch)) \
[414]3191 $($(target)_$(srcdst)_UID.$(bld_trg)) \
3192 $($(target)_$(srcdst)_UID) \
[481]3193 $($(srcsrc)_UID.$(bld_trg).$(bld_trg_arch)) \
[414]3194 $($(srcsrc)_UID.$(bld_trg)) \
3195 $($(srcsrc)_UID) \
[481]3196 $($(srcdst)_UID.$(bld_trg).$(bld_trg_arch)) \
[414]3197 $($(srcdst)_UID.$(bld_trg)) \
3198 $($(srcdst)_UID) \
[481]3199 $($(target)_UID.$(bld_trg).$(bld_trg_arch)) \
[414]3200 $($(target)_UID.$(bld_trg)) \
3201 $($(target)_UID))
[1496]3202local gid := $(firstword \
[481]3203 $($(target)_$(srcsrc)_GID.$(bld_trg).$(bld_trg_arch)) \
[414]3204 $($(target)_$(srcsrc)_GID.$(bld_trg)) \
3205 $($(target)_$(srcsrc)_GID) \
[481]3206 $($(target)_$(srcdst)_GID.$(bld_trg).$(bld_trg_arch)) \
[414]3207 $($(target)_$(srcdst)_GID.$(bld_trg)) \
3208 $($(target)_$(srcdst)_GID) \
[481]3209 $($(srcsrc)_GID.$(bld_trg).$(bld_trg_arch)) \
[414]3210 $($(srcsrc)_GID.$(bld_trg)) \
3211 $($(srcsrc)_GID) \
[481]3212 $($(srcdst)_GID.$(bld_trg).$(bld_trg_arch)) \
[414]3213 $($(srcdst)_GID.$(bld_trg)) \
3214 $($(srcdst)_GID) \
[481]3215 $($(target)_GID.$(bld_trg).$(bld_trg_arch)) \
[414]3216 $($(target)_GID.$(bld_trg)) \
3217 $($(target)_GID))
[1496]3218local flags := \
[830]3219 $($(target)_IFFLAGS) \
3220 $($(target)_IFFLAGS.$(bld_trg)) \
3221 $($(target)_IFFLAGS.$(bld_trg).$(bld_trg_arch)) \
3222 $($(srcdst)_IFFLAGS) \
3223 $($(srcdst)_IFFLAGS.$(bld_trg)) \
3224 $($(srcdst)_IFFLAGS.$(bld_trg).$(bld_trg_arch)) \
3225 $($(srcsrc)_IFFLAGS) \
3226 $($(srcsrc)_IFFLAGS.$(bld_trg)) \
3227 $($(srcsrc)_IFFLAGS.$(bld_trg).$(bld_trg_arch)) \
3228 $($(target)_$(srcdst)_IFFLAGS) \
3229 $($(target)_$(srcdst)_IFFLAGS.$(bld_trg)) \
3230 $($(target)_$(srcdst)_IFFLAGS.$(bld_trg).$(bld_trg_arch)) \
3231 $($(target)_$(srcsrc)_IFFLAGS) \
3232 $($(target)_$(srcsrc)_IFFLAGS.$(bld_trg)) \
3233 $($(target)_$(srcsrc)_IFFLAGS.$(bld_trg).$(bld_trg_arch))
[1614]3234clean_files += \
3235 $($(srcdst)_CLEAN) \
3236 $($(srcdst)_CLEAN.$(bld_trg)) \
3237 $($(srcdst)_CLEAN.$(bld_trg).$(bld_trg_arch)) \
3238 $($(srcsrc)_CLEAN) \
3239 $($(srcsrc)_CLEAN.$(bld_trg)) \
3240 $($(srcsrc)_CLEAN.$(bld_trg).$(bld_trg_arch)) \
3241 $($(target)_$(srcdst)_CLEAN) \
3242 $($(target)_$(srcdst)_CLEAN.$(bld_trg)) \
3243 $($(target)_$(srcdst)_CLEAN.$(bld_trg).$(bld_trg_arch)) \
3244 $($(target)_$(srcsrc)_CLEAN) \
3245 $($(target)_$(srcsrc)_CLEAN.$(bld_trg)) \
3246 $($(target)_$(srcsrc)_CLEAN.$(bld_trg).$(bld_trg_arch))
[414]3247
[725]3248
3249# Adjust the source if we got a default PATH. (This must be done this late!)
[1755]3250local defpath := $(firstword $($(target)_PATH) $($(target)_DEFPATH))
3251ifneq ($(defpath),)
3252 local srcsrc := $(abspathex $(srcsrc),$(defpath))
[725]3253endif
3254
[353]3255# create the command
3256ifdef $(srcsrc)_INSTALLER
[1496]3257 local inscmd := $(call $(srcsrc)_INSTALLER,$(srcsrc),$(insdst),$(target),$(flags))
[830]3258else ifdef $(target)_INSTALLER
[1496]3259 local inscmd := $(call $(target)_INSTALLER,$(srcsrc),$(insdst),$(target),$(flags))
[353]3260else
[1496]3261 local inscmd := $$(INSTALL)\
[414]3262 $(if $(uid),-o $(uid))\
3263 $(if $(gid),-g $(gid))\
3264 $(if $(mode),-m $(mode))\
[1599]3265 $(flags) -- \
[414]3266 $(srcsrc) $(insdst)
[353]3267endif
3268
3269# generate the rule (need double evaluation here)
3270$(eval $(def_install_src_rule))
3271
3272INSTARGET_$(target) += $(insdst)
[1936]3273endef # def_install_src
3274$(eval-opt-var def_install_src)
[353]3275
3276
3277## generate the symlink rule
3278define def_install_symlink_rule
3279# the install rule
3280$(insdst) : | $(call DIRDEP,$(dir $(insdst)))
[1496]3281 %$$(call MSG_INST_SYM,$(insdst),$(symdst))
[1599]3282 $$(QUIET)$$(RM) -f -- $$@
[696]3283 $$(QUIET)$$(LN_SYMLINK) $(symdst) $(insdst)
[1936]3284endef # def_install_symlink_rule
3285$(eval-opt-var def_install_symlink_rule)
[353]3286
3287## create one symlink
3288define def_install_symlink
3289
3290# deal with '=>' in the source file name.
[1496]3291local symdst := $(subst =>, ,$(src))
3292local symlnk := $(firstword $(symdst))
3293local symdst := $(word $(words $(symdst)),$(symdst))
[353]3294
3295# _INSTFUN
[380]3296ifdef $(symlnk)_INSTFUN
[1496]3297 local instfun := $(symlnk)_INSTFUN
[827]3298else ifdef $(target)_INSTFUN
[1496]3299 local instfun := $(target)_INSTFUN
[353]3300else
[1496]3301 local instfun := _INSTALL_FILE
[353]3302endif
3303
3304# _INST
[380]3305ifdef $(symlnk)_INST
[1496]3306 local inst := $(patsubst %/,%,$($(symlnk)_INST))/$(dir $(symlnk))
[827]3307else ifdef $(target)_INST
[1496]3308 local inst := $(patsubst %/,%,$($(target)_INST))/$(dir $(symlnk))
[353]3309else
[1496]3310 local inst := $(dir $(symlnk))
[353]3311endif
3312
3313# calc target
[1496]3314local insdst := $(call $(instfun),$(symlnk),$(target),$(inst),$(PATH_INS))
[380]3315#$(warning symlnk=$(symlnk) symdst=$(symdst) insdst=$(insdst) instfun=$(instfun) inst='$(inst)')
[353]3316
3317# generate the rule (need double evaluation here)
3318$(eval $(def_install_symlink_rule))
3319
3320INSTARGET_$(target) += $(insdst)
[1936]3321endef # def_install_symlink
3322$(optmize def_install_symlink)
[353]3323
[412]3324
[380]3325## generate the install rule
3326define def_install_directory_rule
3327# the install rule
3328$(insdst):
[1496]3329 %$$(call MSG_INST_DIR,$(insdst))
[696]3330 $$(QUIET)$$(INSTALL) -d \
[380]3331 $(if $(uid),-o $(uid))\
3332 $(if $(gid),-g $(gid))\
3333 $(if $(mode),-m $(mode))\
[1599]3334 $(flags) -- \
[380]3335 $(insdst)
[412]3336
3337.NOTPARALLEL: $(insdst)
[1936]3338endef # def_install_directory_rule
3339$(eval-opt-var def_install_directory_rule)
[380]3340
[412]3341
[380]3342## create one directory
3343define def_install_directory
3344
3345# _INST
3346ifdef $(directory)_INST
[1496]3347 local inst := $(PATH_INS)/$(patsubst %/,%,$($(directory)_INST))
[827]3348else ifdef $(target)_INST
[1496]3349 local inst := $(PATH_INS)/$(patsubst %/,%,$($(target)_INST))
[380]3350else
[1496]3351 local inst := $(PATH_INS)
[380]3352endif
3353
[1496]3354local mode := $(firstword \
[481]3355 $($(target)_$(directory)_MODE.$(bld_trg).$(bld_trg_arch)) \
[380]3356 $($(target)_$(directory)_MODE.$(bld_trg)) \
3357 $($(target)_$(directory)_MODE) \
[481]3358 $($(directory)_MODE.$(bld_trg).$(bld_trg_arch)) \
[380]3359 $($(directory)_MODE.$(bld_trg)) \
3360 $($(directory)_MODE) \
[481]3361 $($(target)_MODE.$(bld_trg).$(bld_trg_arch)) \
[380]3362 $($(target)_MODE.$(bld_trg)) \
3363 $($(target)_MODE))
[1496]3364local uid := $(firstword \
[481]3365 $($(target)_$(directory)_UID.$(bld_trg).$(bld_trg_arch)) \
[380]3366 $($(target)_$(directory)_UID.$(bld_trg)) \
3367 $($(target)_$(directory)_UID) \
[481]3368 $($(directory)_UID.$(bld_trg).$(bld_trg_arch)) \
[380]3369 $($(directory)_UID.$(bld_trg)) \
3370 $($(directory)_UID) \
[481]3371 $($(target)_UID.$(bld_trg).$(bld_trg_arch)) \
[380]3372 $($(target)_UID.$(bld_trg)) \
3373 $($(target)_UID))
[1496]3374local gid := $(firstword \
[481]3375 $($(target)_$(directory)_GID.$(bld_trg).$(bld_trg_arch)) \
[380]3376 $($(target)_$(directory)_GID.$(bld_trg)) \
3377 $($(target)_$(directory)_GID) \
[481]3378 $($(directory)_GID.$(bld_trg).$(bld_trg_arch)) \
[380]3379 $($(directory)_GID.$(bld_trg)) \
3380 $($(directory)_GID) \
[481]3381 $($(target)_GID.$(bld_trg).$(bld_trg_arch)) \
[380]3382 $($(target)_GID.$(bld_trg)) \
3383 $($(target)_GID))
[1496]3384local flags := \
[830]3385 $($(target)_IDFLAGS)\
3386 $($(target)_IDFLAGS.$(bld_trg)) \
3387 $($(target)_IDFLAGS.$(bld_trg).$(bld_trg_arch)) \
3388 $($(directory)_IDFLAGS) \
3389 $($(directory)_IDFLAGS.$(bld_trg)) \
3390 $($(directory)_IDFLAGS.$(bld_trg).$(bld_trg_arch)) \
3391 $($(target)_$(directory)_IDFLAGS) \
3392 $($(target)_$(directory)_IDFLAGS.$(bld_trg)) \
3393 $($(target)_$(directory)_IDFLAGS.$(bld_trg).$(bld_trg_arch))
[380]3394
[1496]3395local insdst := $(inst)/$(directory)/
[380]3396#$(warning directory=$(directory) inst=$(inst) insdst=$(insdst) mode=$(mode) gid=$(gid) uid=$(uid))
3397
3398# generate the rule (need double evaluation here)
3399$(eval $(def_install_directory_rule))
3400
3401INSTARGET_DIRS_$(target) += $(insdst)
[1936]3402endef # def_install_directory
3403$(eval-opt-var def_install_directory)
[380]3404
3405
[353]3406## process one install target.
3407define def_install
[744]3408# the basics.
[1504]3409local bld_type := $(firstword $($(target)_BLD_TYPE) $(KBUILD_TYPE))
3410local bld_trg := $(firstword $($(target)_BLD_TRG) $(KBUILD_TARGET))
3411local bld_trg_arch:= $(firstword $($(target)_BLD_TRG_ARCH) $(KBUILD_TARGET_ARCH))
3412local bld_trg_cpu := $(firstword $($(target)_BLD_TRG_CPU) $(KBUILD_TARGET_CPU))
[353]3413
[827]3414INSTARGET_$(target) := $($(target)_GOALS)
[380]3415INSTARGET_DIRS_$(target) :=
[1754]3416local outbase := $(call TARGET_BASE,$(target),$(target))
3417ifndef PATH_$(target)
3418 PATH_$(target) := $(patsubst %/,%,$(dir $(outbase)))
3419else ifneq ($(PATH_$(target)),$(patsubst %/,%,$(dir $(outbase))))
3420 $(error kBuild internal error: PATH_$(target)=$(PATH_$(target)) expected $(patsubst %/,%,$(dir $(outbase))))
3421endif
[380]3422
[1614]3423local 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))
3424
[481]3425$(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]3426 $(evalval def_install_directory))
[380]3427
[481]3428$(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]3429 $(evalval def_install_src))
[353]3430
[481]3431$(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]3432 $(evalval def_install_symlink))
[353]3433
[827]3434# the collection target
[2189]3435local clean_files += $(PATH_TARGET)/$(target).ins
3436TARGET_$(target) := $(PATH_TARGET)/$(target).ins
[1919]3437$(TARGET_$(target)): $$(INSTARGET_$(target)) | $$(INSTARGET_DIRS_$(target)) $(call DIRDEP,$(PATH_TARGET))
[827]3438 @$(QUIET2)$(APPEND) $@
3439
[1919]3440$(target): $$(TARGET_$(target))
[827]3441
3442_INSTALLS += $(TARGET_$(target))
3443_INSTALLS_FILES += $(INSTARGET_$(target))
[380]3444_INSTALLS_DIRS += $(INSTARGET_DIRS_$(target))
[1614]3445_CLEAN_FILES += $(clean_files)
[1754]3446_DIRS += $(PATH_$(target)) $($(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]3447endef # def_install
3448$(eval-opt-var def_install)
[353]3449
3450## process all install targets
[1648]3451$(foreach target, $(_ALL_INSTALLS), \
[1614]3452 $(evalvalctx def_install))
[353]3453
[988]3454ifdef KBUILD_PROFILE_SELF
[2008]3455 $(evalcall def_profile_self, done install targets)
[988]3456endif
[353]3457
[2227]3458# Some introspection targets that can be useful for package maintainers.
3459.PHONY: kbuild-show-install-files kbuild-show-install-dirs
3460kbuild-show-install-files::
3461 $(addprefix $(NL)$(TAB)$(QUIET)$(ECHO) , $(subst $(PATH_INS)/,,$(_INSTALLS_FILES)))
3462
3463kbuild-show-install-dirs::
3464 $(addprefix $(NL)$(TAB)$(QUIET)$(ECHO) , $(subst $(PATH_INS)/,,$(_INSTALLS_DIRS)))
3465
3466
[1646]3467#
3468# TESTING
3469#
3470_TESTING += $(TESTING) $(TESTING.$(KBUILD_TARGET)) $(TESTING.$(KBUILD_TARGET).$(KBUILD_TARGET_ARCH)) $(TESTING.$(KBUILD_TARGET_ARCH)) $(TESTING.$(KBUILD_TARGET_CPU))
[988]3471
[1646]3472
[72]3473#
[417]3474# PACKING
3475#
[1646]3476_PACKING += $(PACKING) $(PACKING.$(KBUILD_TARGET)) $(PACKING.$(KBUILD_TARGET).$(KBUILD_TARGET_ARCH)) $(PACKING.$(KBUILD_TARGET_ARCH)) $(PACKING.$(KBUILD_TARGET_CPU))
[417]3477
3478
3479#
[72]3480# DOCS
3481#
3482
3483
3484#
[353]3485# DIRECTORIES
3486#
[827]3487_DIR_ALL := $(sort $(addsuffix /,$(patsubst %/,%,$(_DIRS))) $(dir $(_OUT_FILES) $(_OBJS) $(_INSTALLS_FILES)))
[380]3488$(foreach directory,$(_INSTALLS_DIRS), $(eval _DIR_ALL := $(filter-out $(directory),$(_DIR_ALL))))
[353]3489
[380]3490
[353]3491define def_mkdir_rule
3492$(directory):
[1496]3493 %$$(call MSG_MKDIR,$$@)
[1599]3494 $$(QUIET)$$(MKDIR) -p -- $$@
[72]3495endef
3496
[353]3497$(foreach directory,$(_DIR_ALL),$(eval $(def_mkdir_rule)))
[72]3498
[988]3499ifdef KBUILD_PROFILE_SELF
[2008]3500 $(evalcall def_profile_self, done directories)
[988]3501endif
[183]3502
[988]3503
[72]3504#
[353]3505# NOTHING
[72]3506#
[353]3507do-nothing:
[2008]3508 %$(call MSG_NOTHING)
[988]3509ifdef KBUILD_PROFILE_SELF
[2008]3510 @$(ECHO) 'prof: $(call _KBUILD_FMT_ELAPSED_EX, $(nanots ), $(_KBUILD_TS_HEADER_START)) - $(call _KBUILD_FMT_ELAPSED_EX, $(nanots ), $(_KBUILD_TS_PREV)) - executing $@'
3511 ifeq ($(KBUILD_PROFILE_SELF),2)
[1456]3512 @$(ECHO) 'stat: $(make-stats )'
[2008]3513 endif
[988]3514endif
[72]3515
[183]3516
[75]3517#
[353]3518# CLEAN UP
[75]3519#
[353]3520do-clean:
[1496]3521 %$(call MSG_CLEAN)
[1599]3522 $(QUIET)$(RM) -f -- $(_OUT_FILES) $(_OBJS) $(_DEPFILES) $(_DEPFILES_INCLUDED) $(_CLEAN_FILES) $(OTHER_CLEAN)
3523 $(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]3524
[98]3525
[897]3526
[353]3527#
3528# PASSES (including directory and makefile walking)
3529#
[221]3530
[1667]3531#
3532# First, check whether we need to order the passes explicitly or not.
3533# This depends on whether we're a leaf makefile or not. A leaf will
3534# know all its dependencies, while a recursive one relies on the
3535# order sub-directories and other makefiles are executed it.
3536#
3537
3538## Setup a pass and check for optimizations.
3539# @param $(PASS) Uppercase pass name.
3540define def_pass_setup_and_optimize
3541
3542# The setup. ## @todo This is looks a bit weird...
3543ifndef SUBDIRS_$(PASS)
3544 SUBDIRS_$(PASS) := $(SUBDIRS) $(SUBDIRS.$(KBUILD_TARGET)) $(SUBDIRS.$(KBUILD_TARGET.$(KBUILD_TARGET_ARCH)))
3545endif
3546ifndef SUBDIRS_AFTER_$(PASS)
3547 SUBDIRS_AFTER_$(PASS) := $(SUBDIRS_AFTER) $(SUBDIRS_AFTER.$(KBUILD_TARGET)) $(SUBDIRS_AFTER.$(KBUILD_TARGET).$(KBUILD_TARGET_ARCH))
3548endif
3549ifndef MAKEFILES_BEFORE_$(PASS)
3550 MAKEFILES_BEFORE_$(PASS) := $(MAKEFILES_BEFORE) $(MAKEFILES_BEFORE.$(KBUILD_TARGET)) $(MAKEFILES_BEFORE.$(KBUILD_TARGET).$(KBUILD_TARGET_ARCH))
3551endif
3552ifndef MAKEFILES_AFTER_$(PASS)
3553 MAKEFILES_AFTER_$(PASS) := $(MAKEFILES_AFTER) $(MAKEFILES_AFTER.$(KBUILD_TARGET)) $(MAKEFILES_AFTER.$(KBUILD_TARGET).$(KBUILD_TARGET_ARCH))
3554endif
3555
3556# The check.
3557ifeq ($(_KBUILD_STRICT_PASS_ORDER),nonstrict)
3558 ifneq ($(strip \
3559 $(SUBDIRS_$(PASS)) $(SUBDIRS_$(PASS).$(KBUILD_TARGET)) $(SUBDIRS_$(PASS).$(KBUILD_TARGET).$(KBUILD_TARGET_ARCH)) \
3560 $(MAKEFILES_BEFORE_$(PASS)) $(MAKEFILES_BEFORE_$(PASS).$(KBUILD_TARGET)) $(MAKEFILES_BEFORE_$(PASS).$(KBUILD_TARGET).$(KBUILD_TARGET_ARCH)) \
3561 $(SUBDIRS_AFTER_$(PASS)) $(SUBDIRS_AFTER_$(PASS).$(KBUILD_TARGET)) $(SUBDIRS_AFTER_$(PASS).$(KBUILD_TARGET).$(KBUILD_TARGET_ARCH)) \
3562 $(MAKEFILES_AFTER_$(PASS)) $(MAKEFILES_AFTER_$(PASS).$(KBUILD_TARGET)) $(MAKEFILES_AFTER_$(PASS).$(KBUILD_TARGET).$(KBUILD_TARGET_ARCH)) \
3563 ),)
3564 _KBUILD_STRICT_PASS_ORDER := strict
3565 endif
3566endif # _KBUILD_STRICT_PASS_ORDER == nonstrict
3567endef # def_pass_setup_and_optimize
[1936]3568$(eval-opt-var def_pass_setup_and_optimize)
[1667]3569
3570## PASS: Setup & optimization.
3571# Check if we can apply the non-strict pass order optimzation (no SUBDIRS_* and MAKEFILES_*),
3572# and set up the pass specific variables as we go along.
3573_KBUILD_STRICT_PASS_ORDER := nonstrict
3574$(foreach PASS, $(PASSES), $(evalval def_pass_setup_and_optimize))
3575#$ (error _KBUILD_STRICT_PASS_ORDER=$(_KBUILD_STRICT_PASS_ORDER))
3576
[2058]3577ifeq ($(_KBUILD_STRICT_PASS_ORDER),strict)
[2059]3578 if !defined(KBUILD_SAFE_PARALLEL) || "$(KMK_OPT_JOBS)" == "1"
[2058]3579_KBUILD_STRICT_PASS_ORDER := strict_unsafe
3580 endif
3581endif
[1667]3582
[2058]3583
[75]3584## Subdir
3585# @param $(pass) Lowercase pass name.
3586# @param $(PASS) Uppercase pass name.
3587# @param $(subdir) Subdirectory
3588# @param $(tag) tag to attach to the rule name.
3589define def_pass_subdir
[219]3590pass_$(pass)$(tag):: $(dep)
[696]3591 + $$(QUIET)$$(MAKE) -C $(subdir) -f $$(notdir $$(firstword $$(wildcard $$(addprefix $(subdir)/,$$(DEFAULT_MAKEFILE))))) pass_$(pass)
[75]3592endef
[72]3593
[75]3594## Submakefile
3595# @param $(pass) Lowercase pass name.
3596# @param $(PASS) Uppercase pass name.
[1667]3597# @param $(makefile) Makefile.
[75]3598# @param $(tag) tag to attach to the rule name.
3599define def_pass_makefile
[219]3600pass_$(pass)$(tag):: $(dep)
[696]3601 + $$(QUIET)$$(MAKE) -C $(patsubst %/,%,$(dir $(makefile))) -f $(notdir $(makefile)) pass_$(pass)
[75]3602endef
[73]3603
[1667]3604## Execute a pass, strict order.
[75]3605# @param $(pass) Lowercase pass name.
3606# @param $(PASS) Uppercase pass name.
[1667]3607define def_pass_strict
[75]3608$(eval tag:=_before)
[2058]3609$(eval dep:= )
[1667]3610$(foreach subdir, $(SUBDIRS_$(PASS)) $(SUBDIRS_$(PASS).$(KBUILD_TARGET)) $(SUBDIRS_$(PASS).$(KBUILD_TARGET).$(KBUILD_TARGET_ARCH)) ,$(eval $(def_pass_subdir)))
[1504]3611$(foreach makefile,$(MAKEFILES_BEFORE_$(PASS)) $(MAKEFILES_BEFORE_$(PASS).$(KBUILD_TARGET)) $(MAKEFILES_BEFORE_$(PASS).$(KBUILD_TARGET).$(KBUILD_TARGET_ARCH)),$(eval $(def_pass_makefile)))
[75]3612
[353]3613$(eval tag:=_after)
3614$(eval dep:=pass_$(pass)_doit)
[1667]3615$(foreach subdir, $(SUBDIRS_AFTER_$(PASS)) $(SUBDIRS_AFTER_$(PASS).$(KBUILD_TARGET)) $(SUBDIRS_AFTER_$(PASS).$(KBUILD_TARGET).$(KBUILD_TARGET_ARCH)) ,$(eval $(def_pass_subdir)))
[1504]3616$(foreach makefile,$(MAKEFILES_AFTER_$(PASS)) $(MAKEFILES_AFTER_$(PASS).$(KBUILD_TARGET)) $(MAKEFILES_AFTER_$(PASS).$(KBUILD_TARGET).$(KBUILD_TARGET_ARCH)) ,$(eval $(def_pass_makefile)))
[75]3617
[353]3618.NOTPARALLEL: pass_$(pass) pass_$(pass)_before pass_$(pass)_after pass_$(pass)_this
3619.PHONY: pass_$(pass) pass_$(pass)_before pass_$(pass)_after pass_$(pass)_this pass_$(pass)_doit
[2058]3620pass_$(pass)_doit: $(PASS_$(PASS)_trgs) $(foreach var,$(PASS_$(PASS)_vars),$($(var)))
[353]3621pass_$(pass)_this: pass_$(pass)_before
[696]3622 + $$(QUIET)$$(MAKE) -f $$(MAKEFILE) pass_$(pass)_doit
[353]3623pass_$(pass)_after:: pass_$(pass)_this
3624pass_$(pass): pass_$(pass)_after
[2058]3625#$ (warning pass=$(pass) PASS=$(PASS): $(PASS_$(PASS)_trgs) $(PASS_$(PASS)_trgs) $(foreach var,$(PASS_$(PASS)_vars),$($(var))))
3626endef # def_pass_strict
3627$(eval-opt-var def_pass_strict)
3628
3629## Execute a pass, strict order.
3630# @param $(pass) Lowercase pass name.
3631# @param $(PASS) Uppercase pass name.
3632define def_pass_strict_unsafe
3633$(eval tag:=_before)
3634$(eval dep:= )
3635$(foreach subdir, $(SUBDIRS_$(PASS)) $(SUBDIRS_$(PASS).$(KBUILD_TARGET)) $(SUBDIRS_$(PASS).$(KBUILD_TARGET).$(KBUILD_TARGET_ARCH)) ,$(eval $(def_pass_subdir)))
3636$(foreach makefile,$(MAKEFILES_BEFORE_$(PASS)) $(MAKEFILES_BEFORE_$(PASS).$(KBUILD_TARGET)) $(MAKEFILES_BEFORE_$(PASS).$(KBUILD_TARGET).$(KBUILD_TARGET_ARCH)),$(eval $(def_pass_makefile)))
3637
3638$(eval tag:=_after)
3639$(eval dep:=pass_$(pass)_doit)
3640$(foreach subdir, $(SUBDIRS_AFTER_$(PASS)) $(SUBDIRS_AFTER_$(PASS).$(KBUILD_TARGET)) $(SUBDIRS_AFTER_$(PASS).$(KBUILD_TARGET).$(KBUILD_TARGET_ARCH)) ,$(eval $(def_pass_subdir)))
3641$(foreach makefile,$(MAKEFILES_AFTER_$(PASS)) $(MAKEFILES_AFTER_$(PASS).$(KBUILD_TARGET)) $(MAKEFILES_AFTER_$(PASS).$(KBUILD_TARGET).$(KBUILD_TARGET_ARCH)) ,$(eval $(def_pass_makefile)))
3642
[1667]3643.PHONY: pass_$(pass) pass_$(pass)_before pass_$(pass)_after pass_$(pass)_doit
[388]3644.NOTPARALLEL: pass_$(pass) pass_$(pass)_before pass_$(pass)_after pass_$(pass)_doit
[353]3645pass_$(pass)_doit: pass_$(pass)_before \
3646 $(PASS_$(PASS)_trgs) $(foreach var,$(PASS_$(PASS)_vars),$($(var)))
3647pass_$(pass): \
3648 pass_$(pass)_before \
3649 pass_$(pass)_doit \
[1667]3650 pass_$(pass)_after
[353]3651#$ (warning pass=$(pass) PASS=$(PASS): $(PASS_$(PASS)_trgs) $(PASS_$(PASS)_trgs) $(foreach var,$(PASS_$(PASS)_vars),$($(var))))
[2058]3652endef # def_pass_strict_unsafe
3653$(eval-opt-var def_pass_strict_unsafe)
[75]3654
[1667]3655## Execute a pass, non-strict pass ordering.
3656# @param $(pass) Lowercase pass name.
3657# @param $(PASS) Uppercase pass name.
3658define def_pass_nonstrict
3659.PHONY: pass_$(pass) pass_$(pass)_before pass_$(pass)_after pass_$(pass)_doit
[1919]3660pass_$(pass)_doit: $(PASS_$(PASS)_trgs) $(foreach var,$(PASS_$(PASS)_vars),$$$$($(var)))
[1667]3661pass_$(pass): pass_$(pass)_doit
3662endef # def_pass_nonstrict
3663
3664## PASS: rules
3665# Generate the rules for the defined passes.
[353]3666$(foreach PASS, $(PASSES), \
3667 $(eval pass := $(PASS_$(PASS)_pass)) \
[1667]3668 $(eval $(def_pass_$(_KBUILD_STRICT_PASS_ORDER))))
[75]3669
[1667]3670
3671## Pass order, strict.
[219]3672# @param $(pass) Current pass name.
3673# @param $(prev_pass) The previous pass name.
[1667]3674define def_pass_order_strict
3675.PHONY: pass_$(pass)_order
[353]3676.NOTPARALLEL: pass_$(pass)_order
[219]3677pass_$(pass)_order: $(pass_prev)
[1496]3678 %$$(call MSG_PASS,$$(if $$(PASS_$(PASS)),$$(PASS_$(PASS)),$(pass)))
[696]3679 + $$(QUIET)$$(MAKE) -f $$(MAKEFILE) pass_$(pass)
[2058]3680$(eval pass_prev := pass_$(pass)_order)
3681endef # def_pass_order_strict
3682$(eval-opt-var def_pass_order_strict)
3683
3684## Pass order, strict unsafe.
3685# @param $(pass) Current pass name.
3686# @param $(prev_pass) The previous pass name.
3687define def_pass_order_strict_unsafe
[353]3688.NOTPARALLEL: pass_$(pass)_order pass_$(pass)_banner
[388]3689.PHONY: pass_$(pass)_order pass_$(pass)_banner
[2058]3690pass_$(pass)_banner: $(pass_prev)
[1496]3691 %$$(call MSG_PASS,$$(if $$(PASS_$(PASS)),$$(PASS_$(PASS)),$(pass)))
[2058]3692pass_$(pass)_order: $(pass_prev) \
[353]3693 pass_$(pass)_banner \
3694 pass_$(pass)
[219]3695$(eval pass_prev := pass_$(pass)_order)
[2058]3696endef # def_pass_order_strict_unsafe
3697$(eval-opt-var def_pass_order_strict_unsafe)
[183]3698
[1667]3699## Pass order, non-strict.
3700# @param $(pass) Current pass name.
3701# @param $(prev_pass) The previous pass name.
3702define def_pass_order_nonstrict
3703.PHONY: pass_$(pass)_order pass_$(pass)_banner
3704pass_$(pass)_banner:
3705 %$$(call MSG_PASS,$$(if $$(PASS_$(PASS)),$$(PASS_$(PASS)),$(pass)))
3706pass_$(pass)_order: \
3707 $(pass_prev) \
3708 pass_$(pass)_banner \
3709 pass_$(pass)
3710$(eval pass_prev := pass_$(pass)_order)
3711endef # def_pass_order_nonstrict
[1936]3712$(eval-opt-var def_pass_order_nonstrict)
[1667]3713
[219]3714## PASS: order
3715# Use dependencies to ensure correct pass order.
3716pass_prev :=
[353]3717$(foreach PASS,$(DEFAULT_PASSES),\
3718 $(eval pass := $(PASS_$(PASS)_pass)) \
[1667]3719 $(eval $(def_pass_order_$(_KBUILD_STRICT_PASS_ORDER))))
[219]3720
[988]3721ifdef KBUILD_PROFILE_SELF
[2008]3722 $(evalcall def_profile_self, done passes)
[988]3723endif
[272]3724
[2107]3725# Some common pass aliases
3726ifndef KBUILD_NO_PASS_ALIASES
3727.PHONY: clean
3728clean: pass_clean
[897]3729
[2107]3730.PHONY: nothing
3731nothing: pass_nothing
3732
3733.PHONY: packing
3734packing: pass_packing
3735
[2222]3736 ifndef KBUILD_NO_TESTING_PASS_ALIASES
[2107]3737.PHONY: check
3738check:: pass_testing
3739
3740.PHONY: test
3741test:: pass_testing
[2222]3742 endif # KBUILD_NO_TESTING_PASS_ALIASES
3743endif # KBUILD_NO_PASS_ALIASES
[2107]3744
3745
[75]3746#
3747# THE MAIN RULES
3748#
[219]3749all_recursive: $(pass_prev)
[75]3750
[130]3751rebuild: clean
[219]3752 + $(MAKE) -f $(firstword $(MAKEFILE_LIST)) all_recursive
[78]3753
[412]3754# @todo make this a non-default pass!
[2106]3755uninstall::
[1599]3756 $(RM) -f -- $(_INSTALLS_FILES)
[412]3757
[2106]3758install:: pass_installs
[78]3759
[1919]3760# misc shortcuts (use secondary expansion here to save strcache[file] space).
[2084]3761targets: bldprogs libraries dlls programs sysmods miscbins others installs
[1919]3762objects: $$(_OBJS)
3763bldprogs: $$(_BLDPROGS)
3764libraries: $$(_LIBS) $$(_IMPORT_LIBS) $$(_OTHER_LIBRARIES)
3765dlls: $$(_DLLS)
3766programs: $$(_PROGRAMS)
3767sysmods: $$(_SYSMODS)
[2084]3768miscbins: $$(_MISCBINS)
[1919]3769others: $$(_OTHERS)
3770installs: $$(_INSTALLS) $$(_INSTALLS_DIRS) $$(_INSTALLS_FILES)
[75]3771
3772
[897]3773
[353]3774#
3775# kBuild debugging stuff.
3776#
[1667]3777## @todo this doesn't work. Move to a debug unit and expand it.
[353]3778show_targets:
[984]3779 @$(foreach target, $(_ALL_TARGETS),\
[353]3780 @$(ECHO) "target: $(target)" $(NLTAB)\
3781 @$(ECHO) " PATH_$(target)=$(PATH_$(target))" $(NLTAB)\
3782 @$(ECHO) " TARGET_$(target)=$(TARGET_$(target))" $(NLTAB)\
3783 @$(ECHO) " INSTARGET_$(target)=$(INSTARGET_$(target))" $(NLTAB)\
[660]3784$(foreach prop,$(PROPS_SINGLE) $(PROPS_ACCUMULATE_L) $(PROPS_ACCUMULATE_R) OBJS_ CLEAN, \
[1504]3785 $(eval _tmp:=$(firstword $($(target)_BLD_TRG) $(KBUILD_TARGET))) \
[353]3786 $(if $($(target)_$(prop).$(_tmp)),\
3787 @$(ECHO) " $(target)_$(prop).$(_tmp)=$($(target)_$(prop).$(_tmp))" $(NLTAB)) \
3788 $(if $($(target)_$(prop)), $(NLTAB)@$(ECHO) " $(target)_$(prop)=$($(target)_$(prop))" $(NLTAB)) \
3789)\
3790$(foreach prop,$(PROPS_DEFERRED), \
[1504]3791 $(eval _tmp:=$(firstword $($(target)_BLD_TRG) $(KBUILD_TARGET))) \
[353]3792 $(if $(value $(target)_$(prop).$(_tmp)),\
3793 @$(ECHO) ' $(target)_$(prop).$(_tmp)=$(value $(TARGET)_$(prop).$(_tmp))' $(NLTAB)) \
3794 $(if $(value $(target)_$(prop)), $(NLTAB)@$(ECHO) ' $(target)_$(prop)=$(value $(target)_$(prop))' $(NLTAB)) \
3795))
3796
3797
3798
3799#
3800# Include dependency files.
3801#
[1798]3802ifdef _DEPFILES
3803 # TODO: first works the second doesn't, provided _KB_INCLUDE_DEPS is undefined:
3804 # if "$(_KB_INCLUDE_DEPS)" == "1"
3805 # if $(_KB_INCLUDE_DEPS) == "1"
3806
3807 ifdef KB_HAVE_INCLUDEDEP_QUEUE
3808 includedep-queue $(_DEPFILES)
3809 else
3810 $(foreach dep, $(_DEPFILES), $(eval includedep $(dep)))
3811 endif
[893]3812endif
[353]3813
3814
[988]3815ifdef KBUILD_PROFILE_SELF
[2008]3816 $(evalcall def_profile_self, end of footer.kmk)
3817 _KBUILD_TS_FOOTER_END := $(_KBUILD_TS_PREV)
3818
3819 ifneq ($(KBUILD_PROFILE_SELF),0)
3820 $(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]3821 $(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]3822 $(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)) )
3823 $(info prof: DEPFILES_INCLUDED=$(words $(_DEPFILES_INCLUDED)) DEPFILES=$(words $(_DEPFILES)) MAKEFILES=$(words $(MAKEFILE_LIST)) )
3824 endif
[988]3825endif
3826
[1781]3827
[72]3828# end-of-file-content
[106]3829__footer_kmk__ := target
[72]3830endif # __footer_kmk__
[438]3831
Note: See TracBrowser for help on using the repository browser.