source: trunk/kBuild/header.kmk@ 3061

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

header.kmk: Added TOUCH tool macros.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 53.8 KB
RevLine 
[69]1# $Id: header.kmk 3061 2017-09-21 15:14:07Z 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: 3061 $ )
[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
[3061]772TOUCH_EXT := $(KBUILD_BIN_PATH)/kmk_touch$(HOSTSUFF_EXE)
773if $(KBUILD_KMK_REVISION) >= 3060
774TOUCH_INT := kmk_touch_append
775else
776TOUCH_INT := $(TOUCH_EXT)
777endif
778TOUCH := $(TOUCH_INT)
779
[380]780# Our default shell is the Almquist shell from *BSD.
[1504]781ASH := $(KBUILD_BIN_PATH)/kmk_ash$(HOSTSUFF_EXE)
[380]782MAKESHELL := $(ASH)
783SHELL := $(ASH)
784export SHELL MAKESHELL
785
[414]786# Symlinking is problematic on some platforms...
[380]787LN_SYMLINK := $(LN) -s
788
[2479]789# When copying to the staging area, use hard links to save time and space.
[2485]790ifndef KBUILD_NO_HARD_LINKING
[2512]791 INSTALL_STAGING := $(INSTALL) --hard-link-files-when-possible
792else
793 INSTALL_STAGING := $(INSTALL)
[2479]794endif
[743]795
[2479]796
[743]797#
798# Some Functions.
[748]799# The lower cased ones are either fallbacks or candidates for functions.c.
[743]800#
801
[130]802## ABSPATH - make paths absolute.
[129]803# This implementation is clumsy and doesn't resolve '..' and '.' components.
[73]804#
[129]805# @param $1 The paths to make absolute.
[696]806# @obsolete Use the GNU make function $(abspath) directly now.
[984]807ABSPATH = $(abspath $(1))$(warning ABSPATH is deprecated, use abspath directly!)
[353]808
[130]809## DIRDEP - make create directory dependencies.
810#
811# @param $1 The paths to the directories which must be created.
[353]812DIRDEP = $(foreach path,$(patsubst %/,%,$(1)),$(path)/)
[129]813
814## Cygwin kludge.
815# This converts /cygdrive/x/% to x:%.
816#
817# @param $1 The paths to make native.
818# @remark This macro is pretty much obsolete since we don't use cygwin base make.
819ifneq ($(patsubst /cygdrive/%,%,$(CURDIR)),$(CURDIR))
[743]820 CYGPATHMIXED = $(foreach path,$(1)\
[129]821 ,$(if $(patsubst /cygdrive/%,,$(path)),$(path),$(patsubst $(strip $(firstword $(subst /, ,$(patsubst /cygdrive/%,%,$(path)))))/%,$(strip $(firstword $(subst /, ,$(patsubst /cygdrive/%,%,$(path))))):/%,$(patsubst /cygdrive/%,%,$(path)))))
822else
[743]823 CYGPATHMIXED = $(1)
[129]824endif
825
[743]826## Removes the drive letter from a path (if it has one)
827# @param $1 the path
828no-drive = $(word $(words $(subst :, ,$(1))),$(subst :, ,$(1)))
[723]829
[743]830## Removes the root slash from a path (if it has one)
831# @param $1 the path
832no-root-slash = $(patsubst /%,%,$(1))
[723]833
[2488]834##
835# Similar to firstword, except it returns the value of first defined variable.
836# @param $1 list of variables to probe.
[2512]837define FIRST-DEFINED-VAR
838local .RETURN := $(strip $(firstdefined $1, value))
839endef
[2488]840
[743]841## Figure out where to put object files.
842# @param $1 real target name.
843# @param $2 normalized main target
[748]844TARGET_BASE = $(PATH_TARGET)/$(2)/$(call no-root-slash,$(call no-drive,$(1)))
[723]845
[743]846## Figure out where to put object files.
847# @param $1 normalized main target
848TARGET_PATH = $(PATH_TARGET)/$(1)
[723]849
[2223]850##
851# Checks if the specified short option ($1) is found in the flags ($2),
852# assuming getopt style options.
853#
854# @returns $3 if present, $4 not.
855#
856# @param $1 The option (single char!).
857# @param $2 The option arguments.
858# @param $3 Eval and return if present.
859# @param $4 Eval and return if not present.
860#
861# @todo May confuse option values starting with '-' for options.
862# @remarks Invoke like this: $(evalcall KB_FN_OPT_TEST_SHORT,d,$(flags),present,not-present)
863#
864define KB_FN_OPT_TEST_SHORT
865local options := $(translate $(strip $(filter -%,$(filter-out --%,$2))),$(SP)-,)
866local .RETURN := $(if-expr $(pos $1,$(options)) != 0,$3,$4)
867endef
[723]868
[2223]869##
870# Checks if the specified long option ($1) is found in the flags ($2),
871# assuming getopt style options.
[129]872#
[2223]873# @returns $3 if present, $4 not.
874#
875# @param $1 The long option, dashes included. No % chars.
876# @param $2 The option arguments.
877# @param $3 Eval and return if present.
878# @param $4 Eval and return if not present.
879#
880# @todo May confuse option values starting with '--' for options.
881# @remarks Invoke like this: $(evalcall KBFN_OPT_TEST_SHORT,--defined,$(flags),present,not-present)
882#
883define KB_FN_OPT_TEST_LONG
884local options := $(filter-out =delete=%,$(subst :, =delete=,$(subst =, =delete=,$2)))
885local .RETURN := $(if-expr "$(filter $1,$(options))" != "",$3,$4)
886endef
887
888##
889# Checks if the specified short ($1) or long ($2) option is found in the flags ($2),
890# assuming getopt style options.
891#
892# @returns $4 if present, $5 not.
893#
894# @param $1 The short option (single char!).
895# @param $2 The long option, dashes included. No % chars.
896# @param $3 The option arguments.
897# @param $4 Eval and return if present.
898# @param $5 Eval and return if not present.
899#
900# @todo May confuse option values starting with '--' for options.
901# @remarks Invoke like this: $(evalcall KB_FN_OPT_TEST_SHORT_LONG,d,--defined,$(flags),present,not-present)
902#
903define KB_FN_OPT_TEST_SHORT_LONG
904local short_options := $(translate $(strip $(filter -%,$(filter-out --%,$3))),$(SP)-,)
905local long_options := $(filter-out =delete=%,$(subst :, =delete=,$(subst =, =delete=,$3)))
906local .RETURN := $(if-expr $(pos $1,$(short_options)) != 0 || "$(filter $2,$(long_options))" != "",$4,$5)
907endef
908
[2434]909##
910# Make an assignment to a deprecated variable.
911#
912# @param $1 The variable name.
913# @param $2 The value.
914# @param $3 The variable to use instead.
915#
916ifdef KBUILD_WITH_DEPREATED_AS_ERROR
[2441]917 KB_FN_ASSIGN_DEPRECATED = $(eval $(subst :,$$(COLON),$1) = $2$$(error $1 is deprecated, use $3 instead))
[2434]918else
[2441]919 KB_FN_ASSIGN_DEPRECATED = $(eval $(subst :,$$(COLON),$1) = $2$$(warning $1 is deprecated, use $3 instead))
[2434]920endif
[2223]921
[2531]922##
[2533]923# Show an assertion message.
924#
925# @param $1 The assertion name.
926# @param $2 The details.
927#
928define KB_FN_ASSERT_MSG
929$(info !! kBuild $1 Assertion Failed !!)
930ifdef target
931 $(info !! target: $(target))
932 local varloc := $(where $(target))
933 if "$(varloc)" == "undefined"
934 local varloc := $(where $(target)_TEMPLATE)
935 endif
936 if "$(varloc)" == "undefined"
937 local varloc := $(where $(target)_SOURCES)
938 endif
939 if "$(varloc)" == "undefined"
940 local varloc := $(where $(target)_EXTENDS)
941 endif
942 if "$(varloc)" == "undefined"
943 local varloc := $(where target)
944 endif
945 ifneq ($(varloc),)
946 $(info !! location: $(varloc))
947 else
948 $(info !! probable location: $($(target)_DEFPATH)/Makefile.kmk)
949 endif
950endif
951$(info !! $2)
952$(error fixme)
953endef
954
955##
[2531]956# Throw an error if the given path $1 isn't absolute and assertions are enabled.
957#
958# @param $1 The name of the path variable to check.
959#
960ifdef KBUILD_INTERNAL_STRICT
961 KB_FN_ASSERT_ABSPATH = $(if-expr "$(abspath $($(strip $1)))" != "$(strip $($(strip $1)))",\
[2533]962 $(evalcall KB_FN_ASSERT_MSG,abspath,$1 is:$(NLTAB)'$($(strip $1))'$(NLTAB)expected:$(NLTAB)'$(abspath $($(strip $1)))'))
[2531]963else
964 KB_FN_ASSERT_ABSPATH :=
965endif
[2223]966
[2531]967
[2223]968#
[3030]969# Somewhat simple solution for automatic command dependencies.
970#
971
972##
973# Advanced version of KB_FN_AUTO_CMD_DEPS_COMMANDS_EX where you set
974# the dependency file name yourself.
975#
976# After or before the recipe do $(call KB_FN_AUTO_CMD_DEPS_EX,<recipe-target>,<dep-file>).
977#
978# @param 1 dep file.
979define KB_FN_AUTO_CMD_DEPS_COMMANDS_EX
980 %$(QUIET2)$(RM) -f -- "$1"
981 %$(QUIET2)$(APPEND) "$1" 'define AUTO_CMD_DEP_$(translate $@,:,_)_PREV_CMDS'
982 %$(QUIET2)$(APPEND) -c "$1" '$@'
983 %$(QUIET2)$(APPEND) "$1" 'endef'
984endef
985
986##
987# Advanced version of KB_FN_AUTO_CMD_DEPS
988#
989# @param 1 recipe name
990# @param 2 dep file.
991KB_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)
992
993##
994# $(call KB_FN_AUTO_CMD_DEPS_COMMANDS) as the first command in a recipe to
995# automatically generate command dependencies.
996# After or before the recipe do $(call KB_FN_AUTO_CMD_DEPS,<recipe-target>).
997define KB_FN_AUTO_CMD_DEPS_COMMANDS
998 %$(QUIET2)$(RM) -f -- "$@.auto-dep"
999 %$(QUIET2)$(APPEND) "$@.auto-dep" 'define AUTO_CMD_DEP_$(translate $@,:,_)_PREV_CMDS'
1000 %$(QUIET2)$(APPEND) -c "$@.auto-dep" '$@'
1001 %$(QUIET2)$(APPEND) "$@.auto-dep" 'endef'
1002endef
1003
1004##
1005# Call before or after defining a recipe that you want automatic command
1006# dependencies on. The recipe must start off by $(call KB_FN_AUTO_CMD_DEPS_COMMANDS).
1007#
1008# @param 1 recipe name
1009KB_FN_AUTO_CMD_DEPS = $(call KB_FN_AUTO_CMD_DEPS_EX,$1,$1.auto-dep)
1010
1011
1012#
[353]1013# Initialize some of the globals which the Config.kmk and
1014# others can add stuff to if they like for processing in the footer.
1015#
1016
[1416]1017## KBUILD_TEMPLATE_PATHS
[353]1018# List a paths (separated by space) where templates can be found.
[1416]1019KBUILD_TEMPLATE_PATHS :=
[353]1020
[1416]1021## KBUILD_TOOL_PATHS
[353]1022# List of paths (separated by space) where tools can be found.
[1416]1023KBUILD_TOOL_PATHS :=
[353]1024
[1416]1025## KBUILD_SDK_PATHS
[353]1026# List of paths (separated by space) where SDKs can be found.
[1416]1027KBUILD_SDK_PATHS :=
[353]1028
[1621]1029## KBUILD_UNIT_PATHS
1030# List of paths (separated by space) where units (USES) can be found.
1031KBUILD_UNIT_PATHS :=
1032
[1416]1033## KBUILD_DEFAULT_PATHS
1034# List of paths (separated by space) to search for stuff as a last resort.
1035KBUILD_DEFAULT_PATHS :=
1036
[353]1037## Proritized list of the default makefile when walking subdirectories.
1038# The user can overload this list.
1039DEFAULT_MAKEFILE := Makefile.kmk makefile.kmk Makefile makefile
1040
[1424]1041## KBUILD_SRC_HANDLERS
1042# The list of source handlers, pair of extension and handler.
1043# The user can overload this list to provide additional or custom
1044# handlers. On a per-target/template see SRC_HANDLERS.
1045KBUILD_SRC_HANDLERS := \
1046 .c:def_src_handler_c \
1047 .C:def_src_handler_c \
1048.cxx:def_src_handler_cxx \
1049.CXX:def_src_handler_cxx \
1050.cpp:def_src_handler_cxx \
1051.CPP:def_src_handler_cxx \
1052 .cc:def_src_handler_cxx \
1053 .CC:def_src_handler_cxx \
1054 .m:def_src_handler_objc \
[2356]1055 .M:def_src_handler_objcxx \
1056 .mm:def_src_handler_objcxx \
[1424]1057.asm:def_src_handler_asm \
1058.ASM:def_src_handler_asm \
1059 .s:def_src_handler_asm \
1060 .S:def_src_handler_asm \
1061 .rc:def_src_handler_rc \
1062.obj:def_src_handler_obj \
1063 .o:def_src_handler_obj \
[1435]1064.res:def_src_handler_obj
[980]1065
[640]1066## PROPS_TOOLS
[985]1067# This is a subset of PROPS_SINGLE.
[2356]1068PROPS_TOOLS := TOOL CTOOL CXXTOOL OBJCTOOL OBJCXXTOOL ASTOOL RCTOOL ARTOOL LDTOOL FETCHTOOL UNPACKTOOL PATCHTOOL
[640]1069
[353]1070## PROPS_SINGLE
1071# The list of non-accumulative target properties.
1072# A Config.kmk file can add it's own properties to this list and kBuild
[1400]1073# will do the necessary inheritance for templates, sdks, tools and targets.
[2475]1074PROPS_SINGLE := $(PROPS_TOOLS) TEMPLATE INSTTYPE INST STAGE NOINST BLD_TYPE BLD_TRG BLD_TRG_ARCH BLD_TRG_CPU FETCHDIR \
[2356]1075 OBJSUFF COBJSUFF CXXOBJSUFF OBJCOBJSUFF OBJCXXOBJSUFF ASOBJSUFF RCOBJSUFF SYSSUFF BINSUFF EXESUFF DLLSUFF LIBSUFF ARLIBSUFF \
[2523]1076 MODE UID GID LD_DEBUG DEBUG_INSTTYPE DEBUG_INST DEBUG_STAGE
[985]1077## PROPS_SINGLE_LNK
1078# Subset of PROPS_SINGLE which applies to all linkable targets.
[2550]1079PROPS_SINGLE_LNK := $(filter-out FETCHTOOL UNPACKTOOL PATCHTOOL FETCHDIR, $(PROPS_SINGLE))
[353]1080
1081## PROPS_DEFERRED
[889]1082# This list of non-accumulative target properties which are or may be
1083# functions, and thus should not be expanded until the very last moment.
[2537]1084PROPS_DEFERRED := INSTFUN INSTALLER PRE_CMDS POST_CMDS PRE_INST_CMDS POST_INST_CMDS \
1085 PRE_FILE_CMDS POST_FILE_CMDS PRE_SYMLINK_CMDS POST_SYMLINK_CMDS PRE_DIRECTORY_CMDS POST_DIRECTORY_CMDS \
1086 NAME SONAME
[353]1087
[660]1088## PROPS_ACCUMULATE_R
[748]1089# The list of accumulative target properties where the right most value/flag
[660]1090# is the 'most significant'.
[353]1091# A Config.kmk file can add it's own properties to this list and kBuild
1092# will do the necessary inheritance from templates to targets.
[660]1093PROPS_ACCUMULATE_R := \
[1702]1094 DEPS LNK_DEPS ORDERDEPS LNK_ORDERDEPS DEFS \
[985]1095 ARFLAGS \
[660]1096 CFLAGS CDEFS \
1097 CXXFLAGS CXXDEFS \
[1256]1098 OBJCFLAGS OBJCDEFS \
[2356]1099 OBJCXXFLAGS OBJCXXDEFS \
[660]1100 ASFLAGS ASDEFS \
1101 RCFLAGS RCDEFS \
1102 LDFLAGS \
[2483]1103 IDFLAGS IFFLAGS EXEC_IFFLAGS ISFLAGS \
[640]1104 FETCHFLAGS UNPACKFLAGS PATCHFLAGS
[985]1105## PROPS_ACCUMULATE_R_LNK
1106# Subset of PROPS_ACCUMULATE_R which applies to all linkable targets.
[2550]1107PROPS_ACCUMULATE_R_LNK := $(filter-out ARFLAGS LDFLAGS EXEC_IFFLAGS FETCHFLAGS UNPACKFLAGS PATCHFLAGS, $(PROPS_ACCUMULATE_R))
[353]1108
[660]1109## PROPS_ACCUMULATE
[748]1110# The list of accumulative target properties where the left most value/flag
[660]1111# is the 'most significant'.
1112# A Config.kmk file can add it's own properties to this list and kBuild
1113# will do the necessary inheritance from templates to targets.
1114PROPS_ACCUMULATE_L := \
[2483]1115 SDKS USES SOURCES EXEC_SOURCES SRC_HANDLERS INTERMEDIATES \
[2356]1116 INCS CINCS CXXINCS OBJCINCS OBJCXXINCS ASINCS RCINCS \
[897]1117 LIBS LIBPATH \
[985]1118 DIRS BLDDIRS CLEAN
1119## PROPS_ACCUMULATE_L_LNK
1120# Subset of PROPS_ACCUMULATE_L which applies to all linkable targets.
[2550]1121PROPS_ACCUMULATE_L_LNK := $(filter-out LIBS LIBPATH EXEC_SOURCES DIRS, $(PROPS_ACCUMULATE_L))
[353]1122
[662]1123## PROPS_ALL
1124# List of all the properties.
1125PROPS_ALL = $(PROPS_SINGLE) $(PROPS_DEFERRED) $(PROPS_ACCUMULATE_L) $(PROPS_ACCUMULATE_R)
[660]1126
[985]1127## @name Properties valid on programs (BLDPROGS and PROGRAMS)
1128## @{
1129PROPS_PROGRAMS_SINGLE := $(PROPS_SINGLE_LNK) LDTOOL EXESUFF
1130PROPS_PROGRAMS_DEFERRED := $(PROPS_DEFERRED)
1131PROPS_PROGRAMS_ACCUMULATE_R := $(PROPS_ACCUMULATE_R_LNK) LDFLAGS
1132PROPS_PROGRAMS_ACCUMULATE_L := $(PROPS_ACCUMULATE_L_LNK) LIBS LIBPATH
1133## @}
1134
1135## @name Properties valid on libraries (LIBRARIES and IMPORT_LIBS)
1136## @{
[989]1137PROPS_LIBRARIES_SINGLE := $(PROPS_SINGLE_LNK) ARTOOL LIBSUFF ARLIBSUFF LIBSUFF
[985]1138PROPS_LIBRARIES_DEFERRED := $(filter-out SONAME,$(PROPS_DEFERRED))
1139PROPS_LIBRARIES_ACCUMULATE_R := $(PROPS_ACCUMULATE_R_LNK) ARFLAGS
1140PROPS_LIBRARIES_ACCUMULATE_L := $(PROPS_ACCUMULATE_L_LNK)
1141## @}
1142
1143## @name Properties valid on dlls (DLLS)
1144## @{
1145PROPS_DLLS_SINGLE := $(PROPS_SINGLE_LNK) LDTOOL DLLSUFF LIBSUFF
1146PROPS_DLLS_DEFERRED := $(PROPS_DEFERRED)
1147PROPS_DLLS_ACCUMULATE_R := $(PROPS_ACCUMULATE_R_LNK) LDFLAGS
1148PROPS_DLLS_ACCUMULATE_L := $(PROPS_ACCUMULATE_L_LNK) LIBS LIBPATH
1149## @}
1150
[989]1151## @name Properties valid on system modules (SYSMODS)
1152## @{
1153PROPS_SYSMODS_SINGLE := $(PROPS_SINGLE_LNK) LDTOOL SYSSUFF
1154PROPS_SYSMODS_DEFERRED := $(PROPS_DEFERRED)
1155PROPS_SYSMODS_ACCUMULATE_R := $(PROPS_ACCUMULATE_R_LNK) LDFLAGS
1156PROPS_SYSMODS_ACCUMULATE_L := $(PROPS_ACCUMULATE_L_LNK) LIBS LIBPATH
1157## @}
1158
[2084]1159## @name Properties valid on misc binaries (MISCBINS)
1160## @{
1161PROPS_MISCBINS_SINGLE := $(PROPS_SINGLE_LNK) LDTOOL BINSUFF
1162PROPS_MISCBINS_DEFERRED := $(PROPS_DEFERRED)
1163PROPS_MISCBINS_ACCUMULATE_R := $(PROPS_ACCUMULATE_R_LNK) LDFLAGS
1164PROPS_MISCBINS_ACCUMULATE_L := $(PROPS_ACCUMULATE_L_LNK) LIBS LIBPATH
1165## @}
1166
[985]1167## @name Properties valid on installs (INSTALLS)
1168## @{
[2550]1169PROPS_INSTALLS_SINGLE := TOOL TEMPLATE INSTTYPE INST STAGE NOINST BLD_TYPE BLD_TRG BLD_TRG_ARCH BLD_TRG_CPU MODE UID GID
[2537]1170PROPS_INSTALLS_DEFERRED := INSTFUN INSTALLER PRE_FILE_CMDS POST_FILE_CMDS PRE_SYMLINK_CMDS POST_SYMLINK_CMDS \
1171 PRE_DIRECTORY_CMDS POST_DIRECTORY_CMDS
[2483]1172PROPS_INSTALLS_ACCUMULATE_R := DEPS ORDERDEPS GOALS INST_ONLY_GOALS STAGE_ONLY_GOALS IFFLAGS EXEC_IFFLAGS
1173PROPS_INSTALLS_ACCUMULATE_L := SOURCES EXEC_SOURCES DIRS CLEAN
[985]1174## @}
1175
[2475]1176## @name Properties valid on fetches (FETCHES)
[985]1177## @{
[1400]1178PROPS_FETCHES_SINGLE := TOOL TEMPLATE FETCHTOOL UNPACKTOOL PATCHTOOL INST FETCHDIR
[985]1179PROPS_FETCHES_DEFERRED :=
1180PROPS_FETCHES_ACCUMULATE_R := FETCHFLAGS UNPACKFLAGS PATCHFLAGS
[1613]1181PROPS_FETCHES_ACCUMULATE_L := SOURCES CLEAN
[985]1182## @}
1183
[2274]1184## KBUILD_COMPILE_CATEGTORIES
1185# Tools categories for compiling.
1186KBUILD_COMPILE_CATEGTORIES := AS C CXX OBJC OBJCXX RC
[985]1187
[2274]1188## KBUILD_GENERIC_CATEGORIES
1189# Generic tool categories.
1190KBUILD_GENERIC_CATEGORIES := FETCH UNPACK PATCH $(addprefix LINK_,LIBRARY PROGRAM DLL SYSMOD MISCBIN)
1191
1192## PROPS_TOOLS_ONLY
1193# Properties found only on tools.
1194# This is expanded in a deferred manner, so it will pick up changes made to
1195# KBUILD_COMPILE_CATEGTORIES and KBUILD_GENERIC_CATEGORIES made by units.
1196PROPS_TOOLS_ONLY = \
1197 $(foreach cat, $(KBUILD_COMPILE_CATEGTORIES), \
1198 COMPILE_$(cat)_CMDS \
1199 COMPILE_$(cat)_OUTPUT \
1200 COMPILE_$(cat)_OUTPUT_MAYBE \
1201 COMPILE_$(cat)_DEPEND \
1202 COMPILE_$(cat)_DEPORD \
1203 COMPILE_$(cat)_USES_KOBJCACHE ) \
1204 $(foreach cat, $(KBUILD_GENERIC_CATEGORIES), \
1205 $(cat)_CMDS \
1206 $(cat)_OUTPUT \
1207 $(cat)_OUTPUT_MAYBE \
1208 $(cat)_DEPEND \
1209 $(cat)_DEPORD ))
1210
1211
[353]1212#
[748]1213# Here is a special 'hack' to prevent innocent environment variables being
1214# picked up and treated as properties. (The most annoying example of why
[662]1215# this is necessary is the Visual C++ commandline with it's LIBPATH.)
1216#
[748]1217# Define KBUILD_DONT_KILL_ENV_PROPS in the env. or on the commandline to
[662]1218# disable this 'hack'.
1219#
1220ifndef KBUILD_DONT_KILL_ENV_PROPS
1221
1222define def_nuke_environment_prop
1223ifeq ($(origin $(prop)),environment)
1224$(prop) =
1225endif
1226endef
[762]1227$(foreach prop, $(PROPS_ALL) \
[2084]1228 FETCHES PATCHES BLDPROGS LIBRARIES IMPORT_LIBS DLLS PROGRAMS SYSMODS MISCBINS INSTALLS OTHERS \
[897]1229 SUBDIRS MAKEFILES BLDDIRS \
[762]1230 ,$(eval $(value def_nuke_environment_prop)))
[662]1231
[897]1232endif # KBUILD_DONT_KILL_ENV_PROPS
[662]1233
1234
1235#
[353]1236# Pass configuration.
1237#
1238# The PASS_<passname>_trgs variable is listing the targets.
1239# The PASS_<passname>_vars variable is listing the target variables.
1240# The PASS_<passname>_pass variable is the lowercased passname.
1241#
1242
[640]1243## PASS: fetches
1244# This pass fetches and unpacks things needed to complete the build.
1245PASS_FETCHES := Fetches
1246PASS_FETCHES_trgs :=
1247PASS_FETCHES_vars := _FETCHES
1248PASS_FETCHES_pass := fetches
1249
1250## PASS: patches
1251# This pass applies patches.
1252PASS_PATCHES := Patches
1253PASS_PATCHES_trgs :=
1254PASS_PATCHES_vars := _PATCHES
1255PASS_PATCHES_pass := patches
1256
[353]1257## PASS: bldprogs
1258# This pass builds targets which are required for building the rest.
1259PASS_BLDPROGS := Build Programs
1260PASS_BLDPROGS_trgs :=
1261PASS_BLDPROGS_vars := _BLDPROGS
1262PASS_BLDPROGS_pass := bldprogs
1263
1264## PASS: libraries
1265# This pass builds library targets.
1266PASS_LIBRARIES := Libraries
1267PASS_LIBRARIES_trgs :=
1268PASS_LIBRARIES_vars := _LIBS _IMPORT_LIBS _OTHER_LIBRARIES
1269PASS_LIBRARIES_pass := libraries
1270
1271## PASS: binaries
1272# This pass builds dll targets.
1273PASS_DLLS := DLLs
1274PASS_DLLS_trgs :=
1275PASS_DLLS_vars := _DLLS _OTHER_DLLS
1276PASS_DLLS_pass := dlls
1277
1278## PASS: binaries
1279# This pass builds binary targets, i.e. programs, system modules and stuff.
1280PASS_BINARIES := Programs
1281PASS_BINARIES_trgs :=
[2084]1282PASS_BINARIES_vars := _PROGRAMS _SYSMODS _MISC_BINS _OTHER_BINARIES
[353]1283PASS_BINARIES_pass := binaries
1284
1285## PASS: others
1286# This pass builds other targets.
1287PASS_OTHERS := Other Stuff
1288PASS_OTHERS_trgs :=
1289PASS_OTHERS_vars := _OTHERS
1290PASS_OTHERS_pass := others
1291
[2475]1292## PASS: staging
[353]1293# This pass installs the built entities to a sandbox area.
[1646]1294## @todo split this up into build install (to sandbox) and real installation.
[2475]1295PASS_STAGING := Staging
1296PASS_STAGING_trgs :=
[2523]1297PASS_STAGING_vars := _STAGE_DIRS _INSTALLS _STAGE_FILES _DEBUG_STAGE_DIRS _DEBUG_STAGE_FILES
[2475]1298PASS_STAGING_pass := staging
1299
1300## PASS: install
1301# This pass installs the built entities to where they will be used (using
1302# DESTROOT or PATH_INS to indicate where this is).
[353]1303PASS_INSTALLS := Install
1304PASS_INSTALLS_trgs :=
[2523]1305PASS_INSTALLS_vars := _INSTALLS_DIRS _INSTALLS_FILES _DEBUG_INSTALL_DIRS _DEBUG_INSTALL_FILES
[353]1306PASS_INSTALLS_pass := installs
1307
[1646]1308## PASS: testing
1309# This pass processes custom rules for executing tests.
1310PASS_TESTING := Tests
1311PASS_TESTING_trgs :=
1312PASS_TESTING_vars := _TESTING
1313PASS_TESTING_pass := testing
1314
[353]1315## PASS: packing
1316# This pass processes custom packing rules.
1317PASS_PACKING := Packing
[414]1318PASS_PACKING_trgs :=
[417]1319PASS_PACKING_vars := _PACKING
[353]1320PASS_PACKING_pass := packing
1321
1322## PASS: clean
1323# This pass removes all generated files.
1324PASS_CLEAN := Clean
1325PASS_CLEAN_trgs := do-clean
1326PASS_CLEAN_vars :=
1327PASS_CLEAN_pass := clean
1328
1329## PASS: nothing
1330# This pass just walks the tree.
1331PASS_NOTHING := Nothing
1332PASS_NOTHING_trgs := do-nothing
1333PASS_NOTHING_vars :=
1334PASS_NOTHING_pass := nothing
1335
1336## DEFAULT_PASSES
1337# The default passes and their order.
[2475]1338DEFAULT_PASSES := BLDPROGS LIBRARIES DLLS BINARIES OTHERS STAGING
[353]1339
1340## PASSES
1341# The passes that should be defined. This must include
1342# all passes mentioned by DEFAULT_PASSES.
[2475]1343PASSES := FETCHES PATCHES $(DEFAULT_PASSES) INSTALLS TESTING PACKING CLEAN NOTHING
[353]1344
1345
1346#
[984]1347# Check for --pretty-command-printing before including the Config.kmk
1348# so that anyone overriding the message macros can take the implied
1349# verbosity level change into account.
1350#
1351ifndef KBUILD_VERBOSE
1352 ifndef KBUILD_QUIET
[1562]1353 ifeq ($(KMK_OPTS_PRETTY_COMMAND_PRINTING),1)
[984]1354 export KBUILD_VERBOSE := 2
1355 endif
1356 endif
1357endif
1358
1359
1360#
[1418]1361# Legacy variable translation.
1362# These will be eliminated when switching to the next version.
1363#
1364ifdef USE_KOBJCACHE
1365 ifndef KBUILD_USE_KOBJCACHE
1366 export KBUILD_USE_KOBJCACHE := $(USE_KOBJCACHE)
1367 endif
1368endif
1369
1370
1371#
[2559]1372# Library path searching hints (target OS + arch).
1373#
1374# KBUILD_LIB_SEARCH_SUBS - Subdirs typically containing the right libraries.
1375# KBUILD_LIB_SEARCH_ROOTS - Roots to search for library subdirs.
1376# KBUILD_LIB_SEARCH_PATHS - ROOTS + SUBS.
1377#
1378ifeq ($(KBUILD_TARGET),darwin)
1379 KBUILD_LIB_SEARCH_ROOTS := \
1380 /usr/ \
1381 /Developer/usr/
1382 KBUILD_LIB_SEARCH_SUBS := lib/
1383
1384else if1of ($(KBUILD_TARGET), freebsd netbsd openbsd dragonfly)
1385 KBUILD_LIB_SEARCH_ROOTS := \
1386 / \
1387 /usr/ \
1388 /usr/local/
1389 KBUILD_LIB_SEARCH_SUBS := lib/
1390
1391else ifeq ($(KBUILD_TARGET),linux)
[2689]1392 ifeq ($(realpath /bin),/usr/bin)
[2688]1393 KBUILD_LIB_SEARCH_ROOTS := \
1394 /usr/ \
1395 / \
1396 /usr/local/
1397 else
1398 KBUILD_LIB_SEARCH_ROOTS := \
1399 / \
1400 /usr/ \
1401 /usr/local/
1402 endif
[2559]1403 ifeq ($(KBUILD_TARGET_ARCH),amd64)
1404 KBUILD_LIB_SEARCH_SUBS := \
1405 lib/x86_64-linux-gnu/ \
1406 lib64/ \
1407 lib/
1408 else ifeq ($(KBUILD_TARGET_ARCH),x86)
1409 KBUILD_LIB_SEARCH_SUBS := \
1410 lib/i686-linux-gnu/ \
1411 lib/i386-linux-gnu/ \
1412 lib32/ \
1413 lib/
1414 else
1415 KBUILD_LIB_SEARCH_SUBS := lib/
1416 endif
1417
1418else ifeq ($(KBUILD_TARGET),solaris)
1419 KBUILD_LIB_SEARCH_ROOTS := \
1420 / \
1421 /usr/ \
1422 /usr/sfw/ \
1423 /usr/local/ \
1424 /sw/
1425 ifeq ($(KBUILD_TARGET_ARCH),amd64)
1426 KBUILD_LIB_SEARCH_SUBS := lib/amd64/ lib/
1427 else ifeq ($(KBUILD_TARGET_ARCH),sparc64)
1428 KBUILD_LIB_SEARCH_SUBS := lib/sparcv9/ lib/
1429 else
1430 KBUILD_LIB_SEARCH_SUBS := lib/
1431 endif
1432
1433else
1434 KBUILD_LIB_SEARCH_SUBS :=
1435 KBUILD_LIB_SEARCH_ROOTS :=
1436endif
[2562]1437KBUILD_LIB_SEARCH_PATHS := $(foreach root, $(KBUILD_LIB_SEARCH_ROOTS), $(addprefix $(root),$(KBUILD_LIB_SEARCH_SUBS)))
[2559]1438
1439
1440#
[69]1441# This is how we find the closest config.kmk.
1442# It's a little hacky but I think it works fine.
[70]1443#
1444_CFGDIR := .
[78]1445_CFGFILES := ./Config.kmk ./config.kmk
[69]1446define def_include_config
[78]1447$(eval _CFGDIR := $(_CFGDIR)/$(dir))
1448_CFGFILES += $(_CFGDIR)/Config.kmk $(_CFGDIR)/config.kmk
[69]1449endef
1450# walk down the _RELATIVE_ path specified by DEPTH.
[78]1451$(foreach dir,$(subst /, ,$(DEPTH)), $(eval $(def_include_config)) )
[69]1452# add the default config file.
[78]1453_CFGFILE := $(firstword $(wildcard $(_CFGFILES) $(FILE_KBUILD_CONFIG)))
[69]1454_CFGFILES :=
1455_CFGDIR :=
[416]1456ifeq ($(_CFGFILE),)
1457$(error kBuild: no Config.kmk file found! Check the DEPTH: DEPTH='$(DEPTH)' PATH_CURRENT='$(PATH_CURRENT)')
1458endif
[69]1459
1460# Include the config.kmk we found file (or the default one).
[988]1461ifdef KBUILD_PROFILE_SELF
[2008]1462 $(evalcall def_profile_self, including $(_CFGFILE))
[988]1463 include $(_CFGFILE)
[2008]1464 $(evalcall def_profile_self, included $(_CFGFILE))
[988]1465else
1466 include $(_CFGFILE)
1467endif
1468
1469
1470
[696]1471#
[874]1472# Finalize a the central path variables now that we've included the Config.kmk file.
1473#
1474# This prevents some trouble when users override the defaults for these
1475# variables and uses relative paths or paths with incorrect case.
1476#
[1692]1477PATH_OUT_BASE := $(abspath $(PATH_OUT_BASE))
[2475]1478PATH_OUT := $(abspath $(PATH_OUT))
1479PATH_OBJ := $(abspath $(PATH_OBJ))
1480PATH_TARGET := $(abspath $(PATH_TARGET))
1481PATH_INS := $(abspath $(PATH_INS))
1482PATH_STAGE := $(abspath $(PATH_STAGE))
[874]1483
[2475]1484# Finalize the install and staging directory layouts.
1485define def_kbuild_finalize_inst
1486local val := $(strip $($(y)_$(x)))
1487ifeq ($(val),)
1488 $(error kBuild: '$(y)_$(x)' is set to an empty value.)
1489endif
1490ifneq ($(words $(val)),1)
1491 $(error kBuild: The '$(y)_$(x)' value '$(val)' should not contain spaces.)
1492endif
1493ifneq ($(pos \,$(val)), 0)
1494 $(error kBuild: The '$(y)_$(x)' value '$(val)' contains DOS slashes: not allowed.)
1495endif
1496ifneq ($(pos $(COLON),$(val)), 0)
1497 $(error kBuild: The '$(y)_$(x)' value '$(val)' contains colon: not allowed.)
1498endif
1499ifneq ($(substr $(val),-1), /)
1500 $(error kBuild: The '$(y)_$(x)' value '$(val)' has no trailing slash.)
1501endif
1502if $(pos /../,$(val)) != 0 || "$(substr $(val), 3)" == "../"
1503 $(error kBuild: The '$(y)_$(x)' value '$(val)' contains dot-dot escape.)
1504endif
1505$($(y)_$(x) := $(val)
[2479]1506
1507local val := $(strip $(PATH_$(y)_$(x)))
1508ifeq ($(val),)
1509 $(error kBuild: 'PATH_$(y)_$(x)' is set to an empty value.)
1510endif
1511PATH_$(y)_$(x) := $(val)
[2475]1512endef
[2479]1513$(foreach y, INST STAGE, $(foreach x, $(KBUILD_INST_PATHS), $(evalcall def_kbuild_finalize_inst)))
[874]1514
[2724]1515# No abspath for devtools since they might've been referenced already and we
1516# don't want conflicting variable expansions.
1517KBUILD_DEVTOOLS := $(KBUILD_DEVTOOLS)
1518KBUILD_DEVTOOLS_TRG := $(KBUILD_DEVTOOLS_TRG)
1519KBUILD_DEVTOOLS_TRG_ALT := $(KBUILD_DEVTOOLS_TRG_ALT)
1520KBUILD_DEVTOOLS_HST := $(KBUILD_DEVTOOLS_HST)
1521KBUILD_DEVTOOLS_HST_ALT := $(KBUILD_DEVTOOLS_HST_ALT)
[2475]1522
[2724]1523
[874]1524#
[788]1525# Setup the message style. The default one is inlined.
[776]1526#
[788]1527# See kBuild/msgstyles for more styles or use KBUILD_MSG_STYLE_PATHS
1528# to create your own message style.
1529#
[776]1530KBUILD_MSG_STYLE ?= default
1531ifeq ($(KBUILD_MSG_STYLE),default)
1532 #
1533 # The 'default' style.
1534 #
1535
1536 ## Fetch starting.
1537 # @param 1 Target name.
1538 MSG_FETCH ?= $(call MSG_L1,Fetching $1...)
1539 ## Re-fetch starting.
1540 # @param 1 Target name.
1541 MSG_REFETCH ?= $(call MSG_L1,Re-fetching $1...)
1542 ## Downloading a fetch component.
1543 # @param 1 Target name.
1544 # @param 2 The source URL.
1545 # @param 3 The destination file name.
1546 MSG_FETCH_DL ?= $(call MSG_L1,Downloading $1 - $2,=> $3)
1547 ## Checking a fetch component.
1548 # @param 1 Target name.
1549 # @param 2 The source URL.
1550 # @param 3 The destination file name.
1551 MSG_FETCH_CHK?= $(call MSG_L1,Checking $1 - $3, ($2))
1552 ## Unpacking a fetch component.
1553 # @param 1 Target name.
1554 # @param 2 The archive file name.
1555 # @param 3 The target directory.
1556 MSG_FETCH_UP ?= $(call MSG_L1,Unpacking $1 - $2 => $3)
1557 ## Fetch completed.
1558 # @param 1 Target name.
1559 MSG_FETCH_OK ?= $(call MSG_L1,Successfully fetched $1)
1560 ## Unfetch a fetch target.
1561 # @param 1 Target name.
1562 MSG_UNFETCH ?= $(call MSG_L1,Unfetching $1...)
1563 ## Compiling a source file.
1564 # @param 1 Target name.
1565 # @param 2 The source filename.
1566 # @param 3 The primary link output file name.
[1256]1567 # @param 4 The source type (C,CXX,OBJC,AS,RC,++).
[776]1568 MSG_COMPILE ?= $(call MSG_L1,Compiling $1 - $2,=> $3)
[890]1569 ## Tool
1570 # @param 1 The tool name (bin2c,...)
1571 # @param 2 Target name.
1572 # @param 3 The source filename.
1573 # @param 4 The primary output file name.
1574 MSG_TOOL ?= $(call MSG_L1,$1 $2 - $3,=> $4)
1575 ## Generate a file, typically a source file.
1576 # @param 1 Target name if applicable.
1577 # @param 2 Output file name.
1578 # @param 3 What it's generated from
1579 MSG_GENERATE ?= $(call MSG_L1,Generating $(if $1,$1 - )$2,$(if $3,from $3))
[776]1580 ## Linking a bldprog/dll/program/sysmod target.
1581 # @param 1 Target name.
1582 # @param 2 The primary link output file name.
1583 # @param 3 The link tool operation (LINK_LIBRARY,LINK_PROGRAM,LINK_DLL,LINK_SYSMOD,++).
1584 MSG_LINK ?= $(call MSG_L1,Linking $1,=> $2)
[844]1585 ## Merging a library into the target (during library linking).
1586 # @param 1 Target name.
1587 # @param 2 The output library name.
1588 # @param 3 The input library name.
[845]1589 MSG_AR_MERGE ?= $(call MSG_L1,Merging $3 into $1, ($2))
[776]1590 ## Creating a directory (build).
1591 # @param 1 Directory name.
1592 MSG_MKDIR ?= $(call MSG_L2,Creating directory $1)
1593 ## Cleaning.
1594 MSG_CLEAN ?= $(call MSG_L1,Cleaning...)
1595 ## Nothing.
1596 MSG_NOTHING ?= $(call MSG_L1,Did nothing in $(CURDIR))
1597 ## Pass
1598 # @param 1 The pass name.
1599 MSG_PASS ?= $(call MSG_L1,Pass - $1)
1600 ## Installing a bldprog/lib/dll/program/sysmod target.
1601 # @param 1 Target name.
1602 # @param 2 The source filename.
1603 # @param 3 The destination file name.
1604 MSG_INST_TRG ?= $(call MSG_L1,Installing $1 => $3)
1605 ## Installing a file (install target).
1606 # @param 1 The source filename.
1607 # @param 2 The destination filename.
1608 MSG_INST_FILE?= $(call MSG_L1,Installing $2,(<= $1))
1609 ## Installing a symlink.
1610 # @param 1 Symlink
1611 # @param 2 Link target
1612 MSG_INST_SYM ?= $(call MSG_L1,Installing symlink $1,=> $2)
1613 ## Installing a directory.
1614 # @param 1 Directory name.
1615 MSG_INST_DIR ?= $(call MSG_L1,Installing directory $1)
1616
[788]1617else
[1504]1618 _KBUILD_MSG_STYLE_FILE := $(firstword $(foreach path, $(KBUILD_MSG_STYLE_PATHS) $(KBUILD_PATH)/msgstyles, $(wildcard $(path)/$(KBUILD_MSG_STYLE).kmk)))
[788]1619 ifneq ($(_KBUILD_MSG_STYLE_FILE),)
1620 include $(_KBUILD_MSG_STYLE_FILE)
[776]1621 else
[788]1622 $(error kBuild: Can't find the style setup file for KBUILD_MSG_STYLE '$(KBUILD_MSG_STYLE)')
[776]1623 endif
1624endif
1625
1626
1627#
[696]1628# Message macros.
1629#
[748]1630# This is done after including Config.kmk as to allow for
[696]1631# KBUILD_QUIET and KBUILD_VERBOSE to be configurable.
1632#
1633ifdef KBUILD_QUIET
[776]1634 # No output
[696]1635 QUIET := @
1636 QUIET2:= @
1637 MSG_L1 =
1638 MSG_L2 =
1639else
1640 ifndef KBUILD_VERBOSE
[776]1641 # Default output level.
1642 QUIET := @
1643 QUIET2 := @
[1496]1644 MSG_L1 ?= %@$(ECHO) "kBuild: $1"
[776]1645 MSG_L2 =
1646 else ifeq ($(KBUILD_VERBOSE),1)
1647 # A bit more output
1648 QUIET := @
1649 QUIET2 := @
[1496]1650 MSG_L1 ?= %@$(ECHO) "kBuild: $1 $2"
[776]1651 MSG_L2 =
1652 else ifeq ($(KBUILD_VERBOSE),2)
1653 # Lot more output
1654 QUIET :=
1655 QUIET2 := @
[1496]1656 MSG_L1 ?= %@$(ECHO) "kBuild: $1 $2"
1657 MSG_L2 ?= %@$(ECHO) "kBuild: $1"
[696]1658 else
1659 # maximal output.
[776]1660 QUIET :=
1661 QUIET2 :=
[1496]1662 MSG_L1 ?= %@$(ECHO) "kBuild: $1 $2"
1663 MSG_L2 ?= %@$(ECHO) "kBuild: $1"
[696]1664 endif
1665endif
1666
[776]1667
[3031]1668##
1669# An internal define used by subheader.kmk, subfooter.kmk, and
1670# KB_FN_PASS_0_ON_TARGET.
[1403]1671#
[3031]1672# @param target The target to process.
[2763]1673#
1674define def_subfooter_header_target_pass
1675 ifndef $(target)_PATH
1676 ifndef $(target)_DEFPATH
1677 $(target)_DEFPATH := $(PATH_SUB_CURRENT)
1678 endif
1679 $(call KB_FN_ASSIGN_DEPRECATED,$(target)_PATH,$($(target)_DEFPATH), $(target)_DEFPATH)
1680 else ifndef $(target)_DEFPATH
1681 $(target)_DEFPATH := $($(target)_PATH)
1682 endif
1683 ifndef $(target)_MAKEFILE
1684 $(target)_MAKEFILE := $(MAKEFILE_CURRENT)
1685 endif
1686 ifndef $(target)_0_OUTDIR
1687 $(target)_0_OUTDIR := $(call TARGET_PATH,$(target))
1688 $(call KB_FN_ASSIGN_DEPRECATED,PATH_$(target),$($(target)_0_OUTDIR), $(target)_0_OUTDIR)
1689 endif
1690endef
1691
[3031]1692##
1693# Function to call to set _0_OUTDIR, _DEFPATH, and _MAKEFILE earlier than subfooter.
1694# Can be used to avoid exploiting double expansion.
1695#
1696# @param 1 The target name.
1697KB_FN_DO_PASS0_ON_TARGET = $(foreach target,$1,$(if-expr defined($(target)_0_OUTDIR),,$(evalval def_subfooter_header_target_pass)))
[2763]1698
[3031]1699
[2763]1700#
[1504]1701# Validate any KBUILD_BLD_TYPES additions and finally the KBUILD_TYPE.
[1403]1702#
1703if1of ($(KBUILD_BLD_TYPES), $(KBUILD_OSES))
1704 $(error kBuild: found KBUILD_BLD_TYPES in KBUILD_OSES!)
1705endif
1706if1of ($(KBUILD_BLD_TYPES), $(KBUILD_ARCHES))
1707 $(error kBuild: found KBUILD_BLD_TYPES in KBUILD_ARCHES!)
1708endif
1709if1of ($(KBUILD_OSES), $(KBUILD_ARCHES))
1710 $(error kBuild: found KBUILD_OSES in KBUILD_ARCHES!)
1711endif
[1504]1712ifn1of ($(KBUILD_TYPE), $(KBUILD_BLD_TYPES))
1713 $(error kBuild: KBUILD_TYPE(=$(KBUILD_TYPE)) is not found in KBUILD_BLD_TYPES(=$(KBUILD_BLD_TYPES))!)
[1403]1714endif
1715
1716
[2887]1717#
1718# Mark the output and temporary directories as volatile on windows.
1719#
1720# This automatically means the directories not listed here are considered
1721# static and won't be invalidated once we start running compile jobs.
1722#
1723ifeq ($(KBUILD_HOST),win)
1724 if $(KBUILD_KMK_REVISION) >= 2886
1725 $(dircache-ctl volatile, $(PATH_OUT_BASE), $(PATH_OUT), $(TEMP), $(TMP), $(TMPDIR), $(TMP))
1726 endif
1727endif
[1403]1728
[2887]1729
[988]1730ifdef KBUILD_PROFILE_SELF
[2008]1731 $(evalcall def_profile_self, end of header.kmk)
1732 _KBUILD_TS_HEADER_END := $(_KBUILD_TS_PREV)
[988]1733endif
1734
[69]1735# end-of-file-content
[72]1736__header_kmk__ := 1
[2688]1737endif # !__header_kmk__
[479]1738
Note: See TracBrowser for help on using the repository browser.