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