# $Id: footer.kmk 782 2007-01-24 20:19:57Z bird $ ## @file # # kBuild - File included at top of makefile. # # Copyright (c) 2004-2007 knut st. osmundsen # # # This file is part of kBuild. # # kBuild is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version source of the License, or # (at your option) any later version. # # kBuild is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with kBuild; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # # ifndef __footer_kmk__ # start-of-file-content # # Make sure that the core variables we defined in recursive expansion mode # up in header.kmk get expanded before we really start using them. The kBuild # functions added to kmk to speed stuff up assumes that the variables are # expanded here. # PATH_OBJ := $(PATH_OBJ) PATH_TARGET := $(PATH_TARGET) PATH_INS := $(PATH_INS) PATH_BIN := $(PATH_BIN) PATH_DLL := $(PATH_DLL) PATH_SYS := $(PATH_SYS) PATH_LIB := $(PATH_LIB) PATH_DOC := $(PATH_DOC) # # Variables. # (Some of these need initialization before including definitions using them.) # # all targets. ALL_TARGETS += \ $(FETCHES) $(FETCHES.$(BUILD_TARGET)) $(FETCHES.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) \ $(PATCHES) $(PATCHES.$(BUILD_TARGET)) $(PATCHES.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) \ $(BLDPROGS) $(BLDPROGS.$(BUILD_PLATFORM)) $(BLDPROGS.$(BUILD_PLATFORM).$(BUILD_PLATFORM_ARCH)) \ $(LIBRARIES) $(LIBRARIES.$(BUILD_TARGET)) $(LIBRARIES.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) \ $(IMPORT_LIBS) $(IMPORT_LIBS.$(BUILD_TARGET)) $(IMPORT_LIBS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) \ $(DLLS) $(DLLS.$(BUILD_TARGET)) $(DLLS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) \ $(PROGRAMS) $(PROGRAMS.$(BUILD_TARGET)) $(PROGRAMS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) \ $(SYSMODS) $(SYSMODS.$(BUILD_TARGET)) $(SYSMODS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) \ $(INSTALLS) $(INSTALLS.$(BUILD_TARGET)) $(INSTALLS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) \ $(OTHERS) $(OTHERS.$(BUILD_TARGET)) $(OTHERS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) # all $(BUILD_TARGET) targets. _ALL_BUILD_TARGET_TARGETS += \ $(FETCHES) $(FETCHES.$(BUILD_TARGET)) $(FETCHES.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) \ $(PATCHES) $(PATCHES.$(BUILD_TARGET)) $(PATCHES.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) \ $(LIBRARIES) $(LIBRARIES.$(BUILD_TARGET)) $(LIBRARIES.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) \ $(IMPORT_LIBS) $(IMPORT_LIBS.$(BUILD_TARGET)) $(IMPORT_LIBS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) \ $(DLLS) $(DLLS.$(BUILD_TARGET)) $(DLLS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) \ $(PROGRAMS) $(PROGRAMS.$(BUILD_TARGET)) $(PROGRAMS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) \ $(SYSMODS) $(SYSMODS.$(BUILD_TARGET)) $(SYSMODS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) \ $(INSTALLS) $(INSTALLS.$(BUILD_TARGET)) $(INSTALLS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) \ $(OTHERS) $(OTHERS.$(BUILD_TARGET)) $(OTHERS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) # all $(BUILD_TARGET) targets. _ALL_BUILD_PLATFORM_TARGETS += \ $(BLDPROGS) $(BLDPROGS.$(BUILD_PLATFORM)) $(BLDPROGS.$(BUILD_PLATFORM).$(BUILD_PLATFORM_ARCH)) # all targets making use of srcname. _ALL_SRCNAME_TARGETS += \ $(FETCHES) $(FETCHES.$(BUILD_TARGET)) $(FETCHES.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) \ $(PATCHES) $(PATCHES.$(BUILD_TARGET)) $(PATCHES.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) # dependency files. _DEPFILES := # included dependency files. _DEPFILES_INCLUDED := # All kind of output files except for _OBJS and _DEPFILES. # Compiling or linking definition outputting other things that $@ and any # required dependency file must add those output files to this variable. _OUT_FILES := # Files which only requires cleaning up. _CLEAN_FILES := # all of a type _OBJS := _FETCHES := _DOWNLOADS:= _UNPACKS := _PATCHES := _UNFETCHES:= _BLDPROGS := _LIBS := _DLLS := _PROGRAMS := _SYSMODS := _INSTALLS := _INSTALLS_DIRS := _OTHERS := _PACKING := _DIRS := $(PATH_TARGET)/ $(PATH_TARGET) _IMPORT_LIBS := # misc pass_prev := # # Basic macros # ## Figure out the tool for a target. # @param $1 normalized target. # @param $2 tooltype. # @param bld_trg build target. # @param bld_trg_arch build target architecture. _TARGET_TOOL = $(strip $(firstword \ $($(1)_$(2)TOOL.$(bld_trg).$(bld_trg_arch)) \ $($(1)_$(2)TOOL.$(bld_trg)) \ $($(1)_$(2)TOOL) \ $($(1)_TOOL.$(bld_trg).$(bld_trg_arch)) \ $($(1)_TOOL.$(bld_trg)) \ $($(1)_TOOL) \ $($(2)TOOL.$(bld_trg).$(bld_trg_arch)) \ $($(2)TOOL.$(bld_trg)) \ $($(2)TOOL) \ $(TOOL.$(bld_trg).$(bld_trg_arch)) \ $(TOOL.$(bld_trg)) \ $(TOOL) \ )) ## Figure out the actual name of an installed file. # @param $1 The file to install. # @param $2 The target name. # @param $3 The _INST value (can be empty). # @param $4 The default directory to use when $3 is empty. _INSTALL_FILE = $(patsubst %/,%/$(notdir $(1)),$(if $(3),$(PATH_INS)/$(3),$(4)/)) # # Include the additional footer macros when bootstrapping kBuild. # ifndef KMK_VERSION include $(PATH_KBUILD)/gnumake-footer.kmk endif # # Check syntax which leads to weird syntax errors. # ## Check # @param $(target) Target name. define def_check_target ifneq ("$($(target)_TEMPLATE)","$(strip $($(target)_TEMPLATE))") $$(error $(target) have an incorrect template name. Remove any tabs!) endif endef $(foreach target, $(ALL_TARGETS),$(eval $(def_check_target))) # # Include templates # _TEMPLATES := $(TEMPLATE) define def_templates ifdef $(target)_TEMPLATE _TEMPLATES += $($(target)_TEMPLATE) endif endef $(foreach target, $(ALL_TARGETS), $(eval $(def_templates))) _TEMPLATES := $(sort $(_TEMPLATES)) # $ (warning dbg: _TEMPLATES=$(_TEMPLATES)) define def_templates_include ifndef TEMPLATE_$(template) include $(firstword $(foreach path, $(TEMPLATE_PATHS) $(PATH_KBUILD)/templates/, $(wildcard $(path)/$(template).kmk))) endif endef $(foreach template, $(_TEMPLATES), $(eval $(def_templates))) # # Template Inheritance. # define def_template_extends_prop ifndef TEMPLATE_$(template)_$(prop) ifdef TEMPLATE_$(parent)_$(prop) TEMPLATE_$(template)_$(prop) = $$(TEMPLATE_$(parent)_$(prop)) endif endif endef define def_template_extends ifdef TEMPLATE_$(template)_EXTENDS ifndef TEMPLATE_$(template)_EXTENDS_STATUS_ TEMPLATE_$(template)_EXTENDS_STATUS_ := 0 parent := $(strip $(TEMPLATE_$(template)_EXTENDS)) # recursivly process the parent if it's inherting from somebody too. ifdef TEMPLATE_$(parent)_EXTENDS ifneq ($(TEMPLATE_$(parent)_EXTENDS_STATUS_),42) # foreach will create 'template' in a new variable context hiding our current variable. $(foreach template, $(parent), $(eval $(value def_template_extends))) parent := $(strip $(TEMPLATE_$(template)_EXTENDS)) endif endif # inherit properties. $(foreach prop, $(PROPS_SINGLE) $(PROPS_ACCUMULATE_R) $(PROPS_ACCUMULATE_L) $(PROPS_DEFERRED)\ $(addsuffix .$(BUILD_TARGET), $(PROPS_SINGLE) $(PROPS_ACCUMULATE_L) $(PROPS_ACCUMULATE_R) $(PROPS_DEFERRED))\ $(addsuffix .$(BUILD_TARGET).$(BUILD_TARGET_ARCH), $(PROPS_SINGLE) $(PROPS_ACCUMULATE_L) $(PROPS_ACCUMULATE_R) $(PROPS_DEFERRED))\ $(addsuffix .$(BUILD_TARGET_ARCH), $(PROPS_SINGLE) $(PROPS_ACCUMULATE_L) $(PROPS_ACCUMULATE_R) $(PROPS_DEFERRED))\ $(addsuffix .$(BUILD_TARGET_CPU), $(PROPS_SINGLE) $(PROPS_ACCUMULATE_L) $(PROPS_ACCUMULATE_R) $(PROPS_DEFERRED))\ $(addsuffix .$(BUILD_TYPE), $(PROPS_SINGLE) $(PROPS_ACCUMULATE_L) $(PROPS_ACCUMULATE_R) $(PROPS_DEFERRED))\ ,$(eval $(def_template_extends_prop))) # exploits the 2 evaluation, so no value! TEMPLATE_$(template)_EXTENDS_STATUS_ := 42 else # protect against inheritance loops. ifneq ($(TEMPLATE_$(template)_EXTENDS_STATUS_),42) $(error kBuild: inheritance loop! template=$(template)) endif endif endif endef # $ (foreach template, $(_TEMPLATES), $(if TEMPLATE_$(template)_EXTENDS, $(eval $(value def_template_extends)))) $(foreach template, $(_TEMPLATES), $(eval $(value def_template_extends))) # # Common Inheritance # ## Inherit one template property in a non-accumulative manner. # @param $(prop) Property name # @param $(target) Target name # @todo fix the precedence order for some properties. define def_inherit_template_one ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop) ifndef $(target)_$(prop) $(target)_$(prop) := $(TEMPLATE_$($(target)_TEMPLATE)_$(prop)) #$ (warning dbgtarget: $(target)_$(prop):='$(value $(target)_$(prop))' TEMPLATE_$($(target)_TEMPLATE)_$(prop)) endif endif ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg) ifndef $(target)_$(prop).$(bld_trg) #$ (warning dbgsource: $(target)_$(prop).$(bld_trg)="TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg)" TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg)) $(target)_$(prop).$(bld_trg) := $(TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg)) endif endif ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg).$(bld_trg_arch) ifndef $(target)_$(prop).$(bld_trg).$(bld_trg_arch) #$ (warning dbgsource: $(target)_$(prop).$(bld_trg).$(bld_trg_arch)="TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg).$(bld_trg_arch)" TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg).$(bld_trg_arch)) $(target)_$(prop).$(bld_trg).$(bld_trg_arch) := $(TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg).$(bld_trg_arch)) endif endif ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_arch) ifndef $(target)_$(prop).$(bld_trg_arch) #$ (warning dbgsource: $(target)_$(prop).$(bld_trg_arch)="TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_arch)" TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_arch)) $(target)_$(prop).$(bld_trg_arch) := $(TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_arch)) endif endif ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_cpu) ifndef $(target)_$(prop).$(bld_trg_cpu) #$ (warning dbgsource: $(target)_$(prop).$(bld_trg_cpu)="TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_cpu)" TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_cpu)) $(target)_$(prop).$(bld_trg_cpu) := $(TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_cpu)) endif endif endef ## Inherit one template property in a non-accumulative manner, deferred expansion. # @param 1: $(prop) Property name # @param 2: $(target) Target name # @todo fix the precedence order for some properties. # @remark this define relies on double evaluation define def_inherit_template_one_deferred ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop) ifndef $(target)_$(prop) $(target)_$(prop) = $$(TEMPLATE_$($(target)_TEMPLATE)_$(prop)) #$ (warning dbgtarget: $(target)_$(prop):='$(value $(target)_$(prop))' TEMPLATE_$($(target)_TEMPLATE)_$(prop)) endif endif ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg) ifndef $(target)_$(prop).$(bld_trg) #$ (warning dbgsource: $(target)_$(prop).$(bld_trg)="TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg)" TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg)) $(target)_$(prop).$(bld_trg) = $$(TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg)) endif endif ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg).$(bld_trg_arch) ifndef $(target)_$(prop).$(bld_trg).$(bld_trg_arch) #$ (warning dbgsource: $(target)_$(prop).$(bld_trg).$(bld_trg_arch)="TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg).$(bld_trg_arch)" TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg).$(bld_trg_arch)) $(target)_$(prop).$(bld_trg).$(bld_trg_arch) = $$(TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg).$(bld_trg_arch)) endif endif ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_arch) ifndef $(target)_$(prop).$(bld_trg_arch) #$ (warning dbgsource: $(target)_$(prop).$(bld_trg_arch)="TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_arch)" TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_arch)) $(target)_$(prop).$(bld_trg_arch) = $$(TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_arch)) endif endif ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_cpu) ifndef $(target)_$(prop).$(bld_trg_cpu) #$ (warning dbgsource: $(target)_$(prop).$(bld_trg_cpu)="TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_cpu)" TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_cpu)) $(target)_$(prop).$(bld_trg_cpu) = $$(TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_cpu)) endif endif endef ## Inherit one acculumlative template property where the 'most significant' items are at the left end. # @param $(prop) Property name # @param $(target) Target name define def_inherit_template_one_accumulate_l ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop) #$ (warning dbgtype: TEMPLATE_$($(target)_TEMPLATE)_$(prop) $(target)_$(prop)=$($(target)_$(prop)) $(TEMPLATE_$($(target)_TEMPLATE)_$(prop))) $(target)_$(prop) += $$(TEMPLATE_$($(target)_TEMPLATE)_$(prop)) #$ (warning dbgtype: $(target)_$(prop)=$($(target)_$(prop))) endif ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(BUILD_TYPE) #$ (warning dbg4: TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(BUILD_TYPE)) $(target)_$(prop).$(BUILD_TYPE) += $$(TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(BUILD_TYPE)) endif ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg) #$ (warning dbg5: TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg)) $(target)_$(prop).$(bld_trg) += $$(TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg)) endif ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg).$(bld_trg_arch) #$ (warning dbg4: TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg).$(bld_trg_arch)) $(target)_$(prop).$(bld_trg).$(bld_trg_arch) += $$(TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg).$(bld_trg_arch)) endif ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_cpu) #$ (warning dbg5: TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_cpu)) $(target)_$(prop).$(bld_trg_cpu) += $$(TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_cpu)) endif ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_arch) #$ (warning dbg6: TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_arch)) $(target)_$(prop).$(bld_trg_arch) += $$(TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_arch)) endif endef ## Inherit one acculumlative template property where the 'most significant' items are at the right end. # First pass, $(value) referenced. # @param $(prop) Property name # @param $(target) Target name define def_inherit_template_one_accumulate_r1 ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop) $(eval _$(target)_$(prop)_R = $(value $(target)_$(prop))) endif ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(BUILD_TYPE) $(eval _$(target)_$(prop).$(BUILD_TYPE)_R = $(value $(target)_$(prop).$(BUILD_TYPE))) endif ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg) $(eval _$(target)_$(prop).$(bld_trg)_R = $(value $(target)_$(prop).$(bld_trg))) endif ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg).$(bld_trg_arch) $(eval _$(target)_$(prop).$(bld_trg).$(bld_trg_arch)_R = $(value $(target)_$(prop).$(bld_trg).$(bld_trg_arch))) endif ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_cpu) $(eval _$(target)_$(prop).$(bld_trg_cpu)_R = $(value $(target)_$(prop).$(bld_trg_cpu))) endif ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_arch) $(eval _$(target)_$(prop).$(bld_trg_arch)_R = $(value $(target)_$(prop).$(bld_trg_arch))) endif endef ## Inherit one template property the other way around. # Second pass, not $(value) referenced. # @param $(prop) Property name # @param $(target) Target name define def_inherit_template_one_accumulate_r2 ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop) $(target)_$(prop) = $$(TEMPLATE_$($(target)_TEMPLATE)_$(prop)) $$(_$(target)_$(prop)_R) endif ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(BUILD_TYPE) $(target)_$(prop).$(BUILD_TYPE) = $$(TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(BUILD_TYPE)) $$(_$(target)_$(prop).$(BUILD_TYPE)_R) endif ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg) $(target)_$(prop).$(bld_trg) = $$(TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg)) $$(_$(target)_$(prop).$(bld_trg)_R) endif ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg).$(bld_trg_arch) $(target)_$(prop).$(bld_trg).$(bld_trg_arch) = $$(TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg).$(bld_trg_arch)) $$(_$(target)_$(prop).$(bld_trg).$(bld_trg_arch)_R) endif ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_cpu) $(target)_$(prop).$(bld_trg_cpu) = $$(TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_cpu)) $$(_$(target)_$(prop).$(bld_trg_cpu)_R) endif ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_arch) $(target)_$(prop).$(bld_trg_arch) = $$(TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(bld_trg_arch)) $$(_$(target)_$(prop).$(bld_trg_arch)_R) endif endef ## Inherit template properties for on target. # @param $(target) Target name. define def_inherit_template # sanity check. ifdef _$(target)_ALREADY_PROCESSED $(error kBuild: The target $(target) appears more than once in the target lists! Please correct the makefile(s)) endif _$(target)_ALREADY_PROCESSED := 1 # Inherit any default template. ifdef TEMPLATE ifeq ($($(target)_TEMPLATE),) $(eval $(target)_TEMPLATE:=$(TEMPLATE)) endif endif # Expand the template if specified. ifneq ($($(target)_TEMPLATE),) $(foreach prop,$(PROPS_SINGLE),$(eval $(value def_inherit_template_one))) $(foreach prop,$(PROPS_DEFERRED),$(eval $(def_inherit_template_one_deferred))) # exploits the 2 evaluation, so no value! $(foreach prop,$(PROPS_ACCUMULATE_L),$(eval $(def_inherit_template_one_accumulate_l))) # += works fine (better) without value. $(foreach prop,$(PROPS_ACCUMULATE_R),\ $(eval $(value def_inherit_template_one_accumulate_r1))\ $(eval $(def_inherit_template_one_accumulate_r2))\ ) # This is a hack! (but it appears to work) endif endef # Inherit template properties bld_trg := $(BUILD_TARGET) bld_trg_arch := $(BUILD_TARGET_ARCH) bld_trg_cpu := $(BUILD_TARGET_CPU) $(foreach target, $(_ALL_BUILD_TARGET_TARGETS),$(eval $(value def_inherit_template))) bld_trg := $(BUILD_PLATFORM) bld_trg_arch := $(BUILD_PLATFORM_ARCH) bld_trg_cpu := $(BUILD_PLATFORM_CPU) $(foreach target, $(_ALL_BUILD_PLATFORM_TARGETS),$(eval $(value def_inherit_template))) # # Include tools & sdks # _TOOLS := $(TOOL.$(BUILD_TARGET)) $(TOOL.$(BUILD_TARGET_ARCH)) $(TOOL.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) \ $(TOOL.$(BUILD_PLATFORM)) $(TOOL.$(BUILD_PLATFORM_ARCH)) $(TOOL.$(BUILD_PLATFORM).$(BUILD_PLATFORM_ARCH)) \ $(TOOL) _SDKS := $(SDKS.$(BUILD_TARGET)) $(SDKS.$(BUILD_TARGET_ARCH)) $(SDKS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) \ $(SDKS.$(BUILD_PLATFORM)) $(SDKS.$(BUILD_PLATFORM_ARCH)) $(SDKS.$(BUILD_PLATFORM).$(BUILD_PLATFORM_ARCH)) \ $(SDKS.$(BUILD_TYPE)) \ $(SDKS) define def_tools_sdks_target_source $(eval _TOOLS += $(foreach prop, $(PROPS_TOOLS), \ $($(source)_$(prop).$(_bld_trg)) \ $($(target)_$(source)_$(prop).$(_bld_trg)) \ $($(source)_$(prop).$(_bld_trg).$(_bld_trg_arch)) \ $($(target)_$(source)_$(prop).$(_bld_trg).$(_bld_trg_arch)) \ $($(source)_$(prop).$(_bld_trg_arch)) \ $($(target)_$(source)_$(prop).$(_bld_trg_arch)) \ $($(source)_$(prop)) \ $($(target)_$(source)_$(prop)))) $(eval _SDKS += \ $($(source)_SDKS.$(_bld_trg)) \ $($(target)_$(source)_SDKS.$(_bld_trg)) \ $($(source)_SDKS.$(_bld_trg).$(_bld_trg_arch)) \ $($(target)_$(source)_SDKS.$(_bld_trg).$(_bld_trg_arch)) \ $($(source)_SDKS.$(_bld_trg_arch)) \ $($(target)_$(source)_SDKS.$(_bld_trg_arch)) \ $($(source)_SDKS.$(BUILD_TYPE)) \ $($(target)_$(source)_SDKS.$(BUILD_TYPE)) \ $($(source)_SDKS) \ $($(target)_$(source)_SDKS)) endef define def_tools_sdks_target _bld_trg := $(firstword $($(target)_BLD_TRG) $(bld_trg)) _bld_trg_arch := $(firstword $($(target)_BLD_TRG_ARCH) $(bld_trg_arch)) _bld_trg_cpu := $(firstword $($(target)_BLD_TRG_CPU) $(bld_trg_cpu)) $(eval _TOOLS += $(foreach prop, $(PROPS_TOOLS), \ $($(target)_$(prop).$(_bld_trg)) \ $($(target)_$(prop).$(_bld_trg_arch)) \ $($(target)_$(prop).$(_bld_trg).$(_bld_trg_arch)) \ $($(target)_$(prop)))) $(eval _SDKS += \ $($(target)_SDKS.$(_bld_trg)) \ $($(target)_SDKS.$(_bld_trg_arch)) \ $($(target)_SDKS.$(_bld_trg).$(_bld_trg_arch)) \ $($(target)_SDKS)) $(foreach source, \ $($(target)_SOURCES.$(_bld_trg)) \ $($(target)_SOURCES.$(_bld_trg_arch)) \ $($(target)_SOURCES.$(_bld_trg).$(_bld_trg_arch)) \ $($(target)_SOURCES.$(_bld_trg_cpu)) \ $($(target)_SOURCES.$(BUILD_TYPE)) \ $($(target)_SOURCES) \ , $(eval $(value def_tools_sdks_target_source))) endef define def_tools_srcname_target _bld_trg := $(firstword $($(target)_BLD_TRG) $(bld_trg)) _bld_trg_arch := $(firstword $($(target)_BLD_TRG_ARCH) $(bld_trg_arch)) _bld_trg_cpu := $(firstword $($(target)_BLD_TRG_CPU) $(bld_trg_cpu)) $(foreach source, $(notdir\ $($(target)_SOURCES.$(_bld_trg)) \ $($(target)_SOURCES.$(_bld_trg_arch)) \ $($(target)_SOURCES.$(_bld_trg).$(_bld_trg_arch)) \ $($(target)_SOURCES.$(_bld_trg_cpu)) \ $($(target)_SOURCES.$(BUILD_TYPE)) \ $($(target)_SOURCES) \ ), $(eval $(value def_tools_sdks_target_source))) endef bld_trg := $(BUILD_TARGET) bld_trg_arch := $(BUILD_TARGET_ARCH) bld_trg_cpu := $(BUILD_TARGET_CPU) $(foreach target, $(_ALL_BUILD_TARGET_TARGETS), $(eval $(value def_tools_sdks_target))) $(foreach target, $(_ALL_SRCNAME_TARGETS), $(eval $(value def_tools_srcname_target))) bld_trg := $(BUILD_PLATFORM) bld_trg_arch := $(BUILD_PLATFORM_ARCH) bld_trg_cpu := $(BUILD_PLATFORM_CPU) $(foreach target, $(_ALL_BUILD_PLATFORM_TARGETS), $(eval $(value def_tools_sdks_target))) # include TOOLS define def_tools_include ifndef TOOL_$(tool) TOOL_$(tool)_KMK_FILE := $(firstword $(foreach path, $(TOOL_PATHS) $(PATH_KBUILD)/tools, $(wildcard $(path)/$(tool).kmk))) ifeq ($(TOOL_$(tool)_KMK_FILE),) $(error kBuild: Cannot find include file for the tool '$(tool)'! Searched: $(TOOL_PATHS) $(PATH_KBUILD)/tools) endif include $(TOOL_$(tool)_KMK_FILE) endif endef _TOOLS := $(sort $(_TOOLS)) $(foreach tool, $(_TOOLS), $(eval $(value def_tools_include))) # include SDKS define def_sdks_include_one ifndef SDK_$(sdk) SDK_$(sdk)_KMK_FILE := $(firstword $(foreach path, $(SDK_PATHS) $(PATH_KBUILD)/sdks, $(wildcard $(path)/$(sdk).kmk))) ifeq ($(SDK_$(sdk)_KMK_FILE),) $(error kBuild: Cannot find include file for the SDK '$(sdk)'! Searched: $(SDK_PATHS) $(PATH_KBUILD)/sdks) endif include $(SDK_$(sdk)_KMK_FILE) endif endef _SDKS := $(sort $(_SDKS)) $(foreach sdk, $(_SDKS), $(eval $(value def_sdks_include_one))) ## @page pg_fetches Fetching Tools, Sources and Similar. # # The targets listed in the the FETCHES target list have the following attributes: # SOURCES # INST # FETCHTOOL # FETCHFLAGS # FETCHDIR # UNPACKTOOL # UNPACKFLAGS # # As usual the target name is an alias for 'creating' the target. Other # aliases are: # pass_fetches # fetch # unfetch # download # unpack # # @remark # # This is a little bit complex because we must guarantee that if a source file # changes only sligtly we must refetch it and to a proper unpacking of it. It # is also a desire that fetched archives and unpacked files can be deleted to # save space. # # Thus, we must be able to cleanup what we've unpacked should any of the # sources be removed. We do this by maintaining a file listing the files # and directories that was unpacked. This operation is named 'unfetch'. # # We make use of the SIZE and MD5 attributes for each of the sources to # create a digest that is stored in the primary target file. Subsequent # runswill compare their digest with it to decide if a refetch is required. # When a refetch is found necessary, an 'unfetch' is performed first to # clean out old files and directores. Note even changes in source order # will cause a refetch due to the way the digest is constructed and # evaluated. # # By not depending directly on the archives (nor on any unpacked files) # but on a goal made up from the archive name, size and md5, we allow # the user to delete the archives. Naturally, this means we'll have to # check and fetch missing archives before attempting to unpack them. # # @remark # # This feature will *NOT* work correctly with vanilla GNU make becuase # it makes use of includedep to avoid too many unnecessary files. # # @todo # 1. Port md5sum or some equivalent tool and include it in kBuild. # 2. Download corruption / continuation. # 3. It's quite possible that there is one too many indirect dependency now... # ## @todo move this! MD5SUM := md5sum ## generates the fetch rule define def_fetch_src_fetch_rule # Indirect goal for downloading something. .PRECIOUS: $(out) $(out) $($(target)_$(srcname)_FETCH_OUTPUT_): | $($(target)_$(srcname)_FETCH_DEPORD_) $$(call MSG_FETCH_DL,$(target),$(source),$(out)) @## @todo do fancy stuff like download continuation. $$(QUIET)$$(RM) -f $(out) $(out).md5 $($(target)_$(srcname)_FETCH_CMDS_) $$(QUIET2)$(if $(md5),$$(APPEND) $(out).md5 "$(md5) *$(out)") $$(QUIET)$(if $(md5),$$(MD5SUM) -c $(out).md5) # Intermediate goal for making sure the md5 and size matches. it will (re) fetch the archive if necessary. $(out).checked_$(md5)_$(size): $($(target)_$(srcname)_FETCH_DEPEND_) | $($(target)_$(srcname)_FETCH_DEPORD_) $$(call MSG_FETCH_CHK,$(target),$(source),$(out)) $$(QUIET)$$(RM) -f $$@ $(out).md5 @# creates the .md5 we pass to md5sum. $$(QUIET2)$(if $(md5),$$(APPEND) $(out).md5 "$(md5) *$(out)") @# (re)fetch the file if it doesn't exist or if it doesn't matches the md5. @## @todo do fancy stuff like download continuation. $$(QUIET)( test -f $(out) && $(if $(md5),$$(MD5SUM) -c $(out).md5, true) ) \ || ( $$(RM_EXT) -f $(out) \ && $$(MAKE) $(out) -f $(MAKEFILE) --no-print-directory ) $$(QUIET2)$$(APPEND) $$@ _TARGET_$(target)_FETCHED += $(out) $(out).checked_$(md5)_$(size) # Just a little precaution. .NOTPARALLEL: $(out) $(out).checked_$(md5)_$(size) endef ## generates the unpack rule define def_fetch_src_unpack_rule # This is the unpack rule. it has an order-only dependency on the download check. $(out) $($(target)_$(srcname)_UNPACK_OUTPUT_): $($(target)_$(srcname)_UNPACK_DEPEND_) \ | $($(target)_$(srcname)_UNPACK_DEPORD_) $(archive).checked_$(md5)_$(size) $$(call MSG_FETCH_UP,$(target),$(archive),$(inst)) $$(QUIET)$$(RM) -f $(out) @# if the source archive doesn't exist fetch it (can have been deleted to save space). $$(QUIET)test -f $(archive) \ || ( $$(RM_EXT) -f $(archive).checked_$(md5)_$(size) \ && $$(MAKE) $(archive).checked_$(md5)_$(size) -f $(MAKEFILE) --no-print-directory ) $($(target)_$(srcname)_UNPACK_CMDS_) $$(QUIET2)$$(APPEND) $(out) $(notdir $(archive).checked_$(md5)_$(size)) $$(QUIET2)$$(APPEND) $(out) $(notdir $(out)) $(eval _TARGET_$(target)_UNPACKED += $(out)) _TARGET_$(target)_DIGEST := $(_TARGET_$(target)_DIGEST)-$(srcname)_$(md5)_$(size) .NOTPARALLEL: $(out) endef ## Processes a fetch source # define def_fetch_src #$ (warning dbg: def_fetch_src: source='$(source)' target='$(target)') # common srcname := $(notdir $(source)) inst := $(firstword \ $($(target)_$(source)_INST)\ $($(target)_$(srcname)_INST)\ $($(source)_INST)\ $($(srcname)_INST)\ $($(target)_INST)\ ) ifneq ($(patsubst %/,ok,$(inst)),ok) $(error kBuild: Bad or missing INST property for source '$(source)' in target '$(target)': $(inst)) endif INSTARGET_$(target)_$(srcname) := $(inst) fetchdir := $(firstword \ $($(target)_$(source)_FETCHDIR)\ $($(target)_$(srcname)_FETCHDIR)\ $($(source)_FETCHDIR)\ $($(srcname)_FETCHDIR)\ $($(target)_FETCHDIR)\ $(FETCHDIR)\ $(PATH_TARGET)\ ) deps := \ $($(target)_$(source)_DEPS)\ $($(target)_$(srcname)_DEPS)\ $($(source)_DEPS)\ $($(srcname)_DEPS)\ $($(target)_DEPS) md5 := $(firstword \ $($(target)_$(source)_MD5)\ $($(target)_$(srcname)_MD5)\ $($(source)_MD5)\ $($(srcname)_MD5)\ $($(target)_MD5)\ ) size := $(firstword \ $($(target)_$(source)_SIZE)\ $($(target)_$(srcname)_SIZE)\ $($(source)_SIZE)\ $($(srcname)_SIZE)\ $($(target)_SIZE)\ ) dep := # not legal for fetch and unpack tools # # The fetching. # out := $(fetchdir)/$(srcname) archive := $(out) TARGET_$(target)_$(srcname) := $(out) dirdep := $(call DIRDEP,$(fetchdir)) tool := $(firstword \ $($(target)_$(source)_FETCHTOOL)\ $($(target)_$(srcname)_FETCHTOOL)\ $($(target)_$(source)_TOOL)\ $($(target)_$(srcname)_TOOL)\ $($(source)_FETCHTOOL)\ $($(srcname)_FETCHTOOL)\ $($(source)_TOOL)\ $($(srcname)_TOOL)\ $($(target)_FETCHTOOL)\ $($(target)_TOOL)\ ) flags :=\ $(TOOL_$(tool)_FETCHFLAGS)\ $(FETCHFLAGS)\ $($(target)_FETCHFLAGS)\ $($(srcname)_FETCHFLAGS)\ $($(source)_FETCHFLAGS)\ $($(target)_$(srcname)_FETCHFLAGS)\ $($(target)_$(source)_FETCHFLAGS) #$ (warning dbg: target=$(target) source=$(source) $(srcname)=$(srcname) tool=$(tool) out=$(out) flags=$(flags) dirdep=$(dirdep) fetchdir=$(fetchdir) md5=$(md5) size=$(size)) ifndef TOOL_$(tool)_FETCH_CMDS $(warning kBuild: tools: \ 1 $($(target)_$(source)_FETCHTOOL)\ 2 $($(target)_$(srcname)_FETCHTOOL)\ 3 $($(target)_$(source)_TOOL)\ 4 $($(target)_$(srcname)_TOOL)\ 5 $($(source)_FETCHTOOL)\ 6 $($(srcname)_FETCHTOOL)\ 7 $($(source)_TOOL)\ 8 $($(srcname)_TOOL)\ 9 $($(target)_FETCHTOOL)\ 10 $($(target)_TOOL) ) $(error kBuild: TOOL_$(tool)_FETCH_CMDS is not defined. source=$(source) target=$(target) ) endif # call the tool $(target)_$(srcname)_FETCH_CMDS_ := $(TOOL_$(tool)_FETCH_CMDS) $(target)_$(srcname)_FETCH_OUTPUT_ := $(TOOL_$(tool)_FETCH_OUTPUT) $(target)_$(srcname)_FETCH_DEPEND_ := $(TOOL_$(tool)_FETCH_DEPEND) $(deps) $(target)_$(srcname)_FETCH_DEPORD_ := $(TOOL_$(tool)_FETCH_DEPORD) $(dirdep) # generate the fetch rule. $(eval $(def_fetch_src_fetch_rule)) # # The unpacking / installing. # out := $(inst)_kBuild_$(target)_$(srcname)_unpacked.lst dirdep := $(call DIRDEP,$(inst)) tool := $(firstword \ $($(target)_$(source)_UNPACKTOOL)\ $($(target)_$(srcname)_UNPACKTOOL)\ $($(target)_$(source)_TOOL)\ $($(target)_$(srcname)_TOOL)\ $($(source)_UNPACKTOOL)\ $($(srcname)_UNPACKTOOL)\ $($(source)_TOOL)\ $($(srcname)_TOOL)\ $($(target)_UNPACKTOOL)\ $($(target)_TOOL) \ ) ifeq ($(tool),) tool := $(toupper $(subst .,,$(suffix $(subst tar.,TAR,$(srcname))))) $(eval $(value def_tools_include)) endif flags :=\ $(TOOL_$(tool)_UNPACKFLAGS)\ $(UNPACKFLAGS)\ $($(target)_UNPACKFLAGS)\ $($(srcname)_UNPACKFLAGS)\ $($(source)_UNPACKFLAGS)\ $($(target)_$(srcname)_UNPACKFLAGS)\ $($(target)_$(source)_UNPACKFLAGS) #$ (warning dbg: target=$(target) source=$(source) $(srcname)=$(srcname) tool=$(tool) out=$(out) flags=$(flags) dirdep=$(dirdep) inst=$(inst) md5=$(md5) size=$(size)) ifndef TOOL_$(tool)_UNPACK_CMDS $(warning kBuild: tools: \ 1 $($(target)_$(source)_UNPACKTOOL)\ 2 $($(target)_$(srcname)_UNPACKTOOL)\ 3 $($(target)_$(source)_TOOL)\ 4 $($(target)_$(srcname)_TOOL)\ 5 $($(source)_UNPACKTOOL)\ 6 $($(srcname)_UNPACKTOOL)\ 7 $($(source)_TOOL)\ 8 $($(srcname)_TOOL)\ 9 $($(target)_UNPACKTOOL)\ 10 $($(target)_TOOL) \ 11 $(toupper $(subst tar.,TAR,$(ext $(srcname)))) \ ) $(error kBuild: TOOL_$(tool)_UNPACK_CMDS is not defined. source=$(source) target=$(target) ) endif # call the tool $(target)_$(srcname)_UNPACK_CMDS_ := $(TOOL_$(tool)_UNPACK_CMDS) $(target)_$(srcname)_UNPACK_OUTPUT_ := $(TOOL_$(tool)_UNPACK_OUTPUT) $(target)_$(srcname)_UNPACK_DEPEND_ := $(TOOL_$(tool)_UNPACK_DEPEND) $(deps) $(target)_$(srcname)_UNPACK_DEPORD_ := $(TOOL_$(tool)_UNPACK_DEPORD) $(dirdep) # generate the fetch rule. $(eval $(def_fetch_src_unpack_rule)) _DIRS += $(inst) $(fetchdir) endef ## # Define the target level rules for a fetch. # @param target # @param out # @param inst # @param _TARGET_$(target)_UNPACKED # @param _TARGET_$(target)_DIGEST # @param bld_trg # @param bld_trg_arch define def_fetch_rules $(out).lst: $(_TARGET_$(target)_UNPACKED) | $(call DIRDEP,$(inst)) $$(call MSG_FETCH_OK,$(target)) $$(QUIET)$$(RM) -f $$@ $$@.tmp $$(QUIET2)$$(APPEND) $$@.tmp "$(notdir $(out))" $$(QUIET)$(if $(_TARGET_$(target)_UNPACKED),$$(CAT_EXT) $(_TARGET_$(target)_UNPACKED) >> $$@.tmp) $$(QUIET)$$(MV) -f $$@.tmp $$@ $(out)_unfetched: $$(call MSG_UNFETCH,$(target)) $$(QUIET)$$(RM) -f $$(addprefix $(inst),$$(shell $$(CAT_EXT) $(out).lst 2> /dev/null | $$(SED) -e '/\/$$$$/d')) $$(QUIET)$$(RMDIR) -p --ignore-fail-on-non-empty --ignore-fail-on-not-exist $$(dir $$@) \ $$(addprefix $(inst),$$(sort $$(dir $$(shell $$(CAT_EXT) $(out).lst 2> /dev/null)))) $$(QUIET)$$(RM) -f $(out).lst $(out) $$(QUIET)$$(RMDIR) -p --ignore-fail-on-non-empty --ignore-fail-on-not-exist $$(dir $$@) $(out): $(comp-vars _TARGET_$(target)_DIGEST_PREV,_TARGET_$(target)_DIGEST,FORCE) | $(call DIRDEP,$(inst)) $$(QUIET)$$(RM) -f $$@ $$(if $$(_TARGET_$(target)_DIGEST),$$(if $$(wildcard $(out).lst)\ ,$$(call MSG_REFETCH,$(target)),$$(call MSG_FETCH,$(target))),$$(call MSG_UNFETCH,$(target))) $$(QUIET)$$(if $$(wildcard $(out).lst ),$$(MAKE) -f $(MAKEFILE) --no-print-directory $(out)_unfetched) $$(QUIET)$$(if $$(_TARGET_$(target)_DIGEST),$$(MAKE) -f $(MAKEFILE) --no-print-directory $(out).lst,$$(RMDIR) -p --ignore-fail-on-non-empty --ignore-fail-on-not-exist $$(dir $$@)) $$(QUIET2)$$(if $$(_TARGET_$(target)_DIGEST),$$(APPEND) $$@ "_TARGET_$(target)_DIGEST_PREV := $(_TARGET_$(target)_DIGEST)") .NOTPARALLEL: $(out).lst $(out)_unfetched $(out) endef ## # Deal with one fetch target. # @param target # @param bld_trg # @param bld_trg_arch define def_fetch # common INSTARGET_$(target) := $($(target)_INST) ifneq ($(patsubst %/,ok,$(INSTARGET_$(target))),ok) $(error kBuild: Bad or missing INST property for target '$(target)'. \ $(target)_INST='$($(target)_INST)' ($(origin $(target)_INST))) endif _TARGET_$(target)_FETCHED := _TARGET_$(target)_UNPACKED := _TARGET_$(target)_DIGEST := # The 'sources'. #$ (warning dbg fetch: target=$(target) sources=$($(target)_SOURCES) $($(target)_SOURCES.$(BUILD_TYPE)) $($(target)_SOURCES.$(BUILD_TARGET)) $($(target)_SOURCES.$(BUILD_TARGET_ARCH)) $($(target)_SOURCES.$(BUILD_TARGET).$(BUILD_TARGET_ARCH))) $(foreach source,$($(target)_SOURCES) $($(target)_SOURCES.$(BUILD_TYPE)) $($(target)_SOURCES.$(BUILD_TARGET)) $($(target)_SOURCES.$(BUILD_TARGET_ARCH)) $($(target)_SOURCES.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)),\ $(eval $(value def_fetch_src))) # The target. inst := $(INSTARGET_$(target)) out := $(inst)_kBuild_fetch_$(target) $(eval includedep $(out)) $(eval $(def_fetch_rules)) # Define the aliases here (doesn't work if defined in def_fetch_rules, just like includedep). $(target): $(out) $(target)_unfetch: $(out)_unfetched _FETCHES += $(out) _DOWNLOADS += $(_TARGET_$(target)_FETCHED) _UNPACKS += $(_TARGET_$(target)_UNPACKED) _UNFETCHES += $(out)_unfetched _DIRS += $(inst) endef # Walk the FETCH target lists. bld_trg := $(BUILD_TARGET) bld_trg_arch := $(BUILD_TARGET_ARCH) $(foreach target, $(FETCHES) $(FETCHES.$(BUILD_TARGET)) $(FETCHES.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)), \ $(eval $(value def_fetch))) # some aliases. download: $(_DOWNLOADS) unpack: $(_UNPACKS) fetch: $(_FETCHES) unfetch: $(_UNFETCHES) ## ## Patching. ## ## #define def_patch_src # #endef # # ## Deal with one patch target. #define def_patch # #$(foreach source,$($(target)_SOURCES) $($(target)_SOURCES.$(BUILD_TYPE)) $($(target)_SOURCES.$(BUILD_TARGET)) $($(target)_SOURCES.$(BUILD_TARGET_ARCH)) $($(target)_SOURCES.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)),\ # $(eval $(value def_patch_src))) # #_PATCHES += #endef # #$(foreach target, $(PATCHES) $(PATCHES.$(BUILD_TARGET)) $(PATCHES.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)), \ # $(eval $(value def_patch))) # # # Object processing. # ## wrapper the compile command dependency check. ifndef NO_COMPILE_CMDS_DEPS _DEP_COMPILE_CMDS = $(comp-cmds $(target)_$(source)_CMDS_PREV_,$(target)_$(source)_CMDS_,FORCE) else _DEP_COMPILE_CMDS = endif ## Generates the rules for building a specific object, and the aliases # for building a source file. # @param $(obj) The object file. define def_target_source_rule $(obj) $($(target)_$(source)_OUTPUT_): \ $($(target)_$(source)_DEPEND_) \ $(_DEP_COMPILE_CMDS) \ | \ $($(target)_$(source)_DEPORD_) $$(call MSG_COMPILE,$(target),$(source),$$@,$(type)) $$(QUIET)$$(RM) -f $(dep) $(obj) $($(target)_$(source)_OUTPUT_) $(custom_pre) $($(target)_$(source)_CMDS_) $(custom_post) ifndef NO_COMPILE_CMDS_DEPS $$(QUIET2)$$(APPEND) "$(dep)" $$(QUIET2)$$(APPEND) "$(dep)" 'define $(target)_$(source)_CMDS_PREV_' ifeq ($(filter append-dash-n,$(KMK_FEATURES)),append-dash-n) $$(QUIET2)$$(APPEND) -v "$(dep)" '$(target)_$(source)_CMDS_' else $$(QUIET2)$$(APPEND) "$(dep)" '$(subst $(NL),'$(NL)$(TAB)@$(APPEND) "$(dep)" ',$($(target)_$(source)_CMDS_))' endif $$(QUIET2)$$(APPEND) "$(dep)" 'endef' endif $(basename $(notdir $(obj))).o: $(obj) $(basename $(notdir $(obj))).obj: $(obj) endef ## wrapper the link command dependency check. ifndef NO_COMPILE_CMDS_DEPS _DEP_LINK_CMDS = $(comp-cmds $(target)_CMDS_PREV_,$(target)_CMDS_,FORCE) else _DEP_LINK_CMDS = endif ## Generate the link rule for a target. # @param $(target) The normalized target name. # @param $(dirdep) Directories we depend upon begin created before linking. # @param $(dep) The name of the dependency file. # @param $(out) # @param $($(target)_OUTPUT_) Output files from the link. # @param $($(target)_DEPEND_) Dependencies. # @param $($(target)_DEPORD_) Dependencies which should only affect build order. # @param $($(target)_CMDS_) The link commands. # @param $($(target)_CMDS_PREV_) The link commands from the previous run. define def_link_rule $(out) $($(target)_OUTPUT_): \ $($(target)_DEPEND_) \ $(_DEP_LINK_CMDS) \ | \ $($(target)_DEPORD_) $$(call MSG_LINK,$(target),$$@,$(tool_do)) $$(QUIET)$$(RM) -f $(dep) $(out) $($(target)_OUTPUT_) $(custom_pre) $($(target)_CMDS_) $(custom_post) ifndef NO_LINK_CMDS_DEPS $$(QUIET2)$$(APPEND) "$(dep)" 'define $(target)_CMDS_PREV_' ifeq ($(filter append-dash-n,$(KMK_FEATURES)),append-dash-n) $$(QUIET2)$$(APPEND) -v "$(dep)" '$(target)_CMDS_' else $$(QUIET2)$$(APPEND) "$(dep)" '$(subst $(NL),'$(NL)$(TAB)@$(APPEND) "$(dep)" ',$($(target)_CMDS_))' endif $$(QUIET2)$$(APPEND) "$(dep)" 'endef' endif $(basename $(notdir $(out))): $(out) endef ## Generate the link & lib install rule # @param $(target) Normalized target name. # @param $(out) The build target. # @param $(INSTARGET_$(target)) The installation targets. # @param $(mode) The file mode (optional) define def_link_install_rule $(INSTARGET_$(target)) : $(out) | $(call DIRDEP,$(dir $(INSTARGET_$(target)))) $$(call MSG_INST_TRG,$(target),$(out),$$@) $$(QUIET)$$(INSTALL) $$(if $(mode),-m $(mode)) $(out) $$@ ifdef KBUILD_DO_AUTO_INSTALL $(basename $(notdir $(out))): $(INSTARGET_$(target)) endif endef ## Generic macro for processing C, C++ and Assembly sources. # @param $(target) Normalized target name. # @param $(source) Source file name. # @param $(type) Source type. {C,CXX,AS} # @param bld_type Build type. # @param bld_trg Build target. # @param bld_trg_arch Build target arch. # @param bld_trg_cpu Build target cpu. def_target_source_c_cpp_asm_rc_new = $(kb-src-one ) ifdef KMK_VERSION def_target_source_c_cpp_asm_rc_var = def_target_source_c_cpp_asm_rc_new else def_target_source_c_cpp_asm_rc_var = def_target_source_c_cpp_asm_rc_old endif ## Generic macro for processing all target sources. # @param $(target) Normalized target name. # @param $(defpath) # @param much-more... define def_target_sources #$ (warning def_target_sources) # C sources type := C $(foreach source, $(filter %.c , $($(target)_SOURCES) $($(target)_SOURCES.$(bld_trg)) $($(target)_SOURCES.$(bld_trg).$(bld_trg_arch)) $($(target)_SOURCES.$(bld_trg_arch)) $($(target)_SOURCES.$(bld_trg_cpu)) $($(target)_SOURCES.$(bld_type)))\ ,$(eval $(value $(def_target_source_c_cpp_asm_rc_var))) ) # C++ sources type := CXX $(foreach source, $(filter %.cpp %.cxx %.xx, $($(target)_SOURCES) $($(target)_SOURCES.$(bld_trg)) $($(target)_SOURCES.$(bld_trg).$(bld_trg_arch)) $($(target)_SOURCES.$(bld_trg_arch)) $($(target)_SOURCES.$(bld_trg_cpu)) $($(target)_SOURCES.$(bld_type)))\ ,$(eval $(value $(def_target_source_c_cpp_asm_rc_var))) ) # ASM sources type := AS $(foreach source, $(filter %.asm %.s %.S , $($(target)_SOURCES) $($(target)_SOURCES.$(bld_trg)) $($(target)_SOURCES.$(bld_trg).$(bld_trg_arch)) $($(target)_SOURCES.$(bld_trg_arch)) $($(target)_SOURCES.$(bld_trg_cpu)) $($(target)_SOURCES.$(bld_type)))\ ,$(eval $(value $(def_target_source_c_cpp_asm_rc_var))) ) # Resource sources type := RC $(foreach source, $(filter %.rc , $($(target)_SOURCES) $($(target)_SOURCES.$(bld_trg)) $($(target)_SOURCES.$(bld_trg).$(bld_trg_arch)) $($(target)_SOURCES.$(bld_trg_arch)) $($(target)_SOURCES.$(bld_trg_cpu)) $($(target)_SOURCES.$(bld_type)))\ ,$(eval $(value $(def_target_source_c_cpp_asm_rc_var))) ) endef ## Generic macro for generating the install rule(s) for a target # and update the globals with default out. # # @param $(target) Normalized target name. # @param $(out) The output file. # @param $(definst) The default _INST value. # @param $(typevar) The name of the variable with all the root targets of its type. # @remark Only library uses this now. define def_target_install_pluss ifndef $(target)_NOINST INSTARGET_$(target) := $(patsubst %/,%/$(notdir $(out)), \ $(if $($(target)_INST), $(addprefix $(PATH_INS)/,$($(target)_INST)), $(definst)/)) $(eval $(def_link_install_rule)) _INSTALLS += $(INSTARGET_$(target)) ifdef KBUILD_DO_AUTO_INSTALL $(typevar) += $(INSTARGET_$(target)) else $(typevar) += $(out) endif else # _NOINST $(typevar) += $(out) endif _OUT_FILES += $($(target)_OUTPUT_) $(out) _CLEAN_FILES += $($(target)_CLEAN) _OBJS += $($(target)_OBJS_) endef # # LIBRARIES # ## Library (one). # @param $(target) Normalized library (target) name. define def_lib # library basics ## @todo prefix bld_type := $(firstword $($(target)_BLD_TYPE) $(BUILD_TYPE)) bld_trg := $(firstword $($(target)_BLD_TRG) $(BUILD_TARGET)) bld_trg_arch:= $(firstword $($(target)_BLD_TRG_ARCH) $(BUILD_TARGET_ARCH)) bld_trg_cpu := $(firstword $($(target)_BLD_TRG_CPU) $(BUILD_TARGET_CPU)) tool := $(call _TARGET_TOOL,$(target),AR) ifeq ($(tool),) $(error kBuild: Library target $(target) does not have a tool defined!) endif outbase := $(call TARGET_BASE,$(target),$(target)) ifndef PATH_$(target) PATH_$(target) := $(patsubst %/,%,$(dir $(outbase))) else ifneq ($(PATH_$(target)),$(patsubst %/,%,$(dir $(outbase)))) $(error kBuild internal error: PATH_$(target)=$(PATH_$(target)) expected $(patsubst %/,%,$(dir $(outbase)))) endif endif suff := $(firstword\ $($(target)_LIBSUFF.$(bld_trg).$(bld_trg_arch))\ $($(target)_LIBSUFF.$(bld_trg))\ $($(target)_LIBSUFF)\ $(TOOL_$(tool)_ARLIBSUFF.$(bld_trg).$(bld_trg_arch))\ $(TOOL_$(tool)_ARLIBSUFF.$(bld_trg))\ $(TOOL_$(tool)_ARLIBSUFF)\ $(SUFF_LIB)) out := $(outbase)$(suff) TARGET_$(target) := $(out) $(target)_OBJS_ := defpath := $($(target)_PATH) # source -> object $(eval $(value def_target_sources)) # library linking tool := $(call _TARGET_TOOL,$(target),AR) outbase := $(call TARGET_BASE,$(target),$(target)) flags :=\ $(TOOL_$(tool)_ARFLAGS)\ $(TOOL_$(tool)_ARFLAGS.$(bld_type))\ $(ARFLAGS)\ $(ARFLAGS.$(bld_type))\ $($(target)_ARFLAGS)\ $($(target)_ARFLAGS.$(bld_type)) \ $($(target)_ARFLAGS.$(bld_trg)) \ $($(target)_ARFLAGS.$(bld_trg_arch)) \ $($(target)_ARFLAGS.$(bld_trg).$(bld_trg_arch)) \ $($(target)_ARFLAGS.$(bld_trg_cpu)) othersrc := $(filter-out %.c %.cpp %.cxx %.cc %.s %.S %.asm %.o %.obj,\ $($(target)_SOURCES) \ $($(target)_SOURCES.$(bld_trg)) \ $($(target)_SOURCES.$(bld_trg_arch)) \ $($(target)_SOURCES.$(bld_trg).$(bld_trg_arch)) \ $($(target)_SOURCES.$(bld_trg_cpu)) \ $($(target)_SOURCES.$(bld_type))) objs = $(filter %.o %.obj, \ $($(target)_SOURCES) \ $($(target)_SOURCES.$(bld_trg)) \ $($(target)_SOURCES.$(bld_trg_arch)) \ $($(target)_SOURCES.$(bld_trg).$(bld_trg_arch)) \ $($(target)_SOURCES.$(bld_trg_cpu)) \ $($(target)_SOURCES.$(bld_type))) \ $($(target)_OBJS_) dirdep := $(call DIRDEP,$(dir $(out))) ## @todo fix dependencies on makefiles an such deps := $($(target)_DEPS) # Adjust paths if we got a default path. ifneq ($(defpath),) objs := $(call abspathex,$(objs),$(defpath)) deps := $(call abspathex,$(deps),$(defpath)) othersrc := $(call abspathex,$(othersrc),$(defpath)) endif # dependency file dep := $(out)$(SUFF_DEP) ifndef NO_LINK_CMDS_DEPS _DEPFILES_INCLUDED += $(dep) $(if $(wildcard $(dep)),$(eval include $(dep))) endif # check that the tool is defined. ifndef TOOL_$(tool)_LINK_LIBRARY_CMDS $(warning kBuild: tools: \ 1 $($(target)_$(source)TOOL.$(bld_trg).$(bld_trg_arch)) \ 2 $($(target)_$(source)TOOL.$(bld_trg)) \ 3 $($(target)_$(source)TOOL) \ 4 $($(target)_TOOL.$(bld_trg).$(bld_trg_arch)) \ 5 $($(target)_TOOL.$(bld_trg)) \ 6 $($(target)_TOOL) \ 7 $($(source)TOOL) \ 8 $($(source)TOOL.$(bld_trg).$(bld_trg_arch)) \ 9 $($(source)TOOL.$(bld_trg)) \ 10 $(TOOL.$(bld_trg).$(bld_trg_arch)) \ 11 $(TOOL.$(bld_trg)) \ 12 $(TOOL) ) $(error kBuild: TOOL_$(tool)_LINK_LIBRARY_CMDS isn't defined! target=$(target) ) endif # call the tool $(target)_CMDS_ := $(TOOL_$(tool)_LINK_LIBRARY_CMDS) $(target)_OUTPUT_ := $(TOOL_$(tool)_LINK_LIBRARY_OUTPUT) $(target)_DEPEND_ := $(TOOL_$(tool)_LINK_LIBRARY_DEPEND) $(deps) $(objs) $(target)_DEPORD_ := $(TOOL_$(tool)_LINK_LIBRARY_DEPORD) $(dirdep) # generate the link rule. $(eval $(def_link_rule)) # installing and globals definst := $(PATH_LIB) typevar := _LIBS $(eval $(value def_target_install_pluss)) endef # Process libraries tool_do := LINK_LIBRARY mode := 0644 $(foreach target, $(LIBRARIES) $(LIBRARIES.$(BUILD_TARGET)) $(LIBRARIES.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)), $(eval $(value def_lib))) # # Link operations. # ## # Link prolog # # @param $(target) Normalized target name. # @param $(EXT) EXE,DLL,SYS. # @param $(definst) The default _INST value. # @param $(typevar) The name of the variable with all the root targets of its type. define def_link_common # basics bld_type := $(firstword $($(target)_BLD_TYPE) $(BUILD_TYPE)) bld_trg := $(firstword $($(target)_BLD_TRG) $(BUILD_$(bld_trg_base_var))) bld_trg_arch:= $(firstword $($(target)_BLD_TRG_ARCH) $(BUILD_$(bld_trg_base_var)_ARCH)) bld_trg_cpu := $(firstword $($(target)_BLD_TRG_CPU) $(BUILD_$(bld_trg_base_var)_CPU)) tool := $(call _TARGET_TOOL,$(target),LD) outbase := $(call TARGET_BASE,$(target),$(target)) ifndef PATH_$(target) PATH_$(target) := $(patsubst %/,%,$(dir $(outbase))) else ifneq ($(PATH_$(target)),$(patsubst %/,%,$(dir $(outbase)))) $(error kBuild internal error: PATH_$(target)=$(PATH_$(target)) expected $(patsubst %/,%,$(dir $(outbase)))) endif endif suff := $(firstword \ $($(target)_$(EXT)SUFF) \ $($(target)_$(EXT)SUFF) \ $(TOOL_$(tool)_LD$(EXT)SUFF) \ $($(EXTPRE)SUFF_$(EXT))) out := $(outbase)$(suff) TARGET_$(target) := $(out) $(target)_OBJS_ := defpath := $($(target)_PATH) # source -> object $(eval $(value def_target_sources)) # more link stuff. tool := $(call _TARGET_TOOL,$(target),LD) outbase := $(call TARGET_BASE,$(target),$(target)) flags :=\ $(TOOL_$(tool)_LDFLAGS)\ $(TOOL_$(tool)_LDFLAGS.$(bld_type))\ $(TOOL_$(tool)_LDFLAGS.$(bld_trg))\ $(TOOL_$(tool)_LDFLAGS.$(bld_trg_arch))\ $(TOOL_$(tool)_LDFLAGS.$(bld_trg).$(bld_trg_arch))\ $(TOOL_$(tool)_LDFLAGS.$(bld_trg_cpu))\ $(LDFLAGS)\ $(LDFLAGS.$(bld_type))\ $(LDFLAGS.$(bld_trg))\ $(LDFLAGS.$(bld_trg_arch))\ $(LDFLAGS.$(bld_trg).$(bld_trg_arch))\ $(LDFLAGS.$(bld_trg_cpu))\ $($(target)_LDFLAGS)\ $($(target)_LDFLAGS.$(bld_type))\ $($(target)_LDFLAGS.$(bld_trg))\ $($(target)_LDFLAGS.$(bld_trg_arch))\ $($(target)_LDFLAGS.$(bld_trg).$(bld_trg_arch))\ $($(target)_LDFLAGS.$(bld_trg_cpu)) othersrc := $(filter-out %.c %.cpp %.cxx %.cc %.s %.S %.asm %.o %.obj,\ $($(target)_SOURCES)\ $($(target)_SOURCES.$(bld_trg)) \ $($(target)_SOURCES.$(bld_trg_arch)) \ $($(target)_SOURCES.$(bld_trg).$(bld_trg_arch)) \ $($(target)_SOURCES.$(bld_trg_cpu)) \ $($(target)_SOURCES.$(bld_type))) objs = $(filter %.o %.obj, \ $($(target)_SOURCES) \ $($(target)_SOURCES.$(bld_trg)) \ $($(target)_SOURCES.$(bld_trg_arch)) \ $($(target)_SOURCES.$(bld_trg).$(bld_trg_arch)) \ $($(target)_SOURCES.$(bld_trg_cpu)) \ $($(target)_SOURCES.$(bld_type))) \ $($(target)_OBJS_) libs :=\ $($(target)_LIBS.$(bld_trg_cpu))\ $($(target)_LIBS.$(bld_trg).$(bld_trg_arch))\ $($(target)_LIBS.$(bld_trg_arch))\ $($(target)_LIBS.$(bld_trg))\ $($(target)_LIBS.$(bld_type))\ $($(target)_LIBS)\ $(foreach sdk, $($(target)_SDKS.$(bld_trg).$(bld_trg_arch)) \ $($(target)_SDKS.$(bld_trg_arch)) \ $($(target)_SDKS.$(bld_trg)) \ $($(target)_SDKS.$(bld_type)) \ $($(target)_SDKS),\ $(SDK_$(sdk)_LIBS.$(bld_trg_cpu))\ $(SDK_$(sdk)_LIBS.$(bld_trg).$(bld_trg_arch))\ $(SDK_$(sdk)_LIBS.$(bld_trg_arch))\ $(SDK_$(sdk)_LIBS.$(bld_trg))\ $(SDK_$(sdk)_LIBS.$(bld_type))\ $(SDK_$(sdk)_LIBS))\ $(LIBS.$(bld_trg_cpu))\ $(LIBS.$(bld_trg).$(bld_trg_arch))\ $(LIBS.$(bld_trg_arch))\ $(LIBS.$(bld_trg))\ $(LIBS.$(bld_type))\ $(LIBS)\ $(foreach sdk, $(SDKS.$(bld_trg).$(bld_trg_arch)) \ $(SDKS.$(bld_trg_arch)) \ $(SDKS.$(bld_trg)) \ $(SDKS.$(bld_type)) \ $(SDKS),\ $(SDK_$(sdk)_LIBS.$(bld_trg_cpu))\ $(SDK_$(sdk)_LIBS.$(bld_trg).$(bld_trg_arch))\ $(SDK_$(sdk)_LIBS.$(bld_trg_arch))\ $(SDK_$(sdk)_LIBS.$(bld_trg))\ $(SDK_$(sdk)_LIBS.$(bld_type))\ $(SDK_$(sdk)_LIBS))\ $(TOOL_$(tool)_LIBS.$(bld_trg_cpu))\ $(TOOL_$(tool)_LIBS.$(bld_trg).$(bld_trg_arch))\ $(TOOL_$(tool)_LIBS.$(bld_trg_arch))\ $(TOOL_$(tool)_LIBS.$(bld_trg))\ $(TOOL_$(tool)_LIBS.$(bld_type))\ $(TOOL_$(tool)_LIBS) libpath :=\ $($(target)_LIBPATH.$(bld_trg_cpu))\ $($(target)_LIBPATH.$(bld_trg).$(bld_trg_arch))\ $($(target)_LIBPATH.$(bld_trg_arch))\ $($(target)_LIBPATH.$(bld_trg))\ $($(target)_LIBPATH.$(bld_type))\ $($(target)_LIBPATH)\ $(foreach sdk, $($(target)_SDKS.$(bld_trg).$(bld_trg_arch)) \ $($(target)_SDKS.$(bld_trg_arch)) \ $($(target)_SDKS.$(bld_trg)) \ $($(target)_SDKS.$(bld_type)) \ $($(target)_SDKS),\ $(SDK_$(sdk)_LIBPATH.$(bld_trg_cpu))\ $(SDK_$(sdk)_LIBPATH.$(bld_trg).$(bld_trg_arch))\ $(SDK_$(sdk)_LIBPATH.$(bld_trg_arch))\ $(SDK_$(sdk)_LIBPATH.$(bld_trg))\ $(SDK_$(sdk)_LIBPATH.$(bld_type))\ $(SDK_$(sdk)_LIBPATH))\ $(LIBPATH.$(bld_trg_cpu))\ $(LIBPATH.$(bld_trg).$(bld_trg_arch))\ $(LIBPATH.$(bld_trg_arch))\ $(LIBPATH.$(bld_trg))\ $(LIBPATH.$(bld_type))\ $(LIBPATH)\ $(foreach sdk, $(SDKS.$(bld_trg).$(bld_trg_arch)) \ $(SDKS.$(bld_trg_arch)) \ $(SDKS.$(bld_trg)) \ $(SDKS.$(bld_type)) \ $(SDKS),\ $(SDK_$(sdk)_LIBPATH.$(bld_trg_cpu))\ $(SDK_$(sdk)_LIBPATH.$(bld_trg).$(bld_trg_arch))\ $(SDK_$(sdk)_LIBPATH.$(bld_trg_arch))\ $(SDK_$(sdk)_LIBPATH.$(bld_trg))\ $(SDK_$(sdk)_LIBPATH.$(bld_type))\ $(SDK_$(sdk)_LIBPATH))\ $(TOOL_$(tool)_LIBPATH.$(bld_trg_cpu))\ $(TOOL_$(tool)_LIBPATH.$(bld_trg).$(bld_trg_arch))\ $(TOOL_$(tool)_LIBPATH.$(bld_trg_arch))\ $(TOOL_$(tool)_LIBPATH.$(bld_trg))\ $(TOOL_$(tool)_LIBPATH.$(bld_type))\ $(TOOL_$(tool)_LIBPATH) dirdep := $(call DIRDEP,$(dir $(out))) ## @todo fix dependencies deps := $($(target)_DEPS) # Adjust paths if we got a default path. ifneq ($(defpath),) libpath := $(call abspathex,$(libpath),$(defpath)) objs := $(call abspathex,$(objs),$(defpath)) deps := $(call abspathex,$(deps),$(defpath)) othersrc := $(call abspathex,$(othersrc),$(defpath)) # libs are not subject to this because of the the -l stuff. Use $(_PATH)/lib if relative to current dir! endif ## @todo this stuff can't be working. custom_pre := $(strip $(firstword \ $($(target)_CUSTOM_PRE.$(bld_trg).$(bld_trg_arch))\ $($(target)_CUSTOM_PRE.$(bld_trg).$(bld_type))\ $($(target)_CUSTOM_PRE.$(bld_trg))\ $($(target)_CUSTOM_PRE.$(bld_type))\ $($(target)_CUSTOM_PRE)\ $(CUSTOM_PRE.$(bld_trg).$(bld_trg_arch))\ $(CUSTOM_PRE.$(bld_trg).$(bld_type))\ $(CUSTOM_PRE.$(bld_trg))\ $(CUSTOM_PRE.$(bld_type))\ $(CUSTOM_PRE)\ )) custom_post := $(strip $(firstword \ $($(target)_CUSTOM_POST.$(bld_trg).$(bld_trg_arch))\ $($(target)_CUSTOM_POST.$(bld_trg).$(bld_type))\ $($(target)_CUSTOM_POST.$(bld_trg))\ $($(target)_CUSTOM_POST.$(bld_type))\ $($(target)_CUSTOM_POST)\ $(CUSTOM_POST.$(bld_trg).$(bld_trg_arch))\ $(CUSTOM_POST.$(bld_trg).$(bld_type))\ $(CUSTOM_POST.$(bld_trg))\ $(CUSTOM_POST.$(bld_type))\ $(CUSTOM_POST)\ )) # installation targets ifndef $(target)_NOINST INSTARGET_$(target) := $(patsubst %/,%/$(notdir $(out)), \ $(if $($(target)_INST), $(addprefix $(PATH_INS)/,$($(target)_INST)), $(definst)/)) ifdef KBUILD_DO_AUTO_INSTALL $(typevar) += $(INSTARGET_$(target)) else $(typevar) += $(out) endif # generate the install rule $(eval $(def_link_install_rule)) else # NOINST INSTARGET_$(target) := $(typevar) += $(out) endif # NOINST # dependency file dep := $(outbase)$(SUFF_DEP) ifndef NO_LINK_CMDS_DEPS _DEPFILES_INCLUDED += $(dep) $(if $(wildcard $(dep)),$(eval include $(dep))) endif # check that the tool is defined. ifndef TOOL_$(tool)_$(tool_do)_CMDS $(warning kBuild: tools: \ 1 $($(target)_$(source)TOOL.$(bld_trg).$(bld_trg_arch)) \ 2 $($(target)_$(source)TOOL.$(bld_trg)) \ 3 $($(target)_$(source)TOOL) \ 4 $($(target)_TOOL.$(bld_trg).$(bld_trg_arch)) \ 5 $($(target)_TOOL.$(bld_trg)) \ 6 $($(target)_TOOL) \ 7 $($(source)TOOL.$(bld_trg).$(bld_trg_arch)) \ 8 $($(source)TOOL.$(bld_trg)) \ 9 $($(source)TOOL) \ 10 $(TOOL.$(bld_trg).$(bld_trg_arch)) \ 11 $(TOOL.$(bld_trg)) \ 12 $(TOOL) ) $(error kBuild: TOOL_$(tool)_$(tool_do)_CMDS isn't defined! target=$(target) ) endif # call the tool $(target)_CMDS_ := $(TOOL_$(tool)_$(tool_do)_CMDS) $(target)_OUTPUT_ := $(TOOL_$(tool)_$(tool_do)_OUTPUT) $(target)_DEPEND_ := $(TOOL_$(tool)_$(tool_do)_DEPEND) $(deps) $(objs) $(target)_DEPORD_ := $(TOOL_$(tool)_$(tool_do)_DEPORD) $(dirdep) # generate the link rule. $(eval $(def_link_rule)) # Update globals. _OBJS += $($(target)_OBJS_) _OUT_FILES += $($(target)_OUTPUT_) $(out) _CLEAN_FILES += $($(target)_CLEAN) _INSTALLS += $(INSTARGET_$(target)) endef # # BLDPROGS # ## Build program (one). # @param $(target) Normalized target (program) name. define def_bldprog # set NOINST if not forced installation. ifndef $(target)_INST $(target)_NOINST := 1 endif # do the usual stuff. $(eval $(value def_link_common)) endef # Process build programs. EXT := EXE EXTPRE := HOST tool_do := LINK_PROGRAM definst := $(PATH_BIN) typevar := _BLDPROGS mode := 0755 bld_trg_base_var := PLATFORM $(foreach target, $(BLDPROGS) $(BLDPROGS.$(BUILD_PLATFORM)) $(BLDPROGS.$(BUILD_PLATFORM).$(BUILD_PLATFORM_ARCH)), $(eval $(value def_bldprog))) # # DLLS # # Process dlls EXT := DLL EXTPRE := tool_do := LINK_DLL definst := $(PATH_DLL) typevar := _DLLS mode := 0755 bld_trg_base_var := TARGET $(foreach target, $(DLLS) $(DLLS.$(BUILD_TARGET)) $(DLLS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)), $(eval $(value def_link_common))) # # Process import libraries. # # - On OS/2 and windows these are libraries. # - On other platforms they are fake DLLs. ifeq ($(filter-out nt os2 win win64 win32,$(BUILD_TARGET)),) $(foreach target, $(IMPORT_LIBS) $(IMPORT_LIBS.$(BUILD_TARGET)) $(IMPORT_LIBS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)), $(eval $(value def_lib))) else $(foreach target, $(IMPORT_LIBS) $(IMPORT_LIBS.$(BUILD_TARGET)) $(IMPORT_LIBS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)), $(eval $(value def_link_common))) endif $(foreach target, $(IMPORT_LIBS) $(IMPORT_LIBS.$(BUILD_TARGET)) $(IMPORT_LIBS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)), \ $(eval _IMPORT_LIBS += $(if $(INSTARGET_$(target)),$(INSTARGET_$(target)), $(TARGET_$(target))))) # # PROGRAMS # # Process programs EXT := EXE EXTPRE := tool_do := LINK_PROGRAM definst := $(PATH_BIN) typevar := _PROGRAMS mode := 0755 bld_trg_base_var := TARGET $(foreach target, $(PROGRAMS) $(PROGRAMS.$(BUILD_TARGET)) $(PROGRAMS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)), $(eval $(value def_link_common))) # # SYSMODS # # Process sysmods EXT := SYS EXTPRE := tool_do := LINK_SYSMOD definst := $(PATH_SYS) typevar := _SYSMODS mode := 0644 bld_trg_base_var := TARGET $(foreach target, $(SYSMODS) $(SYSMODS.$(BUILD_TARGET)) $(SYSMODS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)), $(eval $(value def_link_common))) # # OTHERS # _OTHERS = $(OTHERS) $(OTHERS.$(BUILD_TARGET)) $(OTHERS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) # # INSTALLS # ## generate the install rule define def_install_src_rule # the install rule $(insdst) : $(srcsrc) | $(call DIRDEP,$(dir $(insdst))) $$(call MSG_INST_FILE,$(srcsrc),$(insdst)) $$(QUIET)$$(if $$(filter $(INSTALL),$(inscmd)),,$$(RM) -f $$@) $$(QUIET)$(inscmd) endef ## install one file define def_install_src # deal with '=>' in the source file name. srcdst := $(subst =>, ,$(src)) srcsrc := $(firstword $(srcdst)) srcdstdir := $(dir $(word 2,$(srcdst))) srcdst := $(word $(words $(srcdst)),$(srcdst)) # _INSTFUN ifdef $(srcsrc)_INSTFUN instfun := $(srcsrc)_INSTFUN else ifdef $(target)_INSTFUN instfun := $(target)_INSTFUN else instfun := _INSTALL_FILE endif endif # _INST ifdef $(srcsrc)_INST inst := $(patsubst %/,%,$($(srcsrc)_INST))/$(dir $(srcdstdir)) else ifdef $(target)_INST inst := $(patsubst %/,%,$($(target)_INST))/$(dir $(srcdstdir)) else inst := $(dir $(srcdstdir)) endif endif # calc target insdst := $(call $(instfun),$(srcdst),$(target),$(inst),$(PATH_INS)) #$(warning instfun=$(instfun) srcdst=$(srcdst) target=$(target) inst=$(inst) => insdst=$(insdst)) # mode, uid and gid mode := $(firstword \ $($(target)_$(srcsrc)_MODE.$(bld_trg).$(bld_trg_arch)) \ $($(target)_$(srcsrc)_MODE.$(bld_trg)) \ $($(target)_$(srcsrc)_MODE) \ $($(target)_$(srcdst)_MODE.$(bld_trg).$(bld_trg_arch)) \ $($(target)_$(srcdst)_MODE.$(bld_trg)) \ $($(target)_$(srcdst)_MODE) \ $($(srcsrc)_MODE.$(bld_trg).$(bld_trg_arch)) \ $($(srcsrc)_MODE.$(bld_trg)) \ $($(srcsrc)_MODE) \ $($(srcdst)_MODE.$(bld_trg).$(bld_trg_arch)) \ $($(srcdst)_MODE.$(bld_trg)) \ $($(srcdst)_MODE) \ $($(target)_MODE.$(bld_trg).$(bld_trg_arch)) \ $($(target)_MODE.$(bld_trg)) \ $($(target)_MODE)) uid := $(firstword \ $($(target)_$(srcsrc)_UID.$(bld_trg).$(bld_trg_arch)) \ $($(target)_$(srcsrc)_UID.$(bld_trg)) \ $($(target)_$(srcsrc)_UID) \ $($(target)_$(srcdst)_UID.$(bld_trg).$(bld_trg_arch)) \ $($(target)_$(srcdst)_UID.$(bld_trg)) \ $($(target)_$(srcdst)_UID) \ $($(srcsrc)_UID.$(bld_trg).$(bld_trg_arch)) \ $($(srcsrc)_UID.$(bld_trg)) \ $($(srcsrc)_UID) \ $($(srcdst)_UID.$(bld_trg).$(bld_trg_arch)) \ $($(srcdst)_UID.$(bld_trg)) \ $($(srcdst)_UID) \ $($(target)_UID.$(bld_trg).$(bld_trg_arch)) \ $($(target)_UID.$(bld_trg)) \ $($(target)_UID)) gid := $(firstword \ $($(target)_$(srcsrc)_GID.$(bld_trg).$(bld_trg_arch)) \ $($(target)_$(srcsrc)_GID.$(bld_trg)) \ $($(target)_$(srcsrc)_GID) \ $($(target)_$(srcdst)_GID.$(bld_trg).$(bld_trg_arch)) \ $($(target)_$(srcdst)_GID.$(bld_trg)) \ $($(target)_$(srcdst)_GID) \ $($(srcsrc)_GID.$(bld_trg).$(bld_trg_arch)) \ $($(srcsrc)_GID.$(bld_trg)) \ $($(srcsrc)_GID) \ $($(srcdst)_GID.$(bld_trg).$(bld_trg_arch)) \ $($(srcdst)_GID.$(bld_trg)) \ $($(srcdst)_GID) \ $($(target)_GID.$(bld_trg).$(bld_trg_arch)) \ $($(target)_GID.$(bld_trg)) \ $($(target)_GID)) # Adjust the source if we got a default PATH. (This must be done this late!) ifdef $(target)_PATH srcsrc := $(call abspathex,$(srcsrc),$($(target)_PATH)) endif # create the command ifdef $(srcsrc)_INSTALLER inscmd := $(call $(srcsrc)_INSTALLER,$(srcsrc),$(insdst),$(target)) else ifdef $(target)_INSTALLER inscmd := $(call $(target)_INSTALLER,$(srcsrc),$(insdst),$(target)) else inscmd := $$(INSTALL)\ $(if $(uid),-o $(uid))\ $(if $(gid),-g $(gid))\ $(if $(mode),-m $(mode))\ $(srcsrc) $(insdst) endif endif # generate the rule (need double evaluation here) $(eval $(def_install_src_rule)) INSTARGET_$(target) += $(insdst) endef ## generate the symlink rule define def_install_symlink_rule # the install rule $(insdst) : | $(call DIRDEP,$(dir $(insdst))) $$(call MSG_INST_SYM,$(insdst),$(symdst)) $$(QUIET)$$(RM) -f $$@ $$(QUIET)$$(LN_SYMLINK) $(symdst) $(insdst) endef ## create one symlink define def_install_symlink # deal with '=>' in the source file name. symdst := $(subst =>, ,$(src)) symlnk := $(firstword $(symdst)) symdst := $(word $(words $(symdst)),$(symdst)) # _INSTFUN ifdef $(symlnk)_INSTFUN instfun := $(symlnk)_INSTFUN else ifdef $(target)_INSTFUN instfun := $(target)_INSTFUN else instfun := _INSTALL_FILE endif endif # _INST ifdef $(symlnk)_INST inst := $(patsubst %/,%,$($(symlnk)_INST))/$(dir $(symlnk)) else ifdef $(target)_INST inst := $(patsubst %/,%,$($(target)_INST))/$(dir $(symlnk)) else inst := $(dir $(symlnk)) endif endif # calc target insdst := $(call $(instfun),$(symlnk),$(target),$(inst),$(PATH_INS)) #$(warning symlnk=$(symlnk) symdst=$(symdst) insdst=$(insdst) instfun=$(instfun) inst='$(inst)') # generate the rule (need double evaluation here) $(eval $(def_install_symlink_rule)) INSTARGET_$(target) += $(insdst) endef ## generate the install rule define def_install_directory_rule # the install rule $(insdst): $$(call MSG_INST_DIR,$(insdst)) $$(QUIET)$$(INSTALL) -d \ $(if $(uid),-o $(uid))\ $(if $(gid),-g $(gid))\ $(if $(mode),-m $(mode))\ $(insdst) .NOTPARALLEL: $(insdst) endef ## create one directory define def_install_directory # _INST ifdef $(directory)_INST inst := $(PATH_INS)/$(patsubst %/,%,$($(directory)_INST)) else ifdef $(target)_INST inst := $(PATH_INS)/$(patsubst %/,%,$($(target)_INST)) else inst := $(PATH_INS) endif endif mode := $(firstword \ $($(target)_$(directory)_MODE.$(bld_trg).$(bld_trg_arch)) \ $($(target)_$(directory)_MODE.$(bld_trg)) \ $($(target)_$(directory)_MODE) \ $($(directory)_MODE.$(bld_trg).$(bld_trg_arch)) \ $($(directory)_MODE.$(bld_trg)) \ $($(directory)_MODE) \ $($(target)_MODE.$(bld_trg).$(bld_trg_arch)) \ $($(target)_MODE.$(bld_trg)) \ $($(target)_MODE)) uid := $(firstword \ $($(target)_$(directory)_UID.$(bld_trg).$(bld_trg_arch)) \ $($(target)_$(directory)_UID.$(bld_trg)) \ $($(target)_$(directory)_UID) \ $($(directory)_UID.$(bld_trg).$(bld_trg_arch)) \ $($(directory)_UID.$(bld_trg)) \ $($(directory)_UID) \ $($(target)_UID.$(bld_trg).$(bld_trg_arch)) \ $($(target)_UID.$(bld_trg)) \ $($(target)_UID)) gid := $(firstword \ $($(target)_$(directory)_GID.$(bld_trg).$(bld_trg_arch)) \ $($(target)_$(directory)_GID.$(bld_trg)) \ $($(target)_$(directory)_GID) \ $($(directory)_GID.$(bld_trg).$(bld_trg_arch)) \ $($(directory)_GID.$(bld_trg)) \ $($(directory)_GID) \ $($(target)_GID.$(bld_trg).$(bld_trg_arch)) \ $($(target)_GID.$(bld_trg)) \ $($(target)_GID)) insdst := $(inst)/$(directory)/ #$(warning directory=$(directory) inst=$(inst) insdst=$(insdst) mode=$(mode) gid=$(gid) uid=$(uid)) # generate the rule (need double evaluation here) $(eval $(def_install_directory_rule)) INSTARGET_DIRS_$(target) += $(insdst) endef ## process one install target. define def_install # the basics. bld_type := $(firstword $($(target)_BLD_TYPE) $(BUILD_TYPE)) bld_trg := $(firstword $($(target)_BLD_TRG) $(BUILD_TARGET)) bld_trg_arch:= $(firstword $($(target)_BLD_TRG_ARCH) $(BUILD_TARGET_ARCH)) bld_trg_cpu := $(firstword $($(target)_BLD_TRG_CPU) $(BUILD_TARGET_CPU)) INSTARGET_$(target) := INSTARGET_DIRS_$(target) := $(foreach directory,$($(target)_DIRS) $($(target)_DIRS.$(bld_trg)) $($(target)_DIRS.$(bld_trg).$(bld_trg_arch)) $($(target)_DIRS.$(bld_trg_arch)) $($(target)_DIRS.$(bld_trg_cpu)) $($(target)_DIRS.$(bld_type)), \ $(eval $(value def_install_directory))) $(foreach src,$($(target)_SOURCES) $($(target)_SOURCES.$(bld_trg)) $($(target)_SOURCES.$(bld_trg).$(bld_trg_arch)) $($(target)_SOURCES.$(bld_trg_arch)) $($(target)_SOURCES.$(bld_trg_cpu)) $($(target)_SOURCES.$(bld_type)), \ $(eval $(value def_install_src))) $(foreach src,$($(target)_SYMLINKS) $($(target)_SYMLINKS.$(bld_trg)) $($(target)_SYMLINKS.$(bld_trg).$(bld_trg_arch)) $($(target)_SYMLINKS.$(bld_trg_arch)) $($(target)_SYMLINKS.$(bld_trg_cpu)) $($(target)_SYMLINKS.$(bld_type)), \ $(eval $(value def_install_symlink))) _INSTALLS += $(INSTARGET_$(target)) $($(target)_GOALS) _INSTALLS_DIRS += $(INSTARGET_DIRS_$(target)) endef ## process all install targets $(foreach target, $(INSTALLS) $(INSTALLS.$(BUILD_TARGET)) $(INSTALLS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)), \ $(eval $(value def_install))) # # PACKING # _PACKING += $(PACKING) $(PACKING.$(BUILD_TARGET)) $(PACKING.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) # # DOCS # # # DIRECTORIES # _DIR_ALL := $(sort $(addsuffix /,$(patsubst %/,%,$(_DIRS))) $(dir $(_OUT_FILES) $(_OBJS) $(_INSTALLS))) $(foreach directory,$(_INSTALLS_DIRS), $(eval _DIR_ALL := $(filter-out $(directory),$(_DIR_ALL)))) define def_mkdir_rule $(directory): $$(call MSG_MKDIR,$$@) $$(QUIET)$$(MKDIR) -p $$@ endef $(foreach directory,$(_DIR_ALL),$(eval $(def_mkdir_rule))) # # NOTHING # do-nothing: $(call MSG_NOTHING) # # CLEAN UP # do-clean: $(call MSG_CLEAN) $(QUIET)$(RM) -f $(_OUT_FILES) $(_OBJS) $(_DEPFILES) $(_DEPFILES_INCLUDED) $(_CLEAN_FILES) $(OTHER_CLEAN) # # PASSES (including directory and makefile walking) # ## Subdir # @param $(pass) Lowercase pass name. # @param $(PASS) Uppercase pass name. # @param $(subdir) Subdirectory # @param $(tag) tag to attach to the rule name. define def_pass_subdir pass_$(pass)$(tag):: $(dep) + $$(QUIET)$$(MAKE) -C $(subdir) -f $$(notdir $$(firstword $$(wildcard $$(addprefix $(subdir)/,$$(DEFAULT_MAKEFILE))))) pass_$(pass) endef ## Submakefile # @param $(pass) Lowercase pass name. # @param $(PASS) Uppercase pass name. # @param $(makefile) Makefile. # @param $(tag) tag to attach to the rule name. define def_pass_makefile pass_$(pass)$(tag):: $(dep) + $$(QUIET)$$(MAKE) -C $(patsubst %/,%,$(dir $(makefile))) -f $(notdir $(makefile)) pass_$(pass) endef ## Execute a pass. # @param $(pass) Lowercase pass name. # @param $(PASS) Uppercase pass name. define def_pass_old $(eval SUBDIRS_$(PASS) ?= $(SUBDIRS) $(SUBDIRS.$(BUILD_TARGET)) $(SUBDIRS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) ) $(eval SUBDIRS_AFTER_$(PASS) ?= $(SUBDIRS_AFTER) $(SUBDIRS_AFTER.$(BUILD_TARGET)) $(SUBDIRS_AFTER.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) ) $(eval MAKEFILES_BEFORE_$(PASS) ?= $(MAKEFILES_BEFORE) $(MAKEFILES_BEFORE.$(BUILD_TARGET)) $(MAKEFILES_BEFORE.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) ) $(eval MAKEFILES_AFTER_$(PASS) ?= $(MAKEFILES_AFTER) $(MAKEFILES_AFTER.$(BUILD_TARGET)) $(MAKEFILES_AFTER.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) ) $(eval tag:=_before) $(eval dep:=) $(foreach subdir,$(SUBDIRS_$(PASS)) $(SUBDIRS_$(PASS).$(BUILD_TARGET)) $(SUBDIRS_$(PASS).$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) ,$(eval $(def_pass_subdir))) $(foreach makefile,$(MAKEFILES_BEFORE_$(PASS)) $(MAKEFILES_BEFORE_$(PASS).$(BUILD_TARGET)) $(MAKEFILES_BEFORE_$(PASS).$(BUILD_TARGET).$(BUILD_TARGET_ARCH)),$(eval $(def_pass_makefile))) $(eval tag:=_after) $(eval dep:=pass_$(pass)_doit) $(foreach subdir,$(SUBDIRS_AFTER_$(PASS)) $(SUBDIRS_AFTER_$(PASS).$(BUILD_TARGET)) $(SUBDIRS_AFTER_$(PASS).$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) ,$(eval $(def_pass_subdir))) $(foreach makefile,$(MAKEFILES_AFTER_$(PASS)) $(MAKEFILES_AFTER_$(PASS).$(BUILD_TARGET)) $(MAKEFILES_AFTER_$(PASS).$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) ,$(eval $(def_pass_makefile))) .NOTPARALLEL: pass_$(pass)_before pass_$(pass)_after .PHONY: pass_$(pass) pass_$(pass)_before pass_$(pass)_doit pass_$(pass)_after pass_$(pass)_doit: $(PASS_$(PASS)_trgs) $(foreach var,$(PASS_$(PASS)_vars),$(var)) pass_$(pass)_this: pass_$(pass)_before + $$(QUIET)$$(MAKE) -f $$(MAKEFILE) pass_$(pass)_doit pass_$(pass)_after:: pass_$(pass)_this pass_$(pass): pass_$(pass)_after endef define def_pass $(eval SUBDIRS_$(PASS) ?= $(SUBDIRS) $(SUBDIRS.$(BUILD_TARGET)) $(SUBDIRS.$(BUILD_TARGET.$(BUILD_TARGET_ARCH))) ) $(eval SUBDIRS_AFTER_$(PASS) ?= $(SUBDIRS_AFTER) $(SUBDIRS_AFTER.$(BUILD_TARGET)) $(SUBDIRS_AFTER.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) ) $(eval MAKEFILES_BEFORE_$(PASS) ?= $(MAKEFILES_BEFORE) $(MAKEFILES_BEFORE.$(BUILD_TARGET)) $(MAKEFILES_BEFORE.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) ) $(eval MAKEFILES_AFTER_$(PASS) ?= $(MAKEFILES_AFTER) $(MAKEFILES_AFTER.$(BUILD_TARGET)) $(MAKEFILES_AFTER.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) ) $(eval tag:=_before) $(eval dep:=) $(foreach subdir,$(SUBDIRS_$(PASS)) $(SUBDIRS_$(PASS).$(BUILD_TARGET)) $(SUBDIRS_$(PASS).$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) ,$(eval $(def_pass_subdir))) $(foreach makefile,$(MAKEFILES_BEFORE_$(PASS)) $(MAKEFILES_BEFORE_$(PASS).$(BUILD_TARGET)) $(MAKEFILES_BEFORE_$(PASS).$(BUILD_TARGET).$(BUILD_TARGET_ARCH)),$(eval $(def_pass_makefile))) $(eval tag:=_after) $(eval dep:=pass_$(pass)_doit) $(foreach subdir,$(SUBDIRS_AFTER_$(PASS)) $(SUBDIRS_AFTER_$(PASS).$(BUILD_TARGET)) $(SUBDIRS_AFTER_$(PASS).$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) ,$(eval $(def_pass_subdir))) $(foreach makefile,$(MAKEFILES_AFTER_$(PASS)) $(MAKEFILES_AFTER_$(PASS).$(BUILD_TARGET)) $(MAKEFILES_AFTER_$(PASS).$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) ,$(eval $(def_pass_makefile))) ifdef KBUILD_SAFE_PARALLEL .NOTPARALLEL: pass_$(pass) pass_$(pass)_before pass_$(pass)_after pass_$(pass)_this .PHONY: pass_$(pass) pass_$(pass)_before pass_$(pass)_after pass_$(pass)_this pass_$(pass)_doit pass_$(pass)_doit: $(PASS_$(PASS)_trgs) $(foreach var,$(PASS_$(PASS)_vars),$(var)) pass_$(pass)_this: pass_$(pass)_before + $$(QUIET)$$(MAKE) -f $$(MAKEFILE) pass_$(pass)_doit pass_$(pass)_after:: pass_$(pass)_this pass_$(pass): pass_$(pass)_after else .NOTPARALLEL: pass_$(pass) pass_$(pass)_before pass_$(pass)_after pass_$(pass)_doit .PHONY: pass_$(pass) pass_$(pass)_before pass_$(pass)_after pass_$(pass)_doit pass_$(pass)_doit: pass_$(pass)_before \ $(PASS_$(PASS)_trgs) $(foreach var,$(PASS_$(PASS)_vars),$($(var))) pass_$(pass): \ pass_$(pass)_before \ pass_$(pass)_doit \ pass_$(pass)_after endif #$ (warning pass=$(pass) PASS=$(PASS): $(PASS_$(PASS)_trgs) $(PASS_$(PASS)_trgs) $(foreach var,$(PASS_$(PASS)_vars),$($(var)))) endef # Generate the defined passes. $(foreach PASS, $(PASSES), \ $(eval pass := $(PASS_$(PASS)_pass)) \ $(eval $(def_pass))) ## Pass order # @param $(pass) Current pass name. # @param $(prev_pass) The previous pass name. define def_pass_order ifdef KBUILD_SAFE_PARALLEL .NOTPARALLEL: pass_$(pass)_order .PHONY: pass_$(pass)_order pass_$(pass)_order: $(pass_prev) $$(call MSG_PASS,$$(if $$(PASS_$(PASS)),$$(PASS_$(PASS)),$(pass))) + $$(QUIET)$$(MAKE) -f $$(MAKEFILE) pass_$(pass) else .NOTPARALLEL: pass_$(pass)_order pass_$(pass)_banner .PHONY: pass_$(pass)_order pass_$(pass)_banner pass_$(pass)_banner: $$(call MSG_PASS,$$(if $$(PASS_$(PASS)),$$(PASS_$(PASS)),$(pass))) pass_$(pass)_order: \ $(pass_prev) \ pass_$(pass)_banner \ pass_$(pass) endif $(eval pass_prev := pass_$(pass)_order) endef ## PASS: order # Use dependencies to ensure correct pass order. pass_prev := $(foreach PASS,$(DEFAULT_PASSES),\ $(eval pass := $(PASS_$(PASS)_pass)) \ $(eval $(def_pass_order))) # # THE MAIN RULES # all_recursive: $(pass_prev) rebuild: clean + $(MAKE) -f $(firstword $(MAKEFILE_LIST)) all_recursive # @todo make this a non-default pass! uninstall: $(RM) -f $(_INSTALLS) install: pass_installs # misc shortcuts. targets: bldprogs libraries dlls programs sysmods others installs objects: $(_OBJS) bldprogs: $(_BLDPROGS) libraries: $(_LIBS) $(_IMPORT_LIBS) $(_OTHER_LIBRARIES) dlls: $(_DLLS) programs: $(_PROGRAMS) sysmods: $(_SYSMODS) others: $(_OTHERS) installs: $(_INSTALLS_DIRS) $(_INSTALLS) # # kBuild debugging stuff. # _SPACE := $(subst ., ,.) _TAB := $(subst ., ,.) define _NEWLINE endef NLTAB = $(_NEWLINE)$(TAB) show_targets: @$(foreach target, $(ALL_TARGETS),\ @$(ECHO) "target: $(target)" $(NLTAB)\ @$(ECHO) " PATH_$(target)=$(PATH_$(target))" $(NLTAB)\ @$(ECHO) " TARGET_$(target)=$(TARGET_$(target))" $(NLTAB)\ @$(ECHO) " INSTARGET_$(target)=$(INSTARGET_$(target))" $(NLTAB)\ $(foreach prop,$(PROPS_SINGLE) $(PROPS_ACCUMULATE_L) $(PROPS_ACCUMULATE_R) OBJS_ CLEAN, \ $(eval _tmp:=$(firstword $($(target)_BLD_TRG) $(BUILD_TARGET))) \ $(if $($(target)_$(prop).$(_tmp)),\ @$(ECHO) " $(target)_$(prop).$(_tmp)=$($(target)_$(prop).$(_tmp))" $(NLTAB)) \ $(if $($(target)_$(prop)), $(NLTAB)@$(ECHO) " $(target)_$(prop)=$($(target)_$(prop))" $(NLTAB)) \ )\ $(foreach prop,$(PROPS_DEFERRED), \ $(eval _tmp:=$(firstword $($(target)_BLD_TRG) $(BUILD_TARGET))) \ $(if $(value $(target)_$(prop).$(_tmp)),\ @$(ECHO) ' $(target)_$(prop).$(_tmp)=$(value $(TARGET)_$(prop).$(_tmp))' $(NLTAB)) \ $(if $(value $(target)_$(prop)), $(NLTAB)@$(ECHO) ' $(target)_$(prop)=$(value $(target)_$(prop))' $(NLTAB)) \ )) # # Include dependency files. # $(foreach dep,$(wildcard $(_DEPFILES)),$(eval include $(dep))) # end-of-file-content __footer_kmk__ := target endif # __footer_kmk__