source: trunk/kBuild/footer.kmk@ 530

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

Added kBuild specific functions for speeding up source processing.

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