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
RevLine 
[69]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
[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
[72]108ifeq ($(_BUILD_PLATFORM_OK),0)
109$(error kBuild: BUILD_PLATFORM value '$(BUILD_PLATFORM)' was not recongized!)
110endif
[95]111BUILD_PLATFORM_ARCH := x86
112BUILD_PLATFORM_CPU := i586
[72]113
114
[70]115#
[72]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)
[88]125$(error kBuild: BUILD_TARGET must be all lowercase!)
[72]126endif
127ifeq ($(BUILD_TARGET),os2)
128_BUILD_TARGET_OK := 1
129endif
130
131# Linux
132ifeq ($(BUILD_TARGET),LINUX)
[88]133$(error kBuild: BUILD_TARGET must be all lowercase!)
[72]134endif
135ifeq ($(BUILD_TARGET),linux)
136_BUILD_TARGET_OK := 1
137endif
138
139# Win32
140ifeq ($(BUILD_TARGET),WIN32)
[88]141$(error kBuild: BUILD_TARGET must be all lowercase!)
[72]142endif
[77]143ifeq ($(BUILD_TARGET),win32)
[72]144_BUILD_TARGET_OK := 1
145endif
146
[292]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
[72]155ifeq ($(_BUILD_TARGET_OK),0)
156$(error kBuild: BUILD_TARGET value '$(BUILD_TARGET)' was not recongized!)
157endif
158endif
[78]159BUILD_TARGET_ARCH := x86
160BUILD_TARGET_CPU := i586
[72]161
[266]162# Adjust the DEPTH definition first
163ifeq ($(strip $(DEPTH)),)
164DEPTH := .
165endif
[72]166
167#
[69]168# Common definitions.
169#
170PATH_CURRENT := $(CURDIR)
[70]171# Get the real root path.
[85]172PATH_ROOT := $(PATH_CURRENT)
[70]173ifneq ($(DEPTH),.)
174$(foreach d,$(subst /, ,$(DEPTH)), $(eval PATH_ROOT := $(patsubst %/,%,$(dir $(PATH_ROOT)))) )
[69]175endif
[70]176# Subdirectory relative to the root.
[266]177ifneq ($(DEPTH),.)
[72]178CURSUBDIR := $(patsubst $(PATH_ROOT)/%,%,$(CURDIR))
[266]179else
180CURSUBDIR := .
181endif
[70]182# Output directories.
[242]183ifndef PATH_OUT_BASE
184PATH_OUT_BASE := $(PATH_ROOT)/out
185endif
[240]186ifndef PATH_OUT
[245]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
[242]190PATH_OUT := $(PATH_OUT_BASE)/$(BUILD_TARGET)/$(BUILD_TYPE)
[240]191endif
[245]192endif
[69]193PATH_OBJ := $(PATH_OUT)/obj
[271]194PATH_TARGET := $(PATH_OBJ)/$(CURSUBDIR)
195ifndef KBUILD_NEW_STUFF
[69]196PATH_BIN := $(PATH_OUT)/bin
197PATH_LIB := $(PATH_OUT)/lib
198PATH_DOC := $(PATH_ROOT)/out/doc
[271]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
[70]206
207# Usually kBuild is external to the source tree.
208ifndef PATH_KBUILD
209PATH_KBUILD := $(PATH_ROOT)/kBuild
210endif
211# kBuild tools
[69]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
[72]220SUFF_DEP := .dep
[204]221MAKEFILE := $(firstword $(MAKEFILE_LIST))
[69]222
[72]223
[69]224#
225# Get rid of the GNU Make default stuff
226#
[230]227ifndef KMK_VERSION
[69]228include $(PATH_KBUILD)/StampOutPredefines.kmk
[216]229endif
[69]230
231#
[72]232# Build platform setup.
[69]233#
234# OS/2
[72]235ifeq ($(BUILD_PLATFORM),os2)
[69]236PATH_TOOLS := $(PATH_TOOLS_OS2)
[83]237EXEC_X86_WIN32 := innopec.exe
[69]238HOSTSUFF_EXE := .exe
239endif
240
241# Linux
[72]242ifeq ($(BUILD_PLATFORM),linux)
[69]243PATH_TOOLS := $(PATH_TOOLS_LNX)
[135]244EXEC_X86_WIN32 := wine
[69]245HOSTSUFF_EXE :=
246endif
[70]247
[69]248# Win32
[72]249ifeq ($(BUILD_PLATFORM),win32)
[69]250PATH_TOOLS := $(PATH_TOOLS_W32)
251EXEC_X86_WIN32 :=
252HOSTSUFF_EXE := .exe
253endif
254
[125]255
[73]256#
257# Build target setup.
258#
259ifeq ($(BUILD_TARGET),os2)
260SUFF_OBJ := .obj
261SUFF_LIB := .lib
262SUFF_DLL := .dll
263SUFF_EXE := .exe
[86]264SUFF_SYS := .sys
[73]265SUFF_RES := .res
266endif
267ifeq ($(BUILD_TARGET),win32)
268SUFF_OBJ := .obj
269SUFF_LIB := .lib
270SUFF_DLL := .dll
271SUFF_EXE := .exe
[86]272SUFF_SYS := .sys
[73]273SUFF_RES := .res
274endif
275ifeq ($(BUILD_TARGET),linux)
276SUFF_OBJ := .o
277SUFF_LIB := .a
278SUFF_DLL := .so
279SUFF_EXE :=
[86]280SUFF_SYS := .a
[73]281SUFF_RES :=
282endif
[296]283ifeq ($(BUILD_TARGET),l4)
284SUFF_OBJ := .o
285SUFF_LIB := .a
286SUFF_DLL := .s.so
287SUFF_EXE :=
288SUFF_SYS := .a
289SUFF_RES :=
290endif
[69]291
292#
293# Standard kBuild tools.
294#
295DEP := $(PATH_TOOLS)/kDep$(HOSTSUFF_EXE)
[262]296DEP_PRE := $(PATH_TOOLS)/kDepPre$(HOSTSUFF_EXE)
[233]297ifeq ($(MAKE),kmk)
298MAKE := $(PATH_TOOLS)/kmk$(HOSTSUFF_EXE)
299endif
300
[69]301# Standard Unix shell utils.
[230]302ifdef KMK_BUILTIN
303ECHO := kmk_builtin_echo
304MKDIR := kmk_builtin_mkdir
305RM := kmk_builtin_rm
306CP := kmk_builtin_cp
307else
308ECHO := echo
[69]309MKDIR := $(PATH_TOOLS)/mkdir$(HOSTSUFF_EXE)
310RM := $(PATH_TOOLS)/rm$(HOSTSUFF_EXE)
[87]311CP := $(PATH_TOOLS)/cp$(HOSTSUFF_EXE)
[230]312endif
[237]313CP_EXT := $(PATH_TOOLS)/cp$(HOSTSUFF_EXE)
[87]314MV := $(PATH_TOOLS)/mv$(HOSTSUFF_EXE)
[69]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#
[73]324# Message macros.
[204]325#
326
[73]327ifndef BUILD_QUIET
[75]328ifdef BUILD_DEBUG
329BUILD_VERBOSE := 9
330endif
[230]331MSG_L1 = @$(ECHO) "kBuild: $1"
[73]332ifdef BUILD_VERBOSE
[230]333MSG_L2 = @$(ECHO) "kBuild: $1"
[75]334QUIET :=
[73]335else
[75]336QUIET := @
[73]337MSG_L2 =
338endif
339ifdef BUILD_DEBUG
[230]340MSG_L3 = @$(ECHO) "kBuild: $1"
[73]341else
342MSG_L3 =
343endif
344else
[75]345QUIET :=
[73]346MSG_L1 =
347MSG_L2 =
348MSG_L3 =
349endif
350
[130]351## ABSPATH - make paths absolute.
[129]352# This implementation is clumsy and doesn't resolve '..' and '.' components.
[73]353#
[129]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))))
[130]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)
[129]363
[204]364
[129]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#
[69]378# This is how we find the closest config.kmk.
379# It's a little hacky but I think it works fine.
[70]380#
381_CFGDIR := .
[78]382_CFGFILES := ./Config.kmk ./config.kmk
[69]383define def_include_config
[78]384$(eval _CFGDIR := $(_CFGDIR)/$(dir))
385_CFGFILES += $(_CFGDIR)/Config.kmk $(_CFGDIR)/config.kmk
[69]386endef
387# walk down the _RELATIVE_ path specified by DEPTH.
[78]388$(foreach dir,$(subst /, ,$(DEPTH)), $(eval $(def_include_config)) )
[69]389# add the default config file.
[78]390_CFGFILE := $(firstword $(wildcard $(_CFGFILES) $(FILE_KBUILD_CONFIG)))
[69]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
[72]399__header_kmk__ := 1
[69]400endif # __header_kmk__
Note: See TracBrowser for help on using the repository browser.