source: trunk/kBuild/header.kmk@ 988

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

kBuild profiling.

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