source: trunk/kBuild/header.kmk@ 3343

Last change on this file since 3343 was 3308, checked in by bird, 6 years ago

header.kmk: Pick up DESTDIR if PATH_INS isn't defined. Keep weird DESTROOT as legacy.

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