source: trunk/kBuild/footer.kmk@ 2477

Last change on this file since 2477 was 2477, checked in by bird, 14 years ago

footer.kmk: Install fixes.

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