source: trunk/kBuild/header.kmk@ 3093

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

header.kmk: Fixed TOUCH_INT.

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