source: trunk/kBuild/header.kmk@ 3061

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

header.kmk: Added TOUCH tool macros.

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