source: trunk/kBuild/footer.kmk@ 448

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

corrected bldprogs to inherit .$(BUILD_PLATFORM) instead of .$(BUILD_TARGET) from the template. Also fixed incorrect inheritance of the default template/tool.

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