source: trunk/kBuild/header.kmk@ 3393

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

header.kmk,footer-pass2-compiling-targets.kmk: Introducing KMK_WITH_QUOTING as a simple 'quote' feature indicator. The SOURCES must be handled as a list of quoted files, or we cannot add chkstk.obj and such from an VC++ installation.

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