source: trunk/kBuild/header.kmk@ 294

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

Added L4.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 9.3 KB
Line 
1# $Id: header.kmk 292 2005-06-01 15:06:11Z 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
283
284
285#
286# Standard kBuild tools.
287#
288DEP := $(PATH_TOOLS)/kDep$(HOSTSUFF_EXE)
289DEP_PRE := $(PATH_TOOLS)/kDepPre$(HOSTSUFF_EXE)
290ifeq ($(MAKE),kmk)
291MAKE := $(PATH_TOOLS)/kmk$(HOSTSUFF_EXE)
292endif
293
294# Standard Unix shell utils.
295ifdef KMK_BUILTIN
296ECHO := kmk_builtin_echo
297MKDIR := kmk_builtin_mkdir
298RM := kmk_builtin_rm
299CP := kmk_builtin_cp
300else
301ECHO := echo
302MKDIR := $(PATH_TOOLS)/mkdir$(HOSTSUFF_EXE)
303RM := $(PATH_TOOLS)/rm$(HOSTSUFF_EXE)
304CP := $(PATH_TOOLS)/cp$(HOSTSUFF_EXE)
305endif
306CP_EXT := $(PATH_TOOLS)/cp$(HOSTSUFF_EXE)
307MV := $(PATH_TOOLS)/mv$(HOSTSUFF_EXE)
308SED := $(PATH_TOOLS)/sed$(HOSTSUFF_EXE)
309CAT := $(PATH_TOOLS)/cat$(HOSTSUFF_EXE)
310# Bourn shell clone.
311MAKESHELL := $(PATH_TOOLS)/ash$(HOSTSUFF_EXE)
312SHELL := $(MAKESHELL)
313export SHELL MAKESHELL
314
315
316#
317# Message macros.
318#
319
320ifndef BUILD_QUIET
321ifdef BUILD_DEBUG
322BUILD_VERBOSE := 9
323endif
324MSG_L1 = @$(ECHO) "kBuild: $1"
325ifdef BUILD_VERBOSE
326MSG_L2 = @$(ECHO) "kBuild: $1"
327QUIET :=
328else
329QUIET := @
330MSG_L2 =
331endif
332ifdef BUILD_DEBUG
333MSG_L3 = @$(ECHO) "kBuild: $1"
334else
335MSG_L3 =
336endif
337else
338QUIET :=
339MSG_L1 =
340MSG_L2 =
341MSG_L3 =
342endif
343
344## ABSPATH - make paths absolute.
345# This implementation is clumsy and doesn't resolve '..' and '.' components.
346#
347# @param $1 The paths to make absolute.
348ABSPATH = $(foreach path,$(1)\
349 ,$(strip $(if $(subst <,,$(firstword $(subst /, ,<$(path)))),\
350 $(if $(patsubst %:,,$(firstword $(subst :,: ,$(path)))),$(PATH_CURRENT)/$(path),$(path)),\
351 $(path))))
352## DIRDEP - make create directory dependencies.
353#
354# @param $1 The paths to the directories which must be created.
355DIRDEP = $(foreach path,$(1),$(path)/.dir_created)
356
357
358## Cygwin kludge.
359# This converts /cygdrive/x/% to x:%.
360#
361# @param $1 The paths to make native.
362# @remark This macro is pretty much obsolete since we don't use cygwin base make.
363ifneq ($(patsubst /cygdrive/%,%,$(CURDIR)),$(CURDIR))
364CYGPATHMIXED = $(foreach path,$(1)\
365 ,$(if $(patsubst /cygdrive/%,,$(path)),$(path),$(patsubst $(strip $(firstword $(subst /, ,$(patsubst /cygdrive/%,%,$(path)))))/%,$(strip $(firstword $(subst /, ,$(patsubst /cygdrive/%,%,$(path))))):/%,$(patsubst /cygdrive/%,%,$(path)))))
366else
367CYGPATHMIXED = $(1)
368endif
369
370#
371# This is how we find the closest config.kmk.
372# It's a little hacky but I think it works fine.
373#
374_CFGDIR := .
375_CFGFILES := ./Config.kmk ./config.kmk
376define def_include_config
377$(eval _CFGDIR := $(_CFGDIR)/$(dir))
378_CFGFILES += $(_CFGDIR)/Config.kmk $(_CFGDIR)/config.kmk
379endef
380# walk down the _RELATIVE_ path specified by DEPTH.
381$(foreach dir,$(subst /, ,$(DEPTH)), $(eval $(def_include_config)) )
382# add the default config file.
383_CFGFILE := $(firstword $(wildcard $(_CFGFILES) $(FILE_KBUILD_CONFIG)))
384_CFGFILES :=
385_CFGDIR :=
386
387# Include the config.kmk we found file (or the default one).
388include $(_CFGFILE)
389
390
391# end-of-file-content
392__header_kmk__ := 1
393endif # __header_kmk__
Note: See TracBrowser for help on using the repository browser.