source: trunk/kBuild/footer.kmk@ 830

Last change on this file since 830 was 830, checked in by bird, 18 years ago

New properties for INSTALLS only (atm): IDFLAGS, IFFLAGS, ISFLAGS. directory, file and symlink flags. Also fixed (/broke - it's not tested) some import lib stuff.

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