source: trunk/kBuild/header.kmk@ 895

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

DOLLAR, EQUAL, DOT, COMMA, SEMICOLON and COLON.

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