source: trunk/kBuild/footer.kmk@ 746

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

better place for it.

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