source: trunk/kBuild/footer.kmk@ 455

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

Added arch and cpu to the template to template inheritance. removed some obsolete stuff.

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