source: trunk/kBuild/header.kmk@ 329

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

Fixed a couple of defaults so it all works right on amd64.

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