source: trunk/kBuild/header.kmk@ 1296

Last change on this file since 1296 was 1296, checked in by bird, 18 years ago

New builtin 'test'.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 30.0 KB
RevLine 
[69]1# $Id: header.kmk 1296 2007-12-01 03:47:44Z bird $
2## @file
3#
[978]4# kBuild - File included at top of a makefile.
[69]5#
[782]6# Copyright (c) 2004-2007 knut st. osmundsen <bird-kBuild-spam@anduin.net>
[69]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
13# the Free Software Foundation; either version 2 of the License, or
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
23# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24#
25#
26
27ifndef __header_kmk__
28# start-of-file-content
[988]29ifdef KBUILD_PROFILE_SELF
30 _KBUILD_TS_HEADER_START := $(nanots ) # just a dummy warm up query
31 $(info prof: since start - since previous - event description)
32 _KBUILD_TS_HEADER_START := $(nanots )
33 _KBUILD_TS_PREV := $(_KBUILD_TS_HEADER_START)
34endif
[69]35
[978]36
[69]37#
[978]38# Check make version before we do anything else.
[69]39#
[978]40ifndef KMK_VERSION
[984]41 $(error kBuild: The kmk default variable KMK_VERSION isn't defined! Make sure you are using 'kmk' and not 'make', 'gmake', 'kmk_gmake', 'dmake' or any other make program)
[978]42endif
43ifneq ($(KBUILD_VERSION_MAJOR).$(KBUILD_VERSION_MINOR),0.1)
44 ifneq ($(KBUILD_VERSION_MAJOR),0)
45 $(warning kBuild: kmk major version mismatch, expected '0' found '$(KBUILD_VERSION_MAJOR)'!)
46 else
47 $(warning kBuild: kmk minor version mismatch, expected '1' found '$(KBUILD_VERSION_MINOR)'!)
48 endif
49endif
[69]50
51#
[978]52# The revision in which this file was last modified.
53# This can be useful when using development versions of kBuild.
[380]54#
[978]55KMK_REVISION := $(patsubst %:,, $Rev: 1296 $ )
[414]56
[978]57
[380]58#
[978]59# Define the default goal.
[69]60#
[978]61all: all_recursive
[69]62
[894]63#
[978]64# The phony FORCE target.
[894]65#
[978]66FORCE:
[72]67
[978]68
[69]69#
[978]70# Enable delete on error and second expansion of prerequisites.
[894]71#
[978]72.DELETE_ON_ERROR:
73
[894]74.SECONDEXPANSION:
75
76
77#
[95]78# General purpose macros.
79#
[204]80
[380]81##
82# Newline character(s).
83define NL
[95]84
[380]85
86endef
87
88##
89# Tab character.
90TAB := $(subst ., ,.)
91
92##
[896]93# Newline + tab characters (for generating commands).
94NLTAB = $(NL)$(TAB)
95
96##
[380]97# Space character.
98SP := $(subst ., ,.)
99
100##
[895]101# Hash character.
102define HASH
103#
104endef
[380]105
[895]106##
107# Colon character.
108COLON := :
109
110##
111# Semicolon character.
112SEMICOLON := ;
113
114##
115# Comma character.
116COMMA := ,
117
118##
119# Dot character.
120DOT := .
121
122##
123# Dollar character.
124DOLLAR := $$
125
126##
127# Equal character.
128EQUAL := =
129
130
[95]131#
[985]132# The OSes, Architectures and CPUs that kBuild recognizes.
[978]133#
134# When kBuild is ported to a new OS or architecture a unique keyword needs
135# to be assigned to it and added here. This strictness is required because
136# this keyword namespace is shared between OSes, architectures, cpus and
[984]137# build types. (PORTME)
[978]138#
[985]139KBUILD_OSES := darwin freebsd l4 linux netbsd nt openbsd os2 solaris win
[992]140KBUILD_ARCHES := x86 amd64 sparc32 sparc64 s390 ppc32 ppc64 mips32 mips64 ia64 hppa32 hppa64 arm alpha
[978]141
142
143#
[585]144# Set default build type.
[69]145#
146ifndef BUILD_TYPE
[978]147 BUILD_TYPE := release
148else
149 ifneq ($(filter $(BUILD_TYPE),$(KBUILD_OSES) $(KBUILD_ARCHES)),)
150 $(error kBuild: The BUILD_TYPE value '$(BUILD_TYPE)' is an OS or architecture!)
[585]151 endif
[978]152 ifneq (.$(words $(BUILD_TYPE)).$(BUILD_TYPE).,.1.$(strip $(BUILD_TYPE)).)
153 $(error kBuild: The BUILD_TYPE value '$(BUILD_TYPE)' contains spaces/tabs!)
154 endif
[72]155endif
[69]156
157
158#
[978]159# Assert valid build platform variables.
[70]160#
[978]161# All these are set by kmk so they shouldn't be any trouble
162# unless the user starts messing about with environment variables.
163#
164ifneq (.$(words $(BUILD_PLATFORM)).$(BUILD_PLATFORM).,.1.$(strip $(BUILD_PLATFORM)).)
165 $(error kBuild: The BUILD_PLATFORM value '$(BUILD_PLATFORM)' contains spaces/tabs!)
[72]166endif
[978]167ifneq ($(words $(filter $(BUILD_PLATFORM),$(KBUILD_OSES))),1)
168 $(error kBuild: BUILD_PLATFORM value '$(BUILD_PLATFORM)' is not recognized (valid: $(KBUILD_OSES)))
169endif
[70]170
[980]171ifneq (.$(words $(BUILD_PLATFORM_ARCH)).$(BUILD_PLATFORM_ARCH).,.1.$(strip $(BUILD_PLATFORM_ARCH)).)
[978]172 $(error kBuild: The BUILD_PLATFORM_ARCH value '$(BUILD_PLATFORM_ARCH)' contains spaces/tabs!)
[329]173endif
[978]174ifneq ($(words $(filter $(BUILD_PLATFORM_ARCH),$(KBUILD_ARCHES))),1)
175 $(error kBuild: BUILD_PLATFORM_ARCH value '$(BUILD_PLATFORM_ARCH)' is not recognized (valid: $(KBUILD_ARCHES)))
[329]176endif
[72]177
[978]178ifeq ($(strip $(BUILD_PLATFORM_CPU)),)
[994]179 BUILD_PLATFORM_CPU := blend
180else
181 ifneq (.$(words $(BUILD_PLATFORM_CPU)).$(BUILD_PLATFORM_CPU).,.1.$(strip $(BUILD_PLATFORM_CPU)).)
182 $(error kBuild: The BUILD_PLATFORM_CPU value '$(BUILD_PLATFORM_CPU)' contains spaces/tabs!)
183 endif
184 ifneq ($(filter $(BUILD_PLATFORM_CPU), $(KBUILD_OSES) $(BUILD_ARCHES)),)
185 $(error kBuild: The BUILD_PLATFORM_CPU value '$(BUILD_PLATFORM_CPU)' was found in the OS or architecture keywords!)
186 endif
187 ifeq ($(BUILD_PLATFORM_CPU),$(BUILD_TYPE))
188 $(error kBuild: The BUILD_PLATFORM_CPU value '$(BUILD_PLATFORM_CPU)' is the same as the BUILD_TYPE!)
189 endif
[978]190endif
[72]191
[978]192
[70]193#
[978]194# Assert or set default target platform.
195# When not defined use the corresponding BUILD_PLATFORM value.
[72]196#
197ifndef BUILD_TARGET
[978]198 BUILD_TARGET := $(BUILD_PLATFORM)
[72]199else
[980]200 ifneq (.$(words $(BUILD_TARGET)).$(BUILD_TARGET).,.1.$(strip $(BUILD_TARGET)).)
[978]201 $(error kBuild: The BUILD_TARGET value '$(BUILD_TARGET)' contains spaces/tabs!)
[478]202 endif
[978]203 ifneq ($(words $(filter $(BUILD_TARGET),$(KBUILD_OSES))),1)
204 $(error kBuild: BUILD_TARGET value '$(BUILD_TARGET)' is not recognized (valid: $(KBUILD_OSES)))
205 endif
[72]206endif
207
[329]208ifndef BUILD_TARGET_ARCH
[978]209 BUILD_TARGET_ARCH := $(BUILD_PLATFORM_ARCH)
210else
[980]211 ifneq (.$(words $(BUILD_TARGET_ARCH)).$(BUILD_TARGET_ARCH).,.1.$(strip $(BUILD_TARGET_ARCH)).)
[978]212 $(error kBuild: The BUILD_TARGET_ARCH value '$(BUILD_TARGET_ARCH)' contains spaces/tabs!)
213 endif
214 ifneq ($(words $(filter $(BUILD_TARGET_ARCH),$(KBUILD_ARCHES))),1)
215 $(error kBuild: BUILD_TARGET_ARCH value '$(BUILD_TARGET_ARCH)' is not recognized (valid: $(KBUILD_ARCHES)))
216 endif
[329]217endif
[978]218
[329]219ifndef BUILD_TARGET_CPU
[978]220 BUILD_TARGET_CPU := $(BUILD_PLATFORM_CPU)
[994]221else ifeq ($(strip $(BUILD_TARGET_CPU)),)
222 ifeq ($(BUILD_TARGET_ARCH),$(BUILD_PLATFORM_ARCH))
223 BUILD_TARGET_CPU := $(BUILD_PLATFORM_CPU)
224 else
225 BUILD_TARGET_CPU := blend
226 endif
[978]227else
228 ifneq (.$(words $(BUILD_TARGET_CPU)).$(BUILD_TARGET_CPU).,.1.$(strip $(BUILD_TARGET_CPU)).)
229 $(error kBuild: The BUILD_TARGET_CPU value '$(BUILD_TARGET_CPU)' contains spaces/tabs!)
230 endif
231 ifneq ($(filter $(BUILD_TARGET_CPU), $(KBUILD_OSES) $(BUILD_ARCHES)),)
232 $(error kBuild: The BUILD_TARGET_CPU value was found in the OS or architecture keywords!)
233 endif
234 ifeq ($(BUILD_TARGET_CPU),$(BUILD_TYPE))
235 $(error kBuild: The BUILD_TARGET_CPU value '$(BUILD_TARGET_CPU)' is the same as the BUILD_TYPE!)
236 endif
[329]237endif
[72]238
239
240#
[978]241# Paths and stuff.
[69]242#
[978]243
244# Adjust DEPTH first.
245DEPTH := $(strip $(DEPTH))
246ifeq ($(DEPTH),)
247 DEPTH := .
248endif
249
[725]250## PATH_CURRENT is the current directory (getcwd).
[306]251PATH_CURRENT := $(abspath $(CURDIR))
[725]252## PATH_SUB_CURRENT points to current directory of the current makefile.
253# Meaning that it will change value as we enter and exit sub-makefiles.
254PATH_SUB_CURRENT := $(PATH_CURRENT)
255## PATH_ROOT points to the project root directory.
256PATH_ROOT := $(abspath $(PATH_CURRENT)/$(DEPTH))
257## PATH_SUB_ROOT points to the directory of the top-level makefile.
[472]258ifneq ($(strip $(SUB_DEPTH)),)
[978]259 SUB_DEPTH := $(strip $(SUB_DEPTH))
[725]260 PATH_SUB_ROOT := $(abspath $(PATH_CURRENT)/$(SUB_DEPTH))
[472]261else
[725]262 PATH_SUB_ROOT := $(PATH_CURRENT)
[472]263endif
[306]264
[748]265## CURSUBDIR is PATH_SUB_ROOT described relative to PATH_ROOT.
[725]266# This variable is used to determin where the object files and other output goes.
[306]267ifneq ($(PATH_ROOT),$(PATH_CURRENT))
[725]268CURSUBDIR := $(patsubst $(PATH_ROOT)/%,%,$(PATH_SUB_ROOT))
[266]269else
270CURSUBDIR := .
271endif
[306]272
[70]273# Output directories.
[242]274ifndef PATH_OUT_BASE
[725]275 PATH_OUT_BASE := $(PATH_ROOT)/out
[242]276endif
[240]277ifndef PATH_OUT
[725]278 ifdef BUILD_TARGET_SUB # (BUILD_TARGET_SUB is not currently recognized by kBuild in any other places.)
279 PATH_OUT := $(PATH_OUT_BASE)/$(BUILD_TARGET).$(BUILD_TARGET_ARCH).$(BUILD_TARGET_SUB)/$(BUILD_TYPE)
280 else
281 PATH_OUT := $(PATH_OUT_BASE)/$(BUILD_TARGET).$(BUILD_TARGET_ARCH)/$(BUILD_TYPE)
282 endif
[329]283endif # !define PATH_OUT
[1051]284PATH_OBJCACHE = $(PATH_OUT_BASE)/kObjCache
[353]285PATH_OBJ = $(PATH_OUT)/obj
286PATH_TARGET = $(PATH_OBJ)/$(CURSUBDIR)
287PATH_INS = $(PATH_OUT)
288PATH_BIN = $(PATH_INS)/bin
289PATH_DLL = $(PATH_INS)/bin
290PATH_SYS = $(PATH_INS)/bin
291PATH_LIB = $(PATH_INS)/lib
292PATH_DOC = $(PATH_INS)/doc
[70]293
[978]294# PATH_KBUILD is determined by kmk.
295ifeq ($(strip $(PATH_KBUILD)),)
296 $(error kBuild: PATH_KBUILD is missing or empty! kmk is supposed to set it.)
[70]297endif
[978]298# PATH_KBUILD_BIN is determined by kmk.
299ifeq ($(strip $(PATH_KBUILD_BIN)),)
300 $(error kBuild: PATH_KBUILD_BIN is missing or empty! kmk is supposed to set it.)
301endif
302
[69]303# kBuild files which might be of interest.
304FILE_KBUILD_HEADER := $(PATH_KBUILD)/header.kmk
[725]305#FILE_KBUILD_CONFIG := $(PATH_KBUILD)/config.kmk
[69]306FILE_KBUILD_FOOTER := $(PATH_KBUILD)/footer.kmk
307
[725]308## MAKEFILE is the name of the main makefile.
[204]309MAKEFILE := $(firstword $(MAKEFILE_LIST))
[748]310## MAKEFILE_CURRENT is the name of the current makefile.
[725]311# This is updated everything a sub-makefile is included.
312MAKEFILE_CURRENT := $(MAKEFILE)
[69]313
[72]314
[69]315#
[72]316# Build platform setup.
[984]317# (PORTME)
[69]318#
[984]319
[69]320# OS/2
[72]321ifeq ($(BUILD_PLATFORM),os2)
[83]322EXEC_X86_WIN32 := innopec.exe
[69]323HOSTSUFF_EXE := .exe
324endif
325
326# Linux
[72]327ifeq ($(BUILD_PLATFORM),linux)
[135]328EXEC_X86_WIN32 := wine
[69]329HOSTSUFF_EXE :=
330endif
[70]331
[547]332# Win, Win32, Win64, NT.
333ifeq ($(filter-out win32 win64 win nt,$(BUILD_PLATFORM)),)
[69]334EXEC_X86_WIN32 :=
335HOSTSUFF_EXE := .exe
336endif
337
[299]338# FreeBSD
339ifeq ($(BUILD_PLATFORM),freebsd)
340EXEC_X86_WIN32 := wine
341HOSTSUFF_EXE :=
342endif
[125]343
[557]344# Darwin / Mac OS X
345ifeq ($(BUILD_PLATFORM),darwin)
346EXEC_X86_WIN32 := false
347HOSTSUFF_EXE :=
348endif
349
[811]350# Solaris
351ifeq ($(BUILD_PLATFORM),solaris)
352EXEC_X86_WIN32 := false
353HOSTSUFF_EXE :=
354endif
355
[299]356
[73]357#
358# Build target setup.
[984]359# (PORTME)
[73]360#
[978]361SUFF_DEP := .dep
[480]362ifeq ($(filter-out win32 win64 win nt os2,$(BUILD_TARGET)),)
[73]363SUFF_OBJ := .obj
364SUFF_LIB := .lib
365SUFF_DLL := .dll
366SUFF_EXE := .exe
[86]367SUFF_SYS := .sys
[73]368SUFF_RES := .res
369endif
[480]370ifeq ($(BUILD_TARGET),l4)
[73]371SUFF_OBJ := .o
372SUFF_LIB := .a
[480]373SUFF_DLL := .s.so
[73]374SUFF_EXE :=
[86]375SUFF_SYS := .a
[73]376SUFF_RES :=
377endif
[557]378ifeq ($(BUILD_TARGET),darwin)
379SUFF_OBJ := .o
380SUFF_LIB := .a
381SUFF_DLL := .dylib
382SUFF_EXE :=
[761]383SUFF_SYS :=
[557]384SUFF_RES :=
385endif
[480]386ifndef SUFF_OBJ
[296]387SUFF_OBJ := .o
388SUFF_LIB := .a
[480]389SUFF_DLL := .so
[296]390SUFF_EXE :=
391SUFF_SYS := .a
392SUFF_RES :=
393endif
[69]394
395#
396# Standard kBuild tools.
397#
[978]398ifeq ($(KMK),kmk)
399KMK := $(PATH_KBUILD_BIN)/kmk$(HOSTSUFF_EXE)
[233]400endif
[978]401MAKE := $(KMK)
[233]402
[578]403DEP_EXT := $(PATH_KBUILD_BIN)/kDep$(HOSTSUFF_EXE)
[1272]404if1of (kDep,$(KMK_BUILTIN))
[397]405DEP := kmk_builtin_kDep
[230]406else
[380]407DEP := $(DEP_EXT)
[230]408endif
[69]409
[578]410DEP_IDB_EXT := $(PATH_KBUILD_BIN)/kDepIDB$(HOSTSUFF_EXE)
[1272]411if1of (kDepIDB,$(KMK_BUILTIN))
[1004]412DEP_IDB := kmk_builtin_kDepIDB
[397]413else
414DEP_IDB := $(DEP_IDB_EXT)
415endif
416
[578]417DEP_PRE_EXT := $(PATH_KBUILD_BIN)/kDepPre$(HOSTSUFF_EXE)
[1272]418if1of (kDepPre,$(KMK_BUILTIN))
[1004]419DEP_PRE := kmk_builtin_kDepPre
[380]420else
421DEP_PRE := $(DEP_PRE_EXT)
422endif
423
[1004]424KOBJCACHE_EXT := $(PATH_KBUILD_BIN)/kObjCache$(HOSTSUFF_EXE)
[1272]425if1of (kObjCache,$(KMK_BUILTIN))
[1004]426KOBJCACHE := kmk_builtin_kObjCache
427else
428KOBJCACHE := $(KOBJCACHE_EXT)
429endif
430
[578]431APPEND_EXT := $(PATH_KBUILD_BIN)/kmk_append$(HOSTSUFF_EXE)
[380]432APPEND := kmk_builtin_append
[69]433
[578]434CAT_EXT := $(PATH_KBUILD_BIN)/kmk_cat$(HOSTSUFF_EXE)
[380]435CAT := kmk_builtin_cat
[353]436
[1118]437CMP_EXT := $(PATH_KBUILD_BIN)/kmk_cmp$(HOSTSUFF_EXE)
438CMP := kmk_builtin_cmp
439
[1119]440CP_EXT := $(PATH_KBUILD_BIN)/kmk_cp$(HOSTSUFF_EXE)
441CP := kmk_builtin_cp
442
[578]443ECHO_EXT := $(PATH_KBUILD_BIN)/kmk_echo$(HOSTSUFF_EXE)
[380]444ECHO := kmk_builtin_echo
445
[578]446INSTALL_EXT := $(PATH_KBUILD_BIN)/kmk_install$(HOSTSUFF_EXE)
[380]447INSTALL := kmk_builtin_install
448
[578]449LN_EXT := $(PATH_KBUILD_BIN)/kmk_ln$(HOSTSUFF_EXE)
[380]450LN := kmk_builtin_ln
451
[1118]452MD5SUM_EXT := $(PATH_KBUILD_BIN)/kmk_md5sum$(HOSTSUFF_EXE)
453MD5SUM := kmk_builtin_md5sum
454
[578]455MKDIR_EXT := $(PATH_KBUILD_BIN)/kmk_mkdir$(HOSTSUFF_EXE)
[380]456MKDIR := kmk_builtin_mkdir
457
[578]458MV_EXT := $(PATH_KBUILD_BIN)/kmk_mv$(HOSTSUFF_EXE)
[380]459MV := kmk_builtin_mv
460
[776]461PRINTF_EXT := $(PATH_KBUILD_BIN)/kmk_printf$(HOSTSUFF_EXE)
462PRINTF := kmk_builtin_printf
463
[1272]464REDIRECT_EXT:= $(PATH_KBUILD_BIN)/kmk_redirect$(HOSTSUFF_EXE)
465if1of (redirect,$(KMK_BUILTIN))
466REDIRECT := kmk_builtin_redirect
467else
468REDIRECT := $(REDIRECT_EXT)
469endif
470
[578]471RM_EXT := $(PATH_KBUILD_BIN)/kmk_rm$(HOSTSUFF_EXE)
[380]472RM := kmk_builtin_rm
473
[601]474RMDIR_EXT := $(PATH_KBUILD_BIN)/kmk_rmdir$(HOSTSUFF_EXE)
475RMDIR := kmk_builtin_rmdir
476
[578]477SED_EXT := $(PATH_KBUILD_BIN)/kmk_sed$(HOSTSUFF_EXE)
[1272]478if1of (sed, $(KMK_BUILTIN))
[978]479SED_INT := kmk_builtin_sed
[380]480else
[978]481SED_INT := $(SED_EXT)
482endif
[380]483SED := $(SED_EXT)
484
[1296]485TEST_EXT := $(PATH_KBUILD_BIN)/kmk_test$(HOSTSUFF_EXE)
486TEST := kmk_builtin_test
487
[380]488# Our default shell is the Almquist shell from *BSD.
[578]489ASH := $(PATH_KBUILD_BIN)/kmk_ash$(HOSTSUFF_EXE)
[380]490MAKESHELL := $(ASH)
491SHELL := $(ASH)
492export SHELL MAKESHELL
493
[414]494# Symlinking is problematic on some platforms...
[380]495LN_SYMLINK := $(LN) -s
496
[743]497
498#
499# Some Functions.
[748]500# The lower cased ones are either fallbacks or candidates for functions.c.
[743]501#
502
[130]503## ABSPATH - make paths absolute.
[129]504# This implementation is clumsy and doesn't resolve '..' and '.' components.
[73]505#
[129]506# @param $1 The paths to make absolute.
[696]507# @obsolete Use the GNU make function $(abspath) directly now.
[984]508ABSPATH = $(abspath $(1))$(warning ABSPATH is deprecated, use abspath directly!)
[353]509
[130]510## DIRDEP - make create directory dependencies.
511#
512# @param $1 The paths to the directories which must be created.
[353]513DIRDEP = $(foreach path,$(patsubst %/,%,$(1)),$(path)/)
[129]514
515## Cygwin kludge.
516# This converts /cygdrive/x/% to x:%.
517#
518# @param $1 The paths to make native.
519# @remark This macro is pretty much obsolete since we don't use cygwin base make.
520ifneq ($(patsubst /cygdrive/%,%,$(CURDIR)),$(CURDIR))
[743]521 CYGPATHMIXED = $(foreach path,$(1)\
[129]522 ,$(if $(patsubst /cygdrive/%,,$(path)),$(path),$(patsubst $(strip $(firstword $(subst /, ,$(patsubst /cygdrive/%,%,$(path)))))/%,$(strip $(firstword $(subst /, ,$(patsubst /cygdrive/%,%,$(path))))):/%,$(patsubst /cygdrive/%,%,$(path)))))
523else
[743]524 CYGPATHMIXED = $(1)
[129]525endif
526
[743]527## Removes the drive letter from a path (if it has one)
528# @param $1 the path
529no-drive = $(word $(words $(subst :, ,$(1))),$(subst :, ,$(1)))
[723]530
[743]531## Removes the root slash from a path (if it has one)
532# @param $1 the path
533no-root-slash = $(patsubst /%,%,$(1))
[723]534
[743]535## Figure out where to put object files.
536# @param $1 real target name.
537# @param $2 normalized main target
[748]538TARGET_BASE = $(PATH_TARGET)/$(2)/$(call no-root-slash,$(call no-drive,$(1)))
[723]539
[743]540## Figure out where to put object files.
541# @param $1 normalized main target
542TARGET_PATH = $(PATH_TARGET)/$(1)
[723]543
544
[129]545#
[353]546# Initialize some of the globals which the Config.kmk and
547# others can add stuff to if they like for processing in the footer.
548#
549
550## TEMPLATE_PATHS
551# List a paths (separated by space) where templates can be found.
552TEMPLATE_PATHS :=
553
554## TOOL_PATHS
555# List of paths (separated by space) where tools can be found.
556TOOL_PATHS :=
557
558## SDK_PATHS
559# List of paths (separated by space) where SDKs can be found.
560SDK_PATHS :=
561
562## Proritized list of the default makefile when walking subdirectories.
563# The user can overload this list.
564DEFAULT_MAKEFILE := Makefile.kmk makefile.kmk Makefile makefile
565
[980]566
[640]567## PROPS_TOOLS
[985]568# This is a subset of PROPS_SINGLE.
[1256]569PROPS_TOOLS := TOOL CTOOL CXXTOOL OBJCTOOL ASTOOL RCTOOL ARTOOL LDTOOL FETCHTOOL UNPACKTOOL PATCHTOOL
[640]570
[353]571## PROPS_SINGLE
572# The list of non-accumulative target properties.
573# A Config.kmk file can add it's own properties to this list and kBuild
574# will do the necessary inheritance from templates to targets.
[641]575PROPS_SINGLE := $(PROPS_TOOLS) INST NOINST BLD_TYPE BLD_TRG BLD_TRG_ARCH BLD_TRG_CPU FETCHDIR \
[1256]576 OBJSUFF COBJSUFF CXXOBJSUFF OBJCOBJSUFF ASOBJSUFF RCOBJSUFF SYSSUFF EXESUFF DLLSUFF LIBSUFF ARLIBSUFF
[985]577## PROPS_SINGLE_LNK
578# Subset of PROPS_SINGLE which applies to all linkable targets.
[1256]579PROPS_SINGLE_LNK := TOOL CTOOL CXXTOOL OBJCTOOL ASTOOL RCTOOL \
[985]580 INST NOINST BLD_TYPE BLD_TRG BLD_TRG_ARCH BLD_TRG_CPU \
[1256]581 OBJSUFF COBJSUFF CXXOBJSUFF OBJCOBJSUFF ASOBJSUFF RCOBJSUFF
[353]582
583## PROPS_DEFERRED
[889]584# This list of non-accumulative target properties which are or may be
585# functions, and thus should not be expanded until the very last moment.
[985]586PROPS_DEFERRED := INSTFUN INSTALLER PRE_CMDS POST_CMDS NAME SONAME
[353]587
[660]588## PROPS_ACCUMULATE_R
[748]589# The list of accumulative target properties where the right most value/flag
[660]590# is the 'most significant'.
[353]591# A Config.kmk file can add it's own properties to this list and kBuild
592# will do the necessary inheritance from templates to targets.
[660]593PROPS_ACCUMULATE_R := \
[985]594 DEPS ORDERDEPS DEFS \
595 ARFLAGS \
[660]596 CFLAGS CDEFS \
597 CXXFLAGS CXXDEFS \
[1256]598 OBJCFLAGS OBJCDEFS \
[660]599 ASFLAGS ASDEFS \
600 RCFLAGS RCDEFS \
601 LDFLAGS \
[830]602 IDFLAGS IFDLAGS ISFLAGS \
[640]603 FETCHFLAGS UNPACKFLAGS PATCHFLAGS
[985]604## PROPS_ACCUMULATE_R_LNK
605# Subset of PROPS_ACCUMULATE_R which applies to all linkable targets.
606PROPS_ACCUMULATE_R_LNK := \
607 DEPS ORDERDEPS DEFS \
608 CFLAGS CDEFS \
609 CXXFLAGS CXXDEFS \
[1256]610 OBJCFLAGS OBJCDEFS \
[985]611 ASFLAGS ASDEFS \
612 RCFLAGS RCDEFS \
613 IDFLAGS IFDLAGS ISFLAGS
[353]614
[660]615## PROPS_ACCUMULATE
[748]616# The list of accumulative target properties where the left most value/flag
[660]617# is the 'most significant'.
618# A Config.kmk file can add it's own properties to this list and kBuild
619# will do the necessary inheritance from templates to targets.
620PROPS_ACCUMULATE_L := \
621 SDKS SOURCES \
[1256]622 INCS CINCS CXXINCS OBJCINCS ASINCS RCINCS \
[897]623 LIBS LIBPATH \
[985]624 DIRS BLDDIRS CLEAN
625## PROPS_ACCUMULATE_L_LNK
626# Subset of PROPS_ACCUMULATE_L which applies to all linkable targets.
627PROPS_ACCUMULATE_L_LNK := \
628 SDKS SOURCES \
[1256]629 INCS CINCS CXXINCS OBJCINCS ASINCS RCINCS \
[985]630 BLDDIRS CLEAN
[353]631
[662]632## PROPS_ALL
633# List of all the properties.
634PROPS_ALL = $(PROPS_SINGLE) $(PROPS_DEFERRED) $(PROPS_ACCUMULATE_L) $(PROPS_ACCUMULATE_R)
[660]635
[662]636
[985]637## @name Properties valid on programs (BLDPROGS and PROGRAMS)
638## @{
639PROPS_PROGRAMS_SINGLE := $(PROPS_SINGLE_LNK) LDTOOL EXESUFF
640PROPS_PROGRAMS_DEFERRED := $(PROPS_DEFERRED)
641PROPS_PROGRAMS_ACCUMULATE_R := $(PROPS_ACCUMULATE_R_LNK) LDFLAGS
642PROPS_PROGRAMS_ACCUMULATE_L := $(PROPS_ACCUMULATE_L_LNK) LIBS LIBPATH
643## @}
644
645## @name Properties valid on libraries (LIBRARIES and IMPORT_LIBS)
646## @{
[989]647PROPS_LIBRARIES_SINGLE := $(PROPS_SINGLE_LNK) ARTOOL LIBSUFF ARLIBSUFF LIBSUFF
[985]648PROPS_LIBRARIES_DEFERRED := $(filter-out SONAME,$(PROPS_DEFERRED))
649PROPS_LIBRARIES_ACCUMULATE_R := $(PROPS_ACCUMULATE_R_LNK) ARFLAGS
650PROPS_LIBRARIES_ACCUMULATE_L := $(PROPS_ACCUMULATE_L_LNK)
651## @}
652
653## @name Properties valid on dlls (DLLS)
654## @{
655PROPS_DLLS_SINGLE := $(PROPS_SINGLE_LNK) LDTOOL DLLSUFF LIBSUFF
656PROPS_DLLS_DEFERRED := $(PROPS_DEFERRED)
657PROPS_DLLS_ACCUMULATE_R := $(PROPS_ACCUMULATE_R_LNK) LDFLAGS
658PROPS_DLLS_ACCUMULATE_L := $(PROPS_ACCUMULATE_L_LNK) LIBS LIBPATH
659## @}
660
[989]661## @name Properties valid on system modules (SYSMODS)
662## @{
663PROPS_SYSMODS_SINGLE := $(PROPS_SINGLE_LNK) LDTOOL SYSSUFF
664PROPS_SYSMODS_DEFERRED := $(PROPS_DEFERRED)
665PROPS_SYSMODS_ACCUMULATE_R := $(PROPS_ACCUMULATE_R_LNK) LDFLAGS
666PROPS_SYSMODS_ACCUMULATE_L := $(PROPS_ACCUMULATE_L_LNK) LIBS LIBPATH
667## @}
668
[985]669## @name Properties valid on installs (INSTALLS)
670## @{
671PROPS_INSTALLS_SINGLE := TOOL INST NOINST
672PROPS_INSTALLS_DEFERRED := INSTFUN INSTALLER
673PROPS_INSTALLS_ACCUMULATE_R := DEPS ORDERDEPS
674PROPS_INSTALLS_ACCUMULATE_L := SOURCES DIRS CLEAN
675## @}
676
677## @name Properties valid on fetches (INSTALLS)
678## @{
679PROPS_FETCHES_SINGLE := TOOL FETCHTOOL UNPACKTOOL PATCHTOOL INST FETCHDIR
680PROPS_FETCHES_DEFERRED :=
681PROPS_FETCHES_ACCUMULATE_R := FETCHFLAGS UNPACKFLAGS PATCHFLAGS
682PROPS_FETCHES_ACCUMULATE_L := SOURCES
683## @}
684
685
[353]686#
[748]687# Here is a special 'hack' to prevent innocent environment variables being
688# picked up and treated as properties. (The most annoying example of why
[662]689# this is necessary is the Visual C++ commandline with it's LIBPATH.)
690#
[748]691# Define KBUILD_DONT_KILL_ENV_PROPS in the env. or on the commandline to
[662]692# disable this 'hack'.
693#
694ifndef KBUILD_DONT_KILL_ENV_PROPS
695
696define def_nuke_environment_prop
697ifeq ($(origin $(prop)),environment)
698$(prop) =
699endif
700endef
[762]701$(foreach prop, $(PROPS_ALL) \
702 FETCHES PATCHES BLDPROGS LIBRARIES IMPORT_LIBS DLLS PROGRAMS SYSMODS INSTALLS OTHERS \
[897]703 SUBDIRS MAKEFILES BLDDIRS \
[762]704 ,$(eval $(value def_nuke_environment_prop)))
[662]705
[897]706endif # KBUILD_DONT_KILL_ENV_PROPS
[662]707
708
709#
[353]710# Pass configuration.
711#
712# The PASS_<passname>_trgs variable is listing the targets.
713# The PASS_<passname>_vars variable is listing the target variables.
714# The PASS_<passname>_pass variable is the lowercased passname.
715#
716
[640]717## PASS: fetches
718# This pass fetches and unpacks things needed to complete the build.
719PASS_FETCHES := Fetches
720PASS_FETCHES_trgs :=
721PASS_FETCHES_vars := _FETCHES
722PASS_FETCHES_pass := fetches
723
724## PASS: patches
725# This pass applies patches.
726PASS_PATCHES := Patches
727PASS_PATCHES_trgs :=
728PASS_PATCHES_vars := _PATCHES
729PASS_PATCHES_pass := patches
730
[353]731## PASS: bldprogs
732# This pass builds targets which are required for building the rest.
733PASS_BLDPROGS := Build Programs
734PASS_BLDPROGS_trgs :=
735PASS_BLDPROGS_vars := _BLDPROGS
736PASS_BLDPROGS_pass := bldprogs
737
738## PASS: libraries
739# This pass builds library targets.
740PASS_LIBRARIES := Libraries
741PASS_LIBRARIES_trgs :=
742PASS_LIBRARIES_vars := _LIBS _IMPORT_LIBS _OTHER_LIBRARIES
743PASS_LIBRARIES_pass := libraries
744
745## PASS: binaries
746# This pass builds dll targets.
747PASS_DLLS := DLLs
748PASS_DLLS_trgs :=
749PASS_DLLS_vars := _DLLS _OTHER_DLLS
750PASS_DLLS_pass := dlls
751
752## PASS: binaries
753# This pass builds binary targets, i.e. programs, system modules and stuff.
754PASS_BINARIES := Programs
755PASS_BINARIES_trgs :=
756PASS_BINARIES_vars := _PROGRAMS _SYSMODS _OTHER_BINARIES
757PASS_BINARIES_pass := binaries
758
759## PASS: others
760# This pass builds other targets.
761PASS_OTHERS := Other Stuff
762PASS_OTHERS_trgs :=
763PASS_OTHERS_vars := _OTHERS
764PASS_OTHERS_pass := others
765
766## PASS: install
767# This pass installs the built entities to a sandbox area.
768PASS_INSTALLS := Install
769PASS_INSTALLS_trgs :=
[854]770PASS_INSTALLS_vars := _INSTALLS_DIRS _INSTALLS _INSTALLS_FILES
[353]771PASS_INSTALLS_pass := installs
772
773## PASS: packing
774# This pass processes custom packing rules.
775PASS_PACKING := Packing
[414]776PASS_PACKING_trgs :=
[417]777PASS_PACKING_vars := _PACKING
[353]778PASS_PACKING_pass := packing
[414]779#alias
780packing: pass_packing
[353]781
782## PASS: clean
783# This pass removes all generated files.
784PASS_CLEAN := Clean
785PASS_CLEAN_trgs := do-clean
786PASS_CLEAN_vars :=
787PASS_CLEAN_pass := clean
788# alias
789clean: pass_clean
790
791## PASS: nothing
792# This pass just walks the tree.
793PASS_NOTHING := Nothing
794PASS_NOTHING_trgs := do-nothing
795PASS_NOTHING_vars :=
796PASS_NOTHING_pass := nothing
797# alias
798nothing: pass_nothing
799
800## DEFAULT_PASSES
801# The default passes and their order.
802DEFAULT_PASSES := BLDPROGS LIBRARIES DLLS BINARIES OTHERS INSTALLS
803
804## PASSES
805# The passes that should be defined. This must include
806# all passes mentioned by DEFAULT_PASSES.
[723]807PASSES := FETCHES PATCHES $(DEFAULT_PASSES) NOTHING CLEAN
[353]808
809
810#
[984]811# Check for --pretty-command-printing before including the Config.kmk
812# so that anyone overriding the message macros can take the implied
813# verbosity level change into account.
814#
815ifndef KBUILD_VERBOSE
816 ifndef KBUILD_QUIET
817 ifneq ($(filter --pretty-command-printing,$(MAKEFLAGS)),)
818 export KBUILD_VERBOSE := 2
819 endif
820 endif
821endif
822
823
824#
[69]825# This is how we find the closest config.kmk.
826# It's a little hacky but I think it works fine.
[70]827#
828_CFGDIR := .
[78]829_CFGFILES := ./Config.kmk ./config.kmk
[69]830define def_include_config
[78]831$(eval _CFGDIR := $(_CFGDIR)/$(dir))
832_CFGFILES += $(_CFGDIR)/Config.kmk $(_CFGDIR)/config.kmk
[69]833endef
834# walk down the _RELATIVE_ path specified by DEPTH.
[78]835$(foreach dir,$(subst /, ,$(DEPTH)), $(eval $(def_include_config)) )
[69]836# add the default config file.
[78]837_CFGFILE := $(firstword $(wildcard $(_CFGFILES) $(FILE_KBUILD_CONFIG)))
[69]838_CFGFILES :=
839_CFGDIR :=
[416]840ifeq ($(_CFGFILE),)
841$(error kBuild: no Config.kmk file found! Check the DEPTH: DEPTH='$(DEPTH)' PATH_CURRENT='$(PATH_CURRENT)')
842endif
[69]843
844# Include the config.kmk we found file (or the default one).
[988]845ifdef KBUILD_PROFILE_SELF
846 _KBUILD_TS_NOW := $(nanots )
847 $(info prof: $(int-sub $(_KBUILD_TS_NOW), $(_KBUILD_TS_HEADER_START)) - $(int-sub $(_KBUILD_TS_NOW), $(_KBUILD_TS_PREV)) - including $(_CFGFILE))
848 _KBUILD_TS_PREV := $(_KBUILD_TS_NOW)
[69]849
[988]850 include $(_CFGFILE)
[69]851
[988]852 _KBUILD_TS_NOW := $(nanots )
853 $(info prof: $(int-sub $(_KBUILD_TS_NOW), $(_KBUILD_TS_HEADER_START)) - $(int-sub $(_KBUILD_TS_NOW), $(_KBUILD_TS_PREV)) - included $(_CFGFILE))
854 _KBUILD_TS_PREV := $(_KBUILD_TS_NOW)
855else
856 include $(_CFGFILE)
857endif
858
859
860
[696]861#
[874]862# Finalize a the central path variables now that we've included the Config.kmk file.
863#
864# This prevents some trouble when users override the defaults for these
865# variables and uses relative paths or paths with incorrect case.
866#
867PATH_OUT := $(abspath $(PATH_OUT))
868PATH_OBJ := $(abspath $(PATH_OBJ))
869PATH_TARGET := $(abspath $(PATH_TARGET))
870PATH_INS := $(abspath $(PATH_INS))
871PATH_BIN := $(abspath $(PATH_BIN))
872PATH_DLL := $(abspath $(PATH_DLL))
873PATH_SYS := $(abspath $(PATH_SYS))
874PATH_LIB := $(abspath $(PATH_LIB))
875PATH_DOC := $(abspath $(PATH_DOC))
876
877
878#
[788]879# Setup the message style. The default one is inlined.
[776]880#
[788]881# See kBuild/msgstyles for more styles or use KBUILD_MSG_STYLE_PATHS
882# to create your own message style.
883#
[776]884KBUILD_MSG_STYLE ?= default
885ifeq ($(KBUILD_MSG_STYLE),default)
886 #
887 # The 'default' style.
888 #
889
890 ## Fetch starting.
891 # @param 1 Target name.
892 MSG_FETCH ?= $(call MSG_L1,Fetching $1...)
893 ## Re-fetch starting.
894 # @param 1 Target name.
895 MSG_REFETCH ?= $(call MSG_L1,Re-fetching $1...)
896 ## Downloading a fetch component.
897 # @param 1 Target name.
898 # @param 2 The source URL.
899 # @param 3 The destination file name.
900 MSG_FETCH_DL ?= $(call MSG_L1,Downloading $1 - $2,=> $3)
901 ## Checking a fetch component.
902 # @param 1 Target name.
903 # @param 2 The source URL.
904 # @param 3 The destination file name.
905 MSG_FETCH_CHK?= $(call MSG_L1,Checking $1 - $3, ($2))
906 ## Unpacking a fetch component.
907 # @param 1 Target name.
908 # @param 2 The archive file name.
909 # @param 3 The target directory.
910 MSG_FETCH_UP ?= $(call MSG_L1,Unpacking $1 - $2 => $3)
911 ## Fetch completed.
912 # @param 1 Target name.
913 MSG_FETCH_OK ?= $(call MSG_L1,Successfully fetched $1)
914 ## Unfetch a fetch target.
915 # @param 1 Target name.
916 MSG_UNFETCH ?= $(call MSG_L1,Unfetching $1...)
917 ## Compiling a source file.
918 # @param 1 Target name.
919 # @param 2 The source filename.
920 # @param 3 The primary link output file name.
[1256]921 # @param 4 The source type (C,CXX,OBJC,AS,RC,++).
[776]922 MSG_COMPILE ?= $(call MSG_L1,Compiling $1 - $2,=> $3)
[890]923 ## Tool
924 # @param 1 The tool name (bin2c,...)
925 # @param 2 Target name.
926 # @param 3 The source filename.
927 # @param 4 The primary output file name.
928 MSG_TOOL ?= $(call MSG_L1,$1 $2 - $3,=> $4)
929 ## Generate a file, typically a source file.
930 # @param 1 Target name if applicable.
931 # @param 2 Output file name.
932 # @param 3 What it's generated from
933 MSG_GENERATE ?= $(call MSG_L1,Generating $(if $1,$1 - )$2,$(if $3,from $3))
[776]934 ## Linking a bldprog/dll/program/sysmod target.
935 # @param 1 Target name.
936 # @param 2 The primary link output file name.
937 # @param 3 The link tool operation (LINK_LIBRARY,LINK_PROGRAM,LINK_DLL,LINK_SYSMOD,++).
938 MSG_LINK ?= $(call MSG_L1,Linking $1,=> $2)
[844]939 ## Merging a library into the target (during library linking).
940 # @param 1 Target name.
941 # @param 2 The output library name.
942 # @param 3 The input library name.
[845]943 MSG_AR_MERGE ?= $(call MSG_L1,Merging $3 into $1, ($2))
[776]944 ## Creating a directory (build).
945 # @param 1 Directory name.
946 MSG_MKDIR ?= $(call MSG_L2,Creating directory $1)
947 ## Cleaning.
948 MSG_CLEAN ?= $(call MSG_L1,Cleaning...)
949 ## Nothing.
950 MSG_NOTHING ?= $(call MSG_L1,Did nothing in $(CURDIR))
951 ## Pass
952 # @param 1 The pass name.
953 MSG_PASS ?= $(call MSG_L1,Pass - $1)
954 ## Installing a bldprog/lib/dll/program/sysmod target.
955 # @param 1 Target name.
956 # @param 2 The source filename.
957 # @param 3 The destination file name.
958 MSG_INST_TRG ?= $(call MSG_L1,Installing $1 => $3)
959 ## Installing a file (install target).
960 # @param 1 The source filename.
961 # @param 2 The destination filename.
962 MSG_INST_FILE?= $(call MSG_L1,Installing $2,(<= $1))
963 ## Installing a symlink.
964 # @param 1 Symlink
965 # @param 2 Link target
966 MSG_INST_SYM ?= $(call MSG_L1,Installing symlink $1,=> $2)
967 ## Installing a directory.
968 # @param 1 Directory name.
969 MSG_INST_DIR ?= $(call MSG_L1,Installing directory $1)
970
[788]971else
972 _KBUILD_MSG_STYLE_FILE := $(firstword $(foreach path, $(KBUILD_MSG_STYLE_PATHS) $(PATH_KBUILD)/msgstyles, $(wildcard $(path)/$(KBUILD_MSG_STYLE).kmk)))
973 ifneq ($(_KBUILD_MSG_STYLE_FILE),)
974 include $(_KBUILD_MSG_STYLE_FILE)
[776]975 else
[788]976 $(error kBuild: Can't find the style setup file for KBUILD_MSG_STYLE '$(KBUILD_MSG_STYLE)')
[776]977 endif
978endif
979
980
981#
[696]982# Message macros.
983#
[748]984# This is done after including Config.kmk as to allow for
[696]985# KBUILD_QUIET and KBUILD_VERBOSE to be configurable.
986#
987ifdef KBUILD_QUIET
[776]988 # No output
[696]989 QUIET := @
990 QUIET2:= @
991 MSG_L1 =
992 MSG_L2 =
993else
994 ifndef KBUILD_VERBOSE
[776]995 # Default output level.
996 QUIET := @
997 QUIET2 := @
998 MSG_L1 ?= @$(ECHO) "kBuild: $1"
999 MSG_L2 =
1000 else ifeq ($(KBUILD_VERBOSE),1)
1001 # A bit more output
1002 QUIET := @
1003 QUIET2 := @
1004 MSG_L1 ?= @$(ECHO) "kBuild: $1 $2"
1005 MSG_L2 =
1006 else ifeq ($(KBUILD_VERBOSE),2)
1007 # Lot more output
1008 QUIET :=
1009 QUIET2 := @
1010 MSG_L1 ?= @$(ECHO) "kBuild: $1 $2"
1011 MSG_L2 ?= @$(ECHO) "kBuild: $1"
[696]1012 else
1013 # maximal output.
[776]1014 QUIET :=
1015 QUIET2 :=
1016 MSG_L1 ?= @$(ECHO) "kBuild: $1 $2"
1017 MSG_L2 ?= @$(ECHO) "kBuild: $1"
[696]1018 endif
1019endif
1020
[776]1021
[988]1022ifdef KBUILD_PROFILE_SELF
1023 _KBUILD_TS_HEADER_END := $(nanots )
1024 $(info prof: $(int-sub $(_KBUILD_TS_HEADER_END), $(_KBUILD_TS_HEADER_START)) - $(int-sub $(_KBUILD_TS_HEADER_END), $(_KBUILD_TS_PREV)) - end of header.kmk)
1025 _KBUILD_TS_PREV := $(_KBUILD_TS_HEADER_END)
1026endif
1027
[69]1028# end-of-file-content
[72]1029__header_kmk__ := 1
[69]1030endif # __header_kmk__
[479]1031
Note: See TracBrowser for help on using the repository browser.