source: trunk/kBuild/header.kmk@ 1398

Last change on this file since 1398 was 1390, checked in by bird, 17 years ago

Fixed bug when DEPTH == SUB_DEPTH which caused CURSUBDIR = PATH_SUB_ROOT because patsubst failed (no trailing slash). The result would be lots of werid stuff, esp. on windows. The actual caused was a mixup of PATH_CURRENT and PATH_SUB_ROOT in the test trying to avoid the issue.

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