source: trunk/kBuild/header.kmk@ 296

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

l4 suffixes.

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