source: trunk/kBuild/footer.kmk@ 989

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

forgot sysmods and import libraries inherting.

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