source: trunk/kBuild/footer.kmk@ 585

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

use comp-vars

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 69.1 KB
RevLine 
[72]1# $Id: footer.kmk 581 2006-11-23 13:44:46Z 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
[581]561 ifneq ($(filter comp-vars,$(KMK_FEATURES)),)
562_DEP_LINK_CMDS = $(comp-vars $(target)_CMDS_PREV_,$(target)_CMDS_,FORCE)
563 else
[380]564_DEP_LINK_CMDS = $(if $(subst $(strip $($(target)_CMDS_PREV_)),,$(strip $($(target)_CMDS_))),FORCE,)
[581]565 endif
[380]566else
567_DEP_LINK_CMDS =
568endif
569
570## Generate the link rule for a target.
571# @param $(target) The normalized target name.
572# @param $(dirdep) Directories we depend upon begin created before linking.
573# @param $(dep) The name of the dependency file.
574# @param $(out)
575# @param $($(target)_OUTPUT_) Output files from the link.
576# @param $($(target)_DEPEND_) Dependencies.
577# @param $($(target)_DEPORD_) Dependencies which should only affect build order.
578# @param $($(target)_CMDS_) The link commands.
579# @param $($(target)_CMDS_PREV_) The link commands from the previous run.
580define def_link_rule
581$(out) $($(target)_OUTPUT_): \
582 $($(target)_DEPEND_) \
583 $(_DEP_LINK_CMDS) \
584 | \
585 $($(target)_DEPORD_)
586 $(call MSG_L1,Creating $$@)
[473]587 $(RM) -f $(dep) $(out) $($(target)_OUTPUT_)
[380]588 $(custom_pre)
[412]589
[380]590$($(target)_CMDS_)
591
592 $(custom_post)
[524]593ifndef NO_LINK_CMDS_DEPS
[380]594 @$(APPEND) "$(dep)" 'define $(target)_CMDS_PREV_'
595 @$(APPEND) "$(dep)" '$(subst $(NL),'$(NL)$(TAB)@$(APPEND) "$(dep)" ',$($(target)_CMDS_))'
596 @$(APPEND) "$(dep)" 'endef'
[412]597endif
[380]598
599$(basename $(notdir $(out)))::
[442]600 + $$(MAKE) -f $$(MAKEFILE) $(out)
[380]601endef
602
603
604## Generate the link & lib install rule
605# @param $(target) Normalized target name.
606# @param $(out) The build target.
607# @param $(INSTARGET_$(target)) The installation targets.
608# @param $(mode) The file mode (optional)
609define def_link_install_rule
610$(INSTARGET_$(target)) : $(out) | $(call DIRDEP,$(dir $(INSTARGET_$(target))))
611 $(INSTALL) $$(if $(mode),-m $(mode)) $(out) $$@
612endef
613
614
615
[73]616## Generic macro for processing C, C++ and Assembly sources.
617# @param $(target) Normalized target name.
618# @param $(source) Source file name.
619# @param $(type) Source type. {C,CXX,AS}
[221]620# @param bld_type Build type.
621# @param bld_trg Build target.
622# @param bld_trg_arch Build target arch.
623# @param bld_trg_cpu Build target cpu.
[552]624# @remark obsoleted by kBuild helpers in kmk. Only required for gmake compatbility.
[72]625#
[530]626define def_target_source_c_cpp_asm_old
[105]627#$ (warning dbg: def_target_source_c_cpp_asm: source='$(source)' target='$(target)' type='$(type)')
[73]628
[353]629tool := $(call _SOURCE_TOOL,$(source),$(target),$(type))
630outbase := $(call _OBJECT_BASE,$(source),$(target))
631PATH_$(target)_$(source) := $(patsubst %/,%,$(dir $(outbase)))
632dirdep := $(call DIRDEP,$(dir $(outbase)))
633defs :=\
[78]634 $(TOOL_$(tool)_DEFS)\
[221]635 $(TOOL_$(tool)_DEFS.$(bld_type))\
636 $(TOOL_$(tool)_DEFS.$(bld_trg))\
637 $(TOOL_$(tool)_DEFS.$(bld_trg_arch))\
[481]638 $(TOOL_$(tool)_DEFS.$(bld_trg).$(bld_trg_arch))\
[221]639 $(TOOL_$(tool)_DEFS.$(bld_trg_cpu))\
[74]640 $(TOOL_$(tool)_$(type)DEFS)\
[221]641 $(TOOL_$(tool)_$(type)DEFS.$(bld_type))\
642 $(foreach sdk, $(SDKS.$(bld_trg)) \
[481]643 $(SDKS.$(bld_trg).$(bld_trg_arch)) \
[221]644 $(SDKS.$(bld_type)) \
[78]645 $(SDKS),\
[353]646 $(SDK_$(sdk)_DEFS)\
647 $(SDK_$(sdk)_DEFS.$(bld_type))\
648 $(SDK_$(sdk)_DEFS.$(bld_trg))\
649 $(SDK_$(sdk)_DEFS.$(bld_trg_arch))\
[481]650 $(SDK_$(sdk)_DEFS.$(bld_trg).$(bld_trg_arch))\
[353]651 $(SDK_$(sdk)_DEFS.$(bld_trg_cpu))\
652 $(SDK_$(sdk)_$(type)DEFS)\
653 $(SDK_$(sdk)_$(type)DEFS.$(bld_type))\
654 $(SDK_$(sdk)_$(type)DEFS.$(bld_trg))\
655 $(SDK_$(sdk)_$(type)DEFS.$(bld_trg_arch))\
[481]656 $(SDK_$(sdk)_$(type)DEFS.$(bld_trg).$(bld_trg_arch))\
[353]657 $(SDK_$(sdk)_$(type)DEFS.$(bld_trg_cpu)))\
[74]658 $(DEFS)\
[221]659 $(DEFS.$(bld_type))\
660 $(DEFS.$(bld_trg))\
661 $(DEFS.$(bld_trg_arch))\
[481]662 $(DEFS.$(bld_trg).$(bld_trg_arch))\
[221]663 $(DEFS.$(bld_trg_cpu))\
[78]664 $($(type)DEFS)\
[221]665 $($(type)DEFS.$(bld_type))\
666 $($(type)DEFS.$(bld_trg))\
667 $($(type)DEFS.$(bld_trg_arch))\
[481]668 $($(type)DEFS.$(bld_trg).$(bld_trg_arch))\
[221]669 $($(type)DEFS.$(bld_trg_cpu))\
670 $(foreach sdk, $($(target)_SDKS.$(bld_trg)) \
[481]671 $($(target)_SDKS.$(bld_trg).$(bld_trg_arch)) \
[221]672 $($(target)_SDKS.$(bld_type)) \
[78]673 $($(target)_SDKS),\
[353]674 $(SDK_$(sdk)_DEFS)\
675 $(SDK_$(sdk)_DEFS.$(bld_type))\
676 $(SDK_$(sdk)_DEFS.$(bld_trg))\
677 $(SDK_$(sdk)_DEFS.$(bld_trg_arch))\
[481]678 $(SDK_$(sdk)_DEFS.$(bld_trg).$(bld_trg_arch))\
[353]679 $(SDK_$(sdk)_DEFS.$(bld_trg_cpu))\
680 $(SDK_$(sdk)_$(type)DEFS)\
681 $(SDK_$(sdk)_$(type)DEFS.$(bld_type))\
682 $(SDK_$(sdk)_$(type)DEFS.$(bld_trg))\
683 $(SDK_$(sdk)_$(type)DEFS.$(bld_trg_arch))\
[481]684 $(SDK_$(sdk)_$(type)DEFS.$(bld_trg).$(bld_trg_arch))\
[353]685 $(SDK_$(sdk)_$(type)DEFS.$(bld_trg_cpu)))\
[74]686 $($(target)_DEFS)\
[221]687 $($(target)_DEFS.$(bld_type))\
688 $($(target)_DEFS.$(bld_trg))\
689 $($(target)_DEFS.$(bld_trg_arch))\
[481]690 $($(target)_DEFS.$(bld_trg).$(bld_trg_arch))\
[221]691 $($(target)_DEFS.$(bld_trg_cpu))\
[78]692 $($(target)_$(type)DEFS)\
[221]693 $($(target)_$(type)DEFS.$(bld_type))\
694 $($(target)_$(type)DEFS.$(bld_trg))\
695 $($(target)_$(type)DEFS.$(bld_trg_arch))\
[481]696 $($(target)_$(type)DEFS.$(bld_trg).$(bld_trg_arch))\
[221]697 $($(target)_$(type)DEFS.$(bld_trg_cpu))\
698 $(foreach sdk, $($(source)_SDKS.$(bld_trg)) \
[481]699 $($(source)_SDKS.$(bld_trg).$(bld_trg_arch)) \
[221]700 $($(source)_SDKS.$(bld_type)) \
[78]701 $($(source)_SDKS),\
[353]702 $(SDK_$(sdk)_DEFS)\
703 $(SDK_$(sdk)_DEFS.$(bld_type))\
704 $(SDK_$(sdk)_DEFS.$(bld_trg))\
705 $(SDK_$(sdk)_DEFS.$(bld_trg_arch))\
[481]706 $(SDK_$(sdk)_DEFS.$(bld_trg).$(bld_trg_arch))\
[353]707 $(SDK_$(sdk)_DEFS.$(bld_trg_cpu))\
708 $(SDK_$(sdk)_$(type)DEFS)\
709 $(SDK_$(sdk)_$(type)DEFS.$(bld_type))\
710 $(SDK_$(sdk)_$(type)DEFS.$(bld_trg))\
711 $(SDK_$(sdk)_$(type)DEFS.$(bld_trg_arch))\
[481]712 $(SDK_$(sdk)_$(type)DEFS.$(bld_trg).$(bld_trg_arch))\
[353]713 $(SDK_$(sdk)_$(type)DEFS.$(bld_trg_cpu)))\
[74]714 $($(source)_DEFS)\
[221]715 $($(source)_DEFS.$(bld_type))\
716 $($(source)_DEFS.$(bld_trg))\
717 $($(source)_DEFS.$(bld_trg_arch))\
[481]718 $($(source)_DEFS.$(bld_trg).$(bld_trg_arch))\
[221]719 $($(source)_DEFS.$(bld_trg_cpu))\
[73]720 $($(source)_$(type)DEFS)\
[221]721 $($(source)_$(type)DEFS.$(bld_type))\
722 $($(source)_$(type)DEFS.$(bld_trg))\
723 $($(source)_$(type)DEFS.$(bld_trg_arch))\
[481]724 $($(source)_$(type)DEFS.$(bld_trg).$(bld_trg_arch))\
[221]725 $($(source)_$(type)DEFS.$(bld_trg_cpu))\
726 $(foreach sdk, $($(target)_$(source)_SDKS.$(bld_trg)) \
[481]727 $($(target)_$(source)_SDKS.$(bld_trg).$(bld_trg_arch)) \
[221]728 $($(target)_$(source)_SDKS.$(bld_type)) \
[78]729 $($(target)_$(source)_SDKS),\
[353]730 $(SDK_$(sdk)_DEFS)\
731 $(SDK_$(sdk)_DEFS.$(bld_type))\
732 $(SDK_$(sdk)_DEFS.$(bld_trg))\
733 $(SDK_$(sdk)_DEFS.$(bld_trg_arch))\
[481]734 $(SDK_$(sdk)_DEFS.$(bld_trg).$(bld_trg_arch))\
[353]735 $(SDK_$(sdk)_DEFS.$(bld_trg_cpu))\
736 $(SDK_$(sdk)_$(type)DEFS)\
737 $(SDK_$(sdk)_$(type)DEFS.$(bld_type))\
738 $(SDK_$(sdk)_$(type)DEFS.$(bld_trg))\
739 $(SDK_$(sdk)_$(type)DEFS.$(bld_trg_arch))\
[481]740 $(SDK_$(sdk)_$(type)DEFS.$(bld_trg).$(bld_trg_arch))\
[353]741 $(SDK_$(sdk)_$(type)DEFS.$(bld_trg_cpu)))\
[74]742 $($(target)_$(source)_DEFS)\
[221]743 $($(target)_$(source)_DEFS.$(bld_type))\
744 $($(target)_$(source)_DEFS.$(bld_trg))\
745 $($(target)_$(source)_DEFS.$(bld_trg_arch))\
[481]746 $($(target)_$(source)_DEFS.$(bld_trg).$(bld_trg_arch))\
[221]747 $($(target)_$(source)_DEFS.$(bld_trg_cpu))\
[74]748 $($(target)_$(source)_$(type)DEFS)\
[221]749 $($(target)_$(source)_$(type)DEFS.$(bld_type))\
750 $($(target)_$(source)_$(type)DEFS.$(bld_trg))\
751 $($(target)_$(source)_$(type)DEFS.$(bld_trg_arch))\
[481]752 $($(target)_$(source)_$(type)DEFS.$(bld_trg).$(bld_trg_arch))\
[353]753 $($(target)_$(source)_$(type)DEFS.$(bld_trg_cpu))
754incs :=\
[221]755 $($(target)_$(source)_$(type)INCS.$(bld_trg_cpu))\
[481]756 $($(target)_$(source)_$(type)INCS.$(bld_trg).$(bld_trg_arch))\
[221]757 $($(target)_$(source)_$(type)INCS.$(bld_trg_arch))\
758 $($(target)_$(source)_$(type)INCS.$(bld_trg))\
759 $($(target)_$(source)_$(type)INCS.$(bld_type))\
[73]760 $($(target)_$(source)_$(type)INCS)\
[221]761 $($(target)_$(source)_INCS.$(bld_trg_cpu))\
[481]762 $($(target)_$(source)_INCS.$(bld_trg).$(bld_trg_arch))\
[221]763 $($(target)_$(source)_INCS.$(bld_trg_arch))\
764 $($(target)_$(source)_INCS.$(bld_trg))\
765 $($(target)_$(source)_INCS.$(bld_type))\
[73]766 $($(target)_$(source)_INCS)\
[221]767 $(foreach sdk, $($(target)_$(source)_SDKS.$(bld_trg)) \
[481]768 $($(target)_$(source)_SDKS.$(bld_trg).$(bld_trg_arch)) \
[221]769 $($(target)_$(source)_SDKS.$(bld_type)) \
[133]770 $($(target)_$(source)_SDKS),\
[353]771 $(SDK_$(sdk)_$(type)INCS.$(bld_trg_cpu))\
[481]772 $(SDK_$(sdk)_$(type)INCS.$(bld_trg).$(bld_trg_arch))\
[353]773 $(SDK_$(sdk)_$(type)INCS.$(bld_trg_arch))\
774 $(SDK_$(sdk)_$(type)INCS.$(bld_trg))\
775 $(SDK_$(sdk)_$(type)INCS.$(bld_type))\
776 $(SDK_$(sdk)_$(type)INCS)\
777 $(SDK_$(sdk)_INCS.$(bld_trg_cpu))\
[481]778 $(SDK_$(sdk)_INCS.$(bld_trg).$(bld_trg_arch))\
[353]779 $(SDK_$(sdk)_INCS.$(bld_trg_arch))\
780 $(SDK_$(sdk)_INCS.$(bld_trg))\
781 $(SDK_$(sdk)_INCS.$(bld_type))\
782 $(SDK_$(sdk)_INCS))\
[221]783 $($(source)_$(type)INCS.$(bld_trg_cpu))\
[481]784 $($(source)_$(type)INCS.$(bld_trg).$(bld_trg_arch))\
[221]785 $($(source)_$(type)INCS.$(bld_trg_arch))\
786 $($(source)_$(type)INCS.$(bld_trg))\
787 $($(source)_$(type)INCS.$(bld_type))\
[73]788 $($(source)_$(type)INCS)\
[221]789 $($(source)_INCS.$(bld_trg_cpu))\
[481]790 $($(source)_INCS.$(bld_trg).$(bld_trg_arch))\
[221]791 $($(source)_INCS.$(bld_trg_arch))\
792 $($(source)_INCS.$(bld_trg))\
793 $($(source)_INCS.$(bld_type))\
[73]794 $($(source)_INCS)\
[221]795 $(foreach sdk, $($(source)_SDKS.$(bld_trg)) \
[481]796 $($(source)_SDKS.$(bld_trg).$(bld_trg_arch)) \
[221]797 $($(source)_SDKS.$(bld_type)) \
[78]798 $($(source)_SDKS),\
[353]799 $(SDK_$(sdk)_$(type)INCS.$(bld_trg_cpu))\
[481]800 $(SDK_$(sdk)_$(type)INCS.$(bld_trg).$(bld_trg_arch))\
[353]801 $(SDK_$(sdk)_$(type)INCS.$(bld_trg_arch))\
802 $(SDK_$(sdk)_$(type)INCS.$(bld_trg))\
803 $(SDK_$(sdk)_$(type)INCS.$(bld_type))\
804 $(SDK_$(sdk)_$(type)INCS)\
805 $(SDK_$(sdk)_INCS.$(bld_trg_cpu))\
[481]806 $(SDK_$(sdk)_INCS.$(bld_trg).$(bld_trg_arch))\
[353]807 $(SDK_$(sdk)_INCS.$(bld_trg_arch))\
808 $(SDK_$(sdk)_INCS.$(bld_trg))\
809 $(SDK_$(sdk)_INCS.$(bld_type))\
810 $(SDK_$(sdk)_INCS))\
[221]811 $($(target)_$(type)INCS.$(bld_trg_cpu))\
[481]812 $($(target)_$(type)INCS.$(bld_trg).$(bld_trg_arch))\
[221]813 $($(target)_$(type)INCS.$(bld_trg_arch))\
814 $($(target)_$(type)INCS.$(bld_trg))\
815 $($(target)_$(type)INCS.$(bld_type))\
[73]816 $($(target)_$(type)INCS)\
[221]817 $($(target)_INCS.$(bld_trg_cpu))\
[481]818 $($(target)_INCS.$(bld_trg).$(bld_trg_arch))\
[221]819 $($(target)_INCS.$(bld_trg_arch))\
820 $($(target)_INCS.$(bld_trg))\
821 $($(target)_INCS.$(bld_type))\
[73]822 $($(target)_INCS)\
[221]823 $(foreach sdk, $($(target)_SDKS.$(bld_trg)) \
[481]824 $($(target)_SDKS.$(bld_trg).$(bld_trg_arch)) \
[221]825 $($(target)_SDKS.$(bld_type)) \
[78]826 $($(target)_SDKS),\
[353]827 $(SDK_$(sdk)_$(type)INCS.$(bld_trg_cpu))\
[481]828 $(SDK_$(sdk)_$(type)INCS.$(bld_trg).$(bld_trg_arch))\
[353]829 $(SDK_$(sdk)_$(type)INCS.$(bld_trg_arch))\
830 $(SDK_$(sdk)_$(type)INCS.$(bld_trg))\
831 $(SDK_$(sdk)_$(type)INCS.$(bld_type))\
832 $(SDK_$(sdk)_$(type)INCS)\
833 $(SDK_$(sdk)_INCS.$(bld_trg_cpu))\
[481]834 $(SDK_$(sdk)_INCS.$(bld_trg).$(bld_trg_arch))\
[353]835 $(SDK_$(sdk)_INCS.$(bld_trg_arch))\
836 $(SDK_$(sdk)_INCS.$(bld_trg))\
837 $(SDK_$(sdk)_INCS.$(bld_type))\
838 $(SDK_$(sdk)_INCS))\
[221]839 $(INCS.$(bld_trg_cpu))\
[481]840 $(INCS.$(bld_trg).$(bld_trg_arch))\
[221]841 $(INCS.$(bld_trg_arch))\
842 $(INCS.$(bld_trg))\
843 $(INCS.$(bld_type))\
[73]844 $(INCS)\
[221]845 $(foreach sdk, $(SDKS.$(bld_trg)) \
[481]846 $(SDKS.$(bld_trg).$(bld_trg_arch)) \
[221]847 $(SDKS.$(bld_type)) \
[78]848 $(SDKS),\
[353]849 $(SDK_$(sdk)_$(type)INCS.$(bld_trg_cpu))\
[481]850 $(SDK_$(sdk)_$(type)INCS.$(bld_trg).$(bld_trg_arch))\
[353]851 $(SDK_$(sdk)_$(type)INCS.$(bld_trg_arch))\
852 $(SDK_$(sdk)_$(type)INCS.$(bld_trg))\
853 $(SDK_$(sdk)_$(type)INCS.$(bld_type))\
854 $(SDK_$(sdk)_$(type)INCS)\
855 $(SDK_$(sdk)_INCS.$(bld_trg_cpu))\
[481]856 $(SDK_$(sdk)_INCS.$(bld_trg).$(bld_trg_arch))\
[353]857 $(SDK_$(sdk)_INCS.$(bld_trg_arch))\
858 $(SDK_$(sdk)_INCS.$(bld_trg))\
859 $(SDK_$(sdk)_INCS.$(bld_type))\
860 $(SDK_$(sdk)_INCS))\
[221]861 $(TOOL_$(tool)_$(type)INCS.$(bld_trg_cpu))\
[481]862 $(TOOL_$(tool)_$(type)INCS.$(bld_trg).$(bld_trg_arch))\
[221]863 $(TOOL_$(tool)_$(type)INCS.$(bld_trg_arch))\
864 $(TOOL_$(tool)_$(type)INCS.$(bld_trg))\
865 $(TOOL_$(tool)_$(type)INCS.$(bld_type))\
[353]866 $(TOOL_$(tool)_$(type)INCS)
867flags :=\
[73]868 $(TOOL_$(tool)_$(type)FLAGS)\
[221]869 $(TOOL_$(tool)_$(type)FLAGS.$(bld_type))\
870 $(TOOL_$(tool)_$(type)FLAGS.$(bld_trg))\
871 $(TOOL_$(tool)_$(type)FLAGS.$(bld_trg_arch))\
[481]872 $(TOOL_$(tool)_$(type)FLAGS.$(bld_trg).$(bld_trg_arch))\
[221]873 $(TOOL_$(tool)_$(type)FLAGS.$(bld_trg_cpu))\
[73]874 $($(type)FLAGS)\
[221]875 $($(type)FLAGS.$(bld_type))\
876 $($(type)FLAGS.$(bld_trg))\
877 $($(type)FLAGS.$(bld_trg_arch))\
[481]878 $($(type)FLAGS.$(bld_trg).$(bld_trg_arch))\
[221]879 $($(type)FLAGS.$(bld_trg_cpu))\
[73]880 $($(target)_$(type)FLAGS)\
[221]881 $($(target)_$(type)FLAGS.$(bld_type))\
882 $($(target)_$(type)FLAGS.$(bld_trg))\
883 $($(target)_$(type)FLAGS.$(bld_trg_arch))\
[481]884 $($(target)_$(type)FLAGS.$(bld_trg).$(bld_trg_arch))\
[221]885 $($(target)_$(type)FLAGS.$(bld_trg_cpu))\
[73]886 $($(source)_$(type)FLAGS)\
[221]887 $($(source)_$(type)FLAGS.$(bld_type))\
888 $($(source)_$(type)FLAGS.$(bld_trg))\
889 $($(source)_$(type)FLAGS.$(bld_trg_arch))\
[481]890 $($(source)_$(type)FLAGS.$(bld_trg).$(bld_trg_arch))\
[221]891 $($(source)_$(type)FLAGS.$(bld_trg_cpu))\
[73]892 $($(target)_$(source)_$(type)FLAGS)\
[221]893 $($(target)_$(source)_$(type)FLAGS.$(bld_type))\
894 $($(target)_$(source)_$(type)FLAGS.$(bld_trg))\
895 $($(target)_$(source)_$(type)FLAGS.$(bld_trg_arch))\
[481]896 $($(target)_$(source)_$(type)FLAGS.$(bld_trg).$(bld_trg_arch))\
[353]897 $($(target)_$(source)_$(type)FLAGS.$(bld_trg_cpu))
[552]898# this isn't 100% in sync with kBuild, but it doesn't matter as it's only for gmake now.
[353]899objsuff := $(firstword \
[481]900 $($(target)_$(source)_OBJSUFF.$(bld_trg).$(bld_trg_arch))\
[221]901 $($(target)_$(source)_OBJSUFF.$(bld_trg))\
[74]902 $($(target)_$(source)_OBJSUFF)\
[481]903 $($(source)_OBJSUFF.$(bld_trg).$(bld_trg_arch))\
[221]904 $($(source)_OBJSUFF.$(bld_trg))\
[74]905 $($(source)_OBJSUFF)\
[481]906 $($(target)_OBJSUFF.$(bld_trg).$(bld_trg_arch))\
[221]907 $($(target)_OBJSUFF.$(bld_trg))\
[74]908 $($(target)_OBJSUFF)\
[481]909 $(TOOL_$(tool)_$(type)OBJSUFF.$(bld_trg).$(bld_trg_arch))\
[221]910 $(TOOL_$(tool)_$(type)OBJSUFF.$(bld_trg))\
[74]911 $(TOOL_$(tool)_$(type)OBJSUFF)\
[353]912 $(SUFF_OBJ))
913obj := $(outbase)$(objsuff)
914deps := \
[184]915 $($(target)_$(source)_DEPS)\
[353]916 $($(target)_$(source)_DEPS.$(bld_type))\
917 $($(target)_$(source)_DEPS.$(bld_trg))\
918 $($(target)_$(source)_DEPS.$(bld_trg_arch))\
[481]919 $($(target)_$(source)_DEPS.$(bld_trg).$(bld_trg_arch))\
[353]920 $($(target)_$(source)_DEPS.$(bld_trg_cpu))\
[184]921 $($(source)_DEPS)\
[221]922 $($(source)_DEPS.$(bld_type))\
923 $($(source)_DEPS.$(bld_trg))\
[353]924 $($(source)_DEPS.$(bld_trg_arch))\
[481]925 $($(source)_DEPS.$(bld_trg).$(bld_trg_arch))\
[353]926 $($(source)_DEPS.$(bld_trg_cpu))\
[184]927 $($(target)_DEPS)\
[353]928 $($(target)_DEPS.$(bld_type))\
[481]929 $($(target)_DEPS.$(bld_trg))\
[221]930 $($(target)_DEPS.$(bld_trg_arch))\
[481]931 $($(target)_DEPS.$(bld_trg).$(bld_trg_arch))\
[353]932 $($(target)_DEPS.$(bld_trg_cpu))
[73]933
[380]934# dependencies
935dep := $(obj)$(SUFF_DEP)
[524]936ifndef NO_COMPILE_CMDS_DEPS
[380]937_DEPFILES_INCLUDED += $(dep)
938$(if $(wildcard $(dep)),$(eval include $(dep)))
939endif
[184]940
941#$ (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]942ifndef TOOL_$(tool)_COMPILE_$(type)_CMDS
[353]943$(warning kBuild: tools: \
[481]944 1 $($(target)_$(source)_$(type)TOOL.$(bld_trg).$(bld_trg_arch)) \
945 2 $($(target)_$(source)_$(type)TOOL.$(bld_trg)) \
946 3 $($(target)_$(source)_$(type)TOOL) \
947 4 $($(target)_$(source)_TOOL.$(bld_trg).$(bld_trg_arch)) \
948 5 $($(target)_$(source)_TOOL.$(bld_trg)) \
949 6 $($(target)_$(source)_TOOL) \
950 7 $($(target)_$(type)TOOL.$(bld_trg).$(bld_trg_arch)) \
951 8 $($(target)_$(type)TOOL.$(bld_trg)) \
952 9 $($(target)_$(type)TOOL) \
953 10 $($(target)_TOOL.$(bld_trg).$(bld_trg_arch)) \
954 11 $($(target)_TOOL.$(bld_trg)) \
955 12 $($(target)_TOOL) \
956 13 $($(source)_$(type)TOOL.$(bld_trg).$(bld_trg_arch)) \
957 14 $($(source)_$(type)TOOL.$(bld_trg)) \
958 15 $($(source)_$(type)TOOL) \
959 16 $($(source)_TOOL.$(bld_trg).$(bld_trg_arch)) \
960 17 $($(source)_TOOL.$(bld_trg)) \
961 18 $($(source)_TOOL) \
962 19 $($(type)TOOL.$(bld_trg).$(bld_trg_arch)) \
963 20 $($(type)TOOL.$(bld_trg)) \
964 21 $($(type)TOOL) \
965 22 $(TOOL.$(bld_trg).$(bld_trg_arch)) \
966 23 $(TOOL.$(bld_trg)) \
967 24 $(TOOL) )
[380]968$(error kBuild: TOOL_$(tool)_COMPILE_$(type)_CMDS is not defined. source=$(source) target=$(target) )
[97]969endif
[353]970
[380]971# call the tool
972$(target)_$(source)_CMDS_ := $(TOOL_$(tool)_COMPILE_$(type)_CMDS)
973$(target)_$(source)_OUTPUT_ := $(TOOL_$(tool)_COMPILE_$(type)_OUTPUT)
974$(target)_$(source)_DEPEND_ := $(TOOL_$(tool)_COMPILE_$(type)_DEPEND) $(deps) $(source)
975$(target)_$(source)_DEPORD_ := $(TOOL_$(tool)_COMPILE_$(type)_DEPORD) $(dirdep)
[73]976
[380]977# generate the compile rule.
978$(eval $(def_target_source_rule))
[205]979
[380]980_OUT_FILES += $($(target)_$(source)_OUTPUT_)
[353]981$(target)_OBJS_ += $(obj)
[73]982
983endef
984
[530]985## Generic macro for processing C, C++ and Assembly sources.
986# @param $(target) Normalized target name.
987# @param $(source) Source file name.
988# @param $(type) Source type. {C,CXX,AS}
989# @param bld_type Build type.
990# @param bld_trg Build target.
991# @param bld_trg_arch Build target arch.
992# @param bld_trg_cpu Build target cpu.
993#
994#$ (warning dbg: def_target_source_c_cpp_asm: source='$(source)' target='$(target)' type='$(type)')
995def_target_source_c_cpp_asm_new = $(kb-src-one x)
996
[552]997ifneq ($(filter kb-src-one,$(KMK_FEATURES)),)
[530]998def_target_source_c_cpp_asm_var = def_target_source_c_cpp_asm_new
999else
1000def_target_source_c_cpp_asm_var = def_target_source_c_cpp_asm_old
1001endif
1002
[73]1003## Generic macro for processing all target sources.
[74]1004# @param $(target) Normalized target name.
[73]1005define def_target_sources
1006#$ (warning def_target_sources)
1007# C sources
[353]1008type := C
[481]1009$(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]1010 ,$(eval $(value $(def_target_source_c_cpp_asm_var))) )
[73]1011
1012# C++ sources
[353]1013type := CXX
[481]1014$(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]1015 ,$(eval $(value $(def_target_source_c_cpp_asm_var))) )
[73]1016
1017# ASM sources
[353]1018type := AS
[481]1019$(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]1020 ,$(eval $(value $(def_target_source_c_cpp_asm_var))) )
[353]1021
[73]1022endef
1023
1024
[219]1025
[353]1026## Generic macro for generating the install rule(s) for a target
1027# and update the globals with default out.
[219]1028#
[353]1029# @param $(target) Normalized target name.
1030# @param $(out) The output file.
1031# @param $(definst) The default _INST value.
1032# @param $(typevar) The name of the variable with all the root targets of its type.
1033# @obsolete
1034define def_target_install_pluss
1035ifndef $(target)_NOINST
1036INSTARGET_$(target) := $(patsubst %/,%/$(notdir $(out)), \
1037 $(if $($(target)_INST), $(addprefix $(PATH_INS)/,$($(target)_INST)), $(definst)/))
[219]1038
[353]1039$(eval $(def_link_install_rule))
[239]1040
[579]1041_INSTALLS += $(INSTARGET_$(target))
[272]1042
[353]1043ifdef KBUILD_DO_AUTO_INSTALL
[579]1044$(typevar) += $(INSTARGET_$(target))
[219]1045else
[579]1046$(typevar) += $(out)
[219]1047endif
[353]1048else # _NOINST
[579]1049$(typevar) += $(out)
[353]1050endif
1051
[579]1052_OUT_FILES += $($(target)_OUTPUT_)
[353]1053_CLEAN_FILES += $($(target)_CLEAN)
1054_OBJS += $($(target)_OBJS_)
1055
[219]1056endef
1057
1058
1059
1060#
[72]1061# LIBRARIES
[73]1062#
[72]1063
1064## Library (one).
[74]1065# @param $(target) Normalized library (target) name.
[72]1066define def_lib
[145]1067# library basics
[222]1068## @todo prefix
[353]1069bld_type := $(firstword $($(target)_BLD_TYPE) $(BUILD_TYPE))
1070bld_trg := $(firstword $($(target)_BLD_TRG) $(BUILD_TARGET))
1071bld_trg_arch:= $(firstword $($(target)_BLD_TRG_ARCH) $(BUILD_TARGET_ARCH))
1072bld_trg_cpu := $(firstword $($(target)_BLD_TRG_CPU) $(BUILD_TARGET_CPU))
1073tool := $(call _TARGET_TOOL,$(target),AR)
[78]1074ifeq ($(tool),)
[353]1075$(error kBuild: Library target $(target) does not have a tool defined!)
[78]1076endif
[353]1077outbase := $(call _TARGET_BASE,$(target),$(target))
1078PATH_$(target) := $(patsubst %/,%,$(dir $(outbase)))
1079suff := $(firstword\
[481]1080 $($(target)_LIBSUFF.$(bld_trg).$(bld_trg_arch))\
[221]1081 $($(target)_LIBSUFF.$(bld_trg))\
[126]1082 $($(target)_LIBSUFF)\
[481]1083 $(TOOL_$(tool)_ARLIBSUFF.$(bld_trg).$(bld_trg_arch))\
[221]1084 $(TOOL_$(tool)_ARLIBSUFF.$(bld_trg))\
[126]1085 $(TOOL_$(tool)_ARLIBSUFF)\
[353]1086 $(SUFF_LIB))
1087out := $(outbase)$(suff)
1088TARGET_$(target) := $(out)
1089$(target)_OBJS_ := $(filter %.o %.obj, \
1090 $($(target)_SOURCES) \
1091 $($(target)_SOURCES.$(bld_trg)) \
1092 $($(target)_SOURCES.$(bld_trg_arch)) \
[481]1093 $($(target)_SOURCES.$(bld_trg).$(bld_trg_arch)) \
[353]1094 $($(target)_SOURCES.$(bld_trg_cpu)) \
1095 $($(target)_SOURCES.$(bld_type)))
[145]1096
1097# source -> object
[353]1098$(eval $(value def_target_sources))
[145]1099
1100# library linking
[353]1101tool := $(call _TARGET_TOOL,$(target),AR)
1102outbase := $(call _TARGET_BASE,$(target),$(target))
1103flags :=\
[74]1104 $(TOOL_$(tool)_ARFLAGS)\
[221]1105 $(TOOL_$(tool)_ARFLAGS.$(bld_type))\
[74]1106 $(ARFLAGS)\
[221]1107 $(ARFLAGS.$(bld_type))\
[74]1108 $($(target)_ARFLAGS)\
[481]1109 $($(target)_ARFLAGS.$(bld_type)) \
1110 $($(target)_ARFLAGS.$(bld_trg)) \
1111 $($(target)_ARFLAGS.$(bld_trg_arch)) \
1112 $($(target)_ARFLAGS.$(bld_trg).$(bld_trg_arch)) \
1113 $($(target)_ARFLAGS.$(bld_trg_cpu))
[353]1114othersrc := $(filter-out %.c %.cpp %.cxx %.cc %.s %.S %.asm %.o %.obj,\
1115 $($(target)_SOURCES) \
1116 $($(target)_SOURCES.$(bld_trg)) \
1117 $($(target)_SOURCES.$(bld_trg_arch)) \
[481]1118 $($(target)_SOURCES.$(bld_trg).$(bld_trg_arch)) \
[353]1119 $($(target)_SOURCES.$(bld_trg_cpu)) \
1120 $($(target)_SOURCES.$(bld_type)))
1121objs = $($(target)_OBJS_)
1122dirdep := $(call DIRDEP,$(dir $(out)))
[78]1123## @todo fix dependencies on makefiles an such
[353]1124deps := $($(target)_DEPS)
[72]1125
[380]1126# dependency file
1127dep := $(out)$(SUFF_DEP)
[524]1128ifndef NO_LINK_CMDS_DEPS
[380]1129_DEPFILES_INCLUDED += $(dep)
1130$(if $(wildcard $(dep)),$(eval include $(dep)))
1131endif
[72]1132
[380]1133# check that the tool is defined.
1134ifndef TOOL_$(tool)_LINK_LIBRARY_CMDS
1135$(warning kBuild: tools: \
[481]1136 1 $($(target)_$(source)TOOL.$(bld_trg).$(bld_trg_arch)) \
1137 2 $($(target)_$(source)TOOL.$(bld_trg)) \
1138 3 $($(target)_$(source)TOOL) \
1139 4 $($(target)_TOOL.$(bld_trg).$(bld_trg_arch)) \
1140 5 $($(target)_TOOL.$(bld_trg)) \
1141 6 $($(target)_TOOL) \
1142 7 $($(source)TOOL) \
1143 8 $($(source)TOOL.$(bld_trg).$(bld_trg_arch)) \
1144 9 $($(source)TOOL.$(bld_trg)) \
1145 10 $(TOOL.$(bld_trg).$(bld_trg_arch)) \
1146 11 $(TOOL.$(bld_trg)) \
1147 12 $(TOOL) )
[380]1148$(error kBuild: TOOL_$(tool)_LINK_LIBRARY_CMDS isn't defined! target=$(target) )
1149endif
1150
1151# call the tool
1152$(target)_CMDS_ := $(TOOL_$(tool)_LINK_LIBRARY_CMDS)
1153$(target)_OUTPUT_ := $(TOOL_$(tool)_LINK_LIBRARY_OUTPUT)
1154$(target)_DEPEND_ := $(TOOL_$(tool)_LINK_LIBRARY_DEPEND) $(deps) $(objs)
1155$(target)_DEPORD_ := $(TOOL_$(tool)_LINK_LIBRARY_DEPORD) $(dirdep)
1156
[412]1157# generate the link rule.
[380]1158$(eval $(def_link_rule))
1159
[353]1160# installing and globals
1161definst := $(PATH_LIB)
[380]1162typevar := _LIBS
[353]1163$(eval $(value def_target_install_pluss))
[72]1164endef
1165
1166# Process libraries
[380]1167mode := 0644
[481]1168$(foreach target, $(LIBRARIES) $(LIBRARIES.$(BUILD_TARGET)) $(LIBRARIES.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)), $(eval $(value def_lib)))
[72]1169
1170
1171#
[353]1172# Link operations.
[72]1173#
1174
[353]1175##
1176# Link prolog
1177#
1178# @param $(target) Normalized target name.
1179# @param $(EXT) EXE,DLL,SYS.
1180# @param $(definst) The default _INST value.
1181# @param $(typevar) The name of the variable with all the root targets of its type.
[380]1182define def_link_common
[353]1183# basics
1184bld_type := $(firstword $($(target)_BLD_TYPE) $(BUILD_TYPE))
1185bld_trg := $(firstword $($(target)_BLD_TRG) $(BUILD_$(bld_trg_base_var)))
1186bld_trg_arch:= $(firstword $($(target)_BLD_TRG_ARCH) $(BUILD_$(bld_trg_base_var)_ARCH))
1187bld_trg_cpu := $(firstword $($(target)_BLD_TRG_CPU) $(BUILD_$(bld_trg_base_var)_CPU))
[145]1188
[353]1189tool := $(call _TARGET_TOOL,$(target),LD)
1190outbase := $(call _TARGET_BASE,$(target),$(target))
1191suff := $(firstword \
1192 $($(target)_$(EXT)SUFF) \
1193 $($(target)_$(EXT)SUFF) \
1194 $(TOOL_$(tool)_LD$(EXT)SUFF) \
1195 $($(EXTPRE)SUFF_$(EXT)))
1196out := $(outbase)$(suff)
1197PATH_$(target) := $(patsubst %/,%,$(dir $(outbase)))
1198TARGET_$(target) := $(out)
1199$(target)_OBJS_ := $(filter %.o %.obj, \
1200 $($(target)_SOURCES) \
1201 $($(target)_SOURCES.$(bld_trg)) \
1202 $($(target)_SOURCES.$(bld_trg_arch)) \
[481]1203 $($(target)_SOURCES.$(bld_trg).$(bld_trg_arch)) \
[353]1204 $($(target)_SOURCES.$(bld_trg_cpu)) \
1205 $($(target)_SOURCES.$(bld_type)))
1206
[145]1207# source -> object
[353]1208$(eval $(value def_target_sources))
[145]1209
[353]1210# more library stuff.
1211tool := $(call _TARGET_TOOL,$(target),LD)
1212outbase := $(call _TARGET_BASE,$(target),$(target))
1213flags :=\
[74]1214 $(TOOL_$(tool)_LDFLAGS)\
[221]1215 $(TOOL_$(tool)_LDFLAGS.$(bld_type))\
1216 $(TOOL_$(tool)_LDFLAGS.$(bld_trg))\
1217 $(TOOL_$(tool)_LDFLAGS.$(bld_trg_arch))\
[481]1218 $(TOOL_$(tool)_LDFLAGS.$(bld_trg).$(bld_trg_arch))\
[221]1219 $(TOOL_$(tool)_LDFLAGS.$(bld_trg_cpu))\
[74]1220 $(LDFLAGS)\
[221]1221 $(LDFLAGS.$(bld_type))\
1222 $(LDFLAGS.$(bld_trg))\
1223 $(LDFLAGS.$(bld_trg_arch))\
[481]1224 $(LDFLAGS.$(bld_trg).$(bld_trg_arch))\
[221]1225 $(LDFLAGS.$(bld_trg_cpu))\
[74]1226 $($(target)_LDFLAGS)\
[221]1227 $($(target)_LDFLAGS.$(bld_type))\
1228 $($(target)_LDFLAGS.$(bld_trg))\
1229 $($(target)_LDFLAGS.$(bld_trg_arch))\
[481]1230 $($(target)_LDFLAGS.$(bld_trg).$(bld_trg_arch))\
[353]1231 $($(target)_LDFLAGS.$(bld_trg_cpu))
1232othersrc := $(filter-out %.c %.cpp %.cxx %.cc %.s %.S %.asm %.o %.obj,\
1233 $($(target)_SOURCES)\
1234 $($(target)_SOURCES.$(bld_trg)) \
1235 $($(target)_SOURCES.$(bld_trg_arch)) \
[481]1236 $($(target)_SOURCES.$(bld_trg).$(bld_trg_arch)) \
[353]1237 $($(target)_SOURCES.$(bld_trg_cpu)) \
1238 $($(target)_SOURCES.$(bld_type)))
1239objs = $($(target)_OBJS_)
1240libs :=\
[221]1241 $($(target)_LIBS.$(bld_trg_cpu))\
[481]1242 $($(target)_LIBS.$(bld_trg).$(bld_trg_arch))\
[221]1243 $($(target)_LIBS.$(bld_trg_arch))\
1244 $($(target)_LIBS.$(bld_trg))\
1245 $($(target)_LIBS.$(bld_type))\
[74]1246 $($(target)_LIBS)\
[221]1247 $(foreach sdk, $($(target)_SDKS.$(bld_trg)) \
[481]1248 $($(target)_SDKS.$(bld_trg).$(bld_trg_arch)) \
[221]1249 $($(target)_SDKS.$(bld_type)) \
[122]1250 $($(target)_SDKS),\
[353]1251 $(SDK_$(sdk)_LIBS.$(bld_trg_cpu))\
[481]1252 $(SDK_$(sdk)_LIBS.$(bld_trg).$(bld_trg_arch))\
[353]1253 $(SDK_$(sdk)_LIBS.$(bld_trg_arch))\
1254 $(SDK_$(sdk)_LIBS.$(bld_trg))\
1255 $(SDK_$(sdk)_LIBS.$(bld_type))\
1256 $(SDK_$(sdk)_LIBS))\
[221]1257 $(LIBS.$(bld_trg_cpu))\
[481]1258 $(LIBS.$(bld_trg).$(bld_trg_arch))\
[221]1259 $(LIBS.$(bld_trg_arch))\
1260 $(LIBS.$(bld_trg))\
1261 $(LIBS.$(bld_type))\
[74]1262 $(LIBS)\
[221]1263 $(foreach sdk, $(SDKS.$(bld_trg)) \
[481]1264 $(SDKS.$(bld_trg).$(bld_trg_arch)) \
[221]1265 $(SDKS.$(bld_type)) \
[122]1266 $(SDKS),\
[353]1267 $(SDK_$(sdk)_LIBS.$(bld_trg_cpu))\
[481]1268 $(SDK_$(sdk)_LIBS.$(bld_trg).$(bld_trg_arch))\
[353]1269 $(SDK_$(sdk)_LIBS.$(bld_trg_arch))\
1270 $(SDK_$(sdk)_LIBS.$(bld_trg))\
1271 $(SDK_$(sdk)_LIBS.$(bld_type))\
1272 $(SDK_$(sdk)_LIBS))\
[221]1273 $(TOOL_$(tool)_LIBS.$(bld_trg_cpu))\
[481]1274 $(TOOL_$(tool)_LIBS.$(bld_trg).$(bld_trg_arch))\
[221]1275 $(TOOL_$(tool)_LIBS.$(bld_trg_arch))\
1276 $(TOOL_$(tool)_LIBS.$(bld_trg))\
1277 $(TOOL_$(tool)_LIBS.$(bld_type))\
[353]1278 $(TOOL_$(tool)_LIBS)
1279libpath :=\
[221]1280 $($(target)_LIBPATH.$(bld_trg_cpu))\
[481]1281 $($(target)_LIBPATH.$(bld_trg).$(bld_trg_arch))\
[221]1282 $($(target)_LIBPATH.$(bld_trg_arch))\
1283 $($(target)_LIBPATH.$(bld_trg))\
1284 $($(target)_LIBPATH.$(bld_type))\
[74]1285 $($(target)_LIBPATH)\
[221]1286 $(foreach sdk, $($(target)_SDKS.$(bld_trg)) \
[481]1287 $($(target)_SDKS.$(bld_trg).$(bld_trg_arch)) \
[221]1288 $($(target)_SDKS.$(bld_type)) \
[122]1289 $($(target)_SDKS),\
[353]1290 $(SDK_$(sdk)_LIBPATH.$(bld_trg_cpu))\
[481]1291 $(SDK_$(sdk)_LIBPATH.$(bld_trg).$(bld_trg_arch))\
[353]1292 $(SDK_$(sdk)_LIBPATH.$(bld_trg_arch))\
1293 $(SDK_$(sdk)_LIBPATH.$(bld_trg))\
1294 $(SDK_$(sdk)_LIBPATH.$(bld_type))\
1295 $(SDK_$(sdk)_LIBPATH))\
[221]1296 $(LIBPATH.$(bld_trg_cpu))\
[481]1297 $(LIBPATH.$(bld_trg).$(bld_trg_arch))\
[221]1298 $(LIBPATH.$(bld_trg_arch))\
1299 $(LIBPATH.$(bld_trg))\
1300 $(LIBPATH.$(bld_type))\
[74]1301 $(LIBPATH)\
[221]1302 $(foreach sdk, $(SDKS.$(bld_trg)) \
[481]1303 $(SDKS.$(bld_trg).$(bld_trg_arch)) \
[221]1304 $(SDKS.$(bld_type)) \
[122]1305 $(SDKS),\
[353]1306 $(SDK_$(sdk)_LIBPATH.$(bld_trg_cpu))\
[481]1307 $(SDK_$(sdk)_LIBPATH.$(bld_trg).$(bld_trg_arch))\
[353]1308 $(SDK_$(sdk)_LIBPATH.$(bld_trg_arch))\
1309 $(SDK_$(sdk)_LIBPATH.$(bld_trg))\
1310 $(SDK_$(sdk)_LIBPATH.$(bld_type))\
1311 $(SDK_$(sdk)_LIBPATH))\
[221]1312 $(TOOL_$(tool)_LIBPATH.$(bld_trg_cpu))\
[481]1313 $(TOOL_$(tool)_LIBPATH.$(bld_trg).$(bld_trg_arch))\
[221]1314 $(TOOL_$(tool)_LIBPATH.$(bld_trg_arch))\
1315 $(TOOL_$(tool)_LIBPATH.$(bld_trg))\
1316 $(TOOL_$(tool)_LIBPATH.$(bld_type))\
[353]1317 $(TOOL_$(tool)_LIBPATH)
1318dirdep := $(call DIRDEP,$(dir $(out)))
[74]1319## @todo fix dependencies
[353]1320deps := $($(target)_DEPS)
1321
1322## @todo this stuff can't be working.
1323custom_pre := $(strip $(firstword \
[481]1324 $($(target)_CUSTOM_PRE.$(bld_trg).$(bld_trg_arch))\
[221]1325 $($(target)_CUSTOM_PRE.$(bld_trg).$(bld_type))\
1326 $($(target)_CUSTOM_PRE.$(bld_trg))\
1327 $($(target)_CUSTOM_PRE.$(bld_type))\
[74]1328 $($(target)_CUSTOM_PRE)\
[481]1329 $(CUSTOM_PRE.$(bld_trg).$(bld_trg_arch))\
[221]1330 $(CUSTOM_PRE.$(bld_trg).$(bld_type))\
1331 $(CUSTOM_PRE.$(bld_trg))\
1332 $(CUSTOM_PRE.$(bld_type))\
[74]1333 $(CUSTOM_PRE)\
[353]1334))
1335custom_post := $(strip $(firstword \
[481]1336 $($(target)_CUSTOM_POST.$(bld_trg).$(bld_trg_arch))\
[221]1337 $($(target)_CUSTOM_POST.$(bld_trg).$(bld_type))\
1338 $($(target)_CUSTOM_POST.$(bld_trg))\
1339 $($(target)_CUSTOM_POST.$(bld_type))\
[74]1340 $($(target)_CUSTOM_POST)\
[481]1341 $(CUSTOM_POST.$(bld_trg).$(bld_trg_arch))\
[221]1342 $(CUSTOM_POST.$(bld_trg).$(bld_type))\
1343 $(CUSTOM_POST.$(bld_trg))\
1344 $(CUSTOM_POST.$(bld_type))\
[74]1345 $(CUSTOM_POST)\
[353]1346))
[72]1347
[353]1348# installation targets
1349ifndef $(target)_NOINST
1350INSTARGET_$(target) := $(patsubst %/,%/$(notdir $(out)), \
1351 $(if $($(target)_INST), $(addprefix $(PATH_INS)/,$($(target)_INST)), $(definst)/))
1352ifdef KBUILD_DO_AUTO_INSTALL
1353$(typevar) += $(INSTARGET_$(target))
1354else
1355$(typevar) += $(out)
1356endif
1357# generate the install rule
1358$(eval $(def_link_install_rule))
1359
1360else # NOINST
1361INSTARGET_$(target) :=
1362$(typevar) += $(out)
1363endif # NOINST
1364
[380]1365# dependency file
1366dep := $(outbase)$(SUFF_DEP)
[524]1367ifndef NO_LINK_CMDS_DEPS
[380]1368_DEPFILES_INCLUDED += $(dep)
1369$(if $(wildcard $(dep)),$(eval include $(dep)))
1370endif
[353]1371
[380]1372# check that the tool is defined.
1373ifndef TOOL_$(tool)_$(tool_do)_CMDS
1374$(warning kBuild: tools: \
[481]1375 1 $($(target)_$(source)TOOL.$(bld_trg).$(bld_trg_arch)) \
1376 2 $($(target)_$(source)TOOL.$(bld_trg)) \
1377 3 $($(target)_$(source)TOOL) \
1378 4 $($(target)_TOOL.$(bld_trg).$(bld_trg_arch)) \
1379 5 $($(target)_TOOL.$(bld_trg)) \
1380 6 $($(target)_TOOL) \
1381 7 $($(source)TOOL.$(bld_trg).$(bld_trg_arch)) \
1382 8 $($(source)TOOL.$(bld_trg)) \
1383 9 $($(source)TOOL) \
1384 10 $(TOOL.$(bld_trg).$(bld_trg_arch)) \
1385 11 $(TOOL.$(bld_trg)) \
1386 12 $(TOOL) )
[380]1387$(error kBuild: TOOL_$(tool)_$(tool_do)_CMDS isn't defined! target=$(target) )
1388endif
[353]1389
[380]1390# call the tool
1391$(target)_CMDS_ := $(TOOL_$(tool)_$(tool_do)_CMDS)
1392$(target)_OUTPUT_ := $(TOOL_$(tool)_$(tool_do)_OUTPUT)
1393$(target)_DEPEND_ := $(TOOL_$(tool)_$(tool_do)_DEPEND) $(deps) $(objs)
1394$(target)_DEPORD_ := $(TOOL_$(tool)_$(tool_do)_DEPORD) $(dirdep)
[353]1395
[412]1396# generate the link rule.
[380]1397$(eval $(def_link_rule))
1398
[412]1399
[380]1400# Update globals.
[579]1401_OBJS += $($(target)_OBJS_)
1402_OUT_FILES += $($(target)_OUTPUT_) $(out)
[353]1403_CLEAN_FILES += $($(target)_CLEAN)
[579]1404_INSTALLS += $(INSTARGET_$(target))
[353]1405
1406endef
1407
1408
1409#
1410# BLDPROGS
1411#
1412
1413## Build program (one).
1414# @param $(target) Normalized target (program) name.
1415define def_bldprog
1416
1417# set NOINST if not forced installation.
1418ifndef $(target)_INST
1419$(target)_NOINST := 1
1420endif
1421
[380]1422# do the usual stuff.
1423$(eval $(value def_link_common))
[353]1424
1425endef
1426
1427# Process build programs.
1428EXT := EXE
1429EXTPRE := HOST
[380]1430tool_do := LINK_PROGRAM
[353]1431definst := $(PATH_BIN)
1432typevar := _BLDPROGS
[380]1433mode := 0755
[353]1434bld_trg_base_var := PLATFORM
[481]1435$(foreach target, $(BLDPROGS) $(BLDPROGS.$(BUILD_PLATFORM)) $(BLDPROGS.$(BUILD_PLATFORM).$(BUILD_PLATFORM_ARCH)), $(eval $(value def_bldprog)))
[353]1436
1437
1438
1439#
1440# DLLS
1441#
1442
[189]1443# Process dlls
[353]1444EXT := DLL
1445EXTPRE :=
[380]1446tool_do := LINK_DLL
[353]1447definst := $(PATH_DLL)
1448typevar := _DLLS
[380]1449mode := 0755
[353]1450bld_trg_base_var := TARGET
[481]1451$(foreach target, $(DLLS) $(DLLS.$(BUILD_TARGET)) $(DLLS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)), $(eval $(value def_link_common)))
[74]1452
1453
[72]1454#
[189]1455# Process import libraries.
[72]1456#
[219]1457# - On OS/2 and windows these are libraries.
[189]1458# - On other platforms they are fake DLLs.
[481]1459ifeq ($(filter-out nt os2 win win64 win32,$(BUILD_TARGET)),)
1460$(foreach target, $(IMPORT_LIBS) $(IMPORT_LIBS.$(BUILD_TARGET)) $(IMPORT_LIBS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)), $(eval $(value def_lib)))
[189]1461else
[481]1462$(foreach target, $(IMPORT_LIBS) $(IMPORT_LIBS.$(BUILD_TARGET)) $(IMPORT_LIBS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)), $(eval $(value def_link_common)))
[189]1463endif
[481]1464$(foreach target, $(IMPORT_LIBS) $(IMPORT_LIBS.$(BUILD_TARGET)) $(IMPORT_LIBS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)), \
[353]1465 $(eval _IMPORT_LIBS += $(if $(INSTARGET_$(target)),$(INSTARGET_$(target)), $(TARGET_$(target)))))
[72]1466
[189]1467
1468#
1469# PROGRAMS
1470#
1471
[353]1472# Process programs
1473EXT := EXE
1474EXTPRE :=
[380]1475tool_do := LINK_PROGRAM
[353]1476definst := $(PATH_BIN)
1477typevar := _PROGRAMS
[380]1478mode := 0755
[353]1479bld_trg_base_var := TARGET
[481]1480$(foreach target, $(PROGRAMS) $(PROGRAMS.$(BUILD_TARGET)) $(PROGRAMS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)), $(eval $(value def_link_common)))
[130]1481
1482
[189]1483
[72]1484#
[83]1485# SYSMODS
[72]1486#
1487
[130]1488# Process sysmods
[353]1489EXT := SYS
1490EXTPRE :=
[380]1491tool_do := LINK_SYSMOD
[353]1492definst := $(PATH_SYS)
1493typevar := _SYSMODS
[380]1494mode := 0644
[353]1495bld_trg_base_var := TARGET
[481]1496$(foreach target, $(SYSMODS) $(SYSMODS.$(BUILD_TARGET)) $(SYSMODS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)), $(eval $(value def_link_common)))
[83]1497
1498
[72]1499#
1500# OTHERS
1501#
[481]1502_OTHERS = $(OTHERS) $(OTHERS.$(BUILD_TARGET)) $(OTHERS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH))
[72]1503
1504
[353]1505#
1506# INSTALLS
1507#
[72]1508
[353]1509## generate the install rule
1510define def_install_src_rule
1511# the install rule
1512$(insdst) : $(srcsrc) | $(call DIRDEP,$(dir $(insdst)))
[380]1513 $$(if $$(filter $(INSTALL),$(inscmd)),,$$(RM) -f $$@)
[353]1514 $(inscmd)
1515endef
1516
1517## install one file
1518define def_install_src
1519
1520# deal with '=>' in the source file name.
1521srcdst := $(subst =>, ,$(src))
1522srcsrc := $(firstword $(srcdst))
[424]1523srcdstdir := $(dir $(word 2,$(srcdst)))
[353]1524srcdst := $(word $(words $(srcdst)),$(srcdst))
1525
1526# _INSTFUN
1527ifdef $(srcsrc)_INSTFUN
1528instfun := $(srcsrc)_INSTFUN
1529else
1530ifdef $(target)_INSTFUN
1531instfun := $(target)_INSTFUN
1532else
1533instfun := _INSTALL_FILE
1534endif
1535endif
1536
1537# _INST
1538ifdef $(srcsrc)_INST
[424]1539inst := $(patsubst %/,%,$($(srcsrc)_INST))/$(dir $(srcdstdir))
[353]1540else
1541ifdef $(target)_INST
[424]1542inst := $(patsubst %/,%,$($(target)_INST))/$(dir $(srcdstdir))
[353]1543else
[424]1544inst := $(dir $(srcdstdir))
[353]1545endif
1546endif
1547
1548# calc target
[380]1549insdst := $(call $(instfun),$(srcdst),$(target),$(inst),$(PATH_INS))
[424]1550#$(warning instfun=$(instfun) srcdst=$(srcdst) target=$(target) inst=$(inst) => insdst=$(insdst))
[353]1551
[414]1552# mode, uid and gid
1553mode := $(firstword \
[481]1554 $($(target)_$(srcsrc)_MODE.$(bld_trg).$(bld_trg_arch)) \
[414]1555 $($(target)_$(srcsrc)_MODE.$(bld_trg)) \
1556 $($(target)_$(srcsrc)_MODE) \
[481]1557 $($(target)_$(srcdst)_MODE.$(bld_trg).$(bld_trg_arch)) \
[414]1558 $($(target)_$(srcdst)_MODE.$(bld_trg)) \
1559 $($(target)_$(srcdst)_MODE) \
[481]1560 $($(srcsrc)_MODE.$(bld_trg).$(bld_trg_arch)) \
[414]1561 $($(srcsrc)_MODE.$(bld_trg)) \
1562 $($(srcsrc)_MODE) \
[481]1563 $($(srcdst)_MODE.$(bld_trg).$(bld_trg_arch)) \
[414]1564 $($(srcdst)_MODE.$(bld_trg)) \
1565 $($(srcdst)_MODE) \
[481]1566 $($(target)_MODE.$(bld_trg).$(bld_trg_arch)) \
[414]1567 $($(target)_MODE.$(bld_trg)) \
1568 $($(target)_MODE))
1569uid := $(firstword \
[481]1570 $($(target)_$(srcsrc)_UID.$(bld_trg).$(bld_trg_arch)) \
[414]1571 $($(target)_$(srcsrc)_UID.$(bld_trg)) \
1572 $($(target)_$(srcsrc)_UID) \
[481]1573 $($(target)_$(srcdst)_UID.$(bld_trg).$(bld_trg_arch)) \
[414]1574 $($(target)_$(srcdst)_UID.$(bld_trg)) \
1575 $($(target)_$(srcdst)_UID) \
[481]1576 $($(srcsrc)_UID.$(bld_trg).$(bld_trg_arch)) \
[414]1577 $($(srcsrc)_UID.$(bld_trg)) \
1578 $($(srcsrc)_UID) \
[481]1579 $($(srcdst)_UID.$(bld_trg).$(bld_trg_arch)) \
[414]1580 $($(srcdst)_UID.$(bld_trg)) \
1581 $($(srcdst)_UID) \
[481]1582 $($(target)_UID.$(bld_trg).$(bld_trg_arch)) \
[414]1583 $($(target)_UID.$(bld_trg)) \
1584 $($(target)_UID))
1585gid := $(firstword \
[481]1586 $($(target)_$(srcsrc)_GID.$(bld_trg).$(bld_trg_arch)) \
[414]1587 $($(target)_$(srcsrc)_GID.$(bld_trg)) \
1588 $($(target)_$(srcsrc)_GID) \
[481]1589 $($(target)_$(srcdst)_GID.$(bld_trg).$(bld_trg_arch)) \
[414]1590 $($(target)_$(srcdst)_GID.$(bld_trg)) \
1591 $($(target)_$(srcdst)_GID) \
[481]1592 $($(srcsrc)_GID.$(bld_trg).$(bld_trg_arch)) \
[414]1593 $($(srcsrc)_GID.$(bld_trg)) \
1594 $($(srcsrc)_GID) \
[481]1595 $($(srcdst)_GID.$(bld_trg).$(bld_trg_arch)) \
[414]1596 $($(srcdst)_GID.$(bld_trg)) \
1597 $($(srcdst)_GID) \
[481]1598 $($(target)_GID.$(bld_trg).$(bld_trg_arch)) \
[414]1599 $($(target)_GID.$(bld_trg)) \
1600 $($(target)_GID))
1601
[353]1602# create the command
1603ifdef $(srcsrc)_INSTALLER
1604inscmd := $(call $(srcsrc)_INSTALLER,$(srcsrc),$(insdst),$(target))
1605else
1606ifdef $(target)_INSTALLER
1607inscmd := $(call $(target)_INSTALLER,$(srcsrc),$(insdst),$(target))
1608else
[414]1609inscmd := $$(INSTALL)\
1610 $(if $(uid),-o $(uid))\
1611 $(if $(gid),-g $(gid))\
1612 $(if $(mode),-m $(mode))\
1613 $(srcsrc) $(insdst)
[353]1614endif
1615endif
1616
1617# generate the rule (need double evaluation here)
1618$(eval $(def_install_src_rule))
1619
1620INSTARGET_$(target) += $(insdst)
1621endef
1622
1623
1624## generate the symlink rule
1625define def_install_symlink_rule
1626# the install rule
1627$(insdst) : | $(call DIRDEP,$(dir $(insdst)))
1628 $$(RM) -f $$@
[380]1629 $$(LN_SYMLINK) $(symdst) $(insdst)
[353]1630endef
1631
1632## create one symlink
1633define def_install_symlink
1634
1635# deal with '=>' in the source file name.
[380]1636symdst := $(subst =>, ,$(src))
1637symlnk := $(firstword $(symdst))
1638symdst := $(word $(words $(symdst)),$(symdst))
[353]1639
1640# _INSTFUN
[380]1641ifdef $(symlnk)_INSTFUN
1642instfun := $(symlnk)_INSTFUN
[353]1643else
1644ifdef $(target)_INSTFUN
1645instfun := $(target)_INSTFUN
1646else
1647instfun := _INSTALL_FILE
1648endif
1649endif
1650
1651# _INST
[380]1652ifdef $(symlnk)_INST
1653inst := $(patsubst %/,%,$($(symlnk)_INST))/$(dir $(symlnk))
[353]1654else
1655ifdef $(target)_INST
[380]1656inst := $(patsubst %/,%,$($(target)_INST))/$(dir $(symlnk))
[353]1657else
[380]1658inst := $(dir $(symlnk))
[353]1659endif
1660endif
1661
1662# calc target
[380]1663insdst := $(call $(instfun),$(symlnk),$(target),$(inst),$(PATH_INS))
1664#$(warning symlnk=$(symlnk) symdst=$(symdst) insdst=$(insdst) instfun=$(instfun) inst='$(inst)')
[353]1665
1666# generate the rule (need double evaluation here)
1667$(eval $(def_install_symlink_rule))
1668
1669INSTARGET_$(target) += $(insdst)
1670endef
1671
[412]1672
[380]1673## generate the install rule
1674define def_install_directory_rule
1675# the install rule
1676$(insdst):
1677 $(INSTALL) -d \
1678 $(if $(uid),-o $(uid))\
1679 $(if $(gid),-g $(gid))\
1680 $(if $(mode),-m $(mode))\
1681 $(insdst)
[412]1682
1683.NOTPARALLEL: $(insdst)
[380]1684endef
1685
[412]1686
[380]1687## create one directory
1688define def_install_directory
1689
1690# _INST
1691ifdef $(directory)_INST
1692inst := $(PATH_INS)/$(patsubst %/,%,$($(directory)_INST))
1693else
1694ifdef $(target)_INST
1695inst := $(PATH_INS)/$(patsubst %/,%,$($(target)_INST))
1696else
1697inst := $(PATH_INS)
1698endif
1699endif
1700
1701mode := $(firstword \
[481]1702 $($(target)_$(directory)_MODE.$(bld_trg).$(bld_trg_arch)) \
[380]1703 $($(target)_$(directory)_MODE.$(bld_trg)) \
1704 $($(target)_$(directory)_MODE) \
[481]1705 $($(directory)_MODE.$(bld_trg).$(bld_trg_arch)) \
[380]1706 $($(directory)_MODE.$(bld_trg)) \
1707 $($(directory)_MODE) \
[481]1708 $($(target)_MODE.$(bld_trg).$(bld_trg_arch)) \
[380]1709 $($(target)_MODE.$(bld_trg)) \
1710 $($(target)_MODE))
1711uid := $(firstword \
[481]1712 $($(target)_$(directory)_UID.$(bld_trg).$(bld_trg_arch)) \
[380]1713 $($(target)_$(directory)_UID.$(bld_trg)) \
1714 $($(target)_$(directory)_UID) \
[481]1715 $($(directory)_UID.$(bld_trg).$(bld_trg_arch)) \
[380]1716 $($(directory)_UID.$(bld_trg)) \
1717 $($(directory)_UID) \
[481]1718 $($(target)_UID.$(bld_trg).$(bld_trg_arch)) \
[380]1719 $($(target)_UID.$(bld_trg)) \
1720 $($(target)_UID))
1721gid := $(firstword \
[481]1722 $($(target)_$(directory)_GID.$(bld_trg).$(bld_trg_arch)) \
[380]1723 $($(target)_$(directory)_GID.$(bld_trg)) \
1724 $($(target)_$(directory)_GID) \
[481]1725 $($(directory)_GID.$(bld_trg).$(bld_trg_arch)) \
[380]1726 $($(directory)_GID.$(bld_trg)) \
1727 $($(directory)_GID) \
[481]1728 $($(target)_GID.$(bld_trg).$(bld_trg_arch)) \
[380]1729 $($(target)_GID.$(bld_trg)) \
1730 $($(target)_GID))
1731
1732insdst := $(inst)/$(directory)/
1733#$(warning directory=$(directory) inst=$(inst) insdst=$(insdst) mode=$(mode) gid=$(gid) uid=$(uid))
1734
1735# generate the rule (need double evaluation here)
1736$(eval $(def_install_directory_rule))
1737
1738INSTARGET_DIRS_$(target) += $(insdst)
1739endef
1740
1741
[353]1742## process one install target.
1743define def_install
1744bld_type := $(firstword $($(target)_BLD_TYPE) $(BUILD_TYPE))
1745bld_trg := $(firstword $($(target)_BLD_TRG) $(BUILD_TARGET))
1746bld_trg_arch:= $(firstword $($(target)_BLD_TRG_ARCH) $(BUILD_TARGET_ARCH))
1747bld_trg_cpu := $(firstword $($(target)_BLD_TRG_CPU) $(BUILD_TARGET_CPU))
1748
1749INSTARGET_$(target) :=
[380]1750INSTARGET_DIRS_$(target) :=
1751
[481]1752$(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]1753 $(eval $(value def_install_directory)))
1754
[481]1755$(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]1756 $(eval $(value def_install_src)))
1757
[481]1758$(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]1759 $(eval $(value def_install_symlink)))
1760
[380]1761_INSTALLS += $(INSTARGET_$(target)) $($(target)_GOALS)
1762_INSTALLS_DIRS += $(INSTARGET_DIRS_$(target))
[353]1763endef
1764
1765## process all install targets
[481]1766$(foreach target, $(INSTALLS) $(INSTALLS.$(BUILD_TARGET)) $(INSTALLS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)), \
[353]1767 $(eval $(value def_install)))
1768
1769
[72]1770#
[417]1771# PACKING
1772#
[481]1773_PACKING += $(PACKING) $(PACKING.$(BUILD_TARGET)) $(PACKING.$(BUILD_TARGET).$(BUILD_TARGET_ARCH))
[417]1774
1775
1776#
[72]1777# DOCS
1778#
1779
1780
1781#
[353]1782# DIRECTORIES
1783#
1784_DIR_ALL := $(sort $(addsuffix /,$(patsubst %/,%,$(_DIRS))) $(dir $(_OUT_FILES) $(_OBJS) $(_INSTALLS)))
[380]1785$(foreach directory,$(_INSTALLS_DIRS), $(eval _DIR_ALL := $(filter-out $(directory),$(_DIR_ALL))))
[353]1786
[380]1787
[353]1788define def_mkdir_rule
1789$(directory):
1790 $(call MSG_L1,Creating directory $$@)
1791 $(MKDIR) -p $$@
[72]1792endef
1793
[353]1794$(foreach directory,$(_DIR_ALL),$(eval $(def_mkdir_rule)))
[72]1795
[183]1796
[72]1797#
[353]1798# NOTHING
[72]1799#
[353]1800do-nothing:
1801 $(call MSG_L1,Did nothing in $(CURDIR))
[72]1802
[183]1803
[75]1804#
[353]1805# CLEAN UP
[75]1806#
[353]1807do-clean:
[380]1808 $(RM) -f $(_OUT_FILES) $(_OBJS) $(_DEPFILES) $(_DEPFILES_INCLUDED) $(_CLEAN_FILES) $(OTHER_CLEAN)
[72]1809
[98]1810
[353]1811#
1812# PASSES (including directory and makefile walking)
1813#
[221]1814
[75]1815## Subdir
1816# @param $(pass) Lowercase pass name.
1817# @param $(PASS) Uppercase pass name.
1818# @param $(subdir) Subdirectory
1819# @param $(tag) tag to attach to the rule name.
1820define def_pass_subdir
[219]1821pass_$(pass)$(tag):: $(dep)
1822 + $(QUIET)$$(MAKE) -C $(subdir) -f $$(notdir $$(firstword $$(wildcard $$(addprefix $(subdir)/,$$(DEFAULT_MAKEFILE))))) pass_$(pass)
[75]1823endef
[72]1824
[75]1825## Submakefile
1826# @param $(pass) Lowercase pass name.
1827# @param $(PASS) Uppercase pass name.
1828# @param $(makefile) Makefile.
1829# @param $(tag) tag to attach to the rule name.
1830define def_pass_makefile
[219]1831pass_$(pass)$(tag):: $(dep)
1832 + $(QUIET)$$(MAKE) -C $(patsubst %/,%,$(dir $(makefile))) -f $(notdir $(makefile)) pass_$(pass)
[75]1833endef
[73]1834
[75]1835## Execute a pass.
1836# @param $(pass) Lowercase pass name.
1837# @param $(PASS) Uppercase pass name.
[353]1838define def_pass_old
[481]1839$(eval SUBDIRS_$(PASS) ?= $(SUBDIRS) $(SUBDIRS.$(BUILD_TARGET)) $(SUBDIRS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) )
1840$(eval SUBDIRS_AFTER_$(PASS) ?= $(SUBDIRS_AFTER) $(SUBDIRS_AFTER.$(BUILD_TARGET)) $(SUBDIRS_AFTER.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) )
1841$(eval MAKEFILES_BEFORE_$(PASS) ?= $(MAKEFILES_BEFORE) $(MAKEFILES_BEFORE.$(BUILD_TARGET)) $(MAKEFILES_BEFORE.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) )
1842$(eval MAKEFILES_AFTER_$(PASS) ?= $(MAKEFILES_AFTER) $(MAKEFILES_AFTER.$(BUILD_TARGET)) $(MAKEFILES_AFTER.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) )
[75]1843
1844$(eval tag:=_before)
[219]1845$(eval dep:=)
[481]1846$(foreach subdir,$(SUBDIRS_$(PASS)) $(SUBDIRS_$(PASS).$(BUILD_TARGET)) $(SUBDIRS_$(PASS).$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) ,$(eval $(def_pass_subdir)))
1847$(foreach makefile,$(MAKEFILES_BEFORE_$(PASS)) $(MAKEFILES_BEFORE_$(PASS).$(BUILD_TARGET)) $(MAKEFILES_BEFORE_$(PASS).$(BUILD_TARGET).$(BUILD_TARGET_ARCH)),$(eval $(def_pass_makefile)))
[75]1848
1849$(eval tag:=_after)
[219]1850$(eval dep:=pass_$(pass)_doit)
[481]1851$(foreach subdir,$(SUBDIRS_AFTER_$(PASS)) $(SUBDIRS_AFTER_$(PASS).$(BUILD_TARGET)) $(SUBDIRS_AFTER_$(PASS).$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) ,$(eval $(def_pass_subdir)))
1852$(foreach makefile,$(MAKEFILES_AFTER_$(PASS)) $(MAKEFILES_AFTER_$(PASS).$(BUILD_TARGET)) $(MAKEFILES_AFTER_$(PASS).$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) ,$(eval $(def_pass_makefile)))
[75]1853
1854.NOTPARALLEL: pass_$(pass)_before pass_$(pass)_after
1855.PHONY: pass_$(pass) pass_$(pass)_before pass_$(pass)_doit pass_$(pass)_after
[353]1856pass_$(pass)_doit: $(PASS_$(PASS)_trgs) $(foreach var,$(PASS_$(PASS)_vars),$(var))
[272]1857pass_$(pass)_this: pass_$(pass)_before
[220]1858 + $(QUIET)$$(MAKE) -f $$(MAKEFILE) pass_$(pass)_doit
1859pass_$(pass)_after:: pass_$(pass)_this
[219]1860pass_$(pass): pass_$(pass)_after
[75]1861
[183]1862endef
1863
[353]1864define def_pass
[481]1865$(eval SUBDIRS_$(PASS) ?= $(SUBDIRS) $(SUBDIRS.$(BUILD_TARGET)) $(SUBDIRS.$(BUILD_TARGET.$(BUILD_TARGET_ARCH))) )
1866$(eval SUBDIRS_AFTER_$(PASS) ?= $(SUBDIRS_AFTER) $(SUBDIRS_AFTER.$(BUILD_TARGET)) $(SUBDIRS_AFTER.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) )
1867$(eval MAKEFILES_BEFORE_$(PASS) ?= $(MAKEFILES_BEFORE) $(MAKEFILES_BEFORE.$(BUILD_TARGET)) $(MAKEFILES_BEFORE.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) )
1868$(eval MAKEFILES_AFTER_$(PASS) ?= $(MAKEFILES_AFTER) $(MAKEFILES_AFTER.$(BUILD_TARGET)) $(MAKEFILES_AFTER.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) )
[183]1869
[353]1870$(eval tag:=_before)
1871$(eval dep:=)
[481]1872$(foreach subdir,$(SUBDIRS_$(PASS)) $(SUBDIRS_$(PASS).$(BUILD_TARGET)) $(SUBDIRS_$(PASS).$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) ,$(eval $(def_pass_subdir)))
1873$(foreach makefile,$(MAKEFILES_BEFORE_$(PASS)) $(MAKEFILES_BEFORE_$(PASS).$(BUILD_TARGET)) $(MAKEFILES_BEFORE_$(PASS).$(BUILD_TARGET).$(BUILD_TARGET_ARCH)),$(eval $(def_pass_makefile)))
[75]1874
[353]1875$(eval tag:=_after)
1876$(eval dep:=pass_$(pass)_doit)
[481]1877$(foreach subdir,$(SUBDIRS_AFTER_$(PASS)) $(SUBDIRS_AFTER_$(PASS).$(BUILD_TARGET)) $(SUBDIRS_AFTER_$(PASS).$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) ,$(eval $(def_pass_subdir)))
1878$(foreach makefile,$(MAKEFILES_AFTER_$(PASS)) $(MAKEFILES_AFTER_$(PASS).$(BUILD_TARGET)) $(MAKEFILES_AFTER_$(PASS).$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) ,$(eval $(def_pass_makefile)))
[75]1879
[380]1880ifdef KBUILD_SAFE_PARALLEL
[353]1881.NOTPARALLEL: pass_$(pass) pass_$(pass)_before pass_$(pass)_after pass_$(pass)_this
1882.PHONY: pass_$(pass) pass_$(pass)_before pass_$(pass)_after pass_$(pass)_this pass_$(pass)_doit
1883pass_$(pass)_doit: $(PASS_$(PASS)_trgs) $(foreach var,$(PASS_$(PASS)_vars),$(var))
1884pass_$(pass)_this: pass_$(pass)_before
1885 + $(QUIET)$$(MAKE) -f $$(MAKEFILE) pass_$(pass)_doit
1886pass_$(pass)_after:: pass_$(pass)_this
1887pass_$(pass): pass_$(pass)_after
1888else
[388]1889.NOTPARALLEL: pass_$(pass) pass_$(pass)_before pass_$(pass)_after pass_$(pass)_doit
[353]1890.PHONY: pass_$(pass) pass_$(pass)_before pass_$(pass)_after pass_$(pass)_doit
1891pass_$(pass)_doit: pass_$(pass)_before \
1892 $(PASS_$(PASS)_trgs) $(foreach var,$(PASS_$(PASS)_vars),$($(var)))
1893pass_$(pass): \
1894 pass_$(pass)_before \
1895 pass_$(pass)_doit \
[388]1896 pass_$(pass)_after
[353]1897endif
[189]1898
[353]1899#$ (warning pass=$(pass) PASS=$(PASS): $(PASS_$(PASS)_trgs) $(PASS_$(PASS)_trgs) $(foreach var,$(PASS_$(PASS)_vars),$($(var))))
1900endef
[75]1901
[353]1902# Generate the defined passes.
1903$(foreach PASS, $(PASSES), \
1904 $(eval pass := $(PASS_$(PASS)_pass)) \
1905 $(eval $(def_pass)))
[75]1906
[219]1907## Pass order
1908# @param $(pass) Current pass name.
1909# @param $(prev_pass) The previous pass name.
1910define def_pass_order
[380]1911ifdef KBUILD_SAFE_PARALLEL
[353]1912.NOTPARALLEL: pass_$(pass)_order
1913.PHONY: pass_$(pass)_order
[219]1914pass_$(pass)_order: $(pass_prev)
[353]1915 $(call MSG_L1,Pass - $(if $(PASS_$(PASS)),$(PASS_$(PASS)),$(pass)))
[219]1916 + $(QUIET)$$(MAKE) -f $$(MAKEFILE) pass_$(pass)
[353]1917else
1918.NOTPARALLEL: pass_$(pass)_order pass_$(pass)_banner
[388]1919.PHONY: pass_$(pass)_order pass_$(pass)_banner
[353]1920pass_$(pass)_banner:
1921 $(call MSG_L1,Pass - $(if $(PASS_$(PASS)),$(PASS_$(PASS)),$(pass)))
1922pass_$(pass)_order: \
1923 $(pass_prev) \
1924 pass_$(pass)_banner \
1925 pass_$(pass)
1926endif
[219]1927$(eval pass_prev := pass_$(pass)_order)
1928endef
[183]1929
[219]1930## PASS: order
1931# Use dependencies to ensure correct pass order.
1932pass_prev :=
[353]1933$(foreach PASS,$(DEFAULT_PASSES),\
1934 $(eval pass := $(PASS_$(PASS)_pass)) \
1935 $(eval $(def_pass_order)))
[219]1936
[272]1937
[75]1938#
1939# THE MAIN RULES
1940#
[219]1941all_recursive: $(pass_prev)
[75]1942
[130]1943rebuild: clean
[219]1944 + $(MAKE) -f $(firstword $(MAKEFILE_LIST)) all_recursive
[78]1945
[412]1946# @todo make this a non-default pass!
[353]1947uninstall:
1948 $(RM) -f $(_INSTALLS)
[412]1949
[380]1950install: pass_installs
[78]1951
[75]1952# misc shortcuts.
[380]1953targets: bldprogs libraries dlls programs sysmods others installs
[75]1954objects: $(_OBJS)
[222]1955bldprogs: $(_BLDPROGS)
[189]1956libraries: $(_LIBS) $(_IMPORT_LIBS) $(_OTHER_LIBRARIES)
[205]1957dlls: $(_DLLS)
[219]1958programs: $(_PROGRAMS)
[205]1959sysmods: $(_SYSMODS)
[353]1960others: $(_OTHERS)
[380]1961installs: $(_INSTALLS_DIRS) $(_INSTALLS)
[75]1962
1963
[353]1964#
1965# kBuild debugging stuff.
1966#
1967_SPACE := $(subst ., ,.)
1968_TAB := $(subst ., ,.)
1969define _NEWLINE
1970
1971
1972endef
1973NLTAB = $(_NEWLINE)$(TAB)
1974show_targets:
1975 @$(foreach target, $(ALL_TARGETS),\
1976 @$(ECHO) "target: $(target)" $(NLTAB)\
1977 @$(ECHO) " PATH_$(target)=$(PATH_$(target))" $(NLTAB)\
1978 @$(ECHO) " TARGET_$(target)=$(TARGET_$(target))" $(NLTAB)\
1979 @$(ECHO) " INSTARGET_$(target)=$(INSTARGET_$(target))" $(NLTAB)\
[380]1980$(foreach prop,$(PROPS_SINGLE) $(PROPS_ACCUMULATE) OBJS_ CLEAN, \
[353]1981 $(eval _tmp:=$(firstword $($(target)_BLD_TRG) $(BUILD_TARGET))) \
1982 $(if $($(target)_$(prop).$(_tmp)),\
1983 @$(ECHO) " $(target)_$(prop).$(_tmp)=$($(target)_$(prop).$(_tmp))" $(NLTAB)) \
1984 $(if $($(target)_$(prop)), $(NLTAB)@$(ECHO) " $(target)_$(prop)=$($(target)_$(prop))" $(NLTAB)) \
1985)\
1986$(foreach prop,$(PROPS_DEFERRED), \
1987 $(eval _tmp:=$(firstword $($(target)_BLD_TRG) $(BUILD_TARGET))) \
1988 $(if $(value $(target)_$(prop).$(_tmp)),\
1989 @$(ECHO) ' $(target)_$(prop).$(_tmp)=$(value $(TARGET)_$(prop).$(_tmp))' $(NLTAB)) \
1990 $(if $(value $(target)_$(prop)), $(NLTAB)@$(ECHO) ' $(target)_$(prop)=$(value $(target)_$(prop))' $(NLTAB)) \
1991))
1992
1993
1994
1995#
1996# Include dependency files.
1997#
1998$(foreach dep,$(wildcard $(_DEPFILES)),$(eval include $(dep)))
1999
2000
[72]2001# end-of-file-content
[106]2002__footer_kmk__ := target
[72]2003endif # __footer_kmk__
[438]2004
Note: See TracBrowser for help on using the repository browser.