source: trunk/kBuild/header.kmk@ 980

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

fixes.

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