source: trunk/kBuild/footer.kmk@ 1255

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

Use the kBuild md5sum.

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