source: trunk/kBuild/header.kmk@ 3413

Last change on this file since 3413 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
Line 
1# $Id: header.kmk 3402 2020-07-06 09:29:00Z 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: 3402 $ )
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 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
202KBUILD_ARCHES_32 := x86 arm32 hppa32 m68k mips32 ppc32 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 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
247else
248 if1of ($(KBUILD_TYPE), $(KBUILD_OSES) $(KBUILD_ARCHES))
249 $(error kBuild: The KBUILD_TYPE value '$(KBUILD_TYPE)' is an OS or architecture!)
250 endif
251 ifneq (.$(words $(KBUILD_TYPE)).$(KBUILD_TYPE).,.1.$(strip $(KBUILD_TYPE)).)
252 $(error kBuild: The KBUILD_TYPE value '$(KBUILD_TYPE)' contains spaces/tabs!)
253 endif
254endif
255
256
257#
258# Host platform legacy
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#
273# Assert valid build platform variables.
274#
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#
278ifneq (.$(words $(KBUILD_HOST)).$(KBUILD_HOST).,.1.$(strip $(KBUILD_HOST)).)
279 $(error kBuild: The KBUILD_HOST value '$(KBUILD_HOST)' contains spaces/tabs!)
280endif
281ifneq ($(words $(filter $(KBUILD_HOST),$(KBUILD_OSES))),1)
282 $(error kBuild: KBUILD_HOST value '$(KBUILD_HOST)' is not recognized (valid: $(KBUILD_OSES)))
283endif
284
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!)
287endif
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)))
290endif
291
292ifeq ($(strip $(KBUILD_HOST_CPU)),)
293 KBUILD_HOST_CPU := blend
294else
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!)
297 endif
298 if1of ($(KBUILD_HOST_CPU), $(KBUILD_OSES) $(KBUILD_ARCHES))
299 $(error kBuild: The KBUILD_HOST_CPU value '$(KBUILD_HOST_CPU)' was found in the OS or architecture keywords!)
300 endif
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!)
303 endif
304endif
305
306
307#
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)
319 $(error kBuild: KBUILD_TARGET and BUILD_TARGET disagree)
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)
334 $(error kBuild: KBUILD_TARGET_ARCH and BUILD_TARGET_ARCH disagree)
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)
349 $(error kBuild: KBUILD_TARGET_CPU and BUILD_TARGET_CPU disagree)
350 endif
351 endif
352endif
353override BUILD_TARGET_CPU = $(KBUILD_TARGET_CPU)
354
355
356#
357# Assert or set default target platform.
358# When not defined use the corresponding KBUILD_HOST value.
359#
360ifndef KBUILD_TARGET
361 KBUILD_TARGET := $(KBUILD_HOST)
362else
363 ifneq (.$(words $(KBUILD_TARGET)).$(KBUILD_TARGET).,.1.$(strip $(KBUILD_TARGET)).)
364 $(error kBuild: The KBUILD_TARGET value '$(KBUILD_TARGET)' contains spaces/tabs!)
365 endif
366 ifneq ($(words $(filter $(KBUILD_TARGET),$(KBUILD_OSES))),1)
367 $(error kBuild: KBUILD_TARGET value '$(KBUILD_TARGET)' is not recognized (valid: $(KBUILD_OSES)))
368 endif
369endif
370
371ifndef KBUILD_TARGET_ARCH
372 KBUILD_TARGET_ARCH := $(KBUILD_HOST_ARCH)
373else
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!)
376 endif
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)))
379 endif
380endif
381
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)
387 else
388 KBUILD_TARGET_CPU := blend
389 endif
390else
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!)
393 endif
394 if1of ($(KBUILD_TARGET_CPU), $(KBUILD_OSES) $(KBUILD_ARCHES))
395 $(error kBuild: The KBUILD_TARGET_CPU value was found in the OS or architecture keywords!)
396 endif
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!)
399 endif
400endif
401
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)
405
406
407#
408# Feature indicators.
409#
410
411## File quoting functions.
412if1of (quote, $(KMK_FEATURES))
413 KMK_WITH_QUOTING := 1
414endif
415
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
426# Adjust DEPTH first.
427DEPTH := $(strip $(DEPTH))
428ifeq ($(DEPTH),)
429 DEPTH := .
430endif
431
432## PATH_CURRENT is the current directory (getcwd).
433PATH_CURRENT := $(abspath $(CURDIR))
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.
440ifneq ($(strip $(SUB_DEPTH)),)
441 SUB_DEPTH := $(strip $(SUB_DEPTH))
442 PATH_SUB_ROOT := $(abspath $(PATH_CURRENT)/$(SUB_DEPTH))
443else
444 PATH_SUB_ROOT := $(PATH_CURRENT)
445endif
446
447## CURSUBDIR is PATH_SUB_ROOT described relative to PATH_ROOT.
448# This variable is used to determin where the object files and other output goes.
449ifneq ($(PATH_ROOT),$(PATH_SUB_ROOT))
450 CURSUBDIR := $(patsubst $(PATH_ROOT)/%,%,$(PATH_SUB_ROOT))
451else
452 CURSUBDIR := .
453endif
454
455# Install directory layout. Relative to PATH_INS.
456KBUILD_INST_PATHS := BIN DLL SYS LIB DOC DEBUG SBIN LIBEXEC SHARE
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
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
492# Output directories.
493ifndef PATH_OUT_BASE
494 PATH_OUT_BASE := $(PATH_ROOT)/out
495endif
496ifndef PATH_OUT
497 ifdef BUILD_TARGET_SUB # (BUILD_TARGET_SUB is not currently recognized by kBuild in any other places - obsolete)
498 PATH_OUT = $(PATH_OUT_BASE)/$(KBUILD_TARGET).$(KBUILD_TARGET_ARCH).$(BUILD_TARGET_SUB)/$(KBUILD_TYPE)
499 else
500 PATH_OUT = $(PATH_OUT_BASE)/$(KBUILD_TARGET).$(KBUILD_TARGET_ARCH)/$(KBUILD_TYPE)
501 endif
502endif # !define PATH_OUT
503PATH_OBJCACHE = $(PATH_OUT_BASE)/kObjCache
504PATH_OBJ = $(PATH_OUT)/obj
505PATH_TARGET = $(PATH_OBJ)/$(CURSUBDIR)
506PATH_STAGE = $(PATH_OUT)/stage
507ifndef PATH_INS
508 ifdef DESTDIR
509PATH_INS = $(DESTDIR)
510 else ifdef DESTROOT
511PATH_INS = $(DESTROOT)
512 else
513PATH_INS = $(PATH_OUT)/dist
514 endif
515endif
516
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
524# Development tool tree.
525ifndef KBUILD_DEVTOOLS
526 ifeq ($(PATH_DEVTOOLS),)
527 KBUILD_DEVTOOLS = $(PATH_ROOT)/tools
528 else
529 KBUILD_DEVTOOLS := $(PATH_DEVTOOLS)
530 endif
531endif
532KBUILD_DEVTOOLS_TRG ?= $(KBUILD_DEVTOOLS)/$(KBUILD_TARGET).$(KBUILD_TARGET_ARCH)
533KBUILD_DEVTOOLS_HST ?= $(KBUILD_DEVTOOLS)/$(KBUILD_HOST).$(KBUILD_HOST_ARCH)
534
535if1of ($(KBUILD_TARGET_ARCH), amd64 hppa64 mips64 ppc64 s390x sparc64)
536 ifeq ($(KBUILD_TARGET_ARCH),amd64)
537 KBUILD_DEVTOOLS_TRG_ALT ?= $(KBUILD_DEVTOOLS)/$(KBUILD_TARGET).x86
538 else ifeq ($(KBUILD_TARGET_ARCH),hppa64)
539 KBUILD_DEVTOOLS_TRG_ALT ?= $(KBUILD_DEVTOOLS)/$(KBUILD_TARGET).hppa32
540 else ifeq ($(KBUILD_TARGET_ARCH),mips64)
541 KBUILD_DEVTOOLS_TRG_ALT ?= $(KBUILD_DEVTOOLS)/$(KBUILD_TARGET).mips32
542 else ifeq ($(KBUILD_TARGET_ARCH),ppc64)
543 KBUILD_DEVTOOLS_TRG_ALT ?= $(KBUILD_DEVTOOLS)/$(KBUILD_TARGET).ppc32
544 else ifeq ($(KBUILD_TARGET_ARCH),s390x)
545 KBUILD_DEVTOOLS_TRG_ALT ?= $(KBUILD_DEVTOOLS)/$(KBUILD_TARGET).s390
546 else ifeq ($(KBUILD_TARGET_ARCH),sparc64)
547 KBUILD_DEVTOOLS_TRG_ALT ?= $(KBUILD_DEVTOOLS)/$(KBUILD_TARGET).sparc32
548 endif
549endif
550
551if1of ($(KBUILD_HOST_ARCH), amd64 hppa64 mips64 ppc64 s390x sparc64)
552 ifeq ($(KBUILD_HOST_ARCH),amd64)
553 KBUILD_DEVTOOLS_HST_ALT ?= $(KBUILD_DEVTOOLS)/$(KBUILD_HOST).x86
554 else ifeq ($(KBUILD_HOST_ARCH),hppa64)
555 KBUILD_DEVTOOLS_HST_ALT ?= $(KBUILD_DEVTOOLS)/$(KBUILD_HOST).hppa32
556 else ifeq ($(KBUILD_HOST_ARCH),mips64)
557 KBUILD_DEVTOOLS_HST_ALT ?= $(KBUILD_DEVTOOLS)/$(KBUILD_HOST).mips32
558 else ifeq ($(KBUILD_HOST_ARCH),ppc64)
559 KBUILD_DEVTOOLS_HST_ALT ?= $(KBUILD_DEVTOOLS)/$(KBUILD_HOST).ppc32
560 else ifeq ($(KBUILD_HOST_ARCH),s390x)
561 KBUILD_DEVTOOLS_HST_ALT ?= $(KBUILD_DEVTOOLS)/$(KBUILD_HOST).s390
562 else ifeq ($(KBUILD_HOST_ARCH),sparc64)
563 KBUILD_DEVTOOLS_HST_ALT ?= $(KBUILD_DEVTOOLS)/$(KBUILD_HOST).sparc32
564 endif
565endif
566
567# Deprecated legacy names.
568PATH_DEVTOOLS ?= $(KBUILD_DEVTOOLS)
569PATH_DEVTOOLS_TRG ?= $(KBUILD_DEVTOOLS_TRG)
570PATH_DEVTOOLS_BLD ?= $(KBUILD_DEVTOOLS_TRG)
571PATH_DEVTOOLS_TRG_ALT ?= $(KBUILD_DEVTOOLS_TRG_ALT)
572PATH_DEVTOOLS_HST ?= $(KBUILD_DEVTOOLS_HST)
573PATH_DEVTOOLS_HST_ALT ?= $(KBUILD_DEVTOOLS_HST_ALT)
574
575# KBUILD_PATH / PATH_KBUILD is determined by kmk.
576ifndef KBUILD_PATH
577 KBUILD_PATH := $(PATH_KBUILD)
578endif
579ifeq ($(strip $(KBUILD_PATH)),)
580 $(error kBuild: KBUILD_PATH is missing or empty! kmk is supposed to set it.)
581endif
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
589
590# kBuild files which might be of interest.
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
596
597## MAKEFILE is the name of the main makefile.
598MAKEFILE := $(firstword $(MAKEFILE_LIST))
599## MAKEFILE_CURRENT is the name of the current makefile.
600# This is updated everything a sub-makefile is included.
601MAKEFILE_CURRENT := $(MAKEFILE)
602
603
604## @todo this should be done via SUFF_XYZ.target/host...
605
606#
607# Build platform setup.
608# (PORTME)
609#
610if1of ($(KBUILD_HOST), win nt)
611# Win, Win32, Win64, NT.
612EXEC_X86_WIN32 :=
613HOSTSUFF_EXE := .exe
614HOST_PATH_SEP := $(SEMICOLON)
615
616# OS/2.
617else ifeq ($(KBUILD_HOST),os2)
618EXEC_X86_WIN32 := innopec.exe
619HOSTSUFF_EXE := .exe
620HOST_PATH_SEP := $(SEMICOLON)
621
622else if1of ($(KBUILD_HOST), dragonfly freebsd gnukfbsd gnuknbsd linux openbsd netbsd)
623# Unix (like) systems with wine.
624EXEC_X86_WIN32 := wine
625HOSTSUFF_EXE :=
626HOST_PATH_SEP := $(COLON)
627
628else
629# Unix (like) systems without wine.
630EXEC_X86_WIN32 := false
631HOSTSUFF_EXE :=
632HOST_PATH_SEP := $(COLON)
633endif
634
635
636#
637# Build target setup.
638# (PORTME)
639#
640SUFF_DEP := .dep
641SUFF_BIN :=
642if1of ($(KBUILD_TARGET), win nt os2)
643SUFF_OBJ := .obj
644SUFF_LIB := .lib
645SUFF_DLL := .dll
646SUFF_EXE := .exe
647SUFF_SYS := .sys
648SUFF_RES := .res
649else ifeq ($(KBUILD_TARGET),l4)
650SUFF_OBJ := .o
651SUFF_LIB := .a
652SUFF_DLL := .s.so
653SUFF_EXE :=
654SUFF_SYS := .a
655SUFF_RES :=
656else ifeq ($(KBUILD_TARGET),darwin)
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 :=
668 if1of ($(KBUILD_TARGET), dragonfly freebsd gnukfbsd gnuknbsd linux netbsd openbsd) ## @todo check netbsd, gnuknbsd and openbsd.
669SUFF_SYS := .ko
670 else
671SUFF_SYS :=
672 endif
673SUFF_RES :=
674endif
675
676#
677# Standard kBuild tools.
678#
679ifeq ($(KMK),kmk)
680KMK := $(KBUILD_BIN_PATH)/kmk$(HOSTSUFF_EXE)
681endif
682MAKE := $(KMK)
683
684GMAKE := $(KBUILD_BIN_PATH)/kmk_gmake$(HOSTSUFF_EXE)
685
686#DEP_EXT := $(KBUILD_BIN_PATH)/kDep$(HOSTSUFF_EXE)
687#DEP_INT := $(KBUILD_BIN_PATH)/kDep$(HOSTSUFF_EXE)
688#DEP := $(DEP_INT)
689
690DEP_IDB_EXT := $(KBUILD_BIN_PATH)/kDepIDB$(HOSTSUFF_EXE)
691DEP_IDB_INT := kmk_builtin_kDepIDB
692DEP_IDB := $(DEP_IDB_INT)
693
694DEP_OBJ_EXT := $(KBUILD_BIN_PATH)/kDepObj$(HOSTSUFF_EXE)
695DEP_OBJ_INT := kmk_builtin_kDepObj
696DEP_OBJ := $(DEP_OBJ_INT)
697
698DEP_PRE := $(KBUILD_BIN_PATH)/kDepPre$(HOSTSUFF_EXE)
699
700KOBJCACHE_EXT := $(KBUILD_BIN_PATH)/kObjCache$(HOSTSUFF_EXE)
701KOBJCACHE := $(KOBJCACHE_EXT)
702
703KLIBTWEAKER_EXT := $(KBUILD_BIN_PATH)/kLibTweaker$(HOSTSUFF_EXE)
704KLIBTWEAKER := $(KLIBTWEAKER_EXT)
705
706APPEND_EXT := $(KBUILD_BIN_PATH)/kmk_append$(HOSTSUFF_EXE)
707APPEND_INT := kmk_builtin_append
708APPEND := $(APPEND_INT)
709
710CAT_EXT := $(KBUILD_BIN_PATH)/kmk_cat$(HOSTSUFF_EXE)
711CAT_INT := kmk_builtin_cat
712CAT := $(CAT_INT)
713
714CHMOD_EXT := $(KBUILD_BIN_PATH)/kmk_chmod$(HOSTSUFF_EXE)
715CHMOD_INT := kmk_builtin_chmod
716CHMOD := $(CHMOD_INT)
717
718CMP_EXT := $(KBUILD_BIN_PATH)/kmk_cmp$(HOSTSUFF_EXE)
719CMP_INT := kmk_builtin_cmp
720CMP := $(CMP_INT)
721
722CP_EXT := $(KBUILD_BIN_PATH)/kmk_cp$(HOSTSUFF_EXE)
723CP_INT := kmk_builtin_cp
724CP := $(CP_INT)
725
726ECHO_EXT := $(KBUILD_BIN_PATH)/kmk_echo$(HOSTSUFF_EXE)
727ECHO_INT := kmk_builtin_echo
728ECHO := $(ECHO_INT)
729
730EXPR_EXT := $(KBUILD_BIN_PATH)/kmk_expr$(HOSTSUFF_EXE)
731EXPR_INT := kmk_builtin_expr
732EXPR := $(EXPR_INT)
733
734INSTALL_EXT := $(KBUILD_BIN_PATH)/kmk_install$(HOSTSUFF_EXE)
735INSTALL_INT := kmk_builtin_install
736INSTALL := $(INSTALL_INT)
737
738LN_EXT := $(KBUILD_BIN_PATH)/kmk_ln$(HOSTSUFF_EXE)
739LN_INT := kmk_builtin_ln
740LN := $(LN_INT)
741
742MD5SUM_EXT := $(KBUILD_BIN_PATH)/kmk_md5sum$(HOSTSUFF_EXE)
743MD5SUM_INT := kmk_builtin_md5sum
744MD5SUM := $(MD5SUM_INT)
745
746MKDIR_EXT := $(KBUILD_BIN_PATH)/kmk_mkdir$(HOSTSUFF_EXE)
747MKDIR_INT := kmk_builtin_mkdir
748MKDIR := $(MKDIR_INT)
749
750MV_EXT := $(KBUILD_BIN_PATH)/kmk_mv$(HOSTSUFF_EXE)
751MV_INT := kmk_builtin_mv
752MV := $(MV_INT)
753
754PRINTF_EXT := $(KBUILD_BIN_PATH)/kmk_printf$(HOSTSUFF_EXE)
755PRINTF_INT := kmk_builtin_printf
756PRINTF := $(PRINTF_INT)
757
758REDIRECT_EXT:= $(KBUILD_BIN_PATH)/kmk_redirect$(HOSTSUFF_EXE)
759if $(KBUILD_KMK_REVISION) > 2911
760REDIRECT_INT:= kmk_builtin_redirect
761else
762REDIRECT_INT:= $(REDIRECT_EXT)
763endif
764REDIRECT := $(REDIRECT_INT)
765
766RM_EXT := $(KBUILD_BIN_PATH)/kmk_rm$(HOSTSUFF_EXE)
767RM_INT := kmk_builtin_rm
768RM := $(RM_INT)
769
770RMDIR_EXT := $(KBUILD_BIN_PATH)/kmk_rmdir$(HOSTSUFF_EXE)
771RMDIR_INT := kmk_builtin_rmdir
772RMDIR := $(RMDIR_INT)
773
774SED_EXT := $(KBUILD_BIN_PATH)/kmk_sed$(HOSTSUFF_EXE)
775SED_INT := $(SED_EXT)
776SED := $(SED_EXT)
777
778SLEEP_INT := kmk_builtin_sleep
779SLEEP_EXT := $(KBUILD_BIN_PATH)/kmk_sleep$(HOSTSUFF_EXE)
780SLEEP := $(SLEEP_EXT)
781
782TEST_EXT := $(KBUILD_BIN_PATH)/kmk_test$(HOSTSUFF_EXE)
783TEST_INT := kmk_builtin_test
784TEST := $(TEST_INT)
785
786TIME_EXT := $(KBUILD_BIN_PATH)/kmk_time$(HOSTSUFF_EXE)
787TIME_INT := $(TIME_EXT)
788TIME := $(TIME_INT)
789
790TOUCH_EXT := $(KBUILD_BIN_PATH)/kmk_touch$(HOSTSUFF_EXE)
791if $(KBUILD_KMK_REVISION) >= 3060
792TOUCH_INT := kmk_builtin_touch
793else
794TOUCH_INT := $(TOUCH_EXT)
795endif
796TOUCH := $(TOUCH_INT)
797
798# Our default shell is the Almquist shell from *BSD.
799ASH := $(KBUILD_BIN_PATH)/kmk_ash$(HOSTSUFF_EXE)
800MAKESHELL := $(ASH)
801SHELL := $(ASH)
802export SHELL MAKESHELL
803
804# Symlinking is problematic on some platforms...
805LN_SYMLINK := $(LN) -s
806
807# When copying to the staging area, use hard links to save time and space.
808ifndef KBUILD_NO_HARD_LINKING
809 INSTALL_STAGING := $(INSTALL) --hard-link-files-when-possible
810else
811 INSTALL_STAGING := $(INSTALL)
812endif
813
814
815#
816# Some Functions.
817# The lower cased ones are either fallbacks or candidates for functions.c.
818#
819
820## ABSPATH - make paths absolute.
821# This implementation is clumsy and doesn't resolve '..' and '.' components.
822#
823# @param $1 The paths to make absolute.
824# @obsolete Use the GNU make function $(abspath) directly now.
825ABSPATH = $(abspath $(1))$(warning ABSPATH is deprecated, use abspath directly!)
826
827## DIRDEP - make create directory dependencies.
828#
829# @param $1 The paths to the directories which must be created.
830DIRDEP = $(foreach path,$(patsubst %/,%,$(1)),$(path)/)
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))
838 CYGPATHMIXED = $(foreach path,$(1)\
839 ,$(if $(patsubst /cygdrive/%,,$(path)),$(path),$(patsubst $(strip $(firstword $(subst /, ,$(patsubst /cygdrive/%,%,$(path)))))/%,$(strip $(firstword $(subst /, ,$(patsubst /cygdrive/%,%,$(path))))):/%,$(patsubst /cygdrive/%,%,$(path)))))
840else
841 CYGPATHMIXED = $(1)
842endif
843
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)))
847
848## Removes the root slash from a path (if it has one)
849# @param $1 the path
850no-root-slash = $(patsubst /%,%,$(1))
851
852##
853# Similar to firstword, except it returns the value of first defined variable.
854# @param $1 list of variables to probe.
855define FIRST-DEFINED-VAR
856local .RETURN := $(strip $(firstdefined $1, value))
857endef
858
859## Figure out where to put object files.
860# @param $1 real target name.
861# @param $2 normalized main target
862TARGET_BASE = $(PATH_TARGET)/$(2)/$(call no-root-slash,$(call no-drive,$(1)))
863
864## Figure out where to put object files.
865# @param $1 normalized main target
866TARGET_PATH = $(PATH_TARGET)/$(1)
867
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
886
887##
888# Checks if the specified long option ($1) is found in the flags ($2),
889# assuming getopt style options.
890#
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
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
935 KB_FN_ASSIGN_DEPRECATED = $(eval $(subst :,$$(COLON),$1) = $2$$(error $1 is deprecated, use $3 instead))
936else
937 KB_FN_ASSIGN_DEPRECATED = $(eval $(subst :,$$(COLON),$1) = $2$$(warning $1 is deprecated, use $3 instead))
938endif
939
940##
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##
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)))",\
980 $(evalcall KB_FN_ASSERT_MSG,abspath,$1 is:$(NLTAB)'$($(strip $1))'$(NLTAB)expected:$(NLTAB)'$(abspath $($(strip $1)))'))
981else
982 KB_FN_ASSERT_ABSPATH :=
983endif
984
985
986#
987# Somewhat simple solution for automatic command dependencies.
988#
989
990## Included dependency files (used to be in footer.kmk).
991_DEPFILES_INCLUDED :=
992
993## Temporary for the compile rule below.
994if "$(KBUILD_KMK_REVISION)" >= 3134
995 KBUILD_HAVE_OPTIMIZED_APPEND := 1
996endif
997
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.
1005ifdef KBUILD_HAVE_OPTIMIZED_APPEND
1006define KB_FN_AUTO_CMD_DEPS_COMMANDS_EX
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
1014 %$(QUIET2)$(RM) -f -- "$1"
1015 %$(QUIET2)$(APPEND) "$1" 'define AUTO_CMD_DEP_$(translate $@,:,_)_PREV_CMDS'
1016 %$(QUIET2)$(APPEND) -c "$1" '$@'
1017 %$(QUIET2)$(APPEND) "$1" 'endef'
1018endef
1019endif
1020
1021##
1022# Advanced version of KB_FN_AUTO_CMD_DEPS
1023#
1024# @param 1 recipe name
1025# @param 2 dep file.
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)
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>).
1032ifdef KBUILD_HAVE_OPTIMIZED_APPEND
1033define KB_FN_AUTO_CMD_DEPS_COMMANDS
1034 %$(QUIET2)$(APPEND) -tni "$@.auto-dep" \
1035 'define AUTO_CMD_DEP_$(translate $@,:,_)_PREV_CMDS' \
1036 '--insert-command=$@' \
1037 'endef'
1038endef
1039else
1040define KB_FN_AUTO_CMD_DEPS_COMMANDS
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
1046endif
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#
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
1061## KBUILD_TEMPLATE_PATHS
1062# List a paths (separated by space) where templates can be found.
1063KBUILD_TEMPLATE_PATHS :=
1064
1065## KBUILD_TOOL_PATHS
1066# List of paths (separated by space) where tools can be found.
1067KBUILD_TOOL_PATHS :=
1068
1069## KBUILD_SDK_PATHS
1070# List of paths (separated by space) where SDKs can be found.
1071KBUILD_SDK_PATHS :=
1072
1073## KBUILD_UNIT_PATHS
1074# List of paths (separated by space) where units (USES) can be found.
1075KBUILD_UNIT_PATHS :=
1076
1077## KBUILD_DEFAULT_PATHS
1078# List of paths (separated by space) to search for stuff as a last resort.
1079KBUILD_DEFAULT_PATHS :=
1080
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
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 \
1099 .M:def_src_handler_objcxx \
1100 .mm:def_src_handler_objcxx \
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 \
1108.res:def_src_handler_obj
1109
1110## PROPS_TOOLS
1111# This is a subset of PROPS_SINGLE.
1112PROPS_TOOLS := TOOL CTOOL CXXTOOL PCHTOOL OBJCTOOL OBJCXXTOOL ASTOOL RCTOOL ARTOOL LDTOOL FETCHTOOL UNPACKTOOL PATCHTOOL
1113
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
1117# will do the necessary inheritance for templates, sdks, tools and targets.
1118PROPS_SINGLE := $(PROPS_TOOLS) TEMPLATE INSTTYPE INST STAGE NOINST BLD_TYPE BLD_TRG BLD_TRG_ARCH BLD_TRG_CPU FETCHDIR \
1119 OBJSUFF COBJSUFF CXXOBJSUFF PCHOBJSUFF OBJCOBJSUFF OBJCXXOBJSUFF ASOBJSUFF RCOBJSUFF SYSSUFF BINSUFF EXESUFF DLLSUFF LIBSUFF ARLIBSUFF \
1120 MODE UID GID LD_DEBUG DEBUG_INSTTYPE DEBUG_INST DEBUG_STAGE PCH_HDR
1121## PROPS_SINGLE_LNK
1122# Subset of PROPS_SINGLE which applies to all linkable targets.
1123PROPS_SINGLE_LNK := $(filter-out FETCHTOOL UNPACKTOOL PATCHTOOL FETCHDIR, $(PROPS_SINGLE))
1124
1125## PROPS_DEFERRED
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.
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
1131
1132## PROPS_ACCUMULATE_R
1133# The list of accumulative target properties where the right most value/flag
1134# is the 'most significant'.
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.
1137PROPS_ACCUMULATE_R := \
1138 DEPS LNK_DEPS ORDERDEPS LNK_ORDERDEPS DEFS \
1139 ARFLAGS \
1140 CFLAGS CDEFS \
1141 CXXFLAGS CXXDEFS \
1142 PCHFLAGS PCHDEFS \
1143 OBJCFLAGS OBJCDEFS \
1144 OBJCXXFLAGS OBJCXXDEFS \
1145 ASFLAGS ASDEFS \
1146 RCFLAGS RCDEFS \
1147 LDFLAGS \
1148 IDFLAGS IFFLAGS EXEC_IFFLAGS ISFLAGS \
1149 FETCHFLAGS UNPACKFLAGS PATCHFLAGS
1150## PROPS_ACCUMULATE_R_LNK
1151# Subset of PROPS_ACCUMULATE_R which applies to all linkable targets.
1152PROPS_ACCUMULATE_R_LNK := $(filter-out ARFLAGS LDFLAGS EXEC_IFFLAGS FETCHFLAGS UNPACKFLAGS PATCHFLAGS, $(PROPS_ACCUMULATE_R))
1153
1154## PROPS_ACCUMULATE
1155# The list of accumulative target properties where the left most value/flag
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 := \
1160 SDKS USES SOURCES EXEC_SOURCES SRC_HANDLERS INTERMEDIATES \
1161 INCS CINCS CXXINCS PCHINCS OBJCINCS OBJCXXINCS ASINCS RCINCS \
1162 LIBS LIBPATH \
1163 DIRS BLDDIRS CLEAN
1164## PROPS_ACCUMULATE_L_LNK
1165# Subset of PROPS_ACCUMULATE_L which applies to all linkable targets.
1166PROPS_ACCUMULATE_L_LNK := $(filter-out LIBS LIBPATH EXEC_SOURCES DIRS, $(PROPS_ACCUMULATE_L))
1167
1168## PROPS_ALL
1169# List of all the properties.
1170PROPS_ALL = $(PROPS_SINGLE) $(PROPS_DEFERRED) $(PROPS_ACCUMULATE_L) $(PROPS_ACCUMULATE_R)
1171
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## @{
1182PROPS_LIBRARIES_SINGLE := $(PROPS_SINGLE_LNK) ARTOOL LIBSUFF ARLIBSUFF LIBSUFF
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
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
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
1212## @name Properties valid on installs (INSTALLS)
1213## @{
1214PROPS_INSTALLS_SINGLE := TOOL TEMPLATE INSTTYPE INST STAGE NOINST BLD_TYPE BLD_TRG BLD_TRG_ARCH BLD_TRG_CPU MODE UID GID
1215PROPS_INSTALLS_DEFERRED := INSTFUN INSTALLER PRE_FILE_CMDS POST_FILE_CMDS PRE_SYMLINK_CMDS POST_SYMLINK_CMDS \
1216 PRE_DIRECTORY_CMDS POST_DIRECTORY_CMDS
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
1219## @}
1220
1221## @name Properties valid on fetches (FETCHES)
1222## @{
1223PROPS_FETCHES_SINGLE := TOOL TEMPLATE FETCHTOOL UNPACKTOOL PATCHTOOL INST FETCHDIR
1224PROPS_FETCHES_DEFERRED :=
1225PROPS_FETCHES_ACCUMULATE_R := FETCHFLAGS UNPACKFLAGS PATCHFLAGS
1226PROPS_FETCHES_ACCUMULATE_L := SOURCES CLEAN
1227## @}
1228
1229## KBUILD_COMPILE_CATEGTORIES
1230# Tools categories for compiling.
1231KBUILD_COMPILE_CATEGTORIES := AS C CXX PCH OBJC OBJCXX RC
1232
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
1257#
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
1260# this is necessary is the Visual C++ commandline with it's LIBPATH.)
1261#
1262# Define KBUILD_DONT_KILL_ENV_PROPS in the env. or on the commandline to
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
1272$(foreach prop, $(PROPS_ALL) \
1273 FETCHES PATCHES BLDPROGS LIBRARIES IMPORT_LIBS DLLS PROGRAMS SYSMODS MISCBINS INSTALLS OTHERS \
1274 SUBDIRS MAKEFILES BLDDIRS \
1275 ,$(eval $(value def_nuke_environment_prop)))
1276
1277endif # KBUILD_DONT_KILL_ENV_PROPS
1278
1279
1280#
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
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
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 :=
1327PASS_BINARIES_vars := _PROGRAMS _SYSMODS _MISC_BINS _OTHER_BINARIES
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
1337## PASS: staging
1338# This pass installs the built entities to a sandbox area.
1339## @todo split this up into build install (to sandbox) and real installation.
1340PASS_STAGING := Staging
1341PASS_STAGING_trgs :=
1342PASS_STAGING_vars := _STAGE_DIRS _INSTALLS _STAGE_FILES _DEBUG_STAGE_DIRS _DEBUG_STAGE_FILES
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).
1348PASS_INSTALLS := Install
1349PASS_INSTALLS_trgs :=
1350PASS_INSTALLS_vars := _INSTALLS_DIRS _INSTALLS_FILES _DEBUG_INSTALL_DIRS _DEBUG_INSTALL_FILES
1351PASS_INSTALLS_pass := installs
1352
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
1360## PASS: packing
1361# This pass processes custom packing rules.
1362PASS_PACKING := Packing
1363PASS_PACKING_trgs :=
1364PASS_PACKING_vars := _PACKING
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.
1383DEFAULT_PASSES := BLDPROGS LIBRARIES DLLS BINARIES OTHERS STAGING
1384
1385## PASSES
1386# The passes that should be defined. This must include
1387# all passes mentioned by DEFAULT_PASSES.
1388PASSES := FETCHES PATCHES $(DEFAULT_PASSES) INSTALLS TESTING PACKING CLEAN NOTHING
1389
1390
1391#
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
1398 ifeq ($(KMK_OPTS_PRETTY_COMMAND_PRINTING),1)
1399 export KBUILD_VERBOSE := 2
1400 endif
1401 endif
1402endif
1403
1404
1405#
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#
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
1429else if1of ($(KBUILD_TARGET), freebsd openbsd dragonfly)
1430 KBUILD_LIB_SEARCH_ROOTS := \
1431 / \
1432 /usr/ \
1433 /usr/local/
1434 KBUILD_LIB_SEARCH_SUBS := lib/
1435
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)
1445 ifeq ($(realpath /bin),/usr/bin)
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
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
1490KBUILD_LIB_SEARCH_PATHS := $(foreach root, $(KBUILD_LIB_SEARCH_ROOTS), $(addprefix $(root),$(KBUILD_LIB_SEARCH_SUBS)))
1491
1492
1493#
1494# This is how we find the closest config.kmk.
1495# It's a little hacky but I think it works fine.
1496#
1497_CFGDIR := .
1498_CFGFILES := ./Config.kmk ./config.kmk
1499define def_include_config
1500$(eval _CFGDIR := $(_CFGDIR)/$(dir))
1501_CFGFILES += $(_CFGDIR)/Config.kmk $(_CFGDIR)/config.kmk
1502endef
1503# walk down the _RELATIVE_ path specified by DEPTH.
1504$(foreach dir,$(subst /, ,$(DEPTH)), $(eval $(def_include_config)) )
1505# add the default config file.
1506_CFGFILE := $(firstword $(wildcard $(_CFGFILES) $(FILE_KBUILD_CONFIG)))
1507_CFGFILES :=
1508_CFGDIR :=
1509ifeq ($(_CFGFILE),)
1510$(error kBuild: no Config.kmk file found! Check the DEPTH: DEPTH='$(DEPTH)' PATH_CURRENT='$(PATH_CURRENT)')
1511endif
1512
1513# Include the config.kmk we found file (or the default one).
1514ifdef KBUILD_PROFILE_SELF
1515 $(evalcall def_profile_self, including $(_CFGFILE))
1516 include $(_CFGFILE)
1517 $(evalcall def_profile_self, included $(_CFGFILE))
1518else
1519 include $(_CFGFILE)
1520endif
1521
1522
1523
1524#
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#
1530PATH_OUT_BASE := $(abspath $(PATH_OUT_BASE))
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))
1536
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)
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)
1565endef
1566$(foreach y, INST STAGE, $(foreach x, $(KBUILD_INST_PATHS), $(evalcall def_kbuild_finalize_inst)))
1567
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)
1575
1576
1577#
1578# Setup the message style. The default one is inlined.
1579#
1580# See kBuild/msgstyles for more styles or use KBUILD_MSG_STYLE_PATHS
1581# to create your own message style.
1582#
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.
1620 # @param 4 The source type (C,CXX,OBJC,AS,RC,++).
1621 MSG_COMPILE ?= $(call MSG_L1,Compiling $1 - $2,=> $3)
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))
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)
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.
1642 MSG_AR_MERGE ?= $(call MSG_L1,Merging $3 into $1, ($2))
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
1670else
1671 _KBUILD_MSG_STYLE_FILE := $(firstword $(foreach path, $(KBUILD_MSG_STYLE_PATHS) $(KBUILD_PATH)/msgstyles, $(wildcard $(path)/$(KBUILD_MSG_STYLE).kmk)))
1672 ifneq ($(_KBUILD_MSG_STYLE_FILE),)
1673 include $(_KBUILD_MSG_STYLE_FILE)
1674 else
1675 $(error kBuild: Can't find the style setup file for KBUILD_MSG_STYLE '$(KBUILD_MSG_STYLE)')
1676 endif
1677endif
1678
1679
1680#
1681# Message macros.
1682#
1683# This is done after including Config.kmk as to allow for
1684# KBUILD_QUIET and KBUILD_VERBOSE to be configurable.
1685#
1686ifdef KBUILD_QUIET
1687 # No output
1688 QUIET := @
1689 QUIET2 := @
1690 MSG_L1 :=
1691 MSG_L2 :=
1692else
1693 ifndef KBUILD_VERBOSE
1694 # Default output level.
1695 QUIET := @
1696 QUIET2 := @
1697 MSG_L1 ?= %@$(ECHO) "kBuild: $1"
1698 MSG_L2 :=
1699 else ifeq ($(KBUILD_VERBOSE),1)
1700 # A bit more output
1701 QUIET := @
1702 QUIET2 := @
1703 MSG_L1 ?= %@$(ECHO) "kBuild: $1 $2"
1704 MSG_L2 :=
1705 else ifeq ($(KBUILD_VERBOSE),2)
1706 # Lot more output
1707 QUIET :=
1708 QUIET2 := @
1709 MSG_L1 ?= %@$(ECHO) "kBuild: $1 $2"
1710 MSG_L2 ?= %@$(ECHO) "kBuild: $1"
1711 else
1712 # maximal output.
1713 QUIET :=
1714 QUIET2 :=
1715 MSG_L1 ?= %@$(ECHO) "kBuild: $1 $2"
1716 MSG_L2 ?= %@$(ECHO) "kBuild: $1"
1717 endif
1718endif
1719
1720
1721##
1722# An internal define used by subheader.kmk, subfooter.kmk, and
1723# KB_FN_PASS_0_ON_TARGET.
1724#
1725# @param target The target to process.
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
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)))
1751
1752
1753#
1754# Validate any KBUILD_BLD_TYPES additions and finally the KBUILD_TYPE.
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
1765ifn1of ($(KBUILD_TYPE), $(KBUILD_BLD_TYPES))
1766 $(error kBuild: KBUILD_TYPE(=$(KBUILD_TYPE)) is not found in KBUILD_BLD_TYPES(=$(KBUILD_BLD_TYPES))!)
1767endif
1768
1769
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
1781
1782
1783ifdef KBUILD_PROFILE_SELF
1784 $(evalcall def_profile_self, end of header.kmk)
1785 _KBUILD_TS_HEADER_END := $(_KBUILD_TS_PREV)
1786endif
1787
1788# end-of-file-content
1789__header_kmk__ := 1
1790endif # !__header_kmk__
1791
Note: See TracBrowser for help on using the repository browser.