source: trunk/kBuild/footer.kmk@ 388

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

A bit of parallel hacking.

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