source: trunk/kBuild/footer.kmk@ 1370

Last change on this file since 1370 was 1370, checked in by bird, 18 years ago

Fixed buggy check for template existance (def_templates was called instead of def_templates_include).

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 97.7 KB
RevLine 
[72]1# $Id: footer.kmk 1370 2007-12-09 21:03:03Z bird $
2## @file
3#
4# kBuild - File included at top of makefile.
5#
[782]6# Copyright (c) 2004-2007 knut st. osmundsen <bird-kBuild-spam@anduin.net>
[72]7#
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#
26
27ifndef __footer_kmk__
28# start-of-file-content
[988]29ifdef KBUILD_PROFILE_SELF
30 _KBUILD_TS_FOOTER_START := $(nanots )
31 $(info prof: $(int-sub $(_KBUILD_TS_FOOTER_START), $(_KBUILD_TS_HEADER_START)) - $(int-sub $(_KBUILD_TS_FOOTER_START), $(_KBUILD_TS_PREV)) - start of footer.kmk)
32 _KBUILD_TS_PREV := $(_KBUILD_TS_FOOTER_START)
33endif
[72]34
35#
36# Variables.
[73]37# (Some of these need initialization before including definitions using them.)
[72]38#
39
[985]40# All targets of each types.
41_ALL_BLDPROGS := $(BLDPROGS) $(BLDPROGS.$(BUILD_PLATFORM)) $(BLDPROGS.$(BUILD_PLATFORM).$(BUILD_PLATFORM_ARCH)) $(BLDPROGS.$(BUILD_PLATFORM_ARCH)) $(BLDPROGS.$(BUILD_PLATFORM_CPU)) $(BLDPROGS.$(BUILD_TYPE))
42_ALL_LIBRARIES := $(LIBRARIES) $(LIBRARIES.$(BUILD_TARGET)) $(LIBRARIES.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) $(LIBRARIES.$(BUILD_TARGET_ARCH)) $(LIBRARIES.$(BUILD_TARGET_CPU)) $(LIBRARIES.$(BUILD_TYPE))
43_ALL_IMPORT_LIBS := $(IMPORT_LIBS) $(IMPORT_LIBS.$(BUILD_TARGET)) $(IMPORT_LIBS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) $(IMPORT_LIBS.$(BUILD_TARGET_ARCH)) $(IMPORT_LIBS.$(BUILD_TARGET_CPU)) $(IMPORT_LIBS.$(BUILD_TYPE))
44_ALL_DLLS := $(DLLS) $(DLLS.$(BUILD_TARGET)) $(DLLS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) $(DLLS.$(BUILD_TARGET_ARCH)) $(DLLS.$(BUILD_TARGET_CPU)) $(DLLS.$(BUILD_TYPE))
45_ALL_PROGRAMS := $(PROGRAMS) $(PROGRAMS.$(BUILD_TARGET)) $(PROGRAMS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) $(PROGRAMS.$(BUILD_TARGET_ARCH)) $(PROGRAMS.$(BUILD_TARGET_CPU)) $(PROGRAMS.$(BUILD_TYPE))
46_ALL_SYSMODS := $(SYSMODS) $(SYSMODS.$(BUILD_TARGET)) $(SYSMODS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) $(SYSMODS.$(BUILD_TARGET_ARCH)) $(SYSMODS.$(BUILD_TARGET_CPU)) $(SYSMODS.$(BUILD_TYPE))
47_ALL_OTHERS := $(OTHERS) $(OTHERS.$(BUILD_TARGET)) $(OTHERS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) $(OTHERS.$(BUILD_TARGET_ARCH)) $(OTHERS.$(BUILD_TARGET_CPU)) $(OTHERS.$(BUILD_TYPE))
48_ALL_INSTALLS := $(INSTALLS) $(INSTALLS.$(BUILD_TARGET)) $(INSTALLS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) $(INSTALLS.$(BUILD_TARGET_ARCH)) $(INSTALLS.$(BUILD_TARGET_CPU)) $(INSTALLS.$(BUILD_TYPE))
49_ALL_FETCHES := $(FETCHES) $(FETCHES.$(BUILD_TARGET)) $(FETCHES.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) $(FETCHES.$(BUILD_TARGET_ARCH)) $(FETCHES.$(BUILD_TARGET_CPU)) $(FETCHES.$(BUILD_TYPE))
50_ALL_PATCHES := $(PATCHES) $(PATCHES.$(BUILD_TARGET)) $(PATCHES.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) $(PATCHES.$(BUILD_TARGET_ARCH)) $(PATCHES.$(BUILD_TARGET_CPU)) $(PATCHES.$(BUILD_TYPE))
51
[72]52# all targets.
[985]53_ALL_TARGETS = \
54 $(_ALL_FETCHES) \
55 $(_ALL_PATCHES) \
56 $(_ALL_BLDPROGS) \
57 $(_ALL_LIBRARIES) \
58 $(_ALL_IMPORT_LIBS) \
59 $(_ALL_DLLS) \
60 $(_ALL_PROGRAMS) \
61 $(_ALL_SYSMODS) \
62 $(_ALL_INSTALLS) \
63 $(_ALL_OTHERS)
[72]64
[447]65# all $(BUILD_TARGET) targets.
[985]66_ALL_BUILD_TARGET_TARGETS = \
67 $(_ALL_FETCHES) \
68 $(_ALL_PATCHES) \
69 $(_ALL_LIBRARIES) \
70 $(_ALL_IMPORT_LIBS) \
71 $(_ALL_DLLS) \
72 $(_ALL_PROGRAMS) \
73 $(_ALL_SYSMODS) \
74 $(_ALL_INSTALLS) \
75 $(_ALL_OTHERS)
[447]76
[985]77# all $(BUILD_PLATFORM) targets.
78_ALL_BUILD_PLATFORM_TARGETS = \
79 $(_ALL_BLDPROGS)
[447]80
[640]81# all targets making use of srcname.
[985]82_ALL_SRCNAME_TARGETS = \
83 $(_ALL_FETCHES) \
84 $(_ALL_PATCHES)
[640]85
[75]86# dependency files.
87_DEPFILES :=
88
[380]89# included dependency files.
90_DEPFILES_INCLUDED :=
91
92
[75]93# All kind of output files except for _OBJS and _DEPFILES.
94# Compiling or linking definition outputting other things that $@ and any
95# required dependency file must add those output files to this variable.
96_OUT_FILES :=
97
[353]98# Files which only requires cleaning up.
99_CLEAN_FILES :=
100
[72]101# all of a type
[219]102_OBJS :=
[640]103_FETCHES :=
104_DOWNLOADS:=
105_UNPACKS :=
106_PATCHES :=
[688]107_UNFETCHES:=
[222]108_BLDPROGS :=
[219]109_LIBS :=
110_DLLS :=
111_PROGRAMS :=
112_SYSMODS :=
[353]113_INSTALLS :=
[827]114_INSTALLS_FILES :=
[380]115_INSTALLS_DIRS :=
[353]116_OTHERS :=
[417]117_PACKING :=
[897]118_DIRS := $(PATH_TARGET)/ $(PATH_TARGET) $(BLDDIRS)
[189]119_IMPORT_LIBS :=
[72]120
[220]121# misc
122pass_prev :=
123
124
[984]125
[72]126#
[984]127# Footer macros
[73]128#
129
[78]130## Figure out the tool for a target.
[753]131# @param $1 normalized target.
132# @param $2 tooltype.
[222]133# @param bld_trg build target.
[481]134# @param bld_trg_arch build target architecture.
[79]135_TARGET_TOOL = $(strip $(firstword \
[753]136 $($(1)_$(2)TOOL.$(bld_trg).$(bld_trg_arch)) \
137 $($(1)_$(2)TOOL.$(bld_trg)) \
138 $($(1)_$(2)TOOL) \
139 $($(1)_TOOL.$(bld_trg).$(bld_trg_arch)) \
140 $($(1)_TOOL.$(bld_trg)) \
141 $($(1)_TOOL) \
142 $($(2)TOOL.$(bld_trg).$(bld_trg_arch)) \
143 $($(2)TOOL.$(bld_trg)) \
144 $($(2)TOOL) \
[481]145 $(TOOL.$(bld_trg).$(bld_trg_arch)) \
[222]146 $(TOOL.$(bld_trg)) \
[106]147 $(TOOL) \
[79]148 ))
[183]149
[353]150## Figure out the actual name of an installed file.
151# @param $1 The file to install.
152# @param $2 The target name.
153# @param $3 The _INST value (can be empty).
154# @param $4 The default directory to use when $3 is empty.
155_INSTALL_FILE = $(patsubst %/,%/$(notdir $(1)),$(if $(3),$(PATH_INS)/$(3),$(4)/))
156
157
[985]158## Inherit one template property in a non-accumulative manner.
159# @param $(prop) Property name
160# @param $(src) Source (parent) object.
161# @param $(trg) Target (child) object.
162# @remark Not all properties has all the variations, but making the correct
163# exceptions will only complicate matters and probably not gain much speed.
164define def_inherit_one
165ifdef $(src)_$(prop)
166 ifndef $(trg)_$(prop)
167 $(trg)_$(prop) = $($(src)_$(prop))
168 #$ (warning dbg-inherit: $(trg)_$(prop) = $($(src)_$(prop)) )
169 endif
170endif
171endef # def_inherit_one
[723]172
[985]173## Inherit one template property in a non-accumulative manner.
174# @param $(prop) Property name
175# @param $(src) Source (parent) object.
176# @param $(trg) Target (child) object.
177# @remark Not all properties has all the variations, but making the correct
178# exceptions will only complicate matters and probably not gain much speed.
179# @todo Check how/if this differs from def_inherit_one.
180define def_inherit_one_now
181ifdef $(src)_$(prop)
182 ifndef $(trg)_$(prop)
183 $(trg)_$(prop) := $($(src)_$(prop))
184 #$ (warning dbg-inherit-now: $(trg)_$(prop) = $($(src)_$(prop)) )
185 endif
186endif
187endef # def_inherit_one_now
[185]188
[985]189## Inherit one template property in a non-accumulative manner, deferred expansion.
190# @param $(prop) Property name
191# @param $(src) Source
192# @param $(trg) Target
193# @remark This define relies on double evaluation
194define def_inherit_one_deferred
195ifdef $(src)_$(prop)
196 ifndef $(trg)_$(prop)
197 $(trg)_$(prop) = $$($(src)_$(prop))
198 #$ (warning dbg-inherit-def: $(trg)_$(prop) = $($(src)_$(prop)) )
199 endif
[185]200endif
[985]201endef # def_inherit_one_deferred
[185]202
[985]203## Generic inheritance for use with targets templates and tools.
204# @param trg Object to consider for inheriting.
205# @param src_prefix What to prefix the value found in EXTENDS with to get the object.
206# @param properties List of the properties with straight expansion.
207# @param properties_now List of the properties with immediate expansion.
208# @param properties_deferred List of the properties with deferred expansion (e.g. function).
209define def_inherit
210src := $(strip $($(trg)_EXTENDS))
211ifneq ($(src),)
212 ifndef $(trg)_EXTENDS_STATUS_
213 $(trg)_EXTENDS_STATUS_ := 0
214 src := $(src_prefix)$(src)
[185]215
[985]216 # Recursivly process the parent (src) if it's inherting from somebody too.
217 ifdef $(src)_EXTENDS
218 ifneq ($($(src)_EXTENDS_STATUS_),42)
219 # 'foreach' will create 'trg' in a new variable context hiding
220 # out current variable. 'src' OTOH will be overwritten.
221 #$ (warning def_inherit: recursing into $(src) from $(trg))
222 $(foreach trg, $(src), $(eval $(value def_inherit)))
223 src := $(src_prefix)$(strip $($(trg)_EXTENDS))
224 endif
225 endif
[984]226
[985]227 # Inherit the properties and mark the trg done.
228 #$ (warning def_inherit: trg=$(trg) src=$(src))
229 $(foreach prop, $(properties), $(eval $(def_inherit_one)))
230 $(foreach prop, $(properties_now), $(eval $(def_inherit_one_now)))
231 $(foreach prop, $(properties_deferred), $(eval $(def_inherit_one_deferred)))
232 $(trg)_EXTENDS_STATUS_ := 42
233 else
234 # Check for inheritance loops.
[1266]235 ifneq ($($(trg)_EXTENDS_STATUS_),42)
236 $(error kBuild: Target inheritance loop! target=$(trg) $(trg)_EXTENDS_STATUS_=$($(trg)_EXTENDS_STATUS_))
[985]237 endif
238 endif
239endif
240endef # def_inherit
[984]241
[985]242
[984]243#
[985]244# Determin all the templates that is being used and make
245# sure they are present.
[72]246#
247_TEMPLATES := $(TEMPLATE)
248define def_templates
249ifdef $(target)_TEMPLATE
[985]250 ifneq ("$($(target)_TEMPLATE)","$(strip $($(target)_TEMPLATE))")
251 $$(error kBuild: The template name of target '$(target)' contains tabs ($($(target)_TEMPLATE))). Please remove them)
252 endif
253 _TEMPLATES += $($(target)_TEMPLATE)
[72]254endif
[985]255endef # def_templates
[984]256$(foreach target, $(_ALL_TARGETS), $(eval $(def_templates)))
[72]257_TEMPLATES := $(sort $(_TEMPLATES))
258
259define def_templates_include
260ifndef TEMPLATE_$(template)
[985]261 TEMPLATE_$(template)_INCLUDE_FILE_ := $(firstword $(foreach path, $(TEMPLATE_PATHS) $(PATH_KBUILD)/templates/, $(wildcard $(path)/$(template).kmk)))
262 ifneq ($(TEMPLATE_$(template)_INCLUDE_FILE_),)
263 include $(TEMPLATE_$(template)_INCLUDE_FILE_)
264 else
265 $$(error kBuild: Cannot find template '$(template)')
266 endif
[72]267endif
[985]268endef # def_templates_include
[1370]269$(foreach template, $(_TEMPLATES), $(eval $(def_templates_include)))
[72]270
[985]271#$ (warning dbg _TEMPLATES := $(_TEMPLATES))
[74]272
[985]273
[72]274#
[985]275# Determin the BLD_TRG_* keywords required for correct inherting.
[412]276#
[985]277# This means walking all the template and target lists in order to
278# pick up all BLD_TRG_* attributes.
279#
280_BLD_TYPES := $(BUILD_TYPE)
281_BLD_TARGETS := $(BUILD_TARGET) $(BUILD_PLATFORMS)
282_BLD_ARCHES := $(BUILD_TARGET_ARCH) $(BUILD_PLATFORM_ARCH)
283_BLD_CPUS := $(BUILD_TARGET_CPU) $(BUILD_PLATFORM_CPU)
284
285define def_collect_bld_xyz
286ifdef ($(src)_BLD_TYPE)
287 _BLD_TYPE += $($(src)_BLD_TYPE)
[412]288endif
[985]289ifdef ($(src)_BLD_TRG)
290 _BLD_TARGETS += $($(src)_BLD_TRG)
291endif
292ifdef ($(src)_BLD_TRG_ARCH)
293 _BLD_ARCHES += $($(src)_BLD_TRG_ARCH)
294endif
295ifdef ($(src)_BLD_TRG_CPU)
296 _BLD_CPU += $($(src)_BLD_TRG_CPU)
297endif
298endef # def_collect_bld_xyz
299$(foreach src, $(addprefix TEMPLATE_, $(_TEMPLATES)) $(_ALL_TARGETS)\
300 ,$(eval $(def_collect_bld_xyz)))
[412]301
[985]302# drop duplicate values
303_BLD_TYPES := $(sort $(_BLD_TYPES))
304_BLD_TARGETS := $(sort $(_BLD_TARGETS))
305_BLD_ARCHES := $(sort $(_BLD_ARCHES))
306_BLD_CPUS := $(sort $(_BLD_CPUS))
[552]307
[985]308# Construct all the possible keywords.
309_KEYWORDS := $(_BLD_TYPES) $(_BLD_TARGETS) $(_BLD_ARCHES) $(_BLD_CPUS) \
310 $(foreach bld_trg,$(_BLD_TARGETS),$(addprefix $(bld_trg).,$(_BLD_ARCHES)))
311# $ (warning dbg _KEYWORDS := $(_KEYWORDS))
[412]312
[988]313ifdef KBUILD_PROFILE_SELF
314 _KBUILD_TS_NOW := $(nanots )
315 $(info prof: $(int-sub $(_KBUILD_TS_NOW), $(_KBUILD_TS_HEADER_START)) - $(int-sub $(_KBUILD_TS_NOW), $(_KBUILD_TS_PREV)) - done keywords)
316 _KBUILD_TS_PREV := $(_KBUILD_TS_NOW)
317endif
[552]318
[988]319
[985]320#
321# Target inheritance.
322#
323# This has to be done on a per target list basis as to avoid adding
324# incorrect properties that will wast memory, time, and may confuse
325# later strictness checks. This also has to be done *before* templates
326# are applied to the targets. Since we're doing that part rather
327# early on, the target inheritance feature is a bit restricted at
328# the moment. However, this will be addressed in a little(?) while.
329#
[552]330
[985]331src_prefix :=
332## combines the specified properties $(1) with the $(_KEYWORDS).
333_COMB_KEY_PROP = $(1) $(foreach keyword,$(_KEYWORDS), $(addsuffix .$(keyword), $(1)))
[412]334
[985]335# Fetches.
336properties := $(call _COMB_KEY_PROP,$(PROPS_FETCHES_SINGLE))
337properties_now := $(call _COMB_KEY_PROP,$(PROPS_FETCHES_ACCUMULATE_R) $(PROPS_FETCHES_ACCUMULATE_L))
338properties_deferred := $(call _COMB_KEY_PROP,$(PROPS_FETCHES_DEFERRED))
339$(foreach trg, $(_ALL_FETCHES),$(eval $(value def_inherit)))
[412]340
[985]341## Patches. - not implemented yet.
342#properties := $(call _COMB_KEY_PROP,$(PROPS_PATCHES_SINGLE))
343#properties_now := $(call _COMB_KEY_PROP,$(PROPS_PATCHES_ACCUMULATE_R) $(PROPS_PATCHES_ACCUMULATE_L))
344#properties_deferred := $(call _COMB_KEY_PROP,$(PROPS_PATCHES_DEFERRED))
345#$(foreach trg, $(_ALL_PATCHES),$(eval $(value def_inherit)))
[412]346
[985]347# Programs and build programs.
348properties := $(call _COMB_KEY_PROP,$(PROPS_PROGRAMS_SINGLE))
349properties_now := $(call _COMB_KEY_PROP,$(PROPS_PROGRAMS_ACCUMULATE_R) $(PROPS_PROGRAMS_ACCUMULATE_L))
350properties_deferred := $(call _COMB_KEY_PROP,$(PROPS_PROGRAMS_DEFERRED))
351$(foreach trg, $(_ALL_BLDPROGS) $(_ALL_PROGRAMS),$(eval $(value def_inherit)))
352
353# Libraries and import libraries.
354properties := $(call _COMB_KEY_PROP,$(PROPS_LIBRARIES_SINGLE))
355properties_now := $(call _COMB_KEY_PROP,$(PROPS_LIBRARIES_ACCUMULATE_R) $(PROPS_LIBRARIES_ACCUMULATE_L))
356properties_deferred := $(call _COMB_KEY_PROP,$(PROPS_LIBRARIES_DEFERRED))
[989]357ifeq ($(filter-out nt os2 win win64 win32,$(BUILD_TARGET)),)
358 $(foreach trg, $(_ALL_LIBRARIES) $(_ALL_IMPORT_LIBS),$(eval $(value def_inherit)))
359else
360 $(foreach trg, $(_ALL_LIBRARIES),$(eval $(value def_inherit)))
361endif
[985]362
363# DLLs.
364properties := $(call _COMB_KEY_PROP,$(PROPS_DLLS_SINGLE))
365properties_now := $(call _COMB_KEY_PROP,$(PROPS_DLLS_ACCUMULATE_R) $(PROPS_DLLS_ACCUMULATE_L))
366properties_deferred := $(call _COMB_KEY_PROP,$(PROPS_DLLS_DEFERRED))
[989]367ifeq ($(filter-out nt os2 win win64 win32,$(BUILD_TARGET)),)
368 $(foreach trg, $(_ALL_DLLS),$(eval $(value def_inherit)))
369else
370 $(foreach trg, $(_ALL_DLLS) $(_ALL_IMPORT_LIBS),$(eval $(value def_inherit)))
371endif
[985]372
[989]373# System modules.
374properties := $(call _COMB_KEY_PROP,$(PROPS_SYSMODS_SINGLE))
375properties_now := $(call _COMB_KEY_PROP,$(PROPS_SYSMODS_ACCUMULATE_R) $(PROPS_SYSMODS_ACCUMULATE_L))
376properties_deferred := $(call _COMB_KEY_PROP,$(PROPS_SYSMODS_DEFERRED))
377$(foreach trg, $(_ALL_SYSMODS),$(eval $(value def_inherit)))
378
[985]379# Installs.
380properties := $(call _COMB_KEY_PROP,$(PROPS_INSTALLS_SINGLE))
381properties_now := $(call _COMB_KEY_PROP,$(PROPS_INSTALLS_ACCUMULATE_R) $(PROPS_INSTALLS_ACCUMULATE_L))
382properties_deferred := $(call _COMB_KEY_PROP,$(PROPS_INSTALLS_DEFERRED))
383$(foreach trg, $(_ALL_INSTALLS),$(eval $(value def_inherit)))
384
[988]385ifdef KBUILD_PROFILE_SELF
386 _KBUILD_TS_NOW := $(nanots )
387 $(info prof: $(int-sub $(_KBUILD_TS_NOW), $(_KBUILD_TS_HEADER_START)) - $(int-sub $(_KBUILD_TS_NOW), $(_KBUILD_TS_PREV)) - done target inheritance)
388 _KBUILD_TS_PREV := $(_KBUILD_TS_NOW)
389endif
[985]390
[988]391
[412]392#
[985]393# Template Inheritance.
394#
395# This is much the same as with target inheritance, except we cannot
[1370]396# restrict the properties involved since we haven't got a clue which
397# target platforms/archs are using them. But, we can drop the instance
398# expansion we're doing for targets since there won't be any more
399# changes to either the source nor the target templates beyond this
400# exercise.
[985]401#
402
403src_prefix := TEMPLATE_
404properties :=
405properties_now :=
406properties_deferred := $(call _COMB_KEY_PROP,$(PROPS_ALL))
407$(foreach trg, $(addprefix TEMPLATE_,$(_TEMPLATES)),$(eval $(value def_inherit)))
408
409# done.
410src_prefix :=
411properties :=
412properties_now :=
413properties_deferred :=
414
[988]415ifdef KBUILD_PROFILE_SELF
416 _KBUILD_TS_NOW := $(nanots )
417 $(info prof: $(int-sub $(_KBUILD_TS_NOW), $(_KBUILD_TS_HEADER_START)) - $(int-sub $(_KBUILD_TS_NOW), $(_KBUILD_TS_PREV)) - done template inheritance)
418 _KBUILD_TS_PREV := $(_KBUILD_TS_NOW)
419endif
[985]420
[988]421
[985]422#
[72]423# Common Inheritance
424#
425
[353]426## Inherit one template property in a non-accumulative manner.
[72]427# @param $(prop) Property name
428# @param $(target) Target name
[78]429# @todo fix the precedence order for some properties.
[72]430define def_inherit_template_one
[78]431ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop)
[72]432ifndef $(target)_$(prop)
[353]433$(target)_$(prop) := $(TEMPLATE_$($(target)_TEMPLATE)_$(prop))
434#$ (warning dbgtarget: $(target)_$(prop):='$(value $(target)_$(prop))' TEMPLATE_$($(target)_TEMPLATE)_$(prop))
[72]435endif
436endif
[447]437ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg)
438ifndef $(target)_$(prop).$(bld_trg)
439#$ (warning dbgsource: $(target)_$(prop).$(bld_trg)="TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg)" TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg))
440$(target)_$(prop).$(bld_trg) := $(TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg))
[79]441endif
442endif
[481]443ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg).$(bld_trg_arch)
444ifndef $(target)_$(prop).$(bld_trg).$(bld_trg_arch)
445#$ (warning dbgsource: $(target)_$(prop).$(bld_trg).$(bld_trg_arch)="TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg).$(bld_trg_arch)" TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg).$(bld_trg_arch))
446$(target)_$(prop).$(bld_trg).$(bld_trg_arch) := $(TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg).$(bld_trg_arch))
447endif
448endif
[455]449ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_arch)
450ifndef $(target)_$(prop).$(bld_trg_arch)
451#$ (warning dbgsource: $(target)_$(prop).$(bld_trg_arch)="TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_arch)" TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_arch))
452$(target)_$(prop).$(bld_trg_arch) := $(TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_arch))
453endif
454endif
455ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_cpu)
456ifndef $(target)_$(prop).$(bld_trg_cpu)
457#$ (warning dbgsource: $(target)_$(prop).$(bld_trg_cpu)="TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_cpu)" TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_cpu))
458$(target)_$(prop).$(bld_trg_cpu) := $(TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_cpu))
459endif
460endif
[72]461endef
462
[353]463## Inherit one template property in a non-accumulative manner, deferred expansion.
464# @param 1: $(prop) Property name
465# @param 2: $(target) Target name
466# @todo fix the precedence order for some properties.
467# @remark this define relies on double evaluation
468define def_inherit_template_one_deferred
469ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop)
470ifndef $(target)_$(prop)
471$(target)_$(prop) = $$(TEMPLATE_$($(target)_TEMPLATE)_$(prop))
472#$ (warning dbgtarget: $(target)_$(prop):='$(value $(target)_$(prop))' TEMPLATE_$($(target)_TEMPLATE)_$(prop))
473endif
474endif
[447]475ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg)
476ifndef $(target)_$(prop).$(bld_trg)
477#$ (warning dbgsource: $(target)_$(prop).$(bld_trg)="TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg)" TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg))
478$(target)_$(prop).$(bld_trg) = $$(TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg))
[353]479endif
480endif
[481]481ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg).$(bld_trg_arch)
482ifndef $(target)_$(prop).$(bld_trg).$(bld_trg_arch)
483#$ (warning dbgsource: $(target)_$(prop).$(bld_trg).$(bld_trg_arch)="TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg).$(bld_trg_arch)" TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg).$(bld_trg_arch))
484$(target)_$(prop).$(bld_trg).$(bld_trg_arch) = $$(TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg).$(bld_trg_arch))
485endif
486endif
[455]487ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_arch)
488ifndef $(target)_$(prop).$(bld_trg_arch)
489#$ (warning dbgsource: $(target)_$(prop).$(bld_trg_arch)="TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_arch)" TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_arch))
490$(target)_$(prop).$(bld_trg_arch) = $$(TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_arch))
491endif
492endif
493ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_cpu)
494ifndef $(target)_$(prop).$(bld_trg_cpu)
495#$ (warning dbgsource: $(target)_$(prop).$(bld_trg_cpu)="TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_cpu)" TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_cpu))
496$(target)_$(prop).$(bld_trg_cpu) = $$(TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_cpu))
497endif
498endif
[353]499endef
500
[660]501## Inherit one acculumlative template property where the 'most significant' items are at the left end.
[78]502# @param $(prop) Property name
503# @param $(target) Target name
[660]504define def_inherit_template_one_accumulate_l
[78]505ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop)
[353]506#$ (warning dbgtype: TEMPLATE_$($(target)_TEMPLATE)_$(prop) $(target)_$(prop)=$($(target)_$(prop)) $(TEMPLATE_$($(target)_TEMPLATE)_$(prop)))
[659]507$(target)_$(prop) += $$(TEMPLATE_$($(target)_TEMPLATE)_$(prop))
[442]508#$ (warning dbgtype: $(target)_$(prop)=$($(target)_$(prop)))
[78]509endif
[243]510ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(BUILD_TYPE)
[353]511#$ (warning dbg4: TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(BUILD_TYPE))
[659]512$(target)_$(prop).$(BUILD_TYPE) += $$(TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(BUILD_TYPE))
[243]513endif
[447]514ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg)
[659]515#$ (warning dbg5: TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg))
516$(target)_$(prop).$(bld_trg) += $$(TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg))
[79]517endif
[481]518ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg).$(bld_trg_arch)
519#$ (warning dbg4: TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg).$(bld_trg_arch))
[659]520$(target)_$(prop).$(bld_trg).$(bld_trg_arch) += $$(TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg).$(bld_trg_arch))
[481]521endif
[447]522ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_cpu)
523#$ (warning dbg5: TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_cpu))
[659]524$(target)_$(prop).$(bld_trg_cpu) += $$(TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_cpu))
[79]525endif
[447]526ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_arch)
527#$ (warning dbg6: TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_arch))
[659]528$(target)_$(prop).$(bld_trg_arch) += $$(TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_arch))
[79]529endif
[78]530endef
531
[660]532## Inherit one acculumlative template property where the 'most significant' items are at the right end.
533# @param $(prop) Property name
534# @param $(target) Target name
[981]535define def_inherit_template_one_accumulate_r
[660]536ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop)
[981]537#$ (warning dbgtype: TEMPLATE_$($(target)_TEMPLATE)_$(prop) $(target)_$(prop)=$($(target)_$(prop)) $(TEMPLATE_$($(target)_TEMPLATE)_$(prop)))
538$(target)_$(prop) <=$$(TEMPLATE_$($(target)_TEMPLATE)_$(prop))
539#$ (warning dbgtype: $(target)_$(prop)=$($(target)_$(prop)))
[660]540endif
541ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(BUILD_TYPE)
[981]542#$ (warning dbg4: TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(BUILD_TYPE))
543$(target)_$(prop).$(BUILD_TYPE) <=$$(TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(BUILD_TYPE))
[660]544endif
545ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg)
[981]546#$ (warning dbg5: TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg))
547$(target)_$(prop).$(bld_trg) <=$$(TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg))
[660]548endif
549ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg).$(bld_trg_arch)
[981]550#$ (warning dbg4: TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg).$(bld_trg_arch))
551$(target)_$(prop).$(bld_trg).$(bld_trg_arch) <=$$(TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg).$(bld_trg_arch))
[660]552endif
553ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_cpu)
[981]554#$ (warning dbg5: TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_cpu))
555$(target)_$(prop).$(bld_trg_cpu) <=$$(TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_cpu))
[660]556endif
557ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_arch)
[981]558#$ (warning dbg6: TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_arch))
559$(target)_$(prop).$(bld_trg_arch) <=$$(TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_arch))
[660]560endif
561endef
562
563
[72]564## Inherit template properties for on target.
565# @param $(target) Target name.
566define def_inherit_template
[745]567# sanity check.
568ifdef _$(target)_ALREADY_PROCESSED
569 $(error kBuild: The target $(target) appears more than once in the target lists! Please correct the makefile(s))
570endif
571_$(target)_ALREADY_PROCESSED := 1
572
[447]573# Inherit any default template.
574ifdef TEMPLATE
575ifeq ($($(target)_TEMPLATE),)
576$(eval $(target)_TEMPLATE:=$(TEMPLATE))
577endif
578endif
579# Expand the template if specified.
580ifneq ($($(target)_TEMPLATE),)
[353]581$(foreach prop,$(PROPS_SINGLE),$(eval $(value def_inherit_template_one)))
582$(foreach prop,$(PROPS_DEFERRED),$(eval $(def_inherit_template_one_deferred))) # exploits the 2 evaluation, so no value!
[981]583$(foreach prop,$(PROPS_ACCUMULATE_L),$(eval $(def_inherit_template_one_accumulate_l))) # += works fine without value
584$(foreach prop,$(PROPS_ACCUMULATE_R),$(eval $(def_inherit_template_one_accumulate_r))) # use <= (kmk addition)
[447]585endif
[72]586endef
[353]587
[72]588# Inherit template properties
[447]589bld_trg := $(BUILD_TARGET)
590bld_trg_arch := $(BUILD_TARGET_ARCH)
591bld_trg_cpu := $(BUILD_TARGET_CPU)
592$(foreach target, $(_ALL_BUILD_TARGET_TARGETS),$(eval $(value def_inherit_template)))
[72]593
[447]594bld_trg := $(BUILD_PLATFORM)
595bld_trg_arch := $(BUILD_PLATFORM_ARCH)
596bld_trg_cpu := $(BUILD_PLATFORM_CPU)
597$(foreach target, $(_ALL_BUILD_PLATFORM_TARGETS),$(eval $(value def_inherit_template)))
[72]598
[988]599ifdef KBUILD_PROFILE_SELF
600 _KBUILD_TS_NOW := $(nanots )
601 $(info prof: $(int-sub $(_KBUILD_TS_NOW), $(_KBUILD_TS_HEADER_START)) - $(int-sub $(_KBUILD_TS_NOW), $(_KBUILD_TS_PREV)) - done common inheritance)
602 _KBUILD_TS_PREV := $(_KBUILD_TS_NOW)
603endif
[447]604
[988]605
[72]606#
[460]607# Include tools & sdks
[183]608#
[985]609# The first part of this exercise is to figure out which TOOLS and SDKS
610# that should be included.
611#
[592]612_TOOLS := $(TOOL.$(BUILD_TARGET)) $(TOOL.$(BUILD_TARGET_ARCH)) $(TOOL.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) \
613 $(TOOL.$(BUILD_PLATFORM)) $(TOOL.$(BUILD_PLATFORM_ARCH)) $(TOOL.$(BUILD_PLATFORM).$(BUILD_PLATFORM_ARCH)) \
614 $(TOOL)
615_SDKS := $(SDKS.$(BUILD_TARGET)) $(SDKS.$(BUILD_TARGET_ARCH)) $(SDKS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) \
616 $(SDKS.$(BUILD_PLATFORM)) $(SDKS.$(BUILD_PLATFORM_ARCH)) $(SDKS.$(BUILD_PLATFORM).$(BUILD_PLATFORM_ARCH)) \
617 $(SDKS.$(BUILD_TYPE)) \
618 $(SDKS)
[460]619define def_tools_sdks_target_source
[353]620$(eval _TOOLS += $(foreach prop, $(PROPS_TOOLS), \
[460]621 $($(source)_$(prop).$(_bld_trg)) \
622 $($(target)_$(source)_$(prop).$(_bld_trg)) \
[481]623 $($(source)_$(prop).$(_bld_trg).$(_bld_trg_arch)) \
624 $($(target)_$(source)_$(prop).$(_bld_trg).$(_bld_trg_arch)) \
[460]625 $($(source)_$(prop).$(_bld_trg_arch)) \
626 $($(target)_$(source)_$(prop).$(_bld_trg_arch)) \
[353]627 $($(source)_$(prop)) \
628 $($(target)_$(source)_$(prop))))
[460]629$(eval _SDKS += \
630 $($(source)_SDKS.$(_bld_trg)) \
631 $($(target)_$(source)_SDKS.$(_bld_trg)) \
[481]632 $($(source)_SDKS.$(_bld_trg).$(_bld_trg_arch)) \
633 $($(target)_$(source)_SDKS.$(_bld_trg).$(_bld_trg_arch)) \
[460]634 $($(source)_SDKS.$(_bld_trg_arch)) \
635 $($(target)_$(source)_SDKS.$(_bld_trg_arch)) \
[592]636 $($(source)_SDKS.$(BUILD_TYPE)) \
637 $($(target)_$(source)_SDKS.$(BUILD_TYPE)) \
[460]638 $($(source)_SDKS) \
639 $($(target)_$(source)_SDKS))
[985]640endef # def_tools_sdks_target_source
[353]641
[460]642define def_tools_sdks_target
[985]643_bld_type := $(firstword $($(target)_BLD_TYPE) $(BUILD_TYPE))
[460]644_bld_trg := $(firstword $($(target)_BLD_TRG) $(bld_trg))
645_bld_trg_arch := $(firstword $($(target)_BLD_TRG_ARCH) $(bld_trg_arch))
646_bld_trg_cpu := $(firstword $($(target)_BLD_TRG_CPU) $(bld_trg_cpu))
647
[353]648$(eval _TOOLS += $(foreach prop, $(PROPS_TOOLS), \
[460]649 $($(target)_$(prop).$(_bld_trg)) \
650 $($(target)_$(prop).$(_bld_trg_arch)) \
[481]651 $($(target)_$(prop).$(_bld_trg).$(_bld_trg_arch)) \
[353]652 $($(target)_$(prop))))
[460]653$(eval _SDKS += \
654 $($(target)_SDKS.$(_bld_trg)) \
655 $($(target)_SDKS.$(_bld_trg_arch)) \
[481]656 $($(target)_SDKS.$(_bld_trg).$(_bld_trg_arch)) \
[460]657 $($(target)_SDKS))
[353]658$(foreach source, \
[460]659 $($(target)_SOURCES.$(_bld_trg)) \
660 $($(target)_SOURCES.$(_bld_trg_arch)) \
[481]661 $($(target)_SOURCES.$(_bld_trg).$(_bld_trg_arch)) \
[460]662 $($(target)_SOURCES.$(_bld_trg_cpu)) \
[985]663 $($(target)_SOURCES.$(_bld_type)) \
[353]664 $($(target)_SOURCES) \
[460]665 , $(eval $(value def_tools_sdks_target_source)))
[985]666endef # def_tools_sdks_target
[353]667
[640]668define def_tools_srcname_target
[985]669_bld_type := $(firstword $($(target)_BLD_TYPE) $(BUILD_TYPE))
[640]670_bld_trg := $(firstword $($(target)_BLD_TRG) $(bld_trg))
671_bld_trg_arch := $(firstword $($(target)_BLD_TRG_ARCH) $(bld_trg_arch))
672_bld_trg_cpu := $(firstword $($(target)_BLD_TRG_CPU) $(bld_trg_cpu))
673
674$(foreach source, $(notdir\
675 $($(target)_SOURCES.$(_bld_trg)) \
676 $($(target)_SOURCES.$(_bld_trg_arch)) \
677 $($(target)_SOURCES.$(_bld_trg).$(_bld_trg_arch)) \
678 $($(target)_SOURCES.$(_bld_trg_cpu)) \
[985]679 $($(target)_SOURCES.$(_bld_type)) \
[640]680 $($(target)_SOURCES) \
681 ), $(eval $(value def_tools_sdks_target_source)))
[985]682endef # def_tools_srcname_target
[640]683
[460]684bld_trg := $(BUILD_TARGET)
685bld_trg_arch := $(BUILD_TARGET_ARCH)
686bld_trg_cpu := $(BUILD_TARGET_CPU)
687$(foreach target, $(_ALL_BUILD_TARGET_TARGETS), $(eval $(value def_tools_sdks_target)))
[640]688$(foreach target, $(_ALL_SRCNAME_TARGETS), $(eval $(value def_tools_srcname_target)))
[72]689
[460]690bld_trg := $(BUILD_PLATFORM)
691bld_trg_arch := $(BUILD_PLATFORM_ARCH)
692bld_trg_cpu := $(BUILD_PLATFORM_CPU)
693$(foreach target, $(_ALL_BUILD_PLATFORM_TARGETS), $(eval $(value def_tools_sdks_target)))
694
695
696# include TOOLS
[72]697define def_tools_include
698ifndef TOOL_$(tool)
[985]699 TOOL_$(tool)_KMK_FILE := $(firstword $(foreach path, $(TOOL_PATHS) $(PATH_KBUILD)/tools, $(wildcard $(path)/$(tool).kmk)))
700 ifeq ($(TOOL_$(tool)_KMK_FILE),)
701 $(error kBuild: Cannot find include file for the tool '$(tool)'! Searched: $(TOOL_PATHS) $(PATH_KBUILD)/tools)
702 endif
703 include $(TOOL_$(tool)_KMK_FILE)
704 ifndef TOOL_$(tool)
705 $(warning kBuild: TOOL_$(tool) was not by $(TOOL_$(tool)_KMK_FILE)!)
706 endif
[72]707endif
[985]708endef # def_tools_include
[460]709
710_TOOLS := $(sort $(_TOOLS))
[353]711$(foreach tool, $(_TOOLS), $(eval $(value def_tools_include)))
[72]712
713
[460]714# include SDKS
[122]715define def_sdks_include_one
[72]716ifndef SDK_$(sdk)
[985]717 SDK_$(sdk)_KMK_FILE := $(firstword $(foreach path, $(SDK_PATHS) $(PATH_KBUILD)/sdks, $(wildcard $(path)/$(sdk).kmk)))
718 ifeq ($(SDK_$(sdk)_KMK_FILE),)
719 $(error kBuild: Cannot find include file for the SDK '$(sdk)'! Searched: $(SDK_PATHS) $(PATH_KBUILD)/sdks)
720 endif
721 include $(SDK_$(sdk)_KMK_FILE)
722 ifndef SDK_$(sdk)
723 $(warning kBuild: SDK_$(sdk) was not defined by $(SDK_$(sdk)_KMK_FILE)!)
724 endif
[72]725endif
[985]726endef # def_sdks_include_one
[460]727
[859]728_SDKS := $(sort $(_SDKS))
[353]729$(foreach sdk, $(_SDKS), $(eval $(value def_sdks_include_one)))
[72]730
[985]731## @todo Execute SDKS and TOOL inhertiance.
[380]732
[988]733ifdef KBUILD_PROFILE_SELF
734 _KBUILD_TS_NOW := $(nanots )
735 $(info prof: $(int-sub $(_KBUILD_TS_NOW), $(_KBUILD_TS_HEADER_START)) - $(int-sub $(_KBUILD_TS_NOW), $(_KBUILD_TS_PREV)) - done tools and sdks)
736 _KBUILD_TS_PREV := $(_KBUILD_TS_NOW)
737endif
[640]738
[988]739
[828]740#
741#
742# Target lists - Pass 1
743#
744# This pass is for defining variables that might be referenced in
745# properties of other targets.
746#
747#
748
749# Don't do anything for fetch targets (yet).
750
751##
752# Link prolog for Pass 1.
753#
754# @param $(target) Normalized target name.
755# @param $(EXT) EXE,DLL,SYS,LIB.
756# @param $(EXTPRE) HOST or nothing.
757# @param $(definst) The default _INST value.
758# @param $(tool_prefix) LD or AR.
759# @param $(bld_trg_base_var) TARGET or PLATFORM.
760define def_pass1_link_common
761
762bld_type := $(firstword $($(target)_BLD_TYPE) $(BUILD_TYPE))
763bld_trg := $(firstword $($(target)_BLD_TRG) $(BUILD_$(bld_trg_base_var)))
764bld_trg_arch:= $(firstword $($(target)_BLD_TRG_ARCH) $(BUILD_$(bld_trg_base_var)_ARCH))
765bld_trg_cpu := $(firstword $($(target)_BLD_TRG_CPU) $(BUILD_$(bld_trg_base_var)_CPU))
766
[889]767tool := $(call _TARGET_TOOL,$(target),$(tool_prefix))
768name := $(firstword\
769 $($(target)_NAME.$(bld_trg).$(bld_trg_arch))\
770 $($(target)_NAME.$(bld_trg_arch))\
771 $($(target)_NAME.$(bld_trg))\
772 $($(target)_NAME.$(bld_type))\
773 $($(target)_NAME)\
774 $(target))
775outbase := $(call TARGET_BASE,$(name),$(target))
[828]776ifndef PATH_$(target)
777 PATH_$(target) := $(patsubst %/,%,$(dir $(outbase)))
778else ifneq ($(PATH_$(target)),$(patsubst %/,%,$(dir $(outbase))))
779 $(error kBuild internal error: PATH_$(target)=$(PATH_$(target)) expected $(patsubst %/,%,$(dir $(outbase))))
780endif
781ifeq ($(tool_prefix),AR) ## @todo fix this mess!
782suff := $(firstword\
783 $($(target)_$(EXT)SUFF.$(bld_trg).$(bld_trg_arch))\
784 $($(target)_$(EXT)SUFF.$(bld_trg))\
785 $($(target)_$(EXT)SUFF)\
786 $(TOOL_$(tool)_$(tool_prefix)$(EXT)SUFF.$(bld_trg).$(bld_trg_arch))\
787 $(TOOL_$(tool)_$(tool_prefix)$(EXT)SUFF.$(bld_trg))\
788 $(TOOL_$(tool)_$(tool_prefix)$(EXT)SUFF)\
789 $(SUFF_LIB))
790else
791suff := $(firstword \
792 $($(target)_$(EXT)SUFF) \
793 $($(target)_$(EXT)SUFF) \
794 $(TOOL_$(tool)_$(tool_prefix)$(EXT)SUFF) \
795 $($(EXTPRE)SUFF_$(EXT)))
796endif
797out := $(outbase)$(suff)
798
799# TARGET_*
800TARGET_$(target) := $(out)
801
802# INSTARGET_*
803ifndef $(target)_NOINST
804INSTARGET_$(target) := $(patsubst %/,%/$(notdir $(out)), \
805 $(if $($(target)_INST), $(addprefix $(PATH_INS)/,$($(target)_INST)), $(definst)/))
806
807else # NOINST
808INSTARGET_$(target) :=
809endif # NOINST
810
811endef
812
813
814#
815# BLDPROGS (Pass 1)
816#
817define def_pass1_bldprog
818# set NOINST if not forced installation before doing the usual stuff.
819ifndef $(target)_INST
820$(target)_NOINST := 1
821endif
822$(eval $(value def_pass1_link_common))
823endef
824
825EXT := EXE
826EXTPRE := HOST
827definst := $(PATH_BIN)
828tool_prefix := LD
829bld_trg_base_var := PLATFORM
830$(foreach target, $(BLDPROGS) $(BLDPROGS.$(BUILD_PLATFORM)) $(BLDPROGS.$(BUILD_PLATFORM).$(BUILD_PLATFORM_ARCH)), \
831 $(eval $(value def_pass1_bldprog)))
832
833
834#
835# LIBRARIES (Pass 1)
836#
837EXT := LIB
838EXTPRE :=
839definst := $(PATH_LIB)
840tool_prefix := AR
841bld_trg_base_var := TARGET
842$(foreach target, $(LIBRARIES) $(LIBRARIES.$(BUILD_TARGET)) $(LIBRARIES.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)), \
843 $(eval $(value def_pass1_link_common)))
844
845
846#
847# DLLS (Pass 1)
848#
849EXT := DLL
850EXTPRE :=
851definst := $(PATH_DLL)
852tool_prefix := LD
853bld_trg_base_var := TARGET
854$(foreach target, $(DLLS) $(DLLS.$(BUILD_TARGET)) $(DLLS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)), \
855 $(eval $(value def_pass1_link_common)))
856
857
858#
859# IMPORT LIBRARIES (Pass 1)
860#
861# - On OS/2 and windows these are libraries.
862# - On other platforms they are fake DLLs.
863#
[1260]864if1of ($(BUILD_TARGET), nt os2 win win64 win32)
[828]865 EXT := LIB
866 EXTPRE :=
867 definst := $(PATH_LIB)
868 tool_prefix := AR
869 bld_trg_base_var := TARGET
870 $(foreach target, $(IMPORT_LIBS) $(IMPORT_LIBS.$(BUILD_TARGET)) $(IMPORT_LIBS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)), \
[1260]871 $(eval $(value def_pass1_link_common)))
[828]872else
873 EXT := DLL
874 EXTPRE :=
875 definst := $(PATH_DLL)
876 tool_prefix := LD
877 bld_trg_base_var := TARGET
878 $(foreach target, $(IMPORT_LIBS) $(IMPORT_LIBS.$(BUILD_TARGET)) $(IMPORT_LIBS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)), \
879 $(eval $(value def_pass1_link_common)))
880endif
881
882
883#
884# PROGRAMS (Pass 1)
885#
886EXT := EXE
887EXTPRE :=
888definst := $(PATH_BIN)
889tool_prefix := LD
890bld_trg_base_var := TARGET
891$(foreach target, $(PROGRAMS) $(PROGRAMS.$(BUILD_TARGET)) $(PROGRAMS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)), \
892 $(eval $(value def_pass1_link_common)))
893
894
895#
896# SYSMODS (Pass 1)
897#
898EXT := SYS
899EXTPRE :=
900definst := $(PATH_SYS)
901tool_prefix := LD
902bld_trg_base_var := TARGET
903$(foreach target, $(SYSMODS) $(SYSMODS.$(BUILD_TARGET)) $(SYSMODS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)), \
904 $(eval $(value def_pass1_link_common)))
905
906
907#
908# INSTALLS (Pass 1)
909# Note! INSTARGET_* for INSTALLS aren't available until later.
910#
911define def_pass1_install
[985]912bld_type := $(firstword $($(target)_BLD_TYPE) $(BUILD_TYPE))
913bld_trg := $(firstword $($(target)_BLD_TRG) $(BUILD_TARGET))
[828]914bld_trg_arch:= $(firstword $($(target)_BLD_TRG_ARCH) $(BUILD_TARGET_ARCH))
915bld_trg_cpu := $(firstword $($(target)_BLD_TRG_CPU) $(BUILD_TARGET_CPU))
916# TARGET_*
917TARGET_$(target) := $(PATH_TARGET)/$(target).ins
918# INSTARGET_ later.
919endef
920$(foreach target, $(INSTALLS) $(INSTALLS.$(BUILD_TARGET)) $(INSTALLS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)), \
921 $(eval $(value def_pass1_install)))
922
[988]923ifdef KBUILD_PROFILE_SELF
924 _KBUILD_TS_NOW := $(nanots )
925 $(info prof: $(int-sub $(_KBUILD_TS_NOW), $(_KBUILD_TS_HEADER_START)) - $(int-sub $(_KBUILD_TS_NOW), $(_KBUILD_TS_PREV)) - done pass 1)
926 _KBUILD_TS_PREV := $(_KBUILD_TS_NOW)
927endif
[828]928
929
930
[988]931
[828]932#
933#
934# Target lists - Pass 2
935#
936#
937
938
[688]939## @page pg_fetches Fetching Tools, Sources and Similar.
[73]940#
[688]941# The targets listed in the the FETCHES target list have the following attributes:
942# SOURCES
943# INST
944# FETCHTOOL
945# FETCHFLAGS
946# FETCHDIR
947# UNPACKTOOL
948# UNPACKFLAGS
[640]949#
[719]950# As usual the target name is an alias for 'creating' the target. Other
[688]951# aliases are:
952# pass_fetches
953# fetch
954# unfetch
955# download
956# unpack
957#
958# @remark
959#
960# This is a little bit complex because we must guarantee that if a source file
[719]961# changes only sligtly we must refetch it and to a proper unpacking of it. It
962# is also a desire that fetched archives and unpacked files can be deleted to
[688]963# save space.
964#
[719]965# Thus, we must be able to cleanup what we've unpacked should any of the
[688]966# sources be removed. We do this by maintaining a file listing the files
967# and directories that was unpacked. This operation is named 'unfetch'.
968#
[719]969# We make use of the SIZE and MD5 attributes for each of the sources to
[689]970# create a digest that is stored in the primary target file. Subsequent
971# runswill compare their digest with it to decide if a refetch is required.
[719]972# When a refetch is found necessary, an 'unfetch' is performed first to
[689]973# clean out old files and directores. Note even changes in source order
[719]974# will cause a refetch due to the way the digest is constructed and
[689]975# evaluated.
[688]976#
977# By not depending directly on the archives (nor on any unpacked files)
978# but on a goal made up from the archive name, size and md5, we allow
979# the user to delete the archives. Naturally, this means we'll have to
980# check and fetch missing archives before attempting to unpack them.
[689]981#
982# @remark
983#
[719]984# This feature will *NOT* work correctly with vanilla GNU make becuase
[689]985# it makes use of includedep to avoid too many unnecessary files.
[719]986#
[689]987# @todo
[1255]988# 1. Download corruption / continuation.
989# 2. It's quite possible that there is one too many indirect dependency now...
[688]990#
991
[640]992## generates the fetch rule
993define def_fetch_src_fetch_rule
994# Indirect goal for downloading something.
[682]995.PRECIOUS: $(out)
[1030]996$(out) + $($(target)_$(srcname)_FETCH_OUTPUT_) +| $($(target)_$(srcname)_FETCH_OUTPUT_MAYBE_) : \
997 | $($(target)_$(srcname)_FETCH_DEPORD_)
[776]998 $$(call MSG_FETCH_DL,$(target),$(source),$(out))
[696]999 @## @todo do fancy stuff like download continuation.
[1255]1000 $$(QUIET)$$(RM) -f $(out)
[640]1001 $($(target)_$(srcname)_FETCH_CMDS_)
[1255]1002 $$(QUIET)$(if $(md5),$$(MD5SUM_EXT) -b -C $(md5) $(out))
[640]1003
1004
[682]1005
[640]1006# Intermediate goal for making sure the md5 and size matches. it will (re) fetch the archive if necessary.
1007$(out).checked_$(md5)_$(size): $($(target)_$(srcname)_FETCH_DEPEND_) | $($(target)_$(srcname)_FETCH_DEPORD_)
[776]1008 $$(call MSG_FETCH_CHK,$(target),$(source),$(out))
[1255]1009 $$(QUIET)$$(RM) -f $$@
[688]1010 @# (re)fetch the file if it doesn't exist or if it doesn't matches the md5.
[696]1011 @## @todo do fancy stuff like download continuation.
[1255]1012 $$(QUIET)( test -f $(out) && $(if $(md5),$$(MD5SUM_EXT) -b -C $(md5) $(out), true) ) \
[696]1013 || ( $$(RM_EXT) -f $(out) \
1014 && $$(MAKE) $(out) -f $(MAKEFILE) --no-print-directory )
1015 $$(QUIET2)$$(APPEND) $$@
[640]1016
[719]1017_TARGET_$(target)_FETCHED += $(out) $(out).checked_$(md5)_$(size)
[640]1018
[688]1019# Just a little precaution.
1020.NOTPARALLEL: $(out) $(out).checked_$(md5)_$(size)
1021
[640]1022endef
1023
1024## generates the unpack rule
1025define def_fetch_src_unpack_rule
1026# This is the unpack rule. it has an order-only dependency on the download check.
[1030]1027$(out) + $($(target)_$(srcname)_UNPACK_OUTPUT_) +| $($(target)_$(srcname)_UNPACK_OUTPUT_MAYBE_) : \
1028 $($(target)_$(srcname)_UNPACK_DEPEND_) \
[640]1029 | $($(target)_$(srcname)_UNPACK_DEPORD_) $(archive).checked_$(md5)_$(size)
[776]1030 $$(call MSG_FETCH_UP,$(target),$(archive),$(inst))
[696]1031 $$(QUIET)$$(RM) -f $(out)
[688]1032 @# if the source archive doesn't exist fetch it (can have been deleted to save space).
[696]1033 $$(QUIET)test -f $(archive) \
1034 || ( $$(RM_EXT) -f $(archive).checked_$(md5)_$(size) \
1035 && $$(MAKE) $(archive).checked_$(md5)_$(size) -f $(MAKEFILE) --no-print-directory )
[640]1036 $($(target)_$(srcname)_UNPACK_CMDS_)
[696]1037 $$(QUIET2)$$(APPEND) $(out) $(notdir $(archive).checked_$(md5)_$(size))
1038 $$(QUIET2)$$(APPEND) $(out) $(notdir $(out))
[640]1039
1040$(eval _TARGET_$(target)_UNPACKED += $(out))
1041_TARGET_$(target)_DIGEST := $(_TARGET_$(target)_DIGEST)-$(srcname)_$(md5)_$(size)
1042
[688]1043.NOTPARALLEL: $(out)
1044
[719]1045endef
[640]1046
1047## Processes a fetch source
1048#
1049define def_fetch_src
1050#$ (warning dbg: def_fetch_src: source='$(source)' target='$(target)')
1051
1052# common
1053srcname := $(notdir $(source))
1054inst := $(firstword \
1055 $($(target)_$(source)_INST)\
1056 $($(target)_$(srcname)_INST)\
1057 $($(source)_INST)\
1058 $($(srcname)_INST)\
1059 $($(target)_INST)\
1060)
1061ifneq ($(patsubst %/,ok,$(inst)),ok)
1062$(error kBuild: Bad or missing INST property for source '$(source)' in target '$(target)': $(inst))
1063endif
1064INSTARGET_$(target)_$(srcname) := $(inst)
1065fetchdir := $(firstword \
1066 $($(target)_$(source)_FETCHDIR)\
1067 $($(target)_$(srcname)_FETCHDIR)\
1068 $($(source)_FETCHDIR)\
1069 $($(srcname)_FETCHDIR)\
1070 $($(target)_FETCHDIR)\
1071 $(FETCHDIR)\
1072 $(PATH_TARGET)\
1073)
1074deps := \
1075 $($(target)_$(source)_DEPS)\
1076 $($(target)_$(srcname)_DEPS)\
1077 $($(source)_DEPS)\
1078 $($(srcname)_DEPS)\
1079 $($(target)_DEPS)
[827]1080orderdeps := \
1081 $($(target)_$(source)_ORDERDEPS)\
1082 $($(target)_$(srcname)_ORDERDEPS)\
1083 $($(source)_ORDERDEPS)\
1084 $($(srcname)_ORDERDEPS)\
1085 $($(target)_ORDERDEPS)
[640]1086md5 := $(firstword \
1087 $($(target)_$(source)_MD5)\
1088 $($(target)_$(srcname)_MD5)\
1089 $($(source)_MD5)\
1090 $($(srcname)_MD5)\
1091 $($(target)_MD5)\
1092)
1093size := $(firstword \
1094 $($(target)_$(source)_SIZE)\
1095 $($(target)_$(srcname)_SIZE)\
1096 $($(source)_SIZE)\
1097 $($(srcname)_SIZE)\
1098 $($(target)_SIZE)\
1099)
1100dep := # not legal for fetch and unpack tools
1101
1102
1103#
1104# The fetching.
1105#
1106out := $(fetchdir)/$(srcname)
1107archive := $(out)
1108TARGET_$(target)_$(srcname) := $(out)
1109dirdep := $(call DIRDEP,$(fetchdir))
1110tool := $(firstword \
1111 $($(target)_$(source)_FETCHTOOL)\
1112 $($(target)_$(srcname)_FETCHTOOL)\
1113 $($(target)_$(source)_TOOL)\
1114 $($(target)_$(srcname)_TOOL)\
1115 $($(source)_FETCHTOOL)\
1116 $($(srcname)_FETCHTOOL)\
1117 $($(source)_TOOL)\
1118 $($(srcname)_TOOL)\
1119 $($(target)_FETCHTOOL)\
1120 $($(target)_TOOL)\
1121 )
1122flags :=\
1123 $(TOOL_$(tool)_FETCHFLAGS)\
1124 $(FETCHFLAGS)\
1125 $($(target)_FETCHFLAGS)\
1126 $($(srcname)_FETCHFLAGS)\
1127 $($(source)_FETCHFLAGS)\
1128 $($(target)_$(srcname)_FETCHFLAGS)\
1129 $($(target)_$(source)_FETCHFLAGS)
1130
1131#$ (warning dbg: target=$(target) source=$(source) $(srcname)=$(srcname) tool=$(tool) out=$(out) flags=$(flags) dirdep=$(dirdep) fetchdir=$(fetchdir) md5=$(md5) size=$(size))
1132
1133ifndef TOOL_$(tool)_FETCH_CMDS
1134$(warning kBuild: tools: \
1135 1 $($(target)_$(source)_FETCHTOOL)\
1136 2 $($(target)_$(srcname)_FETCHTOOL)\
1137 3 $($(target)_$(source)_TOOL)\
1138 4 $($(target)_$(srcname)_TOOL)\
1139 5 $($(source)_FETCHTOOL)\
1140 6 $($(srcname)_FETCHTOOL)\
1141 7 $($(source)_TOOL)\
1142 8 $($(srcname)_TOOL)\
1143 9 $($(target)_FETCHTOOL)\
1144 10 $($(target)_TOOL) )
1145$(error kBuild: TOOL_$(tool)_FETCH_CMDS is not defined. source=$(source) target=$(target) )
1146endif
1147
1148# call the tool
1149$(target)_$(srcname)_FETCH_CMDS_ := $(TOOL_$(tool)_FETCH_CMDS)
1150$(target)_$(srcname)_FETCH_OUTPUT_ := $(TOOL_$(tool)_FETCH_OUTPUT)
[1030]1151$(target)_$(srcname)_FETCH_OUTPUT_MAYBE_ := $(TOOL_$(tool)_FETCH_OUTPUT_MAYBE)
[640]1152$(target)_$(srcname)_FETCH_DEPEND_ := $(TOOL_$(tool)_FETCH_DEPEND) $(deps)
[827]1153$(target)_$(srcname)_FETCH_DEPORD_ := $(TOOL_$(tool)_FETCH_DEPORD) $(dirdep) $(orderdeps)
[640]1154
1155# generate the fetch rule.
1156$(eval $(def_fetch_src_fetch_rule))
1157
1158
1159#
1160# The unpacking / installing.
1161#
1162out := $(inst)_kBuild_$(target)_$(srcname)_unpacked.lst
1163dirdep := $(call DIRDEP,$(inst))
1164tool := $(firstword \
1165 $($(target)_$(source)_UNPACKTOOL)\
1166 $($(target)_$(srcname)_UNPACKTOOL)\
1167 $($(target)_$(source)_TOOL)\
1168 $($(target)_$(srcname)_TOOL)\
1169 $($(source)_UNPACKTOOL)\
1170 $($(srcname)_UNPACKTOOL)\
1171 $($(source)_TOOL)\
1172 $($(srcname)_TOOL)\
1173 $($(target)_UNPACKTOOL)\
1174 $($(target)_TOOL) \
1175 )
1176ifeq ($(tool),)
1177tool := $(toupper $(subst .,,$(suffix $(subst tar.,TAR,$(srcname)))))
1178$(eval $(value def_tools_include))
1179endif
1180flags :=\
1181 $(TOOL_$(tool)_UNPACKFLAGS)\
1182 $(UNPACKFLAGS)\
1183 $($(target)_UNPACKFLAGS)\
1184 $($(srcname)_UNPACKFLAGS)\
1185 $($(source)_UNPACKFLAGS)\
1186 $($(target)_$(srcname)_UNPACKFLAGS)\
1187 $($(target)_$(source)_UNPACKFLAGS)
1188
1189#$ (warning dbg: target=$(target) source=$(source) $(srcname)=$(srcname) tool=$(tool) out=$(out) flags=$(flags) dirdep=$(dirdep) inst=$(inst) md5=$(md5) size=$(size))
1190ifndef TOOL_$(tool)_UNPACK_CMDS
1191$(warning kBuild: tools: \
1192 1 $($(target)_$(source)_UNPACKTOOL)\
1193 2 $($(target)_$(srcname)_UNPACKTOOL)\
1194 3 $($(target)_$(source)_TOOL)\
1195 4 $($(target)_$(srcname)_TOOL)\
1196 5 $($(source)_UNPACKTOOL)\
1197 6 $($(srcname)_UNPACKTOOL)\
1198 7 $($(source)_TOOL)\
1199 8 $($(srcname)_TOOL)\
1200 9 $($(target)_UNPACKTOOL)\
1201 10 $($(target)_TOOL) \
1202 11 $(toupper $(subst tar.,TAR,$(ext $(srcname)))) \
1203 )
1204$(error kBuild: TOOL_$(tool)_UNPACK_CMDS is not defined. source=$(source) target=$(target) )
1205endif
1206
1207# call the tool
1208$(target)_$(srcname)_UNPACK_CMDS_ := $(TOOL_$(tool)_UNPACK_CMDS)
1209$(target)_$(srcname)_UNPACK_OUTPUT_ := $(TOOL_$(tool)_UNPACK_OUTPUT)
[1030]1210$(target)_$(srcname)_UNPACK_OUTPUT_MAYBE_ := $(TOOL_$(tool)_UNPACK_OUTPUT_MAYBE)
[640]1211$(target)_$(srcname)_UNPACK_DEPEND_ := $(TOOL_$(tool)_UNPACK_DEPEND) $(deps)
[827]1212$(target)_$(srcname)_UNPACK_DEPORD_ := $(TOOL_$(tool)_UNPACK_DEPORD) $(dirdep) $(orderdeps)
[640]1213
1214# generate the fetch rule.
1215$(eval $(def_fetch_src_unpack_rule))
1216
1217_DIRS += $(inst) $(fetchdir)
1218
1219endef
1220
1221
1222##
1223# Define the target level rules for a fetch.
1224# @param target
1225# @param out
1226# @param inst
[688]1227# @param _TARGET_$(target)_UNPACKED
1228# @param _TARGET_$(target)_DIGEST
[640]1229# @param bld_trg
1230# @param bld_trg_arch
1231define def_fetch_rules
1232
[689]1233$(out).lst: $(_TARGET_$(target)_UNPACKED) | $(call DIRDEP,$(inst))
[776]1234 $$(call MSG_FETCH_OK,$(target))
[696]1235 $$(QUIET)$$(RM) -f $$@ $$@.tmp
[1311]1236 $$(QUIET2)$$(APPEND) $$@.tmp '$(notdir $(out))'
[696]1237 $$(QUIET)$(if $(_TARGET_$(target)_UNPACKED),$$(CAT_EXT) $(_TARGET_$(target)_UNPACKED) >> $$@.tmp)
1238 $$(QUIET)$$(MV) -f $$@.tmp $$@
[640]1239
1240$(out)_unfetched:
[776]1241 $$(call MSG_UNFETCH,$(target))
[696]1242 $$(QUIET)$$(RM) -f $$(addprefix $(inst),$$(shell $$(CAT_EXT) $(out).lst 2> /dev/null | $$(SED) -e '/\/$$$$/d'))
1243 $$(QUIET)$$(RMDIR) -p --ignore-fail-on-non-empty --ignore-fail-on-not-exist $$(dir $$@) \
[689]1244 $$(addprefix $(inst),$$(sort $$(dir $$(shell $$(CAT_EXT) $(out).lst 2> /dev/null))))
[696]1245 $$(QUIET)$$(RM) -f $(out).lst $(out)
1246 $$(QUIET)$$(RMDIR) -p --ignore-fail-on-non-empty --ignore-fail-on-not-exist $$(dir $$@)
[640]1247
[689]1248$(out): $(comp-vars _TARGET_$(target)_DIGEST_PREV,_TARGET_$(target)_DIGEST,FORCE) | $(call DIRDEP,$(inst))
[696]1249 $$(QUIET)$$(RM) -f $$@
[776]1250 $$(if $$(_TARGET_$(target)_DIGEST),$$(if $$(wildcard $(out).lst)\
1251 ,$$(call MSG_REFETCH,$(target)),$$(call MSG_FETCH,$(target))),$$(call MSG_UNFETCH,$(target)))
[696]1252 $$(QUIET)$$(if $$(wildcard $(out).lst ),$$(MAKE) -f $(MAKEFILE) --no-print-directory $(out)_unfetched)
[701]1253 $$(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]1254 $$(QUIET2)$$(if $$(_TARGET_$(target)_DIGEST),$$(APPEND) $$@ "_TARGET_$(target)_DIGEST_PREV := $(_TARGET_$(target)_DIGEST)")
[760]1255
[689]1256.NOTPARALLEL: $(out).lst $(out)_unfetched $(out)
[688]1257
[640]1258endef
1259
1260
1261##
1262# Deal with one fetch target.
1263# @param target
1264# @param bld_trg
1265# @param bld_trg_arch
1266define def_fetch
1267# common
1268INSTARGET_$(target) := $($(target)_INST)
1269ifneq ($(patsubst %/,ok,$(INSTARGET_$(target))),ok)
[679]1270$(error kBuild: Bad or missing INST property for target '$(target)'. \
1271 $(target)_INST='$($(target)_INST)' ($(origin $(target)_INST)))
[640]1272endif
1273_TARGET_$(target)_FETCHED :=
1274_TARGET_$(target)_UNPACKED :=
1275_TARGET_$(target)_DIGEST :=
1276
1277# The 'sources'.
1278#$ (warning dbg fetch: target=$(target) sources=$($(target)_SOURCES) $($(target)_SOURCES.$(BUILD_TYPE)) $($(target)_SOURCES.$(BUILD_TARGET)) $($(target)_SOURCES.$(BUILD_TARGET_ARCH)) $($(target)_SOURCES.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)))
1279$(foreach source,$($(target)_SOURCES) $($(target)_SOURCES.$(BUILD_TYPE)) $($(target)_SOURCES.$(BUILD_TARGET)) $($(target)_SOURCES.$(BUILD_TARGET_ARCH)) $($(target)_SOURCES.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)),\
1280 $(eval $(value def_fetch_src)))
1281
1282# The target.
1283inst := $(INSTARGET_$(target))
1284out := $(inst)_kBuild_fetch_$(target)
1285
[689]1286$(eval includedep $(out))
[690]1287
[640]1288$(eval $(def_fetch_rules))
1289
[690]1290# Define the aliases here (doesn't work if defined in def_fetch_rules, just like includedep).
[749]1291$(target): $(out)
1292$(target)_unfetch: $(out)_unfetched
[690]1293
[689]1294_FETCHES += $(out)
[640]1295_DOWNLOADS += $(_TARGET_$(target)_FETCHED)
1296_UNPACKS += $(_TARGET_$(target)_UNPACKED)
1297_UNFETCHES += $(out)_unfetched
1298_DIRS += $(inst)
1299
1300endef
1301
1302# Walk the FETCH target lists.
1303bld_trg := $(BUILD_TARGET)
1304bld_trg_arch := $(BUILD_TARGET_ARCH)
1305$(foreach target, $(FETCHES) $(FETCHES.$(BUILD_TARGET)) $(FETCHES.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)), \
1306 $(eval $(value def_fetch)))
1307
1308# some aliases.
1309download: $(_DOWNLOADS)
[688]1310unpack: $(_UNPACKS)
1311fetch: $(_FETCHES)
1312unfetch: $(_UNFETCHES)
[640]1313
[988]1314ifdef KBUILD_PROFILE_SELF
1315 _KBUILD_TS_NOW := $(nanots )
1316 $(info prof: $(int-sub $(_KBUILD_TS_NOW), $(_KBUILD_TS_HEADER_START)) - $(int-sub $(_KBUILD_TS_NOW), $(_KBUILD_TS_PREV)) - done fetching targets)
1317 _KBUILD_TS_PREV := $(_KBUILD_TS_NOW)
1318endif
[640]1319
1320
[988]1321
[640]1322##
1323## Patching.
1324##
1325##
[688]1326#define def_patch_src
[640]1327#
1328#endef
1329#
1330#
1331## Deal with one patch target.
1332#define def_patch
1333#
1334#$(foreach source,$($(target)_SOURCES) $($(target)_SOURCES.$(BUILD_TYPE)) $($(target)_SOURCES.$(BUILD_TARGET)) $($(target)_SOURCES.$(BUILD_TARGET_ARCH)) $($(target)_SOURCES.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)),\
[688]1335# $(eval $(value def_patch_src)))
[640]1336#
[719]1337#_PATCHES +=
[640]1338#endef
1339#
1340#$(foreach target, $(PATCHES) $(PATCHES.$(BUILD_TARGET)) $(PATCHES.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)), \
1341# $(eval $(value def_patch)))
1342#
1343
1344
1345#
[73]1346# Object processing.
1347#
[72]1348
[380]1349## wrapper the compile command dependency check.
1350ifndef NO_COMPILE_CMDS_DEPS
[741]1351 _DEP_COMPILE_CMDS = $(comp-cmds $(target)_$(source)_CMDS_PREV_,$(target)_$(source)_CMDS_,FORCE)
[380]1352else
[730]1353 _DEP_COMPILE_CMDS =
[380]1354endif
1355
[749]1356## Generates the rules for building a specific object, and the aliases
[380]1357# for building a source file.
[353]1358# @param $(obj) The object file.
[380]1359define def_target_source_rule
[1025]1360
[1012]1361ifdef TOOL_$(tool)_COMPILE_$(type)_USES_KOBJCACHE
[1030]1362$(outbase).koc +| $(obj) $($(target)_$(source)_OUTPUT_) $($(target)_$(source)_OUTPUT_MAYBE_) : \
[1007]1363 $($(target)_$(source)_DEPEND_) \
1364 $(_DEP_COMPILE_CMDS) \
1365 | \
1366 $($(target)_$(source)_DEPORD_)
1367 $$(call MSG_COMPILE,$(target),$(source),$$@,$(type))
1368else
[1030]1369$(obj) + $($(target)_$(source)_OUTPUT_) +| $($(target)_$(source)_OUTPUT_MAYBE_) : \
[380]1370 $($(target)_$(source)_DEPEND_) \
1371 $(_DEP_COMPILE_CMDS) \
1372 | \
1373 $($(target)_$(source)_DEPORD_)
[776]1374 $$(call MSG_COMPILE,$(target),$(source),$$@,$(type))
[1012]1375ifdef TOOL_$(tool)_COMPILE_$(type)_DONT_PURGE_OUTPUT
[1030]1376 $$(QUIET)$$(RM) -f $(dep) $(obj) $($(target)_$(source)_OUTPUT_) $($(target)_OUTPUT_MAYBE_)
[1007]1377endif
[1012]1378endif
[412]1379
[380]1380$($(target)_$(source)_CMDS_)
1381
1382ifndef NO_COMPILE_CMDS_DEPS
[1311]1383 $$(QUIET2)$$(APPEND) '$(dep)'
1384 $$(QUIET2)$$(APPEND) '$(dep)' 'define $(target)_$(source)_CMDS_PREV_'
1385 $$(QUIET2)$$(APPEND) -v '$(dep)' '$(target)_$(source)_CMDS_'
1386 $$(QUIET2)$$(APPEND) '$(dep)' 'endef'
[770]1387endif
[380]1388
[749]1389$(basename $(notdir $(obj))).o: $(obj)
1390$(basename $(notdir $(obj))).obj: $(obj)
[353]1391endef
[205]1392
[353]1393
[380]1394## wrapper the link command dependency check.
1395ifndef NO_COMPILE_CMDS_DEPS
[741]1396 _DEP_LINK_CMDS = $(comp-cmds $(target)_CMDS_PREV_,$(target)_CMDS_,FORCE)
[380]1397else
[730]1398 _DEP_LINK_CMDS =
[380]1399endif
1400
1401## Generate the link rule for a target.
1402# @param $(target) The normalized target name.
1403# @param $(dirdep) Directories we depend upon begin created before linking.
1404# @param $(dep) The name of the dependency file.
1405# @param $(out)
1406# @param $($(target)_OUTPUT_) Output files from the link.
[1030]1407# @param $($(target)_OUTPUT_MAYBE_) Output files that the link may perhaps create.
[380]1408# @param $($(target)_DEPEND_) Dependencies.
1409# @param $($(target)_DEPORD_) Dependencies which should only affect build order.
1410# @param $($(target)_CMDS_) The link commands.
1411# @param $($(target)_CMDS_PREV_) The link commands from the previous run.
1412define def_link_rule
[1030]1413$(out) + $($(target)_OUTPUT_) +| $($(target)_OUTPUT_MAYBE_) : \
[380]1414 $($(target)_DEPEND_) \
1415 $(_DEP_LINK_CMDS) \
1416 | \
1417 $($(target)_DEPORD_)
[776]1418 $$(call MSG_LINK,$(target),$$@,$(tool_do))
[1030]1419 $$(QUIET)$$(RM) -f $(dep) $(out) $($(target)_OUTPUT_) $($(target)_OUTPUT_MAYBE_)
[412]1420
[380]1421$($(target)_CMDS_)
1422
[524]1423ifndef NO_LINK_CMDS_DEPS
[1311]1424 $$(QUIET2)$$(APPEND) '$(dep)' 'define $(target)_CMDS_PREV_'
1425 $$(QUIET2)$$(APPEND) -v '$(dep)' '$(target)_CMDS_'
1426 $$(QUIET2)$$(APPEND) '$(dep)' 'endef'
[770]1427endif
[380]1428
[749]1429$(basename $(notdir $(out))): $(out)
[719]1430
[380]1431endef
1432
1433
1434## Generate the link & lib install rule
1435# @param $(target) Normalized target name.
1436# @param $(out) The build target.
1437# @param $(INSTARGET_$(target)) The installation targets.
1438# @param $(mode) The file mode (optional)
1439define def_link_install_rule
1440$(INSTARGET_$(target)) : $(out) | $(call DIRDEP,$(dir $(INSTARGET_$(target))))
[776]1441 $$(call MSG_INST_TRG,$(target),$(out),$$@)
[696]1442 $$(QUIET)$$(INSTALL) $$(if $(mode),-m $(mode)) $(out) $$@
[719]1443
1444ifdef KBUILD_DO_AUTO_INSTALL
[749]1445$(basename $(notdir $(out))): $(INSTARGET_$(target))
[719]1446endif
[380]1447endef
1448
1449
[73]1450## Generic macro for processing C, C++ and Assembly sources.
1451# @param $(target) Normalized target name.
1452# @param $(source) Source file name.
[1256]1453# @param $(type) Source type. {C,CXX,AS,OBJC}
[221]1454# @param bld_type Build type.
1455# @param bld_trg Build target.
1456# @param bld_trg_arch Build target arch.
1457# @param bld_trg_cpu Build target cpu.
[1256]1458def_target_source_c_cpp_objc_asm_rc_new = $(kb-src-one )
[741]1459ifdef KMK_VERSION
[1256]1460 def_target_source_c_cpp_objc_asm_rc_var = def_target_source_c_cpp_objc_asm_rc_new
[530]1461else
[1256]1462 def_target_source_c_cpp_objc_asm_rc_var = def_target_source_c_cpp_objc_asm_rc_old
[530]1463endif
1464
[73]1465## Generic macro for processing all target sources.
[74]1466# @param $(target) Normalized target name.
[725]1467# @param $(defpath)
1468# @param much-more...
[73]1469define def_target_sources
1470#$ (warning def_target_sources)
1471# C sources
[353]1472type := C
[481]1473$(foreach source, $(filter %.c , $($(target)_SOURCES) $($(target)_SOURCES.$(bld_trg)) $($(target)_SOURCES.$(bld_trg).$(bld_trg_arch)) $($(target)_SOURCES.$(bld_trg_arch)) $($(target)_SOURCES.$(bld_trg_cpu)) $($(target)_SOURCES.$(bld_type)))\
[1256]1474 ,$(eval $(value $(def_target_source_c_cpp_objc_asm_rc_var))) )
[73]1475
1476# C++ sources
[353]1477type := CXX
[481]1478$(foreach source, $(filter %.cpp %.cxx %.xx, $($(target)_SOURCES) $($(target)_SOURCES.$(bld_trg)) $($(target)_SOURCES.$(bld_trg).$(bld_trg_arch)) $($(target)_SOURCES.$(bld_trg_arch)) $($(target)_SOURCES.$(bld_trg_cpu)) $($(target)_SOURCES.$(bld_type)))\
[1256]1479 ,$(eval $(value $(def_target_source_c_cpp_objc_asm_rc_var))) )
[73]1480
[1256]1481# Objective-C sources
1482type := OBJC
1483$(foreach source, $(filter %.m, $($(target)_SOURCES) $($(target)_SOURCES.$(bld_trg)) $($(target)_SOURCES.$(bld_trg).$(bld_trg_arch)) $($(target)_SOURCES.$(bld_trg_arch)) $($(target)_SOURCES.$(bld_trg_cpu)) $($(target)_SOURCES.$(bld_type)))\
1484 ,$(eval $(value $(def_target_source_c_cpp_objc_asm_rc_var))) )
1485
[73]1486# ASM sources
[353]1487type := AS
[481]1488$(foreach source, $(filter %.asm %.s %.S , $($(target)_SOURCES) $($(target)_SOURCES.$(bld_trg)) $($(target)_SOURCES.$(bld_trg).$(bld_trg_arch)) $($(target)_SOURCES.$(bld_trg_arch)) $($(target)_SOURCES.$(bld_trg_cpu)) $($(target)_SOURCES.$(bld_type)))\
[1256]1489 ,$(eval $(value $(def_target_source_c_cpp_objc_asm_rc_var))) )
[353]1490
[641]1491# Resource sources
1492type := RC
1493$(foreach source, $(filter %.rc , $($(target)_SOURCES) $($(target)_SOURCES.$(bld_trg)) $($(target)_SOURCES.$(bld_trg).$(bld_trg_arch)) $($(target)_SOURCES.$(bld_trg_arch)) $($(target)_SOURCES.$(bld_trg_cpu)) $($(target)_SOURCES.$(bld_type)))\
[1256]1494 ,$(eval $(value $(def_target_source_c_cpp_objc_asm_rc_var))) )
[641]1495
[73]1496endef
1497
1498
[219]1499
[353]1500## Generic macro for generating the install rule(s) for a target
1501# and update the globals with default out.
[219]1502#
[353]1503# @param $(target) Normalized target name.
1504# @param $(out) The output file.
1505# @param $(definst) The default _INST value.
1506# @param $(typevar) The name of the variable with all the root targets of its type.
[729]1507# @remark Only library uses this now.
[353]1508define def_target_install_pluss
1509ifndef $(target)_NOINST
1510INSTARGET_$(target) := $(patsubst %/,%/$(notdir $(out)), \
1511 $(if $($(target)_INST), $(addprefix $(PATH_INS)/,$($(target)_INST)), $(definst)/))
[219]1512
[353]1513$(eval $(def_link_install_rule))
[239]1514
[827]1515_INSTALLS_FILES += $(INSTARGET_$(target))
[272]1516
[353]1517ifdef KBUILD_DO_AUTO_INSTALL
[579]1518$(typevar) += $(INSTARGET_$(target))
[219]1519else
[579]1520$(typevar) += $(out)
[219]1521endif
[353]1522else # _NOINST
[579]1523$(typevar) += $(out)
[353]1524endif
1525
[1030]1526_OUT_FILES += $($(target)_OUTPUT_) $($(target)_OUTPUT_MAYBE_) $(out)
[905]1527_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))
1528_DIRS += $($(target)_BLDDIRS) $($(target)_BLDDIRS.$(bld_trg)) $($(target)_BLDDIRS.$(bld_trg).$(bld_trg_arch)) $($(target)_BLDDIRS.$(bld_trg_arch)) $($(target)_BLDDIRS.$(bld_trg_cpu)) $($(target)_BLDDIRS.$(bld_type))
[353]1529_OBJS += $($(target)_OBJS_)
1530
[219]1531endef
1532
1533
1534
1535#
[72]1536# LIBRARIES
[73]1537#
[72]1538
1539## Library (one).
[74]1540# @param $(target) Normalized library (target) name.
[72]1541define def_lib
[145]1542# library basics
[222]1543## @todo prefix
[353]1544bld_type := $(firstword $($(target)_BLD_TYPE) $(BUILD_TYPE))
1545bld_trg := $(firstword $($(target)_BLD_TRG) $(BUILD_TARGET))
1546bld_trg_arch:= $(firstword $($(target)_BLD_TRG_ARCH) $(BUILD_TARGET_ARCH))
1547bld_trg_cpu := $(firstword $($(target)_BLD_TRG_CPU) $(BUILD_TARGET_CPU))
1548tool := $(call _TARGET_TOOL,$(target),AR)
[78]1549ifeq ($(tool),)
[353]1550$(error kBuild: Library target $(target) does not have a tool defined!)
[78]1551endif
[889]1552name := $(firstword\
1553 $($(target)_NAME.$(bld_trg).$(bld_trg_arch))\
1554 $($(target)_NAME.$(bld_trg_arch))\
1555 $($(target)_NAME.$(bld_trg))\
1556 $($(target)_NAME.$(bld_type))\
1557 $($(target)_NAME)\
1558 $(target))
1559outbase := $(call TARGET_BASE,$(name),$(target))
[743]1560ifndef PATH_$(target)
1561 PATH_$(target) := $(patsubst %/,%,$(dir $(outbase)))
1562else
1563 ifneq ($(PATH_$(target)),$(patsubst %/,%,$(dir $(outbase))))
1564 $(error kBuild internal error: PATH_$(target)=$(PATH_$(target)) expected $(patsubst %/,%,$(dir $(outbase))))
1565 endif
1566endif
[353]1567suff := $(firstword\
[481]1568 $($(target)_LIBSUFF.$(bld_trg).$(bld_trg_arch))\
[221]1569 $($(target)_LIBSUFF.$(bld_trg))\
[126]1570 $($(target)_LIBSUFF)\
[481]1571 $(TOOL_$(tool)_ARLIBSUFF.$(bld_trg).$(bld_trg_arch))\
[221]1572 $(TOOL_$(tool)_ARLIBSUFF.$(bld_trg))\
[126]1573 $(TOOL_$(tool)_ARLIBSUFF)\
[353]1574 $(SUFF_LIB))
1575out := $(outbase)$(suff)
1576TARGET_$(target) := $(out)
[719]1577$(target)_OBJS_ :=
[725]1578defpath := $($(target)_PATH)
[145]1579
1580# source -> object
[353]1581$(eval $(value def_target_sources))
[145]1582
1583# library linking
[353]1584tool := $(call _TARGET_TOOL,$(target),AR)
[889]1585name := $(firstword\
1586 $($(target)_NAME.$(bld_trg).$(bld_trg_arch))\
1587 $($(target)_NAME.$(bld_trg_arch))\
1588 $($(target)_NAME.$(bld_trg))\
1589 $($(target)_NAME.$(bld_type))\
1590 $($(target)_NAME)\
1591 $(target))
1592outbase := $(call TARGET_BASE,$(name),$(target))
[353]1593flags :=\
[74]1594 $(TOOL_$(tool)_ARFLAGS)\
[221]1595 $(TOOL_$(tool)_ARFLAGS.$(bld_type))\
[74]1596 $(ARFLAGS)\
[221]1597 $(ARFLAGS.$(bld_type))\
[74]1598 $($(target)_ARFLAGS)\
[481]1599 $($(target)_ARFLAGS.$(bld_type)) \
1600 $($(target)_ARFLAGS.$(bld_trg)) \
1601 $($(target)_ARFLAGS.$(bld_trg_arch)) \
1602 $($(target)_ARFLAGS.$(bld_trg).$(bld_trg_arch)) \
1603 $($(target)_ARFLAGS.$(bld_trg_cpu))
[1256]1604othersrc := $(filter-out %.c %.cpp %.cxx %.cc %.m %.s %.S %.asm %.rc %.o %.obj %.res,\
[353]1605 $($(target)_SOURCES) \
1606 $($(target)_SOURCES.$(bld_trg)) \
1607 $($(target)_SOURCES.$(bld_trg_arch)) \
[481]1608 $($(target)_SOURCES.$(bld_trg).$(bld_trg_arch)) \
[353]1609 $($(target)_SOURCES.$(bld_trg_cpu)) \
1610 $($(target)_SOURCES.$(bld_type)))
[1148]1611objs = $(filter %.o %.obj %.res, \
[643]1612 $($(target)_SOURCES) \
1613 $($(target)_SOURCES.$(bld_trg)) \
1614 $($(target)_SOURCES.$(bld_trg_arch)) \
1615 $($(target)_SOURCES.$(bld_trg).$(bld_trg_arch)) \
1616 $($(target)_SOURCES.$(bld_trg_cpu)) \
1617 $($(target)_SOURCES.$(bld_type))) \
1618 $($(target)_OBJS_)
[353]1619dirdep := $(call DIRDEP,$(dir $(out)))
1620deps := $($(target)_DEPS)
[827]1621orderdeps := $($(target)_ORDERDEPS)
[72]1622
[725]1623# Adjust paths if we got a default path.
1624ifneq ($(defpath),)
[979]1625 objs := $(abspathex $(objs),$(defpath))
1626 deps := $(abspathex $(deps),$(defpath))
1627 orderdeps := $(abspathex $(orderdeps),$(defpath))
1628 othersrc := $(abspathex $(othersrc),$(defpath))
[725]1629endif
1630
[859]1631
1632# Custom pre-link actions.
1633ifdef $(target)_PRE_CMDS.$(bld_trg).$(bld_trg_arch).$(bld_type)
1634 pre_cmds := $($(target)_PRE_CMDS.$(bld_trg).$(bld_trg_arch).$(bld_type))
1635else ifdef $(target)_PRE_CMDS.$(bld_trg).$(bld_trg_arch)
1636 pre_cmds := $($(target)_PRE_CMDS.$(bld_trg).$(bld_trg_arch))
1637else ifdef $(target)_PRE_CMDS.$(bld_trg).$(bld_type)
1638 pre_cmds := $($(target)_PRE_CMDS.$(bld_trg).$(bld_type))
1639else ifdef $(target)_PRE_CMDS.$(bld_trg_arch)
1640 pre_cmds := $($(target)_PRE_CMDS.$(bld_trg_arch))
1641else ifdef $(target)_PRE_CMDS.$(bld_trg)
1642 pre_cmds := $($(target)_PRE_CMDS.$(bld_trg))
1643else ifdef $(target)_PRE_CMDS.$(bld_type)
1644 pre_cmds := $($(target)_PRE_CMDS.$(bld_type))
1645else ifdef $(target)_PRE_CMDS
1646 pre_cmds := $($(target)_PRE_CMDS)
1647else ifdef PRE_CMDS.$(bld_trg).$(bld_trg_arch).$(bld_type)
1648 pre_cmds := $(PRE_CMDS.$(bld_trg).$(bld_trg_arch).$(bld_type))
1649else ifdef PRE_CMDS.$(bld_trg).$(bld_trg_arch)
1650 pre_cmds := $(PRE_CMDS.$(bld_trg).$(bld_trg_arch))
1651else ifdef PRE_CMDS.$(bld_trg).$(bld_type)
1652 pre_cmds := $(PRE_CMDS.$(bld_trg).$(bld_type))
1653else ifdef PRE_CMDS.$(bld_trg_arch)
1654 pre_cmds := $(PRE_CMDS.$(bld_trg_arch))
1655else ifdef PRE_CMDS.$(bld_trg)
1656 pre_cmds := $(PRE_CMDS.$(bld_trg))
1657else ifdef PRE_CMDS.$(bld_type)
1658 pre_cmds := $(PRE_CMDS.$(bld_type))
1659else
1660 pre_cmds := $(PRE_CMDS)
1661endif
1662
1663# Custom post-link actions.
1664ifdef $(target)_POST_CMDS.$(bld_trg).$(bld_trg_arch).$(bld_type)
1665 post_cmds := $($(target)_POST_CMDS.$(bld_trg).$(bld_trg_arch).$(bld_type))
1666else ifdef $(target)_POST_CMDS.$(bld_trg).$(bld_trg_arch)
1667 post_cmds := $($(target)_POST_CMDS.$(bld_trg).$(bld_trg_arch))
1668else ifdef $(target)_POST_CMDS.$(bld_trg).$(bld_type)
1669 post_cmds := $($(target)_POST_CMDS.$(bld_trg).$(bld_type))
1670else ifdef $(target)_POST_CMDS.$(bld_trg_arch)
1671 post_cmds := $($(target)_POST_CMDS.$(bld_trg_arch))
1672else ifdef $(target)_POST_CMDS.$(bld_trg)
1673 post_cmds := $($(target)_POST_CMDS.$(bld_trg))
1674else ifdef $(target)_POST_CMDS.$(bld_type)
1675 post_cmds := $($(target)_POST_CMDS.$(bld_type))
1676else ifdef $(target)_POST_CMDS
1677 post_cmds := $($(target)_POST_CMDS)
1678else ifdef POST_CMDS.$(bld_trg).$(bld_trg_arch).$(bld_type)
1679 post_cmds := $(POST_CMDS.$(bld_trg).$(bld_trg_arch).$(bld_type))
1680else ifdef POST_CMDS.$(bld_trg).$(bld_trg_arch)
1681 post_cmds := $(POST_CMDS.$(bld_trg).$(bld_trg_arch))
1682else ifdef POST_CMDS.$(bld_trg).$(bld_type)
1683 post_cmds := $(POST_CMDS.$(bld_trg).$(bld_type))
1684else ifdef POST_CMDS.$(bld_trg_arch)
1685 post_cmds := $(POST_CMDS.$(bld_trg_arch))
1686else ifdef POST_CMDS.$(bld_trg)
1687 post_cmds := $(POST_CMDS.$(bld_trg))
1688else ifdef POST_CMDS.$(bld_type)
1689 post_cmds := $(POST_CMDS.$(bld_type))
1690else
1691 post_cmds := $(POST_CMDS)
1692endif
1693
[380]1694# dependency file
1695dep := $(out)$(SUFF_DEP)
[524]1696ifndef NO_LINK_CMDS_DEPS
[893]1697 _DEPFILES_INCLUDED += $(dep)
1698 $(eval includedep $(dep))
[380]1699endif
[72]1700
[380]1701# check that the tool is defined.
1702ifndef TOOL_$(tool)_LINK_LIBRARY_CMDS
1703$(warning kBuild: tools: \
[481]1704 1 $($(target)_$(source)TOOL.$(bld_trg).$(bld_trg_arch)) \
1705 2 $($(target)_$(source)TOOL.$(bld_trg)) \
1706 3 $($(target)_$(source)TOOL) \
1707 4 $($(target)_TOOL.$(bld_trg).$(bld_trg_arch)) \
1708 5 $($(target)_TOOL.$(bld_trg)) \
1709 6 $($(target)_TOOL) \
1710 7 $($(source)TOOL) \
1711 8 $($(source)TOOL.$(bld_trg).$(bld_trg_arch)) \
1712 9 $($(source)TOOL.$(bld_trg)) \
1713 10 $(TOOL.$(bld_trg).$(bld_trg_arch)) \
1714 11 $(TOOL.$(bld_trg)) \
1715 12 $(TOOL) )
[380]1716$(error kBuild: TOOL_$(tool)_LINK_LIBRARY_CMDS isn't defined! target=$(target) )
1717endif
1718
1719# call the tool
1720$(target)_CMDS_ := $(TOOL_$(tool)_LINK_LIBRARY_CMDS)
[859]1721ifneq ($(pre_cmds),)
1722 $(target)_CMDS_ := $(TAB)$(pre_cmds)$(NL)$(TAB)$($(target)_CMDS_)
1723endif
1724ifneq ($(post_cmds),)
1725 $(target)_CMDS_ := $($(target)_CMDS_)$(NL)$(TAB)$(post_cmds)
1726endif
[380]1727$(target)_OUTPUT_ := $(TOOL_$(tool)_LINK_LIBRARY_OUTPUT)
[1030]1728$(target)_OUTPUT_MAYBE_ := $(TOOL_$(tool)_LINK_LIBRARY_OUTPUT_MAYBE)
[380]1729$(target)_DEPEND_ := $(TOOL_$(tool)_LINK_LIBRARY_DEPEND) $(deps) $(objs)
[827]1730$(target)_DEPORD_ := $(TOOL_$(tool)_LINK_LIBRARY_DEPORD) $(dirdep) $(orderdeps)
[380]1731
[412]1732# generate the link rule.
[380]1733$(eval $(def_link_rule))
1734
[353]1735# installing and globals
1736$(eval $(value def_target_install_pluss))
[72]1737endef
1738
1739# Process libraries
[859]1740definst := $(PATH_LIB)
1741typevar := _LIBS
[776]1742tool_do := LINK_LIBRARY
[380]1743mode := 0644
[481]1744$(foreach target, $(LIBRARIES) $(LIBRARIES.$(BUILD_TARGET)) $(LIBRARIES.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)), $(eval $(value def_lib)))
[72]1745
[988]1746ifdef KBUILD_PROFILE_SELF
1747 _KBUILD_TS_NOW := $(nanots )
1748 $(info prof: $(int-sub $(_KBUILD_TS_NOW), $(_KBUILD_TS_HEADER_START)) - $(int-sub $(_KBUILD_TS_NOW), $(_KBUILD_TS_PREV)) - done library targets)
1749 _KBUILD_TS_PREV := $(_KBUILD_TS_NOW)
1750endif
[72]1751
[988]1752
[72]1753#
[353]1754# Link operations.
[72]1755#
1756
[353]1757##
1758# Link prolog
1759#
1760# @param $(target) Normalized target name.
1761# @param $(EXT) EXE,DLL,SYS.
1762# @param $(definst) The default _INST value.
1763# @param $(typevar) The name of the variable with all the root targets of its type.
[380]1764define def_link_common
[353]1765# basics
1766bld_type := $(firstword $($(target)_BLD_TYPE) $(BUILD_TYPE))
1767bld_trg := $(firstword $($(target)_BLD_TRG) $(BUILD_$(bld_trg_base_var)))
1768bld_trg_arch:= $(firstword $($(target)_BLD_TRG_ARCH) $(BUILD_$(bld_trg_base_var)_ARCH))
1769bld_trg_cpu := $(firstword $($(target)_BLD_TRG_CPU) $(BUILD_$(bld_trg_base_var)_CPU))
[145]1770
[353]1771tool := $(call _TARGET_TOOL,$(target),LD)
[889]1772name := $(firstword\
1773 $($(target)_NAME.$(bld_trg).$(bld_trg_arch))\
1774 $($(target)_NAME.$(bld_trg_arch))\
1775 $($(target)_NAME.$(bld_trg))\
1776 $($(target)_NAME.$(bld_type))\
1777 $($(target)_NAME)\
1778 $(target))
1779outbase := $(call TARGET_BASE,$(name),$(target))
[743]1780ifndef PATH_$(target)
1781 PATH_$(target) := $(patsubst %/,%,$(dir $(outbase)))
1782else
1783 ifneq ($(PATH_$(target)),$(patsubst %/,%,$(dir $(outbase))))
1784 $(error kBuild internal error: PATH_$(target)=$(PATH_$(target)) expected $(patsubst %/,%,$(dir $(outbase))))
1785 endif
1786endif
[353]1787suff := $(firstword \
1788 $($(target)_$(EXT)SUFF) \
1789 $($(target)_$(EXT)SUFF) \
1790 $(TOOL_$(tool)_LD$(EXT)SUFF) \
1791 $($(EXTPRE)SUFF_$(EXT)))
1792out := $(outbase)$(suff)
1793TARGET_$(target) := $(out)
[719]1794$(target)_OBJS_ :=
[725]1795defpath := $($(target)_PATH)
[353]1796
[145]1797# source -> object
[353]1798$(eval $(value def_target_sources))
[145]1799
[744]1800# more link stuff.
[353]1801tool := $(call _TARGET_TOOL,$(target),LD)
[889]1802name := $(firstword\
1803 $($(target)_NAME.$(bld_trg).$(bld_trg_arch))\
1804 $($(target)_NAME.$(bld_trg_arch))\
1805 $($(target)_NAME.$(bld_trg))\
1806 $($(target)_NAME.$(bld_type))\
1807 $($(target)_NAME)\
1808 $(target))
1809outbase := $(call TARGET_BASE,$(name),$(target))
[353]1810flags :=\
[74]1811 $(TOOL_$(tool)_LDFLAGS)\
[221]1812 $(TOOL_$(tool)_LDFLAGS.$(bld_type))\
1813 $(TOOL_$(tool)_LDFLAGS.$(bld_trg))\
1814 $(TOOL_$(tool)_LDFLAGS.$(bld_trg_arch))\
[481]1815 $(TOOL_$(tool)_LDFLAGS.$(bld_trg).$(bld_trg_arch))\
[221]1816 $(TOOL_$(tool)_LDFLAGS.$(bld_trg_cpu))\
[1242]1817 $(foreach sdk, $(SDKS) \
1818 $(SDKS.$(bld_type)) \
1819 $(SDKS.$(bld_trg)) \
1820 $(SDKS.$(bld_trg_arch)) \
1821 $(SDKS.$(bld_trg).$(bld_trg_arch)),\
1822 $(SDK_$(sdk)_LDFLAGS)\
1823 $(SDK_$(sdk)_LDFLAGS.$(bld_type))\
1824 $(SDK_$(sdk)_LDFLAGS.$(bld_trg))\
1825 $(SDK_$(sdk)_LDFLAGS.$(bld_trg_arch))\
1826 $(SDK_$(sdk)_LDFLAGS.$(bld_trg).$(bld_trg_arch))\
1827 $(SDK_$(sdk)_LDFLAGS.$(bld_trg_cpu)))\
[74]1828 $(LDFLAGS)\
[221]1829 $(LDFLAGS.$(bld_type))\
1830 $(LDFLAGS.$(bld_trg))\
1831 $(LDFLAGS.$(bld_trg_arch))\
[481]1832 $(LDFLAGS.$(bld_trg).$(bld_trg_arch))\
[221]1833 $(LDFLAGS.$(bld_trg_cpu))\
[1242]1834 $(foreach sdk, $($(target)_SDKS) \
1835 $($(target)_SDKS.$(bld_type)) \
1836 $($(target)_SDKS.$(bld_trg)) \
1837 $($(target)_SDKS.$(bld_trg_arch)) \
1838 $($(target)_SDKS.$(bld_trg).$(bld_trg_arch)),\
1839 $(SDK_$(sdk)_LDFLAGS)\
1840 $(SDK_$(sdk)_LDFLAGS.$(bld_type))\
1841 $(SDK_$(sdk)_LDFLAGS.$(bld_trg))\
1842 $(SDK_$(sdk)_LDFLAGS.$(bld_trg_arch))\
1843 $(SDK_$(sdk)_LDFLAGS.$(bld_trg).$(bld_trg_arch))\
1844 $(SDK_$(sdk)_LDFLAGS.$(bld_trg_cpu)))\
[74]1845 $($(target)_LDFLAGS)\
[221]1846 $($(target)_LDFLAGS.$(bld_type))\
1847 $($(target)_LDFLAGS.$(bld_trg))\
1848 $($(target)_LDFLAGS.$(bld_trg_arch))\
[481]1849 $($(target)_LDFLAGS.$(bld_trg).$(bld_trg_arch))\
[353]1850 $($(target)_LDFLAGS.$(bld_trg_cpu))
[1256]1851othersrc := $(filter-out %.c %.cpp %.cxx %.cc %.m %.s %.S %.asm %.rc %.o %.obj %.res,\
[353]1852 $($(target)_SOURCES)\
1853 $($(target)_SOURCES.$(bld_trg)) \
1854 $($(target)_SOURCES.$(bld_trg_arch)) \
[481]1855 $($(target)_SOURCES.$(bld_trg).$(bld_trg_arch)) \
[353]1856 $($(target)_SOURCES.$(bld_trg_cpu)) \
1857 $($(target)_SOURCES.$(bld_type)))
[1148]1858objs = $(filter %.o %.obj %.res, \
[643]1859 $($(target)_SOURCES) \
1860 $($(target)_SOURCES.$(bld_trg)) \
1861 $($(target)_SOURCES.$(bld_trg_arch)) \
1862 $($(target)_SOURCES.$(bld_trg).$(bld_trg_arch)) \
1863 $($(target)_SOURCES.$(bld_trg_cpu)) \
1864 $($(target)_SOURCES.$(bld_type))) \
1865 $($(target)_OBJS_)
[353]1866libs :=\
[221]1867 $($(target)_LIBS.$(bld_trg_cpu))\
[481]1868 $($(target)_LIBS.$(bld_trg).$(bld_trg_arch))\
[221]1869 $($(target)_LIBS.$(bld_trg_arch))\
1870 $($(target)_LIBS.$(bld_trg))\
1871 $($(target)_LIBS.$(bld_type))\
[74]1872 $($(target)_LIBS)\
[592]1873 $(foreach sdk, $($(target)_SDKS.$(bld_trg).$(bld_trg_arch)) \
1874 $($(target)_SDKS.$(bld_trg_arch)) \
1875 $($(target)_SDKS.$(bld_trg)) \
1876 $($(target)_SDKS.$(bld_type)) \
1877 $($(target)_SDKS),\
[353]1878 $(SDK_$(sdk)_LIBS.$(bld_trg_cpu))\
[481]1879 $(SDK_$(sdk)_LIBS.$(bld_trg).$(bld_trg_arch))\
[353]1880 $(SDK_$(sdk)_LIBS.$(bld_trg_arch))\
1881 $(SDK_$(sdk)_LIBS.$(bld_trg))\
1882 $(SDK_$(sdk)_LIBS.$(bld_type))\
1883 $(SDK_$(sdk)_LIBS))\
[221]1884 $(LIBS.$(bld_trg_cpu))\
[481]1885 $(LIBS.$(bld_trg).$(bld_trg_arch))\
[221]1886 $(LIBS.$(bld_trg_arch))\
1887 $(LIBS.$(bld_trg))\
1888 $(LIBS.$(bld_type))\
[74]1889 $(LIBS)\
[592]1890 $(foreach sdk, $(SDKS.$(bld_trg).$(bld_trg_arch)) \
1891 $(SDKS.$(bld_trg_arch)) \
1892 $(SDKS.$(bld_trg)) \
1893 $(SDKS.$(bld_type)) \
1894 $(SDKS),\
[353]1895 $(SDK_$(sdk)_LIBS.$(bld_trg_cpu))\
[481]1896 $(SDK_$(sdk)_LIBS.$(bld_trg).$(bld_trg_arch))\
[353]1897 $(SDK_$(sdk)_LIBS.$(bld_trg_arch))\
1898 $(SDK_$(sdk)_LIBS.$(bld_trg))\
1899 $(SDK_$(sdk)_LIBS.$(bld_type))\
1900 $(SDK_$(sdk)_LIBS))\
[221]1901 $(TOOL_$(tool)_LIBS.$(bld_trg_cpu))\
[481]1902 $(TOOL_$(tool)_LIBS.$(bld_trg).$(bld_trg_arch))\
[221]1903 $(TOOL_$(tool)_LIBS.$(bld_trg_arch))\
1904 $(TOOL_$(tool)_LIBS.$(bld_trg))\
1905 $(TOOL_$(tool)_LIBS.$(bld_type))\
[353]1906 $(TOOL_$(tool)_LIBS)
1907libpath :=\
[221]1908 $($(target)_LIBPATH.$(bld_trg_cpu))\
[481]1909 $($(target)_LIBPATH.$(bld_trg).$(bld_trg_arch))\
[221]1910 $($(target)_LIBPATH.$(bld_trg_arch))\
1911 $($(target)_LIBPATH.$(bld_trg))\
1912 $($(target)_LIBPATH.$(bld_type))\
[74]1913 $($(target)_LIBPATH)\
[592]1914 $(foreach sdk, $($(target)_SDKS.$(bld_trg).$(bld_trg_arch)) \
1915 $($(target)_SDKS.$(bld_trg_arch)) \
1916 $($(target)_SDKS.$(bld_trg)) \
1917 $($(target)_SDKS.$(bld_type)) \
1918 $($(target)_SDKS),\
[353]1919 $(SDK_$(sdk)_LIBPATH.$(bld_trg_cpu))\
[481]1920 $(SDK_$(sdk)_LIBPATH.$(bld_trg).$(bld_trg_arch))\
[353]1921 $(SDK_$(sdk)_LIBPATH.$(bld_trg_arch))\
1922 $(SDK_$(sdk)_LIBPATH.$(bld_trg))\
1923 $(SDK_$(sdk)_LIBPATH.$(bld_type))\
1924 $(SDK_$(sdk)_LIBPATH))\
[221]1925 $(LIBPATH.$(bld_trg_cpu))\
[481]1926 $(LIBPATH.$(bld_trg).$(bld_trg_arch))\
[221]1927 $(LIBPATH.$(bld_trg_arch))\
1928 $(LIBPATH.$(bld_trg))\
1929 $(LIBPATH.$(bld_type))\
[74]1930 $(LIBPATH)\
[592]1931 $(foreach sdk, $(SDKS.$(bld_trg).$(bld_trg_arch)) \
1932 $(SDKS.$(bld_trg_arch)) \
1933 $(SDKS.$(bld_trg)) \
1934 $(SDKS.$(bld_type)) \
1935 $(SDKS),\
[353]1936 $(SDK_$(sdk)_LIBPATH.$(bld_trg_cpu))\
[481]1937 $(SDK_$(sdk)_LIBPATH.$(bld_trg).$(bld_trg_arch))\
[353]1938 $(SDK_$(sdk)_LIBPATH.$(bld_trg_arch))\
1939 $(SDK_$(sdk)_LIBPATH.$(bld_trg))\
1940 $(SDK_$(sdk)_LIBPATH.$(bld_type))\
1941 $(SDK_$(sdk)_LIBPATH))\
[221]1942 $(TOOL_$(tool)_LIBPATH.$(bld_trg_cpu))\
[481]1943 $(TOOL_$(tool)_LIBPATH.$(bld_trg).$(bld_trg_arch))\
[221]1944 $(TOOL_$(tool)_LIBPATH.$(bld_trg_arch))\
1945 $(TOOL_$(tool)_LIBPATH.$(bld_trg))\
1946 $(TOOL_$(tool)_LIBPATH.$(bld_type))\
[353]1947 $(TOOL_$(tool)_LIBPATH)
1948dirdep := $(call DIRDEP,$(dir $(out)))
1949deps := $($(target)_DEPS)
[827]1950orderdeps := $($(target)_ORDERDEPS)
[353]1951
[725]1952# Adjust paths if we got a default path.
1953ifneq ($(defpath),)
[979]1954 libpath := $(abspathex $(libpath),$(defpath))
1955 objs := $(abspathex $(objs),$(defpath))
1956 deps := $(abspathex $(deps),$(defpath))
1957 orderdeps := $(abspathex $(orderdeps),$(defpath))
1958 othersrc := $(abspathex $(othersrc),$(defpath))
[725]1959 # libs are not subject to this because of the the -l<lib> stuff. Use $(<target>_PATH)/lib if relative to current dir!
1960endif
1961
[859]1962# Custom pre-link actions.
1963ifdef $(target)_PRE_CMDS.$(bld_trg).$(bld_trg_arch).$(bld_type)
1964 pre_cmds := $($(target)_PRE_CMDS.$(bld_trg).$(bld_trg_arch).$(bld_type))
1965else ifdef $(target)_PRE_CMDS.$(bld_trg).$(bld_trg_arch)
1966 pre_cmds := $($(target)_PRE_CMDS.$(bld_trg).$(bld_trg_arch))
1967else ifdef $(target)_PRE_CMDS.$(bld_trg).$(bld_type)
1968 pre_cmds := $($(target)_PRE_CMDS.$(bld_trg).$(bld_type))
1969else ifdef $(target)_PRE_CMDS.$(bld_trg_arch)
1970 pre_cmds := $($(target)_PRE_CMDS.$(bld_trg_arch))
1971else ifdef $(target)_PRE_CMDS.$(bld_trg)
1972 pre_cmds := $($(target)_PRE_CMDS.$(bld_trg))
1973else ifdef $(target)_PRE_CMDS.$(bld_type)
1974 pre_cmds := $($(target)_PRE_CMDS.$(bld_type))
1975else ifdef $(target)_PRE_CMDS
1976 pre_cmds := $($(target)_PRE_CMDS)
1977else ifdef PRE_CMDS.$(bld_trg).$(bld_trg_arch).$(bld_type)
1978 pre_cmds := $(PRE_CMDS.$(bld_trg).$(bld_trg_arch).$(bld_type))
1979else ifdef PRE_CMDS.$(bld_trg).$(bld_trg_arch)
1980 pre_cmds := $(PRE_CMDS.$(bld_trg).$(bld_trg_arch))
1981else ifdef PRE_CMDS.$(bld_trg).$(bld_type)
1982 pre_cmds := $(PRE_CMDS.$(bld_trg).$(bld_type))
1983else ifdef PRE_CMDS.$(bld_trg_arch)
1984 pre_cmds := $(PRE_CMDS.$(bld_trg_arch))
1985else ifdef PRE_CMDS.$(bld_trg)
1986 pre_cmds := $(PRE_CMDS.$(bld_trg))
1987else ifdef PRE_CMDS.$(bld_type)
1988 pre_cmds := $(PRE_CMDS.$(bld_type))
1989else
1990 pre_cmds := $(PRE_CMDS)
1991endif
[72]1992
[859]1993# Custom post-link actions.
1994ifdef $(target)_POST_CMDS.$(bld_trg).$(bld_trg_arch).$(bld_type)
1995 post_cmds := $($(target)_POST_CMDS.$(bld_trg).$(bld_trg_arch).$(bld_type))
1996else ifdef $(target)_POST_CMDS.$(bld_trg).$(bld_trg_arch)
1997 post_cmds := $($(target)_POST_CMDS.$(bld_trg).$(bld_trg_arch))
1998else ifdef $(target)_POST_CMDS.$(bld_trg).$(bld_type)
1999 post_cmds := $($(target)_POST_CMDS.$(bld_trg).$(bld_type))
2000else ifdef $(target)_POST_CMDS.$(bld_trg_arch)
2001 post_cmds := $($(target)_POST_CMDS.$(bld_trg_arch))
2002else ifdef $(target)_POST_CMDS.$(bld_trg)
2003 post_cmds := $($(target)_POST_CMDS.$(bld_trg))
2004else ifdef $(target)_POST_CMDS.$(bld_type)
2005 post_cmds := $($(target)_POST_CMDS.$(bld_type))
2006else ifdef $(target)_POST_CMDS
2007 post_cmds := $($(target)_POST_CMDS)
2008else ifdef POST_CMDS.$(bld_trg).$(bld_trg_arch).$(bld_type)
2009 post_cmds := $(POST_CMDS.$(bld_trg).$(bld_trg_arch).$(bld_type))
2010else ifdef POST_CMDS.$(bld_trg).$(bld_trg_arch)
2011 post_cmds := $(POST_CMDS.$(bld_trg).$(bld_trg_arch))
2012else ifdef POST_CMDS.$(bld_trg).$(bld_type)
2013 post_cmds := $(POST_CMDS.$(bld_trg).$(bld_type))
2014else ifdef POST_CMDS.$(bld_trg_arch)
2015 post_cmds := $(POST_CMDS.$(bld_trg_arch))
2016else ifdef POST_CMDS.$(bld_trg)
2017 post_cmds := $(POST_CMDS.$(bld_trg))
2018else ifdef POST_CMDS.$(bld_type)
2019 post_cmds := $(POST_CMDS.$(bld_type))
2020else
2021 post_cmds := $(POST_CMDS)
2022endif
2023
[353]2024# installation targets
2025ifndef $(target)_NOINST
2026INSTARGET_$(target) := $(patsubst %/,%/$(notdir $(out)), \
2027 $(if $($(target)_INST), $(addprefix $(PATH_INS)/,$($(target)_INST)), $(definst)/))
2028ifdef KBUILD_DO_AUTO_INSTALL
2029$(typevar) += $(INSTARGET_$(target))
2030else
2031$(typevar) += $(out)
2032endif
2033# generate the install rule
2034$(eval $(def_link_install_rule))
2035
2036else # NOINST
2037INSTARGET_$(target) :=
2038$(typevar) += $(out)
2039endif # NOINST
2040
[380]2041# dependency file
2042dep := $(outbase)$(SUFF_DEP)
[524]2043ifndef NO_LINK_CMDS_DEPS
[893]2044 _DEPFILES_INCLUDED += $(dep)
2045 $(eval includedep $(dep))
[380]2046endif
[353]2047
[380]2048# check that the tool is defined.
2049ifndef TOOL_$(tool)_$(tool_do)_CMDS
2050$(warning kBuild: tools: \
[481]2051 1 $($(target)_$(source)TOOL.$(bld_trg).$(bld_trg_arch)) \
2052 2 $($(target)_$(source)TOOL.$(bld_trg)) \
2053 3 $($(target)_$(source)TOOL) \
2054 4 $($(target)_TOOL.$(bld_trg).$(bld_trg_arch)) \
2055 5 $($(target)_TOOL.$(bld_trg)) \
2056 6 $($(target)_TOOL) \
2057 7 $($(source)TOOL.$(bld_trg).$(bld_trg_arch)) \
2058 8 $($(source)TOOL.$(bld_trg)) \
2059 9 $($(source)TOOL) \
2060 10 $(TOOL.$(bld_trg).$(bld_trg_arch)) \
2061 11 $(TOOL.$(bld_trg)) \
2062 12 $(TOOL) )
[380]2063$(error kBuild: TOOL_$(tool)_$(tool_do)_CMDS isn't defined! target=$(target) )
2064endif
[353]2065
[380]2066# call the tool
2067$(target)_CMDS_ := $(TOOL_$(tool)_$(tool_do)_CMDS)
[859]2068ifneq ($(pre_cmds),)
2069 $(target)_CMDS_ := $(TAB)$(pre_cmds)$(NL)$(TAB)$($(target)_CMDS_)
2070endif
2071ifneq ($(post_cmds),)
2072 $(target)_CMDS_ := $($(target)_CMDS_)$(NL)$(TAB)$(post_cmds)
2073endif
[380]2074$(target)_OUTPUT_ := $(TOOL_$(tool)_$(tool_do)_OUTPUT)
[1030]2075$(target)_OUTPUT_MAYBE_ := $(TOOL_$(tool)_$(tool_do)_OUTPUT_MAYBE)
[380]2076$(target)_DEPEND_ := $(TOOL_$(tool)_$(tool_do)_DEPEND) $(deps) $(objs)
[827]2077$(target)_DEPORD_ := $(TOOL_$(tool)_$(tool_do)_DEPORD) $(dirdep) $(orderdeps)
[353]2078
[412]2079# generate the link rule.
[380]2080$(eval $(def_link_rule))
2081
[412]2082
[380]2083# Update globals.
[579]2084_OBJS += $($(target)_OBJS_)
2085_OUT_FILES += $($(target)_OUTPUT_) $(out)
[905]2086_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))
2087_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]2088_INSTALLS_FILES += $(INSTARGET_$(target))
[353]2089
2090endef
2091
2092
2093#
2094# BLDPROGS
2095#
2096
2097## Build program (one).
2098# @param $(target) Normalized target (program) name.
2099define def_bldprog
2100
2101# set NOINST if not forced installation.
2102ifndef $(target)_INST
2103$(target)_NOINST := 1
2104endif
2105
[380]2106# do the usual stuff.
2107$(eval $(value def_link_common))
[353]2108
2109endef
2110
2111# Process build programs.
2112EXT := EXE
2113EXTPRE := HOST
[380]2114tool_do := LINK_PROGRAM
[353]2115definst := $(PATH_BIN)
2116typevar := _BLDPROGS
[380]2117mode := 0755
[353]2118bld_trg_base_var := PLATFORM
[481]2119$(foreach target, $(BLDPROGS) $(BLDPROGS.$(BUILD_PLATFORM)) $(BLDPROGS.$(BUILD_PLATFORM).$(BUILD_PLATFORM_ARCH)), $(eval $(value def_bldprog)))
[353]2120
[988]2121ifdef KBUILD_PROFILE_SELF
2122 _KBUILD_TS_NOW := $(nanots )
2123 $(info prof: $(int-sub $(_KBUILD_TS_NOW), $(_KBUILD_TS_HEADER_START)) - $(int-sub $(_KBUILD_TS_NOW), $(_KBUILD_TS_PREV)) - done build program targets)
2124 _KBUILD_TS_PREV := $(_KBUILD_TS_NOW)
2125endif
[353]2126
2127
2128#
2129# DLLS
2130#
2131
[189]2132# Process dlls
[353]2133EXT := DLL
2134EXTPRE :=
[380]2135tool_do := LINK_DLL
[353]2136definst := $(PATH_DLL)
2137typevar := _DLLS
[830]2138mode := 0644
[353]2139bld_trg_base_var := TARGET
[481]2140$(foreach target, $(DLLS) $(DLLS.$(BUILD_TARGET)) $(DLLS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)), $(eval $(value def_link_common)))
[74]2141
[988]2142ifdef KBUILD_PROFILE_SELF
2143 _KBUILD_TS_NOW := $(nanots )
2144 $(info prof: $(int-sub $(_KBUILD_TS_NOW), $(_KBUILD_TS_HEADER_START)) - $(int-sub $(_KBUILD_TS_NOW), $(_KBUILD_TS_PREV)) - done dll targets)
2145 _KBUILD_TS_PREV := $(_KBUILD_TS_NOW)
2146endif
[74]2147
[988]2148
[72]2149#
[830]2150# IMPORT LIBRARIES
[72]2151#
[219]2152# - On OS/2 and windows these are libraries.
[189]2153# - On other platforms they are fake DLLs.
[830]2154#
2155EXTPRE :=
2156typevar := _IMPORT_LIBS
2157mode := 0644
2158bld_trg_base_var := TARGET
[481]2159ifeq ($(filter-out nt os2 win win64 win32,$(BUILD_TARGET)),)
[830]2160 EXT := LIB
2161 tool_do := LINK_LIBRARY
2162 definst := $(PATH_LIB)
2163 $(foreach target, $(IMPORT_LIBS) $(IMPORT_LIBS.$(BUILD_TARGET)) $(IMPORT_LIBS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)), $(eval $(value def_lib)))
[189]2164else
[830]2165 EXT := DLL
2166 tool_do := LINK_DLL
2167 definst := $(PATH_DLL)
2168 $(foreach target, $(IMPORT_LIBS) $(IMPORT_LIBS.$(BUILD_TARGET)) $(IMPORT_LIBS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)), $(eval $(value def_link_common)))
[189]2169endif
[72]2170
[988]2171ifdef KBUILD_PROFILE_SELF
2172 _KBUILD_TS_NOW := $(nanots )
2173 $(info prof: $(int-sub $(_KBUILD_TS_NOW), $(_KBUILD_TS_HEADER_START)) - $(int-sub $(_KBUILD_TS_NOW), $(_KBUILD_TS_PREV)) - done import library targets)
2174 _KBUILD_TS_PREV := $(_KBUILD_TS_NOW)
2175endif
[189]2176
[988]2177
[189]2178#
2179# PROGRAMS
2180#
2181
[353]2182# Process programs
2183EXT := EXE
2184EXTPRE :=
[380]2185tool_do := LINK_PROGRAM
[353]2186definst := $(PATH_BIN)
2187typevar := _PROGRAMS
[380]2188mode := 0755
[353]2189bld_trg_base_var := TARGET
[481]2190$(foreach target, $(PROGRAMS) $(PROGRAMS.$(BUILD_TARGET)) $(PROGRAMS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)), $(eval $(value def_link_common)))
[130]2191
[988]2192ifdef KBUILD_PROFILE_SELF
2193 _KBUILD_TS_NOW := $(nanots )
2194 $(info prof: $(int-sub $(_KBUILD_TS_NOW), $(_KBUILD_TS_HEADER_START)) - $(int-sub $(_KBUILD_TS_NOW), $(_KBUILD_TS_PREV)) - done program targets)
2195 _KBUILD_TS_PREV := $(_KBUILD_TS_NOW)
2196endif
[130]2197
[189]2198
[72]2199#
[83]2200# SYSMODS
[72]2201#
2202
[130]2203# Process sysmods
[353]2204EXT := SYS
2205EXTPRE :=
[380]2206tool_do := LINK_SYSMOD
[353]2207definst := $(PATH_SYS)
2208typevar := _SYSMODS
[380]2209mode := 0644
[353]2210bld_trg_base_var := TARGET
[481]2211$(foreach target, $(SYSMODS) $(SYSMODS.$(BUILD_TARGET)) $(SYSMODS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)), $(eval $(value def_link_common)))
[83]2212
[988]2213ifdef KBUILD_PROFILE_SELF
2214 _KBUILD_TS_NOW := $(nanots )
2215 $(info prof: $(int-sub $(_KBUILD_TS_NOW), $(_KBUILD_TS_HEADER_START)) - $(int-sub $(_KBUILD_TS_NOW), $(_KBUILD_TS_PREV)) - done sysmod targets)
2216 _KBUILD_TS_PREV := $(_KBUILD_TS_NOW)
2217endif
[83]2218
[988]2219
[72]2220#
2221# OTHERS
2222#
[481]2223_OTHERS = $(OTHERS) $(OTHERS.$(BUILD_TARGET)) $(OTHERS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH))
[72]2224
2225
[353]2226#
2227# INSTALLS
2228#
[72]2229
[353]2230## generate the install rule
2231define def_install_src_rule
2232# the install rule
2233$(insdst) : $(srcsrc) | $(call DIRDEP,$(dir $(insdst)))
[776]2234 $$(call MSG_INST_FILE,$(srcsrc),$(insdst))
[696]2235 $$(QUIET)$(inscmd)
[353]2236endef
2237
2238## install one file
2239define def_install_src
2240
2241# deal with '=>' in the source file name.
2242srcdst := $(subst =>, ,$(src))
2243srcsrc := $(firstword $(srcdst))
[424]2244srcdstdir := $(dir $(word 2,$(srcdst)))
[353]2245srcdst := $(word $(words $(srcdst)),$(srcdst))
2246
2247# _INSTFUN
2248ifdef $(srcsrc)_INSTFUN
[725]2249 instfun := $(srcsrc)_INSTFUN
[1347]2250else ifdef $(target)_INSTFUN
2251 instfun := $(target)_INSTFUN
[353]2252else
[1347]2253 instfun := _INSTALL_FILE
[353]2254endif
2255
2256# _INST
2257ifdef $(srcsrc)_INST
[725]2258 inst := $(patsubst %/,%,$($(srcsrc)_INST))/$(dir $(srcdstdir))
[1347]2259else ifdef $(target)_INST
2260 inst := $(patsubst %/,%,$($(target)_INST))/$(dir $(srcdstdir))
[353]2261else
[1347]2262 inst := $(dir $(srcdstdir))
[353]2263endif
2264
2265# calc target
[380]2266insdst := $(call $(instfun),$(srcdst),$(target),$(inst),$(PATH_INS))
[424]2267#$(warning instfun=$(instfun) srcdst=$(srcdst) target=$(target) inst=$(inst) => insdst=$(insdst))
[353]2268
[414]2269# mode, uid and gid
2270mode := $(firstword \
[481]2271 $($(target)_$(srcsrc)_MODE.$(bld_trg).$(bld_trg_arch)) \
[414]2272 $($(target)_$(srcsrc)_MODE.$(bld_trg)) \
2273 $($(target)_$(srcsrc)_MODE) \
[481]2274 $($(target)_$(srcdst)_MODE.$(bld_trg).$(bld_trg_arch)) \
[414]2275 $($(target)_$(srcdst)_MODE.$(bld_trg)) \
2276 $($(target)_$(srcdst)_MODE) \
[481]2277 $($(srcsrc)_MODE.$(bld_trg).$(bld_trg_arch)) \
[414]2278 $($(srcsrc)_MODE.$(bld_trg)) \
2279 $($(srcsrc)_MODE) \
[481]2280 $($(srcdst)_MODE.$(bld_trg).$(bld_trg_arch)) \
[414]2281 $($(srcdst)_MODE.$(bld_trg)) \
2282 $($(srcdst)_MODE) \
[481]2283 $($(target)_MODE.$(bld_trg).$(bld_trg_arch)) \
[414]2284 $($(target)_MODE.$(bld_trg)) \
2285 $($(target)_MODE))
2286uid := $(firstword \
[481]2287 $($(target)_$(srcsrc)_UID.$(bld_trg).$(bld_trg_arch)) \
[414]2288 $($(target)_$(srcsrc)_UID.$(bld_trg)) \
2289 $($(target)_$(srcsrc)_UID) \
[481]2290 $($(target)_$(srcdst)_UID.$(bld_trg).$(bld_trg_arch)) \
[414]2291 $($(target)_$(srcdst)_UID.$(bld_trg)) \
2292 $($(target)_$(srcdst)_UID) \
[481]2293 $($(srcsrc)_UID.$(bld_trg).$(bld_trg_arch)) \
[414]2294 $($(srcsrc)_UID.$(bld_trg)) \
2295 $($(srcsrc)_UID) \
[481]2296 $($(srcdst)_UID.$(bld_trg).$(bld_trg_arch)) \
[414]2297 $($(srcdst)_UID.$(bld_trg)) \
2298 $($(srcdst)_UID) \
[481]2299 $($(target)_UID.$(bld_trg).$(bld_trg_arch)) \
[414]2300 $($(target)_UID.$(bld_trg)) \
2301 $($(target)_UID))
2302gid := $(firstword \
[481]2303 $($(target)_$(srcsrc)_GID.$(bld_trg).$(bld_trg_arch)) \
[414]2304 $($(target)_$(srcsrc)_GID.$(bld_trg)) \
2305 $($(target)_$(srcsrc)_GID) \
[481]2306 $($(target)_$(srcdst)_GID.$(bld_trg).$(bld_trg_arch)) \
[414]2307 $($(target)_$(srcdst)_GID.$(bld_trg)) \
2308 $($(target)_$(srcdst)_GID) \
[481]2309 $($(srcsrc)_GID.$(bld_trg).$(bld_trg_arch)) \
[414]2310 $($(srcsrc)_GID.$(bld_trg)) \
2311 $($(srcsrc)_GID) \
[481]2312 $($(srcdst)_GID.$(bld_trg).$(bld_trg_arch)) \
[414]2313 $($(srcdst)_GID.$(bld_trg)) \
2314 $($(srcdst)_GID) \
[481]2315 $($(target)_GID.$(bld_trg).$(bld_trg_arch)) \
[414]2316 $($(target)_GID.$(bld_trg)) \
2317 $($(target)_GID))
[830]2318flags := \
2319 $($(target)_IFFLAGS) \
2320 $($(target)_IFFLAGS.$(bld_trg)) \
2321 $($(target)_IFFLAGS.$(bld_trg).$(bld_trg_arch)) \
2322 $($(srcdst)_IFFLAGS) \
2323 $($(srcdst)_IFFLAGS.$(bld_trg)) \
2324 $($(srcdst)_IFFLAGS.$(bld_trg).$(bld_trg_arch)) \
2325 $($(srcsrc)_IFFLAGS) \
2326 $($(srcsrc)_IFFLAGS.$(bld_trg)) \
2327 $($(srcsrc)_IFFLAGS.$(bld_trg).$(bld_trg_arch)) \
2328 $($(target)_$(srcdst)_IFFLAGS) \
2329 $($(target)_$(srcdst)_IFFLAGS.$(bld_trg)) \
2330 $($(target)_$(srcdst)_IFFLAGS.$(bld_trg).$(bld_trg_arch)) \
2331 $($(target)_$(srcsrc)_IFFLAGS) \
2332 $($(target)_$(srcsrc)_IFFLAGS.$(bld_trg)) \
2333 $($(target)_$(srcsrc)_IFFLAGS.$(bld_trg).$(bld_trg_arch))
[414]2334
[725]2335
2336# Adjust the source if we got a default PATH. (This must be done this late!)
2337ifdef $(target)_PATH
[979]2338 srcsrc := $(abspathex $(srcsrc),$($(target)_PATH))
[725]2339endif
2340
[353]2341# create the command
2342ifdef $(srcsrc)_INSTALLER
[830]2343 inscmd := $(call $(srcsrc)_INSTALLER,$(srcsrc),$(insdst),$(target),$(flags))
2344else ifdef $(target)_INSTALLER
2345 inscmd := $(call $(target)_INSTALLER,$(srcsrc),$(insdst),$(target),$(flags))
[353]2346else
[830]2347 inscmd := $$(INSTALL)\
[414]2348 $(if $(uid),-o $(uid))\
2349 $(if $(gid),-g $(gid))\
2350 $(if $(mode),-m $(mode))\
[830]2351 $(flags)\
[414]2352 $(srcsrc) $(insdst)
[353]2353endif
2354
2355# generate the rule (need double evaluation here)
2356$(eval $(def_install_src_rule))
2357
2358INSTARGET_$(target) += $(insdst)
2359endef
2360
2361
2362## generate the symlink rule
2363define def_install_symlink_rule
2364# the install rule
2365$(insdst) : | $(call DIRDEP,$(dir $(insdst)))
[776]2366 $$(call MSG_INST_SYM,$(insdst),$(symdst))
[696]2367 $$(QUIET)$$(RM) -f $$@
2368 $$(QUIET)$$(LN_SYMLINK) $(symdst) $(insdst)
[353]2369endef
2370
2371## create one symlink
2372define def_install_symlink
2373
2374# deal with '=>' in the source file name.
[380]2375symdst := $(subst =>, ,$(src))
2376symlnk := $(firstword $(symdst))
2377symdst := $(word $(words $(symdst)),$(symdst))
[353]2378
2379# _INSTFUN
[380]2380ifdef $(symlnk)_INSTFUN
[827]2381 instfun := $(symlnk)_INSTFUN
2382else ifdef $(target)_INSTFUN
[830]2383 instfun := $(target)_INSTFUN
[353]2384else
[827]2385 instfun := _INSTALL_FILE
[353]2386endif
2387
2388# _INST
[380]2389ifdef $(symlnk)_INST
[725]2390 inst := $(patsubst %/,%,$($(symlnk)_INST))/$(dir $(symlnk))
[827]2391else ifdef $(target)_INST
2392 inst := $(patsubst %/,%,$($(target)_INST))/$(dir $(symlnk))
[353]2393else
[827]2394 inst := $(dir $(symlnk))
[353]2395endif
2396
2397# calc target
[380]2398insdst := $(call $(instfun),$(symlnk),$(target),$(inst),$(PATH_INS))
2399#$(warning symlnk=$(symlnk) symdst=$(symdst) insdst=$(insdst) instfun=$(instfun) inst='$(inst)')
[353]2400
2401# generate the rule (need double evaluation here)
2402$(eval $(def_install_symlink_rule))
2403
2404INSTARGET_$(target) += $(insdst)
2405endef
2406
[412]2407
[380]2408## generate the install rule
2409define def_install_directory_rule
2410# the install rule
2411$(insdst):
[776]2412 $$(call MSG_INST_DIR,$(insdst))
[696]2413 $$(QUIET)$$(INSTALL) -d \
[380]2414 $(if $(uid),-o $(uid))\
2415 $(if $(gid),-g $(gid))\
2416 $(if $(mode),-m $(mode))\
[830]2417 $(flags)\
[380]2418 $(insdst)
[412]2419
2420.NOTPARALLEL: $(insdst)
[380]2421endef
2422
[412]2423
[380]2424## create one directory
2425define def_install_directory
2426
2427# _INST
2428ifdef $(directory)_INST
[725]2429 inst := $(PATH_INS)/$(patsubst %/,%,$($(directory)_INST))
[827]2430else ifdef $(target)_INST
2431 inst := $(PATH_INS)/$(patsubst %/,%,$($(target)_INST))
[380]2432else
[827]2433 inst := $(PATH_INS)
[380]2434endif
2435
2436mode := $(firstword \
[481]2437 $($(target)_$(directory)_MODE.$(bld_trg).$(bld_trg_arch)) \
[380]2438 $($(target)_$(directory)_MODE.$(bld_trg)) \
2439 $($(target)_$(directory)_MODE) \
[481]2440 $($(directory)_MODE.$(bld_trg).$(bld_trg_arch)) \
[380]2441 $($(directory)_MODE.$(bld_trg)) \
2442 $($(directory)_MODE) \
[481]2443 $($(target)_MODE.$(bld_trg).$(bld_trg_arch)) \
[380]2444 $($(target)_MODE.$(bld_trg)) \
2445 $($(target)_MODE))
2446uid := $(firstword \
[481]2447 $($(target)_$(directory)_UID.$(bld_trg).$(bld_trg_arch)) \
[380]2448 $($(target)_$(directory)_UID.$(bld_trg)) \
2449 $($(target)_$(directory)_UID) \
[481]2450 $($(directory)_UID.$(bld_trg).$(bld_trg_arch)) \
[380]2451 $($(directory)_UID.$(bld_trg)) \
2452 $($(directory)_UID) \
[481]2453 $($(target)_UID.$(bld_trg).$(bld_trg_arch)) \
[380]2454 $($(target)_UID.$(bld_trg)) \
2455 $($(target)_UID))
2456gid := $(firstword \
[481]2457 $($(target)_$(directory)_GID.$(bld_trg).$(bld_trg_arch)) \
[380]2458 $($(target)_$(directory)_GID.$(bld_trg)) \
2459 $($(target)_$(directory)_GID) \
[481]2460 $($(directory)_GID.$(bld_trg).$(bld_trg_arch)) \
[380]2461 $($(directory)_GID.$(bld_trg)) \
2462 $($(directory)_GID) \
[481]2463 $($(target)_GID.$(bld_trg).$(bld_trg_arch)) \
[380]2464 $($(target)_GID.$(bld_trg)) \
2465 $($(target)_GID))
[830]2466flags := \
2467 $($(target)_IDFLAGS)\
2468 $($(target)_IDFLAGS.$(bld_trg)) \
2469 $($(target)_IDFLAGS.$(bld_trg).$(bld_trg_arch)) \
2470 $($(directory)_IDFLAGS) \
2471 $($(directory)_IDFLAGS.$(bld_trg)) \
2472 $($(directory)_IDFLAGS.$(bld_trg).$(bld_trg_arch)) \
2473 $($(target)_$(directory)_IDFLAGS) \
2474 $($(target)_$(directory)_IDFLAGS.$(bld_trg)) \
2475 $($(target)_$(directory)_IDFLAGS.$(bld_trg).$(bld_trg_arch))
[380]2476
2477insdst := $(inst)/$(directory)/
2478#$(warning directory=$(directory) inst=$(inst) insdst=$(insdst) mode=$(mode) gid=$(gid) uid=$(uid))
2479
2480# generate the rule (need double evaluation here)
2481$(eval $(def_install_directory_rule))
2482
2483INSTARGET_DIRS_$(target) += $(insdst)
2484endef
2485
2486
[353]2487## process one install target.
2488define def_install
[744]2489# the basics.
[353]2490bld_type := $(firstword $($(target)_BLD_TYPE) $(BUILD_TYPE))
2491bld_trg := $(firstword $($(target)_BLD_TRG) $(BUILD_TARGET))
2492bld_trg_arch:= $(firstword $($(target)_BLD_TRG_ARCH) $(BUILD_TARGET_ARCH))
2493bld_trg_cpu := $(firstword $($(target)_BLD_TRG_CPU) $(BUILD_TARGET_CPU))
2494
[827]2495INSTARGET_$(target) := $($(target)_GOALS)
[380]2496INSTARGET_DIRS_$(target) :=
2497
[481]2498$(foreach directory,$($(target)_DIRS) $($(target)_DIRS.$(bld_trg)) $($(target)_DIRS.$(bld_trg).$(bld_trg_arch)) $($(target)_DIRS.$(bld_trg_arch)) $($(target)_DIRS.$(bld_trg_cpu)) $($(target)_DIRS.$(bld_type)), \
[380]2499 $(eval $(value def_install_directory)))
2500
[481]2501$(foreach src,$($(target)_SOURCES) $($(target)_SOURCES.$(bld_trg)) $($(target)_SOURCES.$(bld_trg).$(bld_trg_arch)) $($(target)_SOURCES.$(bld_trg_arch)) $($(target)_SOURCES.$(bld_trg_cpu)) $($(target)_SOURCES.$(bld_type)), \
[353]2502 $(eval $(value def_install_src)))
2503
[481]2504$(foreach src,$($(target)_SYMLINKS) $($(target)_SYMLINKS.$(bld_trg)) $($(target)_SYMLINKS.$(bld_trg).$(bld_trg_arch)) $($(target)_SYMLINKS.$(bld_trg_arch)) $($(target)_SYMLINKS.$(bld_trg_cpu)) $($(target)_SYMLINKS.$(bld_type)), \
[353]2505 $(eval $(value def_install_symlink)))
2506
[827]2507# the collection target
2508TARGET_$(target) := $(PATH_TARGET)/$(target).ins
[838]2509$(TARGET_$(target)): $(INSTARGET_$(target)) | $(INSTARGET_DIRS_$(target)) $(call DIRDEP,$(PATH_TARGET))
[827]2510 @$(QUIET2)$(APPEND) $@
2511
2512$(target): $(TARGET_$(target))
2513
2514_INSTALLS += $(TARGET_$(target))
2515_INSTALLS_FILES += $(INSTARGET_$(target))
[380]2516_INSTALLS_DIRS += $(INSTARGET_DIRS_$(target))
[905]2517_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))
2518_DIRS += $($(target)_BLDDIRS) $($(target)_BLDDIRS.$(bld_trg)) $($(target)_BLDDIRS.$(bld_trg).$(bld_trg_arch)) $($(target)_BLDDIRS.$(bld_trg_arch)) $($(target)_BLDDIRS.$(bld_trg_cpu)) $($(target)_BLDDIRS.$(bld_type))
[353]2519endef
2520
2521## process all install targets
[481]2522$(foreach target, $(INSTALLS) $(INSTALLS.$(BUILD_TARGET)) $(INSTALLS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)), \
[353]2523 $(eval $(value def_install)))
2524
[988]2525ifdef KBUILD_PROFILE_SELF
2526 _KBUILD_TS_NOW := $(nanots )
2527 $(info prof: $(int-sub $(_KBUILD_TS_NOW), $(_KBUILD_TS_HEADER_START)) - $(int-sub $(_KBUILD_TS_NOW), $(_KBUILD_TS_PREV)) - done install targets)
2528 _KBUILD_TS_PREV := $(_KBUILD_TS_NOW)
2529endif
[353]2530
[988]2531
[72]2532#
[417]2533# PACKING
2534#
[481]2535_PACKING += $(PACKING) $(PACKING.$(BUILD_TARGET)) $(PACKING.$(BUILD_TARGET).$(BUILD_TARGET_ARCH))
[417]2536
2537
2538#
[72]2539# DOCS
2540#
2541
2542
2543#
[353]2544# DIRECTORIES
2545#
[827]2546_DIR_ALL := $(sort $(addsuffix /,$(patsubst %/,%,$(_DIRS))) $(dir $(_OUT_FILES) $(_OBJS) $(_INSTALLS_FILES)))
[380]2547$(foreach directory,$(_INSTALLS_DIRS), $(eval _DIR_ALL := $(filter-out $(directory),$(_DIR_ALL))))
[353]2548
[380]2549
[353]2550define def_mkdir_rule
2551$(directory):
[776]2552 $$(call MSG_MKDIR,$$@)
[696]2553 $$(QUIET)$$(MKDIR) -p $$@
[72]2554endef
2555
[353]2556$(foreach directory,$(_DIR_ALL),$(eval $(def_mkdir_rule)))
[72]2557
[988]2558ifdef KBUILD_PROFILE_SELF
2559 _KBUILD_TS_NOW := $(nanots )
2560 $(info prof: $(int-sub $(_KBUILD_TS_NOW), $(_KBUILD_TS_HEADER_START)) - $(int-sub $(_KBUILD_TS_NOW), $(_KBUILD_TS_PREV)) - done directories)
2561 _KBUILD_TS_PREV := $(_KBUILD_TS_NOW)
2562endif
[183]2563
[988]2564
[72]2565#
[353]2566# NOTHING
[72]2567#
[353]2568do-nothing:
[988]2569ifdef KBUILD_PROFILE_SELF
2570 @$(ECHO) 'prof: $(int-sub $(nanots ), $(_KBUILD_TS_HEADER_START)) - $(int-sub $(nanots ), $(_KBUILD_TS_PREV)) - executing $@'
2571endif
[776]2572 $(call MSG_NOTHING)
[72]2573
[183]2574
[75]2575#
[353]2576# CLEAN UP
[75]2577#
[353]2578do-clean:
[776]2579 $(call MSG_CLEAN)
[701]2580 $(QUIET)$(RM) -f $(_OUT_FILES) $(_OBJS) $(_DEPFILES) $(_DEPFILES_INCLUDED) $(_CLEAN_FILES) $(OTHER_CLEAN)
[966]2581 $(QUIET)$(RMDIR) -p --ignore-fail-on-non-empty --ignore-fail-on-not-exist $(rsort $(dir $(_OUT_FILES) $(_OBJS) $(_DEPFILES) $(_DEPFILES_INCLUDED) $(_CLEAN_FILES) $(OTHER_CLEAN)))
[72]2582
[98]2583
[897]2584
[353]2585#
2586# PASSES (including directory and makefile walking)
2587#
[221]2588
[75]2589## Subdir
2590# @param $(pass) Lowercase pass name.
2591# @param $(PASS) Uppercase pass name.
2592# @param $(subdir) Subdirectory
2593# @param $(tag) tag to attach to the rule name.
2594define def_pass_subdir
[219]2595pass_$(pass)$(tag):: $(dep)
[696]2596 + $$(QUIET)$$(MAKE) -C $(subdir) -f $$(notdir $$(firstword $$(wildcard $$(addprefix $(subdir)/,$$(DEFAULT_MAKEFILE))))) pass_$(pass)
[75]2597endef
[72]2598
[75]2599## Submakefile
2600# @param $(pass) Lowercase pass name.
2601# @param $(PASS) Uppercase pass name.
2602# @param $(makefile) Makefile.
2603# @param $(tag) tag to attach to the rule name.
2604define def_pass_makefile
[219]2605pass_$(pass)$(tag):: $(dep)
[696]2606 + $$(QUIET)$$(MAKE) -C $(patsubst %/,%,$(dir $(makefile))) -f $(notdir $(makefile)) pass_$(pass)
[75]2607endef
[73]2608
[75]2609## Execute a pass.
2610# @param $(pass) Lowercase pass name.
2611# @param $(PASS) Uppercase pass name.
[353]2612define def_pass_old
[481]2613$(eval SUBDIRS_$(PASS) ?= $(SUBDIRS) $(SUBDIRS.$(BUILD_TARGET)) $(SUBDIRS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) )
2614$(eval SUBDIRS_AFTER_$(PASS) ?= $(SUBDIRS_AFTER) $(SUBDIRS_AFTER.$(BUILD_TARGET)) $(SUBDIRS_AFTER.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) )
2615$(eval MAKEFILES_BEFORE_$(PASS) ?= $(MAKEFILES_BEFORE) $(MAKEFILES_BEFORE.$(BUILD_TARGET)) $(MAKEFILES_BEFORE.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) )
2616$(eval MAKEFILES_AFTER_$(PASS) ?= $(MAKEFILES_AFTER) $(MAKEFILES_AFTER.$(BUILD_TARGET)) $(MAKEFILES_AFTER.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) )
[75]2617
2618$(eval tag:=_before)
[219]2619$(eval dep:=)
[481]2620$(foreach subdir,$(SUBDIRS_$(PASS)) $(SUBDIRS_$(PASS).$(BUILD_TARGET)) $(SUBDIRS_$(PASS).$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) ,$(eval $(def_pass_subdir)))
2621$(foreach makefile,$(MAKEFILES_BEFORE_$(PASS)) $(MAKEFILES_BEFORE_$(PASS).$(BUILD_TARGET)) $(MAKEFILES_BEFORE_$(PASS).$(BUILD_TARGET).$(BUILD_TARGET_ARCH)),$(eval $(def_pass_makefile)))
[75]2622
2623$(eval tag:=_after)
[219]2624$(eval dep:=pass_$(pass)_doit)
[481]2625$(foreach subdir,$(SUBDIRS_AFTER_$(PASS)) $(SUBDIRS_AFTER_$(PASS).$(BUILD_TARGET)) $(SUBDIRS_AFTER_$(PASS).$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) ,$(eval $(def_pass_subdir)))
2626$(foreach makefile,$(MAKEFILES_AFTER_$(PASS)) $(MAKEFILES_AFTER_$(PASS).$(BUILD_TARGET)) $(MAKEFILES_AFTER_$(PASS).$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) ,$(eval $(def_pass_makefile)))
[75]2627
2628.NOTPARALLEL: pass_$(pass)_before pass_$(pass)_after
2629.PHONY: pass_$(pass) pass_$(pass)_before pass_$(pass)_doit pass_$(pass)_after
[353]2630pass_$(pass)_doit: $(PASS_$(PASS)_trgs) $(foreach var,$(PASS_$(PASS)_vars),$(var))
[272]2631pass_$(pass)_this: pass_$(pass)_before
[696]2632 + $$(QUIET)$$(MAKE) -f $$(MAKEFILE) pass_$(pass)_doit
[220]2633pass_$(pass)_after:: pass_$(pass)_this
[219]2634pass_$(pass): pass_$(pass)_after
[75]2635
[183]2636endef
2637
[353]2638define def_pass
[481]2639$(eval SUBDIRS_$(PASS) ?= $(SUBDIRS) $(SUBDIRS.$(BUILD_TARGET)) $(SUBDIRS.$(BUILD_TARGET.$(BUILD_TARGET_ARCH))) )
2640$(eval SUBDIRS_AFTER_$(PASS) ?= $(SUBDIRS_AFTER) $(SUBDIRS_AFTER.$(BUILD_TARGET)) $(SUBDIRS_AFTER.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) )
2641$(eval MAKEFILES_BEFORE_$(PASS) ?= $(MAKEFILES_BEFORE) $(MAKEFILES_BEFORE.$(BUILD_TARGET)) $(MAKEFILES_BEFORE.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) )
2642$(eval MAKEFILES_AFTER_$(PASS) ?= $(MAKEFILES_AFTER) $(MAKEFILES_AFTER.$(BUILD_TARGET)) $(MAKEFILES_AFTER.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) )
[183]2643
[353]2644$(eval tag:=_before)
2645$(eval dep:=)
[481]2646$(foreach subdir,$(SUBDIRS_$(PASS)) $(SUBDIRS_$(PASS).$(BUILD_TARGET)) $(SUBDIRS_$(PASS).$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) ,$(eval $(def_pass_subdir)))
2647$(foreach makefile,$(MAKEFILES_BEFORE_$(PASS)) $(MAKEFILES_BEFORE_$(PASS).$(BUILD_TARGET)) $(MAKEFILES_BEFORE_$(PASS).$(BUILD_TARGET).$(BUILD_TARGET_ARCH)),$(eval $(def_pass_makefile)))
[75]2648
[353]2649$(eval tag:=_after)
2650$(eval dep:=pass_$(pass)_doit)
[481]2651$(foreach subdir,$(SUBDIRS_AFTER_$(PASS)) $(SUBDIRS_AFTER_$(PASS).$(BUILD_TARGET)) $(SUBDIRS_AFTER_$(PASS).$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) ,$(eval $(def_pass_subdir)))
2652$(foreach makefile,$(MAKEFILES_AFTER_$(PASS)) $(MAKEFILES_AFTER_$(PASS).$(BUILD_TARGET)) $(MAKEFILES_AFTER_$(PASS).$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) ,$(eval $(def_pass_makefile)))
[75]2653
[380]2654ifdef KBUILD_SAFE_PARALLEL
[353]2655.NOTPARALLEL: pass_$(pass) pass_$(pass)_before pass_$(pass)_after pass_$(pass)_this
2656.PHONY: pass_$(pass) pass_$(pass)_before pass_$(pass)_after pass_$(pass)_this pass_$(pass)_doit
2657pass_$(pass)_doit: $(PASS_$(PASS)_trgs) $(foreach var,$(PASS_$(PASS)_vars),$(var))
2658pass_$(pass)_this: pass_$(pass)_before
[696]2659 + $$(QUIET)$$(MAKE) -f $$(MAKEFILE) pass_$(pass)_doit
[353]2660pass_$(pass)_after:: pass_$(pass)_this
2661pass_$(pass): pass_$(pass)_after
2662else
[388]2663.NOTPARALLEL: pass_$(pass) pass_$(pass)_before pass_$(pass)_after pass_$(pass)_doit
[353]2664.PHONY: pass_$(pass) pass_$(pass)_before pass_$(pass)_after pass_$(pass)_doit
2665pass_$(pass)_doit: pass_$(pass)_before \
2666 $(PASS_$(PASS)_trgs) $(foreach var,$(PASS_$(PASS)_vars),$($(var)))
2667pass_$(pass): \
2668 pass_$(pass)_before \
2669 pass_$(pass)_doit \
[388]2670 pass_$(pass)_after
[353]2671endif
[189]2672
[353]2673#$ (warning pass=$(pass) PASS=$(PASS): $(PASS_$(PASS)_trgs) $(PASS_$(PASS)_trgs) $(foreach var,$(PASS_$(PASS)_vars),$($(var))))
2674endef
[75]2675
[353]2676# Generate the defined passes.
2677$(foreach PASS, $(PASSES), \
2678 $(eval pass := $(PASS_$(PASS)_pass)) \
2679 $(eval $(def_pass)))
[75]2680
[219]2681## Pass order
2682# @param $(pass) Current pass name.
2683# @param $(prev_pass) The previous pass name.
2684define def_pass_order
[380]2685ifdef KBUILD_SAFE_PARALLEL
[353]2686.NOTPARALLEL: pass_$(pass)_order
2687.PHONY: pass_$(pass)_order
[219]2688pass_$(pass)_order: $(pass_prev)
[776]2689 $$(call MSG_PASS,$$(if $$(PASS_$(PASS)),$$(PASS_$(PASS)),$(pass)))
[696]2690 + $$(QUIET)$$(MAKE) -f $$(MAKEFILE) pass_$(pass)
[353]2691else
2692.NOTPARALLEL: pass_$(pass)_order pass_$(pass)_banner
[388]2693.PHONY: pass_$(pass)_order pass_$(pass)_banner
[353]2694pass_$(pass)_banner:
[776]2695 $$(call MSG_PASS,$$(if $$(PASS_$(PASS)),$$(PASS_$(PASS)),$(pass)))
[353]2696pass_$(pass)_order: \
2697 $(pass_prev) \
2698 pass_$(pass)_banner \
2699 pass_$(pass)
2700endif
[219]2701$(eval pass_prev := pass_$(pass)_order)
2702endef
[183]2703
[219]2704## PASS: order
2705# Use dependencies to ensure correct pass order.
2706pass_prev :=
[353]2707$(foreach PASS,$(DEFAULT_PASSES),\
2708 $(eval pass := $(PASS_$(PASS)_pass)) \
2709 $(eval $(def_pass_order)))
[219]2710
[988]2711ifdef KBUILD_PROFILE_SELF
2712 _KBUILD_TS_NOW := $(nanots )
2713 $(info prof: $(int-sub $(_KBUILD_TS_NOW), $(_KBUILD_TS_HEADER_START)) - $(int-sub $(_KBUILD_TS_NOW), $(_KBUILD_TS_PREV)) - done passes)
2714 _KBUILD_TS_PREV := $(_KBUILD_TS_NOW)
2715endif
[272]2716
[897]2717
[75]2718#
2719# THE MAIN RULES
2720#
[219]2721all_recursive: $(pass_prev)
[75]2722
[130]2723rebuild: clean
[219]2724 + $(MAKE) -f $(firstword $(MAKEFILE_LIST)) all_recursive
[78]2725
[412]2726# @todo make this a non-default pass!
[353]2727uninstall:
[827]2728 $(RM) -f $(_INSTALLS_FILES)
[412]2729
[380]2730install: pass_installs
[78]2731
[75]2732# misc shortcuts.
[380]2733targets: bldprogs libraries dlls programs sysmods others installs
[75]2734objects: $(_OBJS)
[222]2735bldprogs: $(_BLDPROGS)
[189]2736libraries: $(_LIBS) $(_IMPORT_LIBS) $(_OTHER_LIBRARIES)
[205]2737dlls: $(_DLLS)
[219]2738programs: $(_PROGRAMS)
[205]2739sysmods: $(_SYSMODS)
[353]2740others: $(_OTHERS)
[854]2741installs: $(_INSTALLS) $(_INSTALLS_DIRS) $(_INSTALLS_FILES)
[75]2742
2743
[897]2744
[353]2745#
2746# kBuild debugging stuff.
2747#
2748show_targets:
[984]2749 @$(foreach target, $(_ALL_TARGETS),\
[353]2750 @$(ECHO) "target: $(target)" $(NLTAB)\
2751 @$(ECHO) " PATH_$(target)=$(PATH_$(target))" $(NLTAB)\
2752 @$(ECHO) " TARGET_$(target)=$(TARGET_$(target))" $(NLTAB)\
2753 @$(ECHO) " INSTARGET_$(target)=$(INSTARGET_$(target))" $(NLTAB)\
[660]2754$(foreach prop,$(PROPS_SINGLE) $(PROPS_ACCUMULATE_L) $(PROPS_ACCUMULATE_R) OBJS_ CLEAN, \
[353]2755 $(eval _tmp:=$(firstword $($(target)_BLD_TRG) $(BUILD_TARGET))) \
2756 $(if $($(target)_$(prop).$(_tmp)),\
2757 @$(ECHO) " $(target)_$(prop).$(_tmp)=$($(target)_$(prop).$(_tmp))" $(NLTAB)) \
2758 $(if $($(target)_$(prop)), $(NLTAB)@$(ECHO) " $(target)_$(prop)=$($(target)_$(prop))" $(NLTAB)) \
2759)\
2760$(foreach prop,$(PROPS_DEFERRED), \
2761 $(eval _tmp:=$(firstword $($(target)_BLD_TRG) $(BUILD_TARGET))) \
2762 $(if $(value $(target)_$(prop).$(_tmp)),\
2763 @$(ECHO) ' $(target)_$(prop).$(_tmp)=$(value $(TARGET)_$(prop).$(_tmp))' $(NLTAB)) \
2764 $(if $(value $(target)_$(prop)), $(NLTAB)@$(ECHO) ' $(target)_$(prop)=$(value $(target)_$(prop))' $(NLTAB)) \
2765))
2766
2767
2768
2769#
2770# Include dependency files.
2771#
[893]2772ifneq ($(_DEPFILES),)
2773 includedep $(_DEPFILES)
2774endif
[353]2775
2776
[988]2777ifdef KBUILD_PROFILE_SELF
2778 _KBUILD_TS_FOOTER_END := $(nanots )
2779 $(info prof: $(int-sub $(_KBUILD_TS_FOOTER_END), $(_KBUILD_TS_HEADER_START)) - $(int-sub $(_KBUILD_TS_FOOTER_END), $(_KBUILD_TS_PREV)) - end of footer.kmk)
2780 $(info prof: footer.kmk: $(int-sub $(_KBUILD_TS_FOOTER_END), $(_KBUILD_TS_FOOTER_START)))
2781 _KBUILD_TS_PREV := $(_KBUILD_TS_FOOTER_END)
2782endif
2783
[72]2784# end-of-file-content
[106]2785__footer_kmk__ := target
[72]2786endif # __footer_kmk__
[438]2787
Note: See TracBrowser for help on using the repository browser.