source: trunk/kBuild/footer.kmk@ 579

Last change on this file since 579 was 579, checked in by bird, 19 years ago

Clean link output files. fixes #3.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 69.0 KB
RevLine 
[72]1# $Id: footer.kmk 579 2006-11-23 10:49:50Z bird $
2## @file
3#
4# kBuild - File included at top of makefile.
5#
[353]6# Copyright (c) 2004-2005 knut st. osmundsen <bird-srcspam@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
29
30#
[530]31# Make sure that the core variables we defined in recursive expansion mode
32# up in header.kmk get expanded before we really start using them. The kBuild
33# functions added to kmk to speed stuff up assumes that the variables are
34# expanded here.
35#
36PATH_OBJ := $(PATH_OBJ)
37PATH_TARGET := $(PATH_TARGET)
38PATH_INS := $(PATH_INS)
39PATH_BIN := $(PATH_BIN)
40PATH_DLL := $(PATH_DLL)
41PATH_SYS := $(PATH_SYS)
42PATH_LIB := $(PATH_LIB)
43PATH_DOC := $(PATH_DOC)
44
45#
[72]46# Variables.
[73]47# (Some of these need initialization before including definitions using them.)
[72]48#
49
50# all targets.
[353]51ALL_TARGETS += \
[481]52 $(BLDPROGS) $(BLDPROGS.$(BUILD_PLATFORM)) $(BLDPROGS.$(BUILD_PLATFORM).$(BUILD_PLATFORM_ARCH)) \
53 $(LIBRARIES) $(LIBRARIES.$(BUILD_TARGET)) $(LIBRARIES.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) \
54 $(IMPORT_LIBS) $(IMPORT_LIBS.$(BUILD_TARGET)) $(IMPORT_LIBS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) \
55 $(DLLS) $(DLLS.$(BUILD_TARGET)) $(DLLS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) \
56 $(PROGRAMS) $(PROGRAMS.$(BUILD_TARGET)) $(PROGRAMS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) \
57 $(SYSMODS) $(SYSMODS.$(BUILD_TARGET)) $(SYSMODS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) \
58 $(INSTALLS) $(INSTALLS.$(BUILD_TARGET)) $(INSTALLS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) \
59 $(OTHERS) $(OTHERS.$(BUILD_TARGET)) $(OTHERS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH))
[72]60
[447]61# all $(BUILD_TARGET) targets.
62_ALL_BUILD_TARGET_TARGETS += \
[482]63 $(BLDPROGS) $(BLDPROGS.$(BUILD_PLATFORM)) $(BLDPROGS.$(BUILD_PLATFORM).$(BUILD_PLATFORM_ARCH)) \
64 $(LIBRARIES) $(LIBRARIES.$(BUILD_TARGET)) $(LIBRARIES.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) \
[481]65 $(IMPORT_LIBS) $(IMPORT_LIBS.$(BUILD_TARGET)) $(IMPORT_LIBS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) \
[482]66 $(DLLS) $(DLLS.$(BUILD_TARGET)) $(DLLS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) \
67 $(PROGRAMS) $(PROGRAMS.$(BUILD_TARGET)) $(PROGRAMS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) \
68 $(SYSMODS) $(SYSMODS.$(BUILD_TARGET)) $(SYSMODS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) \
69 $(INSTALLS) $(INSTALLS.$(BUILD_TARGET)) $(INSTALLS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) \
70 $(OTHERS) $(OTHERS.$(BUILD_TARGET)) $(OTHERS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH))
[447]71
72# all $(BUILD_TARGET) targets.
73_ALL_BUILD_PLATFORM_TARGETS += \
[481]74 $(BLDPROGS) $(BLDPROGS.$(BUILD_PLATFORM)) $(BLDPROGS.$(BUILD_PLATFORM).$(BUILD_PLATFORM_ARCH))
[447]75
[75]76# dependency files.
77_DEPFILES :=
78
[380]79# included dependency files.
80_DEPFILES_INCLUDED :=
81
82
[75]83# All kind of output files except for _OBJS and _DEPFILES.
84# Compiling or linking definition outputting other things that $@ and any
85# required dependency file must add those output files to this variable.
86_OUT_FILES :=
87
[353]88# Files which only requires cleaning up.
89_CLEAN_FILES :=
90
[72]91# all of a type
[219]92_OBJS :=
[222]93_BLDPROGS :=
[219]94_LIBS :=
95_DLLS :=
96_PROGRAMS :=
97_SYSMODS :=
[353]98_INSTALLS :=
[380]99_INSTALLS_DIRS :=
[353]100_OTHERS :=
[417]101_PACKING :=
[380]102_DIRS := $(PATH_TARGET)/ $(PATH_TARGET)
[189]103_IMPORT_LIBS :=
[72]104
[220]105# misc
106pass_prev :=
107
108
[72]109#
[73]110# Basic macros
111#
112
113## Figure out the tool for a source
[481]114# @param target source file
115# @param source normalized main target
116# @param type tooltype
[222]117# @param bld_trg build target.
[481]118# @param bld_trg_arch build target architecture.
[552]119# @remark Obsoleted by kBuild helpers in kmk. Only required for gmake compatbility.
[79]120_SOURCE_TOOL = $(strip $(firstword \
[481]121 $($(target)_$(source)_$(type)TOOL.$(bld_trg).$(bld_trg_arch)) \
[222]122 $($(target)_$(source)_$(type)TOOL.$(bld_trg)) \
[106]123 $($(target)_$(source)_$(type)TOOL) \
[481]124 $($(target)_$(source)_TOOL.$(bld_trg).$(bld_trg_arch)) \
[222]125 $($(target)_$(source)_TOOL.$(bld_trg)) \
[106]126 $($(target)_$(source)_TOOL) \
[530]127 $($(source)_$(type)TOOL.$(bld_trg).$(bld_trg_arch)) \
128 $($(source)_$(type)TOOL.$(bld_trg)) \
129 $($(source)_$(type)TOOL) \
130 $($(source)_TOOL.$(bld_trg).$(bld_trg_arch)) \
131 $($(source)_TOOL.$(bld_trg)) \
132 $($(source)_TOOL) \
[481]133 $($(target)_$(type)TOOL.$(bld_trg).$(bld_trg_arch)) \
[222]134 $($(target)_$(type)TOOL.$(bld_trg)) \
[106]135 $($(target)_$(type)TOOL) \
[481]136 $($(target)_TOOL.$(bld_trg).$(bld_trg_arch)) \
[222]137 $($(target)_TOOL.$(bld_trg)) \
[106]138 $($(target)_TOOL) \
[481]139 $($(type)TOOL.$(bld_trg).$(bld_trg_arch)) \
[222]140 $($(type)TOOL.$(bld_trg)) \
[106]141 $($(type)TOOL) \
[481]142 $(TOOL.$(bld_trg).$(bld_trg_arch)) \
[222]143 $(TOOL.$(bld_trg)) \
[106]144 $(TOOL) ))
[73]145
[78]146## Figure out the tool for a target.
[481]147# @param target normalized target.
148# @param source tooltype.
[222]149# @param bld_trg build target.
[481]150# @param bld_trg_arch build target architecture.
[79]151_TARGET_TOOL = $(strip $(firstword \
[481]152 $($(target)_$(source)TOOL.$(bld_trg).$(bld_trg_arch)) \
[222]153 $($(target)_$(source)TOOL.$(bld_trg)) \
[106]154 $($(target)_$(source)TOOL) \
[481]155 $($(target)_TOOL.$(bld_trg).$(bld_trg_arch)) \
[222]156 $($(target)_TOOL.$(bld_trg)) \
[106]157 $($(target)_TOOL) \
[481]158 $($(source)TOOL.$(bld_trg).$(bld_trg_arch)) \
[238]159 $($(source)TOOL.$(bld_trg)) \
[106]160 $($(source)TOOL) \
[481]161 $(TOOL.$(bld_trg).$(bld_trg_arch)) \
[222]162 $(TOOL.$(bld_trg)) \
[106]163 $(TOOL) \
[79]164 ))
[183]165
[148]166## Removes the drive letter from a path (if it has one)
167# @param $1 the path
168no-drive=$(word $(words $(subst :, ,$(1))),$(subst :, ,$(1)))
[78]169
[148]170## Removes the root slash from a path (if it has one)
171# @param $1 the path
172no-root-slash=$(patsubst /%,%,$(1))
173
[73]174## Figure out where to put object files.
[110]175# @param $1 source file
176# @param $2 normalized main target
[316]177# @remark There are two major hacks here:
178# 1. Source files in the output directory are translated into a gen/ subdir.
[472]179# 2. Catch anyone specifying $(PATH_SUB_CURRENT)/sourcefile.c.
[552]180# @remark obsoleted by kBuild helpers in kmk. Only required for gmake compatbility.
[316]181_OBJECT_BASE = $(PATH_TARGET)/$(2)/$(call no-root-slash,$(call no-drive,$(basename \
[472]182 $(patsubst $(PATH_ROOT)/%,%,$(patsubst $(PATH_SUB_CURRENT)/%,%,$(patsubst $(PATH_TARGET)/$(2)/%,gen/%,$(1)))))))
[73]183
184## Figure out where to put object files.
[110]185# @param $1 real target name.
186# @param $2 normalized main target
[148]187_TARGET_BASE = $(PATH_TARGET)/$(2)/$(call no-root-slash,$(call no-drive,$(basename $(1))))
[73]188
189
[353]190## Figure out the actual name of an installed file.
191# @param $1 The file to install.
192# @param $2 The target name.
193# @param $3 The _INST value (can be empty).
194# @param $4 The default directory to use when $3 is empty.
195_INSTALL_FILE = $(patsubst %/,%/$(notdir $(1)),$(if $(3),$(PATH_INS)/$(3),$(4)/))
196
197
[73]198#
[185]199# Check syntax which leads to weird syntax errors.
200#
201
202## Check
203# @param $(target) Target name.
204define def_check_target
205ifneq ("$($(target)_TEMPLATE)","$(strip $($(target)_TEMPLATE))")
206$$(error $(target) have an incorrect template name. Remove any tabs!)
207endif
208endef
209$(foreach target, $(ALL_TARGETS),$(eval $(def_check_target)))
210
211
212#
[72]213# Include templates
214#
215_TEMPLATES := $(TEMPLATE)
216define def_templates
217ifdef $(target)_TEMPLATE
218_TEMPLATES += $($(target)_TEMPLATE)
219endif
220endef
221$(foreach target, $(ALL_TARGETS), $(eval $(def_templates)))
222_TEMPLATES := $(sort $(_TEMPLATES))
223# $ (warning dbg: _TEMPLATES=$(_TEMPLATES))
224
225define def_templates_include
226ifndef TEMPLATE_$(template)
[353]227include $(firstword $(foreach path, $(TEMPLATE_PATHS) $(PATH_KBUILD)/templates/, $(wildcard $(path)/$(template).kmk)))
[72]228endif
229endef
230$(foreach template, $(_TEMPLATES), $(eval $(def_templates)))
231
[74]232
[72]233#
[412]234# Template Inheritance.
235#
236define def_template_extends_prop
237ifndef TEMPLATE_$(template)_$(prop)
[552]238 ifdef TEMPLATE_$(parent)_$(prop)
[412]239TEMPLATE_$(template)_$(prop) = $$(TEMPLATE_$(parent)_$(prop))
[552]240 endif
[412]241endif
242endef
243
[552]244
[412]245define def_template_extends
246ifdef TEMPLATE_$(template)_EXTENDS
[552]247 ifndef TEMPLATE_$(template)_EXTENDS_STATUS_
248 TEMPLATE_$(template)_EXTENDS_STATUS_ := 0
249 parent := $(strip $(TEMPLATE_$(template)_EXTENDS))
[412]250
[552]251 # recursivly process the parent if it's inherting from somebody too.
252 ifdef TEMPLATE_$(parent)_EXTENDS
253 ifneq ($(TEMPLATE_$(template)_EXTENDS_STATUS_),42)
254 # foreach will create 'template' in a new variable context hiding our current variable.
255 $(foreach template, $(TEMPLATE_$(parent)_EXTENDS), $(eval $(value def_template_extends)))
256 parent := $(strip $(TEMPLATE_$(template)_EXTENDS))
257 endif
258 endif
259
260 # inherit properties.
261 $(foreach prop, $(PROPS_SINGLE) $(PROPS_ACCUMULATE) $(PROPS_DEFERRED)\
262 $(addsuffix .$(BUILD_TARGET), $(PROPS_SINGLE) $(PROPS_ACCUMULATE) $(PROPS_DEFERRED))\
263 $(addsuffix .$(BUILD_TARGET).$(BUILD_TARGET_ARCH), $(PROPS_SINGLE) $(PROPS_ACCUMULATE) $(PROPS_DEFERRED))\
264 $(addsuffix .$(BUILD_TARGET_ARCH), $(PROPS_SINGLE) $(PROPS_ACCUMULATE) $(PROPS_DEFERRED))\
265 $(addsuffix .$(BUILD_TARGET_CPU), $(PROPS_SINGLE) $(PROPS_ACCUMULATE) $(PROPS_DEFERRED))\
266 $(addsuffix .$(BUILD_TYPE), $(PROPS_SINGLE) $(PROPS_ACCUMULATE) $(PROPS_DEFERRED))\
267 ,$(eval $(def_template_extends_prop))) # exploits the 2 evaluation, so no value!
268
269 TEMPLATE_$(template)_EXTENDS_STATUS_ := 42
270 else
271 # protect against inheritance loops.
272 ifneq ($(TEMPLATE_$(template)_EXTENDS_STATUS_),42)
273 $(error kBuild: inheritance loop! template=$(template))
274 endif
275 endif
[412]276endif
277endef
278
279# $ (foreach template, $(_TEMPLATES), $(if TEMPLATE_$(template)_EXTENDS, $(eval $(value def_template_extends))))
280$(foreach template, $(_TEMPLATES), $(eval $(value def_template_extends)))
281
282
283#
[72]284# Common Inheritance
285#
286
[353]287## Inherit one template property in a non-accumulative manner.
[72]288# @param $(prop) Property name
289# @param $(target) Target name
[78]290# @todo fix the precedence order for some properties.
[72]291define def_inherit_template_one
[78]292ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop)
[72]293ifndef $(target)_$(prop)
[353]294$(target)_$(prop) := $(TEMPLATE_$($(target)_TEMPLATE)_$(prop))
295#$ (warning dbgtarget: $(target)_$(prop):='$(value $(target)_$(prop))' TEMPLATE_$($(target)_TEMPLATE)_$(prop))
[72]296endif
297endif
[447]298ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg)
299ifndef $(target)_$(prop).$(bld_trg)
300#$ (warning dbgsource: $(target)_$(prop).$(bld_trg)="TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg)" TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg))
301$(target)_$(prop).$(bld_trg) := $(TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg))
[79]302endif
303endif
[481]304ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg).$(bld_trg_arch)
305ifndef $(target)_$(prop).$(bld_trg).$(bld_trg_arch)
306#$ (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))
307$(target)_$(prop).$(bld_trg).$(bld_trg_arch) := $(TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg).$(bld_trg_arch))
308endif
309endif
[455]310ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_arch)
311ifndef $(target)_$(prop).$(bld_trg_arch)
312#$ (warning dbgsource: $(target)_$(prop).$(bld_trg_arch)="TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_arch)" TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_arch))
313$(target)_$(prop).$(bld_trg_arch) := $(TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_arch))
314endif
315endif
316ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_cpu)
317ifndef $(target)_$(prop).$(bld_trg_cpu)
318#$ (warning dbgsource: $(target)_$(prop).$(bld_trg_cpu)="TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_cpu)" TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_cpu))
319$(target)_$(prop).$(bld_trg_cpu) := $(TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_cpu))
320endif
321endif
[72]322endef
323
[353]324## Inherit one template property in a non-accumulative manner, deferred expansion.
325# @param 1: $(prop) Property name
326# @param 2: $(target) Target name
327# @todo fix the precedence order for some properties.
328# @remark this define relies on double evaluation
329define def_inherit_template_one_deferred
330ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop)
331ifndef $(target)_$(prop)
332$(target)_$(prop) = $$(TEMPLATE_$($(target)_TEMPLATE)_$(prop))
333#$ (warning dbgtarget: $(target)_$(prop):='$(value $(target)_$(prop))' TEMPLATE_$($(target)_TEMPLATE)_$(prop))
334endif
335endif
[447]336ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg)
337ifndef $(target)_$(prop).$(bld_trg)
338#$ (warning dbgsource: $(target)_$(prop).$(bld_trg)="TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg)" TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg))
339$(target)_$(prop).$(bld_trg) = $$(TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg))
[353]340endif
341endif
[481]342ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg).$(bld_trg_arch)
343ifndef $(target)_$(prop).$(bld_trg).$(bld_trg_arch)
344#$ (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))
345$(target)_$(prop).$(bld_trg).$(bld_trg_arch) = $$(TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg).$(bld_trg_arch))
346endif
347endif
[455]348ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_arch)
349ifndef $(target)_$(prop).$(bld_trg_arch)
350#$ (warning dbgsource: $(target)_$(prop).$(bld_trg_arch)="TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_arch)" TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_arch))
351$(target)_$(prop).$(bld_trg_arch) = $$(TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_arch))
352endif
353endif
354ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_cpu)
355ifndef $(target)_$(prop).$(bld_trg_cpu)
356#$ (warning dbgsource: $(target)_$(prop).$(bld_trg_cpu)="TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_cpu)" TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_cpu))
357$(target)_$(prop).$(bld_trg_cpu) = $$(TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_cpu))
358endif
359endif
[353]360endef
361
[183]362## Inherit one template property.
[78]363# @param $(prop) Property name
364# @param $(target) Target name
365define def_inherit_template_one_accumulate
366ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop)
[353]367#$ (warning dbgtype: TEMPLATE_$($(target)_TEMPLATE)_$(prop) $(target)_$(prop)=$($(target)_$(prop)) $(TEMPLATE_$($(target)_TEMPLATE)_$(prop)))
[442]368$(target)_$(prop) += $(TEMPLATE_$($(target)_TEMPLATE)_$(prop))
369#$ (warning dbgtype: $(target)_$(prop)=$($(target)_$(prop)))
[78]370endif
[243]371ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(BUILD_TYPE)
[353]372#$ (warning dbg4: TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(BUILD_TYPE))
[442]373$(target)_$(prop).$(BUILD_TYPE) += $(TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(BUILD_TYPE))
[243]374endif
[447]375ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg)
376#$ (warning dbg4: TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg))
377$(target)_$(prop).$(bld_trg) += $(TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg))
[79]378endif
[481]379ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg).$(bld_trg_arch)
380#$ (warning dbg4: TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg).$(bld_trg_arch))
381$(target)_$(prop).$(bld_trg).$(bld_trg_arch) += $(TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg).$(bld_trg_arch))
382endif
[447]383ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_cpu)
384#$ (warning dbg5: TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_cpu))
385$(target)_$(prop).$(bld_trg_cpu) += $(TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_cpu))
[79]386endif
[447]387ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_arch)
388#$ (warning dbg6: TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_arch))
389$(target)_$(prop).$(bld_trg_arch) += $(TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_arch))
[79]390endif
[78]391endef
392
[72]393## Inherit template properties for on target.
394# @param $(target) Target name.
395define def_inherit_template
[447]396# Inherit any default template.
397ifdef TEMPLATE
398ifeq ($($(target)_TEMPLATE),)
399$(eval $(target)_TEMPLATE:=$(TEMPLATE))
400endif
401endif
402# Expand the template if specified.
403ifneq ($($(target)_TEMPLATE),)
[353]404$(foreach prop,$(PROPS_SINGLE),$(eval $(value def_inherit_template_one)))
405$(foreach prop,$(PROPS_DEFERRED),$(eval $(def_inherit_template_one_deferred))) # exploits the 2 evaluation, so no value!
[442]406$(foreach prop,$(PROPS_ACCUMULATE),$(eval $(def_inherit_template_one_accumulate))) # += works fine (better) without value.
[447]407endif
[72]408endef
[353]409
[72]410# Inherit template properties
[447]411bld_trg := $(BUILD_TARGET)
412bld_trg_arch := $(BUILD_TARGET_ARCH)
413bld_trg_cpu := $(BUILD_TARGET_CPU)
414$(foreach target, $(_ALL_BUILD_TARGET_TARGETS),$(eval $(value def_inherit_template)))
[72]415
[447]416bld_trg := $(BUILD_PLATFORM)
417bld_trg_arch := $(BUILD_PLATFORM_ARCH)
418bld_trg_cpu := $(BUILD_PLATFORM_CPU)
419$(foreach target, $(_ALL_BUILD_PLATFORM_TARGETS),$(eval $(value def_inherit_template)))
[72]420
[447]421
[72]422#
[460]423# Include tools & sdks
[183]424#
[481]425_TOOLS := $(TOOL.$(BUILD_TARGET)) $(TOOL.$(BUILD_TARGET_ARCH)) $(TOOL.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) $(TOOL.$(BUILD_PLATFORM)) $(TOOL.$(BUILD_PLATFORM_ARCH)) $(TOOL.$(BUILD_PLATFORM).$(BUILD_PLATFORM_ARCH)) $(TOOL)
426_SDKS := $(SDKS.$(BUILD_TARGET)) $(SDKS.$(BUILD_TARGET_ARCH)) $(SDKS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) $(SDKS.$(BUILD_PLATFORM)) $(SDKS.$(BUILD_PLATFORM_ARCH)) $(SDKS.$(BUILD_PLATFORM).$(BUILD_PLATFORM_ARCH)) $(SDKS)
[460]427define def_tools_sdks_target_source
[353]428$(eval _TOOLS += $(foreach prop, $(PROPS_TOOLS), \
[460]429 $($(source)_$(prop).$(_bld_trg)) \
430 $($(target)_$(source)_$(prop).$(_bld_trg)) \
[481]431 $($(source)_$(prop).$(_bld_trg).$(_bld_trg_arch)) \
432 $($(target)_$(source)_$(prop).$(_bld_trg).$(_bld_trg_arch)) \
[460]433 $($(source)_$(prop).$(_bld_trg_arch)) \
434 $($(target)_$(source)_$(prop).$(_bld_trg_arch)) \
[353]435 $($(source)_$(prop)) \
436 $($(target)_$(source)_$(prop))))
[460]437$(eval _SDKS += \
438 $($(source)_SDKS.$(_bld_trg)) \
439 $($(target)_$(source)_SDKS.$(_bld_trg)) \
[481]440 $($(source)_SDKS.$(_bld_trg).$(_bld_trg_arch)) \
441 $($(target)_$(source)_SDKS.$(_bld_trg).$(_bld_trg_arch)) \
[460]442 $($(source)_SDKS.$(_bld_trg_arch)) \
443 $($(target)_$(source)_SDKS.$(_bld_trg_arch)) \
444 $($(source)_SDKS) \
445 $($(target)_$(source)_SDKS))
[72]446endef
[353]447
[460]448define def_tools_sdks_target
449_bld_trg := $(firstword $($(target)_BLD_TRG) $(bld_trg))
450_bld_trg_arch := $(firstword $($(target)_BLD_TRG_ARCH) $(bld_trg_arch))
451_bld_trg_cpu := $(firstword $($(target)_BLD_TRG_CPU) $(bld_trg_cpu))
452
[353]453$(eval _TOOLS += $(foreach prop, $(PROPS_TOOLS), \
[460]454 $($(target)_$(prop).$(_bld_trg)) \
455 $($(target)_$(prop).$(_bld_trg_arch)) \
[481]456 $($(target)_$(prop).$(_bld_trg).$(_bld_trg_arch)) \
[353]457 $($(target)_$(prop))))
[460]458$(eval _SDKS += \
459 $($(target)_SDKS.$(_bld_trg)) \
460 $($(target)_SDKS.$(_bld_trg_arch)) \
[481]461 $($(target)_SDKS.$(_bld_trg).$(_bld_trg_arch)) \
[460]462 $($(target)_SDKS))
[353]463$(foreach source, \
[460]464 $($(target)_SOURCES.$(_bld_trg)) \
465 $($(target)_SOURCES.$(_bld_trg_arch)) \
[481]466 $($(target)_SOURCES.$(_bld_trg).$(_bld_trg_arch)) \
[460]467 $($(target)_SOURCES.$(_bld_trg_cpu)) \
[353]468 $($(target)_SOURCES.$(BUILD_TYPE)) \
469 $($(target)_SOURCES) \
[460]470 , $(eval $(value def_tools_sdks_target_source)))
[72]471endef
[353]472
[460]473bld_trg := $(BUILD_TARGET)
474bld_trg_arch := $(BUILD_TARGET_ARCH)
475bld_trg_cpu := $(BUILD_TARGET_CPU)
476$(foreach target, $(_ALL_BUILD_TARGET_TARGETS), $(eval $(value def_tools_sdks_target)))
[72]477
[460]478bld_trg := $(BUILD_PLATFORM)
479bld_trg_arch := $(BUILD_PLATFORM_ARCH)
480bld_trg_cpu := $(BUILD_PLATFORM_CPU)
481$(foreach target, $(_ALL_BUILD_PLATFORM_TARGETS), $(eval $(value def_tools_sdks_target)))
482
483
484# include TOOLS
[72]485define def_tools_include
486ifndef TOOL_$(tool)
[353]487TOOL_$(tool)_KMK_FILE := $(firstword $(foreach path, $(TOOL_PATHS) $(PATH_KBUILD)/tools, $(wildcard $(path)/$(tool).kmk)))
488ifeq ($(TOOL_$(tool)_KMK_FILE),)
489$(error kBuild: Cannot find include file for the tool '$(tool)'! Searched: $(TOOL_PATHS) $(PATH_KBUILD)/tools)
[72]490endif
[353]491include $(TOOL_$(tool)_KMK_FILE)
492endif
[72]493endef
[460]494
495_TOOLS := $(sort $(_TOOLS))
[353]496$(foreach tool, $(_TOOLS), $(eval $(value def_tools_include)))
[72]497
498
[460]499# include SDKS
[122]500define def_sdks_include_one
[72]501ifndef SDK_$(sdk)
[353]502SDK_$(sdk)_KMK_FILE := $(firstword $(foreach path, $(SDK_PATHS) $(PATH_KBUILD)/sdks, $(wildcard $(path)/$(sdk).kmk)))
503ifeq ($(SDK_$(sdk)_KMK_FILE),)
504$(error kBuild: Cannot find include file for the SDK '$(sdk)'! Searched: $(SDK_PATHS) $(PATH_KBUILD)/sdks)
[72]505endif
[353]506include $(SDK_$(sdk)_KMK_FILE)
507endif
[72]508endef
[460]509
510_SDKS := $(sort $(_SDKS))
[353]511$(foreach sdk, $(_SDKS), $(eval $(value def_sdks_include_one)))
[72]512
[380]513
[73]514#
515# Object processing.
516#
[72]517
[380]518## wrapper the compile command dependency check.
519ifndef NO_COMPILE_CMDS_DEPS
[552]520 ifneq ($(filter comp-vars,$(KMK_FEATURES)),)
[530]521_DEP_COMPILE_CMDS = $(comp-vars $(target)_$(source)_CMDS_PREV_,$(target)_$(source)_CMDS_,FORCE)
522 else
[380]523_DEP_COMPILE_CMDS = $(if $(subst $(strip $($(target)_$(source)_CMDS_PREV_)),,$(strip $($(target)_$(source)_CMDS_))),FORCE,)
[530]524 endif
[380]525else
526_DEP_COMPILE_CMDS =
527endif
528
529## Generates the rules for building a specific object, and the '::' aliases
530# for building a source file.
[353]531# @param $(obj) The object file.
[380]532define def_target_source_rule
533$(obj) $($(target)_$(source)_OUTPUT_): \
534 $($(target)_$(source)_DEPEND_) \
535 $(_DEP_COMPILE_CMDS) \
536 | \
537 $($(target)_$(source)_DEPORD_)
538 $(call MSG_L1,Creating $$@)
[472]539 $(RM) -f $(dep) $(obj) $($(target)_$(source)_OUTPUT_)
[380]540 $(custom_pre)
[412]541
[380]542$($(target)_$(source)_CMDS_)
543
544 $(custom_post)
545ifndef NO_COMPILE_CMDS_DEPS
546 @$(APPEND) "$(dep)"
547 @$(APPEND) "$(dep)" 'define $(target)_$(source)_CMDS_PREV_'
548 @$(APPEND) "$(dep)" '$(subst $(NL),'$(NL)$(TAB)@$(APPEND) "$(dep)" ',$($(target)_$(source)_CMDS_))'
549 @$(APPEND) "$(dep)" 'endef'
[412]550endif
[380]551
[353]552$(basename $(notdir $(obj))).o::
[442]553 + $$(MAKE) -f $$(MAKEFILE) $(obj)
[445]554$(basename $(notdir $(obj))).obj::
[442]555 + $$(MAKE) -f $$(MAKEFILE) $(obj)
[353]556endef
[205]557
[353]558
[380]559## wrapper the link command dependency check.
560ifndef NO_COMPILE_CMDS_DEPS
561_DEP_LINK_CMDS = $(if $(subst $(strip $($(target)_CMDS_PREV_)),,$(strip $($(target)_CMDS_))),FORCE,)
562else
563_DEP_LINK_CMDS =
564endif
565
566## Generate the link rule for a target.
567# @param $(target) The normalized target name.
568# @param $(dirdep) Directories we depend upon begin created before linking.
569# @param $(dep) The name of the dependency file.
570# @param $(out)
571# @param $($(target)_OUTPUT_) Output files from the link.
572# @param $($(target)_DEPEND_) Dependencies.
573# @param $($(target)_DEPORD_) Dependencies which should only affect build order.
574# @param $($(target)_CMDS_) The link commands.
575# @param $($(target)_CMDS_PREV_) The link commands from the previous run.
576define def_link_rule
577$(out) $($(target)_OUTPUT_): \
578 $($(target)_DEPEND_) \
579 $(_DEP_LINK_CMDS) \
580 | \
581 $($(target)_DEPORD_)
582 $(call MSG_L1,Creating $$@)
[473]583 $(RM) -f $(dep) $(out) $($(target)_OUTPUT_)
[380]584 $(custom_pre)
[412]585
[380]586$($(target)_CMDS_)
587
588 $(custom_post)
[524]589ifndef NO_LINK_CMDS_DEPS
[380]590 @$(APPEND) "$(dep)" 'define $(target)_CMDS_PREV_'
591 @$(APPEND) "$(dep)" '$(subst $(NL),'$(NL)$(TAB)@$(APPEND) "$(dep)" ',$($(target)_CMDS_))'
592 @$(APPEND) "$(dep)" 'endef'
[412]593endif
[380]594
595$(basename $(notdir $(out)))::
[442]596 + $$(MAKE) -f $$(MAKEFILE) $(out)
[380]597endef
598
599
600## Generate the link & lib install rule
601# @param $(target) Normalized target name.
602# @param $(out) The build target.
603# @param $(INSTARGET_$(target)) The installation targets.
604# @param $(mode) The file mode (optional)
605define def_link_install_rule
606$(INSTARGET_$(target)) : $(out) | $(call DIRDEP,$(dir $(INSTARGET_$(target))))
607 $(INSTALL) $$(if $(mode),-m $(mode)) $(out) $$@
608endef
609
610
611
[73]612## Generic macro for processing C, C++ and Assembly sources.
613# @param $(target) Normalized target name.
614# @param $(source) Source file name.
615# @param $(type) Source type. {C,CXX,AS}
[221]616# @param bld_type Build type.
617# @param bld_trg Build target.
618# @param bld_trg_arch Build target arch.
619# @param bld_trg_cpu Build target cpu.
[552]620# @remark obsoleted by kBuild helpers in kmk. Only required for gmake compatbility.
[72]621#
[530]622define def_target_source_c_cpp_asm_old
[105]623#$ (warning dbg: def_target_source_c_cpp_asm: source='$(source)' target='$(target)' type='$(type)')
[73]624
[353]625tool := $(call _SOURCE_TOOL,$(source),$(target),$(type))
626outbase := $(call _OBJECT_BASE,$(source),$(target))
627PATH_$(target)_$(source) := $(patsubst %/,%,$(dir $(outbase)))
628dirdep := $(call DIRDEP,$(dir $(outbase)))
629defs :=\
[78]630 $(TOOL_$(tool)_DEFS)\
[221]631 $(TOOL_$(tool)_DEFS.$(bld_type))\
632 $(TOOL_$(tool)_DEFS.$(bld_trg))\
633 $(TOOL_$(tool)_DEFS.$(bld_trg_arch))\
[481]634 $(TOOL_$(tool)_DEFS.$(bld_trg).$(bld_trg_arch))\
[221]635 $(TOOL_$(tool)_DEFS.$(bld_trg_cpu))\
[74]636 $(TOOL_$(tool)_$(type)DEFS)\
[221]637 $(TOOL_$(tool)_$(type)DEFS.$(bld_type))\
638 $(foreach sdk, $(SDKS.$(bld_trg)) \
[481]639 $(SDKS.$(bld_trg).$(bld_trg_arch)) \
[221]640 $(SDKS.$(bld_type)) \
[78]641 $(SDKS),\
[353]642 $(SDK_$(sdk)_DEFS)\
643 $(SDK_$(sdk)_DEFS.$(bld_type))\
644 $(SDK_$(sdk)_DEFS.$(bld_trg))\
645 $(SDK_$(sdk)_DEFS.$(bld_trg_arch))\
[481]646 $(SDK_$(sdk)_DEFS.$(bld_trg).$(bld_trg_arch))\
[353]647 $(SDK_$(sdk)_DEFS.$(bld_trg_cpu))\
648 $(SDK_$(sdk)_$(type)DEFS)\
649 $(SDK_$(sdk)_$(type)DEFS.$(bld_type))\
650 $(SDK_$(sdk)_$(type)DEFS.$(bld_trg))\
651 $(SDK_$(sdk)_$(type)DEFS.$(bld_trg_arch))\
[481]652 $(SDK_$(sdk)_$(type)DEFS.$(bld_trg).$(bld_trg_arch))\
[353]653 $(SDK_$(sdk)_$(type)DEFS.$(bld_trg_cpu)))\
[74]654 $(DEFS)\
[221]655 $(DEFS.$(bld_type))\
656 $(DEFS.$(bld_trg))\
657 $(DEFS.$(bld_trg_arch))\
[481]658 $(DEFS.$(bld_trg).$(bld_trg_arch))\
[221]659 $(DEFS.$(bld_trg_cpu))\
[78]660 $($(type)DEFS)\
[221]661 $($(type)DEFS.$(bld_type))\
662 $($(type)DEFS.$(bld_trg))\
663 $($(type)DEFS.$(bld_trg_arch))\
[481]664 $($(type)DEFS.$(bld_trg).$(bld_trg_arch))\
[221]665 $($(type)DEFS.$(bld_trg_cpu))\
666 $(foreach sdk, $($(target)_SDKS.$(bld_trg)) \
[481]667 $($(target)_SDKS.$(bld_trg).$(bld_trg_arch)) \
[221]668 $($(target)_SDKS.$(bld_type)) \
[78]669 $($(target)_SDKS),\
[353]670 $(SDK_$(sdk)_DEFS)\
671 $(SDK_$(sdk)_DEFS.$(bld_type))\
672 $(SDK_$(sdk)_DEFS.$(bld_trg))\
673 $(SDK_$(sdk)_DEFS.$(bld_trg_arch))\
[481]674 $(SDK_$(sdk)_DEFS.$(bld_trg).$(bld_trg_arch))\
[353]675 $(SDK_$(sdk)_DEFS.$(bld_trg_cpu))\
676 $(SDK_$(sdk)_$(type)DEFS)\
677 $(SDK_$(sdk)_$(type)DEFS.$(bld_type))\
678 $(SDK_$(sdk)_$(type)DEFS.$(bld_trg))\
679 $(SDK_$(sdk)_$(type)DEFS.$(bld_trg_arch))\
[481]680 $(SDK_$(sdk)_$(type)DEFS.$(bld_trg).$(bld_trg_arch))\
[353]681 $(SDK_$(sdk)_$(type)DEFS.$(bld_trg_cpu)))\
[74]682 $($(target)_DEFS)\
[221]683 $($(target)_DEFS.$(bld_type))\
684 $($(target)_DEFS.$(bld_trg))\
685 $($(target)_DEFS.$(bld_trg_arch))\
[481]686 $($(target)_DEFS.$(bld_trg).$(bld_trg_arch))\
[221]687 $($(target)_DEFS.$(bld_trg_cpu))\
[78]688 $($(target)_$(type)DEFS)\
[221]689 $($(target)_$(type)DEFS.$(bld_type))\
690 $($(target)_$(type)DEFS.$(bld_trg))\
691 $($(target)_$(type)DEFS.$(bld_trg_arch))\
[481]692 $($(target)_$(type)DEFS.$(bld_trg).$(bld_trg_arch))\
[221]693 $($(target)_$(type)DEFS.$(bld_trg_cpu))\
694 $(foreach sdk, $($(source)_SDKS.$(bld_trg)) \
[481]695 $($(source)_SDKS.$(bld_trg).$(bld_trg_arch)) \
[221]696 $($(source)_SDKS.$(bld_type)) \
[78]697 $($(source)_SDKS),\
[353]698 $(SDK_$(sdk)_DEFS)\
699 $(SDK_$(sdk)_DEFS.$(bld_type))\
700 $(SDK_$(sdk)_DEFS.$(bld_trg))\
701 $(SDK_$(sdk)_DEFS.$(bld_trg_arch))\
[481]702 $(SDK_$(sdk)_DEFS.$(bld_trg).$(bld_trg_arch))\
[353]703 $(SDK_$(sdk)_DEFS.$(bld_trg_cpu))\
704 $(SDK_$(sdk)_$(type)DEFS)\
705 $(SDK_$(sdk)_$(type)DEFS.$(bld_type))\
706 $(SDK_$(sdk)_$(type)DEFS.$(bld_trg))\
707 $(SDK_$(sdk)_$(type)DEFS.$(bld_trg_arch))\
[481]708 $(SDK_$(sdk)_$(type)DEFS.$(bld_trg).$(bld_trg_arch))\
[353]709 $(SDK_$(sdk)_$(type)DEFS.$(bld_trg_cpu)))\
[74]710 $($(source)_DEFS)\
[221]711 $($(source)_DEFS.$(bld_type))\
712 $($(source)_DEFS.$(bld_trg))\
713 $($(source)_DEFS.$(bld_trg_arch))\
[481]714 $($(source)_DEFS.$(bld_trg).$(bld_trg_arch))\
[221]715 $($(source)_DEFS.$(bld_trg_cpu))\
[73]716 $($(source)_$(type)DEFS)\
[221]717 $($(source)_$(type)DEFS.$(bld_type))\
718 $($(source)_$(type)DEFS.$(bld_trg))\
719 $($(source)_$(type)DEFS.$(bld_trg_arch))\
[481]720 $($(source)_$(type)DEFS.$(bld_trg).$(bld_trg_arch))\
[221]721 $($(source)_$(type)DEFS.$(bld_trg_cpu))\
722 $(foreach sdk, $($(target)_$(source)_SDKS.$(bld_trg)) \
[481]723 $($(target)_$(source)_SDKS.$(bld_trg).$(bld_trg_arch)) \
[221]724 $($(target)_$(source)_SDKS.$(bld_type)) \
[78]725 $($(target)_$(source)_SDKS),\
[353]726 $(SDK_$(sdk)_DEFS)\
727 $(SDK_$(sdk)_DEFS.$(bld_type))\
728 $(SDK_$(sdk)_DEFS.$(bld_trg))\
729 $(SDK_$(sdk)_DEFS.$(bld_trg_arch))\
[481]730 $(SDK_$(sdk)_DEFS.$(bld_trg).$(bld_trg_arch))\
[353]731 $(SDK_$(sdk)_DEFS.$(bld_trg_cpu))\
732 $(SDK_$(sdk)_$(type)DEFS)\
733 $(SDK_$(sdk)_$(type)DEFS.$(bld_type))\
734 $(SDK_$(sdk)_$(type)DEFS.$(bld_trg))\
735 $(SDK_$(sdk)_$(type)DEFS.$(bld_trg_arch))\
[481]736 $(SDK_$(sdk)_$(type)DEFS.$(bld_trg).$(bld_trg_arch))\
[353]737 $(SDK_$(sdk)_$(type)DEFS.$(bld_trg_cpu)))\
[74]738 $($(target)_$(source)_DEFS)\
[221]739 $($(target)_$(source)_DEFS.$(bld_type))\
740 $($(target)_$(source)_DEFS.$(bld_trg))\
741 $($(target)_$(source)_DEFS.$(bld_trg_arch))\
[481]742 $($(target)_$(source)_DEFS.$(bld_trg).$(bld_trg_arch))\
[221]743 $($(target)_$(source)_DEFS.$(bld_trg_cpu))\
[74]744 $($(target)_$(source)_$(type)DEFS)\
[221]745 $($(target)_$(source)_$(type)DEFS.$(bld_type))\
746 $($(target)_$(source)_$(type)DEFS.$(bld_trg))\
747 $($(target)_$(source)_$(type)DEFS.$(bld_trg_arch))\
[481]748 $($(target)_$(source)_$(type)DEFS.$(bld_trg).$(bld_trg_arch))\
[353]749 $($(target)_$(source)_$(type)DEFS.$(bld_trg_cpu))
750incs :=\
[221]751 $($(target)_$(source)_$(type)INCS.$(bld_trg_cpu))\
[481]752 $($(target)_$(source)_$(type)INCS.$(bld_trg).$(bld_trg_arch))\
[221]753 $($(target)_$(source)_$(type)INCS.$(bld_trg_arch))\
754 $($(target)_$(source)_$(type)INCS.$(bld_trg))\
755 $($(target)_$(source)_$(type)INCS.$(bld_type))\
[73]756 $($(target)_$(source)_$(type)INCS)\
[221]757 $($(target)_$(source)_INCS.$(bld_trg_cpu))\
[481]758 $($(target)_$(source)_INCS.$(bld_trg).$(bld_trg_arch))\
[221]759 $($(target)_$(source)_INCS.$(bld_trg_arch))\
760 $($(target)_$(source)_INCS.$(bld_trg))\
761 $($(target)_$(source)_INCS.$(bld_type))\
[73]762 $($(target)_$(source)_INCS)\
[221]763 $(foreach sdk, $($(target)_$(source)_SDKS.$(bld_trg)) \
[481]764 $($(target)_$(source)_SDKS.$(bld_trg).$(bld_trg_arch)) \
[221]765 $($(target)_$(source)_SDKS.$(bld_type)) \
[133]766 $($(target)_$(source)_SDKS),\
[353]767 $(SDK_$(sdk)_$(type)INCS.$(bld_trg_cpu))\
[481]768 $(SDK_$(sdk)_$(type)INCS.$(bld_trg).$(bld_trg_arch))\
[353]769 $(SDK_$(sdk)_$(type)INCS.$(bld_trg_arch))\
770 $(SDK_$(sdk)_$(type)INCS.$(bld_trg))\
771 $(SDK_$(sdk)_$(type)INCS.$(bld_type))\
772 $(SDK_$(sdk)_$(type)INCS)\
773 $(SDK_$(sdk)_INCS.$(bld_trg_cpu))\
[481]774 $(SDK_$(sdk)_INCS.$(bld_trg).$(bld_trg_arch))\
[353]775 $(SDK_$(sdk)_INCS.$(bld_trg_arch))\
776 $(SDK_$(sdk)_INCS.$(bld_trg))\
777 $(SDK_$(sdk)_INCS.$(bld_type))\
778 $(SDK_$(sdk)_INCS))\
[221]779 $($(source)_$(type)INCS.$(bld_trg_cpu))\
[481]780 $($(source)_$(type)INCS.$(bld_trg).$(bld_trg_arch))\
[221]781 $($(source)_$(type)INCS.$(bld_trg_arch))\
782 $($(source)_$(type)INCS.$(bld_trg))\
783 $($(source)_$(type)INCS.$(bld_type))\
[73]784 $($(source)_$(type)INCS)\
[221]785 $($(source)_INCS.$(bld_trg_cpu))\
[481]786 $($(source)_INCS.$(bld_trg).$(bld_trg_arch))\
[221]787 $($(source)_INCS.$(bld_trg_arch))\
788 $($(source)_INCS.$(bld_trg))\
789 $($(source)_INCS.$(bld_type))\
[73]790 $($(source)_INCS)\
[221]791 $(foreach sdk, $($(source)_SDKS.$(bld_trg)) \
[481]792 $($(source)_SDKS.$(bld_trg).$(bld_trg_arch)) \
[221]793 $($(source)_SDKS.$(bld_type)) \
[78]794 $($(source)_SDKS),\
[353]795 $(SDK_$(sdk)_$(type)INCS.$(bld_trg_cpu))\
[481]796 $(SDK_$(sdk)_$(type)INCS.$(bld_trg).$(bld_trg_arch))\
[353]797 $(SDK_$(sdk)_$(type)INCS.$(bld_trg_arch))\
798 $(SDK_$(sdk)_$(type)INCS.$(bld_trg))\
799 $(SDK_$(sdk)_$(type)INCS.$(bld_type))\
800 $(SDK_$(sdk)_$(type)INCS)\
801 $(SDK_$(sdk)_INCS.$(bld_trg_cpu))\
[481]802 $(SDK_$(sdk)_INCS.$(bld_trg).$(bld_trg_arch))\
[353]803 $(SDK_$(sdk)_INCS.$(bld_trg_arch))\
804 $(SDK_$(sdk)_INCS.$(bld_trg))\
805 $(SDK_$(sdk)_INCS.$(bld_type))\
806 $(SDK_$(sdk)_INCS))\
[221]807 $($(target)_$(type)INCS.$(bld_trg_cpu))\
[481]808 $($(target)_$(type)INCS.$(bld_trg).$(bld_trg_arch))\
[221]809 $($(target)_$(type)INCS.$(bld_trg_arch))\
810 $($(target)_$(type)INCS.$(bld_trg))\
811 $($(target)_$(type)INCS.$(bld_type))\
[73]812 $($(target)_$(type)INCS)\
[221]813 $($(target)_INCS.$(bld_trg_cpu))\
[481]814 $($(target)_INCS.$(bld_trg).$(bld_trg_arch))\
[221]815 $($(target)_INCS.$(bld_trg_arch))\
816 $($(target)_INCS.$(bld_trg))\
817 $($(target)_INCS.$(bld_type))\
[73]818 $($(target)_INCS)\
[221]819 $(foreach sdk, $($(target)_SDKS.$(bld_trg)) \
[481]820 $($(target)_SDKS.$(bld_trg).$(bld_trg_arch)) \
[221]821 $($(target)_SDKS.$(bld_type)) \
[78]822 $($(target)_SDKS),\
[353]823 $(SDK_$(sdk)_$(type)INCS.$(bld_trg_cpu))\
[481]824 $(SDK_$(sdk)_$(type)INCS.$(bld_trg).$(bld_trg_arch))\
[353]825 $(SDK_$(sdk)_$(type)INCS.$(bld_trg_arch))\
826 $(SDK_$(sdk)_$(type)INCS.$(bld_trg))\
827 $(SDK_$(sdk)_$(type)INCS.$(bld_type))\
828 $(SDK_$(sdk)_$(type)INCS)\
829 $(SDK_$(sdk)_INCS.$(bld_trg_cpu))\
[481]830 $(SDK_$(sdk)_INCS.$(bld_trg).$(bld_trg_arch))\
[353]831 $(SDK_$(sdk)_INCS.$(bld_trg_arch))\
832 $(SDK_$(sdk)_INCS.$(bld_trg))\
833 $(SDK_$(sdk)_INCS.$(bld_type))\
834 $(SDK_$(sdk)_INCS))\
[221]835 $(INCS.$(bld_trg_cpu))\
[481]836 $(INCS.$(bld_trg).$(bld_trg_arch))\
[221]837 $(INCS.$(bld_trg_arch))\
838 $(INCS.$(bld_trg))\
839 $(INCS.$(bld_type))\
[73]840 $(INCS)\
[221]841 $(foreach sdk, $(SDKS.$(bld_trg)) \
[481]842 $(SDKS.$(bld_trg).$(bld_trg_arch)) \
[221]843 $(SDKS.$(bld_type)) \
[78]844 $(SDKS),\
[353]845 $(SDK_$(sdk)_$(type)INCS.$(bld_trg_cpu))\
[481]846 $(SDK_$(sdk)_$(type)INCS.$(bld_trg).$(bld_trg_arch))\
[353]847 $(SDK_$(sdk)_$(type)INCS.$(bld_trg_arch))\
848 $(SDK_$(sdk)_$(type)INCS.$(bld_trg))\
849 $(SDK_$(sdk)_$(type)INCS.$(bld_type))\
850 $(SDK_$(sdk)_$(type)INCS)\
851 $(SDK_$(sdk)_INCS.$(bld_trg_cpu))\
[481]852 $(SDK_$(sdk)_INCS.$(bld_trg).$(bld_trg_arch))\
[353]853 $(SDK_$(sdk)_INCS.$(bld_trg_arch))\
854 $(SDK_$(sdk)_INCS.$(bld_trg))\
855 $(SDK_$(sdk)_INCS.$(bld_type))\
856 $(SDK_$(sdk)_INCS))\
[221]857 $(TOOL_$(tool)_$(type)INCS.$(bld_trg_cpu))\
[481]858 $(TOOL_$(tool)_$(type)INCS.$(bld_trg).$(bld_trg_arch))\
[221]859 $(TOOL_$(tool)_$(type)INCS.$(bld_trg_arch))\
860 $(TOOL_$(tool)_$(type)INCS.$(bld_trg))\
861 $(TOOL_$(tool)_$(type)INCS.$(bld_type))\
[353]862 $(TOOL_$(tool)_$(type)INCS)
863flags :=\
[73]864 $(TOOL_$(tool)_$(type)FLAGS)\
[221]865 $(TOOL_$(tool)_$(type)FLAGS.$(bld_type))\
866 $(TOOL_$(tool)_$(type)FLAGS.$(bld_trg))\
867 $(TOOL_$(tool)_$(type)FLAGS.$(bld_trg_arch))\
[481]868 $(TOOL_$(tool)_$(type)FLAGS.$(bld_trg).$(bld_trg_arch))\
[221]869 $(TOOL_$(tool)_$(type)FLAGS.$(bld_trg_cpu))\
[73]870 $($(type)FLAGS)\
[221]871 $($(type)FLAGS.$(bld_type))\
872 $($(type)FLAGS.$(bld_trg))\
873 $($(type)FLAGS.$(bld_trg_arch))\
[481]874 $($(type)FLAGS.$(bld_trg).$(bld_trg_arch))\
[221]875 $($(type)FLAGS.$(bld_trg_cpu))\
[73]876 $($(target)_$(type)FLAGS)\
[221]877 $($(target)_$(type)FLAGS.$(bld_type))\
878 $($(target)_$(type)FLAGS.$(bld_trg))\
879 $($(target)_$(type)FLAGS.$(bld_trg_arch))\
[481]880 $($(target)_$(type)FLAGS.$(bld_trg).$(bld_trg_arch))\
[221]881 $($(target)_$(type)FLAGS.$(bld_trg_cpu))\
[73]882 $($(source)_$(type)FLAGS)\
[221]883 $($(source)_$(type)FLAGS.$(bld_type))\
884 $($(source)_$(type)FLAGS.$(bld_trg))\
885 $($(source)_$(type)FLAGS.$(bld_trg_arch))\
[481]886 $($(source)_$(type)FLAGS.$(bld_trg).$(bld_trg_arch))\
[221]887 $($(source)_$(type)FLAGS.$(bld_trg_cpu))\
[73]888 $($(target)_$(source)_$(type)FLAGS)\
[221]889 $($(target)_$(source)_$(type)FLAGS.$(bld_type))\
890 $($(target)_$(source)_$(type)FLAGS.$(bld_trg))\
891 $($(target)_$(source)_$(type)FLAGS.$(bld_trg_arch))\
[481]892 $($(target)_$(source)_$(type)FLAGS.$(bld_trg).$(bld_trg_arch))\
[353]893 $($(target)_$(source)_$(type)FLAGS.$(bld_trg_cpu))
[552]894# this isn't 100% in sync with kBuild, but it doesn't matter as it's only for gmake now.
[353]895objsuff := $(firstword \
[481]896 $($(target)_$(source)_OBJSUFF.$(bld_trg).$(bld_trg_arch))\
[221]897 $($(target)_$(source)_OBJSUFF.$(bld_trg))\
[74]898 $($(target)_$(source)_OBJSUFF)\
[481]899 $($(source)_OBJSUFF.$(bld_trg).$(bld_trg_arch))\
[221]900 $($(source)_OBJSUFF.$(bld_trg))\
[74]901 $($(source)_OBJSUFF)\
[481]902 $($(target)_OBJSUFF.$(bld_trg).$(bld_trg_arch))\
[221]903 $($(target)_OBJSUFF.$(bld_trg))\
[74]904 $($(target)_OBJSUFF)\
[481]905 $(TOOL_$(tool)_$(type)OBJSUFF.$(bld_trg).$(bld_trg_arch))\
[221]906 $(TOOL_$(tool)_$(type)OBJSUFF.$(bld_trg))\
[74]907 $(TOOL_$(tool)_$(type)OBJSUFF)\
[353]908 $(SUFF_OBJ))
909obj := $(outbase)$(objsuff)
910deps := \
[184]911 $($(target)_$(source)_DEPS)\
[353]912 $($(target)_$(source)_DEPS.$(bld_type))\
913 $($(target)_$(source)_DEPS.$(bld_trg))\
914 $($(target)_$(source)_DEPS.$(bld_trg_arch))\
[481]915 $($(target)_$(source)_DEPS.$(bld_trg).$(bld_trg_arch))\
[353]916 $($(target)_$(source)_DEPS.$(bld_trg_cpu))\
[184]917 $($(source)_DEPS)\
[221]918 $($(source)_DEPS.$(bld_type))\
919 $($(source)_DEPS.$(bld_trg))\
[353]920 $($(source)_DEPS.$(bld_trg_arch))\
[481]921 $($(source)_DEPS.$(bld_trg).$(bld_trg_arch))\
[353]922 $($(source)_DEPS.$(bld_trg_cpu))\
[184]923 $($(target)_DEPS)\
[353]924 $($(target)_DEPS.$(bld_type))\
[481]925 $($(target)_DEPS.$(bld_trg))\
[221]926 $($(target)_DEPS.$(bld_trg_arch))\
[481]927 $($(target)_DEPS.$(bld_trg).$(bld_trg_arch))\
[353]928 $($(target)_DEPS.$(bld_trg_cpu))
[73]929
[380]930# dependencies
931dep := $(obj)$(SUFF_DEP)
[524]932ifndef NO_COMPILE_CMDS_DEPS
[380]933_DEPFILES_INCLUDED += $(dep)
934$(if $(wildcard $(dep)),$(eval include $(dep)))
935endif
[184]936
937#$ (warning dbg: target=$(target) source=$(source) tool=$(tool) obj=$(obj) dep=$(dep) flags=$(flags) defs=$(defs) incs=$(incs) dirdep=$(dirdep) outbase=$(outbase) objsuff=$(objsuff) deps=$(deps))
[380]938ifndef TOOL_$(tool)_COMPILE_$(type)_CMDS
[353]939$(warning kBuild: tools: \
[481]940 1 $($(target)_$(source)_$(type)TOOL.$(bld_trg).$(bld_trg_arch)) \
941 2 $($(target)_$(source)_$(type)TOOL.$(bld_trg)) \
942 3 $($(target)_$(source)_$(type)TOOL) \
943 4 $($(target)_$(source)_TOOL.$(bld_trg).$(bld_trg_arch)) \
944 5 $($(target)_$(source)_TOOL.$(bld_trg)) \
945 6 $($(target)_$(source)_TOOL) \
946 7 $($(target)_$(type)TOOL.$(bld_trg).$(bld_trg_arch)) \
947 8 $($(target)_$(type)TOOL.$(bld_trg)) \
948 9 $($(target)_$(type)TOOL) \
949 10 $($(target)_TOOL.$(bld_trg).$(bld_trg_arch)) \
950 11 $($(target)_TOOL.$(bld_trg)) \
951 12 $($(target)_TOOL) \
952 13 $($(source)_$(type)TOOL.$(bld_trg).$(bld_trg_arch)) \
953 14 $($(source)_$(type)TOOL.$(bld_trg)) \
954 15 $($(source)_$(type)TOOL) \
955 16 $($(source)_TOOL.$(bld_trg).$(bld_trg_arch)) \
956 17 $($(source)_TOOL.$(bld_trg)) \
957 18 $($(source)_TOOL) \
958 19 $($(type)TOOL.$(bld_trg).$(bld_trg_arch)) \
959 20 $($(type)TOOL.$(bld_trg)) \
960 21 $($(type)TOOL) \
961 22 $(TOOL.$(bld_trg).$(bld_trg_arch)) \
962 23 $(TOOL.$(bld_trg)) \
963 24 $(TOOL) )
[380]964$(error kBuild: TOOL_$(tool)_COMPILE_$(type)_CMDS is not defined. source=$(source) target=$(target) )
[97]965endif
[353]966
[380]967# call the tool
968$(target)_$(source)_CMDS_ := $(TOOL_$(tool)_COMPILE_$(type)_CMDS)
969$(target)_$(source)_OUTPUT_ := $(TOOL_$(tool)_COMPILE_$(type)_OUTPUT)
970$(target)_$(source)_DEPEND_ := $(TOOL_$(tool)_COMPILE_$(type)_DEPEND) $(deps) $(source)
971$(target)_$(source)_DEPORD_ := $(TOOL_$(tool)_COMPILE_$(type)_DEPORD) $(dirdep)
[73]972
[380]973# generate the compile rule.
974$(eval $(def_target_source_rule))
[205]975
[380]976_OUT_FILES += $($(target)_$(source)_OUTPUT_)
[353]977$(target)_OBJS_ += $(obj)
[73]978
979endef
980
[530]981## Generic macro for processing C, C++ and Assembly sources.
982# @param $(target) Normalized target name.
983# @param $(source) Source file name.
984# @param $(type) Source type. {C,CXX,AS}
985# @param bld_type Build type.
986# @param bld_trg Build target.
987# @param bld_trg_arch Build target arch.
988# @param bld_trg_cpu Build target cpu.
989#
990#$ (warning dbg: def_target_source_c_cpp_asm: source='$(source)' target='$(target)' type='$(type)')
991def_target_source_c_cpp_asm_new = $(kb-src-one x)
992
[552]993ifneq ($(filter kb-src-one,$(KMK_FEATURES)),)
[530]994def_target_source_c_cpp_asm_var = def_target_source_c_cpp_asm_new
995else
996def_target_source_c_cpp_asm_var = def_target_source_c_cpp_asm_old
997endif
998
[73]999## Generic macro for processing all target sources.
[74]1000# @param $(target) Normalized target name.
[73]1001define def_target_sources
1002#$ (warning def_target_sources)
1003# C sources
[353]1004type := C
[481]1005$(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)))\
[530]1006 ,$(eval $(value $(def_target_source_c_cpp_asm_var))) )
[73]1007
1008# C++ sources
[353]1009type := CXX
[481]1010$(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)))\
[530]1011 ,$(eval $(value $(def_target_source_c_cpp_asm_var))) )
[73]1012
1013# ASM sources
[353]1014type := AS
[481]1015$(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)))\
[530]1016 ,$(eval $(value $(def_target_source_c_cpp_asm_var))) )
[353]1017
[73]1018endef
1019
1020
[219]1021
[353]1022## Generic macro for generating the install rule(s) for a target
1023# and update the globals with default out.
[219]1024#
[353]1025# @param $(target) Normalized target name.
1026# @param $(out) The output file.
1027# @param $(definst) The default _INST value.
1028# @param $(typevar) The name of the variable with all the root targets of its type.
1029# @obsolete
1030define def_target_install_pluss
1031ifndef $(target)_NOINST
1032INSTARGET_$(target) := $(patsubst %/,%/$(notdir $(out)), \
1033 $(if $($(target)_INST), $(addprefix $(PATH_INS)/,$($(target)_INST)), $(definst)/))
[219]1034
[353]1035$(eval $(def_link_install_rule))
[239]1036
[579]1037_INSTALLS += $(INSTARGET_$(target))
[272]1038
[353]1039ifdef KBUILD_DO_AUTO_INSTALL
[579]1040$(typevar) += $(INSTARGET_$(target))
[219]1041else
[579]1042$(typevar) += $(out)
[219]1043endif
[353]1044else # _NOINST
[579]1045$(typevar) += $(out)
[353]1046endif
1047
[579]1048_OUT_FILES += $($(target)_OUTPUT_)
[353]1049_CLEAN_FILES += $($(target)_CLEAN)
1050_OBJS += $($(target)_OBJS_)
1051
[219]1052endef
1053
1054
1055
1056#
[72]1057# LIBRARIES
[73]1058#
[72]1059
1060## Library (one).
[74]1061# @param $(target) Normalized library (target) name.
[72]1062define def_lib
[145]1063# library basics
[222]1064## @todo prefix
[353]1065bld_type := $(firstword $($(target)_BLD_TYPE) $(BUILD_TYPE))
1066bld_trg := $(firstword $($(target)_BLD_TRG) $(BUILD_TARGET))
1067bld_trg_arch:= $(firstword $($(target)_BLD_TRG_ARCH) $(BUILD_TARGET_ARCH))
1068bld_trg_cpu := $(firstword $($(target)_BLD_TRG_CPU) $(BUILD_TARGET_CPU))
1069tool := $(call _TARGET_TOOL,$(target),AR)
[78]1070ifeq ($(tool),)
[353]1071$(error kBuild: Library target $(target) does not have a tool defined!)
[78]1072endif
[353]1073outbase := $(call _TARGET_BASE,$(target),$(target))
1074PATH_$(target) := $(patsubst %/,%,$(dir $(outbase)))
1075suff := $(firstword\
[481]1076 $($(target)_LIBSUFF.$(bld_trg).$(bld_trg_arch))\
[221]1077 $($(target)_LIBSUFF.$(bld_trg))\
[126]1078 $($(target)_LIBSUFF)\
[481]1079 $(TOOL_$(tool)_ARLIBSUFF.$(bld_trg).$(bld_trg_arch))\
[221]1080 $(TOOL_$(tool)_ARLIBSUFF.$(bld_trg))\
[126]1081 $(TOOL_$(tool)_ARLIBSUFF)\
[353]1082 $(SUFF_LIB))
1083out := $(outbase)$(suff)
1084TARGET_$(target) := $(out)
1085$(target)_OBJS_ := $(filter %.o %.obj, \
1086 $($(target)_SOURCES) \
1087 $($(target)_SOURCES.$(bld_trg)) \
1088 $($(target)_SOURCES.$(bld_trg_arch)) \
[481]1089 $($(target)_SOURCES.$(bld_trg).$(bld_trg_arch)) \
[353]1090 $($(target)_SOURCES.$(bld_trg_cpu)) \
1091 $($(target)_SOURCES.$(bld_type)))
[145]1092
[353]1093
[145]1094# source -> object
[353]1095$(eval $(value def_target_sources))
[145]1096
1097# library linking
[353]1098tool := $(call _TARGET_TOOL,$(target),AR)
1099outbase := $(call _TARGET_BASE,$(target),$(target))
1100flags :=\
[74]1101 $(TOOL_$(tool)_ARFLAGS)\
[221]1102 $(TOOL_$(tool)_ARFLAGS.$(bld_type))\
[74]1103 $(ARFLAGS)\
[221]1104 $(ARFLAGS.$(bld_type))\
[74]1105 $($(target)_ARFLAGS)\
[481]1106 $($(target)_ARFLAGS.$(bld_type)) \
1107 $($(target)_ARFLAGS.$(bld_trg)) \
1108 $($(target)_ARFLAGS.$(bld_trg_arch)) \
1109 $($(target)_ARFLAGS.$(bld_trg).$(bld_trg_arch)) \
1110 $($(target)_ARFLAGS.$(bld_trg_cpu))
[353]1111othersrc := $(filter-out %.c %.cpp %.cxx %.cc %.s %.S %.asm %.o %.obj,\
1112 $($(target)_SOURCES) \
1113 $($(target)_SOURCES.$(bld_trg)) \
1114 $($(target)_SOURCES.$(bld_trg_arch)) \
[481]1115 $($(target)_SOURCES.$(bld_trg).$(bld_trg_arch)) \
[353]1116 $($(target)_SOURCES.$(bld_trg_cpu)) \
1117 $($(target)_SOURCES.$(bld_type)))
1118objs = $($(target)_OBJS_)
1119dirdep := $(call DIRDEP,$(dir $(out)))
[78]1120## @todo fix dependencies on makefiles an such
[353]1121deps := $($(target)_DEPS)
[72]1122
[380]1123# dependency file
1124dep := $(out)$(SUFF_DEP)
[524]1125ifndef NO_LINK_CMDS_DEPS
[380]1126_DEPFILES_INCLUDED += $(dep)
1127$(if $(wildcard $(dep)),$(eval include $(dep)))
1128endif
[72]1129
[380]1130# check that the tool is defined.
1131ifndef TOOL_$(tool)_LINK_LIBRARY_CMDS
1132$(warning kBuild: tools: \
[481]1133 1 $($(target)_$(source)TOOL.$(bld_trg).$(bld_trg_arch)) \
1134 2 $($(target)_$(source)TOOL.$(bld_trg)) \
1135 3 $($(target)_$(source)TOOL) \
1136 4 $($(target)_TOOL.$(bld_trg).$(bld_trg_arch)) \
1137 5 $($(target)_TOOL.$(bld_trg)) \
1138 6 $($(target)_TOOL) \
1139 7 $($(source)TOOL) \
1140 8 $($(source)TOOL.$(bld_trg).$(bld_trg_arch)) \
1141 9 $($(source)TOOL.$(bld_trg)) \
1142 10 $(TOOL.$(bld_trg).$(bld_trg_arch)) \
1143 11 $(TOOL.$(bld_trg)) \
1144 12 $(TOOL) )
[380]1145$(error kBuild: TOOL_$(tool)_LINK_LIBRARY_CMDS isn't defined! target=$(target) )
1146endif
1147
1148# call the tool
1149$(target)_CMDS_ := $(TOOL_$(tool)_LINK_LIBRARY_CMDS)
1150$(target)_OUTPUT_ := $(TOOL_$(tool)_LINK_LIBRARY_OUTPUT)
1151$(target)_DEPEND_ := $(TOOL_$(tool)_LINK_LIBRARY_DEPEND) $(deps) $(objs)
1152$(target)_DEPORD_ := $(TOOL_$(tool)_LINK_LIBRARY_DEPORD) $(dirdep)
1153
[412]1154# generate the link rule.
[380]1155$(eval $(def_link_rule))
1156
[353]1157# installing and globals
1158definst := $(PATH_LIB)
[380]1159typevar := _LIBS
[353]1160$(eval $(value def_target_install_pluss))
[72]1161endef
1162
1163# Process libraries
[380]1164mode := 0644
[481]1165$(foreach target, $(LIBRARIES) $(LIBRARIES.$(BUILD_TARGET)) $(LIBRARIES.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)), $(eval $(value def_lib)))
[72]1166
1167
1168#
[353]1169# Link operations.
[72]1170#
1171
[353]1172##
1173# Link prolog
1174#
1175# @param $(target) Normalized target name.
1176# @param $(EXT) EXE,DLL,SYS.
1177# @param $(definst) The default _INST value.
1178# @param $(typevar) The name of the variable with all the root targets of its type.
[380]1179define def_link_common
[353]1180# basics
1181bld_type := $(firstword $($(target)_BLD_TYPE) $(BUILD_TYPE))
1182bld_trg := $(firstword $($(target)_BLD_TRG) $(BUILD_$(bld_trg_base_var)))
1183bld_trg_arch:= $(firstword $($(target)_BLD_TRG_ARCH) $(BUILD_$(bld_trg_base_var)_ARCH))
1184bld_trg_cpu := $(firstword $($(target)_BLD_TRG_CPU) $(BUILD_$(bld_trg_base_var)_CPU))
[145]1185
[353]1186tool := $(call _TARGET_TOOL,$(target),LD)
1187outbase := $(call _TARGET_BASE,$(target),$(target))
1188suff := $(firstword \
1189 $($(target)_$(EXT)SUFF) \
1190 $($(target)_$(EXT)SUFF) \
1191 $(TOOL_$(tool)_LD$(EXT)SUFF) \
1192 $($(EXTPRE)SUFF_$(EXT)))
1193out := $(outbase)$(suff)
1194PATH_$(target) := $(patsubst %/,%,$(dir $(outbase)))
1195TARGET_$(target) := $(out)
1196$(target)_OBJS_ := $(filter %.o %.obj, \
1197 $($(target)_SOURCES) \
1198 $($(target)_SOURCES.$(bld_trg)) \
1199 $($(target)_SOURCES.$(bld_trg_arch)) \
[481]1200 $($(target)_SOURCES.$(bld_trg).$(bld_trg_arch)) \
[353]1201 $($(target)_SOURCES.$(bld_trg_cpu)) \
1202 $($(target)_SOURCES.$(bld_type)))
1203
[145]1204# source -> object
[353]1205$(eval $(value def_target_sources))
[145]1206
[353]1207# more library stuff.
1208tool := $(call _TARGET_TOOL,$(target),LD)
1209outbase := $(call _TARGET_BASE,$(target),$(target))
1210flags :=\
[74]1211 $(TOOL_$(tool)_LDFLAGS)\
[221]1212 $(TOOL_$(tool)_LDFLAGS.$(bld_type))\
1213 $(TOOL_$(tool)_LDFLAGS.$(bld_trg))\
1214 $(TOOL_$(tool)_LDFLAGS.$(bld_trg_arch))\
[481]1215 $(TOOL_$(tool)_LDFLAGS.$(bld_trg).$(bld_trg_arch))\
[221]1216 $(TOOL_$(tool)_LDFLAGS.$(bld_trg_cpu))\
[74]1217 $(LDFLAGS)\
[221]1218 $(LDFLAGS.$(bld_type))\
1219 $(LDFLAGS.$(bld_trg))\
1220 $(LDFLAGS.$(bld_trg_arch))\
[481]1221 $(LDFLAGS.$(bld_trg).$(bld_trg_arch))\
[221]1222 $(LDFLAGS.$(bld_trg_cpu))\
[74]1223 $($(target)_LDFLAGS)\
[221]1224 $($(target)_LDFLAGS.$(bld_type))\
1225 $($(target)_LDFLAGS.$(bld_trg))\
1226 $($(target)_LDFLAGS.$(bld_trg_arch))\
[481]1227 $($(target)_LDFLAGS.$(bld_trg).$(bld_trg_arch))\
[353]1228 $($(target)_LDFLAGS.$(bld_trg_cpu))
1229othersrc := $(filter-out %.c %.cpp %.cxx %.cc %.s %.S %.asm %.o %.obj,\
1230 $($(target)_SOURCES)\
1231 $($(target)_SOURCES.$(bld_trg)) \
1232 $($(target)_SOURCES.$(bld_trg_arch)) \
[481]1233 $($(target)_SOURCES.$(bld_trg).$(bld_trg_arch)) \
[353]1234 $($(target)_SOURCES.$(bld_trg_cpu)) \
1235 $($(target)_SOURCES.$(bld_type)))
1236objs = $($(target)_OBJS_)
1237libs :=\
[221]1238 $($(target)_LIBS.$(bld_trg_cpu))\
[481]1239 $($(target)_LIBS.$(bld_trg).$(bld_trg_arch))\
[221]1240 $($(target)_LIBS.$(bld_trg_arch))\
1241 $($(target)_LIBS.$(bld_trg))\
1242 $($(target)_LIBS.$(bld_type))\
[74]1243 $($(target)_LIBS)\
[221]1244 $(foreach sdk, $($(target)_SDKS.$(bld_trg)) \
[481]1245 $($(target)_SDKS.$(bld_trg).$(bld_trg_arch)) \
[221]1246 $($(target)_SDKS.$(bld_type)) \
[122]1247 $($(target)_SDKS),\
[353]1248 $(SDK_$(sdk)_LIBS.$(bld_trg_cpu))\
[481]1249 $(SDK_$(sdk)_LIBS.$(bld_trg).$(bld_trg_arch))\
[353]1250 $(SDK_$(sdk)_LIBS.$(bld_trg_arch))\
1251 $(SDK_$(sdk)_LIBS.$(bld_trg))\
1252 $(SDK_$(sdk)_LIBS.$(bld_type))\
1253 $(SDK_$(sdk)_LIBS))\
[221]1254 $(LIBS.$(bld_trg_cpu))\
[481]1255 $(LIBS.$(bld_trg).$(bld_trg_arch))\
[221]1256 $(LIBS.$(bld_trg_arch))\
1257 $(LIBS.$(bld_trg))\
1258 $(LIBS.$(bld_type))\
[74]1259 $(LIBS)\
[221]1260 $(foreach sdk, $(SDKS.$(bld_trg)) \
[481]1261 $(SDKS.$(bld_trg).$(bld_trg_arch)) \
[221]1262 $(SDKS.$(bld_type)) \
[122]1263 $(SDKS),\
[353]1264 $(SDK_$(sdk)_LIBS.$(bld_trg_cpu))\
[481]1265 $(SDK_$(sdk)_LIBS.$(bld_trg).$(bld_trg_arch))\
[353]1266 $(SDK_$(sdk)_LIBS.$(bld_trg_arch))\
1267 $(SDK_$(sdk)_LIBS.$(bld_trg))\
1268 $(SDK_$(sdk)_LIBS.$(bld_type))\
1269 $(SDK_$(sdk)_LIBS))\
[221]1270 $(TOOL_$(tool)_LIBS.$(bld_trg_cpu))\
[481]1271 $(TOOL_$(tool)_LIBS.$(bld_trg).$(bld_trg_arch))\
[221]1272 $(TOOL_$(tool)_LIBS.$(bld_trg_arch))\
1273 $(TOOL_$(tool)_LIBS.$(bld_trg))\
1274 $(TOOL_$(tool)_LIBS.$(bld_type))\
[353]1275 $(TOOL_$(tool)_LIBS)
1276libpath :=\
[221]1277 $($(target)_LIBPATH.$(bld_trg_cpu))\
[481]1278 $($(target)_LIBPATH.$(bld_trg).$(bld_trg_arch))\
[221]1279 $($(target)_LIBPATH.$(bld_trg_arch))\
1280 $($(target)_LIBPATH.$(bld_trg))\
1281 $($(target)_LIBPATH.$(bld_type))\
[74]1282 $($(target)_LIBPATH)\
[221]1283 $(foreach sdk, $($(target)_SDKS.$(bld_trg)) \
[481]1284 $($(target)_SDKS.$(bld_trg).$(bld_trg_arch)) \
[221]1285 $($(target)_SDKS.$(bld_type)) \
[122]1286 $($(target)_SDKS),\
[353]1287 $(SDK_$(sdk)_LIBPATH.$(bld_trg_cpu))\
[481]1288 $(SDK_$(sdk)_LIBPATH.$(bld_trg).$(bld_trg_arch))\
[353]1289 $(SDK_$(sdk)_LIBPATH.$(bld_trg_arch))\
1290 $(SDK_$(sdk)_LIBPATH.$(bld_trg))\
1291 $(SDK_$(sdk)_LIBPATH.$(bld_type))\
1292 $(SDK_$(sdk)_LIBPATH))\
[221]1293 $(LIBPATH.$(bld_trg_cpu))\
[481]1294 $(LIBPATH.$(bld_trg).$(bld_trg_arch))\
[221]1295 $(LIBPATH.$(bld_trg_arch))\
1296 $(LIBPATH.$(bld_trg))\
1297 $(LIBPATH.$(bld_type))\
[74]1298 $(LIBPATH)\
[221]1299 $(foreach sdk, $(SDKS.$(bld_trg)) \
[481]1300 $(SDKS.$(bld_trg).$(bld_trg_arch)) \
[221]1301 $(SDKS.$(bld_type)) \
[122]1302 $(SDKS),\
[353]1303 $(SDK_$(sdk)_LIBPATH.$(bld_trg_cpu))\
[481]1304 $(SDK_$(sdk)_LIBPATH.$(bld_trg).$(bld_trg_arch))\
[353]1305 $(SDK_$(sdk)_LIBPATH.$(bld_trg_arch))\
1306 $(SDK_$(sdk)_LIBPATH.$(bld_trg))\
1307 $(SDK_$(sdk)_LIBPATH.$(bld_type))\
1308 $(SDK_$(sdk)_LIBPATH))\
[221]1309 $(TOOL_$(tool)_LIBPATH.$(bld_trg_cpu))\
[481]1310 $(TOOL_$(tool)_LIBPATH.$(bld_trg).$(bld_trg_arch))\
[221]1311 $(TOOL_$(tool)_LIBPATH.$(bld_trg_arch))\
1312 $(TOOL_$(tool)_LIBPATH.$(bld_trg))\
1313 $(TOOL_$(tool)_LIBPATH.$(bld_type))\
[353]1314 $(TOOL_$(tool)_LIBPATH)
1315dirdep := $(call DIRDEP,$(dir $(out)))
[74]1316## @todo fix dependencies
[353]1317deps := $($(target)_DEPS)
1318
1319## @todo this stuff can't be working.
1320custom_pre := $(strip $(firstword \
[481]1321 $($(target)_CUSTOM_PRE.$(bld_trg).$(bld_trg_arch))\
[221]1322 $($(target)_CUSTOM_PRE.$(bld_trg).$(bld_type))\
1323 $($(target)_CUSTOM_PRE.$(bld_trg))\
1324 $($(target)_CUSTOM_PRE.$(bld_type))\
[74]1325 $($(target)_CUSTOM_PRE)\
[481]1326 $(CUSTOM_PRE.$(bld_trg).$(bld_trg_arch))\
[221]1327 $(CUSTOM_PRE.$(bld_trg).$(bld_type))\
1328 $(CUSTOM_PRE.$(bld_trg))\
1329 $(CUSTOM_PRE.$(bld_type))\
[74]1330 $(CUSTOM_PRE)\
[353]1331))
1332custom_post := $(strip $(firstword \
[481]1333 $($(target)_CUSTOM_POST.$(bld_trg).$(bld_trg_arch))\
[221]1334 $($(target)_CUSTOM_POST.$(bld_trg).$(bld_type))\
1335 $($(target)_CUSTOM_POST.$(bld_trg))\
1336 $($(target)_CUSTOM_POST.$(bld_type))\
[74]1337 $($(target)_CUSTOM_POST)\
[481]1338 $(CUSTOM_POST.$(bld_trg).$(bld_trg_arch))\
[221]1339 $(CUSTOM_POST.$(bld_trg).$(bld_type))\
1340 $(CUSTOM_POST.$(bld_trg))\
1341 $(CUSTOM_POST.$(bld_type))\
[74]1342 $(CUSTOM_POST)\
[353]1343))
[72]1344
[353]1345# installation targets
1346ifndef $(target)_NOINST
1347INSTARGET_$(target) := $(patsubst %/,%/$(notdir $(out)), \
1348 $(if $($(target)_INST), $(addprefix $(PATH_INS)/,$($(target)_INST)), $(definst)/))
1349ifdef KBUILD_DO_AUTO_INSTALL
1350$(typevar) += $(INSTARGET_$(target))
1351else
1352$(typevar) += $(out)
1353endif
1354# generate the install rule
1355$(eval $(def_link_install_rule))
1356
1357else # NOINST
1358INSTARGET_$(target) :=
1359$(typevar) += $(out)
1360endif # NOINST
1361
[380]1362# dependency file
1363dep := $(outbase)$(SUFF_DEP)
[524]1364ifndef NO_LINK_CMDS_DEPS
[380]1365_DEPFILES_INCLUDED += $(dep)
1366$(if $(wildcard $(dep)),$(eval include $(dep)))
1367endif
[353]1368
[380]1369# check that the tool is defined.
1370ifndef TOOL_$(tool)_$(tool_do)_CMDS
1371$(warning kBuild: tools: \
[481]1372 1 $($(target)_$(source)TOOL.$(bld_trg).$(bld_trg_arch)) \
1373 2 $($(target)_$(source)TOOL.$(bld_trg)) \
1374 3 $($(target)_$(source)TOOL) \
1375 4 $($(target)_TOOL.$(bld_trg).$(bld_trg_arch)) \
1376 5 $($(target)_TOOL.$(bld_trg)) \
1377 6 $($(target)_TOOL) \
1378 7 $($(source)TOOL.$(bld_trg).$(bld_trg_arch)) \
1379 8 $($(source)TOOL.$(bld_trg)) \
1380 9 $($(source)TOOL) \
1381 10 $(TOOL.$(bld_trg).$(bld_trg_arch)) \
1382 11 $(TOOL.$(bld_trg)) \
1383 12 $(TOOL) )
[380]1384$(error kBuild: TOOL_$(tool)_$(tool_do)_CMDS isn't defined! target=$(target) )
1385endif
[353]1386
[380]1387# call the tool
1388$(target)_CMDS_ := $(TOOL_$(tool)_$(tool_do)_CMDS)
1389$(target)_OUTPUT_ := $(TOOL_$(tool)_$(tool_do)_OUTPUT)
1390$(target)_DEPEND_ := $(TOOL_$(tool)_$(tool_do)_DEPEND) $(deps) $(objs)
1391$(target)_DEPORD_ := $(TOOL_$(tool)_$(tool_do)_DEPORD) $(dirdep)
[353]1392
[412]1393# generate the link rule.
[380]1394$(eval $(def_link_rule))
1395
[412]1396
[380]1397# Update globals.
[579]1398_OBJS += $($(target)_OBJS_)
1399_OUT_FILES += $($(target)_OUTPUT_) $(out)
[353]1400_CLEAN_FILES += $($(target)_CLEAN)
[579]1401_INSTALLS += $(INSTARGET_$(target))
[353]1402
1403endef
1404
1405
1406#
1407# BLDPROGS
1408#
1409
1410## Build program (one).
1411# @param $(target) Normalized target (program) name.
1412define def_bldprog
1413
1414# set NOINST if not forced installation.
1415ifndef $(target)_INST
1416$(target)_NOINST := 1
1417endif
1418
[380]1419# do the usual stuff.
1420$(eval $(value def_link_common))
[353]1421
1422endef
1423
1424# Process build programs.
1425EXT := EXE
1426EXTPRE := HOST
[380]1427tool_do := LINK_PROGRAM
[353]1428definst := $(PATH_BIN)
1429typevar := _BLDPROGS
[380]1430mode := 0755
[353]1431bld_trg_base_var := PLATFORM
[481]1432$(foreach target, $(BLDPROGS) $(BLDPROGS.$(BUILD_PLATFORM)) $(BLDPROGS.$(BUILD_PLATFORM).$(BUILD_PLATFORM_ARCH)), $(eval $(value def_bldprog)))
[353]1433
1434
1435
1436#
1437# DLLS
1438#
1439
[189]1440# Process dlls
[353]1441EXT := DLL
1442EXTPRE :=
[380]1443tool_do := LINK_DLL
[353]1444definst := $(PATH_DLL)
1445typevar := _DLLS
[380]1446mode := 0755
[353]1447bld_trg_base_var := TARGET
[481]1448$(foreach target, $(DLLS) $(DLLS.$(BUILD_TARGET)) $(DLLS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)), $(eval $(value def_link_common)))
[74]1449
1450
[72]1451#
[189]1452# Process import libraries.
[72]1453#
[219]1454# - On OS/2 and windows these are libraries.
[189]1455# - On other platforms they are fake DLLs.
[481]1456ifeq ($(filter-out nt os2 win win64 win32,$(BUILD_TARGET)),)
1457$(foreach target, $(IMPORT_LIBS) $(IMPORT_LIBS.$(BUILD_TARGET)) $(IMPORT_LIBS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)), $(eval $(value def_lib)))
[189]1458else
[481]1459$(foreach target, $(IMPORT_LIBS) $(IMPORT_LIBS.$(BUILD_TARGET)) $(IMPORT_LIBS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)), $(eval $(value def_link_common)))
[189]1460endif
[481]1461$(foreach target, $(IMPORT_LIBS) $(IMPORT_LIBS.$(BUILD_TARGET)) $(IMPORT_LIBS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)), \
[353]1462 $(eval _IMPORT_LIBS += $(if $(INSTARGET_$(target)),$(INSTARGET_$(target)), $(TARGET_$(target)))))
[72]1463
[189]1464
1465#
1466# PROGRAMS
1467#
1468
[353]1469# Process programs
1470EXT := EXE
1471EXTPRE :=
[380]1472tool_do := LINK_PROGRAM
[353]1473definst := $(PATH_BIN)
1474typevar := _PROGRAMS
[380]1475mode := 0755
[353]1476bld_trg_base_var := TARGET
[481]1477$(foreach target, $(PROGRAMS) $(PROGRAMS.$(BUILD_TARGET)) $(PROGRAMS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)), $(eval $(value def_link_common)))
[130]1478
1479
[189]1480
[72]1481#
[83]1482# SYSMODS
[72]1483#
1484
[130]1485# Process sysmods
[353]1486EXT := SYS
1487EXTPRE :=
[380]1488tool_do := LINK_SYSMOD
[353]1489definst := $(PATH_SYS)
1490typevar := _SYSMODS
[380]1491mode := 0644
[353]1492bld_trg_base_var := TARGET
[481]1493$(foreach target, $(SYSMODS) $(SYSMODS.$(BUILD_TARGET)) $(SYSMODS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)), $(eval $(value def_link_common)))
[83]1494
1495
[72]1496#
1497# OTHERS
1498#
[481]1499_OTHERS = $(OTHERS) $(OTHERS.$(BUILD_TARGET)) $(OTHERS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH))
[72]1500
1501
[353]1502#
1503# INSTALLS
1504#
[72]1505
[353]1506## generate the install rule
1507define def_install_src_rule
1508# the install rule
1509$(insdst) : $(srcsrc) | $(call DIRDEP,$(dir $(insdst)))
[380]1510 $$(if $$(filter $(INSTALL),$(inscmd)),,$$(RM) -f $$@)
[353]1511 $(inscmd)
1512endef
1513
1514## install one file
1515define def_install_src
1516
1517# deal with '=>' in the source file name.
1518srcdst := $(subst =>, ,$(src))
1519srcsrc := $(firstword $(srcdst))
[424]1520srcdstdir := $(dir $(word 2,$(srcdst)))
[353]1521srcdst := $(word $(words $(srcdst)),$(srcdst))
1522
1523# _INSTFUN
1524ifdef $(srcsrc)_INSTFUN
1525instfun := $(srcsrc)_INSTFUN
1526else
1527ifdef $(target)_INSTFUN
1528instfun := $(target)_INSTFUN
1529else
1530instfun := _INSTALL_FILE
1531endif
1532endif
1533
1534# _INST
1535ifdef $(srcsrc)_INST
[424]1536inst := $(patsubst %/,%,$($(srcsrc)_INST))/$(dir $(srcdstdir))
[353]1537else
1538ifdef $(target)_INST
[424]1539inst := $(patsubst %/,%,$($(target)_INST))/$(dir $(srcdstdir))
[353]1540else
[424]1541inst := $(dir $(srcdstdir))
[353]1542endif
1543endif
1544
1545# calc target
[380]1546insdst := $(call $(instfun),$(srcdst),$(target),$(inst),$(PATH_INS))
[424]1547#$(warning instfun=$(instfun) srcdst=$(srcdst) target=$(target) inst=$(inst) => insdst=$(insdst))
[353]1548
[414]1549# mode, uid and gid
1550mode := $(firstword \
[481]1551 $($(target)_$(srcsrc)_MODE.$(bld_trg).$(bld_trg_arch)) \
[414]1552 $($(target)_$(srcsrc)_MODE.$(bld_trg)) \
1553 $($(target)_$(srcsrc)_MODE) \
[481]1554 $($(target)_$(srcdst)_MODE.$(bld_trg).$(bld_trg_arch)) \
[414]1555 $($(target)_$(srcdst)_MODE.$(bld_trg)) \
1556 $($(target)_$(srcdst)_MODE) \
[481]1557 $($(srcsrc)_MODE.$(bld_trg).$(bld_trg_arch)) \
[414]1558 $($(srcsrc)_MODE.$(bld_trg)) \
1559 $($(srcsrc)_MODE) \
[481]1560 $($(srcdst)_MODE.$(bld_trg).$(bld_trg_arch)) \
[414]1561 $($(srcdst)_MODE.$(bld_trg)) \
1562 $($(srcdst)_MODE) \
[481]1563 $($(target)_MODE.$(bld_trg).$(bld_trg_arch)) \
[414]1564 $($(target)_MODE.$(bld_trg)) \
1565 $($(target)_MODE))
1566uid := $(firstword \
[481]1567 $($(target)_$(srcsrc)_UID.$(bld_trg).$(bld_trg_arch)) \
[414]1568 $($(target)_$(srcsrc)_UID.$(bld_trg)) \
1569 $($(target)_$(srcsrc)_UID) \
[481]1570 $($(target)_$(srcdst)_UID.$(bld_trg).$(bld_trg_arch)) \
[414]1571 $($(target)_$(srcdst)_UID.$(bld_trg)) \
1572 $($(target)_$(srcdst)_UID) \
[481]1573 $($(srcsrc)_UID.$(bld_trg).$(bld_trg_arch)) \
[414]1574 $($(srcsrc)_UID.$(bld_trg)) \
1575 $($(srcsrc)_UID) \
[481]1576 $($(srcdst)_UID.$(bld_trg).$(bld_trg_arch)) \
[414]1577 $($(srcdst)_UID.$(bld_trg)) \
1578 $($(srcdst)_UID) \
[481]1579 $($(target)_UID.$(bld_trg).$(bld_trg_arch)) \
[414]1580 $($(target)_UID.$(bld_trg)) \
1581 $($(target)_UID))
1582gid := $(firstword \
[481]1583 $($(target)_$(srcsrc)_GID.$(bld_trg).$(bld_trg_arch)) \
[414]1584 $($(target)_$(srcsrc)_GID.$(bld_trg)) \
1585 $($(target)_$(srcsrc)_GID) \
[481]1586 $($(target)_$(srcdst)_GID.$(bld_trg).$(bld_trg_arch)) \
[414]1587 $($(target)_$(srcdst)_GID.$(bld_trg)) \
1588 $($(target)_$(srcdst)_GID) \
[481]1589 $($(srcsrc)_GID.$(bld_trg).$(bld_trg_arch)) \
[414]1590 $($(srcsrc)_GID.$(bld_trg)) \
1591 $($(srcsrc)_GID) \
[481]1592 $($(srcdst)_GID.$(bld_trg).$(bld_trg_arch)) \
[414]1593 $($(srcdst)_GID.$(bld_trg)) \
1594 $($(srcdst)_GID) \
[481]1595 $($(target)_GID.$(bld_trg).$(bld_trg_arch)) \
[414]1596 $($(target)_GID.$(bld_trg)) \
1597 $($(target)_GID))
1598
[353]1599# create the command
1600ifdef $(srcsrc)_INSTALLER
1601inscmd := $(call $(srcsrc)_INSTALLER,$(srcsrc),$(insdst),$(target))
1602else
1603ifdef $(target)_INSTALLER
1604inscmd := $(call $(target)_INSTALLER,$(srcsrc),$(insdst),$(target))
1605else
[414]1606inscmd := $$(INSTALL)\
1607 $(if $(uid),-o $(uid))\
1608 $(if $(gid),-g $(gid))\
1609 $(if $(mode),-m $(mode))\
1610 $(srcsrc) $(insdst)
[353]1611endif
1612endif
1613
1614# generate the rule (need double evaluation here)
1615$(eval $(def_install_src_rule))
1616
1617INSTARGET_$(target) += $(insdst)
1618endef
1619
1620
1621## generate the symlink rule
1622define def_install_symlink_rule
1623# the install rule
1624$(insdst) : | $(call DIRDEP,$(dir $(insdst)))
1625 $$(RM) -f $$@
[380]1626 $$(LN_SYMLINK) $(symdst) $(insdst)
[353]1627endef
1628
1629## create one symlink
1630define def_install_symlink
1631
1632# deal with '=>' in the source file name.
[380]1633symdst := $(subst =>, ,$(src))
1634symlnk := $(firstword $(symdst))
1635symdst := $(word $(words $(symdst)),$(symdst))
[353]1636
1637# _INSTFUN
[380]1638ifdef $(symlnk)_INSTFUN
1639instfun := $(symlnk)_INSTFUN
[353]1640else
1641ifdef $(target)_INSTFUN
1642instfun := $(target)_INSTFUN
1643else
1644instfun := _INSTALL_FILE
1645endif
1646endif
1647
1648# _INST
[380]1649ifdef $(symlnk)_INST
1650inst := $(patsubst %/,%,$($(symlnk)_INST))/$(dir $(symlnk))
[353]1651else
1652ifdef $(target)_INST
[380]1653inst := $(patsubst %/,%,$($(target)_INST))/$(dir $(symlnk))
[353]1654else
[380]1655inst := $(dir $(symlnk))
[353]1656endif
1657endif
1658
1659# calc target
[380]1660insdst := $(call $(instfun),$(symlnk),$(target),$(inst),$(PATH_INS))
1661#$(warning symlnk=$(symlnk) symdst=$(symdst) insdst=$(insdst) instfun=$(instfun) inst='$(inst)')
[353]1662
1663# generate the rule (need double evaluation here)
1664$(eval $(def_install_symlink_rule))
1665
1666INSTARGET_$(target) += $(insdst)
1667endef
1668
[412]1669
[380]1670## generate the install rule
1671define def_install_directory_rule
1672# the install rule
1673$(insdst):
1674 $(INSTALL) -d \
1675 $(if $(uid),-o $(uid))\
1676 $(if $(gid),-g $(gid))\
1677 $(if $(mode),-m $(mode))\
1678 $(insdst)
[412]1679
1680.NOTPARALLEL: $(insdst)
[380]1681endef
1682
[412]1683
[380]1684## create one directory
1685define def_install_directory
1686
1687# _INST
1688ifdef $(directory)_INST
1689inst := $(PATH_INS)/$(patsubst %/,%,$($(directory)_INST))
1690else
1691ifdef $(target)_INST
1692inst := $(PATH_INS)/$(patsubst %/,%,$($(target)_INST))
1693else
1694inst := $(PATH_INS)
1695endif
1696endif
1697
1698mode := $(firstword \
[481]1699 $($(target)_$(directory)_MODE.$(bld_trg).$(bld_trg_arch)) \
[380]1700 $($(target)_$(directory)_MODE.$(bld_trg)) \
1701 $($(target)_$(directory)_MODE) \
[481]1702 $($(directory)_MODE.$(bld_trg).$(bld_trg_arch)) \
[380]1703 $($(directory)_MODE.$(bld_trg)) \
1704 $($(directory)_MODE) \
[481]1705 $($(target)_MODE.$(bld_trg).$(bld_trg_arch)) \
[380]1706 $($(target)_MODE.$(bld_trg)) \
1707 $($(target)_MODE))
1708uid := $(firstword \
[481]1709 $($(target)_$(directory)_UID.$(bld_trg).$(bld_trg_arch)) \
[380]1710 $($(target)_$(directory)_UID.$(bld_trg)) \
1711 $($(target)_$(directory)_UID) \
[481]1712 $($(directory)_UID.$(bld_trg).$(bld_trg_arch)) \
[380]1713 $($(directory)_UID.$(bld_trg)) \
1714 $($(directory)_UID) \
[481]1715 $($(target)_UID.$(bld_trg).$(bld_trg_arch)) \
[380]1716 $($(target)_UID.$(bld_trg)) \
1717 $($(target)_UID))
1718gid := $(firstword \
[481]1719 $($(target)_$(directory)_GID.$(bld_trg).$(bld_trg_arch)) \
[380]1720 $($(target)_$(directory)_GID.$(bld_trg)) \
1721 $($(target)_$(directory)_GID) \
[481]1722 $($(directory)_GID.$(bld_trg).$(bld_trg_arch)) \
[380]1723 $($(directory)_GID.$(bld_trg)) \
1724 $($(directory)_GID) \
[481]1725 $($(target)_GID.$(bld_trg).$(bld_trg_arch)) \
[380]1726 $($(target)_GID.$(bld_trg)) \
1727 $($(target)_GID))
1728
1729insdst := $(inst)/$(directory)/
1730#$(warning directory=$(directory) inst=$(inst) insdst=$(insdst) mode=$(mode) gid=$(gid) uid=$(uid))
1731
1732# generate the rule (need double evaluation here)
1733$(eval $(def_install_directory_rule))
1734
1735INSTARGET_DIRS_$(target) += $(insdst)
1736endef
1737
1738
[353]1739## process one install target.
1740define def_install
1741bld_type := $(firstword $($(target)_BLD_TYPE) $(BUILD_TYPE))
1742bld_trg := $(firstword $($(target)_BLD_TRG) $(BUILD_TARGET))
1743bld_trg_arch:= $(firstword $($(target)_BLD_TRG_ARCH) $(BUILD_TARGET_ARCH))
1744bld_trg_cpu := $(firstword $($(target)_BLD_TRG_CPU) $(BUILD_TARGET_CPU))
1745
1746INSTARGET_$(target) :=
[380]1747INSTARGET_DIRS_$(target) :=
1748
[481]1749$(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]1750 $(eval $(value def_install_directory)))
1751
[481]1752$(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]1753 $(eval $(value def_install_src)))
1754
[481]1755$(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]1756 $(eval $(value def_install_symlink)))
1757
[380]1758_INSTALLS += $(INSTARGET_$(target)) $($(target)_GOALS)
1759_INSTALLS_DIRS += $(INSTARGET_DIRS_$(target))
[353]1760endef
1761
1762## process all install targets
[481]1763$(foreach target, $(INSTALLS) $(INSTALLS.$(BUILD_TARGET)) $(INSTALLS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)), \
[353]1764 $(eval $(value def_install)))
1765
1766
[72]1767#
[417]1768# PACKING
1769#
[481]1770_PACKING += $(PACKING) $(PACKING.$(BUILD_TARGET)) $(PACKING.$(BUILD_TARGET).$(BUILD_TARGET_ARCH))
[417]1771
1772
1773#
[72]1774# DOCS
1775#
1776
1777
1778#
[353]1779# DIRECTORIES
1780#
1781_DIR_ALL := $(sort $(addsuffix /,$(patsubst %/,%,$(_DIRS))) $(dir $(_OUT_FILES) $(_OBJS) $(_INSTALLS)))
[380]1782$(foreach directory,$(_INSTALLS_DIRS), $(eval _DIR_ALL := $(filter-out $(directory),$(_DIR_ALL))))
[353]1783
[380]1784
[353]1785define def_mkdir_rule
1786$(directory):
1787 $(call MSG_L1,Creating directory $$@)
1788 $(MKDIR) -p $$@
[72]1789endef
1790
[353]1791$(foreach directory,$(_DIR_ALL),$(eval $(def_mkdir_rule)))
[72]1792
[183]1793
[72]1794#
[353]1795# NOTHING
[72]1796#
[353]1797do-nothing:
1798 $(call MSG_L1,Did nothing in $(CURDIR))
[72]1799
[183]1800
[75]1801#
[353]1802# CLEAN UP
[75]1803#
[353]1804do-clean:
[380]1805 $(RM) -f $(_OUT_FILES) $(_OBJS) $(_DEPFILES) $(_DEPFILES_INCLUDED) $(_CLEAN_FILES) $(OTHER_CLEAN)
[72]1806
[98]1807
[353]1808#
1809# PASSES (including directory and makefile walking)
1810#
[221]1811
[75]1812## Subdir
1813# @param $(pass) Lowercase pass name.
1814# @param $(PASS) Uppercase pass name.
1815# @param $(subdir) Subdirectory
1816# @param $(tag) tag to attach to the rule name.
1817define def_pass_subdir
[219]1818pass_$(pass)$(tag):: $(dep)
1819 + $(QUIET)$$(MAKE) -C $(subdir) -f $$(notdir $$(firstword $$(wildcard $$(addprefix $(subdir)/,$$(DEFAULT_MAKEFILE))))) pass_$(pass)
[75]1820endef
[72]1821
[75]1822## Submakefile
1823# @param $(pass) Lowercase pass name.
1824# @param $(PASS) Uppercase pass name.
1825# @param $(makefile) Makefile.
1826# @param $(tag) tag to attach to the rule name.
1827define def_pass_makefile
[219]1828pass_$(pass)$(tag):: $(dep)
1829 + $(QUIET)$$(MAKE) -C $(patsubst %/,%,$(dir $(makefile))) -f $(notdir $(makefile)) pass_$(pass)
[75]1830endef
[73]1831
[75]1832## Execute a pass.
1833# @param $(pass) Lowercase pass name.
1834# @param $(PASS) Uppercase pass name.
[353]1835define def_pass_old
[481]1836$(eval SUBDIRS_$(PASS) ?= $(SUBDIRS) $(SUBDIRS.$(BUILD_TARGET)) $(SUBDIRS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) )
1837$(eval SUBDIRS_AFTER_$(PASS) ?= $(SUBDIRS_AFTER) $(SUBDIRS_AFTER.$(BUILD_TARGET)) $(SUBDIRS_AFTER.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) )
1838$(eval MAKEFILES_BEFORE_$(PASS) ?= $(MAKEFILES_BEFORE) $(MAKEFILES_BEFORE.$(BUILD_TARGET)) $(MAKEFILES_BEFORE.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) )
1839$(eval MAKEFILES_AFTER_$(PASS) ?= $(MAKEFILES_AFTER) $(MAKEFILES_AFTER.$(BUILD_TARGET)) $(MAKEFILES_AFTER.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) )
[75]1840
1841$(eval tag:=_before)
[219]1842$(eval dep:=)
[481]1843$(foreach subdir,$(SUBDIRS_$(PASS)) $(SUBDIRS_$(PASS).$(BUILD_TARGET)) $(SUBDIRS_$(PASS).$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) ,$(eval $(def_pass_subdir)))
1844$(foreach makefile,$(MAKEFILES_BEFORE_$(PASS)) $(MAKEFILES_BEFORE_$(PASS).$(BUILD_TARGET)) $(MAKEFILES_BEFORE_$(PASS).$(BUILD_TARGET).$(BUILD_TARGET_ARCH)),$(eval $(def_pass_makefile)))
[75]1845
1846$(eval tag:=_after)
[219]1847$(eval dep:=pass_$(pass)_doit)
[481]1848$(foreach subdir,$(SUBDIRS_AFTER_$(PASS)) $(SUBDIRS_AFTER_$(PASS).$(BUILD_TARGET)) $(SUBDIRS_AFTER_$(PASS).$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) ,$(eval $(def_pass_subdir)))
1849$(foreach makefile,$(MAKEFILES_AFTER_$(PASS)) $(MAKEFILES_AFTER_$(PASS).$(BUILD_TARGET)) $(MAKEFILES_AFTER_$(PASS).$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) ,$(eval $(def_pass_makefile)))
[75]1850
1851.NOTPARALLEL: pass_$(pass)_before pass_$(pass)_after
1852.PHONY: pass_$(pass) pass_$(pass)_before pass_$(pass)_doit pass_$(pass)_after
[353]1853pass_$(pass)_doit: $(PASS_$(PASS)_trgs) $(foreach var,$(PASS_$(PASS)_vars),$(var))
[272]1854pass_$(pass)_this: pass_$(pass)_before
[220]1855 + $(QUIET)$$(MAKE) -f $$(MAKEFILE) pass_$(pass)_doit
1856pass_$(pass)_after:: pass_$(pass)_this
[219]1857pass_$(pass): pass_$(pass)_after
[75]1858
[183]1859endef
1860
[353]1861define def_pass
[481]1862$(eval SUBDIRS_$(PASS) ?= $(SUBDIRS) $(SUBDIRS.$(BUILD_TARGET)) $(SUBDIRS.$(BUILD_TARGET.$(BUILD_TARGET_ARCH))) )
1863$(eval SUBDIRS_AFTER_$(PASS) ?= $(SUBDIRS_AFTER) $(SUBDIRS_AFTER.$(BUILD_TARGET)) $(SUBDIRS_AFTER.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) )
1864$(eval MAKEFILES_BEFORE_$(PASS) ?= $(MAKEFILES_BEFORE) $(MAKEFILES_BEFORE.$(BUILD_TARGET)) $(MAKEFILES_BEFORE.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) )
1865$(eval MAKEFILES_AFTER_$(PASS) ?= $(MAKEFILES_AFTER) $(MAKEFILES_AFTER.$(BUILD_TARGET)) $(MAKEFILES_AFTER.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) )
[183]1866
[353]1867$(eval tag:=_before)
1868$(eval dep:=)
[481]1869$(foreach subdir,$(SUBDIRS_$(PASS)) $(SUBDIRS_$(PASS).$(BUILD_TARGET)) $(SUBDIRS_$(PASS).$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) ,$(eval $(def_pass_subdir)))
1870$(foreach makefile,$(MAKEFILES_BEFORE_$(PASS)) $(MAKEFILES_BEFORE_$(PASS).$(BUILD_TARGET)) $(MAKEFILES_BEFORE_$(PASS).$(BUILD_TARGET).$(BUILD_TARGET_ARCH)),$(eval $(def_pass_makefile)))
[75]1871
[353]1872$(eval tag:=_after)
1873$(eval dep:=pass_$(pass)_doit)
[481]1874$(foreach subdir,$(SUBDIRS_AFTER_$(PASS)) $(SUBDIRS_AFTER_$(PASS).$(BUILD_TARGET)) $(SUBDIRS_AFTER_$(PASS).$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) ,$(eval $(def_pass_subdir)))
1875$(foreach makefile,$(MAKEFILES_AFTER_$(PASS)) $(MAKEFILES_AFTER_$(PASS).$(BUILD_TARGET)) $(MAKEFILES_AFTER_$(PASS).$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) ,$(eval $(def_pass_makefile)))
[75]1876
[380]1877ifdef KBUILD_SAFE_PARALLEL
[353]1878.NOTPARALLEL: pass_$(pass) pass_$(pass)_before pass_$(pass)_after pass_$(pass)_this
1879.PHONY: pass_$(pass) pass_$(pass)_before pass_$(pass)_after pass_$(pass)_this pass_$(pass)_doit
1880pass_$(pass)_doit: $(PASS_$(PASS)_trgs) $(foreach var,$(PASS_$(PASS)_vars),$(var))
1881pass_$(pass)_this: pass_$(pass)_before
1882 + $(QUIET)$$(MAKE) -f $$(MAKEFILE) pass_$(pass)_doit
1883pass_$(pass)_after:: pass_$(pass)_this
1884pass_$(pass): pass_$(pass)_after
1885else
[388]1886.NOTPARALLEL: pass_$(pass) pass_$(pass)_before pass_$(pass)_after pass_$(pass)_doit
[353]1887.PHONY: pass_$(pass) pass_$(pass)_before pass_$(pass)_after pass_$(pass)_doit
1888pass_$(pass)_doit: pass_$(pass)_before \
1889 $(PASS_$(PASS)_trgs) $(foreach var,$(PASS_$(PASS)_vars),$($(var)))
1890pass_$(pass): \
1891 pass_$(pass)_before \
1892 pass_$(pass)_doit \
[388]1893 pass_$(pass)_after
[353]1894endif
[189]1895
[353]1896#$ (warning pass=$(pass) PASS=$(PASS): $(PASS_$(PASS)_trgs) $(PASS_$(PASS)_trgs) $(foreach var,$(PASS_$(PASS)_vars),$($(var))))
1897endef
[75]1898
[353]1899# Generate the defined passes.
1900$(foreach PASS, $(PASSES), \
1901 $(eval pass := $(PASS_$(PASS)_pass)) \
1902 $(eval $(def_pass)))
[75]1903
[219]1904## Pass order
1905# @param $(pass) Current pass name.
1906# @param $(prev_pass) The previous pass name.
1907define def_pass_order
[380]1908ifdef KBUILD_SAFE_PARALLEL
[353]1909.NOTPARALLEL: pass_$(pass)_order
1910.PHONY: pass_$(pass)_order
[219]1911pass_$(pass)_order: $(pass_prev)
[353]1912 $(call MSG_L1,Pass - $(if $(PASS_$(PASS)),$(PASS_$(PASS)),$(pass)))
[219]1913 + $(QUIET)$$(MAKE) -f $$(MAKEFILE) pass_$(pass)
[353]1914else
1915.NOTPARALLEL: pass_$(pass)_order pass_$(pass)_banner
[388]1916.PHONY: pass_$(pass)_order pass_$(pass)_banner
[353]1917pass_$(pass)_banner:
1918 $(call MSG_L1,Pass - $(if $(PASS_$(PASS)),$(PASS_$(PASS)),$(pass)))
1919pass_$(pass)_order: \
1920 $(pass_prev) \
1921 pass_$(pass)_banner \
1922 pass_$(pass)
1923endif
[219]1924$(eval pass_prev := pass_$(pass)_order)
1925endef
[183]1926
[219]1927## PASS: order
1928# Use dependencies to ensure correct pass order.
1929pass_prev :=
[353]1930$(foreach PASS,$(DEFAULT_PASSES),\
1931 $(eval pass := $(PASS_$(PASS)_pass)) \
1932 $(eval $(def_pass_order)))
[219]1933
[272]1934
[75]1935#
1936# THE MAIN RULES
1937#
[219]1938all_recursive: $(pass_prev)
[75]1939
[130]1940rebuild: clean
[219]1941 + $(MAKE) -f $(firstword $(MAKEFILE_LIST)) all_recursive
[78]1942
[412]1943# @todo make this a non-default pass!
[353]1944uninstall:
1945 $(RM) -f $(_INSTALLS)
[412]1946
[380]1947install: pass_installs
[78]1948
[75]1949# misc shortcuts.
[380]1950targets: bldprogs libraries dlls programs sysmods others installs
[75]1951objects: $(_OBJS)
[222]1952bldprogs: $(_BLDPROGS)
[189]1953libraries: $(_LIBS) $(_IMPORT_LIBS) $(_OTHER_LIBRARIES)
[205]1954dlls: $(_DLLS)
[219]1955programs: $(_PROGRAMS)
[205]1956sysmods: $(_SYSMODS)
[353]1957others: $(_OTHERS)
[380]1958installs: $(_INSTALLS_DIRS) $(_INSTALLS)
[75]1959
1960
[353]1961#
1962# kBuild debugging stuff.
1963#
1964_SPACE := $(subst ., ,.)
1965_TAB := $(subst ., ,.)
1966define _NEWLINE
1967
1968
1969endef
1970NLTAB = $(_NEWLINE)$(TAB)
1971show_targets:
1972 @$(foreach target, $(ALL_TARGETS),\
1973 @$(ECHO) "target: $(target)" $(NLTAB)\
1974 @$(ECHO) " PATH_$(target)=$(PATH_$(target))" $(NLTAB)\
1975 @$(ECHO) " TARGET_$(target)=$(TARGET_$(target))" $(NLTAB)\
1976 @$(ECHO) " INSTARGET_$(target)=$(INSTARGET_$(target))" $(NLTAB)\
[380]1977$(foreach prop,$(PROPS_SINGLE) $(PROPS_ACCUMULATE) OBJS_ CLEAN, \
[353]1978 $(eval _tmp:=$(firstword $($(target)_BLD_TRG) $(BUILD_TARGET))) \
1979 $(if $($(target)_$(prop).$(_tmp)),\
1980 @$(ECHO) " $(target)_$(prop).$(_tmp)=$($(target)_$(prop).$(_tmp))" $(NLTAB)) \
1981 $(if $($(target)_$(prop)), $(NLTAB)@$(ECHO) " $(target)_$(prop)=$($(target)_$(prop))" $(NLTAB)) \
1982)\
1983$(foreach prop,$(PROPS_DEFERRED), \
1984 $(eval _tmp:=$(firstword $($(target)_BLD_TRG) $(BUILD_TARGET))) \
1985 $(if $(value $(target)_$(prop).$(_tmp)),\
1986 @$(ECHO) ' $(target)_$(prop).$(_tmp)=$(value $(TARGET)_$(prop).$(_tmp))' $(NLTAB)) \
1987 $(if $(value $(target)_$(prop)), $(NLTAB)@$(ECHO) ' $(target)_$(prop)=$(value $(target)_$(prop))' $(NLTAB)) \
1988))
1989
1990
1991
1992#
1993# Include dependency files.
1994#
1995$(foreach dep,$(wildcard $(_DEPFILES)),$(eval include $(dep)))
1996
1997
[72]1998# end-of-file-content
[106]1999__footer_kmk__ := target
[72]2000endif # __footer_kmk__
[438]2001
Note: See TracBrowser for help on using the repository browser.