source: trunk/kBuild/header.kmk@ 994

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

logical order. use test. Made the CPU defaults consistent.

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