source: trunk/kBuild/footer.kmk@ 725

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

Partial implementation of a _PATH target property for resolving relative paths. It's primarily intended for sub-makefile mode where we apply it to all targets automatically. TODOs: INCS, DEPs (source level) and SUBDIRS*.

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