source: trunk/kBuild/header.kmk@ 1435

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

.lib and .res should end up in othersrc and not _OBJS_. (recent regression)

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