source: trunk/kBuild/header.kmk@ 1283

Last change on this file since 1283 was 1272, checked in by bird, 18 years ago

redirect

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