source: trunk/kBuild/footer.kmk@ 436

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

fixed install problem.

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