1 | # $Id: header.kmk 306 2005-08-11 20:24:19Z 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 |
|
---|
27 | ifndef __header_kmk__
|
---|
28 | # start-of-file-content
|
---|
29 |
|
---|
30 | #
|
---|
31 | # default rule
|
---|
32 | #
|
---|
33 | all: all_recursive
|
---|
34 |
|
---|
35 | #
|
---|
36 | # Try avoid inference rules.
|
---|
37 | #
|
---|
38 | .SUFFIXES:
|
---|
39 | SUFFIXES :=
|
---|
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.
|
---|
49 | lastword = $(word $(words $(1)), $(1))
|
---|
50 |
|
---|
51 |
|
---|
52 | #
|
---|
53 | # Assert build type.
|
---|
54 | #
|
---|
55 | ifndef BUILD_TYPE
|
---|
56 | ifndef BUILD_MODE
|
---|
57 | $(error kBuild: You must define BUILD_TYPE!)
|
---|
58 | endif
|
---|
59 | BUILD_TYPE := $(BUILD_MODE)
|
---|
60 | endif
|
---|
61 | ifeq ($(BUILD_TYPE),DEBUG)
|
---|
62 | BUILD_TYPE := debug
|
---|
63 | endif
|
---|
64 | ifeq ($(BUILD_TYPE),RELEASE)
|
---|
65 | BUILD_TYPE := release
|
---|
66 | endif
|
---|
67 | ifeq ($(BUILD_TYPE),PROFILE)
|
---|
68 | BUILD_TYPE := profile
|
---|
69 | endif
|
---|
70 |
|
---|
71 |
|
---|
72 | #
|
---|
73 | # Assert build platform.
|
---|
74 | #
|
---|
75 | _BUILD_PLATFORM_OK := 0
|
---|
76 | # OS/2 (have uppercase legacy)
|
---|
77 | ifeq ($(BUILD_PLATFORM),OS2)
|
---|
78 | override BUILD_PLATFORM := os2
|
---|
79 | endif
|
---|
80 | ifeq ($(BUILD_PLATFORM),os2)
|
---|
81 | _BUILD_PLATFORM_OK := 1
|
---|
82 | endif
|
---|
83 |
|
---|
84 | # Linux
|
---|
85 | ifeq ($(BUILD_PLATFORM),LINUX)
|
---|
86 | $(error kBuild: BUILD_PLATFORM must be all lowercase!)
|
---|
87 | endif
|
---|
88 | ifeq ($(BUILD_PLATFORM),linux)
|
---|
89 | _BUILD_PLATFORM_OK := 1
|
---|
90 | endif
|
---|
91 |
|
---|
92 | # Win32
|
---|
93 | ifeq ($(BUILD_PLATFORM),WIN32)
|
---|
94 | $(error kBuild: BUILD_PLATFORM must be all lowercase!)
|
---|
95 | endif
|
---|
96 | ifeq ($(BUILD_PLATFORM),win32)
|
---|
97 | _BUILD_PLATFORM_OK := 1
|
---|
98 | endif
|
---|
99 |
|
---|
100 | # L4
|
---|
101 | ifeq ($(BUILD_PLATFORM),L4)
|
---|
102 | $(error kBuild: BUILD_PLATFORM must be all lowercase!)
|
---|
103 | endif
|
---|
104 | ifeq ($(BUILD_PLATFORM),l4)
|
---|
105 | _BUILD_PLATFORM_OK := 1
|
---|
106 | endif
|
---|
107 |
|
---|
108 | # FreeBSD
|
---|
109 | ifeq ($(BUILD_PLATFORM),FreeBSD)
|
---|
110 | $(error kBuild: BUILD_PLATFORM must be all lowercase!)
|
---|
111 | endif
|
---|
112 | ifeq ($(BUILD_PLATFORM),freebsd)
|
---|
113 | _BUILD_PLATFORM_OK := 1
|
---|
114 | endif
|
---|
115 |
|
---|
116 | ifeq ($(_BUILD_PLATFORM_OK),0)
|
---|
117 | $(error kBuild: BUILD_PLATFORM value '$(BUILD_PLATFORM)' was not recongized!)
|
---|
118 | endif
|
---|
119 | BUILD_PLATFORM_ARCH := x86
|
---|
120 | BUILD_PLATFORM_CPU := i586
|
---|
121 |
|
---|
122 |
|
---|
123 | #
|
---|
124 | # Assert target platform.
|
---|
125 | #
|
---|
126 | ifndef BUILD_TARGET
|
---|
127 | # not defined, set to the same as build platform
|
---|
128 | BUILD_TARGET := $(BUILD_PLATFORM)
|
---|
129 | else
|
---|
130 | _BUILD_TARGET_OK := 0
|
---|
131 | # OS/2
|
---|
132 | ifeq ($(BUILD_TARGET),OS2)
|
---|
133 | $(error kBuild: BUILD_TARGET must be all lowercase!)
|
---|
134 | endif
|
---|
135 | ifeq ($(BUILD_TARGET),os2)
|
---|
136 | _BUILD_TARGET_OK := 1
|
---|
137 | endif
|
---|
138 |
|
---|
139 | # Linux
|
---|
140 | ifeq ($(BUILD_TARGET),LINUX)
|
---|
141 | $(error kBuild: BUILD_TARGET must be all lowercase!)
|
---|
142 | endif
|
---|
143 | ifeq ($(BUILD_TARGET),linux)
|
---|
144 | _BUILD_TARGET_OK := 1
|
---|
145 | endif
|
---|
146 |
|
---|
147 | # Win32
|
---|
148 | ifeq ($(BUILD_TARGET),WIN32)
|
---|
149 | $(error kBuild: BUILD_TARGET must be all lowercase!)
|
---|
150 | endif
|
---|
151 | ifeq ($(BUILD_TARGET),win32)
|
---|
152 | _BUILD_TARGET_OK := 1
|
---|
153 | endif
|
---|
154 |
|
---|
155 | # L4
|
---|
156 | ifeq ($(BUILD_TARGET),L4)
|
---|
157 | $(error kBuild: BUILD_TARGET must be all lowercase!)
|
---|
158 | endif
|
---|
159 | ifeq ($(BUILD_TARGET),l4)
|
---|
160 | _BUILD_TARGET_OK := 1
|
---|
161 | endif
|
---|
162 |
|
---|
163 | # FreeBSD
|
---|
164 | ifeq ($(BUILD_TARGET),FreeBSD)
|
---|
165 | $(error kBuild: BUILD_TARGET must be all lowercase!)
|
---|
166 | endif
|
---|
167 | ifeq ($(BUILD_TARGET),freebsd)
|
---|
168 | _BUILD_TARGET_OK := 1
|
---|
169 | endif
|
---|
170 |
|
---|
171 | ifeq ($(_BUILD_TARGET_OK),0)
|
---|
172 | $(error kBuild: BUILD_TARGET value '$(BUILD_TARGET)' was not recongized!)
|
---|
173 | endif
|
---|
174 | endif
|
---|
175 | BUILD_TARGET_ARCH := x86
|
---|
176 | BUILD_TARGET_CPU := i586
|
---|
177 |
|
---|
178 | # Adjust the DEPTH definition first
|
---|
179 | ifeq ($(strip $(DEPTH)),)
|
---|
180 | DEPTH := .
|
---|
181 | endif
|
---|
182 |
|
---|
183 | #
|
---|
184 | # Common definitions.
|
---|
185 | #
|
---|
186 | ifeq ($(filter abspath,$(KMK_FEATURES)),abspath)
|
---|
187 | PATH_CURRENT := $(abspath $(CURDIR))
|
---|
188 | PATH_ROOT := $(abspath $(PATH_CURRENT)/$(DEPTH))
|
---|
189 |
|
---|
190 | else
|
---|
191 |
|
---|
192 | PATH_CURRENT := $(CURDIR)
|
---|
193 | # Get the real root path.
|
---|
194 | PATH_ROOT := $(PATH_CURRENT)
|
---|
195 | ifneq ($(DEPTH),.)
|
---|
196 | $(foreach d,$(subst /, ,$(DEPTH)), $(eval PATH_ROOT := $(patsubst %/,%,$(dir $(PATH_ROOT)))) )
|
---|
197 | endif
|
---|
198 |
|
---|
199 | endif
|
---|
200 | # Subdirectory relative to the root.
|
---|
201 | ifneq ($(PATH_ROOT),$(PATH_CURRENT))
|
---|
202 | CURSUBDIR := $(patsubst $(PATH_ROOT)/%,%,$(PATH_CURRENT))
|
---|
203 | else
|
---|
204 | CURSUBDIR := .
|
---|
205 | endif
|
---|
206 |
|
---|
207 | # Output directories.
|
---|
208 | ifndef PATH_OUT_BASE
|
---|
209 | PATH_OUT_BASE := $(PATH_ROOT)/out
|
---|
210 | endif
|
---|
211 | ifndef PATH_OUT
|
---|
212 | ifdef BUILD_TARGET_SUB # (BUILD_TARGET_SUB is not currently recognized by kBuild in any other places.)
|
---|
213 | PATH_OUT := $(PATH_OUT_BASE)/$(BUILD_TARGET)/$(BUILD_TARGET_SUB)/$(BUILD_TYPE)
|
---|
214 | else
|
---|
215 | PATH_OUT := $(PATH_OUT_BASE)/$(BUILD_TARGET)/$(BUILD_TYPE)
|
---|
216 | endif
|
---|
217 | endif
|
---|
218 | PATH_OBJ := $(PATH_OUT)/obj
|
---|
219 | PATH_TARGET := $(PATH_OBJ)/$(CURSUBDIR)
|
---|
220 | ifndef KBUILD_NEW_STUFF
|
---|
221 | PATH_BIN := $(PATH_OUT)/bin
|
---|
222 | PATH_LIB := $(PATH_OUT)/lib
|
---|
223 | PATH_DOC := $(PATH_ROOT)/out/doc
|
---|
224 | else
|
---|
225 | PATH_INS := $(PATH_OUT)
|
---|
226 | PATH_BIN := $(PATH_INS)/bin
|
---|
227 | PATH_DLL := $(PATH_INS)/bin
|
---|
228 | PATH_LIB := $(PATH_INS)/lib
|
---|
229 | PATH_DOC := $(PATH_INS)/doc
|
---|
230 | endif
|
---|
231 |
|
---|
232 | # Usually kBuild is external to the source tree.
|
---|
233 | ifndef PATH_KBUILD
|
---|
234 | PATH_KBUILD := $(PATH_ROOT)/kBuild
|
---|
235 | endif
|
---|
236 | ifeq ($(filter abspath,$(KMK_FEATURES)),abspath)
|
---|
237 | PATH_KBUILD := $(abspath $(PATH_KBUILD))
|
---|
238 | endif
|
---|
239 | # kBuild tools
|
---|
240 | PATH_TOOLS_W32 := $(PATH_KBUILD)/bin/x86.win32
|
---|
241 | PATH_TOOLS_LNX := $(PATH_KBUILD)/bin/x86.linux
|
---|
242 | PATH_TOOLS_OS2 := $(PATH_KBUILD)/bin/x86.os2
|
---|
243 | PATH_TOOLS_FREEBSD := $(PATH_KBUILD)/bin/amd64.freebsd
|
---|
244 | # kBuild files which might be of interest.
|
---|
245 | FILE_KBUILD_HEADER := $(PATH_KBUILD)/header.kmk
|
---|
246 | FILE_KBUILD_CONFIG := $(PATH_KBUILD)/config.kmk
|
---|
247 | FILE_KBUILD_FOOTER := $(PATH_KBUILD)/footer.kmk
|
---|
248 |
|
---|
249 | SUFF_DEP := .dep
|
---|
250 | MAKEFILE := $(firstword $(MAKEFILE_LIST))
|
---|
251 |
|
---|
252 |
|
---|
253 | #
|
---|
254 | # Get rid of the GNU Make default stuff
|
---|
255 | #
|
---|
256 | ifndef KMK_VERSION
|
---|
257 | include $(PATH_KBUILD)/StampOutPredefines.kmk
|
---|
258 | endif
|
---|
259 |
|
---|
260 | #
|
---|
261 | # Build platform setup.
|
---|
262 | #
|
---|
263 | # OS/2
|
---|
264 | ifeq ($(BUILD_PLATFORM),os2)
|
---|
265 | PATH_TOOLS := $(PATH_TOOLS_OS2)
|
---|
266 | EXEC_X86_WIN32 := innopec.exe
|
---|
267 | HOSTSUFF_EXE := .exe
|
---|
268 | endif
|
---|
269 |
|
---|
270 | # Linux
|
---|
271 | ifeq ($(BUILD_PLATFORM),linux)
|
---|
272 | PATH_TOOLS := $(PATH_TOOLS_LNX)
|
---|
273 | EXEC_X86_WIN32 := wine
|
---|
274 | HOSTSUFF_EXE :=
|
---|
275 | endif
|
---|
276 |
|
---|
277 | # Win32
|
---|
278 | ifeq ($(BUILD_PLATFORM),win32)
|
---|
279 | PATH_TOOLS := $(PATH_TOOLS_W32)
|
---|
280 | EXEC_X86_WIN32 :=
|
---|
281 | HOSTSUFF_EXE := .exe
|
---|
282 | endif
|
---|
283 |
|
---|
284 | # FreeBSD
|
---|
285 | ifeq ($(BUILD_PLATFORM),freebsd)
|
---|
286 | PATH_TOOLS := $(PATH_TOOLS_FREEBSD)
|
---|
287 | EXEC_X86_WIN32 := wine
|
---|
288 | HOSTSUFF_EXE :=
|
---|
289 | endif
|
---|
290 |
|
---|
291 |
|
---|
292 | #
|
---|
293 | # Build target setup.
|
---|
294 | #
|
---|
295 | ifeq ($(BUILD_TARGET),os2)
|
---|
296 | SUFF_OBJ := .obj
|
---|
297 | SUFF_LIB := .lib
|
---|
298 | SUFF_DLL := .dll
|
---|
299 | SUFF_EXE := .exe
|
---|
300 | SUFF_SYS := .sys
|
---|
301 | SUFF_RES := .res
|
---|
302 | endif
|
---|
303 | ifeq ($(BUILD_TARGET),win32)
|
---|
304 | SUFF_OBJ := .obj
|
---|
305 | SUFF_LIB := .lib
|
---|
306 | SUFF_DLL := .dll
|
---|
307 | SUFF_EXE := .exe
|
---|
308 | SUFF_SYS := .sys
|
---|
309 | SUFF_RES := .res
|
---|
310 | endif
|
---|
311 | ifeq ($(BUILD_TARGET),linux)
|
---|
312 | SUFF_OBJ := .o
|
---|
313 | SUFF_LIB := .a
|
---|
314 | SUFF_DLL := .so
|
---|
315 | SUFF_EXE :=
|
---|
316 | SUFF_SYS := .a
|
---|
317 | SUFF_RES :=
|
---|
318 | endif
|
---|
319 | ifeq ($(BUILD_TARGET),l4)
|
---|
320 | SUFF_OBJ := .o
|
---|
321 | SUFF_LIB := .a
|
---|
322 | SUFF_DLL := .s.so
|
---|
323 | SUFF_EXE :=
|
---|
324 | SUFF_SYS := .a
|
---|
325 | SUFF_RES :=
|
---|
326 | endif
|
---|
327 |
|
---|
328 | #
|
---|
329 | # Standard kBuild tools.
|
---|
330 | #
|
---|
331 | DEP := $(PATH_TOOLS)/kDep$(HOSTSUFF_EXE)
|
---|
332 | DEP_PRE := $(PATH_TOOLS)/kDepPre$(HOSTSUFF_EXE)
|
---|
333 | ifeq ($(MAKE),kmk)
|
---|
334 | MAKE := $(PATH_TOOLS)/kmk$(HOSTSUFF_EXE)
|
---|
335 | endif
|
---|
336 |
|
---|
337 | # Standard Unix shell utils.
|
---|
338 | ifdef KMK_BUILTIN
|
---|
339 | ECHO := kmk_builtin_echo
|
---|
340 | MKDIR := kmk_builtin_mkdir
|
---|
341 | RM := kmk_builtin_rm
|
---|
342 | CP := kmk_builtin_cp
|
---|
343 | else
|
---|
344 | ECHO := echo
|
---|
345 | MKDIR := $(PATH_TOOLS)/mkdir$(HOSTSUFF_EXE)
|
---|
346 | RM := $(PATH_TOOLS)/rm$(HOSTSUFF_EXE)
|
---|
347 | CP := $(PATH_TOOLS)/cp$(HOSTSUFF_EXE)
|
---|
348 | endif
|
---|
349 | CP_EXT := $(PATH_TOOLS)/cp$(HOSTSUFF_EXE)
|
---|
350 | MV := $(PATH_TOOLS)/mv$(HOSTSUFF_EXE)
|
---|
351 | SED := $(PATH_TOOLS)/sed$(HOSTSUFF_EXE)
|
---|
352 | CAT := $(PATH_TOOLS)/cat$(HOSTSUFF_EXE)
|
---|
353 | # Bourn shell clone.
|
---|
354 | MAKESHELL := $(PATH_TOOLS)/ash$(HOSTSUFF_EXE)
|
---|
355 | SHELL := $(MAKESHELL)
|
---|
356 | export SHELL MAKESHELL
|
---|
357 |
|
---|
358 |
|
---|
359 | #
|
---|
360 | # Message macros.
|
---|
361 | #
|
---|
362 |
|
---|
363 | ifndef BUILD_QUIET
|
---|
364 | ifdef BUILD_DEBUG
|
---|
365 | BUILD_VERBOSE := 9
|
---|
366 | endif
|
---|
367 | MSG_L1 = @$(ECHO) "kBuild: $1"
|
---|
368 | ifdef BUILD_VERBOSE
|
---|
369 | MSG_L2 = @$(ECHO) "kBuild: $1"
|
---|
370 | QUIET :=
|
---|
371 | else
|
---|
372 | QUIET := @
|
---|
373 | MSG_L2 =
|
---|
374 | endif
|
---|
375 | ifdef BUILD_DEBUG
|
---|
376 | MSG_L3 = @$(ECHO) "kBuild: $1"
|
---|
377 | else
|
---|
378 | MSG_L3 =
|
---|
379 | endif
|
---|
380 | else
|
---|
381 | QUIET :=
|
---|
382 | MSG_L1 =
|
---|
383 | MSG_L2 =
|
---|
384 | MSG_L3 =
|
---|
385 | endif
|
---|
386 |
|
---|
387 | ## ABSPATH - make paths absolute.
|
---|
388 | # This implementation is clumsy and doesn't resolve '..' and '.' components.
|
---|
389 | #
|
---|
390 | # @param $1 The paths to make absolute.
|
---|
391 | ifeq ($(filter abspath,$(KMK_FEATURES)),abspath)
|
---|
392 | ABSPATH = $(abspath $(1))
|
---|
393 | else
|
---|
394 | ABSPATH = $(foreach path,$(1)\
|
---|
395 | ,$(strip $(if $(subst <,,$(firstword $(subst /, ,<$(path)))),\
|
---|
396 | $(if $(patsubst %:,,$(firstword $(subst :,: ,$(path)))),$(PATH_CURRENT)/$(path),$(path)),\
|
---|
397 | $(path))))
|
---|
398 | endif
|
---|
399 |
|
---|
400 | ## DIRDEP - make create directory dependencies.
|
---|
401 | #
|
---|
402 | # @param $1 The paths to the directories which must be created.
|
---|
403 | DIRDEP = $(foreach path,$(1),$(path)/.dir_created)
|
---|
404 |
|
---|
405 |
|
---|
406 | ## Cygwin kludge.
|
---|
407 | # This converts /cygdrive/x/% to x:%.
|
---|
408 | #
|
---|
409 | # @param $1 The paths to make native.
|
---|
410 | # @remark This macro is pretty much obsolete since we don't use cygwin base make.
|
---|
411 | ifneq ($(patsubst /cygdrive/%,%,$(CURDIR)),$(CURDIR))
|
---|
412 | CYGPATHMIXED = $(foreach path,$(1)\
|
---|
413 | ,$(if $(patsubst /cygdrive/%,,$(path)),$(path),$(patsubst $(strip $(firstword $(subst /, ,$(patsubst /cygdrive/%,%,$(path)))))/%,$(strip $(firstword $(subst /, ,$(patsubst /cygdrive/%,%,$(path))))):/%,$(patsubst /cygdrive/%,%,$(path)))))
|
---|
414 | else
|
---|
415 | CYGPATHMIXED = $(1)
|
---|
416 | endif
|
---|
417 |
|
---|
418 | #
|
---|
419 | # This is how we find the closest config.kmk.
|
---|
420 | # It's a little hacky but I think it works fine.
|
---|
421 | #
|
---|
422 | _CFGDIR := .
|
---|
423 | _CFGFILES := ./Config.kmk ./config.kmk
|
---|
424 | define def_include_config
|
---|
425 | $(eval _CFGDIR := $(_CFGDIR)/$(dir))
|
---|
426 | _CFGFILES += $(_CFGDIR)/Config.kmk $(_CFGDIR)/config.kmk
|
---|
427 | endef
|
---|
428 | # walk down the _RELATIVE_ path specified by DEPTH.
|
---|
429 | $(foreach dir,$(subst /, ,$(DEPTH)), $(eval $(def_include_config)) )
|
---|
430 | # add the default config file.
|
---|
431 | _CFGFILE := $(firstword $(wildcard $(_CFGFILES) $(FILE_KBUILD_CONFIG)))
|
---|
432 | _CFGFILES :=
|
---|
433 | _CFGDIR :=
|
---|
434 |
|
---|
435 | # Include the config.kmk we found file (or the default one).
|
---|
436 | include $(_CFGFILE)
|
---|
437 |
|
---|
438 |
|
---|
439 | # end-of-file-content
|
---|
440 | __header_kmk__ := 1
|
---|
441 | endif # __header_kmk__
|
---|