source: trunk/kBuild/header.kmk@ 340

Last change on this file since 340 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
RevLine 
[69]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
[72]41
[69]42#
[95]43# General purpose macros.
44#
[204]45
[95]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#
[72]53# Assert build type.
[69]54#
55ifndef BUILD_TYPE
56ifndef BUILD_MODE
[72]57$(error kBuild: You must define BUILD_TYPE!)
[69]58endif
59BUILD_TYPE := $(BUILD_MODE)
60endif
[72]61ifeq ($(BUILD_TYPE),DEBUG)
62BUILD_TYPE := debug
63endif
64ifeq ($(BUILD_TYPE),RELEASE)
65BUILD_TYPE := release
66endif
67ifeq ($(BUILD_TYPE),PROFILE)
68BUILD_TYPE := profile
69endif
[69]70
71
72#
[72]73# Assert build platform.
[70]74#
[72]75_BUILD_PLATFORM_OK := 0
[271]76# OS/2 (have uppercase legacy)
[72]77ifeq ($(BUILD_PLATFORM),OS2)
[271]78override BUILD_PLATFORM := os2
[72]79endif
80ifeq ($(BUILD_PLATFORM),os2)
81_BUILD_PLATFORM_OK := 1
82endif
[70]83
[72]84# Linux
85ifeq ($(BUILD_PLATFORM),LINUX)
[88]86$(error kBuild: BUILD_PLATFORM must be all lowercase!)
[72]87endif
88ifeq ($(BUILD_PLATFORM),linux)
89_BUILD_PLATFORM_OK := 1
90endif
91
92# Win32
93ifeq ($(BUILD_PLATFORM),WIN32)
[88]94$(error kBuild: BUILD_PLATFORM must be all lowercase!)
[72]95endif
[83]96ifeq ($(BUILD_PLATFORM),win32)
[72]97_BUILD_PLATFORM_OK := 1
98endif
99
[292]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
[299]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
[72]116ifeq ($(_BUILD_PLATFORM_OK),0)
117$(error kBuild: BUILD_PLATFORM value '$(BUILD_PLATFORM)' was not recongized!)
118endif
[329]119
120# Fill in defaults if needed.
121ifndef BUILD_PLATFORM_ARCH
[95]122BUILD_PLATFORM_ARCH := x86
[329]123endif
124ifndef BUILD_PLATFORM_CPU
[95]125BUILD_PLATFORM_CPU := i586
[329]126endif
[72]127
128
[70]129#
[72]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)
[88]139$(error kBuild: BUILD_TARGET must be all lowercase!)
[72]140endif
141ifeq ($(BUILD_TARGET),os2)
142_BUILD_TARGET_OK := 1
143endif
144
145# Linux
146ifeq ($(BUILD_TARGET),LINUX)
[88]147$(error kBuild: BUILD_TARGET must be all lowercase!)
[72]148endif
149ifeq ($(BUILD_TARGET),linux)
150_BUILD_TARGET_OK := 1
151endif
152
153# Win32
154ifeq ($(BUILD_TARGET),WIN32)
[88]155$(error kBuild: BUILD_TARGET must be all lowercase!)
[72]156endif
[77]157ifeq ($(BUILD_TARGET),win32)
[72]158_BUILD_TARGET_OK := 1
159endif
160
[292]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
[299]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
[72]177ifeq ($(_BUILD_TARGET_OK),0)
178$(error kBuild: BUILD_TARGET value '$(BUILD_TARGET)' was not recongized!)
179endif
180endif
[329]181
182# Fill in defaults if needed.
183ifndef BUILD_TARGET_ARCH
[78]184BUILD_TARGET_ARCH := x86
[329]185endif
186ifndef BUILD_TARGET_CPU
[78]187BUILD_TARGET_CPU := i586
[329]188endif
[72]189
[266]190# Adjust the DEPTH definition first
191ifeq ($(strip $(DEPTH)),)
192DEPTH := .
193endif
[72]194
195#
[69]196# Common definitions.
197#
[306]198ifeq ($(filter abspath,$(KMK_FEATURES)),abspath)
199PATH_CURRENT := $(abspath $(CURDIR))
200PATH_ROOT := $(abspath $(PATH_CURRENT)/$(DEPTH))
201
202else
203
[69]204PATH_CURRENT := $(CURDIR)
[70]205# Get the real root path.
[85]206PATH_ROOT := $(PATH_CURRENT)
[70]207ifneq ($(DEPTH),.)
208$(foreach d,$(subst /, ,$(DEPTH)), $(eval PATH_ROOT := $(patsubst %/,%,$(dir $(PATH_ROOT)))) )
[69]209endif
[306]210
211endif
[70]212# Subdirectory relative to the root.
[306]213ifneq ($(PATH_ROOT),$(PATH_CURRENT))
214CURSUBDIR := $(patsubst $(PATH_ROOT)/%,%,$(PATH_CURRENT))
[266]215else
216CURSUBDIR := .
217endif
[306]218
[70]219# Output directories.
[242]220ifndef PATH_OUT_BASE
221PATH_OUT_BASE := $(PATH_ROOT)/out
222endif
[240]223ifndef PATH_OUT
[329]224ifeq ($(BUILD_PLATFORM_ARCH),x86)
[245]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
[242]228PATH_OUT := $(PATH_OUT_BASE)/$(BUILD_TARGET)/$(BUILD_TYPE)
[240]229endif
[329]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)
[245]235endif
[329]236endif # !x86
237endif # !define PATH_OUT
[69]238PATH_OBJ := $(PATH_OUT)/obj
[271]239PATH_TARGET := $(PATH_OBJ)/$(CURSUBDIR)
240ifndef KBUILD_NEW_STUFF
[69]241PATH_BIN := $(PATH_OUT)/bin
242PATH_LIB := $(PATH_OUT)/lib
243PATH_DOC := $(PATH_ROOT)/out/doc
[271]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
[70]251
252# Usually kBuild is external to the source tree.
253ifndef PATH_KBUILD
254PATH_KBUILD := $(PATH_ROOT)/kBuild
255endif
[306]256ifeq ($(filter abspath,$(KMK_FEATURES)),abspath)
257PATH_KBUILD := $(abspath $(PATH_KBUILD))
258endif
[69]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
[72]264SUFF_DEP := .dep
[204]265MAKEFILE := $(firstword $(MAKEFILE_LIST))
[69]266
[72]267
[69]268#
269# Get rid of the GNU Make default stuff
270#
[230]271ifndef KMK_VERSION
[69]272include $(PATH_KBUILD)/StampOutPredefines.kmk
[216]273endif
[69]274
275#
[72]276# Build platform setup.
[69]277#
[329]278PATH_TOOLS := $(PATH_KBUILD)/bin/$(BUILD_PLATFORM_ARCH).$(BUILD_PLATFORM)
279
[69]280# OS/2
[72]281ifeq ($(BUILD_PLATFORM),os2)
[83]282EXEC_X86_WIN32 := innopec.exe
[69]283HOSTSUFF_EXE := .exe
284endif
285
286# Linux
[72]287ifeq ($(BUILD_PLATFORM),linux)
[135]288EXEC_X86_WIN32 := wine
[69]289HOSTSUFF_EXE :=
290endif
[70]291
[69]292# Win32
[72]293ifeq ($(BUILD_PLATFORM),win32)
[69]294EXEC_X86_WIN32 :=
295HOSTSUFF_EXE := .exe
296endif
297
[299]298# FreeBSD
299ifeq ($(BUILD_PLATFORM),freebsd)
300EXEC_X86_WIN32 := wine
301HOSTSUFF_EXE :=
302endif
[125]303
[299]304
[73]305#
306# Build target setup.
307#
308ifeq ($(BUILD_TARGET),os2)
309SUFF_OBJ := .obj
310SUFF_LIB := .lib
311SUFF_DLL := .dll
312SUFF_EXE := .exe
[86]313SUFF_SYS := .sys
[73]314SUFF_RES := .res
315endif
316ifeq ($(BUILD_TARGET),win32)
317SUFF_OBJ := .obj
318SUFF_LIB := .lib
319SUFF_DLL := .dll
320SUFF_EXE := .exe
[86]321SUFF_SYS := .sys
[73]322SUFF_RES := .res
323endif
324ifeq ($(BUILD_TARGET),linux)
325SUFF_OBJ := .o
326SUFF_LIB := .a
327SUFF_DLL := .so
328SUFF_EXE :=
[86]329SUFF_SYS := .a
[73]330SUFF_RES :=
331endif
[296]332ifeq ($(BUILD_TARGET),l4)
333SUFF_OBJ := .o
334SUFF_LIB := .a
335SUFF_DLL := .s.so
336SUFF_EXE :=
337SUFF_SYS := .a
338SUFF_RES :=
339endif
[69]340
341#
342# Standard kBuild tools.
343#
344DEP := $(PATH_TOOLS)/kDep$(HOSTSUFF_EXE)
[262]345DEP_PRE := $(PATH_TOOLS)/kDepPre$(HOSTSUFF_EXE)
[233]346ifeq ($(MAKE),kmk)
347MAKE := $(PATH_TOOLS)/kmk$(HOSTSUFF_EXE)
348endif
349
[69]350# Standard Unix shell utils.
[230]351ifdef KMK_BUILTIN
352ECHO := kmk_builtin_echo
353MKDIR := kmk_builtin_mkdir
354RM := kmk_builtin_rm
355CP := kmk_builtin_cp
356else
357ECHO := echo
[69]358MKDIR := $(PATH_TOOLS)/mkdir$(HOSTSUFF_EXE)
359RM := $(PATH_TOOLS)/rm$(HOSTSUFF_EXE)
[87]360CP := $(PATH_TOOLS)/cp$(HOSTSUFF_EXE)
[230]361endif
[237]362CP_EXT := $(PATH_TOOLS)/cp$(HOSTSUFF_EXE)
[87]363MV := $(PATH_TOOLS)/mv$(HOSTSUFF_EXE)
[69]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#
[73]373# Message macros.
[204]374#
375
[73]376ifndef BUILD_QUIET
[75]377ifdef BUILD_DEBUG
378BUILD_VERBOSE := 9
379endif
[230]380MSG_L1 = @$(ECHO) "kBuild: $1"
[73]381ifdef BUILD_VERBOSE
[230]382MSG_L2 = @$(ECHO) "kBuild: $1"
[75]383QUIET :=
[73]384else
[75]385QUIET := @
[73]386MSG_L2 =
387endif
388ifdef BUILD_DEBUG
[230]389MSG_L3 = @$(ECHO) "kBuild: $1"
[73]390else
391MSG_L3 =
392endif
393else
[75]394QUIET :=
[73]395MSG_L1 =
396MSG_L2 =
397MSG_L3 =
398endif
399
[130]400## ABSPATH - make paths absolute.
[129]401# This implementation is clumsy and doesn't resolve '..' and '.' components.
[73]402#
[129]403# @param $1 The paths to make absolute.
[306]404ifeq ($(filter abspath,$(KMK_FEATURES)),abspath)
405ABSPATH = $(abspath $(1))
406else
[129]407ABSPATH = $(foreach path,$(1)\
408 ,$(strip $(if $(subst <,,$(firstword $(subst /, ,<$(path)))),\
409 $(if $(patsubst %:,,$(firstword $(subst :,: ,$(path)))),$(PATH_CURRENT)/$(path),$(path)),\
410 $(path))))
[306]411endif
412
[130]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)
[129]417
[204]418
[129]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#
[69]432# This is how we find the closest config.kmk.
433# It's a little hacky but I think it works fine.
[70]434#
435_CFGDIR := .
[78]436_CFGFILES := ./Config.kmk ./config.kmk
[69]437define def_include_config
[78]438$(eval _CFGDIR := $(_CFGDIR)/$(dir))
439_CFGFILES += $(_CFGDIR)/Config.kmk $(_CFGDIR)/config.kmk
[69]440endef
441# walk down the _RELATIVE_ path specified by DEPTH.
[78]442$(foreach dir,$(subst /, ,$(DEPTH)), $(eval $(def_include_config)) )
[69]443# add the default config file.
[78]444_CFGFILE := $(firstword $(wildcard $(_CFGFILES) $(FILE_KBUILD_CONFIG)))
[69]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
[72]453__header_kmk__ := 1
[69]454endif # __header_kmk__
Note: See TracBrowser for help on using the repository browser.