source: trunk/kBuild/header.kmk@ 988

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

kBuild profiling.

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