source: trunk/kBuild/header.kmk@ 1502

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

Mark all, all_recursive and FORCE as .PHONY (saves kmk a few stat calls).

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