source: trunk/kBuild/header.kmk@ 3402

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

header.kmk: Added KMK_WITH_VERSION_COMPARE indicator mirroring 'versort' in KMK_FEATURES.

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