# $Id: header.kmk 438 2006-05-27 12:48:13Z bird $ ## @file # # kBuild - File included at top of makefile. # # Copyright (c) 2004-2005 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 2 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 __header_kmk__ # start-of-file-content # # default rule # all: all_recursive # # The FORCE rule. # FORCE: # # Try avoid inference rules. # .SUFFIXES: SUFFIXES := # # General purpose macros. # ## get last word in a list. # @returns last word in $1. # @param $1 Word list. lastword = $(word $(words $(1)), $(1)) ## # Newline character(s). define NL endef ## # Tab character. TAB := $(subst ., ,.) ## # Space character. SP := $(subst ., ,.) ## # Checks if two strings are equal. # @returns blank if equal # @returns non-blank if not equal. # @param $1 String 1. # @param $2 String 2 STRCMP = $( # # Assert build type. # ifndef BUILD_TYPE ifndef BUILD_MODE $(error kBuild: You must define BUILD_TYPE!) endif BUILD_TYPE := $(BUILD_MODE) endif ifeq ($(BUILD_TYPE),DEBUG) BUILD_TYPE := debug endif ifeq ($(BUILD_TYPE),RELEASE) BUILD_TYPE := release endif ifeq ($(BUILD_TYPE),PROFILE) BUILD_TYPE := profile endif # # Assert build platform. # _BUILD_PLATFORM_OK := 0 # OS/2 (have uppercase legacy) ifeq ($(BUILD_PLATFORM),OS2) override BUILD_PLATFORM := os2 endif ifeq ($(BUILD_PLATFORM),os2) _BUILD_PLATFORM_OK := 1 endif # Linux ifeq ($(BUILD_PLATFORM),LINUX) $(error kBuild: BUILD_PLATFORM must be all lowercase!) endif ifeq ($(BUILD_PLATFORM),linux) _BUILD_PLATFORM_OK := 1 endif # Win32 ifeq ($(BUILD_PLATFORM),WIN32) $(error kBuild: BUILD_PLATFORM must be all lowercase!) endif ifeq ($(BUILD_PLATFORM),win32) _BUILD_PLATFORM_OK := 1 endif # Win64 ifeq ($(BUILD_PLATFORM),WIN64) $(error kBuild: BUILD_PLATFORM must be all lowercase!) endif ifeq ($(BUILD_PLATFORM),win64) _BUILD_PLATFORM_OK := 1 endif # L4 ifeq ($(BUILD_PLATFORM),L4) $(error kBuild: BUILD_PLATFORM must be all lowercase!) endif ifeq ($(BUILD_PLATFORM),l4) _BUILD_PLATFORM_OK := 1 endif # FreeBSD ifeq ($(BUILD_PLATFORM),FreeBSD) $(error kBuild: BUILD_PLATFORM must be all lowercase!) endif ifeq ($(BUILD_PLATFORM),freebsd) _BUILD_PLATFORM_OK := 1 endif ifeq ($(_BUILD_PLATFORM_OK),0) $(error kBuild: BUILD_PLATFORM value '$(BUILD_PLATFORM)' was not recongized!) endif # Fill in defaults if needed. ifndef BUILD_PLATFORM_ARCH ifeq ($(filter-out win64,$(BUILD_PLATFORM)),) BUILD_PLATFORM_ARCH := amd64 else BUILD_PLATFORM_ARCH := x86 endif endif ifndef BUILD_PLATFORM_CPU ifeq ($(filter-out amd64,$(BUILD_PLATFORM_ARCH)),) BUILD_PLATFORM_CPU := k8 else BUILD_PLATFORM_CPU := i586 endif endif # # Assert target platform. # ifndef BUILD_TARGET # not defined, set to the same as build platform BUILD_TARGET := $(BUILD_PLATFORM) else _BUILD_TARGET_OK := 0 # OS/2 ifeq ($(BUILD_TARGET),OS2) $(error kBuild: BUILD_TARGET must be all lowercase!) endif ifeq ($(BUILD_TARGET),os2) _BUILD_TARGET_OK := 1 endif # Linux ifeq ($(BUILD_TARGET),LINUX) $(error kBuild: BUILD_TARGET must be all lowercase!) endif ifeq ($(BUILD_TARGET),linux) _BUILD_TARGET_OK := 1 endif # Win32 ifeq ($(BUILD_TARGET),WIN32) $(error kBuild: BUILD_TARGET must be all lowercase!) endif ifeq ($(BUILD_TARGET),win32) _BUILD_TARGET_OK := 1 endif # Win64 ifeq ($(BUILD_TARGET),WIN64) $(error kBuild: BUILD_TARGET must be all lowercase!) endif ifeq ($(BUILD_TARGET),win64) _BUILD_TARGET_OK := 1 endif # L4 ifeq ($(BUILD_TARGET),L4) $(error kBuild: BUILD_TARGET must be all lowercase!) endif ifeq ($(BUILD_TARGET),l4) _BUILD_TARGET_OK := 1 endif # FreeBSD ifeq ($(BUILD_TARGET),FreeBSD) $(error kBuild: BUILD_TARGET must be all lowercase!) endif ifeq ($(BUILD_TARGET),freebsd) _BUILD_TARGET_OK := 1 endif ifeq ($(_BUILD_TARGET_OK),0) $(error kBuild: BUILD_TARGET value '$(BUILD_TARGET)' was not recongized!) endif endif # Fill in defaults if needed. ifndef BUILD_TARGET_ARCH BUILD_TARGET_ARCH := x86 endif ifndef BUILD_TARGET_CPU BUILD_TARGET_CPU := i586 endif # Adjust the DEPTH definition first ifeq ($(strip $(DEPTH)),) DEPTH := . endif # # Common definitions. # ifeq ($(filter abspath,$(KMK_FEATURES)),abspath) PATH_CURRENT := $(abspath $(CURDIR)) PATH_ROOT := $(abspath $(PATH_CURRENT)/$(DEPTH)) else PATH_CURRENT := $(CURDIR) # Get the real root path. PATH_ROOT := $(PATH_CURRENT) ifneq ($(DEPTH),.) $(foreach d,$(subst /, ,$(DEPTH)), $(eval PATH_ROOT := $(patsubst %/,%,$(dir $(PATH_ROOT)))) ) endif endif # Subdirectory relative to the root. ifneq ($(PATH_ROOT),$(PATH_CURRENT)) CURSUBDIR := $(patsubst $(PATH_ROOT)/%,%,$(PATH_CURRENT)) else CURSUBDIR := . endif # Output directories. ifndef PATH_OUT_BASE PATH_OUT_BASE := $(PATH_ROOT)/out endif ifndef PATH_OUT ifeq ($(BUILD_PLATFORM_ARCH),x86) ifdef BUILD_TARGET_SUB # (BUILD_TARGET_SUB is not currently recognized by kBuild in any other places.) PATH_OUT := $(PATH_OUT_BASE)/$(BUILD_TARGET)/$(BUILD_TARGET_SUB)/$(BUILD_TYPE) else PATH_OUT := $(PATH_OUT_BASE)/$(BUILD_TARGET)/$(BUILD_TYPE) endif else # !x86 ifdef BUILD_TARGET_SUB # (BUILD_TARGET_SUB is not currently recognized by kBuild in any other places.) PATH_OUT := $(PATH_OUT_BASE)/$(BUILD_TARGET)/$(BUILD_TARGET_ARCH)/$(BUILD_TARGET_SUB)/$(BUILD_TYPE) else PATH_OUT := $(PATH_OUT_BASE)/$(BUILD_TARGET)/$(BUILD_TARGET_ARCH)/$(BUILD_TYPE) endif endif # !x86 endif # !define PATH_OUT PATH_OBJ = $(PATH_OUT)/obj PATH_TARGET = $(PATH_OBJ)/$(CURSUBDIR) PATH_INS = $(PATH_OUT) PATH_BIN = $(PATH_INS)/bin PATH_DLL = $(PATH_INS)/bin PATH_SYS = $(PATH_INS)/bin PATH_LIB = $(PATH_INS)/lib PATH_DOC = $(PATH_INS)/doc # Usually kBuild is external to the source tree. ifndef PATH_KBUILD PATH_KBUILD := $(PATH_ROOT)/kBuild endif ifeq ($(filter abspath,$(KMK_FEATURES)),abspath) PATH_KBUILD := $(abspath $(PATH_KBUILD)) endif # kBuild files which might be of interest. FILE_KBUILD_HEADER := $(PATH_KBUILD)/header.kmk FILE_KBUILD_CONFIG := $(PATH_KBUILD)/config.kmk FILE_KBUILD_FOOTER := $(PATH_KBUILD)/footer.kmk SUFF_DEP := .dep MAKEFILE := $(firstword $(MAKEFILE_LIST)) # # Get rid of the GNU Make default stuff # ifndef KMK_VERSION include $(PATH_KBUILD)/StampOutPredefines.kmk endif # # Build platform setup. # PATH_TOOLS := $(PATH_KBUILD)/bin/$(BUILD_PLATFORM_ARCH).$(BUILD_PLATFORM) # OS/2 ifeq ($(BUILD_PLATFORM),os2) EXEC_X86_WIN32 := innopec.exe HOSTSUFF_EXE := .exe endif # Linux ifeq ($(BUILD_PLATFORM),linux) EXEC_X86_WIN32 := wine HOSTSUFF_EXE := endif # Win32 & Win64 ifeq ($(filter-out win32 win64,$(BUILD_TARGET)),) EXEC_X86_WIN32 := HOSTSUFF_EXE := .exe endif # FreeBSD ifeq ($(BUILD_PLATFORM),freebsd) EXEC_X86_WIN32 := wine HOSTSUFF_EXE := endif # # Build target setup. # ifeq ($(BUILD_TARGET),os2) SUFF_OBJ := .obj SUFF_LIB := .lib SUFF_DLL := .dll SUFF_EXE := .exe SUFF_SYS := .sys SUFF_RES := .res endif ifeq ($(filter-out win32 win64,$(BUILD_TARGET)),) SUFF_OBJ := .obj SUFF_LIB := .lib SUFF_DLL := .dll SUFF_EXE := .exe SUFF_SYS := .sys SUFF_RES := .res endif ifeq ($(BUILD_TARGET),linux) SUFF_OBJ := .o SUFF_LIB := .a SUFF_DLL := .so SUFF_EXE := SUFF_SYS := .a SUFF_RES := endif ifeq ($(BUILD_TARGET),l4) SUFF_OBJ := .o SUFF_LIB := .a SUFF_DLL := .s.so SUFF_EXE := SUFF_SYS := .a SUFF_RES := endif # # Standard kBuild tools. # ifeq ($(MAKE),kmk) MAKE := $(PATH_TOOLS)/kmk$(HOSTSUFF_EXE) endif DEP_EXT := $(PATH_TOOLS)/kDep$(HOSTSUFF_EXE) ifeq ($(filter kDep,$(KMK_BUILTIN)),kDep) DEP := kmk_builtin_kDep else DEP := $(DEP_EXT) endif DEP_IDB_EXT := $(PATH_TOOLS)/kDepIDB$(HOSTSUFF_EXE) ifeq ($(filter kDepPre,$(KMK_BUILTIN)),kDepIDB) DEP_IDB := $(if kmk_builtin_kDepIDB else DEP_IDB := $(DEP_IDB_EXT) endif DEP_PRE_EXT := $(PATH_TOOLS)/kDepPre$(HOSTSUFF_EXE) ifeq ($(filter kDepPre,$(KMK_BUILTIN)),kDepPre) DEP_PRE := $(if kmk_builtin_kDepPre else DEP_PRE := $(DEP_PRE_EXT) endif APPEND_EXT := $(PATH_TOOLS)/kmk_append$(HOSTSUFF_EXE) ifeq ($(filter append,$(KMK_BUILTIN)),append) APPEND := kmk_builtin_append else APPEND := $(APPEND_EXT) endif CAT_EXT := $(PATH_TOOLS)/kmk_cat$(HOSTSUFF_EXE) ifeq ($(filter cat,$(KMK_BUILTIN)),cat) CAT := kmk_builtin_cat else CAT := $(CAT_EXT) endif CP_EXT := $(PATH_TOOLS)/kmk_cp$(HOSTSUFF_EXE) ifeq ($(filter cp,$(KMK_BUILTIN)),cp) CP := kmk_builtin_cp else CP := $(CP_EXT) endif ECHO_EXT := $(PATH_TOOLS)/kmk_echo$(HOSTSUFF_EXE) ifeq ($(filter echo,$(KMK_BUILTIN)),echo) ECHO := kmk_builtin_echo else ECHO := $(ECHO_EXT) endif INSTALL_EXT := $(PATH_TOOLS)/kmk_install$(HOSTSUFF_EXE) ifeq ($(filter install,$(KMK_BUILTIN)),install) INSTALL := kmk_builtin_install else INSTALL := $(INSTALL_EXT) endif LN_EXT := $(PATH_TOOLS)/kmk_ln$(HOSTSUFF_EXE) ifeq ($(filter ln,$(KMK_BUILTIN)),ln) LN := kmk_builtin_ln else LN := $(LN_EXT) endif MKDIR_EXT := $(PATH_TOOLS)/kmk_mkdir$(HOSTSUFF_EXE) ifeq ($(filter mkdir,$(KMK_BUILTIN)),mkdir) MKDIR := kmk_builtin_mkdir else MKDIR := $(MKDIR_EXT) endif MV_EXT := $(PATH_TOOLS)/kmk_mv$(HOSTSUFF_EXE) ifeq ($(filter mv,$(KMK_BUILTIN)),mv) MV := kmk_builtin_mv else MV := $(MV_EXT) endif RM_EXT := $(PATH_TOOLS)/kmk_rm$(HOSTSUFF_EXE) ifeq ($(filter rm,$(KMK_BUILTIN)),rm) RM := kmk_builtin_rm else RM := $(RM_EXT) endif SED_EXT := $(PATH_TOOLS)/kmk_sed$(HOSTSUFF_EXE) ifeq ($(filter sed,$(KMK_BUILTIN)),sed) SED := kmk_builtin_sed else SED := $(SED_EXT) endif # Our default shell is the Almquist shell from *BSD. ASH := $(PATH_TOOLS)/kmk_ash$(HOSTSUFF_EXE) MAKESHELL := $(ASH) SHELL := $(ASH) export SHELL MAKESHELL # Symlinking is problematic on some platforms... LN_SYMLINK := $(LN) -s # # Message macros. # ifndef BUILD_QUIET ifdef BUILD_DEBUG BUILD_VERBOSE := 9 endif MSG_L1 = @$(ECHO) "kBuild: $1" ifdef BUILD_VERBOSE MSG_L2 = @$(ECHO) "kBuild: $1" QUIET := else QUIET := @ MSG_L2 = endif ifdef BUILD_DEBUG MSG_L3 = @$(ECHO) "kBuild: $1" else MSG_L3 = endif else QUIET := MSG_L1 = MSG_L2 = MSG_L3 = endif ## ABSPATH - make paths absolute. # This implementation is clumsy and doesn't resolve '..' and '.' components. # # @param $1 The paths to make absolute. ifeq ($(filter abspath,$(KMK_FEATURES)),abspath) ABSPATH = $(abspath $(1)) else ABSPATH = $(foreach path,$(1)\ ,$(strip $(if $(subst <,,$(firstword $(subst /, ,<$(path)))),\ $(if $(patsubst %:,,$(firstword $(subst :,: ,$(path)))),$(PATH_CURRENT)/$(path),$(path)),\ $(path)))) endif ## DIRDEP - make create directory dependencies. # # @param $1 The paths to the directories which must be created. ifeq ($(filter-out win32 win64,$(BUILD_PLATFORM)),) DIRDEP = $(patsubst %/,%,$(1)) else DIRDEP = $(foreach path,$(patsubst %/,%,$(1)),$(path)/) endif ## Cygwin kludge. # This converts /cygdrive/x/% to x:%. # # @param $1 The paths to make native. # @remark This macro is pretty much obsolete since we don't use cygwin base make. ifneq ($(patsubst /cygdrive/%,%,$(CURDIR)),$(CURDIR)) CYGPATHMIXED = $(foreach path,$(1)\ ,$(if $(patsubst /cygdrive/%,,$(path)),$(path),$(patsubst $(strip $(firstword $(subst /, ,$(patsubst /cygdrive/%,%,$(path)))))/%,$(strip $(firstword $(subst /, ,$(patsubst /cygdrive/%,%,$(path))))):/%,$(patsubst /cygdrive/%,%,$(path))))) else CYGPATHMIXED = $(1) endif # # Initialize some of the globals which the Config.kmk and # others can add stuff to if they like for processing in the footer. # ## ALL_TARGET # This is the list of all targets. ALL_TARGETS := ## TEMPLATE_PATHS # List a paths (separated by space) where templates can be found. TEMPLATE_PATHS := ## TOOL_PATHS # List of paths (separated by space) where tools can be found. TOOL_PATHS := ## SDK_PATHS # List of paths (separated by space) where SDKs can be found. SDK_PATHS := ## Proritized list of the default makefile when walking subdirectories. # The user can overload this list. DEFAULT_MAKEFILE := Makefile.kmk makefile.kmk Makefile makefile ## PROPS_SINGLE # The list of non-accumulative target properties. # A Config.kmk file can add it's own properties to this list and kBuild # will do the necessary inheritance from templates to targets. PROPS_SINGLE := TOOL ARTOOL CTOOL CXXTOOL ASTOOL LDTOOL INST NOINST ## PROPS_DEFERRED # This list of non-accumulative target properties which are functions, # and thus should not be expanded until the very last moment. PROPS_DEFERRED := INSTFUN INSTALLER ## PROPS_ACCUMULATE # The list of accumulative target properties. # A Config.kmk file can add it's own properties to this list and kBuild # will do the necessary inheritance from templates to targets. PROPS_ACCUMULATE := \ SDKS DEFS INCS SOURCES \ COPTS CFLAGS CDEFS CINCS CXXOPTS CXXFLAGS CXXDEFS CXXINCS \ ASOPTS ASFLAGS ASDEFS ASINCS \ LDFLAGS LIBS LIBPATH \ BLD_TYPE BLD_TRG BLD_TRG_ARCH BLD_TRG_CPU \ SYSSUFF EXESUFF DLLSUFF LIBSUFF ARLIBSUFF \ ## PROPS_TOOLS # This is a subset of the other PROPS PROPS_TOOLS := TOOL CTOOL CXXTOOL ASTOOL ARTOOL LDTOOL # # Pass configuration. # # The PASS__trgs variable is listing the targets. # The PASS__vars variable is listing the target variables. # The PASS__pass variable is the lowercased passname. # ## PASS: bldprogs # This pass builds targets which are required for building the rest. PASS_BLDPROGS := Build Programs PASS_BLDPROGS_trgs := PASS_BLDPROGS_vars := _BLDPROGS PASS_BLDPROGS_pass := bldprogs ## PASS: libraries # This pass builds library targets. PASS_LIBRARIES := Libraries PASS_LIBRARIES_trgs := PASS_LIBRARIES_vars := _LIBS _IMPORT_LIBS _OTHER_LIBRARIES PASS_LIBRARIES_pass := libraries ## PASS: binaries # This pass builds dll targets. PASS_DLLS := DLLs PASS_DLLS_trgs := PASS_DLLS_vars := _DLLS _OTHER_DLLS PASS_DLLS_pass := dlls ## PASS: binaries # This pass builds binary targets, i.e. programs, system modules and stuff. PASS_BINARIES := Programs PASS_BINARIES_trgs := PASS_BINARIES_vars := _PROGRAMS _SYSMODS _OTHER_BINARIES PASS_BINARIES_pass := binaries ## PASS: others # This pass builds other targets. PASS_OTHERS := Other Stuff PASS_OTHERS_trgs := PASS_OTHERS_vars := _OTHERS PASS_OTHERS_pass := others ## PASS: install # This pass installs the built entities to a sandbox area. PASS_INSTALLS := Install PASS_INSTALLS_trgs := PASS_INSTALLS_vars := _INSTALLS_DIRS _INSTALLS PASS_INSTALLS_pass := installs ## PASS: packing # This pass processes custom packing rules. PASS_PACKING := Packing PASS_PACKING_trgs := PASS_PACKING_vars := _PACKING PASS_PACKING_pass := packing #alias packing: pass_packing ## PASS: clean # This pass removes all generated files. PASS_CLEAN := Clean PASS_CLEAN_trgs := do-clean PASS_CLEAN_vars := PASS_CLEAN_pass := clean # alias clean: pass_clean ## PASS: nothing # This pass just walks the tree. PASS_NOTHING := Nothing PASS_NOTHING_trgs := do-nothing PASS_NOTHING_vars := PASS_NOTHING_pass := nothing # alias nothing: pass_nothing ## DEFAULT_PASSES # The default passes and their order. DEFAULT_PASSES := BLDPROGS LIBRARIES DLLS BINARIES OTHERS INSTALLS ## PASSES # The passes that should be defined. This must include # all passes mentioned by DEFAULT_PASSES. PASSES := $(DEFAULT_PASSES) NOTHING CLEAN # # This is how we find the closest config.kmk. # It's a little hacky but I think it works fine. # _CFGDIR := . _CFGFILES := ./Config.kmk ./config.kmk define def_include_config $(eval _CFGDIR := $(_CFGDIR)/$(dir)) _CFGFILES += $(_CFGDIR)/Config.kmk $(_CFGDIR)/config.kmk endef # walk down the _RELATIVE_ path specified by DEPTH. $(foreach dir,$(subst /, ,$(DEPTH)), $(eval $(def_include_config)) ) # add the default config file. _CFGFILE := $(firstword $(wildcard $(_CFGFILES) $(FILE_KBUILD_CONFIG))) _CFGFILES := _CFGDIR := ifeq ($(_CFGFILE),) $(error kBuild: no Config.kmk file found! Check the DEPTH: DEPTH='$(DEPTH)' PATH_CURRENT='$(PATH_CURRENT)') endif # Include the config.kmk we found file (or the default one). include $(_CFGFILE) # end-of-file-content __header_kmk__ := 1 endif # __header_kmk__