source: trunk/kBuild/footer.kmk@ 412

Last change on this file since 412 was 412, checked in by bird, 20 years ago

Template inheritance (_EXTENDS).

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