source: trunk/kBuild/header.kmk@ 241

Last change on this file since 241 was 240, checked in by bird, 20 years ago

Made PATH_OUT overloadable.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 8.5 KB
RevLine 
[69]1# $Id: header.kmk 240 2005-02-17 22:45:47Z bird $
2## @file
3#
4# kBuild - File included at top of makefile.
5#
6# Copyright (c) 2004 knut st. osmundsen <bird-srcspam@anduin.net>
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#
36# Try avoid inference rules.
37#
38.SUFFIXES:
39SUFFIXES :=
40
[72]41
[69]42#
[95]43# General purpose macros.
44#
[204]45
[95]46## get last word in a list.
47# @returns last word in $1.
48# @param $1 Word list.
49lastword = $(word $(words $(1)), $(1))
50
51
52#
[72]53# Assert build type.
[69]54#
55ifndef BUILD_TYPE
56ifndef BUILD_MODE
[72]57$(error kBuild: You must define BUILD_TYPE!)
[69]58endif
59BUILD_TYPE := $(BUILD_MODE)
60endif
[72]61ifeq ($(BUILD_TYPE),DEBUG)
62BUILD_TYPE := debug
63endif
64ifeq ($(BUILD_TYPE),RELEASE)
65BUILD_TYPE := release
66endif
67ifeq ($(BUILD_TYPE),PROFILE)
68BUILD_TYPE := profile
69endif
[69]70
71
72#
[72]73# Assert build platform.
[70]74#
[72]75_BUILD_PLATFORM_OK := 0
76# OS/2
77ifeq ($(BUILD_PLATFORM),OS2)
[88]78$(error kBuild: BUILD_PLATFORM must be all lowercase!)
[72]79endif
80ifeq ($(BUILD_PLATFORM),os2)
81_BUILD_PLATFORM_OK := 1
82endif
[70]83
[72]84# Linux
85ifeq ($(BUILD_PLATFORM),LINUX)
[88]86$(error kBuild: BUILD_PLATFORM must be all lowercase!)
[72]87endif
88ifeq ($(BUILD_PLATFORM),linux)
89_BUILD_PLATFORM_OK := 1
90endif
91
92# Win32
93ifeq ($(BUILD_PLATFORM),WIN32)
[88]94$(error kBuild: BUILD_PLATFORM must be all lowercase!)
[72]95endif
[83]96ifeq ($(BUILD_PLATFORM),win32)
[72]97_BUILD_PLATFORM_OK := 1
98endif
99
100ifeq ($(_BUILD_PLATFORM_OK),0)
101$(error kBuild: BUILD_PLATFORM value '$(BUILD_PLATFORM)' was not recongized!)
102endif
[95]103BUILD_PLATFORM_ARCH := x86
104BUILD_PLATFORM_CPU := i586
[72]105
106
[70]107#
[72]108# Assert target platform.
109#
110ifndef BUILD_TARGET
111# not defined, set to the same as build platform
112BUILD_TARGET := $(BUILD_PLATFORM)
113else
114_BUILD_TARGET_OK := 0
115# OS/2
116ifeq ($(BUILD_TARGET),OS2)
[88]117$(error kBuild: BUILD_TARGET must be all lowercase!)
[72]118endif
119ifeq ($(BUILD_TARGET),os2)
120_BUILD_TARGET_OK := 1
121endif
122
123# Linux
124ifeq ($(BUILD_TARGET),LINUX)
[88]125$(error kBuild: BUILD_TARGET must be all lowercase!)
[72]126endif
127ifeq ($(BUILD_TARGET),linux)
128_BUILD_TARGET_OK := 1
129endif
130
131# Win32
132ifeq ($(BUILD_TARGET),WIN32)
[88]133$(error kBuild: BUILD_TARGET must be all lowercase!)
[72]134endif
[77]135ifeq ($(BUILD_TARGET),win32)
[72]136_BUILD_TARGET_OK := 1
137endif
138
139ifeq ($(_BUILD_TARGET_OK),0)
140$(error kBuild: BUILD_TARGET value '$(BUILD_TARGET)' was not recongized!)
141endif
142endif
[78]143BUILD_TARGET_ARCH := x86
144BUILD_TARGET_CPU := i586
[72]145
146
147#
[69]148# Common definitions.
149#
150PATH_CURRENT := $(CURDIR)
[70]151# Get the real root path.
[85]152PATH_ROOT := $(PATH_CURRENT)
[70]153ifneq ($(DEPTH),.)
154$(foreach d,$(subst /, ,$(DEPTH)), $(eval PATH_ROOT := $(patsubst %/,%,$(dir $(PATH_ROOT)))) )
[69]155endif
[70]156# Subdirectory relative to the root.
[72]157CURSUBDIR := $(patsubst $(PATH_ROOT)/%,%,$(CURDIR))
[70]158# Output directories.
[240]159ifndef PATH_OUT
[69]160PATH_OUT := $(PATH_ROOT)/out/$(BUILD_TARGET)/$(BUILD_TYPE)
[240]161endif
[69]162PATH_OBJ := $(PATH_OUT)/obj
163PATH_BIN := $(PATH_OUT)/bin
164PATH_LIB := $(PATH_OUT)/lib
165PATH_DOC := $(PATH_ROOT)/out/doc
[72]166PATH_TARGET := $(PATH_OBJ)/$(CURSUBDIR)
[70]167
168# Usually kBuild is external to the source tree.
169ifndef PATH_KBUILD
170PATH_KBUILD := $(PATH_ROOT)/kBuild
171endif
172# kBuild tools
[69]173PATH_TOOLS_W32 := $(PATH_KBUILD)/bin/x86.win32
174PATH_TOOLS_LNX := $(PATH_KBUILD)/bin/x86.linux
175PATH_TOOLS_OS2 := $(PATH_KBUILD)/bin/x86.os2
176# kBuild files which might be of interest.
177FILE_KBUILD_HEADER := $(PATH_KBUILD)/header.kmk
178FILE_KBUILD_CONFIG := $(PATH_KBUILD)/config.kmk
179FILE_KBUILD_FOOTER := $(PATH_KBUILD)/footer.kmk
180
[72]181SUFF_DEP := .dep
[204]182MAKEFILE := $(firstword $(MAKEFILE_LIST))
[69]183
[72]184
[69]185#
186# Get rid of the GNU Make default stuff
187#
[230]188ifndef KMK_VERSION
[69]189include $(PATH_KBUILD)/StampOutPredefines.kmk
[216]190endif
[69]191
192#
[72]193# Build platform setup.
[69]194#
195# OS/2
[72]196ifeq ($(BUILD_PLATFORM),os2)
[69]197PATH_TOOLS := $(PATH_TOOLS_OS2)
[83]198EXEC_X86_WIN32 := innopec.exe
[69]199HOSTSUFF_EXE := .exe
200endif
201
202# Linux
[72]203ifeq ($(BUILD_PLATFORM),linux)
[69]204PATH_TOOLS := $(PATH_TOOLS_LNX)
[135]205EXEC_X86_WIN32 := wine
[69]206HOSTSUFF_EXE :=
207endif
[70]208
[69]209# Win32
[72]210ifeq ($(BUILD_PLATFORM),win32)
[69]211PATH_TOOLS := $(PATH_TOOLS_W32)
212EXEC_X86_WIN32 :=
213HOSTSUFF_EXE := .exe
214endif
215
[125]216
[73]217#
218# Build target setup.
219#
220ifeq ($(BUILD_TARGET),os2)
221SUFF_OBJ := .obj
222SUFF_LIB := .lib
223SUFF_DLL := .dll
224SUFF_EXE := .exe
[86]225SUFF_SYS := .sys
[73]226SUFF_RES := .res
227endif
228ifeq ($(BUILD_TARGET),win32)
229SUFF_OBJ := .obj
230SUFF_LIB := .lib
231SUFF_DLL := .dll
232SUFF_EXE := .exe
[86]233SUFF_SYS := .sys
[73]234SUFF_RES := .res
235endif
236ifeq ($(BUILD_TARGET),linux)
237SUFF_OBJ := .o
238SUFF_LIB := .a
239SUFF_DLL := .so
240SUFF_EXE :=
[86]241SUFF_SYS := .a
[73]242SUFF_RES :=
243endif
[69]244
[73]245
[69]246#
247# Standard kBuild tools.
248#
249DEP := $(PATH_TOOLS)/kDep$(HOSTSUFF_EXE)
[179]250ifdef KBUILD_VCC70_DEPS
[175]251DEP_CCXX := $(PATH_TOOLS)/kDepCCxx$(HOSTSUFF_EXE)
[179]252else
253DEP_CCXX := echo $(PATH_TOOLS)/kDepCCxx$(HOSTSUFF_EXE)
254endif
[233]255ifeq ($(MAKE),kmk)
256MAKE := $(PATH_TOOLS)/kmk$(HOSTSUFF_EXE)
257endif
258
[69]259# Standard Unix shell utils.
[230]260ifdef KMK_BUILTIN
261ECHO := kmk_builtin_echo
262MKDIR := kmk_builtin_mkdir
263RM := kmk_builtin_rm
264CP := kmk_builtin_cp
265else
266ECHO := echo
[69]267MKDIR := $(PATH_TOOLS)/mkdir$(HOSTSUFF_EXE)
268RM := $(PATH_TOOLS)/rm$(HOSTSUFF_EXE)
[87]269CP := $(PATH_TOOLS)/cp$(HOSTSUFF_EXE)
[230]270endif
[237]271CP_EXT := $(PATH_TOOLS)/cp$(HOSTSUFF_EXE)
[87]272MV := $(PATH_TOOLS)/mv$(HOSTSUFF_EXE)
[69]273SED := $(PATH_TOOLS)/sed$(HOSTSUFF_EXE)
274CAT := $(PATH_TOOLS)/cat$(HOSTSUFF_EXE)
275# Bourn shell clone.
276MAKESHELL := $(PATH_TOOLS)/ash$(HOSTSUFF_EXE)
277SHELL := $(MAKESHELL)
278export SHELL MAKESHELL
279
280
281#
[73]282# Message macros.
[204]283#
284
[73]285ifndef BUILD_QUIET
[75]286ifdef BUILD_DEBUG
287BUILD_VERBOSE := 9
288endif
[230]289MSG_L1 = @$(ECHO) "kBuild: $1"
[73]290ifdef BUILD_VERBOSE
[230]291MSG_L2 = @$(ECHO) "kBuild: $1"
[75]292QUIET :=
[73]293else
[75]294QUIET := @
[73]295MSG_L2 =
296endif
297ifdef BUILD_DEBUG
[230]298MSG_L3 = @$(ECHO) "kBuild: $1"
[73]299else
300MSG_L3 =
301endif
302else
[75]303QUIET :=
[73]304MSG_L1 =
305MSG_L2 =
306MSG_L3 =
307endif
308
[130]309## ABSPATH - make paths absolute.
[129]310# This implementation is clumsy and doesn't resolve '..' and '.' components.
[73]311#
[129]312# @param $1 The paths to make absolute.
313ABSPATH = $(foreach path,$(1)\
314 ,$(strip $(if $(subst <,,$(firstword $(subst /, ,<$(path)))),\
315 $(if $(patsubst %:,,$(firstword $(subst :,: ,$(path)))),$(PATH_CURRENT)/$(path),$(path)),\
316 $(path))))
[130]317## DIRDEP - make create directory dependencies.
318#
319# @param $1 The paths to the directories which must be created.
320DIRDEP = $(foreach path,$(1),$(path)/.dir_created)
[129]321
[204]322
[129]323## Cygwin kludge.
324# This converts /cygdrive/x/% to x:%.
325#
326# @param $1 The paths to make native.
327# @remark This macro is pretty much obsolete since we don't use cygwin base make.
328ifneq ($(patsubst /cygdrive/%,%,$(CURDIR)),$(CURDIR))
329CYGPATHMIXED = $(foreach path,$(1)\
330 ,$(if $(patsubst /cygdrive/%,,$(path)),$(path),$(patsubst $(strip $(firstword $(subst /, ,$(patsubst /cygdrive/%,%,$(path)))))/%,$(strip $(firstword $(subst /, ,$(patsubst /cygdrive/%,%,$(path))))):/%,$(patsubst /cygdrive/%,%,$(path)))))
331else
332CYGPATHMIXED = $(1)
333endif
334
335#
[69]336# This is how we find the closest config.kmk.
337# It's a little hacky but I think it works fine.
[70]338#
339_CFGDIR := .
[78]340_CFGFILES := ./Config.kmk ./config.kmk
[69]341define def_include_config
[78]342$(eval _CFGDIR := $(_CFGDIR)/$(dir))
343_CFGFILES += $(_CFGDIR)/Config.kmk $(_CFGDIR)/config.kmk
[69]344endef
345# walk down the _RELATIVE_ path specified by DEPTH.
[78]346$(foreach dir,$(subst /, ,$(DEPTH)), $(eval $(def_include_config)) )
[69]347# add the default config file.
[78]348_CFGFILE := $(firstword $(wildcard $(_CFGFILES) $(FILE_KBUILD_CONFIG)))
[69]349_CFGFILES :=
350_CFGDIR :=
351
352# Include the config.kmk we found file (or the default one).
353include $(_CFGFILE)
354
355
356# end-of-file-content
[72]357__header_kmk__ := 1
[69]358endif # __header_kmk__
Note: See TracBrowser for help on using the repository browser.