source: trunk/kBuild/footer.kmk@ 1242

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

SDKs can have LDFLAGS too. (LIBSDK+darwin)

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 97.9 KB
RevLine 
[72]1# $Id: footer.kmk 1242 2007-10-14 15:20:29Z 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
[688]987# 1. Port md5sum or some equivalent tool and include it in kBuild.
988# 2. Download corruption / continuation.
989# 3. It's quite possible that there is one too many indirect dependency now...
990#
991
992## @todo move this!
[640]993MD5SUM := md5sum
994
995## generates the fetch rule
996define def_fetch_src_fetch_rule
997# Indirect goal for downloading something.
[682]998.PRECIOUS: $(out)
[1030]999$(out) + $($(target)_$(srcname)_FETCH_OUTPUT_) +| $($(target)_$(srcname)_FETCH_OUTPUT_MAYBE_) : \
1000 | $($(target)_$(srcname)_FETCH_DEPORD_)
[776]1001 $$(call MSG_FETCH_DL,$(target),$(source),$(out))
[696]1002 @## @todo do fancy stuff like download continuation.
1003 $$(QUIET)$$(RM) -f $(out) $(out).md5
[640]1004 $($(target)_$(srcname)_FETCH_CMDS_)
[696]1005 $$(QUIET2)$(if $(md5),$$(APPEND) $(out).md5 "$(md5) *$(out)")
1006 $$(QUIET)$(if $(md5),$$(MD5SUM) -c $(out).md5)
[640]1007
1008
[682]1009
[640]1010# Intermediate goal for making sure the md5 and size matches. it will (re) fetch the archive if necessary.
1011$(out).checked_$(md5)_$(size): $($(target)_$(srcname)_FETCH_DEPEND_) | $($(target)_$(srcname)_FETCH_DEPORD_)
[776]1012 $$(call MSG_FETCH_CHK,$(target),$(source),$(out))
[696]1013 $$(QUIET)$$(RM) -f $$@ $(out).md5
[640]1014 @# creates the .md5 we pass to md5sum.
[696]1015 $$(QUIET2)$(if $(md5),$$(APPEND) $(out).md5 "$(md5) *$(out)")
[688]1016 @# (re)fetch the file if it doesn't exist or if it doesn't matches the md5.
[696]1017 @## @todo do fancy stuff like download continuation.
1018 $$(QUIET)( test -f $(out) && $(if $(md5),$$(MD5SUM) -c $(out).md5, true) ) \
1019 || ( $$(RM_EXT) -f $(out) \
1020 && $$(MAKE) $(out) -f $(MAKEFILE) --no-print-directory )
1021 $$(QUIET2)$$(APPEND) $$@
[640]1022
[719]1023_TARGET_$(target)_FETCHED += $(out) $(out).checked_$(md5)_$(size)
[640]1024
[688]1025# Just a little precaution.
1026.NOTPARALLEL: $(out) $(out).checked_$(md5)_$(size)
1027
[640]1028endef
1029
1030## generates the unpack rule
1031define def_fetch_src_unpack_rule
1032# This is the unpack rule. it has an order-only dependency on the download check.
[1030]1033$(out) + $($(target)_$(srcname)_UNPACK_OUTPUT_) +| $($(target)_$(srcname)_UNPACK_OUTPUT_MAYBE_) : \
1034 $($(target)_$(srcname)_UNPACK_DEPEND_) \
[640]1035 | $($(target)_$(srcname)_UNPACK_DEPORD_) $(archive).checked_$(md5)_$(size)
[776]1036 $$(call MSG_FETCH_UP,$(target),$(archive),$(inst))
[696]1037 $$(QUIET)$$(RM) -f $(out)
[688]1038 @# if the source archive doesn't exist fetch it (can have been deleted to save space).
[696]1039 $$(QUIET)test -f $(archive) \
1040 || ( $$(RM_EXT) -f $(archive).checked_$(md5)_$(size) \
1041 && $$(MAKE) $(archive).checked_$(md5)_$(size) -f $(MAKEFILE) --no-print-directory )
[640]1042 $($(target)_$(srcname)_UNPACK_CMDS_)
[696]1043 $$(QUIET2)$$(APPEND) $(out) $(notdir $(archive).checked_$(md5)_$(size))
1044 $$(QUIET2)$$(APPEND) $(out) $(notdir $(out))
[640]1045
1046$(eval _TARGET_$(target)_UNPACKED += $(out))
1047_TARGET_$(target)_DIGEST := $(_TARGET_$(target)_DIGEST)-$(srcname)_$(md5)_$(size)
1048
[688]1049.NOTPARALLEL: $(out)
1050
[719]1051endef
[640]1052
1053## Processes a fetch source
1054#
1055define def_fetch_src
1056#$ (warning dbg: def_fetch_src: source='$(source)' target='$(target)')
1057
1058# common
1059srcname := $(notdir $(source))
1060inst := $(firstword \
1061 $($(target)_$(source)_INST)\
1062 $($(target)_$(srcname)_INST)\
1063 $($(source)_INST)\
1064 $($(srcname)_INST)\
1065 $($(target)_INST)\
1066)
1067ifneq ($(patsubst %/,ok,$(inst)),ok)
1068$(error kBuild: Bad or missing INST property for source '$(source)' in target '$(target)': $(inst))
1069endif
1070INSTARGET_$(target)_$(srcname) := $(inst)
1071fetchdir := $(firstword \
1072 $($(target)_$(source)_FETCHDIR)\
1073 $($(target)_$(srcname)_FETCHDIR)\
1074 $($(source)_FETCHDIR)\
1075 $($(srcname)_FETCHDIR)\
1076 $($(target)_FETCHDIR)\
1077 $(FETCHDIR)\
1078 $(PATH_TARGET)\
1079)
1080deps := \
1081 $($(target)_$(source)_DEPS)\
1082 $($(target)_$(srcname)_DEPS)\
1083 $($(source)_DEPS)\
1084 $($(srcname)_DEPS)\
1085 $($(target)_DEPS)
[827]1086orderdeps := \
1087 $($(target)_$(source)_ORDERDEPS)\
1088 $($(target)_$(srcname)_ORDERDEPS)\
1089 $($(source)_ORDERDEPS)\
1090 $($(srcname)_ORDERDEPS)\
1091 $($(target)_ORDERDEPS)
[640]1092md5 := $(firstword \
1093 $($(target)_$(source)_MD5)\
1094 $($(target)_$(srcname)_MD5)\
1095 $($(source)_MD5)\
1096 $($(srcname)_MD5)\
1097 $($(target)_MD5)\
1098)
1099size := $(firstword \
1100 $($(target)_$(source)_SIZE)\
1101 $($(target)_$(srcname)_SIZE)\
1102 $($(source)_SIZE)\
1103 $($(srcname)_SIZE)\
1104 $($(target)_SIZE)\
1105)
1106dep := # not legal for fetch and unpack tools
1107
1108
1109#
1110# The fetching.
1111#
1112out := $(fetchdir)/$(srcname)
1113archive := $(out)
1114TARGET_$(target)_$(srcname) := $(out)
1115dirdep := $(call DIRDEP,$(fetchdir))
1116tool := $(firstword \
1117 $($(target)_$(source)_FETCHTOOL)\
1118 $($(target)_$(srcname)_FETCHTOOL)\
1119 $($(target)_$(source)_TOOL)\
1120 $($(target)_$(srcname)_TOOL)\
1121 $($(source)_FETCHTOOL)\
1122 $($(srcname)_FETCHTOOL)\
1123 $($(source)_TOOL)\
1124 $($(srcname)_TOOL)\
1125 $($(target)_FETCHTOOL)\
1126 $($(target)_TOOL)\
1127 )
1128flags :=\
1129 $(TOOL_$(tool)_FETCHFLAGS)\
1130 $(FETCHFLAGS)\
1131 $($(target)_FETCHFLAGS)\
1132 $($(srcname)_FETCHFLAGS)\
1133 $($(source)_FETCHFLAGS)\
1134 $($(target)_$(srcname)_FETCHFLAGS)\
1135 $($(target)_$(source)_FETCHFLAGS)
1136
1137#$ (warning dbg: target=$(target) source=$(source) $(srcname)=$(srcname) tool=$(tool) out=$(out) flags=$(flags) dirdep=$(dirdep) fetchdir=$(fetchdir) md5=$(md5) size=$(size))
1138
1139ifndef TOOL_$(tool)_FETCH_CMDS
1140$(warning kBuild: tools: \
1141 1 $($(target)_$(source)_FETCHTOOL)\
1142 2 $($(target)_$(srcname)_FETCHTOOL)\
1143 3 $($(target)_$(source)_TOOL)\
1144 4 $($(target)_$(srcname)_TOOL)\
1145 5 $($(source)_FETCHTOOL)\
1146 6 $($(srcname)_FETCHTOOL)\
1147 7 $($(source)_TOOL)\
1148 8 $($(srcname)_TOOL)\
1149 9 $($(target)_FETCHTOOL)\
1150 10 $($(target)_TOOL) )
1151$(error kBuild: TOOL_$(tool)_FETCH_CMDS is not defined. source=$(source) target=$(target) )
1152endif
1153
1154# call the tool
1155$(target)_$(srcname)_FETCH_CMDS_ := $(TOOL_$(tool)_FETCH_CMDS)
1156$(target)_$(srcname)_FETCH_OUTPUT_ := $(TOOL_$(tool)_FETCH_OUTPUT)
[1030]1157$(target)_$(srcname)_FETCH_OUTPUT_MAYBE_ := $(TOOL_$(tool)_FETCH_OUTPUT_MAYBE)
[640]1158$(target)_$(srcname)_FETCH_DEPEND_ := $(TOOL_$(tool)_FETCH_DEPEND) $(deps)
[827]1159$(target)_$(srcname)_FETCH_DEPORD_ := $(TOOL_$(tool)_FETCH_DEPORD) $(dirdep) $(orderdeps)
[640]1160
1161# generate the fetch rule.
1162$(eval $(def_fetch_src_fetch_rule))
1163
1164
1165#
1166# The unpacking / installing.
1167#
1168out := $(inst)_kBuild_$(target)_$(srcname)_unpacked.lst
1169dirdep := $(call DIRDEP,$(inst))
1170tool := $(firstword \
1171 $($(target)_$(source)_UNPACKTOOL)\
1172 $($(target)_$(srcname)_UNPACKTOOL)\
1173 $($(target)_$(source)_TOOL)\
1174 $($(target)_$(srcname)_TOOL)\
1175 $($(source)_UNPACKTOOL)\
1176 $($(srcname)_UNPACKTOOL)\
1177 $($(source)_TOOL)\
1178 $($(srcname)_TOOL)\
1179 $($(target)_UNPACKTOOL)\
1180 $($(target)_TOOL) \
1181 )
1182ifeq ($(tool),)
1183tool := $(toupper $(subst .,,$(suffix $(subst tar.,TAR,$(srcname)))))
1184$(eval $(value def_tools_include))
1185endif
1186flags :=\
1187 $(TOOL_$(tool)_UNPACKFLAGS)\
1188 $(UNPACKFLAGS)\
1189 $($(target)_UNPACKFLAGS)\
1190 $($(srcname)_UNPACKFLAGS)\
1191 $($(source)_UNPACKFLAGS)\
1192 $($(target)_$(srcname)_UNPACKFLAGS)\
1193 $($(target)_$(source)_UNPACKFLAGS)
1194
1195#$ (warning dbg: target=$(target) source=$(source) $(srcname)=$(srcname) tool=$(tool) out=$(out) flags=$(flags) dirdep=$(dirdep) inst=$(inst) md5=$(md5) size=$(size))
1196ifndef TOOL_$(tool)_UNPACK_CMDS
1197$(warning kBuild: tools: \
1198 1 $($(target)_$(source)_UNPACKTOOL)\
1199 2 $($(target)_$(srcname)_UNPACKTOOL)\
1200 3 $($(target)_$(source)_TOOL)\
1201 4 $($(target)_$(srcname)_TOOL)\
1202 5 $($(source)_UNPACKTOOL)\
1203 6 $($(srcname)_UNPACKTOOL)\
1204 7 $($(source)_TOOL)\
1205 8 $($(srcname)_TOOL)\
1206 9 $($(target)_UNPACKTOOL)\
1207 10 $($(target)_TOOL) \
1208 11 $(toupper $(subst tar.,TAR,$(ext $(srcname)))) \
1209 )
1210$(error kBuild: TOOL_$(tool)_UNPACK_CMDS is not defined. source=$(source) target=$(target) )
1211endif
1212
1213# call the tool
1214$(target)_$(srcname)_UNPACK_CMDS_ := $(TOOL_$(tool)_UNPACK_CMDS)
1215$(target)_$(srcname)_UNPACK_OUTPUT_ := $(TOOL_$(tool)_UNPACK_OUTPUT)
[1030]1216$(target)_$(srcname)_UNPACK_OUTPUT_MAYBE_ := $(TOOL_$(tool)_UNPACK_OUTPUT_MAYBE)
[640]1217$(target)_$(srcname)_UNPACK_DEPEND_ := $(TOOL_$(tool)_UNPACK_DEPEND) $(deps)
[827]1218$(target)_$(srcname)_UNPACK_DEPORD_ := $(TOOL_$(tool)_UNPACK_DEPORD) $(dirdep) $(orderdeps)
[640]1219
1220# generate the fetch rule.
1221$(eval $(def_fetch_src_unpack_rule))
1222
1223_DIRS += $(inst) $(fetchdir)
1224
1225endef
1226
1227
1228##
1229# Define the target level rules for a fetch.
1230# @param target
1231# @param out
1232# @param inst
[688]1233# @param _TARGET_$(target)_UNPACKED
1234# @param _TARGET_$(target)_DIGEST
[640]1235# @param bld_trg
1236# @param bld_trg_arch
1237define def_fetch_rules
1238
[689]1239$(out).lst: $(_TARGET_$(target)_UNPACKED) | $(call DIRDEP,$(inst))
[776]1240 $$(call MSG_FETCH_OK,$(target))
[696]1241 $$(QUIET)$$(RM) -f $$@ $$@.tmp
1242 $$(QUIET2)$$(APPEND) $$@.tmp "$(notdir $(out))"
1243 $$(QUIET)$(if $(_TARGET_$(target)_UNPACKED),$$(CAT_EXT) $(_TARGET_$(target)_UNPACKED) >> $$@.tmp)
1244 $$(QUIET)$$(MV) -f $$@.tmp $$@
[640]1245
1246$(out)_unfetched:
[776]1247 $$(call MSG_UNFETCH,$(target))
[696]1248 $$(QUIET)$$(RM) -f $$(addprefix $(inst),$$(shell $$(CAT_EXT) $(out).lst 2> /dev/null | $$(SED) -e '/\/$$$$/d'))
1249 $$(QUIET)$$(RMDIR) -p --ignore-fail-on-non-empty --ignore-fail-on-not-exist $$(dir $$@) \
[689]1250 $$(addprefix $(inst),$$(sort $$(dir $$(shell $$(CAT_EXT) $(out).lst 2> /dev/null))))
[696]1251 $$(QUIET)$$(RM) -f $(out).lst $(out)
1252 $$(QUIET)$$(RMDIR) -p --ignore-fail-on-non-empty --ignore-fail-on-not-exist $$(dir $$@)
[640]1253
[689]1254$(out): $(comp-vars _TARGET_$(target)_DIGEST_PREV,_TARGET_$(target)_DIGEST,FORCE) | $(call DIRDEP,$(inst))
[696]1255 $$(QUIET)$$(RM) -f $$@
[776]1256 $$(if $$(_TARGET_$(target)_DIGEST),$$(if $$(wildcard $(out).lst)\
1257 ,$$(call MSG_REFETCH,$(target)),$$(call MSG_FETCH,$(target))),$$(call MSG_UNFETCH,$(target)))
[696]1258 $$(QUIET)$$(if $$(wildcard $(out).lst ),$$(MAKE) -f $(MAKEFILE) --no-print-directory $(out)_unfetched)
[701]1259 $$(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]1260 $$(QUIET2)$$(if $$(_TARGET_$(target)_DIGEST),$$(APPEND) $$@ "_TARGET_$(target)_DIGEST_PREV := $(_TARGET_$(target)_DIGEST)")
[760]1261
[689]1262.NOTPARALLEL: $(out).lst $(out)_unfetched $(out)
[688]1263
[640]1264endef
1265
1266
1267##
1268# Deal with one fetch target.
1269# @param target
1270# @param bld_trg
1271# @param bld_trg_arch
1272define def_fetch
1273# common
1274INSTARGET_$(target) := $($(target)_INST)
1275ifneq ($(patsubst %/,ok,$(INSTARGET_$(target))),ok)
[679]1276$(error kBuild: Bad or missing INST property for target '$(target)'. \
1277 $(target)_INST='$($(target)_INST)' ($(origin $(target)_INST)))
[640]1278endif
1279_TARGET_$(target)_FETCHED :=
1280_TARGET_$(target)_UNPACKED :=
1281_TARGET_$(target)_DIGEST :=
1282
1283# The 'sources'.
1284#$ (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)))
1285$(foreach source,$($(target)_SOURCES) $($(target)_SOURCES.$(BUILD_TYPE)) $($(target)_SOURCES.$(BUILD_TARGET)) $($(target)_SOURCES.$(BUILD_TARGET_ARCH)) $($(target)_SOURCES.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)),\
1286 $(eval $(value def_fetch_src)))
1287
1288# The target.
1289inst := $(INSTARGET_$(target))
1290out := $(inst)_kBuild_fetch_$(target)
1291
[689]1292$(eval includedep $(out))
[690]1293
[640]1294$(eval $(def_fetch_rules))
1295
[690]1296# Define the aliases here (doesn't work if defined in def_fetch_rules, just like includedep).
[749]1297$(target): $(out)
1298$(target)_unfetch: $(out)_unfetched
[690]1299
[689]1300_FETCHES += $(out)
[640]1301_DOWNLOADS += $(_TARGET_$(target)_FETCHED)
1302_UNPACKS += $(_TARGET_$(target)_UNPACKED)
1303_UNFETCHES += $(out)_unfetched
1304_DIRS += $(inst)
1305
1306endef
1307
1308# Walk the FETCH target lists.
1309bld_trg := $(BUILD_TARGET)
1310bld_trg_arch := $(BUILD_TARGET_ARCH)
1311$(foreach target, $(FETCHES) $(FETCHES.$(BUILD_TARGET)) $(FETCHES.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)), \
1312 $(eval $(value def_fetch)))
1313
1314# some aliases.
1315download: $(_DOWNLOADS)
[688]1316unpack: $(_UNPACKS)
1317fetch: $(_FETCHES)
1318unfetch: $(_UNFETCHES)
[640]1319
[988]1320ifdef KBUILD_PROFILE_SELF
1321 _KBUILD_TS_NOW := $(nanots )
1322 $(info prof: $(int-sub $(_KBUILD_TS_NOW), $(_KBUILD_TS_HEADER_START)) - $(int-sub $(_KBUILD_TS_NOW), $(_KBUILD_TS_PREV)) - done fetching targets)
1323 _KBUILD_TS_PREV := $(_KBUILD_TS_NOW)
1324endif
[640]1325
1326
[988]1327
[640]1328##
1329## Patching.
1330##
1331##
[688]1332#define def_patch_src
[640]1333#
1334#endef
1335#
1336#
1337## Deal with one patch target.
1338#define def_patch
1339#
1340#$(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]1341# $(eval $(value def_patch_src)))
[640]1342#
[719]1343#_PATCHES +=
[640]1344#endef
1345#
1346#$(foreach target, $(PATCHES) $(PATCHES.$(BUILD_TARGET)) $(PATCHES.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)), \
1347# $(eval $(value def_patch)))
1348#
1349
1350
1351#
[73]1352# Object processing.
1353#
[72]1354
[380]1355## wrapper the compile command dependency check.
1356ifndef NO_COMPILE_CMDS_DEPS
[741]1357 _DEP_COMPILE_CMDS = $(comp-cmds $(target)_$(source)_CMDS_PREV_,$(target)_$(source)_CMDS_,FORCE)
[380]1358else
[730]1359 _DEP_COMPILE_CMDS =
[380]1360endif
1361
[749]1362## Generates the rules for building a specific object, and the aliases
[380]1363# for building a source file.
[353]1364# @param $(obj) The object file.
[380]1365define def_target_source_rule
[1025]1366
[1012]1367ifdef TOOL_$(tool)_COMPILE_$(type)_USES_KOBJCACHE
[1030]1368$(outbase).koc +| $(obj) $($(target)_$(source)_OUTPUT_) $($(target)_$(source)_OUTPUT_MAYBE_) : \
[1007]1369 $($(target)_$(source)_DEPEND_) \
1370 $(_DEP_COMPILE_CMDS) \
1371 | \
1372 $($(target)_$(source)_DEPORD_)
1373 $$(call MSG_COMPILE,$(target),$(source),$$@,$(type))
1374else
[1030]1375$(obj) + $($(target)_$(source)_OUTPUT_) +| $($(target)_$(source)_OUTPUT_MAYBE_) : \
[380]1376 $($(target)_$(source)_DEPEND_) \
1377 $(_DEP_COMPILE_CMDS) \
1378 | \
1379 $($(target)_$(source)_DEPORD_)
[776]1380 $$(call MSG_COMPILE,$(target),$(source),$$@,$(type))
[1012]1381ifdef TOOL_$(tool)_COMPILE_$(type)_DONT_PURGE_OUTPUT
[1030]1382 $$(QUIET)$$(RM) -f $(dep) $(obj) $($(target)_$(source)_OUTPUT_) $($(target)_OUTPUT_MAYBE_)
[1007]1383endif
[1012]1384endif
[412]1385
[380]1386$($(target)_$(source)_CMDS_)
1387
1388ifndef NO_COMPILE_CMDS_DEPS
[696]1389 $$(QUIET2)$$(APPEND) "$(dep)"
1390 $$(QUIET2)$$(APPEND) "$(dep)" 'define $(target)_$(source)_CMDS_PREV_'
[770]1391ifeq ($(filter append-dash-n,$(KMK_FEATURES)),append-dash-n)
1392 $$(QUIET2)$$(APPEND) -v "$(dep)" '$(target)_$(source)_CMDS_'
1393else
[696]1394 $$(QUIET2)$$(APPEND) "$(dep)" '$(subst $(NL),'$(NL)$(TAB)@$(APPEND) "$(dep)" ',$($(target)_$(source)_CMDS_))'
[770]1395endif
[696]1396 $$(QUIET2)$$(APPEND) "$(dep)" 'endef'
[412]1397endif
[380]1398
[749]1399$(basename $(notdir $(obj))).o: $(obj)
1400$(basename $(notdir $(obj))).obj: $(obj)
[353]1401endef
[205]1402
[353]1403
[380]1404## wrapper the link command dependency check.
1405ifndef NO_COMPILE_CMDS_DEPS
[741]1406 _DEP_LINK_CMDS = $(comp-cmds $(target)_CMDS_PREV_,$(target)_CMDS_,FORCE)
[380]1407else
[730]1408 _DEP_LINK_CMDS =
[380]1409endif
1410
1411## Generate the link rule for a target.
1412# @param $(target) The normalized target name.
1413# @param $(dirdep) Directories we depend upon begin created before linking.
1414# @param $(dep) The name of the dependency file.
1415# @param $(out)
1416# @param $($(target)_OUTPUT_) Output files from the link.
[1030]1417# @param $($(target)_OUTPUT_MAYBE_) Output files that the link may perhaps create.
[380]1418# @param $($(target)_DEPEND_) Dependencies.
1419# @param $($(target)_DEPORD_) Dependencies which should only affect build order.
1420# @param $($(target)_CMDS_) The link commands.
1421# @param $($(target)_CMDS_PREV_) The link commands from the previous run.
1422define def_link_rule
[1030]1423$(out) + $($(target)_OUTPUT_) +| $($(target)_OUTPUT_MAYBE_) : \
[380]1424 $($(target)_DEPEND_) \
1425 $(_DEP_LINK_CMDS) \
1426 | \
1427 $($(target)_DEPORD_)
[776]1428 $$(call MSG_LINK,$(target),$$@,$(tool_do))
[1030]1429 $$(QUIET)$$(RM) -f $(dep) $(out) $($(target)_OUTPUT_) $($(target)_OUTPUT_MAYBE_)
[412]1430
[380]1431$($(target)_CMDS_)
1432
[524]1433ifndef NO_LINK_CMDS_DEPS
[696]1434 $$(QUIET2)$$(APPEND) "$(dep)" 'define $(target)_CMDS_PREV_'
[770]1435ifeq ($(filter append-dash-n,$(KMK_FEATURES)),append-dash-n)
1436 $$(QUIET2)$$(APPEND) -v "$(dep)" '$(target)_CMDS_'
1437else
[696]1438 $$(QUIET2)$$(APPEND) "$(dep)" '$(subst $(NL),'$(NL)$(TAB)@$(APPEND) "$(dep)" ',$($(target)_CMDS_))'
[770]1439endif
[696]1440 $$(QUIET2)$$(APPEND) "$(dep)" 'endef'
[412]1441endif
[380]1442
[749]1443$(basename $(notdir $(out))): $(out)
[719]1444
[380]1445endef
1446
1447
1448## Generate the link & lib install rule
1449# @param $(target) Normalized target name.
1450# @param $(out) The build target.
1451# @param $(INSTARGET_$(target)) The installation targets.
1452# @param $(mode) The file mode (optional)
1453define def_link_install_rule
1454$(INSTARGET_$(target)) : $(out) | $(call DIRDEP,$(dir $(INSTARGET_$(target))))
[776]1455 $$(call MSG_INST_TRG,$(target),$(out),$$@)
[696]1456 $$(QUIET)$$(INSTALL) $$(if $(mode),-m $(mode)) $(out) $$@
[719]1457
1458ifdef KBUILD_DO_AUTO_INSTALL
[749]1459$(basename $(notdir $(out))): $(INSTARGET_$(target))
[719]1460endif
[380]1461endef
1462
1463
[73]1464## Generic macro for processing C, C++ and Assembly sources.
1465# @param $(target) Normalized target name.
1466# @param $(source) Source file name.
1467# @param $(type) Source type. {C,CXX,AS}
[221]1468# @param bld_type Build type.
1469# @param bld_trg Build target.
1470# @param bld_trg_arch Build target arch.
1471# @param bld_trg_cpu Build target cpu.
[729]1472def_target_source_c_cpp_asm_rc_new = $(kb-src-one )
[741]1473ifdef KMK_VERSION
[723]1474 def_target_source_c_cpp_asm_rc_var = def_target_source_c_cpp_asm_rc_new
[530]1475else
[723]1476 def_target_source_c_cpp_asm_rc_var = def_target_source_c_cpp_asm_rc_old
[530]1477endif
1478
[73]1479## Generic macro for processing all target sources.
[74]1480# @param $(target) Normalized target name.
[725]1481# @param $(defpath)
1482# @param much-more...
[73]1483define def_target_sources
1484#$ (warning def_target_sources)
1485# C sources
[353]1486type := C
[481]1487$(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]1488 ,$(eval $(value $(def_target_source_c_cpp_asm_rc_var))) )
[73]1489
1490# C++ sources
[353]1491type := CXX
[481]1492$(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]1493 ,$(eval $(value $(def_target_source_c_cpp_asm_rc_var))) )
[73]1494
1495# ASM sources
[353]1496type := AS
[481]1497$(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]1498 ,$(eval $(value $(def_target_source_c_cpp_asm_rc_var))) )
[353]1499
[641]1500# Resource sources
1501type := RC
1502$(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)))\
1503 ,$(eval $(value $(def_target_source_c_cpp_asm_rc_var))) )
1504
[73]1505endef
1506
1507
[219]1508
[353]1509## Generic macro for generating the install rule(s) for a target
1510# and update the globals with default out.
[219]1511#
[353]1512# @param $(target) Normalized target name.
1513# @param $(out) The output file.
1514# @param $(definst) The default _INST value.
1515# @param $(typevar) The name of the variable with all the root targets of its type.
[729]1516# @remark Only library uses this now.
[353]1517define def_target_install_pluss
1518ifndef $(target)_NOINST
1519INSTARGET_$(target) := $(patsubst %/,%/$(notdir $(out)), \
1520 $(if $($(target)_INST), $(addprefix $(PATH_INS)/,$($(target)_INST)), $(definst)/))
[219]1521
[353]1522$(eval $(def_link_install_rule))
[239]1523
[827]1524_INSTALLS_FILES += $(INSTARGET_$(target))
[272]1525
[353]1526ifdef KBUILD_DO_AUTO_INSTALL
[579]1527$(typevar) += $(INSTARGET_$(target))
[219]1528else
[579]1529$(typevar) += $(out)
[219]1530endif
[353]1531else # _NOINST
[579]1532$(typevar) += $(out)
[353]1533endif
1534
[1030]1535_OUT_FILES += $($(target)_OUTPUT_) $($(target)_OUTPUT_MAYBE_) $(out)
[905]1536_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))
1537_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]1538_OBJS += $($(target)_OBJS_)
1539
[219]1540endef
1541
1542
1543
1544#
[72]1545# LIBRARIES
[73]1546#
[72]1547
1548## Library (one).
[74]1549# @param $(target) Normalized library (target) name.
[72]1550define def_lib
[145]1551# library basics
[222]1552## @todo prefix
[353]1553bld_type := $(firstword $($(target)_BLD_TYPE) $(BUILD_TYPE))
1554bld_trg := $(firstword $($(target)_BLD_TRG) $(BUILD_TARGET))
1555bld_trg_arch:= $(firstword $($(target)_BLD_TRG_ARCH) $(BUILD_TARGET_ARCH))
1556bld_trg_cpu := $(firstword $($(target)_BLD_TRG_CPU) $(BUILD_TARGET_CPU))
1557tool := $(call _TARGET_TOOL,$(target),AR)
[78]1558ifeq ($(tool),)
[353]1559$(error kBuild: Library target $(target) does not have a tool defined!)
[78]1560endif
[889]1561name := $(firstword\
1562 $($(target)_NAME.$(bld_trg).$(bld_trg_arch))\
1563 $($(target)_NAME.$(bld_trg_arch))\
1564 $($(target)_NAME.$(bld_trg))\
1565 $($(target)_NAME.$(bld_type))\
1566 $($(target)_NAME)\
1567 $(target))
1568outbase := $(call TARGET_BASE,$(name),$(target))
[743]1569ifndef PATH_$(target)
1570 PATH_$(target) := $(patsubst %/,%,$(dir $(outbase)))
1571else
1572 ifneq ($(PATH_$(target)),$(patsubst %/,%,$(dir $(outbase))))
1573 $(error kBuild internal error: PATH_$(target)=$(PATH_$(target)) expected $(patsubst %/,%,$(dir $(outbase))))
1574 endif
1575endif
[353]1576suff := $(firstword\
[481]1577 $($(target)_LIBSUFF.$(bld_trg).$(bld_trg_arch))\
[221]1578 $($(target)_LIBSUFF.$(bld_trg))\
[126]1579 $($(target)_LIBSUFF)\
[481]1580 $(TOOL_$(tool)_ARLIBSUFF.$(bld_trg).$(bld_trg_arch))\
[221]1581 $(TOOL_$(tool)_ARLIBSUFF.$(bld_trg))\
[126]1582 $(TOOL_$(tool)_ARLIBSUFF)\
[353]1583 $(SUFF_LIB))
1584out := $(outbase)$(suff)
1585TARGET_$(target) := $(out)
[719]1586$(target)_OBJS_ :=
[725]1587defpath := $($(target)_PATH)
[145]1588
1589# source -> object
[353]1590$(eval $(value def_target_sources))
[145]1591
1592# library linking
[353]1593tool := $(call _TARGET_TOOL,$(target),AR)
[889]1594name := $(firstword\
1595 $($(target)_NAME.$(bld_trg).$(bld_trg_arch))\
1596 $($(target)_NAME.$(bld_trg_arch))\
1597 $($(target)_NAME.$(bld_trg))\
1598 $($(target)_NAME.$(bld_type))\
1599 $($(target)_NAME)\
1600 $(target))
1601outbase := $(call TARGET_BASE,$(name),$(target))
[353]1602flags :=\
[74]1603 $(TOOL_$(tool)_ARFLAGS)\
[221]1604 $(TOOL_$(tool)_ARFLAGS.$(bld_type))\
[74]1605 $(ARFLAGS)\
[221]1606 $(ARFLAGS.$(bld_type))\
[74]1607 $($(target)_ARFLAGS)\
[481]1608 $($(target)_ARFLAGS.$(bld_type)) \
1609 $($(target)_ARFLAGS.$(bld_trg)) \
1610 $($(target)_ARFLAGS.$(bld_trg_arch)) \
1611 $($(target)_ARFLAGS.$(bld_trg).$(bld_trg_arch)) \
1612 $($(target)_ARFLAGS.$(bld_trg_cpu))
[1148]1613othersrc := $(filter-out %.c %.cpp %.cxx %.cc %.s %.S %.asm %.rc %.o %.obj %.res,\
[353]1614 $($(target)_SOURCES) \
1615 $($(target)_SOURCES.$(bld_trg)) \
1616 $($(target)_SOURCES.$(bld_trg_arch)) \
[481]1617 $($(target)_SOURCES.$(bld_trg).$(bld_trg_arch)) \
[353]1618 $($(target)_SOURCES.$(bld_trg_cpu)) \
1619 $($(target)_SOURCES.$(bld_type)))
[1148]1620objs = $(filter %.o %.obj %.res, \
[643]1621 $($(target)_SOURCES) \
1622 $($(target)_SOURCES.$(bld_trg)) \
1623 $($(target)_SOURCES.$(bld_trg_arch)) \
1624 $($(target)_SOURCES.$(bld_trg).$(bld_trg_arch)) \
1625 $($(target)_SOURCES.$(bld_trg_cpu)) \
1626 $($(target)_SOURCES.$(bld_type))) \
1627 $($(target)_OBJS_)
[353]1628dirdep := $(call DIRDEP,$(dir $(out)))
1629deps := $($(target)_DEPS)
[827]1630orderdeps := $($(target)_ORDERDEPS)
[72]1631
[725]1632# Adjust paths if we got a default path.
1633ifneq ($(defpath),)
[979]1634 objs := $(abspathex $(objs),$(defpath))
1635 deps := $(abspathex $(deps),$(defpath))
1636 orderdeps := $(abspathex $(orderdeps),$(defpath))
1637 othersrc := $(abspathex $(othersrc),$(defpath))
[725]1638endif
1639
[859]1640
1641# Custom pre-link actions.
1642ifdef $(target)_PRE_CMDS.$(bld_trg).$(bld_trg_arch).$(bld_type)
1643 pre_cmds := $($(target)_PRE_CMDS.$(bld_trg).$(bld_trg_arch).$(bld_type))
1644else ifdef $(target)_PRE_CMDS.$(bld_trg).$(bld_trg_arch)
1645 pre_cmds := $($(target)_PRE_CMDS.$(bld_trg).$(bld_trg_arch))
1646else ifdef $(target)_PRE_CMDS.$(bld_trg).$(bld_type)
1647 pre_cmds := $($(target)_PRE_CMDS.$(bld_trg).$(bld_type))
1648else ifdef $(target)_PRE_CMDS.$(bld_trg_arch)
1649 pre_cmds := $($(target)_PRE_CMDS.$(bld_trg_arch))
1650else ifdef $(target)_PRE_CMDS.$(bld_trg)
1651 pre_cmds := $($(target)_PRE_CMDS.$(bld_trg))
1652else ifdef $(target)_PRE_CMDS.$(bld_type)
1653 pre_cmds := $($(target)_PRE_CMDS.$(bld_type))
1654else ifdef $(target)_PRE_CMDS
1655 pre_cmds := $($(target)_PRE_CMDS)
1656else ifdef PRE_CMDS.$(bld_trg).$(bld_trg_arch).$(bld_type)
1657 pre_cmds := $(PRE_CMDS.$(bld_trg).$(bld_trg_arch).$(bld_type))
1658else ifdef PRE_CMDS.$(bld_trg).$(bld_trg_arch)
1659 pre_cmds := $(PRE_CMDS.$(bld_trg).$(bld_trg_arch))
1660else ifdef PRE_CMDS.$(bld_trg).$(bld_type)
1661 pre_cmds := $(PRE_CMDS.$(bld_trg).$(bld_type))
1662else ifdef PRE_CMDS.$(bld_trg_arch)
1663 pre_cmds := $(PRE_CMDS.$(bld_trg_arch))
1664else ifdef PRE_CMDS.$(bld_trg)
1665 pre_cmds := $(PRE_CMDS.$(bld_trg))
1666else ifdef PRE_CMDS.$(bld_type)
1667 pre_cmds := $(PRE_CMDS.$(bld_type))
1668else
1669 pre_cmds := $(PRE_CMDS)
1670endif
1671
1672# Custom post-link actions.
1673ifdef $(target)_POST_CMDS.$(bld_trg).$(bld_trg_arch).$(bld_type)
1674 post_cmds := $($(target)_POST_CMDS.$(bld_trg).$(bld_trg_arch).$(bld_type))
1675else ifdef $(target)_POST_CMDS.$(bld_trg).$(bld_trg_arch)
1676 post_cmds := $($(target)_POST_CMDS.$(bld_trg).$(bld_trg_arch))
1677else ifdef $(target)_POST_CMDS.$(bld_trg).$(bld_type)
1678 post_cmds := $($(target)_POST_CMDS.$(bld_trg).$(bld_type))
1679else ifdef $(target)_POST_CMDS.$(bld_trg_arch)
1680 post_cmds := $($(target)_POST_CMDS.$(bld_trg_arch))
1681else ifdef $(target)_POST_CMDS.$(bld_trg)
1682 post_cmds := $($(target)_POST_CMDS.$(bld_trg))
1683else ifdef $(target)_POST_CMDS.$(bld_type)
1684 post_cmds := $($(target)_POST_CMDS.$(bld_type))
1685else ifdef $(target)_POST_CMDS
1686 post_cmds := $($(target)_POST_CMDS)
1687else ifdef POST_CMDS.$(bld_trg).$(bld_trg_arch).$(bld_type)
1688 post_cmds := $(POST_CMDS.$(bld_trg).$(bld_trg_arch).$(bld_type))
1689else ifdef POST_CMDS.$(bld_trg).$(bld_trg_arch)
1690 post_cmds := $(POST_CMDS.$(bld_trg).$(bld_trg_arch))
1691else ifdef POST_CMDS.$(bld_trg).$(bld_type)
1692 post_cmds := $(POST_CMDS.$(bld_trg).$(bld_type))
1693else ifdef POST_CMDS.$(bld_trg_arch)
1694 post_cmds := $(POST_CMDS.$(bld_trg_arch))
1695else ifdef POST_CMDS.$(bld_trg)
1696 post_cmds := $(POST_CMDS.$(bld_trg))
1697else ifdef POST_CMDS.$(bld_type)
1698 post_cmds := $(POST_CMDS.$(bld_type))
1699else
1700 post_cmds := $(POST_CMDS)
1701endif
1702
[380]1703# dependency file
1704dep := $(out)$(SUFF_DEP)
[524]1705ifndef NO_LINK_CMDS_DEPS
[893]1706 _DEPFILES_INCLUDED += $(dep)
1707 $(eval includedep $(dep))
[380]1708endif
[72]1709
[380]1710# check that the tool is defined.
1711ifndef TOOL_$(tool)_LINK_LIBRARY_CMDS
1712$(warning kBuild: tools: \
[481]1713 1 $($(target)_$(source)TOOL.$(bld_trg).$(bld_trg_arch)) \
1714 2 $($(target)_$(source)TOOL.$(bld_trg)) \
1715 3 $($(target)_$(source)TOOL) \
1716 4 $($(target)_TOOL.$(bld_trg).$(bld_trg_arch)) \
1717 5 $($(target)_TOOL.$(bld_trg)) \
1718 6 $($(target)_TOOL) \
1719 7 $($(source)TOOL) \
1720 8 $($(source)TOOL.$(bld_trg).$(bld_trg_arch)) \
1721 9 $($(source)TOOL.$(bld_trg)) \
1722 10 $(TOOL.$(bld_trg).$(bld_trg_arch)) \
1723 11 $(TOOL.$(bld_trg)) \
1724 12 $(TOOL) )
[380]1725$(error kBuild: TOOL_$(tool)_LINK_LIBRARY_CMDS isn't defined! target=$(target) )
1726endif
1727
1728# call the tool
1729$(target)_CMDS_ := $(TOOL_$(tool)_LINK_LIBRARY_CMDS)
[859]1730ifneq ($(pre_cmds),)
1731 $(target)_CMDS_ := $(TAB)$(pre_cmds)$(NL)$(TAB)$($(target)_CMDS_)
1732endif
1733ifneq ($(post_cmds),)
1734 $(target)_CMDS_ := $($(target)_CMDS_)$(NL)$(TAB)$(post_cmds)
1735endif
[380]1736$(target)_OUTPUT_ := $(TOOL_$(tool)_LINK_LIBRARY_OUTPUT)
[1030]1737$(target)_OUTPUT_MAYBE_ := $(TOOL_$(tool)_LINK_LIBRARY_OUTPUT_MAYBE)
[380]1738$(target)_DEPEND_ := $(TOOL_$(tool)_LINK_LIBRARY_DEPEND) $(deps) $(objs)
[827]1739$(target)_DEPORD_ := $(TOOL_$(tool)_LINK_LIBRARY_DEPORD) $(dirdep) $(orderdeps)
[380]1740
[412]1741# generate the link rule.
[380]1742$(eval $(def_link_rule))
1743
[353]1744# installing and globals
1745$(eval $(value def_target_install_pluss))
[72]1746endef
1747
1748# Process libraries
[859]1749definst := $(PATH_LIB)
1750typevar := _LIBS
[776]1751tool_do := LINK_LIBRARY
[380]1752mode := 0644
[481]1753$(foreach target, $(LIBRARIES) $(LIBRARIES.$(BUILD_TARGET)) $(LIBRARIES.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)), $(eval $(value def_lib)))
[72]1754
[988]1755ifdef KBUILD_PROFILE_SELF
1756 _KBUILD_TS_NOW := $(nanots )
1757 $(info prof: $(int-sub $(_KBUILD_TS_NOW), $(_KBUILD_TS_HEADER_START)) - $(int-sub $(_KBUILD_TS_NOW), $(_KBUILD_TS_PREV)) - done library targets)
1758 _KBUILD_TS_PREV := $(_KBUILD_TS_NOW)
1759endif
[72]1760
[988]1761
[72]1762#
[353]1763# Link operations.
[72]1764#
1765
[353]1766##
1767# Link prolog
1768#
1769# @param $(target) Normalized target name.
1770# @param $(EXT) EXE,DLL,SYS.
1771# @param $(definst) The default _INST value.
1772# @param $(typevar) The name of the variable with all the root targets of its type.
[380]1773define def_link_common
[353]1774# basics
1775bld_type := $(firstword $($(target)_BLD_TYPE) $(BUILD_TYPE))
1776bld_trg := $(firstword $($(target)_BLD_TRG) $(BUILD_$(bld_trg_base_var)))
1777bld_trg_arch:= $(firstword $($(target)_BLD_TRG_ARCH) $(BUILD_$(bld_trg_base_var)_ARCH))
1778bld_trg_cpu := $(firstword $($(target)_BLD_TRG_CPU) $(BUILD_$(bld_trg_base_var)_CPU))
[145]1779
[353]1780tool := $(call _TARGET_TOOL,$(target),LD)
[889]1781name := $(firstword\
1782 $($(target)_NAME.$(bld_trg).$(bld_trg_arch))\
1783 $($(target)_NAME.$(bld_trg_arch))\
1784 $($(target)_NAME.$(bld_trg))\
1785 $($(target)_NAME.$(bld_type))\
1786 $($(target)_NAME)\
1787 $(target))
1788outbase := $(call TARGET_BASE,$(name),$(target))
[743]1789ifndef PATH_$(target)
1790 PATH_$(target) := $(patsubst %/,%,$(dir $(outbase)))
1791else
1792 ifneq ($(PATH_$(target)),$(patsubst %/,%,$(dir $(outbase))))
1793 $(error kBuild internal error: PATH_$(target)=$(PATH_$(target)) expected $(patsubst %/,%,$(dir $(outbase))))
1794 endif
1795endif
[353]1796suff := $(firstword \
1797 $($(target)_$(EXT)SUFF) \
1798 $($(target)_$(EXT)SUFF) \
1799 $(TOOL_$(tool)_LD$(EXT)SUFF) \
1800 $($(EXTPRE)SUFF_$(EXT)))
1801out := $(outbase)$(suff)
1802TARGET_$(target) := $(out)
[719]1803$(target)_OBJS_ :=
[725]1804defpath := $($(target)_PATH)
[353]1805
[145]1806# source -> object
[353]1807$(eval $(value def_target_sources))
[145]1808
[744]1809# more link stuff.
[353]1810tool := $(call _TARGET_TOOL,$(target),LD)
[889]1811name := $(firstword\
1812 $($(target)_NAME.$(bld_trg).$(bld_trg_arch))\
1813 $($(target)_NAME.$(bld_trg_arch))\
1814 $($(target)_NAME.$(bld_trg))\
1815 $($(target)_NAME.$(bld_type))\
1816 $($(target)_NAME)\
1817 $(target))
1818outbase := $(call TARGET_BASE,$(name),$(target))
[353]1819flags :=\
[74]1820 $(TOOL_$(tool)_LDFLAGS)\
[221]1821 $(TOOL_$(tool)_LDFLAGS.$(bld_type))\
1822 $(TOOL_$(tool)_LDFLAGS.$(bld_trg))\
1823 $(TOOL_$(tool)_LDFLAGS.$(bld_trg_arch))\
[481]1824 $(TOOL_$(tool)_LDFLAGS.$(bld_trg).$(bld_trg_arch))\
[221]1825 $(TOOL_$(tool)_LDFLAGS.$(bld_trg_cpu))\
[1242]1826 $(foreach sdk, $(SDKS) \
1827 $(SDKS.$(bld_type)) \
1828 $(SDKS.$(bld_trg)) \
1829 $(SDKS.$(bld_trg_arch)) \
1830 $(SDKS.$(bld_trg).$(bld_trg_arch)),\
1831 $(SDK_$(sdk)_LDFLAGS)\
1832 $(SDK_$(sdk)_LDFLAGS.$(bld_type))\
1833 $(SDK_$(sdk)_LDFLAGS.$(bld_trg))\
1834 $(SDK_$(sdk)_LDFLAGS.$(bld_trg_arch))\
1835 $(SDK_$(sdk)_LDFLAGS.$(bld_trg).$(bld_trg_arch))\
1836 $(SDK_$(sdk)_LDFLAGS.$(bld_trg_cpu)))\
[74]1837 $(LDFLAGS)\
[221]1838 $(LDFLAGS.$(bld_type))\
1839 $(LDFLAGS.$(bld_trg))\
1840 $(LDFLAGS.$(bld_trg_arch))\
[481]1841 $(LDFLAGS.$(bld_trg).$(bld_trg_arch))\
[221]1842 $(LDFLAGS.$(bld_trg_cpu))\
[1242]1843 $(foreach sdk, $($(target)_SDKS) \
1844 $($(target)_SDKS.$(bld_type)) \
1845 $($(target)_SDKS.$(bld_trg)) \
1846 $($(target)_SDKS.$(bld_trg_arch)) \
1847 $($(target)_SDKS.$(bld_trg).$(bld_trg_arch)),\
1848 $(SDK_$(sdk)_LDFLAGS)\
1849 $(SDK_$(sdk)_LDFLAGS.$(bld_type))\
1850 $(SDK_$(sdk)_LDFLAGS.$(bld_trg))\
1851 $(SDK_$(sdk)_LDFLAGS.$(bld_trg_arch))\
1852 $(SDK_$(sdk)_LDFLAGS.$(bld_trg).$(bld_trg_arch))\
1853 $(SDK_$(sdk)_LDFLAGS.$(bld_trg_cpu)))\
[74]1854 $($(target)_LDFLAGS)\
[221]1855 $($(target)_LDFLAGS.$(bld_type))\
1856 $($(target)_LDFLAGS.$(bld_trg))\
1857 $($(target)_LDFLAGS.$(bld_trg_arch))\
[481]1858 $($(target)_LDFLAGS.$(bld_trg).$(bld_trg_arch))\
[353]1859 $($(target)_LDFLAGS.$(bld_trg_cpu))
[1148]1860othersrc := $(filter-out %.c %.cpp %.cxx %.cc %.s %.S %.asm %.rc %.o %.obj %.res,\
[353]1861 $($(target)_SOURCES)\
1862 $($(target)_SOURCES.$(bld_trg)) \
1863 $($(target)_SOURCES.$(bld_trg_arch)) \
[481]1864 $($(target)_SOURCES.$(bld_trg).$(bld_trg_arch)) \
[353]1865 $($(target)_SOURCES.$(bld_trg_cpu)) \
1866 $($(target)_SOURCES.$(bld_type)))
[1148]1867objs = $(filter %.o %.obj %.res, \
[643]1868 $($(target)_SOURCES) \
1869 $($(target)_SOURCES.$(bld_trg)) \
1870 $($(target)_SOURCES.$(bld_trg_arch)) \
1871 $($(target)_SOURCES.$(bld_trg).$(bld_trg_arch)) \
1872 $($(target)_SOURCES.$(bld_trg_cpu)) \
1873 $($(target)_SOURCES.$(bld_type))) \
1874 $($(target)_OBJS_)
[353]1875libs :=\
[221]1876 $($(target)_LIBS.$(bld_trg_cpu))\
[481]1877 $($(target)_LIBS.$(bld_trg).$(bld_trg_arch))\
[221]1878 $($(target)_LIBS.$(bld_trg_arch))\
1879 $($(target)_LIBS.$(bld_trg))\
1880 $($(target)_LIBS.$(bld_type))\
[74]1881 $($(target)_LIBS)\
[592]1882 $(foreach sdk, $($(target)_SDKS.$(bld_trg).$(bld_trg_arch)) \
1883 $($(target)_SDKS.$(bld_trg_arch)) \
1884 $($(target)_SDKS.$(bld_trg)) \
1885 $($(target)_SDKS.$(bld_type)) \
1886 $($(target)_SDKS),\
[353]1887 $(SDK_$(sdk)_LIBS.$(bld_trg_cpu))\
[481]1888 $(SDK_$(sdk)_LIBS.$(bld_trg).$(bld_trg_arch))\
[353]1889 $(SDK_$(sdk)_LIBS.$(bld_trg_arch))\
1890 $(SDK_$(sdk)_LIBS.$(bld_trg))\
1891 $(SDK_$(sdk)_LIBS.$(bld_type))\
1892 $(SDK_$(sdk)_LIBS))\
[221]1893 $(LIBS.$(bld_trg_cpu))\
[481]1894 $(LIBS.$(bld_trg).$(bld_trg_arch))\
[221]1895 $(LIBS.$(bld_trg_arch))\
1896 $(LIBS.$(bld_trg))\
1897 $(LIBS.$(bld_type))\
[74]1898 $(LIBS)\
[592]1899 $(foreach sdk, $(SDKS.$(bld_trg).$(bld_trg_arch)) \
1900 $(SDKS.$(bld_trg_arch)) \
1901 $(SDKS.$(bld_trg)) \
1902 $(SDKS.$(bld_type)) \
1903 $(SDKS),\
[353]1904 $(SDK_$(sdk)_LIBS.$(bld_trg_cpu))\
[481]1905 $(SDK_$(sdk)_LIBS.$(bld_trg).$(bld_trg_arch))\
[353]1906 $(SDK_$(sdk)_LIBS.$(bld_trg_arch))\
1907 $(SDK_$(sdk)_LIBS.$(bld_trg))\
1908 $(SDK_$(sdk)_LIBS.$(bld_type))\
1909 $(SDK_$(sdk)_LIBS))\
[221]1910 $(TOOL_$(tool)_LIBS.$(bld_trg_cpu))\
[481]1911 $(TOOL_$(tool)_LIBS.$(bld_trg).$(bld_trg_arch))\
[221]1912 $(TOOL_$(tool)_LIBS.$(bld_trg_arch))\
1913 $(TOOL_$(tool)_LIBS.$(bld_trg))\
1914 $(TOOL_$(tool)_LIBS.$(bld_type))\
[353]1915 $(TOOL_$(tool)_LIBS)
1916libpath :=\
[221]1917 $($(target)_LIBPATH.$(bld_trg_cpu))\
[481]1918 $($(target)_LIBPATH.$(bld_trg).$(bld_trg_arch))\
[221]1919 $($(target)_LIBPATH.$(bld_trg_arch))\
1920 $($(target)_LIBPATH.$(bld_trg))\
1921 $($(target)_LIBPATH.$(bld_type))\
[74]1922 $($(target)_LIBPATH)\
[592]1923 $(foreach sdk, $($(target)_SDKS.$(bld_trg).$(bld_trg_arch)) \
1924 $($(target)_SDKS.$(bld_trg_arch)) \
1925 $($(target)_SDKS.$(bld_trg)) \
1926 $($(target)_SDKS.$(bld_type)) \
1927 $($(target)_SDKS),\
[353]1928 $(SDK_$(sdk)_LIBPATH.$(bld_trg_cpu))\
[481]1929 $(SDK_$(sdk)_LIBPATH.$(bld_trg).$(bld_trg_arch))\
[353]1930 $(SDK_$(sdk)_LIBPATH.$(bld_trg_arch))\
1931 $(SDK_$(sdk)_LIBPATH.$(bld_trg))\
1932 $(SDK_$(sdk)_LIBPATH.$(bld_type))\
1933 $(SDK_$(sdk)_LIBPATH))\
[221]1934 $(LIBPATH.$(bld_trg_cpu))\
[481]1935 $(LIBPATH.$(bld_trg).$(bld_trg_arch))\
[221]1936 $(LIBPATH.$(bld_trg_arch))\
1937 $(LIBPATH.$(bld_trg))\
1938 $(LIBPATH.$(bld_type))\
[74]1939 $(LIBPATH)\
[592]1940 $(foreach sdk, $(SDKS.$(bld_trg).$(bld_trg_arch)) \
1941 $(SDKS.$(bld_trg_arch)) \
1942 $(SDKS.$(bld_trg)) \
1943 $(SDKS.$(bld_type)) \
1944 $(SDKS),\
[353]1945 $(SDK_$(sdk)_LIBPATH.$(bld_trg_cpu))\
[481]1946 $(SDK_$(sdk)_LIBPATH.$(bld_trg).$(bld_trg_arch))\
[353]1947 $(SDK_$(sdk)_LIBPATH.$(bld_trg_arch))\
1948 $(SDK_$(sdk)_LIBPATH.$(bld_trg))\
1949 $(SDK_$(sdk)_LIBPATH.$(bld_type))\
1950 $(SDK_$(sdk)_LIBPATH))\
[221]1951 $(TOOL_$(tool)_LIBPATH.$(bld_trg_cpu))\
[481]1952 $(TOOL_$(tool)_LIBPATH.$(bld_trg).$(bld_trg_arch))\
[221]1953 $(TOOL_$(tool)_LIBPATH.$(bld_trg_arch))\
1954 $(TOOL_$(tool)_LIBPATH.$(bld_trg))\
1955 $(TOOL_$(tool)_LIBPATH.$(bld_type))\
[353]1956 $(TOOL_$(tool)_LIBPATH)
1957dirdep := $(call DIRDEP,$(dir $(out)))
1958deps := $($(target)_DEPS)
[827]1959orderdeps := $($(target)_ORDERDEPS)
[353]1960
[725]1961# Adjust paths if we got a default path.
1962ifneq ($(defpath),)
[979]1963 libpath := $(abspathex $(libpath),$(defpath))
1964 objs := $(abspathex $(objs),$(defpath))
1965 deps := $(abspathex $(deps),$(defpath))
1966 orderdeps := $(abspathex $(orderdeps),$(defpath))
1967 othersrc := $(abspathex $(othersrc),$(defpath))
[725]1968 # libs are not subject to this because of the the -l<lib> stuff. Use $(<target>_PATH)/lib if relative to current dir!
1969endif
1970
[859]1971# Custom pre-link actions.
1972ifdef $(target)_PRE_CMDS.$(bld_trg).$(bld_trg_arch).$(bld_type)
1973 pre_cmds := $($(target)_PRE_CMDS.$(bld_trg).$(bld_trg_arch).$(bld_type))
1974else ifdef $(target)_PRE_CMDS.$(bld_trg).$(bld_trg_arch)
1975 pre_cmds := $($(target)_PRE_CMDS.$(bld_trg).$(bld_trg_arch))
1976else ifdef $(target)_PRE_CMDS.$(bld_trg).$(bld_type)
1977 pre_cmds := $($(target)_PRE_CMDS.$(bld_trg).$(bld_type))
1978else ifdef $(target)_PRE_CMDS.$(bld_trg_arch)
1979 pre_cmds := $($(target)_PRE_CMDS.$(bld_trg_arch))
1980else ifdef $(target)_PRE_CMDS.$(bld_trg)
1981 pre_cmds := $($(target)_PRE_CMDS.$(bld_trg))
1982else ifdef $(target)_PRE_CMDS.$(bld_type)
1983 pre_cmds := $($(target)_PRE_CMDS.$(bld_type))
1984else ifdef $(target)_PRE_CMDS
1985 pre_cmds := $($(target)_PRE_CMDS)
1986else ifdef PRE_CMDS.$(bld_trg).$(bld_trg_arch).$(bld_type)
1987 pre_cmds := $(PRE_CMDS.$(bld_trg).$(bld_trg_arch).$(bld_type))
1988else ifdef PRE_CMDS.$(bld_trg).$(bld_trg_arch)
1989 pre_cmds := $(PRE_CMDS.$(bld_trg).$(bld_trg_arch))
1990else ifdef PRE_CMDS.$(bld_trg).$(bld_type)
1991 pre_cmds := $(PRE_CMDS.$(bld_trg).$(bld_type))
1992else ifdef PRE_CMDS.$(bld_trg_arch)
1993 pre_cmds := $(PRE_CMDS.$(bld_trg_arch))
1994else ifdef PRE_CMDS.$(bld_trg)
1995 pre_cmds := $(PRE_CMDS.$(bld_trg))
1996else ifdef PRE_CMDS.$(bld_type)
1997 pre_cmds := $(PRE_CMDS.$(bld_type))
1998else
1999 pre_cmds := $(PRE_CMDS)
2000endif
[72]2001
[859]2002# Custom post-link actions.
2003ifdef $(target)_POST_CMDS.$(bld_trg).$(bld_trg_arch).$(bld_type)
2004 post_cmds := $($(target)_POST_CMDS.$(bld_trg).$(bld_trg_arch).$(bld_type))
2005else ifdef $(target)_POST_CMDS.$(bld_trg).$(bld_trg_arch)
2006 post_cmds := $($(target)_POST_CMDS.$(bld_trg).$(bld_trg_arch))
2007else ifdef $(target)_POST_CMDS.$(bld_trg).$(bld_type)
2008 post_cmds := $($(target)_POST_CMDS.$(bld_trg).$(bld_type))
2009else ifdef $(target)_POST_CMDS.$(bld_trg_arch)
2010 post_cmds := $($(target)_POST_CMDS.$(bld_trg_arch))
2011else ifdef $(target)_POST_CMDS.$(bld_trg)
2012 post_cmds := $($(target)_POST_CMDS.$(bld_trg))
2013else ifdef $(target)_POST_CMDS.$(bld_type)
2014 post_cmds := $($(target)_POST_CMDS.$(bld_type))
2015else ifdef $(target)_POST_CMDS
2016 post_cmds := $($(target)_POST_CMDS)
2017else ifdef POST_CMDS.$(bld_trg).$(bld_trg_arch).$(bld_type)
2018 post_cmds := $(POST_CMDS.$(bld_trg).$(bld_trg_arch).$(bld_type))
2019else ifdef POST_CMDS.$(bld_trg).$(bld_trg_arch)
2020 post_cmds := $(POST_CMDS.$(bld_trg).$(bld_trg_arch))
2021else ifdef POST_CMDS.$(bld_trg).$(bld_type)
2022 post_cmds := $(POST_CMDS.$(bld_trg).$(bld_type))
2023else ifdef POST_CMDS.$(bld_trg_arch)
2024 post_cmds := $(POST_CMDS.$(bld_trg_arch))
2025else ifdef POST_CMDS.$(bld_trg)
2026 post_cmds := $(POST_CMDS.$(bld_trg))
2027else ifdef POST_CMDS.$(bld_type)
2028 post_cmds := $(POST_CMDS.$(bld_type))
2029else
2030 post_cmds := $(POST_CMDS)
2031endif
2032
[353]2033# installation targets
2034ifndef $(target)_NOINST
2035INSTARGET_$(target) := $(patsubst %/,%/$(notdir $(out)), \
2036 $(if $($(target)_INST), $(addprefix $(PATH_INS)/,$($(target)_INST)), $(definst)/))
2037ifdef KBUILD_DO_AUTO_INSTALL
2038$(typevar) += $(INSTARGET_$(target))
2039else
2040$(typevar) += $(out)
2041endif
2042# generate the install rule
2043$(eval $(def_link_install_rule))
2044
2045else # NOINST
2046INSTARGET_$(target) :=
2047$(typevar) += $(out)
2048endif # NOINST
2049
[380]2050# dependency file
2051dep := $(outbase)$(SUFF_DEP)
[524]2052ifndef NO_LINK_CMDS_DEPS
[893]2053 _DEPFILES_INCLUDED += $(dep)
2054 $(eval includedep $(dep))
[380]2055endif
[353]2056
[380]2057# check that the tool is defined.
2058ifndef TOOL_$(tool)_$(tool_do)_CMDS
2059$(warning kBuild: tools: \
[481]2060 1 $($(target)_$(source)TOOL.$(bld_trg).$(bld_trg_arch)) \
2061 2 $($(target)_$(source)TOOL.$(bld_trg)) \
2062 3 $($(target)_$(source)TOOL) \
2063 4 $($(target)_TOOL.$(bld_trg).$(bld_trg_arch)) \
2064 5 $($(target)_TOOL.$(bld_trg)) \
2065 6 $($(target)_TOOL) \
2066 7 $($(source)TOOL.$(bld_trg).$(bld_trg_arch)) \
2067 8 $($(source)TOOL.$(bld_trg)) \
2068 9 $($(source)TOOL) \
2069 10 $(TOOL.$(bld_trg).$(bld_trg_arch)) \
2070 11 $(TOOL.$(bld_trg)) \
2071 12 $(TOOL) )
[380]2072$(error kBuild: TOOL_$(tool)_$(tool_do)_CMDS isn't defined! target=$(target) )
2073endif
[353]2074
[380]2075# call the tool
2076$(target)_CMDS_ := $(TOOL_$(tool)_$(tool_do)_CMDS)
[859]2077ifneq ($(pre_cmds),)
2078 $(target)_CMDS_ := $(TAB)$(pre_cmds)$(NL)$(TAB)$($(target)_CMDS_)
2079endif
2080ifneq ($(post_cmds),)
2081 $(target)_CMDS_ := $($(target)_CMDS_)$(NL)$(TAB)$(post_cmds)
2082endif
[380]2083$(target)_OUTPUT_ := $(TOOL_$(tool)_$(tool_do)_OUTPUT)
[1030]2084$(target)_OUTPUT_MAYBE_ := $(TOOL_$(tool)_$(tool_do)_OUTPUT_MAYBE)
[380]2085$(target)_DEPEND_ := $(TOOL_$(tool)_$(tool_do)_DEPEND) $(deps) $(objs)
[827]2086$(target)_DEPORD_ := $(TOOL_$(tool)_$(tool_do)_DEPORD) $(dirdep) $(orderdeps)
[353]2087
[412]2088# generate the link rule.
[380]2089$(eval $(def_link_rule))
2090
[412]2091
[380]2092# Update globals.
[579]2093_OBJS += $($(target)_OBJS_)
2094_OUT_FILES += $($(target)_OUTPUT_) $(out)
[905]2095_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))
2096_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]2097_INSTALLS_FILES += $(INSTARGET_$(target))
[353]2098
2099endef
2100
2101
2102#
2103# BLDPROGS
2104#
2105
2106## Build program (one).
2107# @param $(target) Normalized target (program) name.
2108define def_bldprog
2109
2110# set NOINST if not forced installation.
2111ifndef $(target)_INST
2112$(target)_NOINST := 1
2113endif
2114
[380]2115# do the usual stuff.
2116$(eval $(value def_link_common))
[353]2117
2118endef
2119
2120# Process build programs.
2121EXT := EXE
2122EXTPRE := HOST
[380]2123tool_do := LINK_PROGRAM
[353]2124definst := $(PATH_BIN)
2125typevar := _BLDPROGS
[380]2126mode := 0755
[353]2127bld_trg_base_var := PLATFORM
[481]2128$(foreach target, $(BLDPROGS) $(BLDPROGS.$(BUILD_PLATFORM)) $(BLDPROGS.$(BUILD_PLATFORM).$(BUILD_PLATFORM_ARCH)), $(eval $(value def_bldprog)))
[353]2129
[988]2130ifdef KBUILD_PROFILE_SELF
2131 _KBUILD_TS_NOW := $(nanots )
2132 $(info prof: $(int-sub $(_KBUILD_TS_NOW), $(_KBUILD_TS_HEADER_START)) - $(int-sub $(_KBUILD_TS_NOW), $(_KBUILD_TS_PREV)) - done build program targets)
2133 _KBUILD_TS_PREV := $(_KBUILD_TS_NOW)
2134endif
[353]2135
2136
2137#
2138# DLLS
2139#
2140
[189]2141# Process dlls
[353]2142EXT := DLL
2143EXTPRE :=
[380]2144tool_do := LINK_DLL
[353]2145definst := $(PATH_DLL)
2146typevar := _DLLS
[830]2147mode := 0644
[353]2148bld_trg_base_var := TARGET
[481]2149$(foreach target, $(DLLS) $(DLLS.$(BUILD_TARGET)) $(DLLS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)), $(eval $(value def_link_common)))
[74]2150
[988]2151ifdef KBUILD_PROFILE_SELF
2152 _KBUILD_TS_NOW := $(nanots )
2153 $(info prof: $(int-sub $(_KBUILD_TS_NOW), $(_KBUILD_TS_HEADER_START)) - $(int-sub $(_KBUILD_TS_NOW), $(_KBUILD_TS_PREV)) - done dll targets)
2154 _KBUILD_TS_PREV := $(_KBUILD_TS_NOW)
2155endif
[74]2156
[988]2157
[72]2158#
[830]2159# IMPORT LIBRARIES
[72]2160#
[219]2161# - On OS/2 and windows these are libraries.
[189]2162# - On other platforms they are fake DLLs.
[830]2163#
2164EXTPRE :=
2165typevar := _IMPORT_LIBS
2166mode := 0644
2167bld_trg_base_var := TARGET
[481]2168ifeq ($(filter-out nt os2 win win64 win32,$(BUILD_TARGET)),)
[830]2169 EXT := LIB
2170 tool_do := LINK_LIBRARY
2171 definst := $(PATH_LIB)
2172 $(foreach target, $(IMPORT_LIBS) $(IMPORT_LIBS.$(BUILD_TARGET)) $(IMPORT_LIBS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)), $(eval $(value def_lib)))
[189]2173else
[830]2174 EXT := DLL
2175 tool_do := LINK_DLL
2176 definst := $(PATH_DLL)
2177 $(foreach target, $(IMPORT_LIBS) $(IMPORT_LIBS.$(BUILD_TARGET)) $(IMPORT_LIBS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)), $(eval $(value def_link_common)))
[189]2178endif
[72]2179
[988]2180ifdef KBUILD_PROFILE_SELF
2181 _KBUILD_TS_NOW := $(nanots )
2182 $(info prof: $(int-sub $(_KBUILD_TS_NOW), $(_KBUILD_TS_HEADER_START)) - $(int-sub $(_KBUILD_TS_NOW), $(_KBUILD_TS_PREV)) - done import library targets)
2183 _KBUILD_TS_PREV := $(_KBUILD_TS_NOW)
2184endif
[189]2185
[988]2186
[189]2187#
2188# PROGRAMS
2189#
2190
[353]2191# Process programs
2192EXT := EXE
2193EXTPRE :=
[380]2194tool_do := LINK_PROGRAM
[353]2195definst := $(PATH_BIN)
2196typevar := _PROGRAMS
[380]2197mode := 0755
[353]2198bld_trg_base_var := TARGET
[481]2199$(foreach target, $(PROGRAMS) $(PROGRAMS.$(BUILD_TARGET)) $(PROGRAMS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)), $(eval $(value def_link_common)))
[130]2200
[988]2201ifdef KBUILD_PROFILE_SELF
2202 _KBUILD_TS_NOW := $(nanots )
2203 $(info prof: $(int-sub $(_KBUILD_TS_NOW), $(_KBUILD_TS_HEADER_START)) - $(int-sub $(_KBUILD_TS_NOW), $(_KBUILD_TS_PREV)) - done program targets)
2204 _KBUILD_TS_PREV := $(_KBUILD_TS_NOW)
2205endif
[130]2206
[189]2207
[72]2208#
[83]2209# SYSMODS
[72]2210#
2211
[130]2212# Process sysmods
[353]2213EXT := SYS
2214EXTPRE :=
[380]2215tool_do := LINK_SYSMOD
[353]2216definst := $(PATH_SYS)
2217typevar := _SYSMODS
[380]2218mode := 0644
[353]2219bld_trg_base_var := TARGET
[481]2220$(foreach target, $(SYSMODS) $(SYSMODS.$(BUILD_TARGET)) $(SYSMODS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)), $(eval $(value def_link_common)))
[83]2221
[988]2222ifdef KBUILD_PROFILE_SELF
2223 _KBUILD_TS_NOW := $(nanots )
2224 $(info prof: $(int-sub $(_KBUILD_TS_NOW), $(_KBUILD_TS_HEADER_START)) - $(int-sub $(_KBUILD_TS_NOW), $(_KBUILD_TS_PREV)) - done sysmod targets)
2225 _KBUILD_TS_PREV := $(_KBUILD_TS_NOW)
2226endif
[83]2227
[988]2228
[72]2229#
2230# OTHERS
2231#
[481]2232_OTHERS = $(OTHERS) $(OTHERS.$(BUILD_TARGET)) $(OTHERS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH))
[72]2233
2234
[353]2235#
2236# INSTALLS
2237#
[72]2238
[353]2239## generate the install rule
2240define def_install_src_rule
2241# the install rule
2242$(insdst) : $(srcsrc) | $(call DIRDEP,$(dir $(insdst)))
[776]2243 $$(call MSG_INST_FILE,$(srcsrc),$(insdst))
[696]2244 $$(QUIET)$(inscmd)
[353]2245endef
2246
2247## install one file
2248define def_install_src
2249
2250# deal with '=>' in the source file name.
2251srcdst := $(subst =>, ,$(src))
2252srcsrc := $(firstword $(srcdst))
[424]2253srcdstdir := $(dir $(word 2,$(srcdst)))
[353]2254srcdst := $(word $(words $(srcdst)),$(srcdst))
2255
2256# _INSTFUN
2257ifdef $(srcsrc)_INSTFUN
[725]2258 instfun := $(srcsrc)_INSTFUN
[353]2259else
[725]2260 ifdef $(target)_INSTFUN
2261 instfun := $(target)_INSTFUN
2262 else
2263 instfun := _INSTALL_FILE
2264 endif
[353]2265endif
2266
2267# _INST
2268ifdef $(srcsrc)_INST
[725]2269 inst := $(patsubst %/,%,$($(srcsrc)_INST))/$(dir $(srcdstdir))
[353]2270else
[725]2271 ifdef $(target)_INST
2272 inst := $(patsubst %/,%,$($(target)_INST))/$(dir $(srcdstdir))
2273 else
2274 inst := $(dir $(srcdstdir))
2275 endif
[353]2276endif
2277
2278# calc target
[380]2279insdst := $(call $(instfun),$(srcdst),$(target),$(inst),$(PATH_INS))
[424]2280#$(warning instfun=$(instfun) srcdst=$(srcdst) target=$(target) inst=$(inst) => insdst=$(insdst))
[353]2281
[414]2282# mode, uid and gid
2283mode := $(firstword \
[481]2284 $($(target)_$(srcsrc)_MODE.$(bld_trg).$(bld_trg_arch)) \
[414]2285 $($(target)_$(srcsrc)_MODE.$(bld_trg)) \
2286 $($(target)_$(srcsrc)_MODE) \
[481]2287 $($(target)_$(srcdst)_MODE.$(bld_trg).$(bld_trg_arch)) \
[414]2288 $($(target)_$(srcdst)_MODE.$(bld_trg)) \
2289 $($(target)_$(srcdst)_MODE) \
[481]2290 $($(srcsrc)_MODE.$(bld_trg).$(bld_trg_arch)) \
[414]2291 $($(srcsrc)_MODE.$(bld_trg)) \
2292 $($(srcsrc)_MODE) \
[481]2293 $($(srcdst)_MODE.$(bld_trg).$(bld_trg_arch)) \
[414]2294 $($(srcdst)_MODE.$(bld_trg)) \
2295 $($(srcdst)_MODE) \
[481]2296 $($(target)_MODE.$(bld_trg).$(bld_trg_arch)) \
[414]2297 $($(target)_MODE.$(bld_trg)) \
2298 $($(target)_MODE))
2299uid := $(firstword \
[481]2300 $($(target)_$(srcsrc)_UID.$(bld_trg).$(bld_trg_arch)) \
[414]2301 $($(target)_$(srcsrc)_UID.$(bld_trg)) \
2302 $($(target)_$(srcsrc)_UID) \
[481]2303 $($(target)_$(srcdst)_UID.$(bld_trg).$(bld_trg_arch)) \
[414]2304 $($(target)_$(srcdst)_UID.$(bld_trg)) \
2305 $($(target)_$(srcdst)_UID) \
[481]2306 $($(srcsrc)_UID.$(bld_trg).$(bld_trg_arch)) \
[414]2307 $($(srcsrc)_UID.$(bld_trg)) \
2308 $($(srcsrc)_UID) \
[481]2309 $($(srcdst)_UID.$(bld_trg).$(bld_trg_arch)) \
[414]2310 $($(srcdst)_UID.$(bld_trg)) \
2311 $($(srcdst)_UID) \
[481]2312 $($(target)_UID.$(bld_trg).$(bld_trg_arch)) \
[414]2313 $($(target)_UID.$(bld_trg)) \
2314 $($(target)_UID))
2315gid := $(firstword \
[481]2316 $($(target)_$(srcsrc)_GID.$(bld_trg).$(bld_trg_arch)) \
[414]2317 $($(target)_$(srcsrc)_GID.$(bld_trg)) \
2318 $($(target)_$(srcsrc)_GID) \
[481]2319 $($(target)_$(srcdst)_GID.$(bld_trg).$(bld_trg_arch)) \
[414]2320 $($(target)_$(srcdst)_GID.$(bld_trg)) \
2321 $($(target)_$(srcdst)_GID) \
[481]2322 $($(srcsrc)_GID.$(bld_trg).$(bld_trg_arch)) \
[414]2323 $($(srcsrc)_GID.$(bld_trg)) \
2324 $($(srcsrc)_GID) \
[481]2325 $($(srcdst)_GID.$(bld_trg).$(bld_trg_arch)) \
[414]2326 $($(srcdst)_GID.$(bld_trg)) \
2327 $($(srcdst)_GID) \
[481]2328 $($(target)_GID.$(bld_trg).$(bld_trg_arch)) \
[414]2329 $($(target)_GID.$(bld_trg)) \
2330 $($(target)_GID))
[830]2331flags := \
2332 $($(target)_IFFLAGS) \
2333 $($(target)_IFFLAGS.$(bld_trg)) \
2334 $($(target)_IFFLAGS.$(bld_trg).$(bld_trg_arch)) \
2335 $($(srcdst)_IFFLAGS) \
2336 $($(srcdst)_IFFLAGS.$(bld_trg)) \
2337 $($(srcdst)_IFFLAGS.$(bld_trg).$(bld_trg_arch)) \
2338 $($(srcsrc)_IFFLAGS) \
2339 $($(srcsrc)_IFFLAGS.$(bld_trg)) \
2340 $($(srcsrc)_IFFLAGS.$(bld_trg).$(bld_trg_arch)) \
2341 $($(target)_$(srcdst)_IFFLAGS) \
2342 $($(target)_$(srcdst)_IFFLAGS.$(bld_trg)) \
2343 $($(target)_$(srcdst)_IFFLAGS.$(bld_trg).$(bld_trg_arch)) \
2344 $($(target)_$(srcsrc)_IFFLAGS) \
2345 $($(target)_$(srcsrc)_IFFLAGS.$(bld_trg)) \
2346 $($(target)_$(srcsrc)_IFFLAGS.$(bld_trg).$(bld_trg_arch))
[414]2347
[725]2348
2349# Adjust the source if we got a default PATH. (This must be done this late!)
2350ifdef $(target)_PATH
[979]2351 srcsrc := $(abspathex $(srcsrc),$($(target)_PATH))
[725]2352endif
2353
[353]2354# create the command
2355ifdef $(srcsrc)_INSTALLER
[830]2356 inscmd := $(call $(srcsrc)_INSTALLER,$(srcsrc),$(insdst),$(target),$(flags))
2357else ifdef $(target)_INSTALLER
2358 inscmd := $(call $(target)_INSTALLER,$(srcsrc),$(insdst),$(target),$(flags))
[353]2359else
[830]2360 inscmd := $$(INSTALL)\
[414]2361 $(if $(uid),-o $(uid))\
2362 $(if $(gid),-g $(gid))\
2363 $(if $(mode),-m $(mode))\
[830]2364 $(flags)\
[414]2365 $(srcsrc) $(insdst)
[353]2366endif
2367
2368# generate the rule (need double evaluation here)
2369$(eval $(def_install_src_rule))
2370
2371INSTARGET_$(target) += $(insdst)
2372endef
2373
2374
2375## generate the symlink rule
2376define def_install_symlink_rule
2377# the install rule
2378$(insdst) : | $(call DIRDEP,$(dir $(insdst)))
[776]2379 $$(call MSG_INST_SYM,$(insdst),$(symdst))
[696]2380 $$(QUIET)$$(RM) -f $$@
2381 $$(QUIET)$$(LN_SYMLINK) $(symdst) $(insdst)
[353]2382endef
2383
2384## create one symlink
2385define def_install_symlink
2386
2387# deal with '=>' in the source file name.
[380]2388symdst := $(subst =>, ,$(src))
2389symlnk := $(firstword $(symdst))
2390symdst := $(word $(words $(symdst)),$(symdst))
[353]2391
2392# _INSTFUN
[380]2393ifdef $(symlnk)_INSTFUN
[827]2394 instfun := $(symlnk)_INSTFUN
2395else ifdef $(target)_INSTFUN
[830]2396 instfun := $(target)_INSTFUN
[353]2397else
[827]2398 instfun := _INSTALL_FILE
[353]2399endif
2400
2401# _INST
[380]2402ifdef $(symlnk)_INST
[725]2403 inst := $(patsubst %/,%,$($(symlnk)_INST))/$(dir $(symlnk))
[827]2404else ifdef $(target)_INST
2405 inst := $(patsubst %/,%,$($(target)_INST))/$(dir $(symlnk))
[353]2406else
[827]2407 inst := $(dir $(symlnk))
[353]2408endif
2409
2410# calc target
[380]2411insdst := $(call $(instfun),$(symlnk),$(target),$(inst),$(PATH_INS))
2412#$(warning symlnk=$(symlnk) symdst=$(symdst) insdst=$(insdst) instfun=$(instfun) inst='$(inst)')
[353]2413
2414# generate the rule (need double evaluation here)
2415$(eval $(def_install_symlink_rule))
2416
2417INSTARGET_$(target) += $(insdst)
2418endef
2419
[412]2420
[380]2421## generate the install rule
2422define def_install_directory_rule
2423# the install rule
2424$(insdst):
[776]2425 $$(call MSG_INST_DIR,$(insdst))
[696]2426 $$(QUIET)$$(INSTALL) -d \
[380]2427 $(if $(uid),-o $(uid))\
2428 $(if $(gid),-g $(gid))\
2429 $(if $(mode),-m $(mode))\
[830]2430 $(flags)\
[380]2431 $(insdst)
[412]2432
2433.NOTPARALLEL: $(insdst)
[380]2434endef
2435
[412]2436
[380]2437## create one directory
2438define def_install_directory
2439
2440# _INST
2441ifdef $(directory)_INST
[725]2442 inst := $(PATH_INS)/$(patsubst %/,%,$($(directory)_INST))
[827]2443else ifdef $(target)_INST
2444 inst := $(PATH_INS)/$(patsubst %/,%,$($(target)_INST))
[380]2445else
[827]2446 inst := $(PATH_INS)
[380]2447endif
2448
2449mode := $(firstword \
[481]2450 $($(target)_$(directory)_MODE.$(bld_trg).$(bld_trg_arch)) \
[380]2451 $($(target)_$(directory)_MODE.$(bld_trg)) \
2452 $($(target)_$(directory)_MODE) \
[481]2453 $($(directory)_MODE.$(bld_trg).$(bld_trg_arch)) \
[380]2454 $($(directory)_MODE.$(bld_trg)) \
2455 $($(directory)_MODE) \
[481]2456 $($(target)_MODE.$(bld_trg).$(bld_trg_arch)) \
[380]2457 $($(target)_MODE.$(bld_trg)) \
2458 $($(target)_MODE))
2459uid := $(firstword \
[481]2460 $($(target)_$(directory)_UID.$(bld_trg).$(bld_trg_arch)) \
[380]2461 $($(target)_$(directory)_UID.$(bld_trg)) \
2462 $($(target)_$(directory)_UID) \
[481]2463 $($(directory)_UID.$(bld_trg).$(bld_trg_arch)) \
[380]2464 $($(directory)_UID.$(bld_trg)) \
2465 $($(directory)_UID) \
[481]2466 $($(target)_UID.$(bld_trg).$(bld_trg_arch)) \
[380]2467 $($(target)_UID.$(bld_trg)) \
2468 $($(target)_UID))
2469gid := $(firstword \
[481]2470 $($(target)_$(directory)_GID.$(bld_trg).$(bld_trg_arch)) \
[380]2471 $($(target)_$(directory)_GID.$(bld_trg)) \
2472 $($(target)_$(directory)_GID) \
[481]2473 $($(directory)_GID.$(bld_trg).$(bld_trg_arch)) \
[380]2474 $($(directory)_GID.$(bld_trg)) \
2475 $($(directory)_GID) \
[481]2476 $($(target)_GID.$(bld_trg).$(bld_trg_arch)) \
[380]2477 $($(target)_GID.$(bld_trg)) \
2478 $($(target)_GID))
[830]2479flags := \
2480 $($(target)_IDFLAGS)\
2481 $($(target)_IDFLAGS.$(bld_trg)) \
2482 $($(target)_IDFLAGS.$(bld_trg).$(bld_trg_arch)) \
2483 $($(directory)_IDFLAGS) \
2484 $($(directory)_IDFLAGS.$(bld_trg)) \
2485 $($(directory)_IDFLAGS.$(bld_trg).$(bld_trg_arch)) \
2486 $($(target)_$(directory)_IDFLAGS) \
2487 $($(target)_$(directory)_IDFLAGS.$(bld_trg)) \
2488 $($(target)_$(directory)_IDFLAGS.$(bld_trg).$(bld_trg_arch))
[380]2489
2490insdst := $(inst)/$(directory)/
2491#$(warning directory=$(directory) inst=$(inst) insdst=$(insdst) mode=$(mode) gid=$(gid) uid=$(uid))
2492
2493# generate the rule (need double evaluation here)
2494$(eval $(def_install_directory_rule))
2495
2496INSTARGET_DIRS_$(target) += $(insdst)
2497endef
2498
2499
[353]2500## process one install target.
2501define def_install
[744]2502# the basics.
[353]2503bld_type := $(firstword $($(target)_BLD_TYPE) $(BUILD_TYPE))
2504bld_trg := $(firstword $($(target)_BLD_TRG) $(BUILD_TARGET))
2505bld_trg_arch:= $(firstword $($(target)_BLD_TRG_ARCH) $(BUILD_TARGET_ARCH))
2506bld_trg_cpu := $(firstword $($(target)_BLD_TRG_CPU) $(BUILD_TARGET_CPU))
2507
[827]2508INSTARGET_$(target) := $($(target)_GOALS)
[380]2509INSTARGET_DIRS_$(target) :=
2510
[481]2511$(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]2512 $(eval $(value def_install_directory)))
2513
[481]2514$(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]2515 $(eval $(value def_install_src)))
2516
[481]2517$(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]2518 $(eval $(value def_install_symlink)))
2519
[827]2520# the collection target
2521TARGET_$(target) := $(PATH_TARGET)/$(target).ins
[838]2522$(TARGET_$(target)): $(INSTARGET_$(target)) | $(INSTARGET_DIRS_$(target)) $(call DIRDEP,$(PATH_TARGET))
[827]2523 @$(QUIET2)$(APPEND) $@
2524
2525$(target): $(TARGET_$(target))
2526
2527_INSTALLS += $(TARGET_$(target))
2528_INSTALLS_FILES += $(INSTARGET_$(target))
[380]2529_INSTALLS_DIRS += $(INSTARGET_DIRS_$(target))
[905]2530_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))
2531_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]2532endef
2533
2534## process all install targets
[481]2535$(foreach target, $(INSTALLS) $(INSTALLS.$(BUILD_TARGET)) $(INSTALLS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)), \
[353]2536 $(eval $(value def_install)))
2537
[988]2538ifdef KBUILD_PROFILE_SELF
2539 _KBUILD_TS_NOW := $(nanots )
2540 $(info prof: $(int-sub $(_KBUILD_TS_NOW), $(_KBUILD_TS_HEADER_START)) - $(int-sub $(_KBUILD_TS_NOW), $(_KBUILD_TS_PREV)) - done install targets)
2541 _KBUILD_TS_PREV := $(_KBUILD_TS_NOW)
2542endif
[353]2543
[988]2544
[72]2545#
[417]2546# PACKING
2547#
[481]2548_PACKING += $(PACKING) $(PACKING.$(BUILD_TARGET)) $(PACKING.$(BUILD_TARGET).$(BUILD_TARGET_ARCH))
[417]2549
2550
2551#
[72]2552# DOCS
2553#
2554
2555
2556#
[353]2557# DIRECTORIES
2558#
[827]2559_DIR_ALL := $(sort $(addsuffix /,$(patsubst %/,%,$(_DIRS))) $(dir $(_OUT_FILES) $(_OBJS) $(_INSTALLS_FILES)))
[380]2560$(foreach directory,$(_INSTALLS_DIRS), $(eval _DIR_ALL := $(filter-out $(directory),$(_DIR_ALL))))
[353]2561
[380]2562
[353]2563define def_mkdir_rule
2564$(directory):
[776]2565 $$(call MSG_MKDIR,$$@)
[696]2566 $$(QUIET)$$(MKDIR) -p $$@
[72]2567endef
2568
[353]2569$(foreach directory,$(_DIR_ALL),$(eval $(def_mkdir_rule)))
[72]2570
[988]2571ifdef KBUILD_PROFILE_SELF
2572 _KBUILD_TS_NOW := $(nanots )
2573 $(info prof: $(int-sub $(_KBUILD_TS_NOW), $(_KBUILD_TS_HEADER_START)) - $(int-sub $(_KBUILD_TS_NOW), $(_KBUILD_TS_PREV)) - done directories)
2574 _KBUILD_TS_PREV := $(_KBUILD_TS_NOW)
2575endif
[183]2576
[988]2577
[72]2578#
[353]2579# NOTHING
[72]2580#
[353]2581do-nothing:
[988]2582ifdef KBUILD_PROFILE_SELF
2583 @$(ECHO) 'prof: $(int-sub $(nanots ), $(_KBUILD_TS_HEADER_START)) - $(int-sub $(nanots ), $(_KBUILD_TS_PREV)) - executing $@'
2584endif
[776]2585 $(call MSG_NOTHING)
[72]2586
[183]2587
[75]2588#
[353]2589# CLEAN UP
[75]2590#
[353]2591do-clean:
[776]2592 $(call MSG_CLEAN)
[701]2593 $(QUIET)$(RM) -f $(_OUT_FILES) $(_OBJS) $(_DEPFILES) $(_DEPFILES_INCLUDED) $(_CLEAN_FILES) $(OTHER_CLEAN)
[966]2594 $(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]2595
[98]2596
[897]2597
[353]2598#
2599# PASSES (including directory and makefile walking)
2600#
[221]2601
[75]2602## Subdir
2603# @param $(pass) Lowercase pass name.
2604# @param $(PASS) Uppercase pass name.
2605# @param $(subdir) Subdirectory
2606# @param $(tag) tag to attach to the rule name.
2607define def_pass_subdir
[219]2608pass_$(pass)$(tag):: $(dep)
[696]2609 + $$(QUIET)$$(MAKE) -C $(subdir) -f $$(notdir $$(firstword $$(wildcard $$(addprefix $(subdir)/,$$(DEFAULT_MAKEFILE))))) pass_$(pass)
[75]2610endef
[72]2611
[75]2612## Submakefile
2613# @param $(pass) Lowercase pass name.
2614# @param $(PASS) Uppercase pass name.
2615# @param $(makefile) Makefile.
2616# @param $(tag) tag to attach to the rule name.
2617define def_pass_makefile
[219]2618pass_$(pass)$(tag):: $(dep)
[696]2619 + $$(QUIET)$$(MAKE) -C $(patsubst %/,%,$(dir $(makefile))) -f $(notdir $(makefile)) pass_$(pass)
[75]2620endef
[73]2621
[75]2622## Execute a pass.
2623# @param $(pass) Lowercase pass name.
2624# @param $(PASS) Uppercase pass name.
[353]2625define def_pass_old
[481]2626$(eval SUBDIRS_$(PASS) ?= $(SUBDIRS) $(SUBDIRS.$(BUILD_TARGET)) $(SUBDIRS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) )
2627$(eval SUBDIRS_AFTER_$(PASS) ?= $(SUBDIRS_AFTER) $(SUBDIRS_AFTER.$(BUILD_TARGET)) $(SUBDIRS_AFTER.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) )
2628$(eval MAKEFILES_BEFORE_$(PASS) ?= $(MAKEFILES_BEFORE) $(MAKEFILES_BEFORE.$(BUILD_TARGET)) $(MAKEFILES_BEFORE.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) )
2629$(eval MAKEFILES_AFTER_$(PASS) ?= $(MAKEFILES_AFTER) $(MAKEFILES_AFTER.$(BUILD_TARGET)) $(MAKEFILES_AFTER.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) )
[75]2630
2631$(eval tag:=_before)
[219]2632$(eval dep:=)
[481]2633$(foreach subdir,$(SUBDIRS_$(PASS)) $(SUBDIRS_$(PASS).$(BUILD_TARGET)) $(SUBDIRS_$(PASS).$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) ,$(eval $(def_pass_subdir)))
2634$(foreach makefile,$(MAKEFILES_BEFORE_$(PASS)) $(MAKEFILES_BEFORE_$(PASS).$(BUILD_TARGET)) $(MAKEFILES_BEFORE_$(PASS).$(BUILD_TARGET).$(BUILD_TARGET_ARCH)),$(eval $(def_pass_makefile)))
[75]2635
2636$(eval tag:=_after)
[219]2637$(eval dep:=pass_$(pass)_doit)
[481]2638$(foreach subdir,$(SUBDIRS_AFTER_$(PASS)) $(SUBDIRS_AFTER_$(PASS).$(BUILD_TARGET)) $(SUBDIRS_AFTER_$(PASS).$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) ,$(eval $(def_pass_subdir)))
2639$(foreach makefile,$(MAKEFILES_AFTER_$(PASS)) $(MAKEFILES_AFTER_$(PASS).$(BUILD_TARGET)) $(MAKEFILES_AFTER_$(PASS).$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) ,$(eval $(def_pass_makefile)))
[75]2640
2641.NOTPARALLEL: pass_$(pass)_before pass_$(pass)_after
2642.PHONY: pass_$(pass) pass_$(pass)_before pass_$(pass)_doit pass_$(pass)_after
[353]2643pass_$(pass)_doit: $(PASS_$(PASS)_trgs) $(foreach var,$(PASS_$(PASS)_vars),$(var))
[272]2644pass_$(pass)_this: pass_$(pass)_before
[696]2645 + $$(QUIET)$$(MAKE) -f $$(MAKEFILE) pass_$(pass)_doit
[220]2646pass_$(pass)_after:: pass_$(pass)_this
[219]2647pass_$(pass): pass_$(pass)_after
[75]2648
[183]2649endef
2650
[353]2651define def_pass
[481]2652$(eval SUBDIRS_$(PASS) ?= $(SUBDIRS) $(SUBDIRS.$(BUILD_TARGET)) $(SUBDIRS.$(BUILD_TARGET.$(BUILD_TARGET_ARCH))) )
2653$(eval SUBDIRS_AFTER_$(PASS) ?= $(SUBDIRS_AFTER) $(SUBDIRS_AFTER.$(BUILD_TARGET)) $(SUBDIRS_AFTER.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) )
2654$(eval MAKEFILES_BEFORE_$(PASS) ?= $(MAKEFILES_BEFORE) $(MAKEFILES_BEFORE.$(BUILD_TARGET)) $(MAKEFILES_BEFORE.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) )
2655$(eval MAKEFILES_AFTER_$(PASS) ?= $(MAKEFILES_AFTER) $(MAKEFILES_AFTER.$(BUILD_TARGET)) $(MAKEFILES_AFTER.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) )
[183]2656
[353]2657$(eval tag:=_before)
2658$(eval dep:=)
[481]2659$(foreach subdir,$(SUBDIRS_$(PASS)) $(SUBDIRS_$(PASS).$(BUILD_TARGET)) $(SUBDIRS_$(PASS).$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) ,$(eval $(def_pass_subdir)))
2660$(foreach makefile,$(MAKEFILES_BEFORE_$(PASS)) $(MAKEFILES_BEFORE_$(PASS).$(BUILD_TARGET)) $(MAKEFILES_BEFORE_$(PASS).$(BUILD_TARGET).$(BUILD_TARGET_ARCH)),$(eval $(def_pass_makefile)))
[75]2661
[353]2662$(eval tag:=_after)
2663$(eval dep:=pass_$(pass)_doit)
[481]2664$(foreach subdir,$(SUBDIRS_AFTER_$(PASS)) $(SUBDIRS_AFTER_$(PASS).$(BUILD_TARGET)) $(SUBDIRS_AFTER_$(PASS).$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) ,$(eval $(def_pass_subdir)))
2665$(foreach makefile,$(MAKEFILES_AFTER_$(PASS)) $(MAKEFILES_AFTER_$(PASS).$(BUILD_TARGET)) $(MAKEFILES_AFTER_$(PASS).$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) ,$(eval $(def_pass_makefile)))
[75]2666
[380]2667ifdef KBUILD_SAFE_PARALLEL
[353]2668.NOTPARALLEL: pass_$(pass) pass_$(pass)_before pass_$(pass)_after pass_$(pass)_this
2669.PHONY: pass_$(pass) pass_$(pass)_before pass_$(pass)_after pass_$(pass)_this pass_$(pass)_doit
2670pass_$(pass)_doit: $(PASS_$(PASS)_trgs) $(foreach var,$(PASS_$(PASS)_vars),$(var))
2671pass_$(pass)_this: pass_$(pass)_before
[696]2672 + $$(QUIET)$$(MAKE) -f $$(MAKEFILE) pass_$(pass)_doit
[353]2673pass_$(pass)_after:: pass_$(pass)_this
2674pass_$(pass): pass_$(pass)_after
2675else
[388]2676.NOTPARALLEL: pass_$(pass) pass_$(pass)_before pass_$(pass)_after pass_$(pass)_doit
[353]2677.PHONY: pass_$(pass) pass_$(pass)_before pass_$(pass)_after pass_$(pass)_doit
2678pass_$(pass)_doit: pass_$(pass)_before \
2679 $(PASS_$(PASS)_trgs) $(foreach var,$(PASS_$(PASS)_vars),$($(var)))
2680pass_$(pass): \
2681 pass_$(pass)_before \
2682 pass_$(pass)_doit \
[388]2683 pass_$(pass)_after
[353]2684endif
[189]2685
[353]2686#$ (warning pass=$(pass) PASS=$(PASS): $(PASS_$(PASS)_trgs) $(PASS_$(PASS)_trgs) $(foreach var,$(PASS_$(PASS)_vars),$($(var))))
2687endef
[75]2688
[353]2689# Generate the defined passes.
2690$(foreach PASS, $(PASSES), \
2691 $(eval pass := $(PASS_$(PASS)_pass)) \
2692 $(eval $(def_pass)))
[75]2693
[219]2694## Pass order
2695# @param $(pass) Current pass name.
2696# @param $(prev_pass) The previous pass name.
2697define def_pass_order
[380]2698ifdef KBUILD_SAFE_PARALLEL
[353]2699.NOTPARALLEL: pass_$(pass)_order
2700.PHONY: pass_$(pass)_order
[219]2701pass_$(pass)_order: $(pass_prev)
[776]2702 $$(call MSG_PASS,$$(if $$(PASS_$(PASS)),$$(PASS_$(PASS)),$(pass)))
[696]2703 + $$(QUIET)$$(MAKE) -f $$(MAKEFILE) pass_$(pass)
[353]2704else
2705.NOTPARALLEL: pass_$(pass)_order pass_$(pass)_banner
[388]2706.PHONY: pass_$(pass)_order pass_$(pass)_banner
[353]2707pass_$(pass)_banner:
[776]2708 $$(call MSG_PASS,$$(if $$(PASS_$(PASS)),$$(PASS_$(PASS)),$(pass)))
[353]2709pass_$(pass)_order: \
2710 $(pass_prev) \
2711 pass_$(pass)_banner \
2712 pass_$(pass)
2713endif
[219]2714$(eval pass_prev := pass_$(pass)_order)
2715endef
[183]2716
[219]2717## PASS: order
2718# Use dependencies to ensure correct pass order.
2719pass_prev :=
[353]2720$(foreach PASS,$(DEFAULT_PASSES),\
2721 $(eval pass := $(PASS_$(PASS)_pass)) \
2722 $(eval $(def_pass_order)))
[219]2723
[988]2724ifdef KBUILD_PROFILE_SELF
2725 _KBUILD_TS_NOW := $(nanots )
2726 $(info prof: $(int-sub $(_KBUILD_TS_NOW), $(_KBUILD_TS_HEADER_START)) - $(int-sub $(_KBUILD_TS_NOW), $(_KBUILD_TS_PREV)) - done passes)
2727 _KBUILD_TS_PREV := $(_KBUILD_TS_NOW)
2728endif
[272]2729
[897]2730
[75]2731#
2732# THE MAIN RULES
2733#
[219]2734all_recursive: $(pass_prev)
[75]2735
[130]2736rebuild: clean
[219]2737 + $(MAKE) -f $(firstword $(MAKEFILE_LIST)) all_recursive
[78]2738
[412]2739# @todo make this a non-default pass!
[353]2740uninstall:
[827]2741 $(RM) -f $(_INSTALLS_FILES)
[412]2742
[380]2743install: pass_installs
[78]2744
[75]2745# misc shortcuts.
[380]2746targets: bldprogs libraries dlls programs sysmods others installs
[75]2747objects: $(_OBJS)
[222]2748bldprogs: $(_BLDPROGS)
[189]2749libraries: $(_LIBS) $(_IMPORT_LIBS) $(_OTHER_LIBRARIES)
[205]2750dlls: $(_DLLS)
[219]2751programs: $(_PROGRAMS)
[205]2752sysmods: $(_SYSMODS)
[353]2753others: $(_OTHERS)
[854]2754installs: $(_INSTALLS) $(_INSTALLS_DIRS) $(_INSTALLS_FILES)
[75]2755
2756
[897]2757
[353]2758#
2759# kBuild debugging stuff.
2760#
2761show_targets:
[984]2762 @$(foreach target, $(_ALL_TARGETS),\
[353]2763 @$(ECHO) "target: $(target)" $(NLTAB)\
2764 @$(ECHO) " PATH_$(target)=$(PATH_$(target))" $(NLTAB)\
2765 @$(ECHO) " TARGET_$(target)=$(TARGET_$(target))" $(NLTAB)\
2766 @$(ECHO) " INSTARGET_$(target)=$(INSTARGET_$(target))" $(NLTAB)\
[660]2767$(foreach prop,$(PROPS_SINGLE) $(PROPS_ACCUMULATE_L) $(PROPS_ACCUMULATE_R) OBJS_ CLEAN, \
[353]2768 $(eval _tmp:=$(firstword $($(target)_BLD_TRG) $(BUILD_TARGET))) \
2769 $(if $($(target)_$(prop).$(_tmp)),\
2770 @$(ECHO) " $(target)_$(prop).$(_tmp)=$($(target)_$(prop).$(_tmp))" $(NLTAB)) \
2771 $(if $($(target)_$(prop)), $(NLTAB)@$(ECHO) " $(target)_$(prop)=$($(target)_$(prop))" $(NLTAB)) \
2772)\
2773$(foreach prop,$(PROPS_DEFERRED), \
2774 $(eval _tmp:=$(firstword $($(target)_BLD_TRG) $(BUILD_TARGET))) \
2775 $(if $(value $(target)_$(prop).$(_tmp)),\
2776 @$(ECHO) ' $(target)_$(prop).$(_tmp)=$(value $(TARGET)_$(prop).$(_tmp))' $(NLTAB)) \
2777 $(if $(value $(target)_$(prop)), $(NLTAB)@$(ECHO) ' $(target)_$(prop)=$(value $(target)_$(prop))' $(NLTAB)) \
2778))
2779
2780
2781
2782#
2783# Include dependency files.
2784#
[893]2785ifneq ($(_DEPFILES),)
2786 includedep $(_DEPFILES)
2787endif
[353]2788
2789
[988]2790ifdef KBUILD_PROFILE_SELF
2791 _KBUILD_TS_FOOTER_END := $(nanots )
2792 $(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)
2793 $(info prof: footer.kmk: $(int-sub $(_KBUILD_TS_FOOTER_END), $(_KBUILD_TS_FOOTER_START)))
2794 _KBUILD_TS_PREV := $(_KBUILD_TS_FOOTER_END)
2795endif
2796
[72]2797# end-of-file-content
[106]2798__footer_kmk__ := target
[72]2799endif # __footer_kmk__
[438]2800
Note: See TracBrowser for help on using the repository browser.