source: trunk/kBuild/header.kmk

Last change on this file was 3654, checked in by bird, 9 months ago

header.kmk: Always zap the IFS variable so it won't confuse kmk_ash.

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