source: trunk/kBuild/header.kmk@ 3031

Last change on this file since 3031 was 3031, checked in by bird, 8 years ago

header.kmk: Added KB_FN_DO_PASS0_ON_TARGET to perform pass 0 early. Pass 0 is what subfooter.kmk does.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 53.4 KB
RevLine 
[69]1# $Id: header.kmk 3031 2017-04-21 08:14:58Z bird $
2## @file
[978]3# kBuild - File included at top of a makefile.
[69]4#
[1547]5
6#
[2763]7# Copyright (c) 2004-2015 knut st. osmundsen <bird-kBuild-spam-xiv@anduin.net>
[69]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#
[1547]26# As a special exception you are granted permission to include this file, via
[1561]27# the kmk include directive, as you wish without this in itself causing the
28# resulting makefile, program or whatever to be covered by the GPL license.
[1547]29# This exception does not however invalidate any other reasons why the makefile,
30# program, whatever should not be covered the GPL.
31#
32#
[69]33
34ifndef __header_kmk__
35# start-of-file-content
[988]36ifdef KBUILD_PROFILE_SELF
37 _KBUILD_TS_HEADER_START := $(nanots ) # just a dummy warm up query
[2008]38 $(info prof: since start - since previous -- event description)
39 ifeq ($(KBUILD_PROFILE_SELF),2)
40 $(info stat: $(make-stats ))
41 endif
[988]42 _KBUILD_TS_HEADER_START := $(nanots )
43 _KBUILD_TS_PREV := $(_KBUILD_TS_HEADER_START)
[2008]44
45 _KBUILD_FMT_ELAPSED_EX = $(int-div $(int-add $(int-sub $1, $2),500000),1000000)ms
46 _KBUILD_FMT_ELAPSED = $(call _KBUILD_FMT_ELAPSED_EX,$(_KBUILD_TS_NOW),$1)
47
48define def_profile_self
49 _KBUILD_TS_NOW := $(nanots )
50 $(info prof: $(call _KBUILD_FMT_ELAPSED,$(_KBUILD_TS_HEADER_START)) - $(call _KBUILD_FMT_ELAPSED, $(_KBUILD_TS_PREV)) -- $(strip $1))
51 ifeq ($(KBUILD_PROFILE_SELF),2)
52 $(info stat: $(make-stats ))
53 endif
54 _KBUILD_TS_PREV := $(_KBUILD_TS_NOW)
55endef
56
[988]57endif
[69]58
[978]59
[69]60#
[978]61# Check make version before we do anything else.
[69]62#
[978]63ifndef KMK_VERSION
[984]64 $(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)
[978]65endif
66ifneq ($(KBUILD_VERSION_MAJOR).$(KBUILD_VERSION_MINOR),0.1)
67 ifneq ($(KBUILD_VERSION_MAJOR),0)
[1348]68 $(warning kBuild: kmk major version mismatch! Expected '0' but found '$(KBUILD_VERSION_MAJOR)'!)
[978]69 else
[1348]70 $(warning kBuild: kmk minor version mismatch! Expected '1' but found '$(KBUILD_VERSION_MINOR)'!)
[978]71 endif
[1348]72else
[2512]73 if $(KBUILD_VERSION_PATCH) < 999
74 $(error kBuild: kmk version mismatch! Expected 0.1.999 or later. Actual version is $(KBUILD_VERSION).)
[1348]75 endif
[978]76endif
[69]77
78#
[978]79# The revision in which this file was last modified.
80# This can be useful when using development versions of kBuild.
[380]81#
[978]82KMK_REVISION := $(patsubst %:,, $Rev: 3031 $ )
[414]83
[978]84
[380]85#
[978]86# Define the default goal.
[69]87#
[1561]88.PHONY: all all_recursive
[978]89all: all_recursive
[69]90
[894]91#
[978]92# The phony FORCE target.
[894]93#
[1501]94.PHONY: FORCE
[978]95FORCE:
[72]96
[978]97
[69]98#
[1782]99# Enable delete on error and second expansion of prerequisites and targets.
[894]100#
[978]101.DELETE_ON_ERROR:
102
[894]103.SECONDEXPANSION:
104
[1782]105.SECONDTARGETEXPANSION:
[894]106
[1782]107
[894]108#
[95]109# General purpose macros.
110#
[204]111
[380]112##
113# Newline character(s).
114define NL
[95]115
[380]116
117endef
118
119##
120# Tab character.
121TAB := $(subst ., ,.)
122
123##
[896]124# Newline + tab characters (for generating commands).
125NLTAB = $(NL)$(TAB)
126
127##
[380]128# Space character.
129SP := $(subst ., ,.)
130
131##
[895]132# Hash character.
133define HASH
134#
135endef
[380]136
[895]137##
138# Colon character.
139COLON := :
140
141##
142# Semicolon character.
143SEMICOLON := ;
144
145##
146# Comma character.
147COMMA := ,
148
149##
150# Dot character.
151DOT := .
152
153##
154# Dollar character.
155DOLLAR := $$
156
157##
158# Equal character.
159EQUAL := =
160
[2515]161##
162# Percent character.
163PERCENT := %
[895]164
[2520]165##
166# Single quote character.
167SQUOTE := '
[2515]168
[2520]169##
170# Double quote character.
171DQUOTE := "
172
173
[95]174#
[1403]175# The list of standard build types in kBuild.
176#
[1416]177# This list can be extended in Config.kmk and it's possible to extend
[1403]178# (inherit) another build type.
179#
[1420]180KBUILD_BLD_TYPES := release profile debug
[1403]181
182
183#
[985]184# The OSes, Architectures and CPUs that kBuild recognizes.
[978]185#
186# When kBuild is ported to a new OS or architecture a unique keyword needs
187# to be assigned to it and added here. This strictness is required because
188# this keyword namespace is shared between OSes, architectures, cpus and
[984]189# build types. (PORTME)
[978]190#
[2559]191KBUILD_OSES := darwin dos dragonfly freebsd haiku l4 linux netbsd nt openbsd os2 solaris win os-agnostic
[2813]192KBUILD_ARCHES := x86 amd64 sparc32 sparc64 s390 s390x ppc32 ppc64 mips32 mips64 ia64 hppa32 hppa64 arm alpha noarch
[2559]193KBUILD_ARCHES_64 := amd64 sparc64 s390x ppc64 mips64 ia64 hppa64 alpha
194KBUILD_ARCHES_32 := x86 sparc32 s390 ppc32 mips32 hppa32 arm
[978]195
196
197#
[2971]198# Mapping of kBuild OS + ARCH to GNU system type wildcards.
199# For use with the foreach/append/prepend and wildcard functions.
200#
201KBUILD_OSARCH_2_GNU_SYSTEM_TYPES.darwin.x86 = i?86-apple-darwin*
202KBUILD_OSARCH_2_GNU_SYSTEM_TYPES.darwin.amd64 = x86_64-apple-darwin* amd64-apple-darwin*
203KBUILD_OSARCH_2_GNU_SYSTEM_TYPES.freebsd.x86 = i?86-*freebsd*
204KBUILD_OSARCH_2_GNU_SYSTEM_TYPES.freebsd.amd64 = x86_64-*freebsd* amd64-*freebsd*
205KBUILD_OSARCH_2_GNU_SYSTEM_TYPES.linux.x86 = i?86-*linux-gnu
206KBUILD_OSARCH_2_GNU_SYSTEM_TYPES.linux.amd64 = x86_64-*linux-gnu amd64-*linux-gnu
207KBUILD_OSARCH_2_GNU_SYSTEM_TYPES.netbsd.x86 = i?86-*netbsd*
208KBUILD_OSARCH_2_GNU_SYSTEM_TYPES.netbsd.amd64 = x86_64-*netbsd* amd64-*netbsd*
209KBUILD_OSARCH_2_GNU_SYSTEM_TYPES.os2.x86 = i?86-*os2*
210KBUILD_OSARCH_2_GNU_SYSTEM_TYPES.solaris.x86 = i?86-*solaris2*
211KBUILD_OSARCH_2_GNU_SYSTEM_TYPES.solaris.amd64 = amd64-*solaris2* x86_64-*solaris2*
212KBUILD_OSARCH_2_GNU_SYSTEM_TYPES.solaris.sparc32 = sparc-*solaris2*
213KBUILD_OSARCH_2_GNU_SYSTEM_TYPES.solaris.sparc64 = sparc64-*solaris2* sparcv9-*solaris2*
214KBUILD_OSARCH_2_GNU_SYSTEM_TYPES.win.x86 = i?86-*mingw32* i?86-*msys* i?86-*cygwin*
215KBUILD_OSARCH_2_GNU_SYSTEM_TYPES.win.amd64 = x86_64-*mingw64* amd64-*mingw64* x86_64-*msys* amd64-*msys* x86_64-*cygwin* amd64-*cygwin*
216
217
218#
[585]219# Set default build type.
[69]220#
[1504]221ifndef KBUILD_TYPE
222 ifdef BUILD_TYPE
223 KBUILD_TYPE := $(BUILD_TYPE)
224 endif
225else ifdef BUILD_TYPE
226 ifneq ($(KBUILD_TYPE),$(BUILD_TYPE))
227 ifeq ($(origin KBUILD_TYPE):$(origin BUILD_TYPE),environment:command line)
228 KBUILD_TYPE := $(BUILD_TYPE)
229 else ifneq ($(origin KBUILD_TYPE):$(origin BUILD_TYPE),command line:environment)
230 $(error kBuild: KBUILD_TYPE and BUILD_TYPE disagree.)
231 endif
232 endif
233endif
234override BUILD_TYPE = $(KBUILD_TYPE)
235
236ifndef KBUILD_TYPE
237 KBUILD_TYPE := release
[978]238else
[1504]239 if1of ($(KBUILD_TYPE), $(KBUILD_OSES) $(KBUILD_ARCHES))
240 $(error kBuild: The KBUILD_TYPE value '$(KBUILD_TYPE)' is an OS or architecture!)
[585]241 endif
[1504]242 ifneq (.$(words $(KBUILD_TYPE)).$(KBUILD_TYPE).,.1.$(strip $(KBUILD_TYPE)).)
243 $(error kBuild: The KBUILD_TYPE value '$(KBUILD_TYPE)' contains spaces/tabs!)
[978]244 endif
[72]245endif
[69]246
247
248#
[1561]249# Host platform legacy
[1504]250# kmk deals with this, so this is only temporary until I've rebuilt everything.
251#
252ifndef KBUILD_HOST
253 KBUILD_HOST := $(BUILD_PLATFORM)
254endif
255ifndef KBUILD_HOST_ARCH
256 KBUILD_HOST_ARCH := $(BUILD_PLATFORM_ARCH)
257endif
258ifndef KBUILD_HOST_CPU
259 KBUILD_HOST_CPU := $(BUILD_PLATFORM_CPU)
260endif
261
262
263#
[978]264# Assert valid build platform variables.
[70]265#
[978]266# All these are set by kmk so they shouldn't be any trouble
267# unless the user starts messing about with environment variables.
268#
[1504]269ifneq (.$(words $(KBUILD_HOST)).$(KBUILD_HOST).,.1.$(strip $(KBUILD_HOST)).)
270 $(error kBuild: The KBUILD_HOST value '$(KBUILD_HOST)' contains spaces/tabs!)
[72]271endif
[1504]272ifneq ($(words $(filter $(KBUILD_HOST),$(KBUILD_OSES))),1)
273 $(error kBuild: KBUILD_HOST value '$(KBUILD_HOST)' is not recognized (valid: $(KBUILD_OSES)))
[978]274endif
[70]275
[1504]276ifneq (.$(words $(KBUILD_HOST_ARCH)).$(KBUILD_HOST_ARCH).,.1.$(strip $(KBUILD_HOST_ARCH)).)
277 $(error kBuild: The KBUILD_HOST_ARCH value '$(KBUILD_HOST_ARCH)' contains spaces/tabs!)
[329]278endif
[1504]279ifneq ($(words $(filter $(KBUILD_HOST_ARCH),$(KBUILD_ARCHES))),1)
280 $(error kBuild: KBUILD_HOST_ARCH value '$(KBUILD_HOST_ARCH)' is not recognized (valid: $(KBUILD_ARCHES)))
[329]281endif
[72]282
[1504]283ifeq ($(strip $(KBUILD_HOST_CPU)),)
284 KBUILD_HOST_CPU := blend
[994]285else
[1504]286 ifneq (.$(words $(KBUILD_HOST_CPU)).$(KBUILD_HOST_CPU).,.1.$(strip $(KBUILD_HOST_CPU)).)
287 $(error kBuild: The KBUILD_HOST_CPU value '$(KBUILD_HOST_CPU)' contains spaces/tabs!)
[994]288 endif
[2403]289 if1of ($(KBUILD_HOST_CPU), $(KBUILD_OSES) $(KBUILD_ARCHES))
[1504]290 $(error kBuild: The KBUILD_HOST_CPU value '$(KBUILD_HOST_CPU)' was found in the OS or architecture keywords!)
[994]291 endif
[1504]292 ifeq ($(KBUILD_HOST_CPU),$(KBUILD_TYPE))
293 $(error kBuild: The KBUILD_HOST_CPU value '$(KBUILD_HOST_CPU)' is the same as the KBUILD_TYPE!)
[994]294 endif
[978]295endif
[72]296
[978]297
[70]298#
[1504]299# Deal with target platform legacy.
300#
301ifndef KBUILD_TARGET
302 ifdef BUILD_TARGET
303 KBUILD_TARGET := $(BUILD_TARGET)
304 endif
305else ifdef BUILD_TARGET
306 ifneq ($(KBUILD_TARGET),$(BUILD_TARGET))
307 ifeq ($(origin KBUILD_TARGET):$(origin BUILD_TARGET),environment:command line)
308 KBUILD_TARGET := $(BUILD_TARGET)
309 else ifneq ($(origin KBUILD_TARGET):$(origin BUILD_TARGET),command line:environment)
[1561]310 $(error kBuild: KBUILD_TARGET and BUILD_TARGET disagree)
[1504]311 endif
312 endif
313endif
314override BUILD_TARGET = $(KBUILD_TARGET)
315
316ifndef KBUILD_TARGET_ARCH
317 ifdef BUILD_TARGET_ARCH
318 KBUILD_TARGET_ARCH := $(BUILD_TARGET_ARCH)
319 endif
320else ifdef BUILD_TARGET_ARCH
321 ifneq ($(KBUILD_TARGET_ARCH),$(BUILD_TARGET_ARCH))
322 ifeq ($(origin KBUILD_TARGET_ARCH):$(origin BUILD_TARGET_ARCH),environment:command line)
323 KBUILD_TARGET_ARCH := $(BUILD_TARGET_ARCH)
324 else ifneq ($(origin KBUILD_TARGET_ARCH):$(origin BUILD_TARGET_ARCH),command line:environment)
[1561]325 $(error kBuild: KBUILD_TARGET_ARCH and BUILD_TARGET_ARCH disagree)
[1504]326 endif
327 endif
328endif
329override BUILD_TARGET_ARCH = $(KBUILD_TARGET_ARCH)
330
331ifndef KBUILD_TARGET_CPU
332 ifdef BUILD_TARGET_CPU
333 KBUILD_TARGET_CPU := $(BUILD_TARGET_CPU)
334 endif
335else ifdef BUILD_TARGET_CPU
336 ifneq ($(KBUILD_TARGET_CPU),$(BUILD_TARGET_CPU))
337 ifeq ($(origin KBUILD_TARGET_CPU):$(origin BUILD_TARGET_CPU),environment:command line)
338 KBUILD_TARGET_CPU := $(BUILD_TARGET_CPU)
339 else ifneq ($(origin KBUILD_TARGET_CPU):$(origin BUILD_TARGET_CPU),command line:environment)
[1561]340 $(error kBuild: KBUILD_TARGET_CPU and BUILD_TARGET_CPU disagree)
[1504]341 endif
342 endif
343endif
344override BUILD_TARGET_CPU = $(KBUILD_TARGET_CPU)
345
346
347#
[978]348# Assert or set default target platform.
[1504]349# When not defined use the corresponding KBUILD_HOST value.
[72]350#
[1504]351ifndef KBUILD_TARGET
352 KBUILD_TARGET := $(KBUILD_HOST)
[72]353else
[1504]354 ifneq (.$(words $(KBUILD_TARGET)).$(KBUILD_TARGET).,.1.$(strip $(KBUILD_TARGET)).)
355 $(error kBuild: The KBUILD_TARGET value '$(KBUILD_TARGET)' contains spaces/tabs!)
[478]356 endif
[1504]357 ifneq ($(words $(filter $(KBUILD_TARGET),$(KBUILD_OSES))),1)
358 $(error kBuild: KBUILD_TARGET value '$(KBUILD_TARGET)' is not recognized (valid: $(KBUILD_OSES)))
[978]359 endif
[72]360endif
361
[1504]362ifndef KBUILD_TARGET_ARCH
363 KBUILD_TARGET_ARCH := $(KBUILD_HOST_ARCH)
[978]364else
[1504]365 ifneq (.$(words $(KBUILD_TARGET_ARCH)).$(KBUILD_TARGET_ARCH).,.1.$(strip $(KBUILD_TARGET_ARCH)).)
366 $(error kBuild: The KBUILD_TARGET_ARCH value '$(KBUILD_TARGET_ARCH)' contains spaces/tabs!)
[978]367 endif
[1504]368 ifneq ($(words $(filter $(KBUILD_TARGET_ARCH),$(KBUILD_ARCHES))),1)
369 $(error kBuild: KBUILD_TARGET_ARCH value '$(KBUILD_TARGET_ARCH)' is not recognized (valid: $(KBUILD_ARCHES)))
[978]370 endif
[329]371endif
[978]372
[1504]373ifndef KBUILD_TARGET_CPU
374 KBUILD_TARGET_CPU := $(KBUILD_HOST_CPU)
375else ifeq ($(strip $(KBUILD_TARGET_CPU)),)
376 ifeq ($(KBUILD_TARGET_ARCH),$(KBUILD_HOST_ARCH))
377 KBUILD_TARGET_CPU := $(KBUILD_HOST_CPU)
[994]378 else
[1504]379 KBUILD_TARGET_CPU := blend
[994]380 endif
[978]381else
[1504]382 ifneq (.$(words $(KBUILD_TARGET_CPU)).$(KBUILD_TARGET_CPU).,.1.$(strip $(KBUILD_TARGET_CPU)).)
383 $(error kBuild: The KBUILD_TARGET_CPU value '$(KBUILD_TARGET_CPU)' contains spaces/tabs!)
[978]384 endif
[2403]385 if1of ($(KBUILD_TARGET_CPU), $(KBUILD_OSES) $(KBUILD_ARCHES))
[1504]386 $(error kBuild: The KBUILD_TARGET_CPU value was found in the OS or architecture keywords!)
[978]387 endif
[1504]388 ifeq ($(KBUILD_TARGET_CPU),$(KBUILD_TYPE))
389 $(error kBuild: The KBUILD_TARGET_CPU value '$(KBUILD_TARGET_CPU)' is the same as the KBUILD_TYPE!)
[978]390 endif
[329]391endif
[72]392
[2971]393# Short hand for $(KBUILD_TARGET).$(KBUILD_TARGET_ARCH).
394KBUILD_TARGET_DOT_ARCH = $(KBUILD_TARGET).$(KBUILD_TARGET_ARCH)
395KBUILD_HOST_DOT_ARCH = $(KBUILD_HOST).$(KBUILD_TARGET_ARCH)
[72]396
[2971]397
[72]398#
[978]399# Paths and stuff.
[69]400#
[978]401
402# Adjust DEPTH first.
403DEPTH := $(strip $(DEPTH))
404ifeq ($(DEPTH),)
405 DEPTH := .
406endif
407
[725]408## PATH_CURRENT is the current directory (getcwd).
[306]409PATH_CURRENT := $(abspath $(CURDIR))
[725]410## PATH_SUB_CURRENT points to current directory of the current makefile.
411# Meaning that it will change value as we enter and exit sub-makefiles.
412PATH_SUB_CURRENT := $(PATH_CURRENT)
413## PATH_ROOT points to the project root directory.
414PATH_ROOT := $(abspath $(PATH_CURRENT)/$(DEPTH))
415## PATH_SUB_ROOT points to the directory of the top-level makefile.
[472]416ifneq ($(strip $(SUB_DEPTH)),)
[978]417 SUB_DEPTH := $(strip $(SUB_DEPTH))
[725]418 PATH_SUB_ROOT := $(abspath $(PATH_CURRENT)/$(SUB_DEPTH))
[472]419else
[725]420 PATH_SUB_ROOT := $(PATH_CURRENT)
[472]421endif
[306]422
[748]423## CURSUBDIR is PATH_SUB_ROOT described relative to PATH_ROOT.
[725]424# This variable is used to determin where the object files and other output goes.
[1390]425ifneq ($(PATH_ROOT),$(PATH_SUB_ROOT))
426 CURSUBDIR := $(patsubst $(PATH_ROOT)/%,%,$(PATH_SUB_ROOT))
[266]427else
[1390]428 CURSUBDIR := .
[266]429endif
[306]430
[2475]431# Install directory layout. Relative to PATH_INS.
[2479]432KBUILD_INST_PATHS := BIN DLL SYS LIB DOC DEBUG SBIN LIBEXEC SHARE
[2475]433INST_BIN = bin/
434if1of ($(KBUILD_TARGET), win)
435INST_DLL = bin/
436else
437INST_DLL = lib/
438endif
439if1of ($(KBUILD_TARGET), os2 win)
440INST_SYS = drivers/
441else
442INST_SYS = kernel/
443endif
444INST_LIB = lib/
445INST_DOC = share/doc/
446INST_DEBUG = debug/
447INST_SBIN = sbin/
448INST_LIBEXEC = libexec/
449INST_SHARE = share/
450
451# Staging directory layout. Relative to PATH_STAGE.
452STAGE_BIN = $(INST_BIN)
453STAGE_DLL = $(INST_DLL)
454STAGE_SYS = $(INST_SYS)
455STAGE_LIB = $(INST_LIB)
456STAGE_DOC = $(INST_DOC)
457STAGE_DEBUG = $(INST_DEBUG)
458STAGE_SBIN = $(INST_SBIN)
459STAGE_LIBEXEC = $(INST_LIBEXEC)
460STAGE_SHARE = $(INST_SHARE)
461
[2479]462# Install and staging directory paths.
463$(foreach path, $(KBUILD_INST_PATHS), \
464 $(eval PATH_STAGE_$(path) = $$(patsubst %/,%,$$(PATH_STAGE)/$$(STAGE_$(path)))) \
465 $(eval PATH_INST_$(path) = $$(patsubst %/,%,$$(PATH_INS)/$$(INST_$(path)))) \
466)
467
[70]468# Output directories.
[242]469ifndef PATH_OUT_BASE
[725]470 PATH_OUT_BASE := $(PATH_ROOT)/out
[242]471endif
[240]472ifndef PATH_OUT
[1504]473 ifdef BUILD_TARGET_SUB # (BUILD_TARGET_SUB is not currently recognized by kBuild in any other places - obsolete)
[1691]474 PATH_OUT = $(PATH_OUT_BASE)/$(KBUILD_TARGET).$(KBUILD_TARGET_ARCH).$(BUILD_TARGET_SUB)/$(KBUILD_TYPE)
[725]475 else
[1691]476 PATH_OUT = $(PATH_OUT_BASE)/$(KBUILD_TARGET).$(KBUILD_TARGET_ARCH)/$(KBUILD_TYPE)
[725]477 endif
[329]478endif # !define PATH_OUT
[1051]479PATH_OBJCACHE = $(PATH_OUT_BASE)/kObjCache
[353]480PATH_OBJ = $(PATH_OUT)/obj
481PATH_TARGET = $(PATH_OBJ)/$(CURSUBDIR)
[2475]482PATH_STAGE = $(PATH_OUT)/stage
483ifndef PATH_INS
484 ifdef DESTROOT
485PATH_INS = $(DESTROOT)
486 else
487PATH_INS = $(PATH_OUT)/dist
488 endif
489endif
[70]490
[2513]491# Tripwire obsolete PATH defines.
492PATH_BIN = $(error kBuild: PATH_BIN is obsoleted in kBuild 0.1.2. Use PATH_STAGE_BIN or PATH_INST_BIN instead)
493PATH_DLL = $(error kBuild: PATH_LIB is obsoleted in kBuild 0.1.2. Use PATH_STAGE_DLL or PATH_INST_DLL instead)
494PATH_LIB = $(error kBuild: PATH_LIB is obsoleted in kBuild 0.1.2. Use PATH_STAGE_LIB or PATH_INST_LIB instead)
495PATH_SYS = $(error kBuild: PATH_SYS is obsoleted in kBuild 0.1.2. Use PATH_STAGE_SYS or PATH_INST_SYS instead)
496PATH_DOC = $(error kBuild: PATH_DOC is obsoleted in kBuild 0.1.2. Use PATH_STAGE_DOC or PATH_INST_DOC instead)
497
[2271]498# Development tool tree.
[2729]499ifndef KBUILD_DEVTOOLS
500 ifeq ($(PATH_DEVTOOLS),)
501 KBUILD_DEVTOOLS = $(PATH_ROOT)/tools
502 else
503 KBUILD_DEVTOOLS := $(PATH_DEVTOOLS)
504 endif
505endif
[2724]506KBUILD_DEVTOOLS_TRG ?= $(KBUILD_DEVTOOLS)/$(KBUILD_TARGET).$(KBUILD_TARGET_ARCH)
507KBUILD_DEVTOOLS_HST ?= $(KBUILD_DEVTOOLS)/$(KBUILD_HOST).$(KBUILD_HOST_ARCH)
[2271]508
509if1of ($(KBUILD_TARGET_ARCH), amd64 hppa64 mips64 ppc64 s390x sparc64)
510 ifeq ($(KBUILD_TARGET_ARCH),amd64)
[2729]511 KBUILD_DEVTOOLS_TRG_ALT ?= $(KBUILD_DEVTOOLS)/$(KBUILD_TARGET).x86
[2271]512 else ifeq ($(KBUILD_TARGET_ARCH),hppa64)
[2729]513 KBUILD_DEVTOOLS_TRG_ALT ?= $(KBUILD_DEVTOOLS)/$(KBUILD_TARGET).hppa32
[2271]514 else ifeq ($(KBUILD_TARGET_ARCH),mips64)
[2729]515 KBUILD_DEVTOOLS_TRG_ALT ?= $(KBUILD_DEVTOOLS)/$(KBUILD_TARGET).mips32
[2271]516 else ifeq ($(KBUILD_TARGET_ARCH),ppc64)
[2729]517 KBUILD_DEVTOOLS_TRG_ALT ?= $(KBUILD_DEVTOOLS)/$(KBUILD_TARGET).ppc32
[2271]518 else ifeq ($(KBUILD_TARGET_ARCH),s390x)
[2729]519 KBUILD_DEVTOOLS_TRG_ALT ?= $(KBUILD_DEVTOOLS)/$(KBUILD_TARGET).s390
[2271]520 else ifeq ($(KBUILD_TARGET_ARCH),sparc64)
[2729]521 KBUILD_DEVTOOLS_TRG_ALT ?= $(KBUILD_DEVTOOLS)/$(KBUILD_TARGET).sparc32
[2271]522 endif
523endif
524
525if1of ($(KBUILD_HOST_ARCH), amd64 hppa64 mips64 ppc64 s390x sparc64)
526 ifeq ($(KBUILD_HOST_ARCH),amd64)
[2729]527 KBUILD_DEVTOOLS_HST_ALT ?= $(KBUILD_DEVTOOLS)/$(KBUILD_HOST).x86
[2271]528 else ifeq ($(KBUILD_HOST_ARCH),hppa64)
[2729]529 KBUILD_DEVTOOLS_HST_ALT ?= $(KBUILD_DEVTOOLS)/$(KBUILD_HOST).hppa32
[2271]530 else ifeq ($(KBUILD_HOST_ARCH),mips64)
[2729]531 KBUILD_DEVTOOLS_HST_ALT ?= $(KBUILD_DEVTOOLS)/$(KBUILD_HOST).mips32
[2271]532 else ifeq ($(KBUILD_HOST_ARCH),ppc64)
[2729]533 KBUILD_DEVTOOLS_HST_ALT ?= $(KBUILD_DEVTOOLS)/$(KBUILD_HOST).ppc32
[2271]534 else ifeq ($(KBUILD_HOST_ARCH),s390x)
[2729]535 KBUILD_DEVTOOLS_HST_ALT ?= $(KBUILD_DEVTOOLS)/$(KBUILD_HOST).s390
[2271]536 else ifeq ($(KBUILD_HOST_ARCH),sparc64)
[2729]537 KBUILD_DEVTOOLS_HST_ALT ?= $(KBUILD_DEVTOOLS)/$(KBUILD_HOST).sparc32
[2271]538 endif
539endif
540
[2725]541# Deprecated legacy names.
542PATH_DEVTOOLS ?= $(KBUILD_DEVTOOLS)
543PATH_DEVTOOLS_TRG ?= $(KBUILD_DEVTOOLS_TRG)
[2751]544PATH_DEVTOOLS_BLD ?= $(KBUILD_DEVTOOLS_TRG)
[2725]545PATH_DEVTOOLS_TRG_ALT ?= $(KBUILD_DEVTOOLS_TRG_ALT)
546PATH_DEVTOOLS_HST ?= $(KBUILD_DEVTOOLS_HST)
547PATH_DEVTOOLS_HST_ALT ?= $(KBUILD_DEVTOOLS_HST_ALT)
[2271]548
[1504]549# KBUILD_PATH / PATH_KBUILD is determined by kmk.
550ifndef KBUILD_PATH
551 KBUILD_PATH := $(PATH_KBUILD)
[70]552endif
[1504]553ifeq ($(strip $(KBUILD_PATH)),)
554 $(error kBuild: KBUILD_PATH is missing or empty! kmk is supposed to set it.)
[978]555endif
[1504]556# KBUILD_BIN_PATH / PATH_KBUILD_BIN is determined by kmk.
557ifndef KBUILD_BIN_PATH
558 KBUILD_BIN_PATH := $(PATH_KBUILD_BIN)
559endif
560ifeq ($(strip $(KBUILD_BIN_PATH)),)
561 $(error kBuild: KBUILD_BIN_PATH is missing or empty! kmk is supposed to set it.)
562endif
[978]563
[69]564# kBuild files which might be of interest.
[1664]565FILE_KBUILD_HEADER := $(KBUILD_PATH)/header.kmk
566#FILE_KBUILD_CONFIG := $(KBUILD_PATH)/config.kmk
567FILE_KBUILD_FOOTER := $(KBUILD_PATH)/footer.kmk
568FILE_KBUILD_SUB_HEADER := $(KBUILD_PATH)/subheader.kmk
569FILE_KBUILD_SUB_FOOTER := $(KBUILD_PATH)/subfooter.kmk
[69]570
[725]571## MAKEFILE is the name of the main makefile.
[204]572MAKEFILE := $(firstword $(MAKEFILE_LIST))
[748]573## MAKEFILE_CURRENT is the name of the current makefile.
[725]574# This is updated everything a sub-makefile is included.
575MAKEFILE_CURRENT := $(MAKEFILE)
[69]576
[72]577
[1602]578## @todo this should be done via SUFF_XYZ.target/host...
579
[69]580#
[72]581# Build platform setup.
[984]582# (PORTME)
[69]583#
[1602]584if1of ($(KBUILD_HOST), win nt)
585# Win, Win32, Win64, NT.
586EXEC_X86_WIN32 :=
587HOSTSUFF_EXE := .exe
[984]588
[1602]589# OS/2.
590else ifeq ($(KBUILD_HOST),os2)
[83]591EXEC_X86_WIN32 := innopec.exe
[69]592HOSTSUFF_EXE := .exe
593
[1602]594else if1of ($(KBUILD_HOST), freebsd dragonfly linux openbsd netbsd)
595# Unix (like) systems with wine.
[135]596EXEC_X86_WIN32 := wine
[69]597HOSTSUFF_EXE :=
[70]598
[1602]599else
600# Unix (like) systems without wine.
[557]601EXEC_X86_WIN32 := false
602HOSTSUFF_EXE :=
603endif
604
[811]605
[73]606#
607# Build target setup.
[984]608# (PORTME)
[73]609#
[1388]610SUFF_DEP := .dep
[2088]611SUFF_BIN :=
[1504]612if1of ($(KBUILD_TARGET), win nt os2)
[1388]613SUFF_OBJ := .obj
614SUFF_LIB := .lib
615SUFF_DLL := .dll
616SUFF_EXE := .exe
617SUFF_SYS := .sys
618SUFF_RES := .res
[1504]619else ifeq ($(KBUILD_TARGET),l4)
[1388]620SUFF_OBJ := .o
621SUFF_LIB := .a
622SUFF_DLL := .s.so
623SUFF_EXE :=
624SUFF_SYS := .a
625SUFF_RES :=
[1504]626else ifeq ($(KBUILD_TARGET),darwin)
[1388]627SUFF_OBJ := .o
628SUFF_LIB := .a
629SUFF_DLL := .dylib
630SUFF_EXE :=
631SUFF_SYS :=
632SUFF_RES :=
633else
634SUFF_OBJ := .o
635SUFF_LIB := .a
636SUFF_DLL := .so
637SUFF_EXE :=
[1602]638 if1of ($(KBUILD_TARGET), dragonfly freebsd linux netbsd openbsd) ## @todo check netbsd and openbsd.
[1389]639SUFF_SYS := .ko
[1388]640 else
[1389]641SUFF_SYS :=
642 endif
[1388]643SUFF_RES :=
[73]644endif
[69]645
646#
647# Standard kBuild tools.
648#
[978]649ifeq ($(KMK),kmk)
[1504]650KMK := $(KBUILD_BIN_PATH)/kmk$(HOSTSUFF_EXE)
[233]651endif
[978]652MAKE := $(KMK)
[233]653
[1504]654GMAKE := $(KBUILD_BIN_PATH)/kmk_gmake$(HOSTSUFF_EXE)
[1378]655
[2148]656#DEP_EXT := $(KBUILD_BIN_PATH)/kDep$(HOSTSUFF_EXE)
657#DEP_INT := $(KBUILD_BIN_PATH)/kDep$(HOSTSUFF_EXE)
658#DEP := $(DEP_INT)
[69]659
[1504]660DEP_IDB_EXT := $(KBUILD_BIN_PATH)/kDepIDB$(HOSTSUFF_EXE)
[2148]661DEP_IDB_INT := kmk_builtin_kDepIDB
662DEP_IDB := $(DEP_IDB_INT)
[397]663
[2895]664DEP_OBJ_EXT := $(KBUILD_BIN_PATH)/kDepObj$(HOSTSUFF_EXE)
665DEP_OBJ_INT := kmk_builtin_kDepObj
666DEP_OBJ := $(DEP_OBJ_INT)
667
[2148]668DEP_PRE := $(KBUILD_BIN_PATH)/kDepPre$(HOSTSUFF_EXE)
[380]669
[1504]670KOBJCACHE_EXT := $(KBUILD_BIN_PATH)/kObjCache$(HOSTSUFF_EXE)
[1004]671KOBJCACHE := $(KOBJCACHE_EXT)
672
[2793]673KLIBTWEAKER_EXT := $(KBUILD_BIN_PATH)/kLibTweaker$(HOSTSUFF_EXE)
[2796]674KLIBTWEAKER := $(KLIBTWEAKER_EXT)
[2793]675
[1504]676APPEND_EXT := $(KBUILD_BIN_PATH)/kmk_append$(HOSTSUFF_EXE)
[2148]677APPEND_INT := kmk_builtin_append
678APPEND := $(APPEND_INT)
[69]679
[1504]680CAT_EXT := $(KBUILD_BIN_PATH)/kmk_cat$(HOSTSUFF_EXE)
[2148]681CAT_INT := kmk_builtin_cat
682CAT := $(CAT_INT)
[353]683
[1753]684CHMOD_EXT := $(KBUILD_BIN_PATH)/kmk_chmod$(HOSTSUFF_EXE)
[2148]685CHMOD_INT := kmk_builtin_chmod
686CHMOD := $(CHMOD_INT)
[1753]687
[1504]688CMP_EXT := $(KBUILD_BIN_PATH)/kmk_cmp$(HOSTSUFF_EXE)
[2148]689CMP_INT := kmk_builtin_cmp
690CMP := $(CMP_INT)
[1118]691
[1504]692CP_EXT := $(KBUILD_BIN_PATH)/kmk_cp$(HOSTSUFF_EXE)
[2148]693CP_INT := kmk_builtin_cp
694CP := $(CP_INT)
[1119]695
[1504]696ECHO_EXT := $(KBUILD_BIN_PATH)/kmk_echo$(HOSTSUFF_EXE)
[2148]697ECHO_INT := kmk_builtin_echo
698ECHO := $(ECHO_INT)
[380]699
[1753]700EXPR_EXT := $(KBUILD_BIN_PATH)/kmk_expr$(HOSTSUFF_EXE)
[2148]701EXPR_INT := kmk_builtin_expr
702EXPR := $(EXPR_INT)
[1753]703
[1504]704INSTALL_EXT := $(KBUILD_BIN_PATH)/kmk_install$(HOSTSUFF_EXE)
[2148]705INSTALL_INT := kmk_builtin_install
706INSTALL := $(INSTALL_INT)
[380]707
[1504]708LN_EXT := $(KBUILD_BIN_PATH)/kmk_ln$(HOSTSUFF_EXE)
[2148]709LN_INT := kmk_builtin_ln
710LN := $(LN_INT)
[380]711
[1504]712MD5SUM_EXT := $(KBUILD_BIN_PATH)/kmk_md5sum$(HOSTSUFF_EXE)
[2148]713MD5SUM_INT := kmk_builtin_md5sum
714MD5SUM := $(MD5SUM_INT)
[1118]715
[1504]716MKDIR_EXT := $(KBUILD_BIN_PATH)/kmk_mkdir$(HOSTSUFF_EXE)
[2148]717MKDIR_INT := kmk_builtin_mkdir
718MKDIR := $(MKDIR_INT)
[380]719
[1504]720MV_EXT := $(KBUILD_BIN_PATH)/kmk_mv$(HOSTSUFF_EXE)
[2148]721MV_INT := kmk_builtin_mv
722MV := $(MV_INT)
[380]723
[1504]724PRINTF_EXT := $(KBUILD_BIN_PATH)/kmk_printf$(HOSTSUFF_EXE)
[2148]725PRINTF_INT := kmk_builtin_printf
726PRINTF := $(PRINTF_INT)
[776]727
[1504]728REDIRECT_EXT:= $(KBUILD_BIN_PATH)/kmk_redirect$(HOSTSUFF_EXE)
[2912]729if $(KBUILD_KMK_REVISION) > 2911
730REDIRECT_INT:= kmk_builtin_redirect
731else
[2148]732REDIRECT_INT:= $(REDIRECT_EXT)
[2912]733endif
[2148]734REDIRECT := $(REDIRECT_INT)
[1272]735
[1504]736RM_EXT := $(KBUILD_BIN_PATH)/kmk_rm$(HOSTSUFF_EXE)
[2148]737RM_INT := kmk_builtin_rm
738RM := $(RM_INT)
[380]739
[1504]740RMDIR_EXT := $(KBUILD_BIN_PATH)/kmk_rmdir$(HOSTSUFF_EXE)
[2148]741RMDIR_INT := kmk_builtin_rmdir
742RMDIR := $(RMDIR_INT)
[601]743
[1504]744SED_EXT := $(KBUILD_BIN_PATH)/kmk_sed$(HOSTSUFF_EXE)
[978]745SED_INT := $(SED_EXT)
[380]746SED := $(SED_EXT)
747
[2148]748SLEEP_INT := kmk_builtin_sleep
749SLEEP_EXT := $(KBUILD_BIN_PATH)/kmk_sleep$(HOSTSUFF_EXE)
750SLEEP := $(SLEEP_EXT)
751
[1504]752TEST_EXT := $(KBUILD_BIN_PATH)/kmk_test$(HOSTSUFF_EXE)
[2148]753TEST_INT := kmk_builtin_test
754TEST := $(TEST_INT)
[1296]755
[2148]756TIME_EXT := $(KBUILD_BIN_PATH)/kmk_time$(HOSTSUFF_EXE)
757TIME_INT := $(TIME_EXT)
758TIME := $(TIME_INT)
759
[380]760# Our default shell is the Almquist shell from *BSD.
[1504]761ASH := $(KBUILD_BIN_PATH)/kmk_ash$(HOSTSUFF_EXE)
[380]762MAKESHELL := $(ASH)
763SHELL := $(ASH)
764export SHELL MAKESHELL
765
[414]766# Symlinking is problematic on some platforms...
[380]767LN_SYMLINK := $(LN) -s
768
[2479]769# When copying to the staging area, use hard links to save time and space.
[2485]770ifndef KBUILD_NO_HARD_LINKING
[2512]771 INSTALL_STAGING := $(INSTALL) --hard-link-files-when-possible
772else
773 INSTALL_STAGING := $(INSTALL)
[2479]774endif
[743]775
[2479]776
[743]777#
778# Some Functions.
[748]779# The lower cased ones are either fallbacks or candidates for functions.c.
[743]780#
781
[130]782## ABSPATH - make paths absolute.
[129]783# This implementation is clumsy and doesn't resolve '..' and '.' components.
[73]784#
[129]785# @param $1 The paths to make absolute.
[696]786# @obsolete Use the GNU make function $(abspath) directly now.
[984]787ABSPATH = $(abspath $(1))$(warning ABSPATH is deprecated, use abspath directly!)
[353]788
[130]789## DIRDEP - make create directory dependencies.
790#
791# @param $1 The paths to the directories which must be created.
[353]792DIRDEP = $(foreach path,$(patsubst %/,%,$(1)),$(path)/)
[129]793
794## Cygwin kludge.
795# This converts /cygdrive/x/% to x:%.
796#
797# @param $1 The paths to make native.
798# @remark This macro is pretty much obsolete since we don't use cygwin base make.
799ifneq ($(patsubst /cygdrive/%,%,$(CURDIR)),$(CURDIR))
[743]800 CYGPATHMIXED = $(foreach path,$(1)\
[129]801 ,$(if $(patsubst /cygdrive/%,,$(path)),$(path),$(patsubst $(strip $(firstword $(subst /, ,$(patsubst /cygdrive/%,%,$(path)))))/%,$(strip $(firstword $(subst /, ,$(patsubst /cygdrive/%,%,$(path))))):/%,$(patsubst /cygdrive/%,%,$(path)))))
802else
[743]803 CYGPATHMIXED = $(1)
[129]804endif
805
[743]806## Removes the drive letter from a path (if it has one)
807# @param $1 the path
808no-drive = $(word $(words $(subst :, ,$(1))),$(subst :, ,$(1)))
[723]809
[743]810## Removes the root slash from a path (if it has one)
811# @param $1 the path
812no-root-slash = $(patsubst /%,%,$(1))
[723]813
[2488]814##
815# Similar to firstword, except it returns the value of first defined variable.
816# @param $1 list of variables to probe.
[2512]817define FIRST-DEFINED-VAR
818local .RETURN := $(strip $(firstdefined $1, value))
819endef
[2488]820
[743]821## Figure out where to put object files.
822# @param $1 real target name.
823# @param $2 normalized main target
[748]824TARGET_BASE = $(PATH_TARGET)/$(2)/$(call no-root-slash,$(call no-drive,$(1)))
[723]825
[743]826## Figure out where to put object files.
827# @param $1 normalized main target
828TARGET_PATH = $(PATH_TARGET)/$(1)
[723]829
[2223]830##
831# Checks if the specified short option ($1) is found in the flags ($2),
832# assuming getopt style options.
833#
834# @returns $3 if present, $4 not.
835#
836# @param $1 The option (single char!).
837# @param $2 The option arguments.
838# @param $3 Eval and return if present.
839# @param $4 Eval and return if not present.
840#
841# @todo May confuse option values starting with '-' for options.
842# @remarks Invoke like this: $(evalcall KB_FN_OPT_TEST_SHORT,d,$(flags),present,not-present)
843#
844define KB_FN_OPT_TEST_SHORT
845local options := $(translate $(strip $(filter -%,$(filter-out --%,$2))),$(SP)-,)
846local .RETURN := $(if-expr $(pos $1,$(options)) != 0,$3,$4)
847endef
[723]848
[2223]849##
850# Checks if the specified long option ($1) is found in the flags ($2),
851# assuming getopt style options.
[129]852#
[2223]853# @returns $3 if present, $4 not.
854#
855# @param $1 The long option, dashes included. No % chars.
856# @param $2 The option arguments.
857# @param $3 Eval and return if present.
858# @param $4 Eval and return if not present.
859#
860# @todo May confuse option values starting with '--' for options.
861# @remarks Invoke like this: $(evalcall KBFN_OPT_TEST_SHORT,--defined,$(flags),present,not-present)
862#
863define KB_FN_OPT_TEST_LONG
864local options := $(filter-out =delete=%,$(subst :, =delete=,$(subst =, =delete=,$2)))
865local .RETURN := $(if-expr "$(filter $1,$(options))" != "",$3,$4)
866endef
867
868##
869# Checks if the specified short ($1) or long ($2) option is found in the flags ($2),
870# assuming getopt style options.
871#
872# @returns $4 if present, $5 not.
873#
874# @param $1 The short option (single char!).
875# @param $2 The long option, dashes included. No % chars.
876# @param $3 The option arguments.
877# @param $4 Eval and return if present.
878# @param $5 Eval and return if not present.
879#
880# @todo May confuse option values starting with '--' for options.
881# @remarks Invoke like this: $(evalcall KB_FN_OPT_TEST_SHORT_LONG,d,--defined,$(flags),present,not-present)
882#
883define KB_FN_OPT_TEST_SHORT_LONG
884local short_options := $(translate $(strip $(filter -%,$(filter-out --%,$3))),$(SP)-,)
885local long_options := $(filter-out =delete=%,$(subst :, =delete=,$(subst =, =delete=,$3)))
886local .RETURN := $(if-expr $(pos $1,$(short_options)) != 0 || "$(filter $2,$(long_options))" != "",$4,$5)
887endef
888
[2434]889##
890# Make an assignment to a deprecated variable.
891#
892# @param $1 The variable name.
893# @param $2 The value.
894# @param $3 The variable to use instead.
895#
896ifdef KBUILD_WITH_DEPREATED_AS_ERROR
[2441]897 KB_FN_ASSIGN_DEPRECATED = $(eval $(subst :,$$(COLON),$1) = $2$$(error $1 is deprecated, use $3 instead))
[2434]898else
[2441]899 KB_FN_ASSIGN_DEPRECATED = $(eval $(subst :,$$(COLON),$1) = $2$$(warning $1 is deprecated, use $3 instead))
[2434]900endif
[2223]901
[2531]902##
[2533]903# Show an assertion message.
904#
905# @param $1 The assertion name.
906# @param $2 The details.
907#
908define KB_FN_ASSERT_MSG
909$(info !! kBuild $1 Assertion Failed !!)
910ifdef target
911 $(info !! target: $(target))
912 local varloc := $(where $(target))
913 if "$(varloc)" == "undefined"
914 local varloc := $(where $(target)_TEMPLATE)
915 endif
916 if "$(varloc)" == "undefined"
917 local varloc := $(where $(target)_SOURCES)
918 endif
919 if "$(varloc)" == "undefined"
920 local varloc := $(where $(target)_EXTENDS)
921 endif
922 if "$(varloc)" == "undefined"
923 local varloc := $(where target)
924 endif
925 ifneq ($(varloc),)
926 $(info !! location: $(varloc))
927 else
928 $(info !! probable location: $($(target)_DEFPATH)/Makefile.kmk)
929 endif
930endif
931$(info !! $2)
932$(error fixme)
933endef
934
935##
[2531]936# Throw an error if the given path $1 isn't absolute and assertions are enabled.
937#
938# @param $1 The name of the path variable to check.
939#
940ifdef KBUILD_INTERNAL_STRICT
941 KB_FN_ASSERT_ABSPATH = $(if-expr "$(abspath $($(strip $1)))" != "$(strip $($(strip $1)))",\
[2533]942 $(evalcall KB_FN_ASSERT_MSG,abspath,$1 is:$(NLTAB)'$($(strip $1))'$(NLTAB)expected:$(NLTAB)'$(abspath $($(strip $1)))'))
[2531]943else
944 KB_FN_ASSERT_ABSPATH :=
945endif
[2223]946
[2531]947
[2223]948#
[3030]949# Somewhat simple solution for automatic command dependencies.
950#
951
952##
953# Advanced version of KB_FN_AUTO_CMD_DEPS_COMMANDS_EX where you set
954# the dependency file name yourself.
955#
956# After or before the recipe do $(call KB_FN_AUTO_CMD_DEPS_EX,<recipe-target>,<dep-file>).
957#
958# @param 1 dep file.
959define KB_FN_AUTO_CMD_DEPS_COMMANDS_EX
960 %$(QUIET2)$(RM) -f -- "$1"
961 %$(QUIET2)$(APPEND) "$1" 'define AUTO_CMD_DEP_$(translate $@,:,_)_PREV_CMDS'
962 %$(QUIET2)$(APPEND) -c "$1" '$@'
963 %$(QUIET2)$(APPEND) "$1" 'endef'
964endef
965
966##
967# Advanced version of KB_FN_AUTO_CMD_DEPS
968#
969# @param 1 recipe name
970# @param 2 dep file.
971KB_FN_AUTO_CMD_DEPS_EX = $(eval includedep $2)$(eval _DEPFILES_INCLUDED += $2)$1: .MUST_MAKE = $$(comp-cmds-ex $$(AUTO_CMD_DEP_$(translate $1,:,_)_PREV_CMDS),$$(commands $1),FORCE)
972
973##
974# $(call KB_FN_AUTO_CMD_DEPS_COMMANDS) as the first command in a recipe to
975# automatically generate command dependencies.
976# After or before the recipe do $(call KB_FN_AUTO_CMD_DEPS,<recipe-target>).
977define KB_FN_AUTO_CMD_DEPS_COMMANDS
978 %$(QUIET2)$(RM) -f -- "$@.auto-dep"
979 %$(QUIET2)$(APPEND) "$@.auto-dep" 'define AUTO_CMD_DEP_$(translate $@,:,_)_PREV_CMDS'
980 %$(QUIET2)$(APPEND) -c "$@.auto-dep" '$@'
981 %$(QUIET2)$(APPEND) "$@.auto-dep" 'endef'
982endef
983
984##
985# Call before or after defining a recipe that you want automatic command
986# dependencies on. The recipe must start off by $(call KB_FN_AUTO_CMD_DEPS_COMMANDS).
987#
988# @param 1 recipe name
989KB_FN_AUTO_CMD_DEPS = $(call KB_FN_AUTO_CMD_DEPS_EX,$1,$1.auto-dep)
990
991
992#
[353]993# Initialize some of the globals which the Config.kmk and
994# others can add stuff to if they like for processing in the footer.
995#
996
[1416]997## KBUILD_TEMPLATE_PATHS
[353]998# List a paths (separated by space) where templates can be found.
[1416]999KBUILD_TEMPLATE_PATHS :=
[353]1000
[1416]1001## KBUILD_TOOL_PATHS
[353]1002# List of paths (separated by space) where tools can be found.
[1416]1003KBUILD_TOOL_PATHS :=
[353]1004
[1416]1005## KBUILD_SDK_PATHS
[353]1006# List of paths (separated by space) where SDKs can be found.
[1416]1007KBUILD_SDK_PATHS :=
[353]1008
[1621]1009## KBUILD_UNIT_PATHS
1010# List of paths (separated by space) where units (USES) can be found.
1011KBUILD_UNIT_PATHS :=
1012
[1416]1013## KBUILD_DEFAULT_PATHS
1014# List of paths (separated by space) to search for stuff as a last resort.
1015KBUILD_DEFAULT_PATHS :=
1016
[353]1017## Proritized list of the default makefile when walking subdirectories.
1018# The user can overload this list.
1019DEFAULT_MAKEFILE := Makefile.kmk makefile.kmk Makefile makefile
1020
[1424]1021## KBUILD_SRC_HANDLERS
1022# The list of source handlers, pair of extension and handler.
1023# The user can overload this list to provide additional or custom
1024# handlers. On a per-target/template see SRC_HANDLERS.
1025KBUILD_SRC_HANDLERS := \
1026 .c:def_src_handler_c \
1027 .C:def_src_handler_c \
1028.cxx:def_src_handler_cxx \
1029.CXX:def_src_handler_cxx \
1030.cpp:def_src_handler_cxx \
1031.CPP:def_src_handler_cxx \
1032 .cc:def_src_handler_cxx \
1033 .CC:def_src_handler_cxx \
1034 .m:def_src_handler_objc \
[2356]1035 .M:def_src_handler_objcxx \
1036 .mm:def_src_handler_objcxx \
[1424]1037.asm:def_src_handler_asm \
1038.ASM:def_src_handler_asm \
1039 .s:def_src_handler_asm \
1040 .S:def_src_handler_asm \
1041 .rc:def_src_handler_rc \
1042.obj:def_src_handler_obj \
1043 .o:def_src_handler_obj \
[1435]1044.res:def_src_handler_obj
[980]1045
[640]1046## PROPS_TOOLS
[985]1047# This is a subset of PROPS_SINGLE.
[2356]1048PROPS_TOOLS := TOOL CTOOL CXXTOOL OBJCTOOL OBJCXXTOOL ASTOOL RCTOOL ARTOOL LDTOOL FETCHTOOL UNPACKTOOL PATCHTOOL
[640]1049
[353]1050## PROPS_SINGLE
1051# The list of non-accumulative target properties.
1052# A Config.kmk file can add it's own properties to this list and kBuild
[1400]1053# will do the necessary inheritance for templates, sdks, tools and targets.
[2475]1054PROPS_SINGLE := $(PROPS_TOOLS) TEMPLATE INSTTYPE INST STAGE NOINST BLD_TYPE BLD_TRG BLD_TRG_ARCH BLD_TRG_CPU FETCHDIR \
[2356]1055 OBJSUFF COBJSUFF CXXOBJSUFF OBJCOBJSUFF OBJCXXOBJSUFF ASOBJSUFF RCOBJSUFF SYSSUFF BINSUFF EXESUFF DLLSUFF LIBSUFF ARLIBSUFF \
[2523]1056 MODE UID GID LD_DEBUG DEBUG_INSTTYPE DEBUG_INST DEBUG_STAGE
[985]1057## PROPS_SINGLE_LNK
1058# Subset of PROPS_SINGLE which applies to all linkable targets.
[2550]1059PROPS_SINGLE_LNK := $(filter-out FETCHTOOL UNPACKTOOL PATCHTOOL FETCHDIR, $(PROPS_SINGLE))
[353]1060
1061## PROPS_DEFERRED
[889]1062# This list of non-accumulative target properties which are or may be
1063# functions, and thus should not be expanded until the very last moment.
[2537]1064PROPS_DEFERRED := INSTFUN INSTALLER PRE_CMDS POST_CMDS PRE_INST_CMDS POST_INST_CMDS \
1065 PRE_FILE_CMDS POST_FILE_CMDS PRE_SYMLINK_CMDS POST_SYMLINK_CMDS PRE_DIRECTORY_CMDS POST_DIRECTORY_CMDS \
1066 NAME SONAME
[353]1067
[660]1068## PROPS_ACCUMULATE_R
[748]1069# The list of accumulative target properties where the right most value/flag
[660]1070# is the 'most significant'.
[353]1071# A Config.kmk file can add it's own properties to this list and kBuild
1072# will do the necessary inheritance from templates to targets.
[660]1073PROPS_ACCUMULATE_R := \
[1702]1074 DEPS LNK_DEPS ORDERDEPS LNK_ORDERDEPS DEFS \
[985]1075 ARFLAGS \
[660]1076 CFLAGS CDEFS \
1077 CXXFLAGS CXXDEFS \
[1256]1078 OBJCFLAGS OBJCDEFS \
[2356]1079 OBJCXXFLAGS OBJCXXDEFS \
[660]1080 ASFLAGS ASDEFS \
1081 RCFLAGS RCDEFS \
1082 LDFLAGS \
[2483]1083 IDFLAGS IFFLAGS EXEC_IFFLAGS ISFLAGS \
[640]1084 FETCHFLAGS UNPACKFLAGS PATCHFLAGS
[985]1085## PROPS_ACCUMULATE_R_LNK
1086# Subset of PROPS_ACCUMULATE_R which applies to all linkable targets.
[2550]1087PROPS_ACCUMULATE_R_LNK := $(filter-out ARFLAGS LDFLAGS EXEC_IFFLAGS FETCHFLAGS UNPACKFLAGS PATCHFLAGS, $(PROPS_ACCUMULATE_R))
[353]1088
[660]1089## PROPS_ACCUMULATE
[748]1090# The list of accumulative target properties where the left most value/flag
[660]1091# is the 'most significant'.
1092# A Config.kmk file can add it's own properties to this list and kBuild
1093# will do the necessary inheritance from templates to targets.
1094PROPS_ACCUMULATE_L := \
[2483]1095 SDKS USES SOURCES EXEC_SOURCES SRC_HANDLERS INTERMEDIATES \
[2356]1096 INCS CINCS CXXINCS OBJCINCS OBJCXXINCS ASINCS RCINCS \
[897]1097 LIBS LIBPATH \
[985]1098 DIRS BLDDIRS CLEAN
1099## PROPS_ACCUMULATE_L_LNK
1100# Subset of PROPS_ACCUMULATE_L which applies to all linkable targets.
[2550]1101PROPS_ACCUMULATE_L_LNK := $(filter-out LIBS LIBPATH EXEC_SOURCES DIRS, $(PROPS_ACCUMULATE_L))
[353]1102
[662]1103## PROPS_ALL
1104# List of all the properties.
1105PROPS_ALL = $(PROPS_SINGLE) $(PROPS_DEFERRED) $(PROPS_ACCUMULATE_L) $(PROPS_ACCUMULATE_R)
[660]1106
[985]1107## @name Properties valid on programs (BLDPROGS and PROGRAMS)
1108## @{
1109PROPS_PROGRAMS_SINGLE := $(PROPS_SINGLE_LNK) LDTOOL EXESUFF
1110PROPS_PROGRAMS_DEFERRED := $(PROPS_DEFERRED)
1111PROPS_PROGRAMS_ACCUMULATE_R := $(PROPS_ACCUMULATE_R_LNK) LDFLAGS
1112PROPS_PROGRAMS_ACCUMULATE_L := $(PROPS_ACCUMULATE_L_LNK) LIBS LIBPATH
1113## @}
1114
1115## @name Properties valid on libraries (LIBRARIES and IMPORT_LIBS)
1116## @{
[989]1117PROPS_LIBRARIES_SINGLE := $(PROPS_SINGLE_LNK) ARTOOL LIBSUFF ARLIBSUFF LIBSUFF
[985]1118PROPS_LIBRARIES_DEFERRED := $(filter-out SONAME,$(PROPS_DEFERRED))
1119PROPS_LIBRARIES_ACCUMULATE_R := $(PROPS_ACCUMULATE_R_LNK) ARFLAGS
1120PROPS_LIBRARIES_ACCUMULATE_L := $(PROPS_ACCUMULATE_L_LNK)
1121## @}
1122
1123## @name Properties valid on dlls (DLLS)
1124## @{
1125PROPS_DLLS_SINGLE := $(PROPS_SINGLE_LNK) LDTOOL DLLSUFF LIBSUFF
1126PROPS_DLLS_DEFERRED := $(PROPS_DEFERRED)
1127PROPS_DLLS_ACCUMULATE_R := $(PROPS_ACCUMULATE_R_LNK) LDFLAGS
1128PROPS_DLLS_ACCUMULATE_L := $(PROPS_ACCUMULATE_L_LNK) LIBS LIBPATH
1129## @}
1130
[989]1131## @name Properties valid on system modules (SYSMODS)
1132## @{
1133PROPS_SYSMODS_SINGLE := $(PROPS_SINGLE_LNK) LDTOOL SYSSUFF
1134PROPS_SYSMODS_DEFERRED := $(PROPS_DEFERRED)
1135PROPS_SYSMODS_ACCUMULATE_R := $(PROPS_ACCUMULATE_R_LNK) LDFLAGS
1136PROPS_SYSMODS_ACCUMULATE_L := $(PROPS_ACCUMULATE_L_LNK) LIBS LIBPATH
1137## @}
1138
[2084]1139## @name Properties valid on misc binaries (MISCBINS)
1140## @{
1141PROPS_MISCBINS_SINGLE := $(PROPS_SINGLE_LNK) LDTOOL BINSUFF
1142PROPS_MISCBINS_DEFERRED := $(PROPS_DEFERRED)
1143PROPS_MISCBINS_ACCUMULATE_R := $(PROPS_ACCUMULATE_R_LNK) LDFLAGS
1144PROPS_MISCBINS_ACCUMULATE_L := $(PROPS_ACCUMULATE_L_LNK) LIBS LIBPATH
1145## @}
1146
[985]1147## @name Properties valid on installs (INSTALLS)
1148## @{
[2550]1149PROPS_INSTALLS_SINGLE := TOOL TEMPLATE INSTTYPE INST STAGE NOINST BLD_TYPE BLD_TRG BLD_TRG_ARCH BLD_TRG_CPU MODE UID GID
[2537]1150PROPS_INSTALLS_DEFERRED := INSTFUN INSTALLER PRE_FILE_CMDS POST_FILE_CMDS PRE_SYMLINK_CMDS POST_SYMLINK_CMDS \
1151 PRE_DIRECTORY_CMDS POST_DIRECTORY_CMDS
[2483]1152PROPS_INSTALLS_ACCUMULATE_R := DEPS ORDERDEPS GOALS INST_ONLY_GOALS STAGE_ONLY_GOALS IFFLAGS EXEC_IFFLAGS
1153PROPS_INSTALLS_ACCUMULATE_L := SOURCES EXEC_SOURCES DIRS CLEAN
[985]1154## @}
1155
[2475]1156## @name Properties valid on fetches (FETCHES)
[985]1157## @{
[1400]1158PROPS_FETCHES_SINGLE := TOOL TEMPLATE FETCHTOOL UNPACKTOOL PATCHTOOL INST FETCHDIR
[985]1159PROPS_FETCHES_DEFERRED :=
1160PROPS_FETCHES_ACCUMULATE_R := FETCHFLAGS UNPACKFLAGS PATCHFLAGS
[1613]1161PROPS_FETCHES_ACCUMULATE_L := SOURCES CLEAN
[985]1162## @}
1163
[2274]1164## KBUILD_COMPILE_CATEGTORIES
1165# Tools categories for compiling.
1166KBUILD_COMPILE_CATEGTORIES := AS C CXX OBJC OBJCXX RC
[985]1167
[2274]1168## KBUILD_GENERIC_CATEGORIES
1169# Generic tool categories.
1170KBUILD_GENERIC_CATEGORIES := FETCH UNPACK PATCH $(addprefix LINK_,LIBRARY PROGRAM DLL SYSMOD MISCBIN)
1171
1172## PROPS_TOOLS_ONLY
1173# Properties found only on tools.
1174# This is expanded in a deferred manner, so it will pick up changes made to
1175# KBUILD_COMPILE_CATEGTORIES and KBUILD_GENERIC_CATEGORIES made by units.
1176PROPS_TOOLS_ONLY = \
1177 $(foreach cat, $(KBUILD_COMPILE_CATEGTORIES), \
1178 COMPILE_$(cat)_CMDS \
1179 COMPILE_$(cat)_OUTPUT \
1180 COMPILE_$(cat)_OUTPUT_MAYBE \
1181 COMPILE_$(cat)_DEPEND \
1182 COMPILE_$(cat)_DEPORD \
1183 COMPILE_$(cat)_USES_KOBJCACHE ) \
1184 $(foreach cat, $(KBUILD_GENERIC_CATEGORIES), \
1185 $(cat)_CMDS \
1186 $(cat)_OUTPUT \
1187 $(cat)_OUTPUT_MAYBE \
1188 $(cat)_DEPEND \
1189 $(cat)_DEPORD ))
1190
1191
[353]1192#
[748]1193# Here is a special 'hack' to prevent innocent environment variables being
1194# picked up and treated as properties. (The most annoying example of why
[662]1195# this is necessary is the Visual C++ commandline with it's LIBPATH.)
1196#
[748]1197# Define KBUILD_DONT_KILL_ENV_PROPS in the env. or on the commandline to
[662]1198# disable this 'hack'.
1199#
1200ifndef KBUILD_DONT_KILL_ENV_PROPS
1201
1202define def_nuke_environment_prop
1203ifeq ($(origin $(prop)),environment)
1204$(prop) =
1205endif
1206endef
[762]1207$(foreach prop, $(PROPS_ALL) \
[2084]1208 FETCHES PATCHES BLDPROGS LIBRARIES IMPORT_LIBS DLLS PROGRAMS SYSMODS MISCBINS INSTALLS OTHERS \
[897]1209 SUBDIRS MAKEFILES BLDDIRS \
[762]1210 ,$(eval $(value def_nuke_environment_prop)))
[662]1211
[897]1212endif # KBUILD_DONT_KILL_ENV_PROPS
[662]1213
1214
1215#
[353]1216# Pass configuration.
1217#
1218# The PASS_<passname>_trgs variable is listing the targets.
1219# The PASS_<passname>_vars variable is listing the target variables.
1220# The PASS_<passname>_pass variable is the lowercased passname.
1221#
1222
[640]1223## PASS: fetches
1224# This pass fetches and unpacks things needed to complete the build.
1225PASS_FETCHES := Fetches
1226PASS_FETCHES_trgs :=
1227PASS_FETCHES_vars := _FETCHES
1228PASS_FETCHES_pass := fetches
1229
1230## PASS: patches
1231# This pass applies patches.
1232PASS_PATCHES := Patches
1233PASS_PATCHES_trgs :=
1234PASS_PATCHES_vars := _PATCHES
1235PASS_PATCHES_pass := patches
1236
[353]1237## PASS: bldprogs
1238# This pass builds targets which are required for building the rest.
1239PASS_BLDPROGS := Build Programs
1240PASS_BLDPROGS_trgs :=
1241PASS_BLDPROGS_vars := _BLDPROGS
1242PASS_BLDPROGS_pass := bldprogs
1243
1244## PASS: libraries
1245# This pass builds library targets.
1246PASS_LIBRARIES := Libraries
1247PASS_LIBRARIES_trgs :=
1248PASS_LIBRARIES_vars := _LIBS _IMPORT_LIBS _OTHER_LIBRARIES
1249PASS_LIBRARIES_pass := libraries
1250
1251## PASS: binaries
1252# This pass builds dll targets.
1253PASS_DLLS := DLLs
1254PASS_DLLS_trgs :=
1255PASS_DLLS_vars := _DLLS _OTHER_DLLS
1256PASS_DLLS_pass := dlls
1257
1258## PASS: binaries
1259# This pass builds binary targets, i.e. programs, system modules and stuff.
1260PASS_BINARIES := Programs
1261PASS_BINARIES_trgs :=
[2084]1262PASS_BINARIES_vars := _PROGRAMS _SYSMODS _MISC_BINS _OTHER_BINARIES
[353]1263PASS_BINARIES_pass := binaries
1264
1265## PASS: others
1266# This pass builds other targets.
1267PASS_OTHERS := Other Stuff
1268PASS_OTHERS_trgs :=
1269PASS_OTHERS_vars := _OTHERS
1270PASS_OTHERS_pass := others
1271
[2475]1272## PASS: staging
[353]1273# This pass installs the built entities to a sandbox area.
[1646]1274## @todo split this up into build install (to sandbox) and real installation.
[2475]1275PASS_STAGING := Staging
1276PASS_STAGING_trgs :=
[2523]1277PASS_STAGING_vars := _STAGE_DIRS _INSTALLS _STAGE_FILES _DEBUG_STAGE_DIRS _DEBUG_STAGE_FILES
[2475]1278PASS_STAGING_pass := staging
1279
1280## PASS: install
1281# This pass installs the built entities to where they will be used (using
1282# DESTROOT or PATH_INS to indicate where this is).
[353]1283PASS_INSTALLS := Install
1284PASS_INSTALLS_trgs :=
[2523]1285PASS_INSTALLS_vars := _INSTALLS_DIRS _INSTALLS_FILES _DEBUG_INSTALL_DIRS _DEBUG_INSTALL_FILES
[353]1286PASS_INSTALLS_pass := installs
1287
[1646]1288## PASS: testing
1289# This pass processes custom rules for executing tests.
1290PASS_TESTING := Tests
1291PASS_TESTING_trgs :=
1292PASS_TESTING_vars := _TESTING
1293PASS_TESTING_pass := testing
1294
[353]1295## PASS: packing
1296# This pass processes custom packing rules.
1297PASS_PACKING := Packing
[414]1298PASS_PACKING_trgs :=
[417]1299PASS_PACKING_vars := _PACKING
[353]1300PASS_PACKING_pass := packing
1301
1302## PASS: clean
1303# This pass removes all generated files.
1304PASS_CLEAN := Clean
1305PASS_CLEAN_trgs := do-clean
1306PASS_CLEAN_vars :=
1307PASS_CLEAN_pass := clean
1308
1309## PASS: nothing
1310# This pass just walks the tree.
1311PASS_NOTHING := Nothing
1312PASS_NOTHING_trgs := do-nothing
1313PASS_NOTHING_vars :=
1314PASS_NOTHING_pass := nothing
1315
1316## DEFAULT_PASSES
1317# The default passes and their order.
[2475]1318DEFAULT_PASSES := BLDPROGS LIBRARIES DLLS BINARIES OTHERS STAGING
[353]1319
1320## PASSES
1321# The passes that should be defined. This must include
1322# all passes mentioned by DEFAULT_PASSES.
[2475]1323PASSES := FETCHES PATCHES $(DEFAULT_PASSES) INSTALLS TESTING PACKING CLEAN NOTHING
[353]1324
1325
1326#
[984]1327# Check for --pretty-command-printing before including the Config.kmk
1328# so that anyone overriding the message macros can take the implied
1329# verbosity level change into account.
1330#
1331ifndef KBUILD_VERBOSE
1332 ifndef KBUILD_QUIET
[1562]1333 ifeq ($(KMK_OPTS_PRETTY_COMMAND_PRINTING),1)
[984]1334 export KBUILD_VERBOSE := 2
1335 endif
1336 endif
1337endif
1338
1339
1340#
[1418]1341# Legacy variable translation.
1342# These will be eliminated when switching to the next version.
1343#
1344ifdef USE_KOBJCACHE
1345 ifndef KBUILD_USE_KOBJCACHE
1346 export KBUILD_USE_KOBJCACHE := $(USE_KOBJCACHE)
1347 endif
1348endif
1349
1350
1351#
[2559]1352# Library path searching hints (target OS + arch).
1353#
1354# KBUILD_LIB_SEARCH_SUBS - Subdirs typically containing the right libraries.
1355# KBUILD_LIB_SEARCH_ROOTS - Roots to search for library subdirs.
1356# KBUILD_LIB_SEARCH_PATHS - ROOTS + SUBS.
1357#
1358ifeq ($(KBUILD_TARGET),darwin)
1359 KBUILD_LIB_SEARCH_ROOTS := \
1360 /usr/ \
1361 /Developer/usr/
1362 KBUILD_LIB_SEARCH_SUBS := lib/
1363
1364else if1of ($(KBUILD_TARGET), freebsd netbsd openbsd dragonfly)
1365 KBUILD_LIB_SEARCH_ROOTS := \
1366 / \
1367 /usr/ \
1368 /usr/local/
1369 KBUILD_LIB_SEARCH_SUBS := lib/
1370
1371else ifeq ($(KBUILD_TARGET),linux)
[2689]1372 ifeq ($(realpath /bin),/usr/bin)
[2688]1373 KBUILD_LIB_SEARCH_ROOTS := \
1374 /usr/ \
1375 / \
1376 /usr/local/
1377 else
1378 KBUILD_LIB_SEARCH_ROOTS := \
1379 / \
1380 /usr/ \
1381 /usr/local/
1382 endif
[2559]1383 ifeq ($(KBUILD_TARGET_ARCH),amd64)
1384 KBUILD_LIB_SEARCH_SUBS := \
1385 lib/x86_64-linux-gnu/ \
1386 lib64/ \
1387 lib/
1388 else ifeq ($(KBUILD_TARGET_ARCH),x86)
1389 KBUILD_LIB_SEARCH_SUBS := \
1390 lib/i686-linux-gnu/ \
1391 lib/i386-linux-gnu/ \
1392 lib32/ \
1393 lib/
1394 else
1395 KBUILD_LIB_SEARCH_SUBS := lib/
1396 endif
1397
1398else ifeq ($(KBUILD_TARGET),solaris)
1399 KBUILD_LIB_SEARCH_ROOTS := \
1400 / \
1401 /usr/ \
1402 /usr/sfw/ \
1403 /usr/local/ \
1404 /sw/
1405 ifeq ($(KBUILD_TARGET_ARCH),amd64)
1406 KBUILD_LIB_SEARCH_SUBS := lib/amd64/ lib/
1407 else ifeq ($(KBUILD_TARGET_ARCH),sparc64)
1408 KBUILD_LIB_SEARCH_SUBS := lib/sparcv9/ lib/
1409 else
1410 KBUILD_LIB_SEARCH_SUBS := lib/
1411 endif
1412
1413else
1414 KBUILD_LIB_SEARCH_SUBS :=
1415 KBUILD_LIB_SEARCH_ROOTS :=
1416endif
[2562]1417KBUILD_LIB_SEARCH_PATHS := $(foreach root, $(KBUILD_LIB_SEARCH_ROOTS), $(addprefix $(root),$(KBUILD_LIB_SEARCH_SUBS)))
[2559]1418
1419
1420#
[69]1421# This is how we find the closest config.kmk.
1422# It's a little hacky but I think it works fine.
[70]1423#
1424_CFGDIR := .
[78]1425_CFGFILES := ./Config.kmk ./config.kmk
[69]1426define def_include_config
[78]1427$(eval _CFGDIR := $(_CFGDIR)/$(dir))
1428_CFGFILES += $(_CFGDIR)/Config.kmk $(_CFGDIR)/config.kmk
[69]1429endef
1430# walk down the _RELATIVE_ path specified by DEPTH.
[78]1431$(foreach dir,$(subst /, ,$(DEPTH)), $(eval $(def_include_config)) )
[69]1432# add the default config file.
[78]1433_CFGFILE := $(firstword $(wildcard $(_CFGFILES) $(FILE_KBUILD_CONFIG)))
[69]1434_CFGFILES :=
1435_CFGDIR :=
[416]1436ifeq ($(_CFGFILE),)
1437$(error kBuild: no Config.kmk file found! Check the DEPTH: DEPTH='$(DEPTH)' PATH_CURRENT='$(PATH_CURRENT)')
1438endif
[69]1439
1440# Include the config.kmk we found file (or the default one).
[988]1441ifdef KBUILD_PROFILE_SELF
[2008]1442 $(evalcall def_profile_self, including $(_CFGFILE))
[988]1443 include $(_CFGFILE)
[2008]1444 $(evalcall def_profile_self, included $(_CFGFILE))
[988]1445else
1446 include $(_CFGFILE)
1447endif
1448
1449
1450
[696]1451#
[874]1452# Finalize a the central path variables now that we've included the Config.kmk file.
1453#
1454# This prevents some trouble when users override the defaults for these
1455# variables and uses relative paths or paths with incorrect case.
1456#
[1692]1457PATH_OUT_BASE := $(abspath $(PATH_OUT_BASE))
[2475]1458PATH_OUT := $(abspath $(PATH_OUT))
1459PATH_OBJ := $(abspath $(PATH_OBJ))
1460PATH_TARGET := $(abspath $(PATH_TARGET))
1461PATH_INS := $(abspath $(PATH_INS))
1462PATH_STAGE := $(abspath $(PATH_STAGE))
[874]1463
[2475]1464# Finalize the install and staging directory layouts.
1465define def_kbuild_finalize_inst
1466local val := $(strip $($(y)_$(x)))
1467ifeq ($(val),)
1468 $(error kBuild: '$(y)_$(x)' is set to an empty value.)
1469endif
1470ifneq ($(words $(val)),1)
1471 $(error kBuild: The '$(y)_$(x)' value '$(val)' should not contain spaces.)
1472endif
1473ifneq ($(pos \,$(val)), 0)
1474 $(error kBuild: The '$(y)_$(x)' value '$(val)' contains DOS slashes: not allowed.)
1475endif
1476ifneq ($(pos $(COLON),$(val)), 0)
1477 $(error kBuild: The '$(y)_$(x)' value '$(val)' contains colon: not allowed.)
1478endif
1479ifneq ($(substr $(val),-1), /)
1480 $(error kBuild: The '$(y)_$(x)' value '$(val)' has no trailing slash.)
1481endif
1482if $(pos /../,$(val)) != 0 || "$(substr $(val), 3)" == "../"
1483 $(error kBuild: The '$(y)_$(x)' value '$(val)' contains dot-dot escape.)
1484endif
1485$($(y)_$(x) := $(val)
[2479]1486
1487local val := $(strip $(PATH_$(y)_$(x)))
1488ifeq ($(val),)
1489 $(error kBuild: 'PATH_$(y)_$(x)' is set to an empty value.)
1490endif
1491PATH_$(y)_$(x) := $(val)
[2475]1492endef
[2479]1493$(foreach y, INST STAGE, $(foreach x, $(KBUILD_INST_PATHS), $(evalcall def_kbuild_finalize_inst)))
[874]1494
[2724]1495# No abspath for devtools since they might've been referenced already and we
1496# don't want conflicting variable expansions.
1497KBUILD_DEVTOOLS := $(KBUILD_DEVTOOLS)
1498KBUILD_DEVTOOLS_TRG := $(KBUILD_DEVTOOLS_TRG)
1499KBUILD_DEVTOOLS_TRG_ALT := $(KBUILD_DEVTOOLS_TRG_ALT)
1500KBUILD_DEVTOOLS_HST := $(KBUILD_DEVTOOLS_HST)
1501KBUILD_DEVTOOLS_HST_ALT := $(KBUILD_DEVTOOLS_HST_ALT)
[2475]1502
[2724]1503
[874]1504#
[788]1505# Setup the message style. The default one is inlined.
[776]1506#
[788]1507# See kBuild/msgstyles for more styles or use KBUILD_MSG_STYLE_PATHS
1508# to create your own message style.
1509#
[776]1510KBUILD_MSG_STYLE ?= default
1511ifeq ($(KBUILD_MSG_STYLE),default)
1512 #
1513 # The 'default' style.
1514 #
1515
1516 ## Fetch starting.
1517 # @param 1 Target name.
1518 MSG_FETCH ?= $(call MSG_L1,Fetching $1...)
1519 ## Re-fetch starting.
1520 # @param 1 Target name.
1521 MSG_REFETCH ?= $(call MSG_L1,Re-fetching $1...)
1522 ## Downloading a fetch component.
1523 # @param 1 Target name.
1524 # @param 2 The source URL.
1525 # @param 3 The destination file name.
1526 MSG_FETCH_DL ?= $(call MSG_L1,Downloading $1 - $2,=> $3)
1527 ## Checking a fetch component.
1528 # @param 1 Target name.
1529 # @param 2 The source URL.
1530 # @param 3 The destination file name.
1531 MSG_FETCH_CHK?= $(call MSG_L1,Checking $1 - $3, ($2))
1532 ## Unpacking a fetch component.
1533 # @param 1 Target name.
1534 # @param 2 The archive file name.
1535 # @param 3 The target directory.
1536 MSG_FETCH_UP ?= $(call MSG_L1,Unpacking $1 - $2 => $3)
1537 ## Fetch completed.
1538 # @param 1 Target name.
1539 MSG_FETCH_OK ?= $(call MSG_L1,Successfully fetched $1)
1540 ## Unfetch a fetch target.
1541 # @param 1 Target name.
1542 MSG_UNFETCH ?= $(call MSG_L1,Unfetching $1...)
1543 ## Compiling a source file.
1544 # @param 1 Target name.
1545 # @param 2 The source filename.
1546 # @param 3 The primary link output file name.
[1256]1547 # @param 4 The source type (C,CXX,OBJC,AS,RC,++).
[776]1548 MSG_COMPILE ?= $(call MSG_L1,Compiling $1 - $2,=> $3)
[890]1549 ## Tool
1550 # @param 1 The tool name (bin2c,...)
1551 # @param 2 Target name.
1552 # @param 3 The source filename.
1553 # @param 4 The primary output file name.
1554 MSG_TOOL ?= $(call MSG_L1,$1 $2 - $3,=> $4)
1555 ## Generate a file, typically a source file.
1556 # @param 1 Target name if applicable.
1557 # @param 2 Output file name.
1558 # @param 3 What it's generated from
1559 MSG_GENERATE ?= $(call MSG_L1,Generating $(if $1,$1 - )$2,$(if $3,from $3))
[776]1560 ## Linking a bldprog/dll/program/sysmod target.
1561 # @param 1 Target name.
1562 # @param 2 The primary link output file name.
1563 # @param 3 The link tool operation (LINK_LIBRARY,LINK_PROGRAM,LINK_DLL,LINK_SYSMOD,++).
1564 MSG_LINK ?= $(call MSG_L1,Linking $1,=> $2)
[844]1565 ## Merging a library into the target (during library linking).
1566 # @param 1 Target name.
1567 # @param 2 The output library name.
1568 # @param 3 The input library name.
[845]1569 MSG_AR_MERGE ?= $(call MSG_L1,Merging $3 into $1, ($2))
[776]1570 ## Creating a directory (build).
1571 # @param 1 Directory name.
1572 MSG_MKDIR ?= $(call MSG_L2,Creating directory $1)
1573 ## Cleaning.
1574 MSG_CLEAN ?= $(call MSG_L1,Cleaning...)
1575 ## Nothing.
1576 MSG_NOTHING ?= $(call MSG_L1,Did nothing in $(CURDIR))
1577 ## Pass
1578 # @param 1 The pass name.
1579 MSG_PASS ?= $(call MSG_L1,Pass - $1)
1580 ## Installing a bldprog/lib/dll/program/sysmod target.
1581 # @param 1 Target name.
1582 # @param 2 The source filename.
1583 # @param 3 The destination file name.
1584 MSG_INST_TRG ?= $(call MSG_L1,Installing $1 => $3)
1585 ## Installing a file (install target).
1586 # @param 1 The source filename.
1587 # @param 2 The destination filename.
1588 MSG_INST_FILE?= $(call MSG_L1,Installing $2,(<= $1))
1589 ## Installing a symlink.
1590 # @param 1 Symlink
1591 # @param 2 Link target
1592 MSG_INST_SYM ?= $(call MSG_L1,Installing symlink $1,=> $2)
1593 ## Installing a directory.
1594 # @param 1 Directory name.
1595 MSG_INST_DIR ?= $(call MSG_L1,Installing directory $1)
1596
[788]1597else
[1504]1598 _KBUILD_MSG_STYLE_FILE := $(firstword $(foreach path, $(KBUILD_MSG_STYLE_PATHS) $(KBUILD_PATH)/msgstyles, $(wildcard $(path)/$(KBUILD_MSG_STYLE).kmk)))
[788]1599 ifneq ($(_KBUILD_MSG_STYLE_FILE),)
1600 include $(_KBUILD_MSG_STYLE_FILE)
[776]1601 else
[788]1602 $(error kBuild: Can't find the style setup file for KBUILD_MSG_STYLE '$(KBUILD_MSG_STYLE)')
[776]1603 endif
1604endif
1605
1606
1607#
[696]1608# Message macros.
1609#
[748]1610# This is done after including Config.kmk as to allow for
[696]1611# KBUILD_QUIET and KBUILD_VERBOSE to be configurable.
1612#
1613ifdef KBUILD_QUIET
[776]1614 # No output
[696]1615 QUIET := @
1616 QUIET2:= @
1617 MSG_L1 =
1618 MSG_L2 =
1619else
1620 ifndef KBUILD_VERBOSE
[776]1621 # Default output level.
1622 QUIET := @
1623 QUIET2 := @
[1496]1624 MSG_L1 ?= %@$(ECHO) "kBuild: $1"
[776]1625 MSG_L2 =
1626 else ifeq ($(KBUILD_VERBOSE),1)
1627 # A bit more output
1628 QUIET := @
1629 QUIET2 := @
[1496]1630 MSG_L1 ?= %@$(ECHO) "kBuild: $1 $2"
[776]1631 MSG_L2 =
1632 else ifeq ($(KBUILD_VERBOSE),2)
1633 # Lot more output
1634 QUIET :=
1635 QUIET2 := @
[1496]1636 MSG_L1 ?= %@$(ECHO) "kBuild: $1 $2"
1637 MSG_L2 ?= %@$(ECHO) "kBuild: $1"
[696]1638 else
1639 # maximal output.
[776]1640 QUIET :=
1641 QUIET2 :=
[1496]1642 MSG_L1 ?= %@$(ECHO) "kBuild: $1 $2"
1643 MSG_L2 ?= %@$(ECHO) "kBuild: $1"
[696]1644 endif
1645endif
1646
[776]1647
[3031]1648##
1649# An internal define used by subheader.kmk, subfooter.kmk, and
1650# KB_FN_PASS_0_ON_TARGET.
[1403]1651#
[3031]1652# @param target The target to process.
[2763]1653#
1654define def_subfooter_header_target_pass
1655 ifndef $(target)_PATH
1656 ifndef $(target)_DEFPATH
1657 $(target)_DEFPATH := $(PATH_SUB_CURRENT)
1658 endif
1659 $(call KB_FN_ASSIGN_DEPRECATED,$(target)_PATH,$($(target)_DEFPATH), $(target)_DEFPATH)
1660 else ifndef $(target)_DEFPATH
1661 $(target)_DEFPATH := $($(target)_PATH)
1662 endif
1663 ifndef $(target)_MAKEFILE
1664 $(target)_MAKEFILE := $(MAKEFILE_CURRENT)
1665 endif
1666 ifndef $(target)_0_OUTDIR
1667 $(target)_0_OUTDIR := $(call TARGET_PATH,$(target))
1668 $(call KB_FN_ASSIGN_DEPRECATED,PATH_$(target),$($(target)_0_OUTDIR), $(target)_0_OUTDIR)
1669 endif
1670endef
1671
[3031]1672##
1673# Function to call to set _0_OUTDIR, _DEFPATH, and _MAKEFILE earlier than subfooter.
1674# Can be used to avoid exploiting double expansion.
1675#
1676# @param 1 The target name.
1677KB_FN_DO_PASS0_ON_TARGET = $(foreach target,$1,$(if-expr defined($(target)_0_OUTDIR),,$(evalval def_subfooter_header_target_pass)))
[2763]1678
[3031]1679
[2763]1680#
[1504]1681# Validate any KBUILD_BLD_TYPES additions and finally the KBUILD_TYPE.
[1403]1682#
1683if1of ($(KBUILD_BLD_TYPES), $(KBUILD_OSES))
1684 $(error kBuild: found KBUILD_BLD_TYPES in KBUILD_OSES!)
1685endif
1686if1of ($(KBUILD_BLD_TYPES), $(KBUILD_ARCHES))
1687 $(error kBuild: found KBUILD_BLD_TYPES in KBUILD_ARCHES!)
1688endif
1689if1of ($(KBUILD_OSES), $(KBUILD_ARCHES))
1690 $(error kBuild: found KBUILD_OSES in KBUILD_ARCHES!)
1691endif
[1504]1692ifn1of ($(KBUILD_TYPE), $(KBUILD_BLD_TYPES))
1693 $(error kBuild: KBUILD_TYPE(=$(KBUILD_TYPE)) is not found in KBUILD_BLD_TYPES(=$(KBUILD_BLD_TYPES))!)
[1403]1694endif
1695
1696
[2887]1697#
1698# Mark the output and temporary directories as volatile on windows.
1699#
1700# This automatically means the directories not listed here are considered
1701# static and won't be invalidated once we start running compile jobs.
1702#
1703ifeq ($(KBUILD_HOST),win)
1704 if $(KBUILD_KMK_REVISION) >= 2886
1705 $(dircache-ctl volatile, $(PATH_OUT_BASE), $(PATH_OUT), $(TEMP), $(TMP), $(TMPDIR), $(TMP))
1706 endif
1707endif
[1403]1708
[2887]1709
[988]1710ifdef KBUILD_PROFILE_SELF
[2008]1711 $(evalcall def_profile_self, end of header.kmk)
1712 _KBUILD_TS_HEADER_END := $(_KBUILD_TS_PREV)
[988]1713endif
1714
[69]1715# end-of-file-content
[72]1716__header_kmk__ := 1
[2688]1717endif # !__header_kmk__
[479]1718
Note: See TracBrowser for help on using the repository browser.