source: trunk/kBuild/header.kmk@ 266

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

DEPTH=. caused invalid CURSUBDIR and a lot of trouble came from that.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 8.8 KB
Line 
1# $Id: header.kmk 266 2005-05-01 04:33:30Z 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# Adjust the DEPTH definition first
147ifeq ($(strip $(DEPTH)),)
148DEPTH := .
149endif
150
151#
152# Common definitions.
153#
154PATH_CURRENT := $(CURDIR)
155# Get the real root path.
156PATH_ROOT := $(PATH_CURRENT)
157ifneq ($(DEPTH),.)
158$(foreach d,$(subst /, ,$(DEPTH)), $(eval PATH_ROOT := $(patsubst %/,%,$(dir $(PATH_ROOT)))) )
159endif
160# Subdirectory relative to the root.
161ifneq ($(DEPTH),.)
162CURSUBDIR := $(patsubst $(PATH_ROOT)/%,%,$(CURDIR))
163else
164CURSUBDIR := .
165endif
166# Output directories.
167ifndef PATH_OUT_BASE
168PATH_OUT_BASE := $(PATH_ROOT)/out
169endif
170ifndef PATH_OUT
171ifdef BUILD_TARGET_SUB # (BUILD_TARGET_SUB is not currently recognized by kBuild in any other places.)
172PATH_OUT := $(PATH_OUT_BASE)/$(BUILD_TARGET)/$(BUILD_TARGET_SUB)/$(BUILD_TYPE)
173else
174PATH_OUT := $(PATH_OUT_BASE)/$(BUILD_TARGET)/$(BUILD_TYPE)
175endif
176endif
177PATH_OBJ := $(PATH_OUT)/obj
178PATH_BIN := $(PATH_OUT)/bin
179PATH_LIB := $(PATH_OUT)/lib
180PATH_DOC := $(PATH_ROOT)/out/doc
181PATH_TARGET := $(PATH_OBJ)/$(CURSUBDIR)
182
183# Usually kBuild is external to the source tree.
184ifndef PATH_KBUILD
185PATH_KBUILD := $(PATH_ROOT)/kBuild
186endif
187# kBuild tools
188PATH_TOOLS_W32 := $(PATH_KBUILD)/bin/x86.win32
189PATH_TOOLS_LNX := $(PATH_KBUILD)/bin/x86.linux
190PATH_TOOLS_OS2 := $(PATH_KBUILD)/bin/x86.os2
191# kBuild files which might be of interest.
192FILE_KBUILD_HEADER := $(PATH_KBUILD)/header.kmk
193FILE_KBUILD_CONFIG := $(PATH_KBUILD)/config.kmk
194FILE_KBUILD_FOOTER := $(PATH_KBUILD)/footer.kmk
195
196SUFF_DEP := .dep
197MAKEFILE := $(firstword $(MAKEFILE_LIST))
198
199
200#
201# Get rid of the GNU Make default stuff
202#
203ifndef KMK_VERSION
204include $(PATH_KBUILD)/StampOutPredefines.kmk
205endif
206
207#
208# Build platform setup.
209#
210# OS/2
211ifeq ($(BUILD_PLATFORM),os2)
212PATH_TOOLS := $(PATH_TOOLS_OS2)
213EXEC_X86_WIN32 := innopec.exe
214HOSTSUFF_EXE := .exe
215endif
216
217# Linux
218ifeq ($(BUILD_PLATFORM),linux)
219PATH_TOOLS := $(PATH_TOOLS_LNX)
220EXEC_X86_WIN32 := wine
221HOSTSUFF_EXE :=
222endif
223
224# Win32
225ifeq ($(BUILD_PLATFORM),win32)
226PATH_TOOLS := $(PATH_TOOLS_W32)
227EXEC_X86_WIN32 :=
228HOSTSUFF_EXE := .exe
229endif
230
231
232#
233# Build target setup.
234#
235ifeq ($(BUILD_TARGET),os2)
236SUFF_OBJ := .obj
237SUFF_LIB := .lib
238SUFF_DLL := .dll
239SUFF_EXE := .exe
240SUFF_SYS := .sys
241SUFF_RES := .res
242endif
243ifeq ($(BUILD_TARGET),win32)
244SUFF_OBJ := .obj
245SUFF_LIB := .lib
246SUFF_DLL := .dll
247SUFF_EXE := .exe
248SUFF_SYS := .sys
249SUFF_RES := .res
250endif
251ifeq ($(BUILD_TARGET),linux)
252SUFF_OBJ := .o
253SUFF_LIB := .a
254SUFF_DLL := .so
255SUFF_EXE :=
256SUFF_SYS := .a
257SUFF_RES :=
258endif
259
260
261#
262# Standard kBuild tools.
263#
264DEP := $(PATH_TOOLS)/kDep$(HOSTSUFF_EXE)
265DEP_PRE := $(PATH_TOOLS)/kDepPre$(HOSTSUFF_EXE)
266ifeq ($(MAKE),kmk)
267MAKE := $(PATH_TOOLS)/kmk$(HOSTSUFF_EXE)
268endif
269
270# Standard Unix shell utils.
271ifdef KMK_BUILTIN
272ECHO := kmk_builtin_echo
273MKDIR := kmk_builtin_mkdir
274RM := kmk_builtin_rm
275CP := kmk_builtin_cp
276else
277ECHO := echo
278MKDIR := $(PATH_TOOLS)/mkdir$(HOSTSUFF_EXE)
279RM := $(PATH_TOOLS)/rm$(HOSTSUFF_EXE)
280CP := $(PATH_TOOLS)/cp$(HOSTSUFF_EXE)
281endif
282CP_EXT := $(PATH_TOOLS)/cp$(HOSTSUFF_EXE)
283MV := $(PATH_TOOLS)/mv$(HOSTSUFF_EXE)
284SED := $(PATH_TOOLS)/sed$(HOSTSUFF_EXE)
285CAT := $(PATH_TOOLS)/cat$(HOSTSUFF_EXE)
286# Bourn shell clone.
287MAKESHELL := $(PATH_TOOLS)/ash$(HOSTSUFF_EXE)
288SHELL := $(MAKESHELL)
289export SHELL MAKESHELL
290
291
292#
293# Message macros.
294#
295
296ifndef BUILD_QUIET
297ifdef BUILD_DEBUG
298BUILD_VERBOSE := 9
299endif
300MSG_L1 = @$(ECHO) "kBuild: $1"
301ifdef BUILD_VERBOSE
302MSG_L2 = @$(ECHO) "kBuild: $1"
303QUIET :=
304else
305QUIET := @
306MSG_L2 =
307endif
308ifdef BUILD_DEBUG
309MSG_L3 = @$(ECHO) "kBuild: $1"
310else
311MSG_L3 =
312endif
313else
314QUIET :=
315MSG_L1 =
316MSG_L2 =
317MSG_L3 =
318endif
319
320## ABSPATH - make paths absolute.
321# This implementation is clumsy and doesn't resolve '..' and '.' components.
322#
323# @param $1 The paths to make absolute.
324ABSPATH = $(foreach path,$(1)\
325 ,$(strip $(if $(subst <,,$(firstword $(subst /, ,<$(path)))),\
326 $(if $(patsubst %:,,$(firstword $(subst :,: ,$(path)))),$(PATH_CURRENT)/$(path),$(path)),\
327 $(path))))
328## DIRDEP - make create directory dependencies.
329#
330# @param $1 The paths to the directories which must be created.
331DIRDEP = $(foreach path,$(1),$(path)/.dir_created)
332
333
334## Cygwin kludge.
335# This converts /cygdrive/x/% to x:%.
336#
337# @param $1 The paths to make native.
338# @remark This macro is pretty much obsolete since we don't use cygwin base make.
339ifneq ($(patsubst /cygdrive/%,%,$(CURDIR)),$(CURDIR))
340CYGPATHMIXED = $(foreach path,$(1)\
341 ,$(if $(patsubst /cygdrive/%,,$(path)),$(path),$(patsubst $(strip $(firstword $(subst /, ,$(patsubst /cygdrive/%,%,$(path)))))/%,$(strip $(firstword $(subst /, ,$(patsubst /cygdrive/%,%,$(path))))):/%,$(patsubst /cygdrive/%,%,$(path)))))
342else
343CYGPATHMIXED = $(1)
344endif
345
346#
347# This is how we find the closest config.kmk.
348# It's a little hacky but I think it works fine.
349#
350_CFGDIR := .
351_CFGFILES := ./Config.kmk ./config.kmk
352define def_include_config
353$(eval _CFGDIR := $(_CFGDIR)/$(dir))
354_CFGFILES += $(_CFGDIR)/Config.kmk $(_CFGDIR)/config.kmk
355endef
356# walk down the _RELATIVE_ path specified by DEPTH.
357$(foreach dir,$(subst /, ,$(DEPTH)), $(eval $(def_include_config)) )
358# add the default config file.
359_CFGFILE := $(firstword $(wildcard $(_CFGFILES) $(FILE_KBUILD_CONFIG)))
360_CFGFILES :=
361_CFGDIR :=
362
363# Include the config.kmk we found file (or the default one).
364include $(_CFGFILE)
365
366
367# end-of-file-content
368__header_kmk__ := 1
369endif # __header_kmk__
Note: See TracBrowser for help on using the repository browser.