source: trunk/kBuild/footer.kmk@ 743

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

set PATH_target early (i.e. in subheader/subfooter).

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