source: trunk/kBuild/footer.kmk@ 454

Last change on this file since 454 was 450, checked in by bird, 19 years ago

Fixed regression/bug from the inherit defaults change - we didn't include the default tool anylonger.

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