source: trunk/kBuild/footer.kmk@ 985

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

Working on inhertiance. Added target inherting but it's a bit restricted by the expansion order currently (it not tested either).

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