source: trunk/kBuild/header.kmk@ 3058

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

header.kmk: Added OPENPAR and CLOSEPAR variables for use in macro invocations.

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