source: trunk/kBuild/header.kmk@ 319

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

Use $(abspath ) when possible.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 10.4 KB
Line 
1# $Id: header.kmk 306 2005-08-11 20:24:19Z 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 (have uppercase legacy)
77ifeq ($(BUILD_PLATFORM),OS2)
78override BUILD_PLATFORM := os2
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
100# L4
101ifeq ($(BUILD_PLATFORM),L4)
102$(error kBuild: BUILD_PLATFORM must be all lowercase!)
103endif
104ifeq ($(BUILD_PLATFORM),l4)
105_BUILD_PLATFORM_OK := 1
106endif
107
108# FreeBSD
109ifeq ($(BUILD_PLATFORM),FreeBSD)
110$(error kBuild: BUILD_PLATFORM must be all lowercase!)
111endif
112ifeq ($(BUILD_PLATFORM),freebsd)
113_BUILD_PLATFORM_OK := 1
114endif
115
116ifeq ($(_BUILD_PLATFORM_OK),0)
117$(error kBuild: BUILD_PLATFORM value '$(BUILD_PLATFORM)' was not recongized!)
118endif
119BUILD_PLATFORM_ARCH := x86
120BUILD_PLATFORM_CPU := i586
121
122
123#
124# Assert target platform.
125#
126ifndef BUILD_TARGET
127# not defined, set to the same as build platform
128BUILD_TARGET := $(BUILD_PLATFORM)
129else
130_BUILD_TARGET_OK := 0
131# OS/2
132ifeq ($(BUILD_TARGET),OS2)
133$(error kBuild: BUILD_TARGET must be all lowercase!)
134endif
135ifeq ($(BUILD_TARGET),os2)
136_BUILD_TARGET_OK := 1
137endif
138
139# Linux
140ifeq ($(BUILD_TARGET),LINUX)
141$(error kBuild: BUILD_TARGET must be all lowercase!)
142endif
143ifeq ($(BUILD_TARGET),linux)
144_BUILD_TARGET_OK := 1
145endif
146
147# Win32
148ifeq ($(BUILD_TARGET),WIN32)
149$(error kBuild: BUILD_TARGET must be all lowercase!)
150endif
151ifeq ($(BUILD_TARGET),win32)
152_BUILD_TARGET_OK := 1
153endif
154
155# L4
156ifeq ($(BUILD_TARGET),L4)
157$(error kBuild: BUILD_TARGET must be all lowercase!)
158endif
159ifeq ($(BUILD_TARGET),l4)
160_BUILD_TARGET_OK := 1
161endif
162
163# FreeBSD
164ifeq ($(BUILD_TARGET),FreeBSD)
165$(error kBuild: BUILD_TARGET must be all lowercase!)
166endif
167ifeq ($(BUILD_TARGET),freebsd)
168_BUILD_TARGET_OK := 1
169endif
170
171ifeq ($(_BUILD_TARGET_OK),0)
172$(error kBuild: BUILD_TARGET value '$(BUILD_TARGET)' was not recongized!)
173endif
174endif
175BUILD_TARGET_ARCH := x86
176BUILD_TARGET_CPU := i586
177
178# Adjust the DEPTH definition first
179ifeq ($(strip $(DEPTH)),)
180DEPTH := .
181endif
182
183#
184# Common definitions.
185#
186ifeq ($(filter abspath,$(KMK_FEATURES)),abspath)
187PATH_CURRENT := $(abspath $(CURDIR))
188PATH_ROOT := $(abspath $(PATH_CURRENT)/$(DEPTH))
189
190else
191
192PATH_CURRENT := $(CURDIR)
193# Get the real root path.
194PATH_ROOT := $(PATH_CURRENT)
195ifneq ($(DEPTH),.)
196$(foreach d,$(subst /, ,$(DEPTH)), $(eval PATH_ROOT := $(patsubst %/,%,$(dir $(PATH_ROOT)))) )
197endif
198
199endif
200# Subdirectory relative to the root.
201ifneq ($(PATH_ROOT),$(PATH_CURRENT))
202CURSUBDIR := $(patsubst $(PATH_ROOT)/%,%,$(PATH_CURRENT))
203else
204CURSUBDIR := .
205endif
206
207# Output directories.
208ifndef PATH_OUT_BASE
209PATH_OUT_BASE := $(PATH_ROOT)/out
210endif
211ifndef PATH_OUT
212ifdef BUILD_TARGET_SUB # (BUILD_TARGET_SUB is not currently recognized by kBuild in any other places.)
213PATH_OUT := $(PATH_OUT_BASE)/$(BUILD_TARGET)/$(BUILD_TARGET_SUB)/$(BUILD_TYPE)
214else
215PATH_OUT := $(PATH_OUT_BASE)/$(BUILD_TARGET)/$(BUILD_TYPE)
216endif
217endif
218PATH_OBJ := $(PATH_OUT)/obj
219PATH_TARGET := $(PATH_OBJ)/$(CURSUBDIR)
220ifndef KBUILD_NEW_STUFF
221PATH_BIN := $(PATH_OUT)/bin
222PATH_LIB := $(PATH_OUT)/lib
223PATH_DOC := $(PATH_ROOT)/out/doc
224else
225PATH_INS := $(PATH_OUT)
226PATH_BIN := $(PATH_INS)/bin
227PATH_DLL := $(PATH_INS)/bin
228PATH_LIB := $(PATH_INS)/lib
229PATH_DOC := $(PATH_INS)/doc
230endif
231
232# Usually kBuild is external to the source tree.
233ifndef PATH_KBUILD
234PATH_KBUILD := $(PATH_ROOT)/kBuild
235endif
236ifeq ($(filter abspath,$(KMK_FEATURES)),abspath)
237PATH_KBUILD := $(abspath $(PATH_KBUILD))
238endif
239# kBuild tools
240PATH_TOOLS_W32 := $(PATH_KBUILD)/bin/x86.win32
241PATH_TOOLS_LNX := $(PATH_KBUILD)/bin/x86.linux
242PATH_TOOLS_OS2 := $(PATH_KBUILD)/bin/x86.os2
243PATH_TOOLS_FREEBSD := $(PATH_KBUILD)/bin/amd64.freebsd
244# kBuild files which might be of interest.
245FILE_KBUILD_HEADER := $(PATH_KBUILD)/header.kmk
246FILE_KBUILD_CONFIG := $(PATH_KBUILD)/config.kmk
247FILE_KBUILD_FOOTER := $(PATH_KBUILD)/footer.kmk
248
249SUFF_DEP := .dep
250MAKEFILE := $(firstword $(MAKEFILE_LIST))
251
252
253#
254# Get rid of the GNU Make default stuff
255#
256ifndef KMK_VERSION
257include $(PATH_KBUILD)/StampOutPredefines.kmk
258endif
259
260#
261# Build platform setup.
262#
263# OS/2
264ifeq ($(BUILD_PLATFORM),os2)
265PATH_TOOLS := $(PATH_TOOLS_OS2)
266EXEC_X86_WIN32 := innopec.exe
267HOSTSUFF_EXE := .exe
268endif
269
270# Linux
271ifeq ($(BUILD_PLATFORM),linux)
272PATH_TOOLS := $(PATH_TOOLS_LNX)
273EXEC_X86_WIN32 := wine
274HOSTSUFF_EXE :=
275endif
276
277# Win32
278ifeq ($(BUILD_PLATFORM),win32)
279PATH_TOOLS := $(PATH_TOOLS_W32)
280EXEC_X86_WIN32 :=
281HOSTSUFF_EXE := .exe
282endif
283
284# FreeBSD
285ifeq ($(BUILD_PLATFORM),freebsd)
286PATH_TOOLS := $(PATH_TOOLS_FREEBSD)
287EXEC_X86_WIN32 := wine
288HOSTSUFF_EXE :=
289endif
290
291
292#
293# Build target setup.
294#
295ifeq ($(BUILD_TARGET),os2)
296SUFF_OBJ := .obj
297SUFF_LIB := .lib
298SUFF_DLL := .dll
299SUFF_EXE := .exe
300SUFF_SYS := .sys
301SUFF_RES := .res
302endif
303ifeq ($(BUILD_TARGET),win32)
304SUFF_OBJ := .obj
305SUFF_LIB := .lib
306SUFF_DLL := .dll
307SUFF_EXE := .exe
308SUFF_SYS := .sys
309SUFF_RES := .res
310endif
311ifeq ($(BUILD_TARGET),linux)
312SUFF_OBJ := .o
313SUFF_LIB := .a
314SUFF_DLL := .so
315SUFF_EXE :=
316SUFF_SYS := .a
317SUFF_RES :=
318endif
319ifeq ($(BUILD_TARGET),l4)
320SUFF_OBJ := .o
321SUFF_LIB := .a
322SUFF_DLL := .s.so
323SUFF_EXE :=
324SUFF_SYS := .a
325SUFF_RES :=
326endif
327
328#
329# Standard kBuild tools.
330#
331DEP := $(PATH_TOOLS)/kDep$(HOSTSUFF_EXE)
332DEP_PRE := $(PATH_TOOLS)/kDepPre$(HOSTSUFF_EXE)
333ifeq ($(MAKE),kmk)
334MAKE := $(PATH_TOOLS)/kmk$(HOSTSUFF_EXE)
335endif
336
337# Standard Unix shell utils.
338ifdef KMK_BUILTIN
339ECHO := kmk_builtin_echo
340MKDIR := kmk_builtin_mkdir
341RM := kmk_builtin_rm
342CP := kmk_builtin_cp
343else
344ECHO := echo
345MKDIR := $(PATH_TOOLS)/mkdir$(HOSTSUFF_EXE)
346RM := $(PATH_TOOLS)/rm$(HOSTSUFF_EXE)
347CP := $(PATH_TOOLS)/cp$(HOSTSUFF_EXE)
348endif
349CP_EXT := $(PATH_TOOLS)/cp$(HOSTSUFF_EXE)
350MV := $(PATH_TOOLS)/mv$(HOSTSUFF_EXE)
351SED := $(PATH_TOOLS)/sed$(HOSTSUFF_EXE)
352CAT := $(PATH_TOOLS)/cat$(HOSTSUFF_EXE)
353# Bourn shell clone.
354MAKESHELL := $(PATH_TOOLS)/ash$(HOSTSUFF_EXE)
355SHELL := $(MAKESHELL)
356export SHELL MAKESHELL
357
358
359#
360# Message macros.
361#
362
363ifndef BUILD_QUIET
364ifdef BUILD_DEBUG
365BUILD_VERBOSE := 9
366endif
367MSG_L1 = @$(ECHO) "kBuild: $1"
368ifdef BUILD_VERBOSE
369MSG_L2 = @$(ECHO) "kBuild: $1"
370QUIET :=
371else
372QUIET := @
373MSG_L2 =
374endif
375ifdef BUILD_DEBUG
376MSG_L3 = @$(ECHO) "kBuild: $1"
377else
378MSG_L3 =
379endif
380else
381QUIET :=
382MSG_L1 =
383MSG_L2 =
384MSG_L3 =
385endif
386
387## ABSPATH - make paths absolute.
388# This implementation is clumsy and doesn't resolve '..' and '.' components.
389#
390# @param $1 The paths to make absolute.
391ifeq ($(filter abspath,$(KMK_FEATURES)),abspath)
392ABSPATH = $(abspath $(1))
393else
394ABSPATH = $(foreach path,$(1)\
395 ,$(strip $(if $(subst <,,$(firstword $(subst /, ,<$(path)))),\
396 $(if $(patsubst %:,,$(firstword $(subst :,: ,$(path)))),$(PATH_CURRENT)/$(path),$(path)),\
397 $(path))))
398endif
399
400## DIRDEP - make create directory dependencies.
401#
402# @param $1 The paths to the directories which must be created.
403DIRDEP = $(foreach path,$(1),$(path)/.dir_created)
404
405
406## Cygwin kludge.
407# This converts /cygdrive/x/% to x:%.
408#
409# @param $1 The paths to make native.
410# @remark This macro is pretty much obsolete since we don't use cygwin base make.
411ifneq ($(patsubst /cygdrive/%,%,$(CURDIR)),$(CURDIR))
412CYGPATHMIXED = $(foreach path,$(1)\
413 ,$(if $(patsubst /cygdrive/%,,$(path)),$(path),$(patsubst $(strip $(firstword $(subst /, ,$(patsubst /cygdrive/%,%,$(path)))))/%,$(strip $(firstword $(subst /, ,$(patsubst /cygdrive/%,%,$(path))))):/%,$(patsubst /cygdrive/%,%,$(path)))))
414else
415CYGPATHMIXED = $(1)
416endif
417
418#
419# This is how we find the closest config.kmk.
420# It's a little hacky but I think it works fine.
421#
422_CFGDIR := .
423_CFGFILES := ./Config.kmk ./config.kmk
424define def_include_config
425$(eval _CFGDIR := $(_CFGDIR)/$(dir))
426_CFGFILES += $(_CFGDIR)/Config.kmk $(_CFGDIR)/config.kmk
427endef
428# walk down the _RELATIVE_ path specified by DEPTH.
429$(foreach dir,$(subst /, ,$(DEPTH)), $(eval $(def_include_config)) )
430# add the default config file.
431_CFGFILE := $(firstword $(wildcard $(_CFGFILES) $(FILE_KBUILD_CONFIG)))
432_CFGFILES :=
433_CFGDIR :=
434
435# Include the config.kmk we found file (or the default one).
436include $(_CFGFILE)
437
438
439# end-of-file-content
440__header_kmk__ := 1
441endif # __header_kmk__
Note: See TracBrowser for help on using the repository browser.