source: trunk/kBuild/header.kmk@ 1492

Last change on this file since 1492 was 1441, checked in by bird, 17 years ago

output make-stats when KBUILD_PROFILE_SELF is active.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 32.1 KB
Line 
1# $Id: header.kmk 1441 2008-03-30 05:31:21Z bird $
2## @file
3#
4# kBuild - File included at top of a 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
27ifndef __header_kmk__
28# start-of-file-content
29ifdef KBUILD_PROFILE_SELF
30 _KBUILD_TS_HEADER_START := $(nanots ) # just a dummy warm up query
31 $(info prof: since start - since previous - event description)
32 $(info stat: $(make-stats ))
33 _KBUILD_TS_HEADER_START := $(nanots )
34 _KBUILD_TS_PREV := $(_KBUILD_TS_HEADER_START)
35endif
36
37
38#
39# Check make version before we do anything else.
40#
41ifndef KMK_VERSION
42 $(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)
43endif
44ifneq ($(KBUILD_VERSION_MAJOR).$(KBUILD_VERSION_MINOR),0.1)
45 ifneq ($(KBUILD_VERSION_MAJOR),0)
46 $(warning kBuild: kmk major version mismatch! Expected '0' but found '$(KBUILD_VERSION_MAJOR)'!)
47 else
48 $(warning kBuild: kmk minor version mismatch! Expected '1' but found '$(KBUILD_VERSION_MINOR)'!)
49 endif
50else
51 ifneq ($(int-ge $(KBUILD_VERSION_PATCH),2),1)
52 $(warning kBuild: kmk version mismatch! Expected 0.1.2 or later. Actual version is $(KBUILD_VERSION_MAJOR).$(KBUILD_VERSION_MINOR).$(KBUILD_VERSION_PATCH).)
53 endif
54endif
55
56#
57# The revision in which this file was last modified.
58# This can be useful when using development versions of kBuild.
59#
60KMK_REVISION := $(patsubst %:,, $Rev: 1441 $ )
61
62
63#
64# Define the default goal.
65#
66all: all_recursive
67
68#
69# The phony FORCE target.
70#
71FORCE:
72
73
74#
75# Enable delete on error and second expansion of prerequisites.
76#
77.DELETE_ON_ERROR:
78
79.SECONDEXPANSION:
80
81
82#
83# General purpose macros.
84#
85
86##
87# Newline character(s).
88define NL
89
90
91endef
92
93##
94# Tab character.
95TAB := $(subst ., ,.)
96
97##
98# Newline + tab characters (for generating commands).
99NLTAB = $(NL)$(TAB)
100
101##
102# Space character.
103SP := $(subst ., ,.)
104
105##
106# Hash character.
107define HASH
108#
109endef
110
111##
112# Colon character.
113COLON := :
114
115##
116# Semicolon character.
117SEMICOLON := ;
118
119##
120# Comma character.
121COMMA := ,
122
123##
124# Dot character.
125DOT := .
126
127##
128# Dollar character.
129DOLLAR := $$
130
131##
132# Equal character.
133EQUAL := =
134
135
136#
137# The list of standard build types in kBuild.
138#
139# This list can be extended in Config.kmk and it's possible to extend
140# (inherit) another build type.
141#
142KBUILD_BLD_TYPES := release profile debug
143
144
145#
146# The OSes, Architectures and CPUs that kBuild recognizes.
147#
148# When kBuild is ported to a new OS or architecture a unique keyword needs
149# to be assigned to it and added here. This strictness is required because
150# this keyword namespace is shared between OSes, architectures, cpus and
151# build types. (PORTME)
152#
153KBUILD_OSES := darwin freebsd l4 linux netbsd nt openbsd os2 solaris win
154KBUILD_ARCHES := x86 amd64 sparc32 sparc64 s390 s390x ppc32 ppc64 mips32 mips64 ia64 hppa32 hppa64 arm alpha
155
156
157#
158# Set default build type.
159#
160ifndef BUILD_TYPE
161 BUILD_TYPE := release
162else
163 if1of ($(BUILD_TYPE), $(KBUILD_OSES) $(KBUILD_ARCHES))
164 $(error kBuild: The BUILD_TYPE value '$(BUILD_TYPE)' is an OS or architecture!)
165 endif
166 ifneq (.$(words $(BUILD_TYPE)).$(BUILD_TYPE).,.1.$(strip $(BUILD_TYPE)).)
167 $(error kBuild: The BUILD_TYPE value '$(BUILD_TYPE)' contains spaces/tabs!)
168 endif
169endif
170
171
172#
173# Assert valid build platform variables.
174#
175# All these are set by kmk so they shouldn't be any trouble
176# unless the user starts messing about with environment variables.
177#
178ifneq (.$(words $(BUILD_PLATFORM)).$(BUILD_PLATFORM).,.1.$(strip $(BUILD_PLATFORM)).)
179 $(error kBuild: The BUILD_PLATFORM value '$(BUILD_PLATFORM)' contains spaces/tabs!)
180endif
181ifneq ($(words $(filter $(BUILD_PLATFORM),$(KBUILD_OSES))),1)
182 $(error kBuild: BUILD_PLATFORM value '$(BUILD_PLATFORM)' is not recognized (valid: $(KBUILD_OSES)))
183endif
184
185ifneq (.$(words $(BUILD_PLATFORM_ARCH)).$(BUILD_PLATFORM_ARCH).,.1.$(strip $(BUILD_PLATFORM_ARCH)).)
186 $(error kBuild: The BUILD_PLATFORM_ARCH value '$(BUILD_PLATFORM_ARCH)' contains spaces/tabs!)
187endif
188ifneq ($(words $(filter $(BUILD_PLATFORM_ARCH),$(KBUILD_ARCHES))),1)
189 $(error kBuild: BUILD_PLATFORM_ARCH value '$(BUILD_PLATFORM_ARCH)' is not recognized (valid: $(KBUILD_ARCHES)))
190endif
191
192ifeq ($(strip $(BUILD_PLATFORM_CPU)),)
193 BUILD_PLATFORM_CPU := blend
194else
195 ifneq (.$(words $(BUILD_PLATFORM_CPU)).$(BUILD_PLATFORM_CPU).,.1.$(strip $(BUILD_PLATFORM_CPU)).)
196 $(error kBuild: The BUILD_PLATFORM_CPU value '$(BUILD_PLATFORM_CPU)' contains spaces/tabs!)
197 endif
198 if1of ($(BUILD_PLATFORM_CPU), $(KBUILD_OSES) $(BUILD_ARCHES))
199 $(error kBuild: The BUILD_PLATFORM_CPU value '$(BUILD_PLATFORM_CPU)' was found in the OS or architecture keywords!)
200 endif
201 ifeq ($(BUILD_PLATFORM_CPU),$(BUILD_TYPE))
202 $(error kBuild: The BUILD_PLATFORM_CPU value '$(BUILD_PLATFORM_CPU)' is the same as the BUILD_TYPE!)
203 endif
204endif
205
206
207#
208# Assert or set default target platform.
209# When not defined use the corresponding BUILD_PLATFORM value.
210#
211ifndef BUILD_TARGET
212 BUILD_TARGET := $(BUILD_PLATFORM)
213else
214 ifneq (.$(words $(BUILD_TARGET)).$(BUILD_TARGET).,.1.$(strip $(BUILD_TARGET)).)
215 $(error kBuild: The BUILD_TARGET value '$(BUILD_TARGET)' contains spaces/tabs!)
216 endif
217 ifneq ($(words $(filter $(BUILD_TARGET),$(KBUILD_OSES))),1)
218 $(error kBuild: BUILD_TARGET value '$(BUILD_TARGET)' is not recognized (valid: $(KBUILD_OSES)))
219 endif
220endif
221
222ifndef BUILD_TARGET_ARCH
223 BUILD_TARGET_ARCH := $(BUILD_PLATFORM_ARCH)
224else
225 ifneq (.$(words $(BUILD_TARGET_ARCH)).$(BUILD_TARGET_ARCH).,.1.$(strip $(BUILD_TARGET_ARCH)).)
226 $(error kBuild: The BUILD_TARGET_ARCH value '$(BUILD_TARGET_ARCH)' contains spaces/tabs!)
227 endif
228 ifneq ($(words $(filter $(BUILD_TARGET_ARCH),$(KBUILD_ARCHES))),1)
229 $(error kBuild: BUILD_TARGET_ARCH value '$(BUILD_TARGET_ARCH)' is not recognized (valid: $(KBUILD_ARCHES)))
230 endif
231endif
232
233ifndef BUILD_TARGET_CPU
234 BUILD_TARGET_CPU := $(BUILD_PLATFORM_CPU)
235else ifeq ($(strip $(BUILD_TARGET_CPU)),)
236 ifeq ($(BUILD_TARGET_ARCH),$(BUILD_PLATFORM_ARCH))
237 BUILD_TARGET_CPU := $(BUILD_PLATFORM_CPU)
238 else
239 BUILD_TARGET_CPU := blend
240 endif
241else
242 ifneq (.$(words $(BUILD_TARGET_CPU)).$(BUILD_TARGET_CPU).,.1.$(strip $(BUILD_TARGET_CPU)).)
243 $(error kBuild: The BUILD_TARGET_CPU value '$(BUILD_TARGET_CPU)' contains spaces/tabs!)
244 endif
245 if1of ($(BUILD_TARGET_CPU), $(KBUILD_OSES) $(BUILD_ARCHES))
246 $(error kBuild: The BUILD_TARGET_CPU value was found in the OS or architecture keywords!)
247 endif
248 ifeq ($(BUILD_TARGET_CPU),$(BUILD_TYPE))
249 $(error kBuild: The BUILD_TARGET_CPU value '$(BUILD_TARGET_CPU)' is the same as the BUILD_TYPE!)
250 endif
251endif
252
253
254#
255# Paths and stuff.
256#
257
258# Adjust DEPTH first.
259DEPTH := $(strip $(DEPTH))
260ifeq ($(DEPTH),)
261 DEPTH := .
262endif
263
264## PATH_CURRENT is the current directory (getcwd).
265PATH_CURRENT := $(abspath $(CURDIR))
266## PATH_SUB_CURRENT points to current directory of the current makefile.
267# Meaning that it will change value as we enter and exit sub-makefiles.
268PATH_SUB_CURRENT := $(PATH_CURRENT)
269## PATH_ROOT points to the project root directory.
270PATH_ROOT := $(abspath $(PATH_CURRENT)/$(DEPTH))
271## PATH_SUB_ROOT points to the directory of the top-level makefile.
272ifneq ($(strip $(SUB_DEPTH)),)
273 SUB_DEPTH := $(strip $(SUB_DEPTH))
274 PATH_SUB_ROOT := $(abspath $(PATH_CURRENT)/$(SUB_DEPTH))
275else
276 PATH_SUB_ROOT := $(PATH_CURRENT)
277endif
278
279## CURSUBDIR is PATH_SUB_ROOT described relative to PATH_ROOT.
280# This variable is used to determin where the object files and other output goes.
281ifneq ($(PATH_ROOT),$(PATH_SUB_ROOT))
282 CURSUBDIR := $(patsubst $(PATH_ROOT)/%,%,$(PATH_SUB_ROOT))
283else
284 CURSUBDIR := .
285endif
286
287# Output directories.
288ifndef PATH_OUT_BASE
289 PATH_OUT_BASE := $(PATH_ROOT)/out
290endif
291ifndef PATH_OUT
292 ifdef BUILD_TARGET_SUB # (BUILD_TARGET_SUB is not currently recognized by kBuild in any other places.)
293 PATH_OUT := $(PATH_OUT_BASE)/$(BUILD_TARGET).$(BUILD_TARGET_ARCH).$(BUILD_TARGET_SUB)/$(BUILD_TYPE)
294 else
295 PATH_OUT := $(PATH_OUT_BASE)/$(BUILD_TARGET).$(BUILD_TARGET_ARCH)/$(BUILD_TYPE)
296 endif
297endif # !define PATH_OUT
298PATH_OBJCACHE = $(PATH_OUT_BASE)/kObjCache
299PATH_OBJ = $(PATH_OUT)/obj
300PATH_TARGET = $(PATH_OBJ)/$(CURSUBDIR)
301PATH_INS = $(PATH_OUT)
302PATH_BIN = $(PATH_INS)/bin
303PATH_DLL = $(PATH_INS)/bin
304PATH_SYS = $(PATH_INS)/bin
305PATH_LIB = $(PATH_INS)/lib
306PATH_DOC = $(PATH_INS)/doc
307
308# PATH_KBUILD is determined by kmk.
309ifeq ($(strip $(PATH_KBUILD)),)
310 $(error kBuild: PATH_KBUILD is missing or empty! kmk is supposed to set it.)
311endif
312# PATH_KBUILD_BIN is determined by kmk.
313ifeq ($(strip $(PATH_KBUILD_BIN)),)
314 $(error kBuild: PATH_KBUILD_BIN is missing or empty! kmk is supposed to set it.)
315endif
316
317# kBuild files which might be of interest.
318FILE_KBUILD_HEADER := $(PATH_KBUILD)/header.kmk
319#FILE_KBUILD_CONFIG := $(PATH_KBUILD)/config.kmk
320FILE_KBUILD_FOOTER := $(PATH_KBUILD)/footer.kmk
321
322## MAKEFILE is the name of the main makefile.
323MAKEFILE := $(firstword $(MAKEFILE_LIST))
324## MAKEFILE_CURRENT is the name of the current makefile.
325# This is updated everything a sub-makefile is included.
326MAKEFILE_CURRENT := $(MAKEFILE)
327
328
329#
330# Build platform setup.
331# (PORTME)
332#
333
334# OS/2
335ifeq ($(BUILD_PLATFORM),os2)
336EXEC_X86_WIN32 := innopec.exe
337HOSTSUFF_EXE := .exe
338endif
339
340# Linux
341ifeq ($(BUILD_PLATFORM),linux)
342EXEC_X86_WIN32 := wine
343HOSTSUFF_EXE :=
344endif
345
346# Win, Win32, Win64, NT.
347if1of ($(BUILD_PLATFORM), win nt)
348EXEC_X86_WIN32 :=
349HOSTSUFF_EXE := .exe
350endif
351
352# FreeBSD
353ifeq ($(BUILD_PLATFORM),freebsd)
354EXEC_X86_WIN32 := wine
355HOSTSUFF_EXE :=
356endif
357
358# Darwin / Mac OS X
359ifeq ($(BUILD_PLATFORM),darwin)
360EXEC_X86_WIN32 := false
361HOSTSUFF_EXE :=
362endif
363
364# Solaris
365ifeq ($(BUILD_PLATFORM),solaris)
366EXEC_X86_WIN32 := false
367HOSTSUFF_EXE :=
368endif
369
370
371#
372# Build target setup.
373# (PORTME)
374#
375SUFF_DEP := .dep
376if1of ($(BUILD_TARGET), win nt os2)
377SUFF_OBJ := .obj
378SUFF_LIB := .lib
379SUFF_DLL := .dll
380SUFF_EXE := .exe
381SUFF_SYS := .sys
382SUFF_RES := .res
383else ifeq ($(BUILD_TARGET),l4)
384SUFF_OBJ := .o
385SUFF_LIB := .a
386SUFF_DLL := .s.so
387SUFF_EXE :=
388SUFF_SYS := .a
389SUFF_RES :=
390else ifeq ($(BUILD_TARGET),darwin)
391SUFF_OBJ := .o
392SUFF_LIB := .a
393SUFF_DLL := .dylib
394SUFF_EXE :=
395SUFF_SYS :=
396SUFF_RES :=
397else
398SUFF_OBJ := .o
399SUFF_LIB := .a
400SUFF_DLL := .so
401SUFF_EXE :=
402 if1of ($(BUILD_TARGET), freebsd linux netbsd openbsd) ## @todo check netbsd and openbsd.
403SUFF_SYS := .ko
404 else
405SUFF_SYS :=
406 endif
407SUFF_RES :=
408endif
409
410#
411# Standard kBuild tools.
412#
413ifeq ($(KMK),kmk)
414KMK := $(PATH_KBUILD_BIN)/kmk$(HOSTSUFF_EXE)
415endif
416MAKE := $(KMK)
417
418GMAKE := $(PATH_KBUILD_BIN)/kmk_gmake$(HOSTSUFF_EXE)
419
420DEP_EXT := $(PATH_KBUILD_BIN)/kDep$(HOSTSUFF_EXE)
421if1of (kDep, $(KMK_BUILTIN))
422DEP := kmk_builtin_kDep
423else
424DEP := $(DEP_EXT)
425endif
426
427DEP_IDB_EXT := $(PATH_KBUILD_BIN)/kDepIDB$(HOSTSUFF_EXE)
428if1of (kDepIDB, $(KMK_BUILTIN))
429DEP_IDB := kmk_builtin_kDepIDB
430else
431DEP_IDB := $(DEP_IDB_EXT)
432endif
433
434DEP_PRE_EXT := $(PATH_KBUILD_BIN)/kDepPre$(HOSTSUFF_EXE)
435if1of (kDepPre, $(KMK_BUILTIN))
436DEP_PRE := kmk_builtin_kDepPre
437else
438DEP_PRE := $(DEP_PRE_EXT)
439endif
440
441KOBJCACHE_EXT := $(PATH_KBUILD_BIN)/kObjCache$(HOSTSUFF_EXE)
442if1of (kObjCache, $(KMK_BUILTIN))
443KOBJCACHE := kmk_builtin_kObjCache
444else
445KOBJCACHE := $(KOBJCACHE_EXT)
446endif
447
448APPEND_EXT := $(PATH_KBUILD_BIN)/kmk_append$(HOSTSUFF_EXE)
449APPEND := kmk_builtin_append
450
451CAT_EXT := $(PATH_KBUILD_BIN)/kmk_cat$(HOSTSUFF_EXE)
452CAT := kmk_builtin_cat
453
454CMP_EXT := $(PATH_KBUILD_BIN)/kmk_cmp$(HOSTSUFF_EXE)
455CMP := kmk_builtin_cmp
456
457CP_EXT := $(PATH_KBUILD_BIN)/kmk_cp$(HOSTSUFF_EXE)
458CP := kmk_builtin_cp
459
460ECHO_EXT := $(PATH_KBUILD_BIN)/kmk_echo$(HOSTSUFF_EXE)
461ECHO := kmk_builtin_echo
462
463INSTALL_EXT := $(PATH_KBUILD_BIN)/kmk_install$(HOSTSUFF_EXE)
464INSTALL := kmk_builtin_install
465
466LN_EXT := $(PATH_KBUILD_BIN)/kmk_ln$(HOSTSUFF_EXE)
467LN := kmk_builtin_ln
468
469MD5SUM_EXT := $(PATH_KBUILD_BIN)/kmk_md5sum$(HOSTSUFF_EXE)
470MD5SUM := kmk_builtin_md5sum
471
472MKDIR_EXT := $(PATH_KBUILD_BIN)/kmk_mkdir$(HOSTSUFF_EXE)
473MKDIR := kmk_builtin_mkdir
474
475MV_EXT := $(PATH_KBUILD_BIN)/kmk_mv$(HOSTSUFF_EXE)
476MV := kmk_builtin_mv
477
478PRINTF_EXT := $(PATH_KBUILD_BIN)/kmk_printf$(HOSTSUFF_EXE)
479PRINTF := kmk_builtin_printf
480
481REDIRECT_EXT:= $(PATH_KBUILD_BIN)/kmk_redirect$(HOSTSUFF_EXE)
482if1of (redirect, $(KMK_BUILTIN))
483REDIRECT := kmk_builtin_redirect
484else
485REDIRECT := $(REDIRECT_EXT)
486endif
487
488RM_EXT := $(PATH_KBUILD_BIN)/kmk_rm$(HOSTSUFF_EXE)
489RM := kmk_builtin_rm
490
491RMDIR_EXT := $(PATH_KBUILD_BIN)/kmk_rmdir$(HOSTSUFF_EXE)
492RMDIR := kmk_builtin_rmdir
493
494SED_EXT := $(PATH_KBUILD_BIN)/kmk_sed$(HOSTSUFF_EXE)
495if1of (sed, $(KMK_BUILTIN))
496SED_INT := kmk_builtin_sed
497else
498SED_INT := $(SED_EXT)
499endif
500SED := $(SED_EXT)
501
502TEST_EXT := $(PATH_KBUILD_BIN)/kmk_test$(HOSTSUFF_EXE)
503TEST := kmk_builtin_test
504
505# Our default shell is the Almquist shell from *BSD.
506ASH := $(PATH_KBUILD_BIN)/kmk_ash$(HOSTSUFF_EXE)
507MAKESHELL := $(ASH)
508SHELL := $(ASH)
509export SHELL MAKESHELL
510
511# Symlinking is problematic on some platforms...
512LN_SYMLINK := $(LN) -s
513
514
515#
516# Some Functions.
517# The lower cased ones are either fallbacks or candidates for functions.c.
518#
519
520## ABSPATH - make paths absolute.
521# This implementation is clumsy and doesn't resolve '..' and '.' components.
522#
523# @param $1 The paths to make absolute.
524# @obsolete Use the GNU make function $(abspath) directly now.
525ABSPATH = $(abspath $(1))$(warning ABSPATH is deprecated, use abspath directly!)
526
527## DIRDEP - make create directory dependencies.
528#
529# @param $1 The paths to the directories which must be created.
530DIRDEP = $(foreach path,$(patsubst %/,%,$(1)),$(path)/)
531
532## Cygwin kludge.
533# This converts /cygdrive/x/% to x:%.
534#
535# @param $1 The paths to make native.
536# @remark This macro is pretty much obsolete since we don't use cygwin base make.
537ifneq ($(patsubst /cygdrive/%,%,$(CURDIR)),$(CURDIR))
538 CYGPATHMIXED = $(foreach path,$(1)\
539 ,$(if $(patsubst /cygdrive/%,,$(path)),$(path),$(patsubst $(strip $(firstword $(subst /, ,$(patsubst /cygdrive/%,%,$(path)))))/%,$(strip $(firstword $(subst /, ,$(patsubst /cygdrive/%,%,$(path))))):/%,$(patsubst /cygdrive/%,%,$(path)))))
540else
541 CYGPATHMIXED = $(1)
542endif
543
544## Removes the drive letter from a path (if it has one)
545# @param $1 the path
546no-drive = $(word $(words $(subst :, ,$(1))),$(subst :, ,$(1)))
547
548## Removes the root slash from a path (if it has one)
549# @param $1 the path
550no-root-slash = $(patsubst /%,%,$(1))
551
552## Figure out where to put object files.
553# @param $1 real target name.
554# @param $2 normalized main target
555TARGET_BASE = $(PATH_TARGET)/$(2)/$(call no-root-slash,$(call no-drive,$(1)))
556
557## Figure out where to put object files.
558# @param $1 normalized main target
559TARGET_PATH = $(PATH_TARGET)/$(1)
560
561
562#
563# Initialize some of the globals which the Config.kmk and
564# others can add stuff to if they like for processing in the footer.
565#
566
567## KBUILD_TEMPLATE_PATHS
568# List a paths (separated by space) where templates can be found.
569KBUILD_TEMPLATE_PATHS :=
570
571## KBUILD_TOOL_PATHS
572# List of paths (separated by space) where tools can be found.
573KBUILD_TOOL_PATHS :=
574
575## KBUILD_SDK_PATHS
576# List of paths (separated by space) where SDKs can be found.
577KBUILD_SDK_PATHS :=
578
579## KBUILD_DEFAULT_PATHS
580# List of paths (separated by space) to search for stuff as a last resort.
581KBUILD_DEFAULT_PATHS :=
582
583## Proritized list of the default makefile when walking subdirectories.
584# The user can overload this list.
585DEFAULT_MAKEFILE := Makefile.kmk makefile.kmk Makefile makefile
586
587## KBUILD_SRC_HANDLERS
588# The list of source handlers, pair of extension and handler.
589# The user can overload this list to provide additional or custom
590# handlers. On a per-target/template see SRC_HANDLERS.
591KBUILD_SRC_HANDLERS := \
592 .c:def_src_handler_c \
593 .C:def_src_handler_c \
594.cxx:def_src_handler_cxx \
595.CXX:def_src_handler_cxx \
596.cpp:def_src_handler_cxx \
597.CPP:def_src_handler_cxx \
598 .cc:def_src_handler_cxx \
599 .CC:def_src_handler_cxx \
600 .m:def_src_handler_objc \
601.asm:def_src_handler_asm \
602.ASM:def_src_handler_asm \
603 .s:def_src_handler_asm \
604 .S:def_src_handler_asm \
605 .rc:def_src_handler_rc \
606.obj:def_src_handler_obj \
607 .o:def_src_handler_obj \
608.res:def_src_handler_obj
609
610## PROPS_TOOLS
611# This is a subset of PROPS_SINGLE.
612PROPS_TOOLS := TOOL CTOOL CXXTOOL OBJCTOOL ASTOOL RCTOOL ARTOOL LDTOOL FETCHTOOL UNPACKTOOL PATCHTOOL
613
614## PROPS_SINGLE
615# The list of non-accumulative target properties.
616# A Config.kmk file can add it's own properties to this list and kBuild
617# will do the necessary inheritance for templates, sdks, tools and targets.
618PROPS_SINGLE := $(PROPS_TOOLS) TEMPLATE INST NOINST BLD_TYPE BLD_TRG BLD_TRG_ARCH BLD_TRG_CPU FETCHDIR \
619 OBJSUFF COBJSUFF CXXOBJSUFF OBJCOBJSUFF ASOBJSUFF RCOBJSUFF SYSSUFF EXESUFF DLLSUFF LIBSUFF ARLIBSUFF
620## PROPS_SINGLE_LNK
621# Subset of PROPS_SINGLE which applies to all linkable targets.
622PROPS_SINGLE_LNK := TOOL TEMPLATE CTOOL CXXTOOL OBJCTOOL ASTOOL RCTOOL \
623 INST NOINST BLD_TYPE BLD_TRG BLD_TRG_ARCH BLD_TRG_CPU \
624 OBJSUFF COBJSUFF CXXOBJSUFF OBJCOBJSUFF ASOBJSUFF RCOBJSUFF
625
626## PROPS_DEFERRED
627# This list of non-accumulative target properties which are or may be
628# functions, and thus should not be expanded until the very last moment.
629PROPS_DEFERRED := INSTFUN INSTALLER PRE_CMDS POST_CMDS NAME SONAME
630
631## PROPS_ACCUMULATE_R
632# The list of accumulative target properties where the right most value/flag
633# is the 'most significant'.
634# A Config.kmk file can add it's own properties to this list and kBuild
635# will do the necessary inheritance from templates to targets.
636PROPS_ACCUMULATE_R := \
637 DEPS ORDERDEPS DEFS \
638 ARFLAGS \
639 CFLAGS CDEFS \
640 CXXFLAGS CXXDEFS \
641 OBJCFLAGS OBJCDEFS \
642 ASFLAGS ASDEFS \
643 RCFLAGS RCDEFS \
644 LDFLAGS \
645 IDFLAGS IFDLAGS ISFLAGS \
646 FETCHFLAGS UNPACKFLAGS PATCHFLAGS
647## PROPS_ACCUMULATE_R_LNK
648# Subset of PROPS_ACCUMULATE_R which applies to all linkable targets.
649PROPS_ACCUMULATE_R_LNK := \
650 DEPS ORDERDEPS DEFS \
651 CFLAGS CDEFS \
652 CXXFLAGS CXXDEFS \
653 OBJCFLAGS OBJCDEFS \
654 ASFLAGS ASDEFS \
655 RCFLAGS RCDEFS \
656 IDFLAGS IFDLAGS ISFLAGS
657
658## PROPS_ACCUMULATE
659# The list of accumulative target properties where the left most value/flag
660# is the 'most significant'.
661# A Config.kmk file can add it's own properties to this list and kBuild
662# will do the necessary inheritance from templates to targets.
663PROPS_ACCUMULATE_L := \
664 SDKS SOURCES SRC_HANDLERS INTERMEDIATES \
665 INCS CINCS CXXINCS OBJCINCS ASINCS RCINCS \
666 LIBS LIBPATH \
667 DIRS BLDDIRS CLEAN
668## PROPS_ACCUMULATE_L_LNK
669# Subset of PROPS_ACCUMULATE_L which applies to all linkable targets.
670PROPS_ACCUMULATE_L_LNK := \
671 SDKS SOURCES SRC_HANDLERS \
672 INCS CINCS CXXINCS OBJCINCS ASINCS RCINCS \
673 BLDDIRS CLEAN
674
675## PROPS_ALL
676# List of all the properties.
677PROPS_ALL = $(PROPS_SINGLE) $(PROPS_DEFERRED) $(PROPS_ACCUMULATE_L) $(PROPS_ACCUMULATE_R)
678
679
680## @name Properties valid on programs (BLDPROGS and PROGRAMS)
681## @{
682PROPS_PROGRAMS_SINGLE := $(PROPS_SINGLE_LNK) LDTOOL EXESUFF
683PROPS_PROGRAMS_DEFERRED := $(PROPS_DEFERRED)
684PROPS_PROGRAMS_ACCUMULATE_R := $(PROPS_ACCUMULATE_R_LNK) LDFLAGS
685PROPS_PROGRAMS_ACCUMULATE_L := $(PROPS_ACCUMULATE_L_LNK) LIBS LIBPATH
686## @}
687
688## @name Properties valid on libraries (LIBRARIES and IMPORT_LIBS)
689## @{
690PROPS_LIBRARIES_SINGLE := $(PROPS_SINGLE_LNK) ARTOOL LIBSUFF ARLIBSUFF LIBSUFF
691PROPS_LIBRARIES_DEFERRED := $(filter-out SONAME,$(PROPS_DEFERRED))
692PROPS_LIBRARIES_ACCUMULATE_R := $(PROPS_ACCUMULATE_R_LNK) ARFLAGS
693PROPS_LIBRARIES_ACCUMULATE_L := $(PROPS_ACCUMULATE_L_LNK)
694## @}
695
696## @name Properties valid on dlls (DLLS)
697## @{
698PROPS_DLLS_SINGLE := $(PROPS_SINGLE_LNK) LDTOOL DLLSUFF LIBSUFF
699PROPS_DLLS_DEFERRED := $(PROPS_DEFERRED)
700PROPS_DLLS_ACCUMULATE_R := $(PROPS_ACCUMULATE_R_LNK) LDFLAGS
701PROPS_DLLS_ACCUMULATE_L := $(PROPS_ACCUMULATE_L_LNK) LIBS LIBPATH
702## @}
703
704## @name Properties valid on system modules (SYSMODS)
705## @{
706PROPS_SYSMODS_SINGLE := $(PROPS_SINGLE_LNK) LDTOOL SYSSUFF
707PROPS_SYSMODS_DEFERRED := $(PROPS_DEFERRED)
708PROPS_SYSMODS_ACCUMULATE_R := $(PROPS_ACCUMULATE_R_LNK) LDFLAGS
709PROPS_SYSMODS_ACCUMULATE_L := $(PROPS_ACCUMULATE_L_LNK) LIBS LIBPATH
710## @}
711
712## @name Properties valid on installs (INSTALLS)
713## @{
714PROPS_INSTALLS_SINGLE := TOOL TEMPLATE INST NOINST
715PROPS_INSTALLS_DEFERRED := INSTFUN INSTALLER
716PROPS_INSTALLS_ACCUMULATE_R := DEPS ORDERDEPS
717PROPS_INSTALLS_ACCUMULATE_L := SOURCES DIRS CLEAN
718## @}
719
720## @name Properties valid on fetches (INSTALLS)
721## @{
722PROPS_FETCHES_SINGLE := TOOL TEMPLATE FETCHTOOL UNPACKTOOL PATCHTOOL INST FETCHDIR
723PROPS_FETCHES_DEFERRED :=
724PROPS_FETCHES_ACCUMULATE_R := FETCHFLAGS UNPACKFLAGS PATCHFLAGS
725PROPS_FETCHES_ACCUMULATE_L := SOURCES
726## @}
727
728
729#
730# Here is a special 'hack' to prevent innocent environment variables being
731# picked up and treated as properties. (The most annoying example of why
732# this is necessary is the Visual C++ commandline with it's LIBPATH.)
733#
734# Define KBUILD_DONT_KILL_ENV_PROPS in the env. or on the commandline to
735# disable this 'hack'.
736#
737ifndef KBUILD_DONT_KILL_ENV_PROPS
738
739define def_nuke_environment_prop
740ifeq ($(origin $(prop)),environment)
741$(prop) =
742endif
743endef
744$(foreach prop, $(PROPS_ALL) \
745 FETCHES PATCHES BLDPROGS LIBRARIES IMPORT_LIBS DLLS PROGRAMS SYSMODS INSTALLS OTHERS \
746 SUBDIRS MAKEFILES BLDDIRS \
747 ,$(eval $(value def_nuke_environment_prop)))
748
749endif # KBUILD_DONT_KILL_ENV_PROPS
750
751
752#
753# Pass configuration.
754#
755# The PASS_<passname>_trgs variable is listing the targets.
756# The PASS_<passname>_vars variable is listing the target variables.
757# The PASS_<passname>_pass variable is the lowercased passname.
758#
759
760## PASS: fetches
761# This pass fetches and unpacks things needed to complete the build.
762PASS_FETCHES := Fetches
763PASS_FETCHES_trgs :=
764PASS_FETCHES_vars := _FETCHES
765PASS_FETCHES_pass := fetches
766
767## PASS: patches
768# This pass applies patches.
769PASS_PATCHES := Patches
770PASS_PATCHES_trgs :=
771PASS_PATCHES_vars := _PATCHES
772PASS_PATCHES_pass := patches
773
774## PASS: bldprogs
775# This pass builds targets which are required for building the rest.
776PASS_BLDPROGS := Build Programs
777PASS_BLDPROGS_trgs :=
778PASS_BLDPROGS_vars := _BLDPROGS
779PASS_BLDPROGS_pass := bldprogs
780
781## PASS: libraries
782# This pass builds library targets.
783PASS_LIBRARIES := Libraries
784PASS_LIBRARIES_trgs :=
785PASS_LIBRARIES_vars := _LIBS _IMPORT_LIBS _OTHER_LIBRARIES
786PASS_LIBRARIES_pass := libraries
787
788## PASS: binaries
789# This pass builds dll targets.
790PASS_DLLS := DLLs
791PASS_DLLS_trgs :=
792PASS_DLLS_vars := _DLLS _OTHER_DLLS
793PASS_DLLS_pass := dlls
794
795## PASS: binaries
796# This pass builds binary targets, i.e. programs, system modules and stuff.
797PASS_BINARIES := Programs
798PASS_BINARIES_trgs :=
799PASS_BINARIES_vars := _PROGRAMS _SYSMODS _OTHER_BINARIES
800PASS_BINARIES_pass := binaries
801
802## PASS: others
803# This pass builds other targets.
804PASS_OTHERS := Other Stuff
805PASS_OTHERS_trgs :=
806PASS_OTHERS_vars := _OTHERS
807PASS_OTHERS_pass := others
808
809## PASS: install
810# This pass installs the built entities to a sandbox area.
811PASS_INSTALLS := Install
812PASS_INSTALLS_trgs :=
813PASS_INSTALLS_vars := _INSTALLS_DIRS _INSTALLS _INSTALLS_FILES
814PASS_INSTALLS_pass := installs
815
816## PASS: packing
817# This pass processes custom packing rules.
818PASS_PACKING := Packing
819PASS_PACKING_trgs :=
820PASS_PACKING_vars := _PACKING
821PASS_PACKING_pass := packing
822#alias
823packing: pass_packing
824
825## PASS: clean
826# This pass removes all generated files.
827PASS_CLEAN := Clean
828PASS_CLEAN_trgs := do-clean
829PASS_CLEAN_vars :=
830PASS_CLEAN_pass := clean
831# alias
832clean: pass_clean
833
834## PASS: nothing
835# This pass just walks the tree.
836PASS_NOTHING := Nothing
837PASS_NOTHING_trgs := do-nothing
838PASS_NOTHING_vars :=
839PASS_NOTHING_pass := nothing
840# alias
841nothing: pass_nothing
842
843## DEFAULT_PASSES
844# The default passes and their order.
845DEFAULT_PASSES := BLDPROGS LIBRARIES DLLS BINARIES OTHERS INSTALLS
846
847## PASSES
848# The passes that should be defined. This must include
849# all passes mentioned by DEFAULT_PASSES.
850PASSES := FETCHES PATCHES $(DEFAULT_PASSES) NOTHING CLEAN
851
852
853#
854# Check for --pretty-command-printing before including the Config.kmk
855# so that anyone overriding the message macros can take the implied
856# verbosity level change into account.
857#
858ifndef KBUILD_VERBOSE
859 ifndef KBUILD_QUIET
860 ifneq ($(filter --pretty-command-printing,$(MAKEFLAGS)),)
861 export KBUILD_VERBOSE := 2
862 endif
863 endif
864endif
865
866
867#
868# Legacy variable translation.
869# These will be eliminated when switching to the next version.
870#
871ifdef USE_KOBJCACHE
872 ifndef KBUILD_USE_KOBJCACHE
873 export KBUILD_USE_KOBJCACHE := $(USE_KOBJCACHE)
874 endif
875endif
876
877
878#
879# This is how we find the closest config.kmk.
880# It's a little hacky but I think it works fine.
881#
882_CFGDIR := .
883_CFGFILES := ./Config.kmk ./config.kmk
884define def_include_config
885$(eval _CFGDIR := $(_CFGDIR)/$(dir))
886_CFGFILES += $(_CFGDIR)/Config.kmk $(_CFGDIR)/config.kmk
887endef
888# walk down the _RELATIVE_ path specified by DEPTH.
889$(foreach dir,$(subst /, ,$(DEPTH)), $(eval $(def_include_config)) )
890# add the default config file.
891_CFGFILE := $(firstword $(wildcard $(_CFGFILES) $(FILE_KBUILD_CONFIG)))
892_CFGFILES :=
893_CFGDIR :=
894ifeq ($(_CFGFILE),)
895$(error kBuild: no Config.kmk file found! Check the DEPTH: DEPTH='$(DEPTH)' PATH_CURRENT='$(PATH_CURRENT)')
896endif
897
898# Include the config.kmk we found file (or the default one).
899ifdef KBUILD_PROFILE_SELF
900 _KBUILD_TS_NOW := $(nanots )
901 $(info prof: $(int-sub $(_KBUILD_TS_NOW), $(_KBUILD_TS_HEADER_START)) - $(int-sub $(_KBUILD_TS_NOW), $(_KBUILD_TS_PREV)) - including $(_CFGFILE))
902 $(info stat: $(make-stats ))
903 _KBUILD_TS_PREV := $(_KBUILD_TS_NOW)
904
905 include $(_CFGFILE)
906
907 _KBUILD_TS_NOW := $(nanots )
908 $(info prof: $(int-sub $(_KBUILD_TS_NOW), $(_KBUILD_TS_HEADER_START)) - $(int-sub $(_KBUILD_TS_NOW), $(_KBUILD_TS_PREV)) - included $(_CFGFILE))
909 $(info stat: $(make-stats ))
910 _KBUILD_TS_PREV := $(_KBUILD_TS_NOW)
911else
912 include $(_CFGFILE)
913endif
914
915
916
917#
918# Finalize a the central path variables now that we've included the Config.kmk file.
919#
920# This prevents some trouble when users override the defaults for these
921# variables and uses relative paths or paths with incorrect case.
922#
923PATH_OUT := $(abspath $(PATH_OUT))
924PATH_OBJ := $(abspath $(PATH_OBJ))
925PATH_TARGET := $(abspath $(PATH_TARGET))
926PATH_INS := $(abspath $(PATH_INS))
927PATH_BIN := $(abspath $(PATH_BIN))
928PATH_DLL := $(abspath $(PATH_DLL))
929PATH_SYS := $(abspath $(PATH_SYS))
930PATH_LIB := $(abspath $(PATH_LIB))
931PATH_DOC := $(abspath $(PATH_DOC))
932
933
934#
935# Setup the message style. The default one is inlined.
936#
937# See kBuild/msgstyles for more styles or use KBUILD_MSG_STYLE_PATHS
938# to create your own message style.
939#
940KBUILD_MSG_STYLE ?= default
941ifeq ($(KBUILD_MSG_STYLE),default)
942 #
943 # The 'default' style.
944 #
945
946 ## Fetch starting.
947 # @param 1 Target name.
948 MSG_FETCH ?= $(call MSG_L1,Fetching $1...)
949 ## Re-fetch starting.
950 # @param 1 Target name.
951 MSG_REFETCH ?= $(call MSG_L1,Re-fetching $1...)
952 ## Downloading a fetch component.
953 # @param 1 Target name.
954 # @param 2 The source URL.
955 # @param 3 The destination file name.
956 MSG_FETCH_DL ?= $(call MSG_L1,Downloading $1 - $2,=> $3)
957 ## Checking a fetch component.
958 # @param 1 Target name.
959 # @param 2 The source URL.
960 # @param 3 The destination file name.
961 MSG_FETCH_CHK?= $(call MSG_L1,Checking $1 - $3, ($2))
962 ## Unpacking a fetch component.
963 # @param 1 Target name.
964 # @param 2 The archive file name.
965 # @param 3 The target directory.
966 MSG_FETCH_UP ?= $(call MSG_L1,Unpacking $1 - $2 => $3)
967 ## Fetch completed.
968 # @param 1 Target name.
969 MSG_FETCH_OK ?= $(call MSG_L1,Successfully fetched $1)
970 ## Unfetch a fetch target.
971 # @param 1 Target name.
972 MSG_UNFETCH ?= $(call MSG_L1,Unfetching $1...)
973 ## Compiling a source file.
974 # @param 1 Target name.
975 # @param 2 The source filename.
976 # @param 3 The primary link output file name.
977 # @param 4 The source type (C,CXX,OBJC,AS,RC,++).
978 MSG_COMPILE ?= $(call MSG_L1,Compiling $1 - $2,=> $3)
979 ## Tool
980 # @param 1 The tool name (bin2c,...)
981 # @param 2 Target name.
982 # @param 3 The source filename.
983 # @param 4 The primary output file name.
984 MSG_TOOL ?= $(call MSG_L1,$1 $2 - $3,=> $4)
985 ## Generate a file, typically a source file.
986 # @param 1 Target name if applicable.
987 # @param 2 Output file name.
988 # @param 3 What it's generated from
989 MSG_GENERATE ?= $(call MSG_L1,Generating $(if $1,$1 - )$2,$(if $3,from $3))
990 ## Linking a bldprog/dll/program/sysmod target.
991 # @param 1 Target name.
992 # @param 2 The primary link output file name.
993 # @param 3 The link tool operation (LINK_LIBRARY,LINK_PROGRAM,LINK_DLL,LINK_SYSMOD,++).
994 MSG_LINK ?= $(call MSG_L1,Linking $1,=> $2)
995 ## Merging a library into the target (during library linking).
996 # @param 1 Target name.
997 # @param 2 The output library name.
998 # @param 3 The input library name.
999 MSG_AR_MERGE ?= $(call MSG_L1,Merging $3 into $1, ($2))
1000 ## Creating a directory (build).
1001 # @param 1 Directory name.
1002 MSG_MKDIR ?= $(call MSG_L2,Creating directory $1)
1003 ## Cleaning.
1004 MSG_CLEAN ?= $(call MSG_L1,Cleaning...)
1005 ## Nothing.
1006 MSG_NOTHING ?= $(call MSG_L1,Did nothing in $(CURDIR))
1007 ## Pass
1008 # @param 1 The pass name.
1009 MSG_PASS ?= $(call MSG_L1,Pass - $1)
1010 ## Installing a bldprog/lib/dll/program/sysmod target.
1011 # @param 1 Target name.
1012 # @param 2 The source filename.
1013 # @param 3 The destination file name.
1014 MSG_INST_TRG ?= $(call MSG_L1,Installing $1 => $3)
1015 ## Installing a file (install target).
1016 # @param 1 The source filename.
1017 # @param 2 The destination filename.
1018 MSG_INST_FILE?= $(call MSG_L1,Installing $2,(<= $1))
1019 ## Installing a symlink.
1020 # @param 1 Symlink
1021 # @param 2 Link target
1022 MSG_INST_SYM ?= $(call MSG_L1,Installing symlink $1,=> $2)
1023 ## Installing a directory.
1024 # @param 1 Directory name.
1025 MSG_INST_DIR ?= $(call MSG_L1,Installing directory $1)
1026
1027else
1028 _KBUILD_MSG_STYLE_FILE := $(firstword $(foreach path, $(KBUILD_MSG_STYLE_PATHS) $(PATH_KBUILD)/msgstyles, $(wildcard $(path)/$(KBUILD_MSG_STYLE).kmk)))
1029 ifneq ($(_KBUILD_MSG_STYLE_FILE),)
1030 include $(_KBUILD_MSG_STYLE_FILE)
1031 else
1032 $(error kBuild: Can't find the style setup file for KBUILD_MSG_STYLE '$(KBUILD_MSG_STYLE)')
1033 endif
1034endif
1035
1036
1037#
1038# Message macros.
1039#
1040# This is done after including Config.kmk as to allow for
1041# KBUILD_QUIET and KBUILD_VERBOSE to be configurable.
1042#
1043ifdef KBUILD_QUIET
1044 # No output
1045 QUIET := @
1046 QUIET2:= @
1047 MSG_L1 =
1048 MSG_L2 =
1049else
1050 ifndef KBUILD_VERBOSE
1051 # Default output level.
1052 QUIET := @
1053 QUIET2 := @
1054 MSG_L1 ?= @$(ECHO) "kBuild: $1"
1055 MSG_L2 =
1056 else ifeq ($(KBUILD_VERBOSE),1)
1057 # A bit more output
1058 QUIET := @
1059 QUIET2 := @
1060 MSG_L1 ?= @$(ECHO) "kBuild: $1 $2"
1061 MSG_L2 =
1062 else ifeq ($(KBUILD_VERBOSE),2)
1063 # Lot more output
1064 QUIET :=
1065 QUIET2 := @
1066 MSG_L1 ?= @$(ECHO) "kBuild: $1 $2"
1067 MSG_L2 ?= @$(ECHO) "kBuild: $1"
1068 else
1069 # maximal output.
1070 QUIET :=
1071 QUIET2 :=
1072 MSG_L1 ?= @$(ECHO) "kBuild: $1 $2"
1073 MSG_L2 ?= @$(ECHO) "kBuild: $1"
1074 endif
1075endif
1076
1077
1078#
1079# Validate any KBUILD_BLD_TYPES additions and finally the BUILD_TYPE.
1080#
1081if1of ($(KBUILD_BLD_TYPES), $(KBUILD_OSES))
1082 $(error kBuild: found KBUILD_BLD_TYPES in KBUILD_OSES!)
1083endif
1084if1of ($(KBUILD_BLD_TYPES), $(KBUILD_ARCHES))
1085 $(error kBuild: found KBUILD_BLD_TYPES in KBUILD_ARCHES!)
1086endif
1087if1of ($(KBUILD_OSES), $(KBUILD_ARCHES))
1088 $(error kBuild: found KBUILD_OSES in KBUILD_ARCHES!)
1089endif
1090ifn1of ($(BUILD_TYPE), $(KBUILD_BLD_TYPES))
1091 $(error kBuild: BUILD_TYPE(=$(BUILD_TYPE)) is not found in KBUILD_BLD_TYPES(=$(KBUILD_BLD_TYPES))!)
1092endif
1093
1094
1095
1096ifdef KBUILD_PROFILE_SELF
1097 _KBUILD_TS_HEADER_END := $(nanots )
1098 $(info prof: $(int-sub $(_KBUILD_TS_HEADER_END), $(_KBUILD_TS_HEADER_START)) - $(int-sub $(_KBUILD_TS_HEADER_END), $(_KBUILD_TS_PREV)) - end of header.kmk)
1099 $(info stat: $(make-stats ))
1100 _KBUILD_TS_PREV := $(_KBUILD_TS_HEADER_END)
1101endif
1102
1103# end-of-file-content
1104__header_kmk__ := 1
1105endif # __header_kmk__
1106
Note: See TracBrowser for help on using the repository browser.