1 | # $Id: header.kmk 854 2007-02-11 04:19:04Z bird $
|
---|
2 | ## @file
|
---|
3 | #
|
---|
4 | # kBuild - File included at top of makefile.
|
---|
5 | #
|
---|
6 | # Copyright (c) 2004-2007 knut st. osmundsen <bird-kBuild-spam@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 | # The FORCE rule.
|
---|
37 | #
|
---|
38 | FORCE:
|
---|
39 |
|
---|
40 | #
|
---|
41 | # Try avoid inference rules.
|
---|
42 | #
|
---|
43 | .SUFFIXES:
|
---|
44 | SUFFIXES :=
|
---|
45 |
|
---|
46 |
|
---|
47 | #
|
---|
48 | # General purpose macros.
|
---|
49 | #
|
---|
50 |
|
---|
51 | ## get last word in a list.
|
---|
52 | # @returns last word in $1.
|
---|
53 | # @param $1 Word list.
|
---|
54 | lastword = $(word $(words $(1)), $(1))
|
---|
55 |
|
---|
56 | ##
|
---|
57 | # Newline character(s).
|
---|
58 | define NL
|
---|
59 |
|
---|
60 |
|
---|
61 | endef
|
---|
62 |
|
---|
63 | ##
|
---|
64 | # Tab character.
|
---|
65 | TAB := $(subst ., ,.)
|
---|
66 |
|
---|
67 | ##
|
---|
68 | # Space character.
|
---|
69 | SP := $(subst ., ,.)
|
---|
70 |
|
---|
71 | ##
|
---|
72 | # Checks if two strings are equal.
|
---|
73 | # @returns blank if equal
|
---|
74 | # @returns non-blank if not equal.
|
---|
75 | # @param $1 String 1.
|
---|
76 | # @param $2 String 2
|
---|
77 | STRCMP = $( todo )
|
---|
78 |
|
---|
79 | #
|
---|
80 | # Set default build type.
|
---|
81 | #
|
---|
82 | ifndef BUILD_TYPE
|
---|
83 | ifdef BUILD_MODE
|
---|
84 | # BUILD_MODE is legacy from the OS/2 build system. :)
|
---|
85 | BUILD_TYPE := $(tolower $(BUILD_MODE))
|
---|
86 | else
|
---|
87 | BUILD_TYPE := release
|
---|
88 | endif
|
---|
89 | endif
|
---|
90 |
|
---|
91 |
|
---|
92 | #
|
---|
93 | # Assert build platform.
|
---|
94 | #
|
---|
95 | ifndef BUILD_PLATFORM
|
---|
96 | $(error kBuild: BUILD_PLATFORM is undefined!)
|
---|
97 | else
|
---|
98 | BUILD_PLATFORM := $(strip $(BUILD_PLATFORM))
|
---|
99 | ifneq ($(words $(BUILD_PLATFORM))$(filter-out darwin freebsd l4 linux nt os2 solaris win win32 win64,$(BUILD_PLATFORM)),1)
|
---|
100 | # OS/2 (have uppercase legacy)
|
---|
101 | ifeq ($(BUILD_PLATFORM),OS2)
|
---|
102 | $(error kBuild: BUILD_PLATFORM must be all lowercase!)
|
---|
103 | endif
|
---|
104 | $(error kBuild: BUILD_PLATFORM value '$(BUILD_PLATFORM)' was not recognized!)
|
---|
105 | endif
|
---|
106 | endif
|
---|
107 |
|
---|
108 | # Fill in defaults if needed.
|
---|
109 | ifndef BUILD_PLATFORM_ARCH
|
---|
110 | ifeq ($(filter-out win64,$(BUILD_PLATFORM)),)
|
---|
111 | BUILD_PLATFORM_ARCH := amd64
|
---|
112 | else
|
---|
113 | BUILD_PLATFORM_ARCH := x86
|
---|
114 | endif
|
---|
115 | endif
|
---|
116 | ifndef BUILD_PLATFORM_CPU
|
---|
117 | ifeq ($(filter-out amd64,$(BUILD_PLATFORM_ARCH)),)
|
---|
118 | BUILD_PLATFORM_CPU:= k8
|
---|
119 | else
|
---|
120 | BUILD_PLATFORM_CPU:= i586
|
---|
121 | endif
|
---|
122 | endif
|
---|
123 |
|
---|
124 |
|
---|
125 | #
|
---|
126 | # Assert target platform.
|
---|
127 | #
|
---|
128 | ifndef BUILD_TARGET
|
---|
129 | # not defined, set to the same as build platform
|
---|
130 | BUILD_TARGET := $(BUILD_PLATFORM)
|
---|
131 | else
|
---|
132 | BUILD_TARGET := $(strip $(BUILD_TARGET))
|
---|
133 | ifneq ($(words $(BUILD_TARGET))$(filter-out darwin freebsd l4 linux nt os2 solaris win win32 win64,$(BUILD_TARGET)),1)
|
---|
134 | # OS/2 (have uppercase legacy)
|
---|
135 | ifeq ($(BUILD_TARGET),OS2)
|
---|
136 | $(error kBuild: BUILD_TARGET must be all lowercase!)
|
---|
137 | endif
|
---|
138 | $(error kBuild: BUILD_TARGET value '$(BUILD_TARGET)' was not recognized!)
|
---|
139 | endif
|
---|
140 | endif
|
---|
141 |
|
---|
142 | # Fill in defaults if needed.
|
---|
143 | ifndef BUILD_TARGET_ARCH
|
---|
144 | BUILD_TARGET_ARCH := x86
|
---|
145 | endif
|
---|
146 | ifndef BUILD_TARGET_CPU
|
---|
147 | BUILD_TARGET_CPU := i586
|
---|
148 | endif
|
---|
149 |
|
---|
150 | # Adjust the DEPTH definition first
|
---|
151 | ifeq ($(strip $(DEPTH)),)
|
---|
152 | DEPTH := .
|
---|
153 | endif
|
---|
154 |
|
---|
155 | #
|
---|
156 | # Common definitions.
|
---|
157 | #
|
---|
158 | ## PATH_CURRENT is the current directory (getcwd).
|
---|
159 | PATH_CURRENT := $(abspath $(CURDIR))
|
---|
160 | ## PATH_SUB_CURRENT points to current directory of the current makefile.
|
---|
161 | # Meaning that it will change value as we enter and exit sub-makefiles.
|
---|
162 | PATH_SUB_CURRENT := $(PATH_CURRENT)
|
---|
163 | ## PATH_ROOT points to the project root directory.
|
---|
164 | PATH_ROOT := $(abspath $(PATH_CURRENT)/$(DEPTH))
|
---|
165 | ## PATH_SUB_ROOT points to the directory of the top-level makefile.
|
---|
166 | ifneq ($(strip $(SUB_DEPTH)),)
|
---|
167 | PATH_SUB_ROOT := $(abspath $(PATH_CURRENT)/$(SUB_DEPTH))
|
---|
168 | else
|
---|
169 | PATH_SUB_ROOT := $(PATH_CURRENT)
|
---|
170 | endif
|
---|
171 |
|
---|
172 | ## CURSUBDIR is PATH_SUB_ROOT described relative to PATH_ROOT.
|
---|
173 | # This variable is used to determin where the object files and other output goes.
|
---|
174 | ifneq ($(PATH_ROOT),$(PATH_CURRENT))
|
---|
175 | CURSUBDIR := $(patsubst $(PATH_ROOT)/%,%,$(PATH_SUB_ROOT))
|
---|
176 | else
|
---|
177 | CURSUBDIR := .
|
---|
178 | endif
|
---|
179 |
|
---|
180 | # Output directories.
|
---|
181 | ifndef PATH_OUT_BASE
|
---|
182 | PATH_OUT_BASE := $(PATH_ROOT)/out
|
---|
183 | endif
|
---|
184 | ifndef PATH_OUT
|
---|
185 | ifdef BUILD_TARGET_SUB # (BUILD_TARGET_SUB is not currently recognized by kBuild in any other places.)
|
---|
186 | PATH_OUT := $(PATH_OUT_BASE)/$(BUILD_TARGET).$(BUILD_TARGET_ARCH).$(BUILD_TARGET_SUB)/$(BUILD_TYPE)
|
---|
187 | else
|
---|
188 | PATH_OUT := $(PATH_OUT_BASE)/$(BUILD_TARGET).$(BUILD_TARGET_ARCH)/$(BUILD_TYPE)
|
---|
189 | endif
|
---|
190 | endif # !define PATH_OUT
|
---|
191 | PATH_OBJ = $(PATH_OUT)/obj
|
---|
192 | PATH_TARGET = $(PATH_OBJ)/$(CURSUBDIR)
|
---|
193 | PATH_INS = $(PATH_OUT)
|
---|
194 | PATH_BIN = $(PATH_INS)/bin
|
---|
195 | PATH_DLL = $(PATH_INS)/bin
|
---|
196 | PATH_SYS = $(PATH_INS)/bin
|
---|
197 | PATH_LIB = $(PATH_INS)/lib
|
---|
198 | PATH_DOC = $(PATH_INS)/doc
|
---|
199 |
|
---|
200 | # Usually kBuild is external to the source tree.
|
---|
201 | ifndef PATH_KBUILD
|
---|
202 | PATH_KBUILD := $(PATH_ROOT)/kBuild
|
---|
203 | endif
|
---|
204 | PATH_KBUILD := $(abspath $(PATH_KBUILD))
|
---|
205 | # kBuild files which might be of interest.
|
---|
206 | FILE_KBUILD_HEADER := $(PATH_KBUILD)/header.kmk
|
---|
207 | #FILE_KBUILD_CONFIG := $(PATH_KBUILD)/config.kmk
|
---|
208 | FILE_KBUILD_FOOTER := $(PATH_KBUILD)/footer.kmk
|
---|
209 |
|
---|
210 | SUFF_DEP := .dep
|
---|
211 | ## MAKEFILE is the name of the main makefile.
|
---|
212 | MAKEFILE := $(firstword $(MAKEFILE_LIST))
|
---|
213 | ## MAKEFILE_CURRENT is the name of the current makefile.
|
---|
214 | # This is updated everything a sub-makefile is included.
|
---|
215 | MAKEFILE_CURRENT := $(MAKEFILE)
|
---|
216 |
|
---|
217 |
|
---|
218 | #
|
---|
219 | # Check make version.
|
---|
220 | #
|
---|
221 | ifdef KMK_VERSION
|
---|
222 | ifneq ($(KBUILD_VERSION_MAJOR).$(KBUILD_VERSION_MINOR),0.1)
|
---|
223 | ifneq ($(KBUILD_VERSION_MAJOR),0)
|
---|
224 | $(warning kBuild: kmk major version mismatch, expected '0' found '$(KBUILD_VERSION_MAJOR)'!)
|
---|
225 | else
|
---|
226 | $(warning kBuild: kmk minor version mismatch, expected '1' found '$(KBUILD_VERSION_MINOR)'!)
|
---|
227 | endif
|
---|
228 | endif
|
---|
229 | endif
|
---|
230 |
|
---|
231 |
|
---|
232 | #
|
---|
233 | # The revision in which this file was last modified.
|
---|
234 | # This can be useful when using development versions of kBuild.
|
---|
235 | #
|
---|
236 | KMK_REVISION := $(patsubst %:,, $Rev: 854 $ )
|
---|
237 |
|
---|
238 |
|
---|
239 | #
|
---|
240 | # Build platform setup.
|
---|
241 | #
|
---|
242 | # OS/2
|
---|
243 | ifeq ($(BUILD_PLATFORM),os2)
|
---|
244 | EXEC_X86_WIN32 := innopec.exe
|
---|
245 | HOSTSUFF_EXE := .exe
|
---|
246 | endif
|
---|
247 |
|
---|
248 | # Linux
|
---|
249 | ifeq ($(BUILD_PLATFORM),linux)
|
---|
250 | EXEC_X86_WIN32 := wine
|
---|
251 | HOSTSUFF_EXE :=
|
---|
252 | endif
|
---|
253 |
|
---|
254 | # Win, Win32, Win64, NT.
|
---|
255 | ifeq ($(filter-out win32 win64 win nt,$(BUILD_PLATFORM)),)
|
---|
256 | EXEC_X86_WIN32 :=
|
---|
257 | HOSTSUFF_EXE := .exe
|
---|
258 | endif
|
---|
259 |
|
---|
260 | # FreeBSD
|
---|
261 | ifeq ($(BUILD_PLATFORM),freebsd)
|
---|
262 | EXEC_X86_WIN32 := wine
|
---|
263 | HOSTSUFF_EXE :=
|
---|
264 | endif
|
---|
265 |
|
---|
266 | # Darwin / Mac OS X
|
---|
267 | ifeq ($(BUILD_PLATFORM),darwin)
|
---|
268 | EXEC_X86_WIN32 := false
|
---|
269 | HOSTSUFF_EXE :=
|
---|
270 | endif
|
---|
271 |
|
---|
272 | # Solaris
|
---|
273 | ifeq ($(BUILD_PLATFORM),solaris)
|
---|
274 | EXEC_X86_WIN32 := false
|
---|
275 | HOSTSUFF_EXE :=
|
---|
276 | endif
|
---|
277 |
|
---|
278 | ifndef PATH_KBUILD_BIN
|
---|
279 | PATH_KBUILD_BIN := $(PATH_KBUILD)/bin/$(BUILD_PLATFORM).$(BUILD_PLATFORM_ARCH)
|
---|
280 | ifeq ($(wildcard $(PATH_KBUILD_BIN)/kmk_ash$(HOSTSUFF_EXE)),)
|
---|
281 | ifeq ($(BUILD_TARGET_ARCH),amd64)
|
---|
282 | PATH_KBUILD_BIN := $(PATH_KBUILD)/bin/$(BUILD_PLATFORM).x86
|
---|
283 | endif
|
---|
284 | ifeq ($(wildcard $(PATH_KBUILD_BIN)/kmk_ash$(HOSTSUFF_EXE)),)
|
---|
285 | ifeq ($(filter-out win64 win32 win nt ,$(BUILD_PLATFORM)),)
|
---|
286 | PATH_KBUILD_BIN := $(PATH_KBUILD)/bin/win.x86
|
---|
287 | endif
|
---|
288 | endif
|
---|
289 | ifeq ($(wildcard $(PATH_KBUILD_BIN)/kmk_ash$(HOSTSUFF_EXE)),)
|
---|
290 | # give up
|
---|
291 | PATH_KBUILD_BIN := $(PATH_KBUILD)/bin/$(BUILD_PLATFORM).$(BUILD_PLATFORM_ARCH)
|
---|
292 | endif
|
---|
293 | endif
|
---|
294 | endif
|
---|
295 |
|
---|
296 |
|
---|
297 | #
|
---|
298 | # Build target setup.
|
---|
299 | #
|
---|
300 | ifeq ($(filter-out win32 win64 win nt os2,$(BUILD_TARGET)),)
|
---|
301 | SUFF_OBJ := .obj
|
---|
302 | SUFF_LIB := .lib
|
---|
303 | SUFF_DLL := .dll
|
---|
304 | SUFF_EXE := .exe
|
---|
305 | SUFF_SYS := .sys
|
---|
306 | SUFF_RES := .res
|
---|
307 | endif
|
---|
308 | ifeq ($(BUILD_TARGET),l4)
|
---|
309 | SUFF_OBJ := .o
|
---|
310 | SUFF_LIB := .a
|
---|
311 | SUFF_DLL := .s.so
|
---|
312 | SUFF_EXE :=
|
---|
313 | SUFF_SYS := .a
|
---|
314 | SUFF_RES :=
|
---|
315 | endif
|
---|
316 | ifeq ($(BUILD_TARGET),darwin)
|
---|
317 | SUFF_OBJ := .o
|
---|
318 | SUFF_LIB := .a
|
---|
319 | SUFF_DLL := .dylib
|
---|
320 | SUFF_EXE :=
|
---|
321 | SUFF_SYS :=
|
---|
322 | SUFF_RES :=
|
---|
323 | endif
|
---|
324 | ifndef SUFF_OBJ
|
---|
325 | SUFF_OBJ := .o
|
---|
326 | SUFF_LIB := .a
|
---|
327 | SUFF_DLL := .so
|
---|
328 | SUFF_EXE :=
|
---|
329 | SUFF_SYS := .a
|
---|
330 | SUFF_RES :=
|
---|
331 | endif
|
---|
332 |
|
---|
333 | #
|
---|
334 | # Standard kBuild tools.
|
---|
335 | #
|
---|
336 | ifeq ($(MAKE),kmk)
|
---|
337 | MAKE := $(PATH_KBUILD_BIN)/kmk$(HOSTSUFF_EXE)
|
---|
338 | endif
|
---|
339 |
|
---|
340 | DEP_EXT := $(PATH_KBUILD_BIN)/kDep$(HOSTSUFF_EXE)
|
---|
341 | ifeq ($(filter kDep,$(KMK_BUILTIN)),kDep)
|
---|
342 | DEP := kmk_builtin_kDep
|
---|
343 | else
|
---|
344 | DEP := $(DEP_EXT)
|
---|
345 | endif
|
---|
346 |
|
---|
347 | DEP_IDB_EXT := $(PATH_KBUILD_BIN)/kDepIDB$(HOSTSUFF_EXE)
|
---|
348 | ifeq ($(filter kDepPre,$(KMK_BUILTIN)),kDepIDB)
|
---|
349 | DEP_IDB := $(if kmk_builtin_kDepIDB
|
---|
350 | else
|
---|
351 | DEP_IDB := $(DEP_IDB_EXT)
|
---|
352 | endif
|
---|
353 |
|
---|
354 | DEP_PRE_EXT := $(PATH_KBUILD_BIN)/kDepPre$(HOSTSUFF_EXE)
|
---|
355 | ifeq ($(filter kDepPre,$(KMK_BUILTIN)),kDepPre)
|
---|
356 | DEP_PRE := $(if kmk_builtin_kDepPre
|
---|
357 | else
|
---|
358 | DEP_PRE := $(DEP_PRE_EXT)
|
---|
359 | endif
|
---|
360 |
|
---|
361 | APPEND_EXT := $(PATH_KBUILD_BIN)/kmk_append$(HOSTSUFF_EXE)
|
---|
362 | ifeq ($(filter append,$(KMK_BUILTIN)),append)
|
---|
363 | APPEND := kmk_builtin_append
|
---|
364 | else
|
---|
365 | APPEND := $(APPEND_EXT)
|
---|
366 | endif
|
---|
367 |
|
---|
368 | CAT_EXT := $(PATH_KBUILD_BIN)/kmk_cat$(HOSTSUFF_EXE)
|
---|
369 | ifeq ($(filter cat,$(KMK_BUILTIN)),cat)
|
---|
370 | CAT := kmk_builtin_cat
|
---|
371 | else
|
---|
372 | CAT := $(CAT_EXT)
|
---|
373 | endif
|
---|
374 |
|
---|
375 | CP_EXT := $(PATH_KBUILD_BIN)/kmk_cp$(HOSTSUFF_EXE)
|
---|
376 | ifeq ($(filter cp,$(KMK_BUILTIN)),cp)
|
---|
377 | CP := kmk_builtin_cp
|
---|
378 | else
|
---|
379 | CP := $(CP_EXT)
|
---|
380 | endif
|
---|
381 |
|
---|
382 | ECHO_EXT := $(PATH_KBUILD_BIN)/kmk_echo$(HOSTSUFF_EXE)
|
---|
383 | ifeq ($(filter echo,$(KMK_BUILTIN)),echo)
|
---|
384 | ECHO := kmk_builtin_echo
|
---|
385 | else
|
---|
386 | ECHO := $(ECHO_EXT)
|
---|
387 | endif
|
---|
388 |
|
---|
389 | INSTALL_EXT := $(PATH_KBUILD_BIN)/kmk_install$(HOSTSUFF_EXE)
|
---|
390 | ifeq ($(filter install,$(KMK_BUILTIN)),install)
|
---|
391 | INSTALL := kmk_builtin_install
|
---|
392 | else
|
---|
393 | INSTALL := $(INSTALL_EXT)
|
---|
394 | endif
|
---|
395 |
|
---|
396 | LN_EXT := $(PATH_KBUILD_BIN)/kmk_ln$(HOSTSUFF_EXE)
|
---|
397 | ifeq ($(filter ln,$(KMK_BUILTIN)),ln)
|
---|
398 | LN := kmk_builtin_ln
|
---|
399 | else
|
---|
400 | LN := $(LN_EXT)
|
---|
401 | endif
|
---|
402 |
|
---|
403 | MKDIR_EXT := $(PATH_KBUILD_BIN)/kmk_mkdir$(HOSTSUFF_EXE)
|
---|
404 | ifeq ($(filter mkdir,$(KMK_BUILTIN)),mkdir)
|
---|
405 | MKDIR := kmk_builtin_mkdir
|
---|
406 | else
|
---|
407 | MKDIR := $(MKDIR_EXT)
|
---|
408 | endif
|
---|
409 |
|
---|
410 | MV_EXT := $(PATH_KBUILD_BIN)/kmk_mv$(HOSTSUFF_EXE)
|
---|
411 | ifeq ($(filter mv,$(KMK_BUILTIN)),mv)
|
---|
412 | MV := kmk_builtin_mv
|
---|
413 | else
|
---|
414 | MV := $(MV_EXT)
|
---|
415 | endif
|
---|
416 |
|
---|
417 | PRINTF_EXT := $(PATH_KBUILD_BIN)/kmk_printf$(HOSTSUFF_EXE)
|
---|
418 | ifeq ($(filter printf,$(KMK_BUILTIN)),printf)
|
---|
419 | PRINTF := kmk_builtin_printf
|
---|
420 | else
|
---|
421 | PRINTF := $(PRINTF_EXT)
|
---|
422 | endif
|
---|
423 |
|
---|
424 | RM_EXT := $(PATH_KBUILD_BIN)/kmk_rm$(HOSTSUFF_EXE)
|
---|
425 | ifeq ($(filter rm,$(KMK_BUILTIN)),rm)
|
---|
426 | RM := kmk_builtin_rm
|
---|
427 | else
|
---|
428 | RM := $(RM_EXT)
|
---|
429 | endif
|
---|
430 |
|
---|
431 | RMDIR_EXT := $(PATH_KBUILD_BIN)/kmk_rmdir$(HOSTSUFF_EXE)
|
---|
432 | ifeq ($(filter rmdir,$(KMK_BUILTIN)),rmdir)
|
---|
433 | RMDIR := kmk_builtin_rmdir
|
---|
434 | else
|
---|
435 | RMDIR := $(RMDIR_EXT)
|
---|
436 | endif
|
---|
437 |
|
---|
438 | SED_EXT := $(PATH_KBUILD_BIN)/kmk_sed$(HOSTSUFF_EXE)
|
---|
439 | ifeq ($(filter sed,$(KMK_BUILTIN)),sed)
|
---|
440 | SED := kmk_builtin_sed
|
---|
441 | else
|
---|
442 | SED := $(SED_EXT)
|
---|
443 | endif
|
---|
444 |
|
---|
445 | # Our default shell is the Almquist shell from *BSD.
|
---|
446 | ASH := $(PATH_KBUILD_BIN)/kmk_ash$(HOSTSUFF_EXE)
|
---|
447 | MAKESHELL := $(ASH)
|
---|
448 | SHELL := $(ASH)
|
---|
449 | export SHELL MAKESHELL
|
---|
450 |
|
---|
451 | # Symlinking is problematic on some platforms...
|
---|
452 | LN_SYMLINK := $(LN) -s
|
---|
453 |
|
---|
454 |
|
---|
455 | #
|
---|
456 | # Some Functions.
|
---|
457 | # The lower cased ones are either fallbacks or candidates for functions.c.
|
---|
458 | #
|
---|
459 |
|
---|
460 | ## ABSPATH - make paths absolute.
|
---|
461 | # This implementation is clumsy and doesn't resolve '..' and '.' components.
|
---|
462 | #
|
---|
463 | # @param $1 The paths to make absolute.
|
---|
464 | # @obsolete Use the GNU make function $(abspath) directly now.
|
---|
465 | ABSPATH = $(abspath $(1))
|
---|
466 |
|
---|
467 | ## DIRDEP - make create directory dependencies.
|
---|
468 | #
|
---|
469 | # @param $1 The paths to the directories which must be created.
|
---|
470 | DIRDEP = $(foreach path,$(patsubst %/,%,$(1)),$(path)/)
|
---|
471 |
|
---|
472 | ## Cygwin kludge.
|
---|
473 | # This converts /cygdrive/x/% to x:%.
|
---|
474 | #
|
---|
475 | # @param $1 The paths to make native.
|
---|
476 | # @remark This macro is pretty much obsolete since we don't use cygwin base make.
|
---|
477 | ifneq ($(patsubst /cygdrive/%,%,$(CURDIR)),$(CURDIR))
|
---|
478 | CYGPATHMIXED = $(foreach path,$(1)\
|
---|
479 | ,$(if $(patsubst /cygdrive/%,,$(path)),$(path),$(patsubst $(strip $(firstword $(subst /, ,$(patsubst /cygdrive/%,%,$(path)))))/%,$(strip $(firstword $(subst /, ,$(patsubst /cygdrive/%,%,$(path))))):/%,$(patsubst /cygdrive/%,%,$(path)))))
|
---|
480 | else
|
---|
481 | CYGPATHMIXED = $(1)
|
---|
482 | endif
|
---|
483 |
|
---|
484 | ifneq ($(filter xargs,$(KMK_FEATURES)),xargs) ## @todo Retire this to gnumake-header.kmk when it has been implemented.
|
---|
485 | ##
|
---|
486 | # Fake xargs without doing any commandline splitting.
|
---|
487 | # @param $1 The initial command.
|
---|
488 | # @param $2 The command for the subseqent command lines. optional
|
---|
489 | # @param $3 The command for the final command lines. optional
|
---|
490 | # @param $($#) The arguments.
|
---|
491 | xargs = $(1) $(if $(4),$(4),$(if $(3),$(3),$(2)))
|
---|
492 | endif
|
---|
493 |
|
---|
494 | ## Removes the drive letter from a path (if it has one)
|
---|
495 | # @param $1 the path
|
---|
496 | no-drive = $(word $(words $(subst :, ,$(1))),$(subst :, ,$(1)))
|
---|
497 |
|
---|
498 | ## Removes the root slash from a path (if it has one)
|
---|
499 | # @param $1 the path
|
---|
500 | no-root-slash = $(patsubst /%,%,$(1))
|
---|
501 |
|
---|
502 | ## Figure out where to put object files.
|
---|
503 | # @param $1 real target name.
|
---|
504 | # @param $2 normalized main target
|
---|
505 | TARGET_BASE = $(PATH_TARGET)/$(2)/$(call no-root-slash,$(call no-drive,$(1)))
|
---|
506 |
|
---|
507 | ## Figure out where to put object files.
|
---|
508 | # @param $1 normalized main target
|
---|
509 | TARGET_PATH = $(PATH_TARGET)/$(1)
|
---|
510 |
|
---|
511 |
|
---|
512 | #
|
---|
513 | # Initialize some of the globals which the Config.kmk and
|
---|
514 | # others can add stuff to if they like for processing in the footer.
|
---|
515 | #
|
---|
516 |
|
---|
517 | ## ALL_TARGET
|
---|
518 | # This is the list of all targets.
|
---|
519 | ALL_TARGETS :=
|
---|
520 |
|
---|
521 | ## TEMPLATE_PATHS
|
---|
522 | # List a paths (separated by space) where templates can be found.
|
---|
523 | TEMPLATE_PATHS :=
|
---|
524 |
|
---|
525 | ## TOOL_PATHS
|
---|
526 | # List of paths (separated by space) where tools can be found.
|
---|
527 | TOOL_PATHS :=
|
---|
528 |
|
---|
529 | ## SDK_PATHS
|
---|
530 | # List of paths (separated by space) where SDKs can be found.
|
---|
531 | SDK_PATHS :=
|
---|
532 |
|
---|
533 | ## Proritized list of the default makefile when walking subdirectories.
|
---|
534 | # The user can overload this list.
|
---|
535 | DEFAULT_MAKEFILE := Makefile.kmk makefile.kmk Makefile makefile
|
---|
536 |
|
---|
537 | ## PROPS_TOOLS
|
---|
538 | # This is a subset of the other PROPS
|
---|
539 | PROPS_TOOLS := TOOL CTOOL CXXTOOL ASTOOL RCTOOL ARTOOL LDTOOL FETCHTOOL UNPACKTOOL PATCHTOOL
|
---|
540 |
|
---|
541 | ## PROPS_SINGLE
|
---|
542 | # The list of non-accumulative target properties.
|
---|
543 | # A Config.kmk file can add it's own properties to this list and kBuild
|
---|
544 | # will do the necessary inheritance from templates to targets.
|
---|
545 | PROPS_SINGLE := $(PROPS_TOOLS) INST NOINST BLD_TYPE BLD_TRG BLD_TRG_ARCH BLD_TRG_CPU FETCHDIR \
|
---|
546 | OBJSUFF COBJSUFF CXXOBJSUFF ASOBJSUFF RCOBJSUFF SYSSUFF EXESUFF DLLSUFF LIBSUFF ARLIBSUFF
|
---|
547 |
|
---|
548 | ## PROPS_DEFERRED
|
---|
549 | # This list of non-accumulative target properties which are functions,
|
---|
550 | # and thus should not be expanded until the very last moment.
|
---|
551 | PROPS_DEFERRED := INSTFUN INSTALLER
|
---|
552 |
|
---|
553 | ## PROPS_ACCUMULATE_R
|
---|
554 | # The list of accumulative target properties where the right most value/flag
|
---|
555 | # is the 'most significant'.
|
---|
556 | # A Config.kmk file can add it's own properties to this list and kBuild
|
---|
557 | # will do the necessary inheritance from templates to targets.
|
---|
558 | PROPS_ACCUMULATE_R := \
|
---|
559 | DEFS DEPS ORDERDEPS \
|
---|
560 | CFLAGS CDEFS \
|
---|
561 | CXXFLAGS CXXDEFS \
|
---|
562 | ASFLAGS ASDEFS \
|
---|
563 | RCFLAGS RCDEFS \
|
---|
564 | LDFLAGS \
|
---|
565 | IDFLAGS IFDLAGS ISFLAGS \
|
---|
566 | FETCHFLAGS UNPACKFLAGS PATCHFLAGS
|
---|
567 |
|
---|
568 | ## PROPS_ACCUMULATE
|
---|
569 | # The list of accumulative target properties where the left most value/flag
|
---|
570 | # is the 'most significant'.
|
---|
571 | # A Config.kmk file can add it's own properties to this list and kBuild
|
---|
572 | # will do the necessary inheritance from templates to targets.
|
---|
573 | PROPS_ACCUMULATE_L := \
|
---|
574 | SDKS SOURCES \
|
---|
575 | INCS CINCS CXXINCX ASINCS RCINCS \
|
---|
576 | LIBS LIBPATH
|
---|
577 |
|
---|
578 | ## PROPS_ALL
|
---|
579 | # List of all the properties.
|
---|
580 | PROPS_ALL = $(PROPS_SINGLE) $(PROPS_DEFERRED) $(PROPS_ACCUMULATE_L) $(PROPS_ACCUMULATE_R)
|
---|
581 |
|
---|
582 |
|
---|
583 | #
|
---|
584 | # Here is a special 'hack' to prevent innocent environment variables being
|
---|
585 | # picked up and treated as properties. (The most annoying example of why
|
---|
586 | # this is necessary is the Visual C++ commandline with it's LIBPATH.)
|
---|
587 | #
|
---|
588 | # Define KBUILD_DONT_KILL_ENV_PROPS in the env. or on the commandline to
|
---|
589 | # disable this 'hack'.
|
---|
590 | #
|
---|
591 | ifndef KBUILD_DONT_KILL_ENV_PROPS
|
---|
592 |
|
---|
593 | define def_nuke_environment_prop
|
---|
594 | ifeq ($(origin $(prop)),environment)
|
---|
595 | $(prop) =
|
---|
596 | endif
|
---|
597 | endef
|
---|
598 | $(foreach prop, $(PROPS_ALL) \
|
---|
599 | FETCHES PATCHES BLDPROGS LIBRARIES IMPORT_LIBS DLLS PROGRAMS SYSMODS INSTALLS OTHERS \
|
---|
600 | SUBDIRS MAKEFILES \
|
---|
601 | ,$(eval $(value def_nuke_environment_prop)))
|
---|
602 |
|
---|
603 | endif
|
---|
604 |
|
---|
605 |
|
---|
606 | #
|
---|
607 | # Pass configuration.
|
---|
608 | #
|
---|
609 | # The PASS_<passname>_trgs variable is listing the targets.
|
---|
610 | # The PASS_<passname>_vars variable is listing the target variables.
|
---|
611 | # The PASS_<passname>_pass variable is the lowercased passname.
|
---|
612 | #
|
---|
613 |
|
---|
614 | ## PASS: fetches
|
---|
615 | # This pass fetches and unpacks things needed to complete the build.
|
---|
616 | PASS_FETCHES := Fetches
|
---|
617 | PASS_FETCHES_trgs :=
|
---|
618 | PASS_FETCHES_vars := _FETCHES
|
---|
619 | PASS_FETCHES_pass := fetches
|
---|
620 |
|
---|
621 | ## PASS: patches
|
---|
622 | # This pass applies patches.
|
---|
623 | PASS_PATCHES := Patches
|
---|
624 | PASS_PATCHES_trgs :=
|
---|
625 | PASS_PATCHES_vars := _PATCHES
|
---|
626 | PASS_PATCHES_pass := patches
|
---|
627 |
|
---|
628 | ## PASS: bldprogs
|
---|
629 | # This pass builds targets which are required for building the rest.
|
---|
630 | PASS_BLDPROGS := Build Programs
|
---|
631 | PASS_BLDPROGS_trgs :=
|
---|
632 | PASS_BLDPROGS_vars := _BLDPROGS
|
---|
633 | PASS_BLDPROGS_pass := bldprogs
|
---|
634 |
|
---|
635 | ## PASS: libraries
|
---|
636 | # This pass builds library targets.
|
---|
637 | PASS_LIBRARIES := Libraries
|
---|
638 | PASS_LIBRARIES_trgs :=
|
---|
639 | PASS_LIBRARIES_vars := _LIBS _IMPORT_LIBS _OTHER_LIBRARIES
|
---|
640 | PASS_LIBRARIES_pass := libraries
|
---|
641 |
|
---|
642 | ## PASS: binaries
|
---|
643 | # This pass builds dll targets.
|
---|
644 | PASS_DLLS := DLLs
|
---|
645 | PASS_DLLS_trgs :=
|
---|
646 | PASS_DLLS_vars := _DLLS _OTHER_DLLS
|
---|
647 | PASS_DLLS_pass := dlls
|
---|
648 |
|
---|
649 | ## PASS: binaries
|
---|
650 | # This pass builds binary targets, i.e. programs, system modules and stuff.
|
---|
651 | PASS_BINARIES := Programs
|
---|
652 | PASS_BINARIES_trgs :=
|
---|
653 | PASS_BINARIES_vars := _PROGRAMS _SYSMODS _OTHER_BINARIES
|
---|
654 | PASS_BINARIES_pass := binaries
|
---|
655 |
|
---|
656 | ## PASS: others
|
---|
657 | # This pass builds other targets.
|
---|
658 | PASS_OTHERS := Other Stuff
|
---|
659 | PASS_OTHERS_trgs :=
|
---|
660 | PASS_OTHERS_vars := _OTHERS
|
---|
661 | PASS_OTHERS_pass := others
|
---|
662 |
|
---|
663 | ## PASS: install
|
---|
664 | # This pass installs the built entities to a sandbox area.
|
---|
665 | PASS_INSTALLS := Install
|
---|
666 | PASS_INSTALLS_trgs :=
|
---|
667 | PASS_INSTALLS_vars := _INSTALLS_DIRS _INSTALLS _INSTALLS_FILES
|
---|
668 | PASS_INSTALLS_pass := installs
|
---|
669 |
|
---|
670 | ## PASS: packing
|
---|
671 | # This pass processes custom packing rules.
|
---|
672 | PASS_PACKING := Packing
|
---|
673 | PASS_PACKING_trgs :=
|
---|
674 | PASS_PACKING_vars := _PACKING
|
---|
675 | PASS_PACKING_pass := packing
|
---|
676 | #alias
|
---|
677 | packing: pass_packing
|
---|
678 |
|
---|
679 | ## PASS: clean
|
---|
680 | # This pass removes all generated files.
|
---|
681 | PASS_CLEAN := Clean
|
---|
682 | PASS_CLEAN_trgs := do-clean
|
---|
683 | PASS_CLEAN_vars :=
|
---|
684 | PASS_CLEAN_pass := clean
|
---|
685 | # alias
|
---|
686 | clean: pass_clean
|
---|
687 |
|
---|
688 | ## PASS: nothing
|
---|
689 | # This pass just walks the tree.
|
---|
690 | PASS_NOTHING := Nothing
|
---|
691 | PASS_NOTHING_trgs := do-nothing
|
---|
692 | PASS_NOTHING_vars :=
|
---|
693 | PASS_NOTHING_pass := nothing
|
---|
694 | # alias
|
---|
695 | nothing: pass_nothing
|
---|
696 |
|
---|
697 | ## DEFAULT_PASSES
|
---|
698 | # The default passes and their order.
|
---|
699 | DEFAULT_PASSES := BLDPROGS LIBRARIES DLLS BINARIES OTHERS INSTALLS
|
---|
700 |
|
---|
701 | ## PASSES
|
---|
702 | # The passes that should be defined. This must include
|
---|
703 | # all passes mentioned by DEFAULT_PASSES.
|
---|
704 | PASSES := FETCHES PATCHES $(DEFAULT_PASSES) NOTHING CLEAN
|
---|
705 |
|
---|
706 |
|
---|
707 | #
|
---|
708 | # Include the gnumake header hacks if we're not using kmk.
|
---|
709 | #
|
---|
710 | ifndef KMK_VERSION
|
---|
711 | include $(PATH_KBUILD)/gnumake-header.kmk
|
---|
712 | endif
|
---|
713 |
|
---|
714 |
|
---|
715 | #
|
---|
716 | # This is how we find the closest config.kmk.
|
---|
717 | # It's a little hacky but I think it works fine.
|
---|
718 | #
|
---|
719 | _CFGDIR := .
|
---|
720 | _CFGFILES := ./Config.kmk ./config.kmk
|
---|
721 | define def_include_config
|
---|
722 | $(eval _CFGDIR := $(_CFGDIR)/$(dir))
|
---|
723 | _CFGFILES += $(_CFGDIR)/Config.kmk $(_CFGDIR)/config.kmk
|
---|
724 | endef
|
---|
725 | # walk down the _RELATIVE_ path specified by DEPTH.
|
---|
726 | $(foreach dir,$(subst /, ,$(DEPTH)), $(eval $(def_include_config)) )
|
---|
727 | # add the default config file.
|
---|
728 | _CFGFILE := $(firstword $(wildcard $(_CFGFILES) $(FILE_KBUILD_CONFIG)))
|
---|
729 | _CFGFILES :=
|
---|
730 | _CFGDIR :=
|
---|
731 | ifeq ($(_CFGFILE),)
|
---|
732 | $(error kBuild: no Config.kmk file found! Check the DEPTH: DEPTH='$(DEPTH)' PATH_CURRENT='$(PATH_CURRENT)')
|
---|
733 | endif
|
---|
734 |
|
---|
735 | #
|
---|
736 | # Check for --pretty-command-printing before including the Config.kmk
|
---|
737 | # so that anyone overriding the message macros can take the implied
|
---|
738 | # verbosity level change into account.
|
---|
739 | #
|
---|
740 | ifndef KBUILD_VERBOSE
|
---|
741 | ifndef KBUILD_QUIET
|
---|
742 | ifneq ($(filter --pretty-command-printing,$(MAKEFLAGS)),)
|
---|
743 | export KBUILD_VERBOSE := 2
|
---|
744 | endif
|
---|
745 | endif
|
---|
746 | endif
|
---|
747 |
|
---|
748 |
|
---|
749 | # Include the config.kmk we found file (or the default one).
|
---|
750 | include $(_CFGFILE)
|
---|
751 |
|
---|
752 |
|
---|
753 | #
|
---|
754 | # Setup the message style. The default one is inlined.
|
---|
755 | #
|
---|
756 | # See kBuild/msgstyles for more styles or use KBUILD_MSG_STYLE_PATHS
|
---|
757 | # to create your own message style.
|
---|
758 | #
|
---|
759 | KBUILD_MSG_STYLE ?= default
|
---|
760 | ifeq ($(KBUILD_MSG_STYLE),default)
|
---|
761 | #
|
---|
762 | # The 'default' style.
|
---|
763 | #
|
---|
764 |
|
---|
765 | ## Fetch starting.
|
---|
766 | # @param 1 Target name.
|
---|
767 | MSG_FETCH ?= $(call MSG_L1,Fetching $1...)
|
---|
768 | ## Re-fetch starting.
|
---|
769 | # @param 1 Target name.
|
---|
770 | MSG_REFETCH ?= $(call MSG_L1,Re-fetching $1...)
|
---|
771 | ## Downloading a fetch component.
|
---|
772 | # @param 1 Target name.
|
---|
773 | # @param 2 The source URL.
|
---|
774 | # @param 3 The destination file name.
|
---|
775 | MSG_FETCH_DL ?= $(call MSG_L1,Downloading $1 - $2,=> $3)
|
---|
776 | ## Checking a fetch component.
|
---|
777 | # @param 1 Target name.
|
---|
778 | # @param 2 The source URL.
|
---|
779 | # @param 3 The destination file name.
|
---|
780 | MSG_FETCH_CHK?= $(call MSG_L1,Checking $1 - $3, ($2))
|
---|
781 | ## Unpacking a fetch component.
|
---|
782 | # @param 1 Target name.
|
---|
783 | # @param 2 The archive file name.
|
---|
784 | # @param 3 The target directory.
|
---|
785 | MSG_FETCH_UP ?= $(call MSG_L1,Unpacking $1 - $2 => $3)
|
---|
786 | ## Fetch completed.
|
---|
787 | # @param 1 Target name.
|
---|
788 | MSG_FETCH_OK ?= $(call MSG_L1,Successfully fetched $1)
|
---|
789 | ## Unfetch a fetch target.
|
---|
790 | # @param 1 Target name.
|
---|
791 | MSG_UNFETCH ?= $(call MSG_L1,Unfetching $1...)
|
---|
792 | ## Compiling a source file.
|
---|
793 | # @param 1 Target name.
|
---|
794 | # @param 2 The source filename.
|
---|
795 | # @param 3 The primary link output file name.
|
---|
796 | # @param 4 The source type (CXX,C,AS,RC,++).
|
---|
797 | MSG_COMPILE ?= $(call MSG_L1,Compiling $1 - $2,=> $3)
|
---|
798 | ## Linking a bldprog/dll/program/sysmod target.
|
---|
799 | # @param 1 Target name.
|
---|
800 | # @param 2 The primary link output file name.
|
---|
801 | # @param 3 The link tool operation (LINK_LIBRARY,LINK_PROGRAM,LINK_DLL,LINK_SYSMOD,++).
|
---|
802 | MSG_LINK ?= $(call MSG_L1,Linking $1,=> $2)
|
---|
803 | ## Merging a library into the target (during library linking).
|
---|
804 | # @param 1 Target name.
|
---|
805 | # @param 2 The output library name.
|
---|
806 | # @param 3 The input library name.
|
---|
807 | MSG_AR_MERGE ?= $(call MSG_L1,Merging $3 into $1, ($2))
|
---|
808 | ## Creating a directory (build).
|
---|
809 | # @param 1 Directory name.
|
---|
810 | MSG_MKDIR ?= $(call MSG_L2,Creating directory $1)
|
---|
811 | ## Cleaning.
|
---|
812 | MSG_CLEAN ?= $(call MSG_L1,Cleaning...)
|
---|
813 | ## Nothing.
|
---|
814 | MSG_NOTHING ?= $(call MSG_L1,Did nothing in $(CURDIR))
|
---|
815 | ## Pass
|
---|
816 | # @param 1 The pass name.
|
---|
817 | MSG_PASS ?= $(call MSG_L1,Pass - $1)
|
---|
818 | ## Installing a bldprog/lib/dll/program/sysmod target.
|
---|
819 | # @param 1 Target name.
|
---|
820 | # @param 2 The source filename.
|
---|
821 | # @param 3 The destination file name.
|
---|
822 | MSG_INST_TRG ?= $(call MSG_L1,Installing $1 => $3)
|
---|
823 | ## Installing a file (install target).
|
---|
824 | # @param 1 The source filename.
|
---|
825 | # @param 2 The destination filename.
|
---|
826 | MSG_INST_FILE?= $(call MSG_L1,Installing $2,(<= $1))
|
---|
827 | ## Installing a symlink.
|
---|
828 | # @param 1 Symlink
|
---|
829 | # @param 2 Link target
|
---|
830 | MSG_INST_SYM ?= $(call MSG_L1,Installing symlink $1,=> $2)
|
---|
831 | ## Installing a directory.
|
---|
832 | # @param 1 Directory name.
|
---|
833 | MSG_INST_DIR ?= $(call MSG_L1,Installing directory $1)
|
---|
834 |
|
---|
835 | else
|
---|
836 | _KBUILD_MSG_STYLE_FILE := $(firstword $(foreach path, $(KBUILD_MSG_STYLE_PATHS) $(PATH_KBUILD)/msgstyles, $(wildcard $(path)/$(KBUILD_MSG_STYLE).kmk)))
|
---|
837 | ifneq ($(_KBUILD_MSG_STYLE_FILE),)
|
---|
838 | include $(_KBUILD_MSG_STYLE_FILE)
|
---|
839 | else
|
---|
840 | $(error kBuild: Can't find the style setup file for KBUILD_MSG_STYLE '$(KBUILD_MSG_STYLE)')
|
---|
841 | endif
|
---|
842 | endif
|
---|
843 |
|
---|
844 |
|
---|
845 | #
|
---|
846 | # Message macros.
|
---|
847 | #
|
---|
848 | # This is done after including Config.kmk as to allow for
|
---|
849 | # KBUILD_QUIET and KBUILD_VERBOSE to be configurable.
|
---|
850 | #
|
---|
851 | ifdef KBUILD_QUIET
|
---|
852 | # No output
|
---|
853 | QUIET := @
|
---|
854 | QUIET2:= @
|
---|
855 | MSG_L1 =
|
---|
856 | MSG_L2 =
|
---|
857 | else
|
---|
858 | ifndef KBUILD_VERBOSE
|
---|
859 | # Default output level.
|
---|
860 | QUIET := @
|
---|
861 | QUIET2 := @
|
---|
862 | MSG_L1 ?= @$(ECHO) "kBuild: $1"
|
---|
863 | MSG_L2 =
|
---|
864 | else ifeq ($(KBUILD_VERBOSE),1)
|
---|
865 | # A bit more output
|
---|
866 | QUIET := @
|
---|
867 | QUIET2 := @
|
---|
868 | MSG_L1 ?= @$(ECHO) "kBuild: $1 $2"
|
---|
869 | MSG_L2 =
|
---|
870 | else ifeq ($(KBUILD_VERBOSE),2)
|
---|
871 | # Lot more output
|
---|
872 | QUIET :=
|
---|
873 | QUIET2 := @
|
---|
874 | MSG_L1 ?= @$(ECHO) "kBuild: $1 $2"
|
---|
875 | MSG_L2 ?= @$(ECHO) "kBuild: $1"
|
---|
876 | else
|
---|
877 | # maximal output.
|
---|
878 | QUIET :=
|
---|
879 | QUIET2 :=
|
---|
880 | MSG_L1 ?= @$(ECHO) "kBuild: $1 $2"
|
---|
881 | MSG_L2 ?= @$(ECHO) "kBuild: $1"
|
---|
882 | endif
|
---|
883 | endif
|
---|
884 |
|
---|
885 |
|
---|
886 |
|
---|
887 | # end-of-file-content
|
---|
888 | __header_kmk__ := 1
|
---|
889 | endif # __header_kmk__
|
---|
890 |
|
---|