source: trunk/kBuild/header.kmk@ 896

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

NLTAB.

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