source: trunk/kBuild/header.kmk@ 299

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

FreeBSD 5.x on amd64

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