source: trunk/kBuild/footer.kmk@ 471

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

fixed sdks and tools inclusion.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 55.1 KB
RevLine 
[72]1# $Id: footer.kmk 460 2006-07-02 22:21:59Z bird $
2## @file
3#
4# kBuild - File included at top of makefile.
5#
[353]6# Copyright (c) 2004-2005 knut st. osmundsen <bird-srcspam@anduin.net>
[72]7#
8#
9# This file is part of kBuild.
10#
11# kBuild is free software; you can redistribute it and/or modify
12# it under the terms of the GNU General Public License as published by
[106]13# the Free Software Foundation; either version source of the License, or
[72]14# (at your option) any later version.
15#
16# kBuild is distributed in the hope that it will be useful,
17# but WITHOUT ANY WARRANTY; without even the implied warranty of
18# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19# GNU General Public License for more details.
20#
21# You should have received a copy of the GNU General Public License
22# along with kBuild; if not, write to the Free Software
[353]23# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
[72]24#
25#
26
27ifndef __footer_kmk__
28# start-of-file-content
29
30#
31# Variables.
[73]32# (Some of these need initialization before including definitions using them.)
[72]33#
34
35# all targets.
[353]36ALL_TARGETS += \
[239]37 $(BLDPROGS) $(BLDPROGS.$(BUILD_PLATFORM)) \
[189]38 $(LIBRARIES) $(LIBRARIES.$(BUILD_TARGET)) \
39 $(IMPORT_LIBS) $(IMPORT_LIBS.$(BUILD_TARGET)) \
40 $(DLLS) $(DLLS.$(BUILD_TARGET)) \
41 $(PROGRAMS) $(PROGRAMS.$(BUILD_TARGET)) \
42 $(SYSMODS) $(SYSMODS.$(BUILD_TARGET)) \
[353]43 $(INSTALLS) $(INSTALLS.$(BUILD_TARGET)) \
[189]44 $(OTHERS) $(OTHERS.$(BUILD_TARGET))
[72]45
[447]46# all $(BUILD_TARGET) targets.
47_ALL_BUILD_TARGET_TARGETS += \
48 $(BLDPROGS) $(BLDPROGS.$(BUILD_PLATFORM)) \
49 $(LIBRARIES) $(LIBRARIES.$(BUILD_TARGET)) \
50 $(IMPORT_LIBS) $(IMPORT_LIBS.$(BUILD_TARGET)) \
51 $(DLLS) $(DLLS.$(BUILD_TARGET)) \
52 $(PROGRAMS) $(PROGRAMS.$(BUILD_TARGET)) \
53 $(SYSMODS) $(SYSMODS.$(BUILD_TARGET)) \
54 $(INSTALLS) $(INSTALLS.$(BUILD_TARGET)) \
55 $(OTHERS) $(OTHERS.$(BUILD_TARGET))
56
57# all $(BUILD_TARGET) targets.
58_ALL_BUILD_PLATFORM_TARGETS += \
59 $(BLDPROGS) $(BLDPROGS.$(BUILD_PLATFORM))
60
[75]61# dependency files.
62_DEPFILES :=
63
[380]64# included dependency files.
65_DEPFILES_INCLUDED :=
66
67
[75]68# All kind of output files except for _OBJS and _DEPFILES.
69# Compiling or linking definition outputting other things that $@ and any
70# required dependency file must add those output files to this variable.
71_OUT_FILES :=
72
[353]73# Files which only requires cleaning up.
74_CLEAN_FILES :=
75
[72]76# all of a type
[219]77_OBJS :=
[222]78_BLDPROGS :=
[219]79_LIBS :=
80_DLLS :=
81_PROGRAMS :=
82_SYSMODS :=
[353]83_INSTALLS :=
[380]84_INSTALLS_DIRS :=
[353]85_OTHERS :=
[417]86_PACKING :=
[380]87_DIRS := $(PATH_TARGET)/ $(PATH_TARGET)
[189]88_IMPORT_LIBS :=
[72]89
[220]90# misc
91pass_prev :=
92
93
[72]94#
[73]95# Basic macros
96#
97
98## Figure out the tool for a source
[106]99# @param $target source file
100# @param $source normalized main target
101# @param $type tooltype
[222]102# @param bld_trg build target.
[79]103_SOURCE_TOOL = $(strip $(firstword \
[222]104 $($(target)_$(source)_$(type)TOOL.$(bld_trg)) \
[106]105 $($(target)_$(source)_$(type)TOOL) \
[222]106 $($(target)_$(source)_TOOL.$(bld_trg)) \
[106]107 $($(target)_$(source)_TOOL) \
[222]108 $($(target)_$(type)TOOL.$(bld_trg)) \
[106]109 $($(target)_$(type)TOOL) \
[222]110 $($(target)_TOOL.$(bld_trg)) \
[106]111 $($(target)_TOOL) \
[222]112 $($(source)_$(type)TOOL.$(bld_trg)) \
[106]113 $($(source)_$(type)TOOL) \
[222]114 $($(source)_TOOL.$(bld_trg)) \
[106]115 $($(source)_TOOL) \
[222]116 $($(type)TOOL.$(bld_trg)) \
[106]117 $($(type)TOOL) \
[222]118 $(TOOL.$(bld_trg)) \
[106]119 $(TOOL) ))
[73]120
[78]121## Figure out the tool for a target.
[106]122# @param $target normalized target.
123# @param $source tooltype.
[222]124# @param bld_trg build target.
[79]125_TARGET_TOOL = $(strip $(firstword \
[222]126 $($(target)_$(source)TOOL.$(bld_trg)) \
[106]127 $($(target)_$(source)TOOL) \
[222]128 $($(target)_TOOL.$(bld_trg)) \
[106]129 $($(target)_TOOL) \
[238]130 $($(source)TOOL.$(bld_trg)) \
[106]131 $($(source)TOOL) \
[222]132 $(TOOL.$(bld_trg)) \
[106]133 $(TOOL) \
[79]134 ))
[183]135
[148]136## Removes the drive letter from a path (if it has one)
137# @param $1 the path
138no-drive=$(word $(words $(subst :, ,$(1))),$(subst :, ,$(1)))
[78]139
[148]140## Removes the root slash from a path (if it has one)
141# @param $1 the path
142no-root-slash=$(patsubst /%,%,$(1))
143
[73]144## Figure out where to put object files.
[110]145# @param $1 source file
146# @param $2 normalized main target
[316]147# @remark There are two major hacks here:
148# 1. Source files in the output directory are translated into a gen/ subdir.
149# 2. Catch anyone specifying $(PATH_CURRENT)/sourcefile.c.
150_OBJECT_BASE = $(PATH_TARGET)/$(2)/$(call no-root-slash,$(call no-drive,$(basename \
151 $(patsubst $(PATH_ROOT)/%,%,$(patsubst $(PATH_CURRENT)/%,%,$(patsubst $(PATH_TARGET)/$(2)/%,gen/%,$(1)))))))
[73]152
153## Figure out where to put object files.
[110]154# @param $1 real target name.
155# @param $2 normalized main target
[148]156_TARGET_BASE = $(PATH_TARGET)/$(2)/$(call no-root-slash,$(call no-drive,$(basename $(1))))
[73]157
158
[353]159## Figure out the actual name of an installed file.
160# @param $1 The file to install.
161# @param $2 The target name.
162# @param $3 The _INST value (can be empty).
163# @param $4 The default directory to use when $3 is empty.
164_INSTALL_FILE = $(patsubst %/,%/$(notdir $(1)),$(if $(3),$(PATH_INS)/$(3),$(4)/))
165
166
[73]167#
[185]168# Check syntax which leads to weird syntax errors.
169#
170
171## Check
172# @param $(target) Target name.
173define def_check_target
174ifneq ("$($(target)_TEMPLATE)","$(strip $($(target)_TEMPLATE))")
175$$(error $(target) have an incorrect template name. Remove any tabs!)
176endif
177endef
178$(foreach target, $(ALL_TARGETS),$(eval $(def_check_target)))
179
180
181#
[72]182# Include templates
183#
184_TEMPLATES := $(TEMPLATE)
185define def_templates
186ifdef $(target)_TEMPLATE
187_TEMPLATES += $($(target)_TEMPLATE)
188endif
189endef
190$(foreach target, $(ALL_TARGETS), $(eval $(def_templates)))
191_TEMPLATES := $(sort $(_TEMPLATES))
192# $ (warning dbg: _TEMPLATES=$(_TEMPLATES))
193
194define def_templates_include
195ifndef TEMPLATE_$(template)
[353]196include $(firstword $(foreach path, $(TEMPLATE_PATHS) $(PATH_KBUILD)/templates/, $(wildcard $(path)/$(template).kmk)))
[72]197endif
198endef
199$(foreach template, $(_TEMPLATES), $(eval $(def_templates)))
200
[74]201
[72]202#
[412]203# Template Inheritance.
204#
205define def_template_extends_prop
206ifndef TEMPLATE_$(template)_$(prop)
207ifdef TEMPLATE_$(parent)_$(prop)
208TEMPLATE_$(template)_$(prop) = $$(TEMPLATE_$(parent)_$(prop))
209endif
210endif
211endef
212
213define def_template_extends
214ifdef TEMPLATE_$(template)_EXTENDS
215parent := $(strip $(TEMPLATE_$(template)_EXTENDS))
216
217$(foreach prop, $(PROPS_SINGLE) $(PROPS_ACCUMULATE) $(PROPS_DEFERRED)\
218$(addsuffix .$(BUILD_TARGET), $(PROPS_SINGLE) $(PROPS_ACCUMULATE) $(PROPS_DEFERRED))\
[455]219$(addsuffix .$(BUILD_TARGET_ARCH), $(PROPS_SINGLE) $(PROPS_ACCUMULATE) $(PROPS_DEFERRED))\
220$(addsuffix .$(BUILD_TARGET_CPU), $(PROPS_SINGLE) $(PROPS_ACCUMULATE) $(PROPS_DEFERRED))\
[412]221$(addsuffix .$(BUILD_TYPE), $(PROPS_SINGLE) $(PROPS_ACCUMULATE) $(PROPS_DEFERRED))\
222,$(eval $(def_template_extends_prop))) # exploits the 2 evaluation, so no value!
223endif
224endef
225
226# $ (foreach template, $(_TEMPLATES), $(if TEMPLATE_$(template)_EXTENDS, $(eval $(value def_template_extends))))
227$(foreach template, $(_TEMPLATES), $(eval $(value def_template_extends)))
228
229
230#
[72]231# Common Inheritance
232#
233
[353]234## Inherit one template property in a non-accumulative manner.
[72]235# @param $(prop) Property name
236# @param $(target) Target name
[78]237# @todo fix the precedence order for some properties.
[72]238define def_inherit_template_one
[78]239ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop)
[72]240ifndef $(target)_$(prop)
[353]241$(target)_$(prop) := $(TEMPLATE_$($(target)_TEMPLATE)_$(prop))
242#$ (warning dbgtarget: $(target)_$(prop):='$(value $(target)_$(prop))' TEMPLATE_$($(target)_TEMPLATE)_$(prop))
[72]243endif
244endif
[447]245ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg)
246ifndef $(target)_$(prop).$(bld_trg)
247#$ (warning dbgsource: $(target)_$(prop).$(bld_trg)="TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg)" TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg))
248$(target)_$(prop).$(bld_trg) := $(TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg))
[79]249endif
250endif
[455]251ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_arch)
252ifndef $(target)_$(prop).$(bld_trg_arch)
253#$ (warning dbgsource: $(target)_$(prop).$(bld_trg_arch)="TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_arch)" TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_arch))
254$(target)_$(prop).$(bld_trg_arch) := $(TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_arch))
255endif
256endif
257ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_cpu)
258ifndef $(target)_$(prop).$(bld_trg_cpu)
259#$ (warning dbgsource: $(target)_$(prop).$(bld_trg_cpu)="TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_cpu)" TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_cpu))
260$(target)_$(prop).$(bld_trg_cpu) := $(TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_cpu))
261endif
262endif
[72]263endef
264
[353]265## Inherit one template property in a non-accumulative manner, deferred expansion.
266# @param 1: $(prop) Property name
267# @param 2: $(target) Target name
268# @todo fix the precedence order for some properties.
269# @remark this define relies on double evaluation
270define def_inherit_template_one_deferred
271ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop)
272ifndef $(target)_$(prop)
273$(target)_$(prop) = $$(TEMPLATE_$($(target)_TEMPLATE)_$(prop))
274#$ (warning dbgtarget: $(target)_$(prop):='$(value $(target)_$(prop))' TEMPLATE_$($(target)_TEMPLATE)_$(prop))
275endif
276endif
[447]277ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg)
278ifndef $(target)_$(prop).$(bld_trg)
279#$ (warning dbgsource: $(target)_$(prop).$(bld_trg)="TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg)" TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg))
280$(target)_$(prop).$(bld_trg) = $$(TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg))
[353]281endif
282endif
[455]283ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_arch)
284ifndef $(target)_$(prop).$(bld_trg_arch)
285#$ (warning dbgsource: $(target)_$(prop).$(bld_trg_arch)="TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_arch)" TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_arch))
286$(target)_$(prop).$(bld_trg_arch) = $$(TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_arch))
287endif
288endif
289ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_cpu)
290ifndef $(target)_$(prop).$(bld_trg_cpu)
291#$ (warning dbgsource: $(target)_$(prop).$(bld_trg_cpu)="TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_cpu)" TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_cpu))
292$(target)_$(prop).$(bld_trg_cpu) = $$(TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_cpu))
293endif
294endif
[353]295endef
296
[183]297## Inherit one template property.
[78]298# @param $(prop) Property name
299# @param $(target) Target name
300define def_inherit_template_one_accumulate
301ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop)
[353]302#$ (warning dbgtype: TEMPLATE_$($(target)_TEMPLATE)_$(prop) $(target)_$(prop)=$($(target)_$(prop)) $(TEMPLATE_$($(target)_TEMPLATE)_$(prop)))
[442]303$(target)_$(prop) += $(TEMPLATE_$($(target)_TEMPLATE)_$(prop))
304#$ (warning dbgtype: $(target)_$(prop)=$($(target)_$(prop)))
[78]305endif
[243]306ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(BUILD_TYPE)
[353]307#$ (warning dbg4: TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(BUILD_TYPE))
[442]308$(target)_$(prop).$(BUILD_TYPE) += $(TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(BUILD_TYPE))
[243]309endif
[447]310ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg)
311#$ (warning dbg4: TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg))
312$(target)_$(prop).$(bld_trg) += $(TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg))
[79]313endif
[447]314ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_cpu)
315#$ (warning dbg5: TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_cpu))
316$(target)_$(prop).$(bld_trg_cpu) += $(TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_cpu))
[79]317endif
[447]318ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_arch)
319#$ (warning dbg6: TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_arch))
320$(target)_$(prop).$(bld_trg_arch) += $(TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_arch))
[79]321endif
[78]322endef
323
[72]324## Inherit template properties for on target.
325# @param $(target) Target name.
326define def_inherit_template
[447]327# Inherit any default template.
328ifdef TEMPLATE
329ifeq ($($(target)_TEMPLATE),)
330$(eval $(target)_TEMPLATE:=$(TEMPLATE))
331endif
332endif
333# Expand the template if specified.
334ifneq ($($(target)_TEMPLATE),)
[353]335$(foreach prop,$(PROPS_SINGLE),$(eval $(value def_inherit_template_one)))
336$(foreach prop,$(PROPS_DEFERRED),$(eval $(def_inherit_template_one_deferred))) # exploits the 2 evaluation, so no value!
[442]337$(foreach prop,$(PROPS_ACCUMULATE),$(eval $(def_inherit_template_one_accumulate))) # += works fine (better) without value.
[447]338endif
[72]339endef
[353]340
[72]341# Inherit template properties
[447]342bld_trg := $(BUILD_TARGET)
343bld_trg_arch := $(BUILD_TARGET_ARCH)
344bld_trg_cpu := $(BUILD_TARGET_CPU)
345$(foreach target, $(_ALL_BUILD_TARGET_TARGETS),$(eval $(value def_inherit_template)))
[72]346
[447]347bld_trg := $(BUILD_PLATFORM)
348bld_trg_arch := $(BUILD_PLATFORM_ARCH)
349bld_trg_cpu := $(BUILD_PLATFORM_CPU)
350$(foreach target, $(_ALL_BUILD_PLATFORM_TARGETS),$(eval $(value def_inherit_template)))
[72]351
[447]352
[72]353#
[460]354# Include tools & sdks
[183]355#
[460]356_TOOLS := $(TOOL.$(BUILD_TARGET)) $(TOOL.$(BUILD_TARGET_ARCH)) $(TOOL.$(BUILD_PLATFORM)) $(TOOL.$(BUILD_PLATFORM_ARCH)) $(TOOL)
357_SDKS := $(SDKS.$(BUILD_TARGET)) $(SDKS.$(BUILD_TARGET_ARCH)) $(SDKS.$(BUILD_PLATFORM)) $(SDKS.$(BUILD_PLATFORM_ARCH)) $(SDKS)
358define def_tools_sdks_target_source
[353]359$(eval _TOOLS += $(foreach prop, $(PROPS_TOOLS), \
[460]360 $($(source)_$(prop).$(_bld_trg)) \
361 $($(target)_$(source)_$(prop).$(_bld_trg)) \
362 $($(source)_$(prop).$(_bld_trg_arch)) \
363 $($(target)_$(source)_$(prop).$(_bld_trg_arch)) \
[353]364 $($(source)_$(prop)) \
365 $($(target)_$(source)_$(prop))))
[460]366$(eval _SDKS += \
367 $($(source)_SDKS.$(_bld_trg)) \
368 $($(target)_$(source)_SDKS.$(_bld_trg)) \
369 $($(source)_SDKS.$(_bld_trg_arch)) \
370 $($(target)_$(source)_SDKS.$(_bld_trg_arch)) \
371 $($(source)_SDKS) \
372 $($(target)_$(source)_SDKS))
[72]373endef
[353]374
[460]375define def_tools_sdks_target
376_bld_trg := $(firstword $($(target)_BLD_TRG) $(bld_trg))
377_bld_trg_arch := $(firstword $($(target)_BLD_TRG_ARCH) $(bld_trg_arch))
378_bld_trg_cpu := $(firstword $($(target)_BLD_TRG_CPU) $(bld_trg_cpu))
379
[353]380$(eval _TOOLS += $(foreach prop, $(PROPS_TOOLS), \
[460]381 $($(target)_$(prop).$(_bld_trg)) \
382 $($(target)_$(prop).$(_bld_trg_arch)) \
[353]383 $($(target)_$(prop))))
[460]384$(eval _SDKS += \
385 $($(target)_SDKS.$(_bld_trg)) \
386 $($(target)_SDKS.$(_bld_trg_arch)) \
387 $($(target)_SDKS))
[353]388$(foreach source, \
[460]389 $($(target)_SOURCES.$(_bld_trg)) \
390 $($(target)_SOURCES.$(_bld_trg_arch)) \
391 $($(target)_SOURCES.$(_bld_trg_cpu)) \
[353]392 $($(target)_SOURCES.$(BUILD_TYPE)) \
393 $($(target)_SOURCES) \
[460]394 , $(eval $(value def_tools_sdks_target_source)))
[72]395endef
[353]396
[460]397bld_trg := $(BUILD_TARGET)
398bld_trg_arch := $(BUILD_TARGET_ARCH)
399bld_trg_cpu := $(BUILD_TARGET_CPU)
400$(foreach target, $(_ALL_BUILD_TARGET_TARGETS), $(eval $(value def_tools_sdks_target)))
[72]401
[460]402bld_trg := $(BUILD_PLATFORM)
403bld_trg_arch := $(BUILD_PLATFORM_ARCH)
404bld_trg_cpu := $(BUILD_PLATFORM_CPU)
405$(foreach target, $(_ALL_BUILD_PLATFORM_TARGETS), $(eval $(value def_tools_sdks_target)))
406
407
408# include TOOLS
[72]409define def_tools_include
410ifndef TOOL_$(tool)
[353]411TOOL_$(tool)_KMK_FILE := $(firstword $(foreach path, $(TOOL_PATHS) $(PATH_KBUILD)/tools, $(wildcard $(path)/$(tool).kmk)))
412ifeq ($(TOOL_$(tool)_KMK_FILE),)
413$(error kBuild: Cannot find include file for the tool '$(tool)'! Searched: $(TOOL_PATHS) $(PATH_KBUILD)/tools)
[72]414endif
[353]415include $(TOOL_$(tool)_KMK_FILE)
416endif
[72]417endef
[460]418
419_TOOLS := $(sort $(_TOOLS))
[353]420$(foreach tool, $(_TOOLS), $(eval $(value def_tools_include)))
[72]421
422
[460]423# include SDKS
[122]424define def_sdks_include_one
[72]425ifndef SDK_$(sdk)
[353]426SDK_$(sdk)_KMK_FILE := $(firstword $(foreach path, $(SDK_PATHS) $(PATH_KBUILD)/sdks, $(wildcard $(path)/$(sdk).kmk)))
427ifeq ($(SDK_$(sdk)_KMK_FILE),)
428$(error kBuild: Cannot find include file for the SDK '$(sdk)'! Searched: $(SDK_PATHS) $(PATH_KBUILD)/sdks)
[72]429endif
[353]430include $(SDK_$(sdk)_KMK_FILE)
431endif
[72]432endef
[460]433
434_SDKS := $(sort $(_SDKS))
[353]435$(foreach sdk, $(_SDKS), $(eval $(value def_sdks_include_one)))
[72]436
[380]437
[73]438#
439# Object processing.
440#
[72]441
[380]442## wrapper the compile command dependency check.
443ifndef NO_COMPILE_CMDS_DEPS
444_DEP_COMPILE_CMDS = $(if $(subst $(strip $($(target)_$(source)_CMDS_PREV_)),,$(strip $($(target)_$(source)_CMDS_))),FORCE,)
445else
446_DEP_COMPILE_CMDS =
447endif
448
449## Generates the rules for building a specific object, and the '::' aliases
450# for building a source file.
[353]451# @param $(obj) The object file.
[380]452define def_target_source_rule
453$(obj) $($(target)_$(source)_OUTPUT_): \
454 $($(target)_$(source)_DEPEND_) \
455 $(_DEP_COMPILE_CMDS) \
456 | \
457 $($(target)_$(source)_DEPORD_)
458 $(call MSG_L1,Creating $$@)
459 $(RM) -f $(dep) $(out) $($(target)_$(source)_OUTPUT_)
460 $(custom_pre)
[412]461
[380]462$($(target)_$(source)_CMDS_)
463
464 $(custom_post)
465ifndef NO_COMPILE_CMDS_DEPS
466 @$(APPEND) "$(dep)"
467 @$(APPEND) "$(dep)" 'define $(target)_$(source)_CMDS_PREV_'
468 @$(APPEND) "$(dep)" '$(subst $(NL),'$(NL)$(TAB)@$(APPEND) "$(dep)" ',$($(target)_$(source)_CMDS_))'
469 @$(APPEND) "$(dep)" 'endef'
[412]470endif
[380]471
[353]472$(basename $(notdir $(obj))).o::
[442]473 + $$(MAKE) -f $$(MAKEFILE) $(obj)
[445]474$(basename $(notdir $(obj))).obj::
[442]475 + $$(MAKE) -f $$(MAKEFILE) $(obj)
[353]476endef
[205]477
[353]478
[380]479## wrapper the link command dependency check.
480ifndef NO_COMPILE_CMDS_DEPS
481_DEP_LINK_CMDS = $(if $(subst $(strip $($(target)_CMDS_PREV_)),,$(strip $($(target)_CMDS_))),FORCE,)
482else
483_DEP_LINK_CMDS =
484endif
485
486## Generate the link rule for a target.
487# @param $(target) The normalized target name.
488# @param $(dirdep) Directories we depend upon begin created before linking.
489# @param $(dep) The name of the dependency file.
490# @param $(out)
491# @param $($(target)_OUTPUT_) Output files from the link.
492# @param $($(target)_DEPEND_) Dependencies.
493# @param $($(target)_DEPORD_) Dependencies which should only affect build order.
494# @param $($(target)_CMDS_) The link commands.
495# @param $($(target)_CMDS_PREV_) The link commands from the previous run.
496define def_link_rule
497$(out) $($(target)_OUTPUT_): \
498 $($(target)_DEPEND_) \
499 $(_DEP_LINK_CMDS) \
500 | \
501 $($(target)_DEPORD_)
502 $(call MSG_L1,Creating $$@)
503 $(RM) -f $(dep) $($(target)_OUTPUT_)
504 $(custom_pre)
[412]505
[380]506$($(target)_CMDS_)
507
508 $(custom_post)
509ifndef NO_LINK_CMDS_DEP
510 @$(APPEND) "$(dep)" 'define $(target)_CMDS_PREV_'
511 @$(APPEND) "$(dep)" '$(subst $(NL),'$(NL)$(TAB)@$(APPEND) "$(dep)" ',$($(target)_CMDS_))'
512 @$(APPEND) "$(dep)" 'endef'
[412]513endif
[380]514
515$(basename $(notdir $(out)))::
[442]516 + $$(MAKE) -f $$(MAKEFILE) $(out)
[380]517endef
518
519
520## Generate the link & lib install rule
521# @param $(target) Normalized target name.
522# @param $(out) The build target.
523# @param $(INSTARGET_$(target)) The installation targets.
524# @param $(mode) The file mode (optional)
525define def_link_install_rule
526$(INSTARGET_$(target)) : $(out) | $(call DIRDEP,$(dir $(INSTARGET_$(target))))
527 $(INSTALL) $$(if $(mode),-m $(mode)) $(out) $$@
528endef
529
530
531
[73]532## Generic macro for processing C, C++ and Assembly sources.
533# @param $(target) Normalized target name.
534# @param $(source) Source file name.
535# @param $(type) Source type. {C,CXX,AS}
[221]536# @param bld_type Build type.
537# @param bld_trg Build target.
538# @param bld_trg_arch Build target arch.
539# @param bld_trg_cpu Build target cpu.
[72]540#
[73]541# @remark I've no clue why I've to $(eval ..) everything in this define. MAKE bug?
[105]542# @remark I now have a clue. Have to use $$ if not.
[73]543define def_target_source_c_cpp_asm
[105]544#$ (warning dbg: def_target_source_c_cpp_asm: source='$(source)' target='$(target)' type='$(type)')
[73]545
[353]546tool := $(call _SOURCE_TOOL,$(source),$(target),$(type))
547outbase := $(call _OBJECT_BASE,$(source),$(target))
548PATH_$(target)_$(source) := $(patsubst %/,%,$(dir $(outbase)))
549dirdep := $(call DIRDEP,$(dir $(outbase)))
550defs :=\
[78]551 $(TOOL_$(tool)_DEFS)\
[221]552 $(TOOL_$(tool)_DEFS.$(bld_type))\
553 $(TOOL_$(tool)_DEFS.$(bld_trg))\
554 $(TOOL_$(tool)_DEFS.$(bld_trg_arch))\
555 $(TOOL_$(tool)_DEFS.$(bld_trg_cpu))\
[74]556 $(TOOL_$(tool)_$(type)DEFS)\
[221]557 $(TOOL_$(tool)_$(type)DEFS.$(bld_type))\
558 $(foreach sdk, $(SDKS.$(bld_trg)) \
559 $(SDKS.$(bld_type)) \
[78]560 $(SDKS),\
[353]561 $(SDK_$(sdk)_DEFS)\
562 $(SDK_$(sdk)_DEFS.$(bld_type))\
563 $(SDK_$(sdk)_DEFS.$(bld_trg))\
564 $(SDK_$(sdk)_DEFS.$(bld_trg_arch))\
565 $(SDK_$(sdk)_DEFS.$(bld_trg_cpu))\
566 $(SDK_$(sdk)_$(type)DEFS)\
567 $(SDK_$(sdk)_$(type)DEFS.$(bld_type))\
568 $(SDK_$(sdk)_$(type)DEFS.$(bld_trg))\
569 $(SDK_$(sdk)_$(type)DEFS.$(bld_trg_arch))\
570 $(SDK_$(sdk)_$(type)DEFS.$(bld_trg_cpu)))\
[74]571 $(DEFS)\
[221]572 $(DEFS.$(bld_type))\
573 $(DEFS.$(bld_trg))\
574 $(DEFS.$(bld_trg_arch))\
575 $(DEFS.$(bld_trg_cpu))\
[78]576 $($(type)DEFS)\
[221]577 $($(type)DEFS.$(bld_type))\
578 $($(type)DEFS.$(bld_trg))\
579 $($(type)DEFS.$(bld_trg_arch))\
580 $($(type)DEFS.$(bld_trg_cpu))\
581 $(foreach sdk, $($(target)_SDKS.$(bld_trg)) \
582 $($(target)_SDKS.$(bld_type)) \
[78]583 $($(target)_SDKS),\
[353]584 $(SDK_$(sdk)_DEFS)\
585 $(SDK_$(sdk)_DEFS.$(bld_type))\
586 $(SDK_$(sdk)_DEFS.$(bld_trg))\
587 $(SDK_$(sdk)_DEFS.$(bld_trg_arch))\
588 $(SDK_$(sdk)_DEFS.$(bld_trg_cpu))\
589 $(SDK_$(sdk)_$(type)DEFS)\
590 $(SDK_$(sdk)_$(type)DEFS.$(bld_type))\
591 $(SDK_$(sdk)_$(type)DEFS.$(bld_trg))\
592 $(SDK_$(sdk)_$(type)DEFS.$(bld_trg_arch))\
593 $(SDK_$(sdk)_$(type)DEFS.$(bld_trg_cpu)))\
[74]594 $($(target)_DEFS)\
[221]595 $($(target)_DEFS.$(bld_type))\
596 $($(target)_DEFS.$(bld_trg))\
597 $($(target)_DEFS.$(bld_trg_arch))\
598 $($(target)_DEFS.$(bld_trg_cpu))\
[78]599 $($(target)_$(type)DEFS)\
[221]600 $($(target)_$(type)DEFS.$(bld_type))\
601 $($(target)_$(type)DEFS.$(bld_trg))\
602 $($(target)_$(type)DEFS.$(bld_trg_arch))\
603 $($(target)_$(type)DEFS.$(bld_trg_cpu))\
604 $(foreach sdk, $($(source)_SDKS.$(bld_trg)) \
605 $($(source)_SDKS.$(bld_type)) \
[78]606 $($(source)_SDKS),\
[353]607 $(SDK_$(sdk)_DEFS)\
608 $(SDK_$(sdk)_DEFS.$(bld_type))\
609 $(SDK_$(sdk)_DEFS.$(bld_trg))\
610 $(SDK_$(sdk)_DEFS.$(bld_trg_arch))\
611 $(SDK_$(sdk)_DEFS.$(bld_trg_cpu))\
612 $(SDK_$(sdk)_$(type)DEFS)\
613 $(SDK_$(sdk)_$(type)DEFS.$(bld_type))\
614 $(SDK_$(sdk)_$(type)DEFS.$(bld_trg))\
615 $(SDK_$(sdk)_$(type)DEFS.$(bld_trg_arch))\
616 $(SDK_$(sdk)_$(type)DEFS.$(bld_trg_cpu)))\
[74]617 $($(source)_DEFS)\
[221]618 $($(source)_DEFS.$(bld_type))\
619 $($(source)_DEFS.$(bld_trg))\
620 $($(source)_DEFS.$(bld_trg_arch))\
621 $($(source)_DEFS.$(bld_trg_cpu))\
[73]622 $($(source)_$(type)DEFS)\
[221]623 $($(source)_$(type)DEFS.$(bld_type))\
624 $($(source)_$(type)DEFS.$(bld_trg))\
625 $($(source)_$(type)DEFS.$(bld_trg_arch))\
626 $($(source)_$(type)DEFS.$(bld_trg_cpu))\
627 $(foreach sdk, $($(target)_$(source)_SDKS.$(bld_trg)) \
628 $($(target)_$(source)_SDKS.$(bld_type)) \
[78]629 $($(target)_$(source)_SDKS),\
[353]630 $(SDK_$(sdk)_DEFS)\
631 $(SDK_$(sdk)_DEFS.$(bld_type))\
632 $(SDK_$(sdk)_DEFS.$(bld_trg))\
633 $(SDK_$(sdk)_DEFS.$(bld_trg_arch))\
634 $(SDK_$(sdk)_DEFS.$(bld_trg_cpu))\
635 $(SDK_$(sdk)_$(type)DEFS)\
636 $(SDK_$(sdk)_$(type)DEFS.$(bld_type))\
637 $(SDK_$(sdk)_$(type)DEFS.$(bld_trg))\
638 $(SDK_$(sdk)_$(type)DEFS.$(bld_trg_arch))\
639 $(SDK_$(sdk)_$(type)DEFS.$(bld_trg_cpu)))\
[74]640 $($(target)_$(source)_DEFS)\
[221]641 $($(target)_$(source)_DEFS.$(bld_type))\
642 $($(target)_$(source)_DEFS.$(bld_trg))\
643 $($(target)_$(source)_DEFS.$(bld_trg_arch))\
644 $($(target)_$(source)_DEFS.$(bld_trg_cpu))\
[74]645 $($(target)_$(source)_$(type)DEFS)\
[221]646 $($(target)_$(source)_$(type)DEFS.$(bld_type))\
647 $($(target)_$(source)_$(type)DEFS.$(bld_trg))\
648 $($(target)_$(source)_$(type)DEFS.$(bld_trg_arch))\
[353]649 $($(target)_$(source)_$(type)DEFS.$(bld_trg_cpu))
650incs :=\
[221]651 $($(target)_$(source)_$(type)INCS.$(bld_trg_cpu))\
652 $($(target)_$(source)_$(type)INCS.$(bld_trg_arch))\
653 $($(target)_$(source)_$(type)INCS.$(bld_trg))\
654 $($(target)_$(source)_$(type)INCS.$(bld_type))\
[73]655 $($(target)_$(source)_$(type)INCS)\
[221]656 $($(target)_$(source)_INCS.$(bld_trg_cpu))\
657 $($(target)_$(source)_INCS.$(bld_trg_arch))\
658 $($(target)_$(source)_INCS.$(bld_trg))\
659 $($(target)_$(source)_INCS.$(bld_type))\
[73]660 $($(target)_$(source)_INCS)\
[221]661 $(foreach sdk, $($(target)_$(source)_SDKS.$(bld_trg)) \
662 $($(target)_$(source)_SDKS.$(bld_type)) \
[133]663 $($(target)_$(source)_SDKS),\
[353]664 $(SDK_$(sdk)_$(type)INCS.$(bld_trg_cpu))\
665 $(SDK_$(sdk)_$(type)INCS.$(bld_trg_arch))\
666 $(SDK_$(sdk)_$(type)INCS.$(bld_trg))\
667 $(SDK_$(sdk)_$(type)INCS.$(bld_type))\
668 $(SDK_$(sdk)_$(type)INCS)\
669 $(SDK_$(sdk)_INCS.$(bld_trg_cpu))\
670 $(SDK_$(sdk)_INCS.$(bld_trg_arch))\
671 $(SDK_$(sdk)_INCS.$(bld_trg))\
672 $(SDK_$(sdk)_INCS.$(bld_type))\
673 $(SDK_$(sdk)_INCS))\
[221]674 $($(source)_$(type)INCS.$(bld_trg_cpu))\
675 $($(source)_$(type)INCS.$(bld_trg_arch))\
676 $($(source)_$(type)INCS.$(bld_trg))\
677 $($(source)_$(type)INCS.$(bld_type))\
[73]678 $($(source)_$(type)INCS)\
[221]679 $($(source)_INCS.$(bld_trg_cpu))\
680 $($(source)_INCS.$(bld_trg_arch))\
681 $($(source)_INCS.$(bld_trg))\
682 $($(source)_INCS.$(bld_type))\
[73]683 $($(source)_INCS)\
[221]684 $(foreach sdk, $($(source)_SDKS.$(bld_trg)) \
685 $($(source)_SDKS.$(bld_type)) \
[78]686 $($(source)_SDKS),\
[353]687 $(SDK_$(sdk)_$(type)INCS.$(bld_trg_cpu))\
688 $(SDK_$(sdk)_$(type)INCS.$(bld_trg_arch))\
689 $(SDK_$(sdk)_$(type)INCS.$(bld_trg))\
690 $(SDK_$(sdk)_$(type)INCS.$(bld_type))\
691 $(SDK_$(sdk)_$(type)INCS)\
692 $(SDK_$(sdk)_INCS.$(bld_trg_cpu))\
693 $(SDK_$(sdk)_INCS.$(bld_trg_arch))\
694 $(SDK_$(sdk)_INCS.$(bld_trg))\
695 $(SDK_$(sdk)_INCS.$(bld_type))\
696 $(SDK_$(sdk)_INCS))\
[221]697 $($(target)_$(type)INCS.$(bld_trg_cpu))\
698 $($(target)_$(type)INCS.$(bld_trg_arch))\
699 $($(target)_$(type)INCS.$(bld_trg))\
700 $($(target)_$(type)INCS.$(bld_type))\
[73]701 $($(target)_$(type)INCS)\
[221]702 $($(target)_INCS.$(bld_trg_cpu))\
703 $($(target)_INCS.$(bld_trg_arch))\
704 $($(target)_INCS.$(bld_trg))\
705 $($(target)_INCS.$(bld_type))\
[73]706 $($(target)_INCS)\
[221]707 $(foreach sdk, $($(target)_SDKS.$(bld_trg)) \
708 $($(target)_SDKS.$(bld_type)) \
[78]709 $($(target)_SDKS),\
[353]710 $(SDK_$(sdk)_$(type)INCS.$(bld_trg_cpu))\
711 $(SDK_$(sdk)_$(type)INCS.$(bld_trg_arch))\
712 $(SDK_$(sdk)_$(type)INCS.$(bld_trg))\
713 $(SDK_$(sdk)_$(type)INCS.$(bld_type))\
714 $(SDK_$(sdk)_$(type)INCS)\
715 $(SDK_$(sdk)_INCS.$(bld_trg_cpu))\
716 $(SDK_$(sdk)_INCS.$(bld_trg_arch))\
717 $(SDK_$(sdk)_INCS.$(bld_trg))\
718 $(SDK_$(sdk)_INCS.$(bld_type))\
719 $(SDK_$(sdk)_INCS))\
[221]720 $(INCS.$(bld_trg_cpu))\
721 $(INCS.$(bld_trg_arch))\
722 $(INCS.$(bld_trg))\
723 $(INCS.$(bld_type))\
[73]724 $(INCS)\
[221]725 $(foreach sdk, $(SDKS.$(bld_trg)) \
726 $(SDKS.$(bld_type)) \
[78]727 $(SDKS),\
[353]728 $(SDK_$(sdk)_$(type)INCS.$(bld_trg_cpu))\
729 $(SDK_$(sdk)_$(type)INCS.$(bld_trg_arch))\
730 $(SDK_$(sdk)_$(type)INCS.$(bld_trg))\
731 $(SDK_$(sdk)_$(type)INCS.$(bld_type))\
732 $(SDK_$(sdk)_$(type)INCS)\
733 $(SDK_$(sdk)_INCS.$(bld_trg_cpu))\
734 $(SDK_$(sdk)_INCS.$(bld_trg_arch))\
735 $(SDK_$(sdk)_INCS.$(bld_trg))\
736 $(SDK_$(sdk)_INCS.$(bld_type))\
737 $(SDK_$(sdk)_INCS))\
[221]738 $(TOOL_$(tool)_$(type)INCS.$(bld_trg_cpu))\
739 $(TOOL_$(tool)_$(type)INCS.$(bld_trg_arch))\
740 $(TOOL_$(tool)_$(type)INCS.$(bld_trg))\
741 $(TOOL_$(tool)_$(type)INCS.$(bld_type))\
[353]742 $(TOOL_$(tool)_$(type)INCS)
743flags :=\
[73]744 $(TOOL_$(tool)_$(type)FLAGS)\
[221]745 $(TOOL_$(tool)_$(type)FLAGS.$(bld_type))\
746 $(TOOL_$(tool)_$(type)FLAGS.$(bld_trg))\
747 $(TOOL_$(tool)_$(type)FLAGS.$(bld_trg_arch))\
748 $(TOOL_$(tool)_$(type)FLAGS.$(bld_trg_cpu))\
[73]749 $($(type)FLAGS)\
[221]750 $($(type)FLAGS.$(bld_type))\
751 $($(type)FLAGS.$(bld_trg))\
752 $($(type)FLAGS.$(bld_trg_arch))\
753 $($(type)FLAGS.$(bld_trg_cpu))\
[73]754 $($(target)_$(type)FLAGS)\
[221]755 $($(target)_$(type)FLAGS.$(bld_type))\
756 $($(target)_$(type)FLAGS.$(bld_trg))\
757 $($(target)_$(type)FLAGS.$(bld_trg_arch))\
758 $($(target)_$(type)FLAGS.$(bld_trg_cpu))\
[73]759 $($(source)_$(type)FLAGS)\
[221]760 $($(source)_$(type)FLAGS.$(bld_type))\
761 $($(source)_$(type)FLAGS.$(bld_trg))\
762 $($(source)_$(type)FLAGS.$(bld_trg_arch))\
763 $($(source)_$(type)FLAGS.$(bld_trg_cpu))\
[73]764 $($(target)_$(source)_$(type)FLAGS)\
[221]765 $($(target)_$(source)_$(type)FLAGS.$(bld_type))\
766 $($(target)_$(source)_$(type)FLAGS.$(bld_trg))\
767 $($(target)_$(source)_$(type)FLAGS.$(bld_trg_arch))\
[353]768 $($(target)_$(source)_$(type)FLAGS.$(bld_trg_cpu))
769objsuff := $(firstword \
[221]770 $($(target)_$(source)_OBJSUFF.$(bld_trg))\
[74]771 $($(target)_$(source)_OBJSUFF)\
[221]772 $($(source)_OBJSUFF.$(bld_trg))\
[74]773 $($(source)_OBJSUFF)\
[221]774 $($(target)_OBJSUFF.$(bld_trg))\
[74]775 $($(target)_OBJSUFF)\
[221]776 $(TOOL_$(tool)_$(type)OBJSUFF.$(bld_trg))\
[74]777 $(TOOL_$(tool)_$(type)OBJSUFF)\
[353]778 $(SUFF_OBJ))
779obj := $(outbase)$(objsuff)
780deps := \
[184]781 $($(target)_$(source)_DEPS)\
[353]782 $($(target)_$(source)_DEPS.$(bld_type))\
783 $($(target)_$(source)_DEPS.$(bld_trg))\
784 $($(target)_$(source)_DEPS.$(bld_trg_arch))\
785 $($(target)_$(source)_DEPS.$(bld_trg_cpu))\
[184]786 $($(source)_DEPS)\
[221]787 $($(source)_DEPS.$(bld_type))\
788 $($(source)_DEPS.$(bld_trg))\
[353]789 $($(source)_DEPS.$(bld_trg_arch))\
790 $($(source)_DEPS.$(bld_trg_cpu))\
[184]791 $($(target)_DEPS)\
[353]792 $($(target)_DEPS.$(bld_type))\
[221]793 $($(target)_DEPS.$(bld_trg_arch))\
[353]794 $($(target)_DEPS.$(bld_trg_cpu))
[73]795
[380]796# dependencies
797dep := $(obj)$(SUFF_DEP)
798ifndef NO_COMPILE_DEPS
799_DEPFILES_INCLUDED += $(dep)
800$(if $(wildcard $(dep)),$(eval include $(dep)))
801endif
[184]802
803#$ (warning dbg: target=$(target) source=$(source) tool=$(tool) obj=$(obj) dep=$(dep) flags=$(flags) defs=$(defs) incs=$(incs) dirdep=$(dirdep) outbase=$(outbase) objsuff=$(objsuff) deps=$(deps))
[380]804ifndef TOOL_$(tool)_COMPILE_$(type)_CMDS
[353]805$(warning kBuild: tools: \
[221]806 1 $($(target)_$(source)_$(type)TOOL.$(bld_trg)) \
[106]807 2 $($(target)_$(source)_$(type)TOOL) \
[221]808 3 $($(target)_$(source)_TOOL.$(bld_trg)) \
[106]809 4 $($(target)_$(source)_TOOL) \
[221]810 5 $($(target)_$(type)TOOL.$(bld_trg)) \
[106]811 6 $($(target)_$(type)TOOL) \
[221]812 7 $($(target)_TOOL.$(bld_trg)) \
[106]813 8 $($(target)_TOOL) \
[221]814 9 $($(source)_$(type)TOOL.$(bld_trg)) \
[106]815 10 $($(source)_$(type)TOOL) \
[221]816 11 $($(source)_TOOL.$(bld_trg)) \
[106]817 12 $($(source)_TOOL) \
[221]818 13 $($(type)TOOL.$(bld_trg)) \
[106]819 14 $($(type)TOOL) \
[221]820 15 $(TOOL.$(bld_trg)) \
[106]821 16 $(TOOL) )
[380]822$(error kBuild: TOOL_$(tool)_COMPILE_$(type)_CMDS is not defined. source=$(source) target=$(target) )
[97]823endif
[353]824
[380]825# call the tool
826$(target)_$(source)_CMDS_ := $(TOOL_$(tool)_COMPILE_$(type)_CMDS)
827$(target)_$(source)_OUTPUT_ := $(TOOL_$(tool)_COMPILE_$(type)_OUTPUT)
828$(target)_$(source)_DEPEND_ := $(TOOL_$(tool)_COMPILE_$(type)_DEPEND) $(deps) $(source)
829$(target)_$(source)_DEPORD_ := $(TOOL_$(tool)_COMPILE_$(type)_DEPORD) $(dirdep)
[73]830
[380]831# generate the compile rule.
832$(eval $(def_target_source_rule))
[205]833
[380]834_OUT_FILES += $($(target)_$(source)_OUTPUT_)
[353]835$(target)_OBJS_ += $(obj)
[73]836
837endef
838
839## Generic macro for processing all target sources.
[74]840# @param $(target) Normalized target name.
[73]841define def_target_sources
842#$ (warning def_target_sources)
843# C sources
[353]844type := C
845$(foreach source, $(filter %.c, $($(target)_SOURCES) $($(target)_SOURCES.$(bld_trg)) $($(target)_SOURCES.$(bld_trg_arch)) $($(target)_SOURCES.$(bld_trg_cpu)) $($(target)_SOURCES.$(bld_type)))\
846 ,$(eval $(value def_target_source_c_cpp_asm)) )
[73]847
848# C++ sources
[353]849type := CXX
850$(foreach source, $(filter %.cpp %.cxx %.xx, $($(target)_SOURCES) $($(target)_SOURCES.$(bld_trg)) $($(target)_SOURCES.$(bld_trg_arch)) $($(target)_SOURCES.$(bld_trg_cpu)) $($(target)_SOURCES.$(bld_type)))\
851 ,$(eval $(value def_target_source_c_cpp_asm)) )
[73]852
853# ASM sources
[353]854type := AS
855$(foreach source, $(filter %.asm %.s %.S, $($(target)_SOURCES) $($(target)_SOURCES.$(bld_trg)) $($(target)_SOURCES.$(bld_trg_arch)) $($(target)_SOURCES.$(bld_trg_cpu)) $($(target)_SOURCES.$(bld_type)))\
856 ,$(eval $(value def_target_source_c_cpp_asm)) )
857
[73]858endef
859
860
[219]861
[353]862## Generic macro for generating the install rule(s) for a target
863# and update the globals with default out.
[219]864#
[353]865# @param $(target) Normalized target name.
866# @param $(out) The output file.
867# @param $(definst) The default _INST value.
868# @param $(typevar) The name of the variable with all the root targets of its type.
869# @obsolete
870define def_target_install_pluss
871ifndef $(target)_NOINST
872INSTARGET_$(target) := $(patsubst %/,%/$(notdir $(out)), \
873 $(if $($(target)_INST), $(addprefix $(PATH_INS)/,$($(target)_INST)), $(definst)/))
[219]874
[353]875$(eval $(def_link_install_rule))
[239]876
[353]877_INSTALLS += $(INSTARGET_$(target))
[272]878
[353]879ifdef KBUILD_DO_AUTO_INSTALL
880$(typevar) += $(INSTARGET_$(target))
[219]881else
[353]882$(typevar) += $(out)
[219]883endif
[353]884else # _NOINST
885$(typevar) += $(out)
886endif
887
888_OUT_FILES += $(out)
889_CLEAN_FILES += $($(target)_CLEAN)
890_OBJS += $($(target)_OBJS_)
891
[219]892endef
893
894
895
896#
[72]897# LIBRARIES
[73]898#
[72]899
900## Library (one).
[74]901# @param $(target) Normalized library (target) name.
[72]902define def_lib
[145]903# library basics
[222]904## @todo prefix
[353]905bld_type := $(firstword $($(target)_BLD_TYPE) $(BUILD_TYPE))
906bld_trg := $(firstword $($(target)_BLD_TRG) $(BUILD_TARGET))
907bld_trg_arch:= $(firstword $($(target)_BLD_TRG_ARCH) $(BUILD_TARGET_ARCH))
908bld_trg_cpu := $(firstword $($(target)_BLD_TRG_CPU) $(BUILD_TARGET_CPU))
909tool := $(call _TARGET_TOOL,$(target),AR)
[78]910ifeq ($(tool),)
[353]911$(error kBuild: Library target $(target) does not have a tool defined!)
[78]912endif
[353]913outbase := $(call _TARGET_BASE,$(target),$(target))
914PATH_$(target) := $(patsubst %/,%,$(dir $(outbase)))
915suff := $(firstword\
[221]916 $($(target)_LIBSUFF.$(bld_trg))\
[126]917 $($(target)_LIBSUFF)\
[221]918 $(TOOL_$(tool)_ARLIBSUFF.$(bld_trg))\
[126]919 $(TOOL_$(tool)_ARLIBSUFF)\
[353]920 $(SUFF_LIB))
921out := $(outbase)$(suff)
922TARGET_$(target) := $(out)
923$(target)_OBJS_ := $(filter %.o %.obj, \
924 $($(target)_SOURCES) \
925 $($(target)_SOURCES.$(bld_trg)) \
926 $($(target)_SOURCES.$(bld_trg_arch)) \
927 $($(target)_SOURCES.$(bld_trg_cpu)) \
928 $($(target)_SOURCES.$(bld_type)))
[145]929
[353]930
[145]931# source -> object
[353]932$(eval $(value def_target_sources))
[145]933
934# library linking
[353]935tool := $(call _TARGET_TOOL,$(target),AR)
936outbase := $(call _TARGET_BASE,$(target),$(target))
937flags :=\
[74]938 $(TOOL_$(tool)_ARFLAGS)\
[221]939 $(TOOL_$(tool)_ARFLAGS.$(bld_type))\
[74]940 $(ARFLAGS)\
[221]941 $(ARFLAGS.$(bld_type))\
[74]942 $($(target)_ARFLAGS)\
[353]943 $($(target)_ARFLAGS.$(bld_type))
944othersrc := $(filter-out %.c %.cpp %.cxx %.cc %.s %.S %.asm %.o %.obj,\
945 $($(target)_SOURCES) \
946 $($(target)_SOURCES.$(bld_trg)) \
947 $($(target)_SOURCES.$(bld_trg_arch)) \
948 $($(target)_SOURCES.$(bld_trg_cpu)) \
949 $($(target)_SOURCES.$(bld_type)))
950objs = $($(target)_OBJS_)
951dirdep := $(call DIRDEP,$(dir $(out)))
[78]952## @todo fix dependencies on makefiles an such
[353]953deps := $($(target)_DEPS)
[72]954
[380]955# dependency file
956dep := $(out)$(SUFF_DEP)
957ifndef NO_LINK_CMDS_DEP
958_DEPFILES_INCLUDED += $(dep)
959$(if $(wildcard $(dep)),$(eval include $(dep)))
960endif
[72]961
[380]962# check that the tool is defined.
963ifndef TOOL_$(tool)_LINK_LIBRARY_CMDS
964$(warning kBuild: tools: \
965 1 $($(target)_$(source)TOOL.$(bld_trg)) \
966 2 $($(target)_$(source)TOOL) \
967 3 $($(target)_TOOL.$(bld_trg)) \
968 4 $($(target)_TOOL) \
969 5 $($(source)TOOL) \
970 6 $($(source)TOOL.$(bld_trg)) \
971 7 $(TOOL.$(bld_trg)) \
972 8 $(TOOL) )
973$(error kBuild: TOOL_$(tool)_LINK_LIBRARY_CMDS isn't defined! target=$(target) )
974endif
975
976# call the tool
977$(target)_CMDS_ := $(TOOL_$(tool)_LINK_LIBRARY_CMDS)
978$(target)_OUTPUT_ := $(TOOL_$(tool)_LINK_LIBRARY_OUTPUT)
979$(target)_DEPEND_ := $(TOOL_$(tool)_LINK_LIBRARY_DEPEND) $(deps) $(objs)
980$(target)_DEPORD_ := $(TOOL_$(tool)_LINK_LIBRARY_DEPORD) $(dirdep)
981
[412]982# generate the link rule.
[380]983$(eval $(def_link_rule))
984
[353]985# installing and globals
986definst := $(PATH_LIB)
[380]987typevar := _LIBS
[353]988$(eval $(value def_target_install_pluss))
[72]989endef
990
991# Process libraries
[380]992mode := 0644
[353]993$(foreach target, $(LIBRARIES) $(LIBRARIES.$(BUILD_TARGET)), $(eval $(value def_lib)))
[72]994
995
996#
[353]997# Link operations.
[72]998#
999
[353]1000##
1001# Link prolog
1002#
1003# @param $(target) Normalized target name.
1004# @param $(EXT) EXE,DLL,SYS.
1005# @param $(definst) The default _INST value.
1006# @param $(typevar) The name of the variable with all the root targets of its type.
[380]1007define def_link_common
[353]1008# basics
1009bld_type := $(firstword $($(target)_BLD_TYPE) $(BUILD_TYPE))
1010bld_trg := $(firstword $($(target)_BLD_TRG) $(BUILD_$(bld_trg_base_var)))
1011bld_trg_arch:= $(firstword $($(target)_BLD_TRG_ARCH) $(BUILD_$(bld_trg_base_var)_ARCH))
1012bld_trg_cpu := $(firstword $($(target)_BLD_TRG_CPU) $(BUILD_$(bld_trg_base_var)_CPU))
[145]1013
[353]1014tool := $(call _TARGET_TOOL,$(target),LD)
1015outbase := $(call _TARGET_BASE,$(target),$(target))
1016suff := $(firstword \
1017 $($(target)_$(EXT)SUFF) \
1018 $($(target)_$(EXT)SUFF) \
1019 $(TOOL_$(tool)_LD$(EXT)SUFF) \
1020 $($(EXTPRE)SUFF_$(EXT)))
1021out := $(outbase)$(suff)
1022PATH_$(target) := $(patsubst %/,%,$(dir $(outbase)))
1023TARGET_$(target) := $(out)
1024$(target)_OBJS_ := $(filter %.o %.obj, \
1025 $($(target)_SOURCES) \
1026 $($(target)_SOURCES.$(bld_trg)) \
1027 $($(target)_SOURCES.$(bld_trg_arch)) \
1028 $($(target)_SOURCES.$(bld_trg_cpu)) \
1029 $($(target)_SOURCES.$(bld_type)))
1030
[145]1031# source -> object
[353]1032$(eval $(value def_target_sources))
[145]1033
[353]1034# more library stuff.
1035tool := $(call _TARGET_TOOL,$(target),LD)
1036outbase := $(call _TARGET_BASE,$(target),$(target))
1037flags :=\
[74]1038 $(TOOL_$(tool)_LDFLAGS)\
[221]1039 $(TOOL_$(tool)_LDFLAGS.$(bld_type))\
1040 $(TOOL_$(tool)_LDFLAGS.$(bld_trg))\
1041 $(TOOL_$(tool)_LDFLAGS.$(bld_trg_arch))\
1042 $(TOOL_$(tool)_LDFLAGS.$(bld_trg_cpu))\
[74]1043 $(LDFLAGS)\
[221]1044 $(LDFLAGS.$(bld_type))\
1045 $(LDFLAGS.$(bld_trg))\
1046 $(LDFLAGS.$(bld_trg_arch))\
1047 $(LDFLAGS.$(bld_trg_cpu))\
[74]1048 $($(target)_LDFLAGS)\
[221]1049 $($(target)_LDFLAGS.$(bld_type))\
1050 $($(target)_LDFLAGS.$(bld_trg))\
1051 $($(target)_LDFLAGS.$(bld_trg_arch))\
[353]1052 $($(target)_LDFLAGS.$(bld_trg_cpu))
1053othersrc := $(filter-out %.c %.cpp %.cxx %.cc %.s %.S %.asm %.o %.obj,\
1054 $($(target)_SOURCES)\
1055 $($(target)_SOURCES.$(bld_trg)) \
1056 $($(target)_SOURCES.$(bld_trg_arch)) \
1057 $($(target)_SOURCES.$(bld_trg_cpu)) \
1058 $($(target)_SOURCES.$(bld_type)))
1059objs = $($(target)_OBJS_)
1060libs :=\
[221]1061 $($(target)_LIBS.$(bld_trg_cpu))\
1062 $($(target)_LIBS.$(bld_trg_arch))\
1063 $($(target)_LIBS.$(bld_trg))\
1064 $($(target)_LIBS.$(bld_type))\
[74]1065 $($(target)_LIBS)\
[221]1066 $(foreach sdk, $($(target)_SDKS.$(bld_trg)) \
1067 $($(target)_SDKS.$(bld_type)) \
[122]1068 $($(target)_SDKS),\
[353]1069 $(SDK_$(sdk)_LIBS.$(bld_trg_cpu))\
1070 $(SDK_$(sdk)_LIBS.$(bld_trg_arch))\
1071 $(SDK_$(sdk)_LIBS.$(bld_trg))\
1072 $(SDK_$(sdk)_LIBS.$(bld_type))\
1073 $(SDK_$(sdk)_LIBS))\
[221]1074 $(LIBS.$(bld_trg_cpu))\
1075 $(LIBS.$(bld_trg_arch))\
1076 $(LIBS.$(bld_trg))\
1077 $(LIBS.$(bld_type))\
[74]1078 $(LIBS)\
[221]1079 $(foreach sdk, $(SDKS.$(bld_trg)) \
1080 $(SDKS.$(bld_type)) \
[122]1081 $(SDKS),\
[353]1082 $(SDK_$(sdk)_LIBS.$(bld_trg_cpu))\
1083 $(SDK_$(sdk)_LIBS.$(bld_trg_arch))\
1084 $(SDK_$(sdk)_LIBS.$(bld_trg))\
1085 $(SDK_$(sdk)_LIBS.$(bld_type))\
1086 $(SDK_$(sdk)_LIBS))\
[221]1087 $(TOOL_$(tool)_LIBS.$(bld_trg_cpu))\
1088 $(TOOL_$(tool)_LIBS.$(bld_trg_arch))\
1089 $(TOOL_$(tool)_LIBS.$(bld_trg))\
1090 $(TOOL_$(tool)_LIBS.$(bld_type))\
[353]1091 $(TOOL_$(tool)_LIBS)
1092libpath :=\
[221]1093 $($(target)_LIBPATH.$(bld_trg_cpu))\
1094 $($(target)_LIBPATH.$(bld_trg_arch))\
1095 $($(target)_LIBPATH.$(bld_trg))\
1096 $($(target)_LIBPATH.$(bld_type))\
[74]1097 $($(target)_LIBPATH)\
[221]1098 $(foreach sdk, $($(target)_SDKS.$(bld_trg)) \
1099 $($(target)_SDKS.$(bld_type)) \
[122]1100 $($(target)_SDKS),\
[353]1101 $(SDK_$(sdk)_LIBPATH.$(bld_trg_cpu))\
1102 $(SDK_$(sdk)_LIBPATH.$(bld_trg_arch))\
1103 $(SDK_$(sdk)_LIBPATH.$(bld_trg))\
1104 $(SDK_$(sdk)_LIBPATH.$(bld_type))\
1105 $(SDK_$(sdk)_LIBPATH))\
[221]1106 $(LIBPATH.$(bld_trg_cpu))\
1107 $(LIBPATH.$(bld_trg_arch))\
1108 $(LIBPATH.$(bld_trg))\
1109 $(LIBPATH.$(bld_type))\
[74]1110 $(LIBPATH)\
[221]1111 $(foreach sdk, $(SDKS.$(bld_trg)) \
1112 $(SDKS.$(bld_type)) \
[122]1113 $(SDKS),\
[353]1114 $(SDK_$(sdk)_LIBPATH.$(bld_trg_cpu))\
1115 $(SDK_$(sdk)_LIBPATH.$(bld_trg_arch))\
1116 $(SDK_$(sdk)_LIBPATH.$(bld_trg))\
1117 $(SDK_$(sdk)_LIBPATH.$(bld_type))\
1118 $(SDK_$(sdk)_LIBPATH))\
[221]1119 $(TOOL_$(tool)_LIBPATH.$(bld_trg_cpu))\
1120 $(TOOL_$(tool)_LIBPATH.$(bld_trg_arch))\
1121 $(TOOL_$(tool)_LIBPATH.$(bld_trg))\
1122 $(TOOL_$(tool)_LIBPATH.$(bld_type))\
[353]1123 $(TOOL_$(tool)_LIBPATH)
1124dirdep := $(call DIRDEP,$(dir $(out)))
[74]1125## @todo fix dependencies
[353]1126deps := $($(target)_DEPS)
1127
1128## @todo this stuff can't be working.
1129custom_pre := $(strip $(firstword \
[221]1130 $($(target)_CUSTOM_PRE.$(bld_trg).$(bld_type))\
1131 $($(target)_CUSTOM_PRE.$(bld_trg))\
1132 $($(target)_CUSTOM_PRE.$(bld_type))\
[74]1133 $($(target)_CUSTOM_PRE)\
[221]1134 $(CUSTOM_PRE.$(bld_trg).$(bld_type))\
1135 $(CUSTOM_PRE.$(bld_trg))\
1136 $(CUSTOM_PRE.$(bld_type))\
[74]1137 $(CUSTOM_PRE)\
[353]1138))
1139custom_post := $(strip $(firstword \
[221]1140 $($(target)_CUSTOM_POST.$(bld_trg).$(bld_type))\
1141 $($(target)_CUSTOM_POST.$(bld_trg))\
1142 $($(target)_CUSTOM_POST.$(bld_type))\
[74]1143 $($(target)_CUSTOM_POST)\
[221]1144 $(CUSTOM_POST.$(bld_trg).$(bld_type))\
1145 $(CUSTOM_POST.$(bld_trg))\
1146 $(CUSTOM_POST.$(bld_type))\
[74]1147 $(CUSTOM_POST)\
[353]1148))
[72]1149
[353]1150# installation targets
1151ifndef $(target)_NOINST
1152INSTARGET_$(target) := $(patsubst %/,%/$(notdir $(out)), \
1153 $(if $($(target)_INST), $(addprefix $(PATH_INS)/,$($(target)_INST)), $(definst)/))
1154ifdef KBUILD_DO_AUTO_INSTALL
1155$(typevar) += $(INSTARGET_$(target))
1156else
1157$(typevar) += $(out)
1158endif
1159# generate the install rule
1160$(eval $(def_link_install_rule))
1161
1162else # NOINST
1163INSTARGET_$(target) :=
1164$(typevar) += $(out)
1165endif # NOINST
1166
[380]1167# dependency file
1168dep := $(outbase)$(SUFF_DEP)
1169ifndef NO_LINK_CMDS_DEP
1170_DEPFILES_INCLUDED += $(dep)
1171$(if $(wildcard $(dep)),$(eval include $(dep)))
1172endif
[353]1173
[380]1174# check that the tool is defined.
1175ifndef TOOL_$(tool)_$(tool_do)_CMDS
1176$(warning kBuild: tools: \
1177 1 $($(target)_$(source)TOOL.$(bld_trg)) \
1178 2 $($(target)_$(source)TOOL) \
1179 3 $($(target)_TOOL.$(bld_trg)) \
1180 4 $($(target)_TOOL) \
1181 5 $($(source)TOOL) \
1182 6 $($(source)TOOL.$(bld_trg)) \
1183 7 $(TOOL.$(bld_trg)) \
1184 8 $(TOOL) )
1185$(error kBuild: TOOL_$(tool)_$(tool_do)_CMDS isn't defined! target=$(target) )
1186endif
[353]1187
[380]1188# call the tool
1189$(target)_CMDS_ := $(TOOL_$(tool)_$(tool_do)_CMDS)
1190$(target)_OUTPUT_ := $(TOOL_$(tool)_$(tool_do)_OUTPUT)
1191$(target)_DEPEND_ := $(TOOL_$(tool)_$(tool_do)_DEPEND) $(deps) $(objs)
1192$(target)_DEPORD_ := $(TOOL_$(tool)_$(tool_do)_DEPORD) $(dirdep)
[353]1193
[412]1194# generate the link rule.
[380]1195$(eval $(def_link_rule))
1196
[412]1197
[380]1198# Update globals.
[353]1199_OBJS += $($(target)_OBJS_)
[380]1200_OUT_FILES += $($(target)_OUTPUT_) $(out)
[353]1201_CLEAN_FILES += $($(target)_CLEAN)
[380]1202_INSTALLS += $(INSTARGET_$(target))
[353]1203
1204endef
1205
1206
1207#
1208# BLDPROGS
1209#
1210
1211## Build program (one).
1212# @param $(target) Normalized target (program) name.
1213define def_bldprog
1214
1215# set NOINST if not forced installation.
1216ifndef $(target)_INST
1217$(target)_NOINST := 1
1218endif
1219
[380]1220# do the usual stuff.
1221$(eval $(value def_link_common))
[353]1222
1223endef
1224
1225# Process build programs.
1226EXT := EXE
1227EXTPRE := HOST
[380]1228tool_do := LINK_PROGRAM
[353]1229definst := $(PATH_BIN)
1230typevar := _BLDPROGS
[380]1231mode := 0755
[353]1232bld_trg_base_var := PLATFORM
1233$(foreach target, $(BLDPROGS) $(BLDPROGS.$(BUILD_PLATFORM)), $(eval $(value def_bldprog)))
1234
1235
1236
1237#
1238# DLLS
1239#
1240
[189]1241# Process dlls
[353]1242EXT := DLL
1243EXTPRE :=
[380]1244tool_do := LINK_DLL
[353]1245definst := $(PATH_DLL)
1246typevar := _DLLS
[380]1247mode := 0755
[353]1248bld_trg_base_var := TARGET
[380]1249$(foreach target, $(DLLS) $(DLLS.$(BUILD_TARGET)), $(eval $(value def_link_common)))
[74]1250
1251
[72]1252#
[189]1253# Process import libraries.
[72]1254#
[219]1255# - On OS/2 and windows these are libraries.
[189]1256# - On other platforms they are fake DLLs.
[438]1257ifeq ($(filter-out win64 win32 os2,$(BUILD_TARGET)),)
[353]1258$(foreach target, $(IMPORT_LIBS) $(IMPORT_LIBS.$(BUILD_TARGET)), $(eval $(value def_lib)))
[189]1259else
[380]1260$(foreach target, $(IMPORT_LIBS) $(IMPORT_LIBS.$(BUILD_TARGET)), $(eval $(value def_link_common)))
[189]1261endif
[353]1262$(foreach target, $(IMPORT_LIBS) $(IMPORT_LIBS.$(BUILD_TARGET)), \
1263 $(eval _IMPORT_LIBS += $(if $(INSTARGET_$(target)),$(INSTARGET_$(target)), $(TARGET_$(target)))))
[72]1264
[189]1265
1266#
1267# PROGRAMS
1268#
1269
[353]1270# Process programs
1271EXT := EXE
1272EXTPRE :=
[380]1273tool_do := LINK_PROGRAM
[353]1274definst := $(PATH_BIN)
1275typevar := _PROGRAMS
[380]1276mode := 0755
[353]1277bld_trg_base_var := TARGET
[380]1278$(foreach target, $(PROGRAMS) $(PROGRAMS.$(BUILD_TARGET)), $(eval $(value def_link_common)))
[130]1279
1280
[189]1281
[72]1282#
[83]1283# SYSMODS
[72]1284#
1285
[130]1286# Process sysmods
[353]1287EXT := SYS
1288EXTPRE :=
[380]1289tool_do := LINK_SYSMOD
[353]1290definst := $(PATH_SYS)
1291typevar := _SYSMODS
[380]1292mode := 0644
[353]1293bld_trg_base_var := TARGET
[380]1294$(foreach target, $(SYSMODS) $(SYSMODS.$(BUILD_TARGET)), $(eval $(value def_link_common)))
[83]1295
1296
[72]1297#
1298# OTHERS
1299#
[190]1300_OTHERS = $(OTHERS) $(OTHERS.$(BUILD_TARGET))
[72]1301
1302
[353]1303#
1304# INSTALLS
1305#
[72]1306
[353]1307## generate the install rule
1308define def_install_src_rule
1309# the install rule
1310$(insdst) : $(srcsrc) | $(call DIRDEP,$(dir $(insdst)))
[380]1311 $$(if $$(filter $(INSTALL),$(inscmd)),,$$(RM) -f $$@)
[353]1312 $(inscmd)
1313endef
1314
1315## install one file
1316define def_install_src
1317
1318# deal with '=>' in the source file name.
1319srcdst := $(subst =>, ,$(src))
1320srcsrc := $(firstword $(srcdst))
[424]1321srcdstdir := $(dir $(word 2,$(srcdst)))
[353]1322srcdst := $(word $(words $(srcdst)),$(srcdst))
1323
1324# _INSTFUN
1325ifdef $(srcsrc)_INSTFUN
1326instfun := $(srcsrc)_INSTFUN
1327else
1328ifdef $(target)_INSTFUN
1329instfun := $(target)_INSTFUN
1330else
1331instfun := _INSTALL_FILE
1332endif
1333endif
1334
1335# _INST
1336ifdef $(srcsrc)_INST
[424]1337inst := $(patsubst %/,%,$($(srcsrc)_INST))/$(dir $(srcdstdir))
[353]1338else
1339ifdef $(target)_INST
[424]1340inst := $(patsubst %/,%,$($(target)_INST))/$(dir $(srcdstdir))
[353]1341else
[424]1342inst := $(dir $(srcdstdir))
[353]1343endif
1344endif
1345
1346# calc target
[380]1347insdst := $(call $(instfun),$(srcdst),$(target),$(inst),$(PATH_INS))
[424]1348#$(warning instfun=$(instfun) srcdst=$(srcdst) target=$(target) inst=$(inst) => insdst=$(insdst))
[353]1349
[414]1350# mode, uid and gid
1351mode := $(firstword \
1352 $($(target)_$(srcsrc)_MODE.$(bld_trg)) \
1353 $($(target)_$(srcsrc)_MODE) \
1354 $($(target)_$(srcdst)_MODE.$(bld_trg)) \
1355 $($(target)_$(srcdst)_MODE) \
1356 $($(srcsrc)_MODE.$(bld_trg)) \
1357 $($(srcsrc)_MODE) \
1358 $($(srcdst)_MODE.$(bld_trg)) \
1359 $($(srcdst)_MODE) \
1360 $($(target)_MODE.$(bld_trg)) \
1361 $($(target)_MODE))
1362uid := $(firstword \
1363 $($(target)_$(srcsrc)_UID.$(bld_trg)) \
1364 $($(target)_$(srcsrc)_UID) \
1365 $($(target)_$(srcdst)_UID.$(bld_trg)) \
1366 $($(target)_$(srcdst)_UID) \
1367 $($(srcsrc)_UID.$(bld_trg)) \
1368 $($(srcsrc)_UID) \
1369 $($(srcdst)_UID.$(bld_trg)) \
1370 $($(srcdst)_UID) \
1371 $($(target)_UID.$(bld_trg)) \
1372 $($(target)_UID))
1373gid := $(firstword \
1374 $($(target)_$(srcsrc)_GID.$(bld_trg)) \
1375 $($(target)_$(srcsrc)_GID) \
1376 $($(target)_$(srcdst)_GID.$(bld_trg)) \
1377 $($(target)_$(srcdst)_GID) \
1378 $($(srcsrc)_GID.$(bld_trg)) \
1379 $($(srcsrc)_GID) \
1380 $($(srcdst)_GID.$(bld_trg)) \
1381 $($(srcdst)_GID) \
1382 $($(target)_GID.$(bld_trg)) \
1383 $($(target)_GID))
1384
[353]1385# create the command
1386ifdef $(srcsrc)_INSTALLER
1387inscmd := $(call $(srcsrc)_INSTALLER,$(srcsrc),$(insdst),$(target))
1388else
1389ifdef $(target)_INSTALLER
1390inscmd := $(call $(target)_INSTALLER,$(srcsrc),$(insdst),$(target))
1391else
[414]1392inscmd := $$(INSTALL)\
1393 $(if $(uid),-o $(uid))\
1394 $(if $(gid),-g $(gid))\
1395 $(if $(mode),-m $(mode))\
1396 $(srcsrc) $(insdst)
[353]1397endif
1398endif
1399
1400# generate the rule (need double evaluation here)
1401$(eval $(def_install_src_rule))
1402
1403INSTARGET_$(target) += $(insdst)
1404endef
1405
1406
1407## generate the symlink rule
1408define def_install_symlink_rule
1409# the install rule
1410$(insdst) : | $(call DIRDEP,$(dir $(insdst)))
1411 $$(RM) -f $$@
[380]1412 $$(LN_SYMLINK) $(symdst) $(insdst)
[353]1413endef
1414
1415## create one symlink
1416define def_install_symlink
1417
1418# deal with '=>' in the source file name.
[380]1419symdst := $(subst =>, ,$(src))
1420symlnk := $(firstword $(symdst))
1421symdst := $(word $(words $(symdst)),$(symdst))
[353]1422
1423# _INSTFUN
[380]1424ifdef $(symlnk)_INSTFUN
1425instfun := $(symlnk)_INSTFUN
[353]1426else
1427ifdef $(target)_INSTFUN
1428instfun := $(target)_INSTFUN
1429else
1430instfun := _INSTALL_FILE
1431endif
1432endif
1433
1434# _INST
[380]1435ifdef $(symlnk)_INST
1436inst := $(patsubst %/,%,$($(symlnk)_INST))/$(dir $(symlnk))
[353]1437else
1438ifdef $(target)_INST
[380]1439inst := $(patsubst %/,%,$($(target)_INST))/$(dir $(symlnk))
[353]1440else
[380]1441inst := $(dir $(symlnk))
[353]1442endif
1443endif
1444
1445# calc target
[380]1446insdst := $(call $(instfun),$(symlnk),$(target),$(inst),$(PATH_INS))
1447#$(warning symlnk=$(symlnk) symdst=$(symdst) insdst=$(insdst) instfun=$(instfun) inst='$(inst)')
[353]1448
1449# generate the rule (need double evaluation here)
1450$(eval $(def_install_symlink_rule))
1451
1452INSTARGET_$(target) += $(insdst)
1453endef
1454
[412]1455
[380]1456## generate the install rule
1457define def_install_directory_rule
1458# the install rule
1459$(insdst):
1460 $(INSTALL) -d \
1461 $(if $(uid),-o $(uid))\
1462 $(if $(gid),-g $(gid))\
1463 $(if $(mode),-m $(mode))\
1464 $(insdst)
[412]1465
1466.NOTPARALLEL: $(insdst)
[380]1467endef
1468
[412]1469
[380]1470## create one directory
1471define def_install_directory
1472
1473# _INST
1474ifdef $(directory)_INST
1475inst := $(PATH_INS)/$(patsubst %/,%,$($(directory)_INST))
1476else
1477ifdef $(target)_INST
1478inst := $(PATH_INS)/$(patsubst %/,%,$($(target)_INST))
1479else
1480inst := $(PATH_INS)
1481endif
1482endif
1483
1484mode := $(firstword \
1485 $($(target)_$(directory)_MODE.$(bld_trg)) \
1486 $($(target)_$(directory)_MODE) \
1487 $($(directory)_MODE.$(bld_trg)) \
1488 $($(directory)_MODE) \
1489 $($(target)_MODE.$(bld_trg)) \
1490 $($(target)_MODE))
1491uid := $(firstword \
1492 $($(target)_$(directory)_UID.$(bld_trg)) \
1493 $($(target)_$(directory)_UID) \
1494 $($(directory)_UID.$(bld_trg)) \
1495 $($(directory)_UID) \
1496 $($(target)_UID.$(bld_trg)) \
1497 $($(target)_UID))
1498gid := $(firstword \
1499 $($(target)_$(directory)_GID.$(bld_trg)) \
1500 $($(target)_$(directory)_GID) \
1501 $($(directory)_GID.$(bld_trg)) \
1502 $($(directory)_GID) \
1503 $($(target)_GID.$(bld_trg)) \
1504 $($(target)_GID))
1505
1506insdst := $(inst)/$(directory)/
1507#$(warning directory=$(directory) inst=$(inst) insdst=$(insdst) mode=$(mode) gid=$(gid) uid=$(uid))
1508
1509# generate the rule (need double evaluation here)
1510$(eval $(def_install_directory_rule))
1511
1512INSTARGET_DIRS_$(target) += $(insdst)
1513endef
1514
1515
[353]1516## process one install target.
1517define def_install
1518bld_type := $(firstword $($(target)_BLD_TYPE) $(BUILD_TYPE))
1519bld_trg := $(firstword $($(target)_BLD_TRG) $(BUILD_TARGET))
1520bld_trg_arch:= $(firstword $($(target)_BLD_TRG_ARCH) $(BUILD_TARGET_ARCH))
1521bld_trg_cpu := $(firstword $($(target)_BLD_TRG_CPU) $(BUILD_TARGET_CPU))
1522
1523INSTARGET_$(target) :=
[380]1524INSTARGET_DIRS_$(target) :=
1525
1526$(foreach directory,$($(target)_DIRS) $($(target)_DIRS.$(bld_trg)) $($(target)_DIRS.$(bld_trg_arch)) $($(target)_DIRS.$(bld_trg_cpu)) $($(target)_DIRS.$(bld_type)), \
1527 $(eval $(value def_install_directory)))
1528
[353]1529$(foreach src,$($(target)_SOURCES) $($(target)_SOURCES.$(bld_trg)) $($(target)_SOURCES.$(bld_trg_arch)) $($(target)_SOURCES.$(bld_trg_cpu)) $($(target)_SOURCES.$(bld_type)), \
1530 $(eval $(value def_install_src)))
1531
1532$(foreach src,$($(target)_SYMLINKS) $($(target)_SYMLINKS.$(bld_trg)) $($(target)_SYMLINKS.$(bld_trg_arch)) $($(target)_SYMLINKS.$(bld_trg_cpu)) $($(target)_SYMLINKS.$(bld_type)), \
1533 $(eval $(value def_install_symlink)))
1534
[380]1535_INSTALLS += $(INSTARGET_$(target)) $($(target)_GOALS)
1536_INSTALLS_DIRS += $(INSTARGET_DIRS_$(target))
[353]1537endef
1538
1539## process all install targets
1540$(foreach target, $(INSTALLS) $(INSTALLS.$(BUILD_TARGET)), \
1541 $(eval $(value def_install)))
1542
1543
[72]1544#
[417]1545# PACKING
1546#
1547_PACKING += $(PACKING) $(PACKING.$(BUILD_TARGET))
1548
1549
1550#
[72]1551# DOCS
1552#
1553
1554
1555#
[353]1556# DIRECTORIES
1557#
1558_DIR_ALL := $(sort $(addsuffix /,$(patsubst %/,%,$(_DIRS))) $(dir $(_OUT_FILES) $(_OBJS) $(_INSTALLS)))
[380]1559$(foreach directory,$(_INSTALLS_DIRS), $(eval _DIR_ALL := $(filter-out $(directory),$(_DIR_ALL))))
[353]1560
[380]1561
[353]1562define def_mkdir_rule
1563$(directory):
1564 $(call MSG_L1,Creating directory $$@)
1565 $(MKDIR) -p $$@
[72]1566endef
1567
[353]1568$(foreach directory,$(_DIR_ALL),$(eval $(def_mkdir_rule)))
[72]1569
[183]1570
[72]1571#
[353]1572# NOTHING
[72]1573#
[353]1574do-nothing:
1575 $(call MSG_L1,Did nothing in $(CURDIR))
[72]1576
[183]1577
[75]1578#
[353]1579# CLEAN UP
[75]1580#
[353]1581do-clean:
[380]1582 $(RM) -f $(_OUT_FILES) $(_OBJS) $(_DEPFILES) $(_DEPFILES_INCLUDED) $(_CLEAN_FILES) $(OTHER_CLEAN)
[72]1583
[98]1584
[353]1585#
1586# PASSES (including directory and makefile walking)
1587#
[221]1588
[75]1589## Subdir
1590# @param $(pass) Lowercase pass name.
1591# @param $(PASS) Uppercase pass name.
1592# @param $(subdir) Subdirectory
1593# @param $(tag) tag to attach to the rule name.
1594define def_pass_subdir
[219]1595pass_$(pass)$(tag):: $(dep)
1596 + $(QUIET)$$(MAKE) -C $(subdir) -f $$(notdir $$(firstword $$(wildcard $$(addprefix $(subdir)/,$$(DEFAULT_MAKEFILE))))) pass_$(pass)
[75]1597endef
[72]1598
[75]1599## Submakefile
1600# @param $(pass) Lowercase pass name.
1601# @param $(PASS) Uppercase pass name.
1602# @param $(makefile) Makefile.
1603# @param $(tag) tag to attach to the rule name.
1604define def_pass_makefile
[219]1605pass_$(pass)$(tag):: $(dep)
1606 + $(QUIET)$$(MAKE) -C $(patsubst %/,%,$(dir $(makefile))) -f $(notdir $(makefile)) pass_$(pass)
[75]1607endef
[73]1608
[75]1609## Execute a pass.
1610# @param $(pass) Lowercase pass name.
1611# @param $(PASS) Uppercase pass name.
[353]1612define def_pass_old
[183]1613$(eval SUBDIRS_$(PASS) ?= $(SUBDIRS) $(SUBDIRS.$(BUILD_TARGET)))
1614$(eval SUBDIRS_AFTER_$(PASS) ?= $(SUBDIRS_AFTER) $(SUBDIRS_AFTER.$(BUILD_TARGET)))
1615$(eval MAKEFILES_BEFORE_$(PASS) ?= $(MAKEFILES_BEFORE) $(MAKEFILES_BEFORE.$(BUILD_TARGET)))
1616$(eval MAKEFILES_AFTER_$(PASS) ?= $(MAKEFILES_AFTER) $(MAKEFILES_AFTER.$(BUILD_TARGET)))
[75]1617
1618$(eval tag:=_before)
[219]1619$(eval dep:=)
[183]1620$(foreach subdir,$(SUBDIRS_$(PASS)) $(SUBDIRS_$(PASS).$(BUILD_TARGET)) ,$(eval $(def_pass_subdir)))
1621$(foreach makefile,$(MAKEFILES_BEFORE_$(PASS)) $(MAKEFILES_BEFORE_$(PASS).$(BUILD_TARGET)),$(eval $(def_pass_makefile)))
[75]1622
1623$(eval tag:=_after)
[219]1624$(eval dep:=pass_$(pass)_doit)
[183]1625$(foreach subdir,$(SUBDIRS_AFTER_$(PASS)) $(SUBDIRS_AFTER_$(PASS).$(BUILD_TARGET)) ,$(eval $(def_pass_subdir)))
1626$(foreach makefile,$(MAKEFILES_AFTER_$(PASS)) $(MAKEFILES_AFTER_$(PASS).$(BUILD_TARGET)) ,$(eval $(def_pass_makefile)))
[75]1627
1628.NOTPARALLEL: pass_$(pass)_before pass_$(pass)_after
1629.PHONY: pass_$(pass) pass_$(pass)_before pass_$(pass)_doit pass_$(pass)_after
[353]1630pass_$(pass)_doit: $(PASS_$(PASS)_trgs) $(foreach var,$(PASS_$(PASS)_vars),$(var))
[272]1631pass_$(pass)_this: pass_$(pass)_before
[220]1632 + $(QUIET)$$(MAKE) -f $$(MAKEFILE) pass_$(pass)_doit
1633pass_$(pass)_after:: pass_$(pass)_this
[219]1634pass_$(pass): pass_$(pass)_after
[75]1635
[183]1636endef
1637
[353]1638define def_pass
1639$(eval SUBDIRS_$(PASS) ?= $(SUBDIRS) $(SUBDIRS.$(BUILD_TARGET)))
1640$(eval SUBDIRS_AFTER_$(PASS) ?= $(SUBDIRS_AFTER) $(SUBDIRS_AFTER.$(BUILD_TARGET)))
1641$(eval MAKEFILES_BEFORE_$(PASS) ?= $(MAKEFILES_BEFORE) $(MAKEFILES_BEFORE.$(BUILD_TARGET)))
1642$(eval MAKEFILES_AFTER_$(PASS) ?= $(MAKEFILES_AFTER) $(MAKEFILES_AFTER.$(BUILD_TARGET)))
[183]1643
[353]1644$(eval tag:=_before)
1645$(eval dep:=)
1646$(foreach subdir,$(SUBDIRS_$(PASS)) $(SUBDIRS_$(PASS).$(BUILD_TARGET)) ,$(eval $(def_pass_subdir)))
1647$(foreach makefile,$(MAKEFILES_BEFORE_$(PASS)) $(MAKEFILES_BEFORE_$(PASS).$(BUILD_TARGET)),$(eval $(def_pass_makefile)))
[75]1648
[353]1649$(eval tag:=_after)
1650$(eval dep:=pass_$(pass)_doit)
1651$(foreach subdir,$(SUBDIRS_AFTER_$(PASS)) $(SUBDIRS_AFTER_$(PASS).$(BUILD_TARGET)) ,$(eval $(def_pass_subdir)))
1652$(foreach makefile,$(MAKEFILES_AFTER_$(PASS)) $(MAKEFILES_AFTER_$(PASS).$(BUILD_TARGET)) ,$(eval $(def_pass_makefile)))
[75]1653
[380]1654ifdef KBUILD_SAFE_PARALLEL
[353]1655.NOTPARALLEL: pass_$(pass) pass_$(pass)_before pass_$(pass)_after pass_$(pass)_this
1656.PHONY: pass_$(pass) pass_$(pass)_before pass_$(pass)_after pass_$(pass)_this pass_$(pass)_doit
1657pass_$(pass)_doit: $(PASS_$(PASS)_trgs) $(foreach var,$(PASS_$(PASS)_vars),$(var))
1658pass_$(pass)_this: pass_$(pass)_before
1659 + $(QUIET)$$(MAKE) -f $$(MAKEFILE) pass_$(pass)_doit
1660pass_$(pass)_after:: pass_$(pass)_this
1661pass_$(pass): pass_$(pass)_after
1662else
[388]1663.NOTPARALLEL: pass_$(pass) pass_$(pass)_before pass_$(pass)_after pass_$(pass)_doit
[353]1664.PHONY: pass_$(pass) pass_$(pass)_before pass_$(pass)_after pass_$(pass)_doit
1665pass_$(pass)_doit: pass_$(pass)_before \
1666 $(PASS_$(PASS)_trgs) $(foreach var,$(PASS_$(PASS)_vars),$($(var)))
1667pass_$(pass): \
1668 pass_$(pass)_before \
1669 pass_$(pass)_doit \
[388]1670 pass_$(pass)_after
[353]1671endif
[189]1672
[353]1673#$ (warning pass=$(pass) PASS=$(PASS): $(PASS_$(PASS)_trgs) $(PASS_$(PASS)_trgs) $(foreach var,$(PASS_$(PASS)_vars),$($(var))))
1674endef
[75]1675
[353]1676# Generate the defined passes.
1677$(foreach PASS, $(PASSES), \
1678 $(eval pass := $(PASS_$(PASS)_pass)) \
1679 $(eval $(def_pass)))
[75]1680
[219]1681## Pass order
1682# @param $(pass) Current pass name.
1683# @param $(prev_pass) The previous pass name.
1684define def_pass_order
[380]1685ifdef KBUILD_SAFE_PARALLEL
[353]1686.NOTPARALLEL: pass_$(pass)_order
1687.PHONY: pass_$(pass)_order
[219]1688pass_$(pass)_order: $(pass_prev)
[353]1689 $(call MSG_L1,Pass - $(if $(PASS_$(PASS)),$(PASS_$(PASS)),$(pass)))
[219]1690 + $(QUIET)$$(MAKE) -f $$(MAKEFILE) pass_$(pass)
[353]1691else
1692.NOTPARALLEL: pass_$(pass)_order pass_$(pass)_banner
[388]1693.PHONY: pass_$(pass)_order pass_$(pass)_banner
[353]1694pass_$(pass)_banner:
1695 $(call MSG_L1,Pass - $(if $(PASS_$(PASS)),$(PASS_$(PASS)),$(pass)))
1696pass_$(pass)_order: \
1697 $(pass_prev) \
1698 pass_$(pass)_banner \
1699 pass_$(pass)
1700endif
[219]1701$(eval pass_prev := pass_$(pass)_order)
1702endef
[183]1703
[219]1704## PASS: order
1705# Use dependencies to ensure correct pass order.
1706pass_prev :=
[353]1707$(foreach PASS,$(DEFAULT_PASSES),\
1708 $(eval pass := $(PASS_$(PASS)_pass)) \
1709 $(eval $(def_pass_order)))
[219]1710
[272]1711
[75]1712#
1713# THE MAIN RULES
1714#
[219]1715all_recursive: $(pass_prev)
[75]1716
[130]1717rebuild: clean
[219]1718 + $(MAKE) -f $(firstword $(MAKEFILE_LIST)) all_recursive
[78]1719
[412]1720# @todo make this a non-default pass!
[353]1721uninstall:
1722 $(RM) -f $(_INSTALLS)
[412]1723
[380]1724install: pass_installs
[78]1725
[75]1726# misc shortcuts.
[380]1727targets: bldprogs libraries dlls programs sysmods others installs
[75]1728objects: $(_OBJS)
[222]1729bldprogs: $(_BLDPROGS)
[189]1730libraries: $(_LIBS) $(_IMPORT_LIBS) $(_OTHER_LIBRARIES)
[205]1731dlls: $(_DLLS)
[219]1732programs: $(_PROGRAMS)
[205]1733sysmods: $(_SYSMODS)
[353]1734others: $(_OTHERS)
[380]1735installs: $(_INSTALLS_DIRS) $(_INSTALLS)
[75]1736
1737
[353]1738#
1739# kBuild debugging stuff.
1740#
1741_SPACE := $(subst ., ,.)
1742_TAB := $(subst ., ,.)
1743define _NEWLINE
1744
1745
1746endef
1747NLTAB = $(_NEWLINE)$(TAB)
1748show_targets:
1749 @$(foreach target, $(ALL_TARGETS),\
1750 @$(ECHO) "target: $(target)" $(NLTAB)\
1751 @$(ECHO) " PATH_$(target)=$(PATH_$(target))" $(NLTAB)\
1752 @$(ECHO) " TARGET_$(target)=$(TARGET_$(target))" $(NLTAB)\
1753 @$(ECHO) " INSTARGET_$(target)=$(INSTARGET_$(target))" $(NLTAB)\
[380]1754$(foreach prop,$(PROPS_SINGLE) $(PROPS_ACCUMULATE) OBJS_ CLEAN, \
[353]1755 $(eval _tmp:=$(firstword $($(target)_BLD_TRG) $(BUILD_TARGET))) \
1756 $(if $($(target)_$(prop).$(_tmp)),\
1757 @$(ECHO) " $(target)_$(prop).$(_tmp)=$($(target)_$(prop).$(_tmp))" $(NLTAB)) \
1758 $(if $($(target)_$(prop)), $(NLTAB)@$(ECHO) " $(target)_$(prop)=$($(target)_$(prop))" $(NLTAB)) \
1759)\
1760$(foreach prop,$(PROPS_DEFERRED), \
1761 $(eval _tmp:=$(firstword $($(target)_BLD_TRG) $(BUILD_TARGET))) \
1762 $(if $(value $(target)_$(prop).$(_tmp)),\
1763 @$(ECHO) ' $(target)_$(prop).$(_tmp)=$(value $(TARGET)_$(prop).$(_tmp))' $(NLTAB)) \
1764 $(if $(value $(target)_$(prop)), $(NLTAB)@$(ECHO) ' $(target)_$(prop)=$(value $(target)_$(prop))' $(NLTAB)) \
1765))
1766
1767
1768
1769#
1770# Include dependency files.
1771#
1772$(foreach dep,$(wildcard $(_DEPFILES)),$(eval include $(dep)))
1773
1774
[72]1775# end-of-file-content
[106]1776__footer_kmk__ := target
[72]1777endif # __footer_kmk__
[438]1778
Note: See TracBrowser for help on using the repository browser.