source: trunk/kBuild/header.kmk@ 239

Last change on this file since 239 was 237, checked in by bird, 20 years ago

Fixed CP builtin problem.

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