source: trunk/kBuild/header.kmk@ 274

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

doing install stuff. (not quite done yet)

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