0.1.5-p2/header.kmk: force revision update.
[kbuild-mirror.git] / kBuild / header.kmk
blobf11abc7689024535b8b7a7912b2dd440f9aa0663
1 # $Id$
2 ## @file
3 # kBuild - File included at top of a makefile.
7 # Copyright (c) 2004-2009 knut st. osmundsen <bird-kBuild-spamix@anduin.net>
9 # This file is part of kBuild.
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.
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.
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
26 # As a special exception you are granted permission to include this file, via
27 # the kmk include directive, as you wish without this in itself causing the
28 # resulting makefile, program or whatever to be covered by the GPL license.
29 # This exception does not however invalidate any other reasons why the makefile,
30 # program, whatever should not be covered the GPL.
34 ifndef __header_kmk__
35 # start-of-file-content
36 ifdef KBUILD_PROFILE_SELF
37 _KBUILD_TS_HEADER_START := $(nanots ) # just a dummy warm up query
38 $(info prof: since start - since previous -- event description)
39 ifeq ($(KBUILD_PROFILE_SELF),2)
40 $(info stat: $(make-stats ))
41 endif
42 _KBUILD_TS_HEADER_START := $(nanots )
43 _KBUILD_TS_PREV := $(_KBUILD_TS_HEADER_START)
45 _KBUILD_FMT_ELAPSED_EX = $(int-div $(int-add $(int-sub $1, $2),500000),1000000)ms
46 _KBUILD_FMT_ELAPSED = $(call _KBUILD_FMT_ELAPSED_EX,$(_KBUILD_TS_NOW),$1)
48 define def_profile_self
49 _KBUILD_TS_NOW := $(nanots )
50 $(info prof: $(call _KBUILD_FMT_ELAPSED,$(_KBUILD_TS_HEADER_START)) - $(call _KBUILD_FMT_ELAPSED, $(_KBUILD_TS_PREV)) -- $(strip $1))
51 ifeq ($(KBUILD_PROFILE_SELF),2)
52 $(info stat: $(make-stats ))
53 endif
54 _KBUILD_TS_PREV := $(_KBUILD_TS_NOW)
55 endef
57 endif
61 # Check make version before we do anything else.
63 ifndef KMK_VERSION
64 $(error kBuild: The kmk default variable KMK_VERSION isn't defined! Make sure you are using 'kmk' and not 'make', 'gmake', 'kmk_gmake', 'dmake' or any other make program)
65 endif
66 ifneq ($(KBUILD_VERSION_MAJOR).$(KBUILD_VERSION_MINOR),0.1)
67 ifneq ($(KBUILD_VERSION_MAJOR),0)
68 $(warning kBuild: kmk major version mismatch! Expected '0' but found '$(KBUILD_VERSION_MAJOR)'!)
69 else
70 $(warning kBuild: kmk minor version mismatch! Expected '1' but found '$(KBUILD_VERSION_MINOR)'!)
71 endif
72 else
73 ifneq ($(int-ge $(KBUILD_VERSION_PATCH),4),1)
74 $(warning kBuild: kmk version mismatch! Expected 0.1.4 or later. Actual version is $(KBUILD_VERSION_MAJOR).$(KBUILD_VERSION_MINOR).$(KBUILD_VERSION_PATCH).)
75 endif
76 endif
79 # The revision in which this file was last modified.
80 # This can be useful when using development versions of kBuild.
82 KMK_REVISION := $(patsubst %:,, $Rev$ )
86 # Define the default goal.
88 .PHONY: all all_recursive
89 all: all_recursive
92 # The phony FORCE target.
94 .PHONY: FORCE
95 FORCE:
99 # Enable delete on error and second expansion of prerequisites and targets.
101 .DELETE_ON_ERROR:
103 .SECONDEXPANSION:
105 .SECONDTARGETEXPANSION:
109 # General purpose macros.
113 # Newline character(s).
114 define NL
117 endef
120 # Tab character.
121 TAB := $(subst ., ,.)
124 # Newline + tab characters (for generating commands).
125 NLTAB = $(NL)$(TAB)
128 # Space character.
129 SP := $(subst ., ,.)
132 # Hash character.
133 define HASH
135 endef
138 # Colon character.
139 COLON := :
142 # Semicolon character.
143 SEMICOLON := ;
146 # Comma character.
147 COMMA := ,
150 # Dot character.
151 DOT := .
154 # Dollar character.
155 DOLLAR := $$
158 # Equal character.
159 EQUAL := =
163 # The list of standard build types in kBuild.
165 # This list can be extended in Config.kmk and it's possible to extend
166 # (inherit) another build type.
168 KBUILD_BLD_TYPES := release profile debug
172 # The OSes, Architectures and CPUs that kBuild recognizes.
174 # When kBuild is ported to a new OS or architecture a unique keyword needs
175 # to be assigned to it and added here. This strictness is required because
176 # this keyword namespace is shared between OSes, architectures, cpus and
177 # build types. (PORTME)
179 KBUILD_OSES := darwin dos dragonfly freebsd l4 linux netbsd nt openbsd os2 solaris win os-agnostic
180 KBUILD_ARCHES := x86 amd64 sparc32 sparc64 s390 s390x ppc32 ppc64 mips32 mips64 ia64 hppa32 hppa64 arm alpha
184 # Set default build type.
186 ifndef KBUILD_TYPE
187 ifdef BUILD_TYPE
188 KBUILD_TYPE := $(BUILD_TYPE)
189 endif
190 else ifdef BUILD_TYPE
191 ifneq ($(KBUILD_TYPE),$(BUILD_TYPE))
192 ifeq ($(origin KBUILD_TYPE):$(origin BUILD_TYPE),environment:command line)
193 KBUILD_TYPE := $(BUILD_TYPE)
194 else ifneq ($(origin KBUILD_TYPE):$(origin BUILD_TYPE),command line:environment)
195 $(error kBuild: KBUILD_TYPE and BUILD_TYPE disagree.)
196 endif
197 endif
198 endif
199 override BUILD_TYPE = $(KBUILD_TYPE)
201 ifndef KBUILD_TYPE
202 KBUILD_TYPE := release
203 else
204 if1of ($(KBUILD_TYPE), $(KBUILD_OSES) $(KBUILD_ARCHES))
205 $(error kBuild: The KBUILD_TYPE value '$(KBUILD_TYPE)' is an OS or architecture!)
206 endif
207 ifneq (.$(words $(KBUILD_TYPE)).$(KBUILD_TYPE).,.1.$(strip $(KBUILD_TYPE)).)
208 $(error kBuild: The KBUILD_TYPE value '$(KBUILD_TYPE)' contains spaces/tabs!)
209 endif
210 endif
214 # Host platform legacy
215 # kmk deals with this, so this is only temporary until I've rebuilt everything.
217 ifndef KBUILD_HOST
218 KBUILD_HOST := $(BUILD_PLATFORM)
219 endif
220 ifndef KBUILD_HOST_ARCH
221 KBUILD_HOST_ARCH := $(BUILD_PLATFORM_ARCH)
222 endif
223 ifndef KBUILD_HOST_CPU
224 KBUILD_HOST_CPU := $(BUILD_PLATFORM_CPU)
225 endif
229 # Assert valid build platform variables.
231 # All these are set by kmk so they shouldn't be any trouble
232 # unless the user starts messing about with environment variables.
234 ifneq (.$(words $(KBUILD_HOST)).$(KBUILD_HOST).,.1.$(strip $(KBUILD_HOST)).)
235 $(error kBuild: The KBUILD_HOST value '$(KBUILD_HOST)' contains spaces/tabs!)
236 endif
237 ifneq ($(words $(filter $(KBUILD_HOST),$(KBUILD_OSES))),1)
238 $(error kBuild: KBUILD_HOST value '$(KBUILD_HOST)' is not recognized (valid: $(KBUILD_OSES)))
239 endif
241 ifneq (.$(words $(KBUILD_HOST_ARCH)).$(KBUILD_HOST_ARCH).,.1.$(strip $(KBUILD_HOST_ARCH)).)
242 $(error kBuild: The KBUILD_HOST_ARCH value '$(KBUILD_HOST_ARCH)' contains spaces/tabs!)
243 endif
244 ifneq ($(words $(filter $(KBUILD_HOST_ARCH),$(KBUILD_ARCHES))),1)
245 $(error kBuild: KBUILD_HOST_ARCH value '$(KBUILD_HOST_ARCH)' is not recognized (valid: $(KBUILD_ARCHES)))
246 endif
248 ifeq ($(strip $(KBUILD_HOST_CPU)),)
249 KBUILD_HOST_CPU := blend
250 else
251 ifneq (.$(words $(KBUILD_HOST_CPU)).$(KBUILD_HOST_CPU).,.1.$(strip $(KBUILD_HOST_CPU)).)
252 $(error kBuild: The KBUILD_HOST_CPU value '$(KBUILD_HOST_CPU)' contains spaces/tabs!)
253 endif
254 if1of ($(KBUILD_HOST_CPU), $(KBUILD_OSES) $(BUILD_ARCHES))
255 $(error kBuild: The KBUILD_HOST_CPU value '$(KBUILD_HOST_CPU)' was found in the OS or architecture keywords!)
256 endif
257 ifeq ($(KBUILD_HOST_CPU),$(KBUILD_TYPE))
258 $(error kBuild: The KBUILD_HOST_CPU value '$(KBUILD_HOST_CPU)' is the same as the KBUILD_TYPE!)
259 endif
260 endif
264 # Deal with target platform legacy.
266 ifndef KBUILD_TARGET
267 ifdef BUILD_TARGET
268 KBUILD_TARGET := $(BUILD_TARGET)
269 endif
270 else ifdef BUILD_TARGET
271 ifneq ($(KBUILD_TARGET),$(BUILD_TARGET))
272 ifeq ($(origin KBUILD_TARGET):$(origin BUILD_TARGET),environment:command line)
273 KBUILD_TARGET := $(BUILD_TARGET)
274 else ifneq ($(origin KBUILD_TARGET):$(origin BUILD_TARGET),command line:environment)
275 $(error kBuild: KBUILD_TARGET and BUILD_TARGET disagree)
276 endif
277 endif
278 endif
279 override BUILD_TARGET = $(KBUILD_TARGET)
281 ifndef KBUILD_TARGET_ARCH
282 ifdef BUILD_TARGET_ARCH
283 KBUILD_TARGET_ARCH := $(BUILD_TARGET_ARCH)
284 endif
285 else ifdef BUILD_TARGET_ARCH
286 ifneq ($(KBUILD_TARGET_ARCH),$(BUILD_TARGET_ARCH))
287 ifeq ($(origin KBUILD_TARGET_ARCH):$(origin BUILD_TARGET_ARCH),environment:command line)
288 KBUILD_TARGET_ARCH := $(BUILD_TARGET_ARCH)
289 else ifneq ($(origin KBUILD_TARGET_ARCH):$(origin BUILD_TARGET_ARCH),command line:environment)
290 $(error kBuild: KBUILD_TARGET_ARCH and BUILD_TARGET_ARCH disagree)
291 endif
292 endif
293 endif
294 override BUILD_TARGET_ARCH = $(KBUILD_TARGET_ARCH)
296 ifndef KBUILD_TARGET_CPU
297 ifdef BUILD_TARGET_CPU
298 KBUILD_TARGET_CPU := $(BUILD_TARGET_CPU)
299 endif
300 else ifdef BUILD_TARGET_CPU
301 ifneq ($(KBUILD_TARGET_CPU),$(BUILD_TARGET_CPU))
302 ifeq ($(origin KBUILD_TARGET_CPU):$(origin BUILD_TARGET_CPU),environment:command line)
303 KBUILD_TARGET_CPU := $(BUILD_TARGET_CPU)
304 else ifneq ($(origin KBUILD_TARGET_CPU):$(origin BUILD_TARGET_CPU),command line:environment)
305 $(error kBuild: KBUILD_TARGET_CPU and BUILD_TARGET_CPU disagree)
306 endif
307 endif
308 endif
309 override BUILD_TARGET_CPU = $(KBUILD_TARGET_CPU)
313 # Assert or set default target platform.
314 # When not defined use the corresponding KBUILD_HOST value.
316 ifndef KBUILD_TARGET
317 KBUILD_TARGET := $(KBUILD_HOST)
318 else
319 ifneq (.$(words $(KBUILD_TARGET)).$(KBUILD_TARGET).,.1.$(strip $(KBUILD_TARGET)).)
320 $(error kBuild: The KBUILD_TARGET value '$(KBUILD_TARGET)' contains spaces/tabs!)
321 endif
322 ifneq ($(words $(filter $(KBUILD_TARGET),$(KBUILD_OSES))),1)
323 $(error kBuild: KBUILD_TARGET value '$(KBUILD_TARGET)' is not recognized (valid: $(KBUILD_OSES)))
324 endif
325 endif
327 ifndef KBUILD_TARGET_ARCH
328 KBUILD_TARGET_ARCH := $(KBUILD_HOST_ARCH)
329 else
330 ifneq (.$(words $(KBUILD_TARGET_ARCH)).$(KBUILD_TARGET_ARCH).,.1.$(strip $(KBUILD_TARGET_ARCH)).)
331 $(error kBuild: The KBUILD_TARGET_ARCH value '$(KBUILD_TARGET_ARCH)' contains spaces/tabs!)
332 endif
333 ifneq ($(words $(filter $(KBUILD_TARGET_ARCH),$(KBUILD_ARCHES))),1)
334 $(error kBuild: KBUILD_TARGET_ARCH value '$(KBUILD_TARGET_ARCH)' is not recognized (valid: $(KBUILD_ARCHES)))
335 endif
336 endif
338 ifndef KBUILD_TARGET_CPU
339 KBUILD_TARGET_CPU := $(KBUILD_HOST_CPU)
340 else ifeq ($(strip $(KBUILD_TARGET_CPU)),)
341 ifeq ($(KBUILD_TARGET_ARCH),$(KBUILD_HOST_ARCH))
342 KBUILD_TARGET_CPU := $(KBUILD_HOST_CPU)
343 else
344 KBUILD_TARGET_CPU := blend
345 endif
346 else
347 ifneq (.$(words $(KBUILD_TARGET_CPU)).$(KBUILD_TARGET_CPU).,.1.$(strip $(KBUILD_TARGET_CPU)).)
348 $(error kBuild: The KBUILD_TARGET_CPU value '$(KBUILD_TARGET_CPU)' contains spaces/tabs!)
349 endif
350 if1of ($(KBUILD_TARGET_CPU), $(KBUILD_OSES) $(BUILD_ARCHES))
351 $(error kBuild: The KBUILD_TARGET_CPU value was found in the OS or architecture keywords!)
352 endif
353 ifeq ($(KBUILD_TARGET_CPU),$(KBUILD_TYPE))
354 $(error kBuild: The KBUILD_TARGET_CPU value '$(KBUILD_TARGET_CPU)' is the same as the KBUILD_TYPE!)
355 endif
356 endif
360 # Paths and stuff.
363 # Adjust DEPTH first.
364 DEPTH := $(strip $(DEPTH))
365 ifeq ($(DEPTH),)
366 DEPTH := .
367 endif
369 ## PATH_CURRENT is the current directory (getcwd).
370 PATH_CURRENT := $(abspath $(CURDIR))
371 ## PATH_SUB_CURRENT points to current directory of the current makefile.
372 # Meaning that it will change value as we enter and exit sub-makefiles.
373 PATH_SUB_CURRENT := $(PATH_CURRENT)
374 ## PATH_ROOT points to the project root directory.
375 PATH_ROOT := $(abspath $(PATH_CURRENT)/$(DEPTH))
376 ## PATH_SUB_ROOT points to the directory of the top-level makefile.
377 ifneq ($(strip $(SUB_DEPTH)),)
378 SUB_DEPTH := $(strip $(SUB_DEPTH))
379 PATH_SUB_ROOT := $(abspath $(PATH_CURRENT)/$(SUB_DEPTH))
380 else
381 PATH_SUB_ROOT := $(PATH_CURRENT)
382 endif
384 ## CURSUBDIR is PATH_SUB_ROOT described relative to PATH_ROOT.
385 # This variable is used to determin where the object files and other output goes.
386 ifneq ($(PATH_ROOT),$(PATH_SUB_ROOT))
387 CURSUBDIR := $(patsubst $(PATH_ROOT)/%,%,$(PATH_SUB_ROOT))
388 else
389 CURSUBDIR := .
390 endif
392 # Output directories.
393 ifndef PATH_OUT_BASE
394 PATH_OUT_BASE := $(PATH_ROOT)/out
395 endif
396 ifndef PATH_OUT
397 ifdef BUILD_TARGET_SUB # (BUILD_TARGET_SUB is not currently recognized by kBuild in any other places - obsolete)
398 PATH_OUT = $(PATH_OUT_BASE)/$(KBUILD_TARGET).$(KBUILD_TARGET_ARCH).$(BUILD_TARGET_SUB)/$(KBUILD_TYPE)
399 else
400 PATH_OUT = $(PATH_OUT_BASE)/$(KBUILD_TARGET).$(KBUILD_TARGET_ARCH)/$(KBUILD_TYPE)
401 endif
402 endif # !define PATH_OUT
403 PATH_OBJCACHE = $(PATH_OUT_BASE)/kObjCache
404 PATH_OBJ = $(PATH_OUT)/obj
405 PATH_TARGET = $(PATH_OBJ)/$(CURSUBDIR)
406 PATH_INS = $(PATH_OUT)
407 PATH_BIN = $(PATH_INS)/bin
408 PATH_DLL = $(PATH_INS)/bin
409 PATH_SYS = $(PATH_INS)/bin
410 PATH_LIB = $(PATH_INS)/lib
411 PATH_DOC = $(PATH_INS)/doc
413 # Development tool tree.
414 KBUILD_DEVTOOLS = $(if $(PATH_DEVTOOLS),$(PATH_DEVTOOLS),$(PATH_ROOT)/tools)
415 KBUILD_DEVTOOLS_TRG = $(KBUILD_DEVTOOLS)/$(KBUILD_TARGET).$(KBUILD_TARGET_ARCH)
416 KBUILD_DEVTOOLS_HST = $(KBUILD_DEVTOOLS)/$(KBUILD_HOST).$(KBUILD_HOST_ARCH)
418 if1of ($(KBUILD_TARGET_ARCH), amd64 hppa64 mips64 ppc64 s390x sparc64)
419 ifeq ($(KBUILD_TARGET_ARCH),amd64)
420 KBUILD_DEVTOOLS_TRG_ALT = $(PATH_DEVTOOLS)/$(KBUILD_TARGET).x86
421 else ifeq ($(KBUILD_TARGET_ARCH),hppa64)
422 KBUILD_DEVTOOLS_TRG_ALT = $(PATH_DEVTOOLS)/$(KBUILD_TARGET).hppa32
423 else ifeq ($(KBUILD_TARGET_ARCH),mips64)
424 KBUILD_DEVTOOLS_TRG_ALT = $(PATH_DEVTOOLS)/$(KBUILD_TARGET).mips32
425 else ifeq ($(KBUILD_TARGET_ARCH),ppc64)
426 KBUILD_DEVTOOLS_TRG_ALT = $(PATH_DEVTOOLS)/$(KBUILD_TARGET).ppc32
427 else ifeq ($(KBUILD_TARGET_ARCH),s390x)
428 KBUILD_DEVTOOLS_TRG_ALT = $(PATH_DEVTOOLS)/$(KBUILD_TARGET).s390
429 else ifeq ($(KBUILD_TARGET_ARCH),sparc64)
430 KBUILD_DEVTOOLS_TRG_ALT = $(PATH_DEVTOOLS)/$(KBUILD_TARGET).sparc32
431 endif
432 endif
434 if1of ($(KBUILD_HOST_ARCH), amd64 hppa64 mips64 ppc64 s390x sparc64)
435 ifeq ($(KBUILD_HOST_ARCH),amd64)
436 KBUILD_DEVTOOLS_HST_ALT = $(PATH_DEVTOOLS)/$(KBUILD_HOST).x86
437 else ifeq ($(KBUILD_HOST_ARCH),hppa64)
438 KBUILD_DEVTOOLS_HST_ALT = $(PATH_DEVTOOLS)/$(KBUILD_HOST).hppa32
439 else ifeq ($(KBUILD_HOST_ARCH),mips64)
440 KBUILD_DEVTOOLS_HST_ALT = $(PATH_DEVTOOLS)/$(KBUILD_HOST).mips32
441 else ifeq ($(KBUILD_HOST_ARCH),ppc64)
442 KBUILD_DEVTOOLS_HST_ALT = $(PATH_DEVTOOLS)/$(KBUILD_HOST).ppc32
443 else ifeq ($(KBUILD_HOST_ARCH),s390x)
444 KBUILD_DEVTOOLS_HST_ALT = $(PATH_DEVTOOLS)/$(KBUILD_HOST).s390
445 else ifeq ($(KBUILD_HOST_ARCH),sparc64)
446 KBUILD_DEVTOOLS_HST_ALT = $(PATH_DEVTOOLS)/$(KBUILD_HOST).sparc32
447 endif
448 endif
451 # KBUILD_PATH / PATH_KBUILD is determined by kmk.
452 ifndef KBUILD_PATH
453 KBUILD_PATH := $(PATH_KBUILD)
454 endif
455 ifeq ($(strip $(KBUILD_PATH)),)
456 $(error kBuild: KBUILD_PATH is missing or empty! kmk is supposed to set it.)
457 endif
458 # KBUILD_BIN_PATH / PATH_KBUILD_BIN is determined by kmk.
459 ifndef KBUILD_BIN_PATH
460 KBUILD_BIN_PATH := $(PATH_KBUILD_BIN)
461 endif
462 ifeq ($(strip $(KBUILD_BIN_PATH)),)
463 $(error kBuild: KBUILD_BIN_PATH is missing or empty! kmk is supposed to set it.)
464 endif
466 # kBuild files which might be of interest.
467 FILE_KBUILD_HEADER := $(KBUILD_PATH)/header.kmk
468 #FILE_KBUILD_CONFIG := $(KBUILD_PATH)/config.kmk
469 FILE_KBUILD_FOOTER := $(KBUILD_PATH)/footer.kmk
470 FILE_KBUILD_SUB_HEADER := $(KBUILD_PATH)/subheader.kmk
471 FILE_KBUILD_SUB_FOOTER := $(KBUILD_PATH)/subfooter.kmk
473 ## MAKEFILE is the name of the main makefile.
474 MAKEFILE := $(firstword $(MAKEFILE_LIST))
475 ## MAKEFILE_CURRENT is the name of the current makefile.
476 # This is updated everything a sub-makefile is included.
477 MAKEFILE_CURRENT := $(MAKEFILE)
480 ## @todo this should be done via SUFF_XYZ.target/host...
483 # Build platform setup.
484 # (PORTME)
486 if1of ($(KBUILD_HOST), win nt)
487 # Win, Win32, Win64, NT.
488 EXEC_X86_WIN32 :=
489 HOSTSUFF_EXE := .exe
491 # OS/2.
492 else ifeq ($(KBUILD_HOST),os2)
493 EXEC_X86_WIN32 := innopec.exe
494 HOSTSUFF_EXE := .exe
496 else if1of ($(KBUILD_HOST), freebsd dragonfly linux openbsd netbsd)
497 # Unix (like) systems with wine.
498 EXEC_X86_WIN32 := wine
499 HOSTSUFF_EXE :=
501 else
502 # Unix (like) systems without wine.
503 EXEC_X86_WIN32 := false
504 HOSTSUFF_EXE :=
505 endif
509 # Build target setup.
510 # (PORTME)
512 SUFF_DEP := .dep
513 SUFF_BIN :=
514 if1of ($(KBUILD_TARGET), win nt os2)
515 SUFF_OBJ := .obj
516 SUFF_LIB := .lib
517 SUFF_DLL := .dll
518 SUFF_EXE := .exe
519 SUFF_SYS := .sys
520 SUFF_RES := .res
521 else ifeq ($(KBUILD_TARGET),l4)
522 SUFF_OBJ := .o
523 SUFF_LIB := .a
524 SUFF_DLL := .s.so
525 SUFF_EXE :=
526 SUFF_SYS := .a
527 SUFF_RES :=
528 else ifeq ($(KBUILD_TARGET),darwin)
529 SUFF_OBJ := .o
530 SUFF_LIB := .a
531 SUFF_DLL := .dylib
532 SUFF_EXE :=
533 SUFF_SYS :=
534 SUFF_RES :=
535 else
536 SUFF_OBJ := .o
537 SUFF_LIB := .a
538 SUFF_DLL := .so
539 SUFF_EXE :=
540 if1of ($(KBUILD_TARGET), dragonfly freebsd linux netbsd openbsd) ## @todo check netbsd and openbsd.
541 SUFF_SYS := .ko
542 else
543 SUFF_SYS :=
544 endif
545 SUFF_RES :=
546 endif
549 # Standard kBuild tools.
551 ifeq ($(KMK),kmk)
552 KMK := $(KBUILD_BIN_PATH)/kmk$(HOSTSUFF_EXE)
553 endif
554 MAKE := $(KMK)
556 GMAKE := $(KBUILD_BIN_PATH)/kmk_gmake$(HOSTSUFF_EXE)
558 #DEP_EXT := $(KBUILD_BIN_PATH)/kDep$(HOSTSUFF_EXE)
559 #DEP_INT := $(KBUILD_BIN_PATH)/kDep$(HOSTSUFF_EXE)
560 #DEP := $(DEP_INT)
562 DEP_IDB_EXT := $(KBUILD_BIN_PATH)/kDepIDB$(HOSTSUFF_EXE)
563 DEP_IDB_INT := kmk_builtin_kDepIDB
564 DEP_IDB := $(DEP_IDB_INT)
566 DEP_PRE := $(KBUILD_BIN_PATH)/kDepPre$(HOSTSUFF_EXE)
568 KOBJCACHE_EXT := $(KBUILD_BIN_PATH)/kObjCache$(HOSTSUFF_EXE)
569 KOBJCACHE := $(KOBJCACHE_EXT)
571 APPEND_EXT := $(KBUILD_BIN_PATH)/kmk_append$(HOSTSUFF_EXE)
572 APPEND_INT := kmk_builtin_append
573 APPEND := $(APPEND_INT)
575 CAT_EXT := $(KBUILD_BIN_PATH)/kmk_cat$(HOSTSUFF_EXE)
576 CAT_INT := kmk_builtin_cat
577 CAT := $(CAT_INT)
579 CHMOD_EXT := $(KBUILD_BIN_PATH)/kmk_chmod$(HOSTSUFF_EXE)
580 CHMOD_INT := kmk_builtin_chmod
581 CHMOD := $(CHMOD_INT)
583 CMP_EXT := $(KBUILD_BIN_PATH)/kmk_cmp$(HOSTSUFF_EXE)
584 CMP_INT := kmk_builtin_cmp
585 CMP := $(CMP_INT)
587 CP_EXT := $(KBUILD_BIN_PATH)/kmk_cp$(HOSTSUFF_EXE)
588 CP_INT := kmk_builtin_cp
589 CP := $(CP_INT)
591 ECHO_EXT := $(KBUILD_BIN_PATH)/kmk_echo$(HOSTSUFF_EXE)
592 ECHO_INT := kmk_builtin_echo
593 ECHO := $(ECHO_INT)
595 EXPR_EXT := $(KBUILD_BIN_PATH)/kmk_expr$(HOSTSUFF_EXE)
596 EXPR_INT := kmk_builtin_expr
597 EXPR := $(EXPR_INT)
599 INSTALL_EXT := $(KBUILD_BIN_PATH)/kmk_install$(HOSTSUFF_EXE)
600 INSTALL_INT := kmk_builtin_install
601 INSTALL := $(INSTALL_INT)
603 LN_EXT := $(KBUILD_BIN_PATH)/kmk_ln$(HOSTSUFF_EXE)
604 LN_INT := kmk_builtin_ln
605 LN := $(LN_INT)
607 MD5SUM_EXT := $(KBUILD_BIN_PATH)/kmk_md5sum$(HOSTSUFF_EXE)
608 MD5SUM_INT := kmk_builtin_md5sum
609 MD5SUM := $(MD5SUM_INT)
611 MKDIR_EXT := $(KBUILD_BIN_PATH)/kmk_mkdir$(HOSTSUFF_EXE)
612 MKDIR_INT := kmk_builtin_mkdir
613 MKDIR := $(MKDIR_INT)
615 MV_EXT := $(KBUILD_BIN_PATH)/kmk_mv$(HOSTSUFF_EXE)
616 MV_INT := kmk_builtin_mv
617 MV := $(MV_INT)
619 PRINTF_EXT := $(KBUILD_BIN_PATH)/kmk_printf$(HOSTSUFF_EXE)
620 PRINTF_INT := kmk_builtin_printf
621 PRINTF := $(PRINTF_INT)
623 REDIRECT_EXT:= $(KBUILD_BIN_PATH)/kmk_redirect$(HOSTSUFF_EXE)
624 REDIRECT_INT:= $(REDIRECT_EXT)
625 REDIRECT := $(REDIRECT_INT)
627 RM_EXT := $(KBUILD_BIN_PATH)/kmk_rm$(HOSTSUFF_EXE)
628 RM_INT := kmk_builtin_rm
629 RM := $(RM_INT)
631 RMDIR_EXT := $(KBUILD_BIN_PATH)/kmk_rmdir$(HOSTSUFF_EXE)
632 RMDIR_INT := kmk_builtin_rmdir
633 RMDIR := $(RMDIR_INT)
635 SED_EXT := $(KBUILD_BIN_PATH)/kmk_sed$(HOSTSUFF_EXE)
636 SED_INT := $(SED_EXT)
637 SED := $(SED_EXT)
639 SLEEP_INT := kmk_builtin_sleep
640 SLEEP_EXT := $(KBUILD_BIN_PATH)/kmk_sleep$(HOSTSUFF_EXE)
641 SLEEP := $(SLEEP_EXT)
643 TEST_EXT := $(KBUILD_BIN_PATH)/kmk_test$(HOSTSUFF_EXE)
644 TEST_INT := kmk_builtin_test
645 TEST := $(TEST_INT)
647 TIME_EXT := $(KBUILD_BIN_PATH)/kmk_time$(HOSTSUFF_EXE)
648 TIME_INT := $(TIME_EXT)
649 TIME := $(TIME_INT)
651 # Our default shell is the Almquist shell from *BSD.
652 ASH := $(KBUILD_BIN_PATH)/kmk_ash$(HOSTSUFF_EXE)
653 MAKESHELL := $(ASH)
654 SHELL := $(ASH)
655 export SHELL MAKESHELL
657 # Symlinking is problematic on some platforms...
658 LN_SYMLINK := $(LN) -s
662 # Some Functions.
663 # The lower cased ones are either fallbacks or candidates for functions.c.
666 ## ABSPATH - make paths absolute.
667 # This implementation is clumsy and doesn't resolve '..' and '.' components.
669 # @param $1 The paths to make absolute.
670 # @obsolete Use the GNU make function $(abspath) directly now.
671 ABSPATH = $(abspath $(1))$(warning ABSPATH is deprecated, use abspath directly!)
673 ## DIRDEP - make create directory dependencies.
675 # @param $1 The paths to the directories which must be created.
676 DIRDEP = $(foreach path,$(patsubst %/,%,$(1)),$(path)/)
678 ## Cygwin kludge.
679 # This converts /cygdrive/x/% to x:%.
681 # @param $1 The paths to make native.
682 # @remark This macro is pretty much obsolete since we don't use cygwin base make.
683 ifneq ($(patsubst /cygdrive/%,%,$(CURDIR)),$(CURDIR))
684 CYGPATHMIXED = $(foreach path,$(1)\
685 ,$(if $(patsubst /cygdrive/%,,$(path)),$(path),$(patsubst $(strip $(firstword $(subst /, ,$(patsubst /cygdrive/%,%,$(path)))))/%,$(strip $(firstword $(subst /, ,$(patsubst /cygdrive/%,%,$(path))))):/%,$(patsubst /cygdrive/%,%,$(path)))))
686 else
687 CYGPATHMIXED = $(1)
688 endif
690 ## Removes the drive letter from a path (if it has one)
691 # @param $1 the path
692 no-drive = $(word $(words $(subst :, ,$(1))),$(subst :, ,$(1)))
694 ## Removes the root slash from a path (if it has one)
695 # @param $1 the path
696 no-root-slash = $(patsubst /%,%,$(1))
698 ## Figure out where to put object files.
699 # @param $1 real target name.
700 # @param $2 normalized main target
701 TARGET_BASE = $(PATH_TARGET)/$(2)/$(call no-root-slash,$(call no-drive,$(1)))
703 ## Figure out where to put object files.
704 # @param $1 normalized main target
705 TARGET_PATH = $(PATH_TARGET)/$(1)
708 # Checks if the specified short option ($1) is found in the flags ($2),
709 # assuming getopt style options.
711 # @returns $3 if present, $4 not.
713 # @param $1 The option (single char!).
714 # @param $2 The option arguments.
715 # @param $3 Eval and return if present.
716 # @param $4 Eval and return if not present.
718 # @todo May confuse option values starting with '-' for options.
719 # @remarks Invoke like this: $(evalcall KB_FN_OPT_TEST_SHORT,d,$(flags),present,not-present)
721 define KB_FN_OPT_TEST_SHORT
722 local options := $(translate $(strip $(filter -%,$(filter-out --%,$2))),$(SP)-,)
723 local .RETURN := $(if-expr $(pos $1,$(options)) != 0,$3,$4)
724 endef
727 # Checks if the specified long option ($1) is found in the flags ($2),
728 # assuming getopt style options.
730 # @returns $3 if present, $4 not.
732 # @param $1 The long option, dashes included. No % chars.
733 # @param $2 The option arguments.
734 # @param $3 Eval and return if present.
735 # @param $4 Eval and return if not present.
737 # @todo May confuse option values starting with '--' for options.
738 # @remarks Invoke like this: $(evalcall KBFN_OPT_TEST_SHORT,--defined,$(flags),present,not-present)
740 define KB_FN_OPT_TEST_LONG
741 local options := $(filter-out =delete=%,$(subst :, =delete=,$(subst =, =delete=,$2)))
742 local .RETURN := $(if-expr "$(filter $1,$(options))" != "",$3,$4)
743 endef
746 # Checks if the specified short ($1) or long ($2) option is found in the flags ($2),
747 # assuming getopt style options.
749 # @returns $4 if present, $5 not.
751 # @param $1 The short option (single char!).
752 # @param $2 The long option, dashes included. No % chars.
753 # @param $3 The option arguments.
754 # @param $4 Eval and return if present.
755 # @param $5 Eval and return if not present.
757 # @todo May confuse option values starting with '--' for options.
758 # @remarks Invoke like this: $(evalcall KB_FN_OPT_TEST_SHORT_LONG,d,--defined,$(flags),present,not-present)
760 define KB_FN_OPT_TEST_SHORT_LONG
761 local short_options := $(translate $(strip $(filter -%,$(filter-out --%,$3))),$(SP)-,)
762 local long_options := $(filter-out =delete=%,$(subst :, =delete=,$(subst =, =delete=,$3)))
763 local .RETURN := $(if-expr $(pos $1,$(short_options)) != 0 || "$(filter $2,$(long_options))" != "",$4,$5)
764 endef
769 # Initialize some of the globals which the Config.kmk and
770 # others can add stuff to if they like for processing in the footer.
773 ## KBUILD_TEMPLATE_PATHS
774 # List a paths (separated by space) where templates can be found.
775 KBUILD_TEMPLATE_PATHS :=
777 ## KBUILD_TOOL_PATHS
778 # List of paths (separated by space) where tools can be found.
779 KBUILD_TOOL_PATHS :=
781 ## KBUILD_SDK_PATHS
782 # List of paths (separated by space) where SDKs can be found.
783 KBUILD_SDK_PATHS :=
785 ## KBUILD_UNIT_PATHS
786 # List of paths (separated by space) where units (USES) can be found.
787 KBUILD_UNIT_PATHS :=
789 ## KBUILD_DEFAULT_PATHS
790 # List of paths (separated by space) to search for stuff as a last resort.
791 KBUILD_DEFAULT_PATHS :=
793 ## Proritized list of the default makefile when walking subdirectories.
794 # The user can overload this list.
795 DEFAULT_MAKEFILE := Makefile.kmk makefile.kmk Makefile makefile
797 ## KBUILD_SRC_HANDLERS
798 # The list of source handlers, pair of extension and handler.
799 # The user can overload this list to provide additional or custom
800 # handlers. On a per-target/template see SRC_HANDLERS.
801 KBUILD_SRC_HANDLERS := \
802 .c:def_src_handler_c \
803 .C:def_src_handler_c \
804 .cxx:def_src_handler_cxx \
805 .CXX:def_src_handler_cxx \
806 .cpp:def_src_handler_cxx \
807 .CPP:def_src_handler_cxx \
808 .cc:def_src_handler_cxx \
809 .CC:def_src_handler_cxx \
810 .m:def_src_handler_objc \
811 .M:def_src_handler_objcxx \
812 .mm:def_src_handler_objcxx \
813 .asm:def_src_handler_asm \
814 .ASM:def_src_handler_asm \
815 .s:def_src_handler_asm \
816 .S:def_src_handler_asm \
817 .rc:def_src_handler_rc \
818 .obj:def_src_handler_obj \
819 .o:def_src_handler_obj \
820 .res:def_src_handler_obj
822 ## PROPS_TOOLS
823 # This is a subset of PROPS_SINGLE.
824 PROPS_TOOLS := TOOL CTOOL CXXTOOL OBJCTOOL OBJCXXTOOL ASTOOL RCTOOL ARTOOL LDTOOL FETCHTOOL UNPACKTOOL PATCHTOOL
826 ## PROPS_SINGLE
827 # The list of non-accumulative target properties.
828 # A Config.kmk file can add it's own properties to this list and kBuild
829 # will do the necessary inheritance for templates, sdks, tools and targets.
830 PROPS_SINGLE := $(PROPS_TOOLS) TEMPLATE INST NOINST BLD_TYPE BLD_TRG BLD_TRG_ARCH BLD_TRG_CPU FETCHDIR \
831 OBJSUFF COBJSUFF CXXOBJSUFF OBJCOBJSUFF OBJCXXOBJSUFF ASOBJSUFF RCOBJSUFF SYSSUFF BINSUFF EXESUFF DLLSUFF LIBSUFF ARLIBSUFF \
832 MODE UID GID
833 ## PROPS_SINGLE_LNK
834 # Subset of PROPS_SINGLE which applies to all linkable targets.
835 PROPS_SINGLE_LNK := TOOL TEMPLATE CTOOL CXXTOOL OBJCTOOL OBJCXXTOOL ASTOOL RCTOOL \
836 INST NOINST BLD_TYPE BLD_TRG BLD_TRG_ARCH BLD_TRG_CPU \
837 OBJSUFF COBJSUFF CXXOBJSUFF OBJCOBJSUFF OBJCXXOBJSUFF ASOBJSUFF RCOBJSUFF \
838 MODE UID GID
840 ## PROPS_DEFERRED
841 # This list of non-accumulative target properties which are or may be
842 # functions, and thus should not be expanded until the very last moment.
843 PROPS_DEFERRED := INSTFUN INSTALLER PRE_CMDS POST_CMDS NAME SONAME
845 ## PROPS_ACCUMULATE_R
846 # The list of accumulative target properties where the right most value/flag
847 # is the 'most significant'.
848 # A Config.kmk file can add it's own properties to this list and kBuild
849 # will do the necessary inheritance from templates to targets.
850 PROPS_ACCUMULATE_R := \
851 DEPS LNK_DEPS ORDERDEPS LNK_ORDERDEPS DEFS \
852 ARFLAGS \
853 CFLAGS CDEFS \
854 CXXFLAGS CXXDEFS \
855 OBJCFLAGS OBJCDEFS \
856 OBJCXXFLAGS OBJCXXDEFS \
857 ASFLAGS ASDEFS \
858 RCFLAGS RCDEFS \
859 LDFLAGS \
860 IDFLAGS IFDLAGS ISFLAGS \
861 FETCHFLAGS UNPACKFLAGS PATCHFLAGS
862 ## PROPS_ACCUMULATE_R_LNK
863 # Subset of PROPS_ACCUMULATE_R which applies to all linkable targets.
864 PROPS_ACCUMULATE_R_LNK := \
865 DEPS LNK_DEPS ORDERDEPS LNK_ORDERDEPS DEFS \
866 CFLAGS CDEFS \
867 CXXFLAGS CXXDEFS \
868 OBJCFLAGS OBJCDEFS \
869 OBJCXXFLAGS OBJCXXDEFS \
870 ASFLAGS ASDEFS \
871 RCFLAGS RCDEFS \
872 IDFLAGS IFDLAGS ISFLAGS
874 ## PROPS_ACCUMULATE
875 # The list of accumulative target properties where the left most value/flag
876 # is the 'most significant'.
877 # A Config.kmk file can add it's own properties to this list and kBuild
878 # will do the necessary inheritance from templates to targets.
879 PROPS_ACCUMULATE_L := \
880 SDKS USES SOURCES SRC_HANDLERS INTERMEDIATES \
881 INCS CINCS CXXINCS OBJCINCS OBJCXXINCS ASINCS RCINCS \
882 LIBS LIBPATH \
883 DIRS BLDDIRS CLEAN
884 ## PROPS_ACCUMULATE_L_LNK
885 # Subset of PROPS_ACCUMULATE_L which applies to all linkable targets.
886 PROPS_ACCUMULATE_L_LNK := \
887 SDKS USES SOURCES SRC_HANDLERS INTERMEDIATES \
888 INCS CINCS CXXINCS OBJCINCS OBJCXXINCS ASINCS RCINCS \
889 BLDDIRS CLEAN
891 ## PROPS_ALL
892 # List of all the properties.
893 PROPS_ALL = $(PROPS_SINGLE) $(PROPS_DEFERRED) $(PROPS_ACCUMULATE_L) $(PROPS_ACCUMULATE_R)
895 ## @name Properties valid on programs (BLDPROGS and PROGRAMS)
896 ## @{
897 PROPS_PROGRAMS_SINGLE := $(PROPS_SINGLE_LNK) LDTOOL EXESUFF
898 PROPS_PROGRAMS_DEFERRED := $(PROPS_DEFERRED)
899 PROPS_PROGRAMS_ACCUMULATE_R := $(PROPS_ACCUMULATE_R_LNK) LDFLAGS
900 PROPS_PROGRAMS_ACCUMULATE_L := $(PROPS_ACCUMULATE_L_LNK) LIBS LIBPATH
901 ## @}
903 ## @name Properties valid on libraries (LIBRARIES and IMPORT_LIBS)
904 ## @{
905 PROPS_LIBRARIES_SINGLE := $(PROPS_SINGLE_LNK) ARTOOL LIBSUFF ARLIBSUFF LIBSUFF
906 PROPS_LIBRARIES_DEFERRED := $(filter-out SONAME,$(PROPS_DEFERRED))
907 PROPS_LIBRARIES_ACCUMULATE_R := $(PROPS_ACCUMULATE_R_LNK) ARFLAGS
908 PROPS_LIBRARIES_ACCUMULATE_L := $(PROPS_ACCUMULATE_L_LNK)
909 ## @}
911 ## @name Properties valid on dlls (DLLS)
912 ## @{
913 PROPS_DLLS_SINGLE := $(PROPS_SINGLE_LNK) LDTOOL DLLSUFF LIBSUFF
914 PROPS_DLLS_DEFERRED := $(PROPS_DEFERRED)
915 PROPS_DLLS_ACCUMULATE_R := $(PROPS_ACCUMULATE_R_LNK) LDFLAGS
916 PROPS_DLLS_ACCUMULATE_L := $(PROPS_ACCUMULATE_L_LNK) LIBS LIBPATH
917 ## @}
919 ## @name Properties valid on system modules (SYSMODS)
920 ## @{
921 PROPS_SYSMODS_SINGLE := $(PROPS_SINGLE_LNK) LDTOOL SYSSUFF
922 PROPS_SYSMODS_DEFERRED := $(PROPS_DEFERRED)
923 PROPS_SYSMODS_ACCUMULATE_R := $(PROPS_ACCUMULATE_R_LNK) LDFLAGS
924 PROPS_SYSMODS_ACCUMULATE_L := $(PROPS_ACCUMULATE_L_LNK) LIBS LIBPATH
925 ## @}
927 ## @name Properties valid on misc binaries (MISCBINS)
928 ## @{
929 PROPS_MISCBINS_SINGLE := $(PROPS_SINGLE_LNK) LDTOOL BINSUFF
930 PROPS_MISCBINS_DEFERRED := $(PROPS_DEFERRED)
931 PROPS_MISCBINS_ACCUMULATE_R := $(PROPS_ACCUMULATE_R_LNK) LDFLAGS
932 PROPS_MISCBINS_ACCUMULATE_L := $(PROPS_ACCUMULATE_L_LNK) LIBS LIBPATH
933 ## @}
935 ## @name Properties valid on installs (INSTALLS)
936 ## @{
937 PROPS_INSTALLS_SINGLE := TOOL TEMPLATE INST NOINST
938 PROPS_INSTALLS_DEFERRED := INSTFUN INSTALLER
939 PROPS_INSTALLS_ACCUMULATE_R := DEPS ORDERDEPS
940 PROPS_INSTALLS_ACCUMULATE_L := SOURCES DIRS CLEAN
941 ## @}
943 ## @name Properties valid on fetches (INSTALLS)
944 ## @{
945 PROPS_FETCHES_SINGLE := TOOL TEMPLATE FETCHTOOL UNPACKTOOL PATCHTOOL INST FETCHDIR
946 PROPS_FETCHES_DEFERRED :=
947 PROPS_FETCHES_ACCUMULATE_R := FETCHFLAGS UNPACKFLAGS PATCHFLAGS
948 PROPS_FETCHES_ACCUMULATE_L := SOURCES CLEAN
949 ## @}
951 ## KBUILD_COMPILE_CATEGTORIES
952 # Tools categories for compiling.
953 KBUILD_COMPILE_CATEGTORIES := AS C CXX OBJC OBJCXX RC
955 ## KBUILD_GENERIC_CATEGORIES
956 # Generic tool categories.
957 KBUILD_GENERIC_CATEGORIES := FETCH UNPACK PATCH $(addprefix LINK_,LIBRARY PROGRAM DLL SYSMOD MISCBIN)
959 ## PROPS_TOOLS_ONLY
960 # Properties found only on tools.
961 # This is expanded in a deferred manner, so it will pick up changes made to
962 # KBUILD_COMPILE_CATEGTORIES and KBUILD_GENERIC_CATEGORIES made by units.
963 PROPS_TOOLS_ONLY = \
964 $(foreach cat, $(KBUILD_COMPILE_CATEGTORIES), \
965 COMPILE_$(cat)_CMDS \
966 COMPILE_$(cat)_OUTPUT \
967 COMPILE_$(cat)_OUTPUT_MAYBE \
968 COMPILE_$(cat)_DEPEND \
969 COMPILE_$(cat)_DEPORD \
970 COMPILE_$(cat)_USES_KOBJCACHE ) \
971 $(foreach cat, $(KBUILD_GENERIC_CATEGORIES), \
972 $(cat)_CMDS \
973 $(cat)_OUTPUT \
974 $(cat)_OUTPUT_MAYBE \
975 $(cat)_DEPEND \
976 $(cat)_DEPORD ))
980 # Here is a special 'hack' to prevent innocent environment variables being
981 # picked up and treated as properties. (The most annoying example of why
982 # this is necessary is the Visual C++ commandline with it's LIBPATH.)
984 # Define KBUILD_DONT_KILL_ENV_PROPS in the env. or on the commandline to
985 # disable this 'hack'.
987 ifndef KBUILD_DONT_KILL_ENV_PROPS
989 define def_nuke_environment_prop
990 ifeq ($(origin $(prop)),environment)
991 $(prop) =
992 endif
993 endef
994 $(foreach prop, $(PROPS_ALL) \
995 FETCHES PATCHES BLDPROGS LIBRARIES IMPORT_LIBS DLLS PROGRAMS SYSMODS MISCBINS INSTALLS OTHERS \
996 SUBDIRS MAKEFILES BLDDIRS \
997 ,$(eval $(value def_nuke_environment_prop)))
999 endif # KBUILD_DONT_KILL_ENV_PROPS
1003 # Pass configuration.
1005 # The PASS_<passname>_trgs variable is listing the targets.
1006 # The PASS_<passname>_vars variable is listing the target variables.
1007 # The PASS_<passname>_pass variable is the lowercased passname.
1010 ## PASS: fetches
1011 # This pass fetches and unpacks things needed to complete the build.
1012 PASS_FETCHES := Fetches
1013 PASS_FETCHES_trgs :=
1014 PASS_FETCHES_vars := _FETCHES
1015 PASS_FETCHES_pass := fetches
1017 ## PASS: patches
1018 # This pass applies patches.
1019 PASS_PATCHES := Patches
1020 PASS_PATCHES_trgs :=
1021 PASS_PATCHES_vars := _PATCHES
1022 PASS_PATCHES_pass := patches
1024 ## PASS: bldprogs
1025 # This pass builds targets which are required for building the rest.
1026 PASS_BLDPROGS := Build Programs
1027 PASS_BLDPROGS_trgs :=
1028 PASS_BLDPROGS_vars := _BLDPROGS
1029 PASS_BLDPROGS_pass := bldprogs
1031 ## PASS: libraries
1032 # This pass builds library targets.
1033 PASS_LIBRARIES := Libraries
1034 PASS_LIBRARIES_trgs :=
1035 PASS_LIBRARIES_vars := _LIBS _IMPORT_LIBS _OTHER_LIBRARIES
1036 PASS_LIBRARIES_pass := libraries
1038 ## PASS: binaries
1039 # This pass builds dll targets.
1040 PASS_DLLS := DLLs
1041 PASS_DLLS_trgs :=
1042 PASS_DLLS_vars := _DLLS _OTHER_DLLS
1043 PASS_DLLS_pass := dlls
1045 ## PASS: binaries
1046 # This pass builds binary targets, i.e. programs, system modules and stuff.
1047 PASS_BINARIES := Programs
1048 PASS_BINARIES_trgs :=
1049 PASS_BINARIES_vars := _PROGRAMS _SYSMODS _MISC_BINS _OTHER_BINARIES
1050 PASS_BINARIES_pass := binaries
1052 ## PASS: others
1053 # This pass builds other targets.
1054 PASS_OTHERS := Other Stuff
1055 PASS_OTHERS_trgs :=
1056 PASS_OTHERS_vars := _OTHERS
1057 PASS_OTHERS_pass := others
1059 ## PASS: install
1060 # This pass installs the built entities to a sandbox area.
1061 ## @todo split this up into build install (to sandbox) and real installation.
1062 PASS_INSTALLS := Install
1063 PASS_INSTALLS_trgs :=
1064 PASS_INSTALLS_vars := _INSTALLS_DIRS _INSTALLS _INSTALLS_FILES
1065 PASS_INSTALLS_pass := installs
1067 ## PASS: testing
1068 # This pass processes custom rules for executing tests.
1069 PASS_TESTING := Tests
1070 PASS_TESTING_trgs :=
1071 PASS_TESTING_vars := _TESTING
1072 PASS_TESTING_pass := testing
1074 ## PASS: packing
1075 # This pass processes custom packing rules.
1076 PASS_PACKING := Packing
1077 PASS_PACKING_trgs :=
1078 PASS_PACKING_vars := _PACKING
1079 PASS_PACKING_pass := packing
1081 ## PASS: clean
1082 # This pass removes all generated files.
1083 PASS_CLEAN := Clean
1084 PASS_CLEAN_trgs := do-clean
1085 PASS_CLEAN_vars :=
1086 PASS_CLEAN_pass := clean
1088 ## PASS: nothing
1089 # This pass just walks the tree.
1090 PASS_NOTHING := Nothing
1091 PASS_NOTHING_trgs := do-nothing
1092 PASS_NOTHING_vars :=
1093 PASS_NOTHING_pass := nothing
1095 ## DEFAULT_PASSES
1096 # The default passes and their order.
1097 DEFAULT_PASSES := BLDPROGS LIBRARIES DLLS BINARIES OTHERS INSTALLS
1099 ## PASSES
1100 # The passes that should be defined. This must include
1101 # all passes mentioned by DEFAULT_PASSES.
1102 PASSES := FETCHES PATCHES $(DEFAULT_PASSES) TESTING PACKING CLEAN NOTHING
1106 # Check for --pretty-command-printing before including the Config.kmk
1107 # so that anyone overriding the message macros can take the implied
1108 # verbosity level change into account.
1110 ifndef KBUILD_VERBOSE
1111 ifndef KBUILD_QUIET
1112 ifeq ($(KMK_OPTS_PRETTY_COMMAND_PRINTING),1)
1113 export KBUILD_VERBOSE := 2
1114 endif
1115 endif
1116 endif
1120 # Legacy variable translation.
1121 # These will be eliminated when switching to the next version.
1123 ifdef USE_KOBJCACHE
1124 ifndef KBUILD_USE_KOBJCACHE
1125 export KBUILD_USE_KOBJCACHE := $(USE_KOBJCACHE)
1126 endif
1127 endif
1131 # This is how we find the closest config.kmk.
1132 # It's a little hacky but I think it works fine.
1134 _CFGDIR := .
1135 _CFGFILES := ./Config.kmk ./config.kmk
1136 define def_include_config
1137 $(eval _CFGDIR := $(_CFGDIR)/$(dir))
1138 _CFGFILES += $(_CFGDIR)/Config.kmk $(_CFGDIR)/config.kmk
1139 endef
1140 # walk down the _RELATIVE_ path specified by DEPTH.
1141 $(foreach dir,$(subst /, ,$(DEPTH)), $(eval $(def_include_config)) )
1142 # add the default config file.
1143 _CFGFILE := $(firstword $(wildcard $(_CFGFILES) $(FILE_KBUILD_CONFIG)))
1144 _CFGFILES :=
1145 _CFGDIR :=
1146 ifeq ($(_CFGFILE),)
1147 $(error kBuild: no Config.kmk file found! Check the DEPTH: DEPTH='$(DEPTH)' PATH_CURRENT='$(PATH_CURRENT)')
1148 endif
1150 # Include the config.kmk we found file (or the default one).
1151 ifdef KBUILD_PROFILE_SELF
1152 $(evalcall def_profile_self, including $(_CFGFILE))
1153 include $(_CFGFILE)
1154 $(evalcall def_profile_self, included $(_CFGFILE))
1155 else
1156 include $(_CFGFILE)
1157 endif
1162 # Finalize a the central path variables now that we've included the Config.kmk file.
1164 # This prevents some trouble when users override the defaults for these
1165 # variables and uses relative paths or paths with incorrect case.
1167 PATH_OUT_BASE := $(abspath $(PATH_OUT_BASE))
1168 PATH_OUT := $(abspath $(PATH_OUT))
1169 PATH_OBJ := $(abspath $(PATH_OBJ))
1170 PATH_TARGET := $(abspath $(PATH_TARGET))
1171 PATH_INS := $(abspath $(PATH_INS))
1172 PATH_BIN := $(abspath $(PATH_BIN))
1173 PATH_DLL := $(abspath $(PATH_DLL))
1174 PATH_SYS := $(abspath $(PATH_SYS))
1175 PATH_LIB := $(abspath $(PATH_LIB))
1176 PATH_DOC := $(abspath $(PATH_DOC))
1180 # Setup the message style. The default one is inlined.
1182 # See kBuild/msgstyles for more styles or use KBUILD_MSG_STYLE_PATHS
1183 # to create your own message style.
1185 KBUILD_MSG_STYLE ?= default
1186 ifeq ($(KBUILD_MSG_STYLE),default)
1188 # The 'default' style.
1191 ## Fetch starting.
1192 # @param 1 Target name.
1193 MSG_FETCH ?= $(call MSG_L1,Fetching $1...)
1194 ## Re-fetch starting.
1195 # @param 1 Target name.
1196 MSG_REFETCH ?= $(call MSG_L1,Re-fetching $1...)
1197 ## Downloading a fetch component.
1198 # @param 1 Target name.
1199 # @param 2 The source URL.
1200 # @param 3 The destination file name.
1201 MSG_FETCH_DL ?= $(call MSG_L1,Downloading $1 - $2,=> $3)
1202 ## Checking a fetch component.
1203 # @param 1 Target name.
1204 # @param 2 The source URL.
1205 # @param 3 The destination file name.
1206 MSG_FETCH_CHK?= $(call MSG_L1,Checking $1 - $3, ($2))
1207 ## Unpacking a fetch component.
1208 # @param 1 Target name.
1209 # @param 2 The archive file name.
1210 # @param 3 The target directory.
1211 MSG_FETCH_UP ?= $(call MSG_L1,Unpacking $1 - $2 => $3)
1212 ## Fetch completed.
1213 # @param 1 Target name.
1214 MSG_FETCH_OK ?= $(call MSG_L1,Successfully fetched $1)
1215 ## Unfetch a fetch target.
1216 # @param 1 Target name.
1217 MSG_UNFETCH ?= $(call MSG_L1,Unfetching $1...)
1218 ## Compiling a source file.
1219 # @param 1 Target name.
1220 # @param 2 The source filename.
1221 # @param 3 The primary link output file name.
1222 # @param 4 The source type (C,CXX,OBJC,AS,RC,++).
1223 MSG_COMPILE ?= $(call MSG_L1,Compiling $1 - $2,=> $3)
1224 ## Tool
1225 # @param 1 The tool name (bin2c,...)
1226 # @param 2 Target name.
1227 # @param 3 The source filename.
1228 # @param 4 The primary output file name.
1229 MSG_TOOL ?= $(call MSG_L1,$1 $2 - $3,=> $4)
1230 ## Generate a file, typically a source file.
1231 # @param 1 Target name if applicable.
1232 # @param 2 Output file name.
1233 # @param 3 What it's generated from
1234 MSG_GENERATE ?= $(call MSG_L1,Generating $(if $1,$1 - )$2,$(if $3,from $3))
1235 ## Linking a bldprog/dll/program/sysmod target.
1236 # @param 1 Target name.
1237 # @param 2 The primary link output file name.
1238 # @param 3 The link tool operation (LINK_LIBRARY,LINK_PROGRAM,LINK_DLL,LINK_SYSMOD,++).
1239 MSG_LINK ?= $(call MSG_L1,Linking $1,=> $2)
1240 ## Merging a library into the target (during library linking).
1241 # @param 1 Target name.
1242 # @param 2 The output library name.
1243 # @param 3 The input library name.
1244 MSG_AR_MERGE ?= $(call MSG_L1,Merging $3 into $1, ($2))
1245 ## Creating a directory (build).
1246 # @param 1 Directory name.
1247 MSG_MKDIR ?= $(call MSG_L2,Creating directory $1)
1248 ## Cleaning.
1249 MSG_CLEAN ?= $(call MSG_L1,Cleaning...)
1250 ## Nothing.
1251 MSG_NOTHING ?= $(call MSG_L1,Did nothing in $(CURDIR))
1252 ## Pass
1253 # @param 1 The pass name.
1254 MSG_PASS ?= $(call MSG_L1,Pass - $1)
1255 ## Installing a bldprog/lib/dll/program/sysmod target.
1256 # @param 1 Target name.
1257 # @param 2 The source filename.
1258 # @param 3 The destination file name.
1259 MSG_INST_TRG ?= $(call MSG_L1,Installing $1 => $3)
1260 ## Installing a file (install target).
1261 # @param 1 The source filename.
1262 # @param 2 The destination filename.
1263 MSG_INST_FILE?= $(call MSG_L1,Installing $2,(<= $1))
1264 ## Installing a symlink.
1265 # @param 1 Symlink
1266 # @param 2 Link target
1267 MSG_INST_SYM ?= $(call MSG_L1,Installing symlink $1,=> $2)
1268 ## Installing a directory.
1269 # @param 1 Directory name.
1270 MSG_INST_DIR ?= $(call MSG_L1,Installing directory $1)
1272 else
1273 _KBUILD_MSG_STYLE_FILE := $(firstword $(foreach path, $(KBUILD_MSG_STYLE_PATHS) $(KBUILD_PATH)/msgstyles, $(wildcard $(path)/$(KBUILD_MSG_STYLE).kmk)))
1274 ifneq ($(_KBUILD_MSG_STYLE_FILE),)
1275 include $(_KBUILD_MSG_STYLE_FILE)
1276 else
1277 $(error kBuild: Can't find the style setup file for KBUILD_MSG_STYLE '$(KBUILD_MSG_STYLE)')
1278 endif
1279 endif
1283 # Message macros.
1285 # This is done after including Config.kmk as to allow for
1286 # KBUILD_QUIET and KBUILD_VERBOSE to be configurable.
1288 ifdef KBUILD_QUIET
1289 # No output
1290 QUIET := @
1291 QUIET2:= @
1292 MSG_L1 =
1293 MSG_L2 =
1294 else
1295 ifndef KBUILD_VERBOSE
1296 # Default output level.
1297 QUIET := @
1298 QUIET2 := @
1299 MSG_L1 ?= %@$(ECHO) "kBuild: $1"
1300 MSG_L2 =
1301 else ifeq ($(KBUILD_VERBOSE),1)
1302 # A bit more output
1303 QUIET := @
1304 QUIET2 := @
1305 MSG_L1 ?= %@$(ECHO) "kBuild: $1 $2"
1306 MSG_L2 =
1307 else ifeq ($(KBUILD_VERBOSE),2)
1308 # Lot more output
1309 QUIET :=
1310 QUIET2 := @
1311 MSG_L1 ?= %@$(ECHO) "kBuild: $1 $2"
1312 MSG_L2 ?= %@$(ECHO) "kBuild: $1"
1313 else
1314 # maximal output.
1315 QUIET :=
1316 QUIET2 :=
1317 MSG_L1 ?= %@$(ECHO) "kBuild: $1 $2"
1318 MSG_L2 ?= %@$(ECHO) "kBuild: $1"
1319 endif
1320 endif
1324 # Validate any KBUILD_BLD_TYPES additions and finally the KBUILD_TYPE.
1326 if1of ($(KBUILD_BLD_TYPES), $(KBUILD_OSES))
1327 $(error kBuild: found KBUILD_BLD_TYPES in KBUILD_OSES!)
1328 endif
1329 if1of ($(KBUILD_BLD_TYPES), $(KBUILD_ARCHES))
1330 $(error kBuild: found KBUILD_BLD_TYPES in KBUILD_ARCHES!)
1331 endif
1332 if1of ($(KBUILD_OSES), $(KBUILD_ARCHES))
1333 $(error kBuild: found KBUILD_OSES in KBUILD_ARCHES!)
1334 endif
1335 ifn1of ($(KBUILD_TYPE), $(KBUILD_BLD_TYPES))
1336 $(error kBuild: KBUILD_TYPE(=$(KBUILD_TYPE)) is not found in KBUILD_BLD_TYPES(=$(KBUILD_BLD_TYPES))!)
1337 endif
1341 ifdef KBUILD_PROFILE_SELF
1342 $(evalcall def_profile_self, end of header.kmk)
1343 _KBUILD_TS_HEADER_END := $(_KBUILD_TS_PREV)
1344 endif
1346 # end-of-file-content
1347 __header_kmk__ := 1
1348 endif # __header_kmk__