source: trunk/kBuild/header.kmk@ 3423

Last change on this file since 3423 was 3423, checked in by bird, 5 years ago

header.kmk: Complain if legacy variables like BUILD_TYPE and BUILD_TARGET_ARCH are seen on the command line. Removed temporary KBUILD_HOST* fallback definitions.

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