source: trunk/kBuild/footer.kmk@ 680

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

more details.

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