source: trunk/kBuild/header.kmk@ 3060

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

header.kmk: Added OPENPAR and CLOSEPAR variables for use in macro invocations.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 53.6 KB
Line 
1# $Id: header.kmk 3058 2017-09-16 16:14:10Z 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: 3058 $ )
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
772# Our default shell is the Almquist shell from *BSD.
773ASH := $(KBUILD_BIN_PATH)/kmk_ash$(HOSTSUFF_EXE)
774MAKESHELL := $(ASH)
775SHELL := $(ASH)
776export SHELL MAKESHELL
777
778# Symlinking is problematic on some platforms...
779LN_SYMLINK := $(LN) -s
780
781# When copying to the staging area, use hard links to save time and space.
782ifndef KBUILD_NO_HARD_LINKING
783 INSTALL_STAGING := $(INSTALL) --hard-link-files-when-possible
784else
785 INSTALL_STAGING := $(INSTALL)
786endif
787
788
789#
790# Some Functions.
791# The lower cased ones are either fallbacks or candidates for functions.c.
792#
793
794## ABSPATH - make paths absolute.
795# This implementation is clumsy and doesn't resolve '..' and '.' components.
796#
797# @param $1 The paths to make absolute.
798# @obsolete Use the GNU make function $(abspath) directly now.
799ABSPATH = $(abspath $(1))$(warning ABSPATH is deprecated, use abspath directly!)
800
801## DIRDEP - make create directory dependencies.
802#
803# @param $1 The paths to the directories which must be created.
804DIRDEP = $(foreach path,$(patsubst %/,%,$(1)),$(path)/)
805
806## Cygwin kludge.
807# This converts /cygdrive/x/% to x:%.
808#
809# @param $1 The paths to make native.
810# @remark This macro is pretty much obsolete since we don't use cygwin base make.
811ifneq ($(patsubst /cygdrive/%,%,$(CURDIR)),$(CURDIR))
812 CYGPATHMIXED = $(foreach path,$(1)\
813 ,$(if $(patsubst /cygdrive/%,,$(path)),$(path),$(patsubst $(strip $(firstword $(subst /, ,$(patsubst /cygdrive/%,%,$(path)))))/%,$(strip $(firstword $(subst /, ,$(patsubst /cygdrive/%,%,$(path))))):/%,$(patsubst /cygdrive/%,%,$(path)))))
814else
815 CYGPATHMIXED = $(1)
816endif
817
818## Removes the drive letter from a path (if it has one)
819# @param $1 the path
820no-drive = $(word $(words $(subst :, ,$(1))),$(subst :, ,$(1)))
821
822## Removes the root slash from a path (if it has one)
823# @param $1 the path
824no-root-slash = $(patsubst /%,%,$(1))
825
826##
827# Similar to firstword, except it returns the value of first defined variable.
828# @param $1 list of variables to probe.
829define FIRST-DEFINED-VAR
830local .RETURN := $(strip $(firstdefined $1, value))
831endef
832
833## Figure out where to put object files.
834# @param $1 real target name.
835# @param $2 normalized main target
836TARGET_BASE = $(PATH_TARGET)/$(2)/$(call no-root-slash,$(call no-drive,$(1)))
837
838## Figure out where to put object files.
839# @param $1 normalized main target
840TARGET_PATH = $(PATH_TARGET)/$(1)
841
842##
843# Checks if the specified short option ($1) is found in the flags ($2),
844# assuming getopt style options.
845#
846# @returns $3 if present, $4 not.
847#
848# @param $1 The option (single char!).
849# @param $2 The option arguments.
850# @param $3 Eval and return if present.
851# @param $4 Eval and return if not present.
852#
853# @todo May confuse option values starting with '-' for options.
854# @remarks Invoke like this: $(evalcall KB_FN_OPT_TEST_SHORT,d,$(flags),present,not-present)
855#
856define KB_FN_OPT_TEST_SHORT
857local options := $(translate $(strip $(filter -%,$(filter-out --%,$2))),$(SP)-,)
858local .RETURN := $(if-expr $(pos $1,$(options)) != 0,$3,$4)
859endef
860
861##
862# Checks if the specified long option ($1) is found in the flags ($2),
863# assuming getopt style options.
864#
865# @returns $3 if present, $4 not.
866#
867# @param $1 The long option, dashes included. No % chars.
868# @param $2 The option arguments.
869# @param $3 Eval and return if present.
870# @param $4 Eval and return if not present.
871#
872# @todo May confuse option values starting with '--' for options.
873# @remarks Invoke like this: $(evalcall KBFN_OPT_TEST_SHORT,--defined,$(flags),present,not-present)
874#
875define KB_FN_OPT_TEST_LONG
876local options := $(filter-out =delete=%,$(subst :, =delete=,$(subst =, =delete=,$2)))
877local .RETURN := $(if-expr "$(filter $1,$(options))" != "",$3,$4)
878endef
879
880##
881# Checks if the specified short ($1) or long ($2) option is found in the flags ($2),
882# assuming getopt style options.
883#
884# @returns $4 if present, $5 not.
885#
886# @param $1 The short option (single char!).
887# @param $2 The long option, dashes included. No % chars.
888# @param $3 The option arguments.
889# @param $4 Eval and return if present.
890# @param $5 Eval and return if not present.
891#
892# @todo May confuse option values starting with '--' for options.
893# @remarks Invoke like this: $(evalcall KB_FN_OPT_TEST_SHORT_LONG,d,--defined,$(flags),present,not-present)
894#
895define KB_FN_OPT_TEST_SHORT_LONG
896local short_options := $(translate $(strip $(filter -%,$(filter-out --%,$3))),$(SP)-,)
897local long_options := $(filter-out =delete=%,$(subst :, =delete=,$(subst =, =delete=,$3)))
898local .RETURN := $(if-expr $(pos $1,$(short_options)) != 0 || "$(filter $2,$(long_options))" != "",$4,$5)
899endef
900
901##
902# Make an assignment to a deprecated variable.
903#
904# @param $1 The variable name.
905# @param $2 The value.
906# @param $3 The variable to use instead.
907#
908ifdef KBUILD_WITH_DEPREATED_AS_ERROR
909 KB_FN_ASSIGN_DEPRECATED = $(eval $(subst :,$$(COLON),$1) = $2$$(error $1 is deprecated, use $3 instead))
910else
911 KB_FN_ASSIGN_DEPRECATED = $(eval $(subst :,$$(COLON),$1) = $2$$(warning $1 is deprecated, use $3 instead))
912endif
913
914##
915# Show an assertion message.
916#
917# @param $1 The assertion name.
918# @param $2 The details.
919#
920define KB_FN_ASSERT_MSG
921$(info !! kBuild $1 Assertion Failed !!)
922ifdef target
923 $(info !! target: $(target))
924 local varloc := $(where $(target))
925 if "$(varloc)" == "undefined"
926 local varloc := $(where $(target)_TEMPLATE)
927 endif
928 if "$(varloc)" == "undefined"
929 local varloc := $(where $(target)_SOURCES)
930 endif
931 if "$(varloc)" == "undefined"
932 local varloc := $(where $(target)_EXTENDS)
933 endif
934 if "$(varloc)" == "undefined"
935 local varloc := $(where target)
936 endif
937 ifneq ($(varloc),)
938 $(info !! location: $(varloc))
939 else
940 $(info !! probable location: $($(target)_DEFPATH)/Makefile.kmk)
941 endif
942endif
943$(info !! $2)
944$(error fixme)
945endef
946
947##
948# Throw an error if the given path $1 isn't absolute and assertions are enabled.
949#
950# @param $1 The name of the path variable to check.
951#
952ifdef KBUILD_INTERNAL_STRICT
953 KB_FN_ASSERT_ABSPATH = $(if-expr "$(abspath $($(strip $1)))" != "$(strip $($(strip $1)))",\
954 $(evalcall KB_FN_ASSERT_MSG,abspath,$1 is:$(NLTAB)'$($(strip $1))'$(NLTAB)expected:$(NLTAB)'$(abspath $($(strip $1)))'))
955else
956 KB_FN_ASSERT_ABSPATH :=
957endif
958
959
960#
961# Somewhat simple solution for automatic command dependencies.
962#
963
964##
965# Advanced version of KB_FN_AUTO_CMD_DEPS_COMMANDS_EX where you set
966# the dependency file name yourself.
967#
968# After or before the recipe do $(call KB_FN_AUTO_CMD_DEPS_EX,<recipe-target>,<dep-file>).
969#
970# @param 1 dep file.
971define KB_FN_AUTO_CMD_DEPS_COMMANDS_EX
972 %$(QUIET2)$(RM) -f -- "$1"
973 %$(QUIET2)$(APPEND) "$1" 'define AUTO_CMD_DEP_$(translate $@,:,_)_PREV_CMDS'
974 %$(QUIET2)$(APPEND) -c "$1" '$@'
975 %$(QUIET2)$(APPEND) "$1" 'endef'
976endef
977
978##
979# Advanced version of KB_FN_AUTO_CMD_DEPS
980#
981# @param 1 recipe name
982# @param 2 dep file.
983KB_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)
984
985##
986# $(call KB_FN_AUTO_CMD_DEPS_COMMANDS) as the first command in a recipe to
987# automatically generate command dependencies.
988# After or before the recipe do $(call KB_FN_AUTO_CMD_DEPS,<recipe-target>).
989define KB_FN_AUTO_CMD_DEPS_COMMANDS
990 %$(QUIET2)$(RM) -f -- "$@.auto-dep"
991 %$(QUIET2)$(APPEND) "$@.auto-dep" 'define AUTO_CMD_DEP_$(translate $@,:,_)_PREV_CMDS'
992 %$(QUIET2)$(APPEND) -c "$@.auto-dep" '$@'
993 %$(QUIET2)$(APPEND) "$@.auto-dep" 'endef'
994endef
995
996##
997# Call before or after defining a recipe that you want automatic command
998# dependencies on. The recipe must start off by $(call KB_FN_AUTO_CMD_DEPS_COMMANDS).
999#
1000# @param 1 recipe name
1001KB_FN_AUTO_CMD_DEPS = $(call KB_FN_AUTO_CMD_DEPS_EX,$1,$1.auto-dep)
1002
1003
1004#
1005# Initialize some of the globals which the Config.kmk and
1006# others can add stuff to if they like for processing in the footer.
1007#
1008
1009## KBUILD_TEMPLATE_PATHS
1010# List a paths (separated by space) where templates can be found.
1011KBUILD_TEMPLATE_PATHS :=
1012
1013## KBUILD_TOOL_PATHS
1014# List of paths (separated by space) where tools can be found.
1015KBUILD_TOOL_PATHS :=
1016
1017## KBUILD_SDK_PATHS
1018# List of paths (separated by space) where SDKs can be found.
1019KBUILD_SDK_PATHS :=
1020
1021## KBUILD_UNIT_PATHS
1022# List of paths (separated by space) where units (USES) can be found.
1023KBUILD_UNIT_PATHS :=
1024
1025## KBUILD_DEFAULT_PATHS
1026# List of paths (separated by space) to search for stuff as a last resort.
1027KBUILD_DEFAULT_PATHS :=
1028
1029## Proritized list of the default makefile when walking subdirectories.
1030# The user can overload this list.
1031DEFAULT_MAKEFILE := Makefile.kmk makefile.kmk Makefile makefile
1032
1033## KBUILD_SRC_HANDLERS
1034# The list of source handlers, pair of extension and handler.
1035# The user can overload this list to provide additional or custom
1036# handlers. On a per-target/template see SRC_HANDLERS.
1037KBUILD_SRC_HANDLERS := \
1038 .c:def_src_handler_c \
1039 .C:def_src_handler_c \
1040.cxx:def_src_handler_cxx \
1041.CXX:def_src_handler_cxx \
1042.cpp:def_src_handler_cxx \
1043.CPP:def_src_handler_cxx \
1044 .cc:def_src_handler_cxx \
1045 .CC:def_src_handler_cxx \
1046 .m:def_src_handler_objc \
1047 .M:def_src_handler_objcxx \
1048 .mm:def_src_handler_objcxx \
1049.asm:def_src_handler_asm \
1050.ASM:def_src_handler_asm \
1051 .s:def_src_handler_asm \
1052 .S:def_src_handler_asm \
1053 .rc:def_src_handler_rc \
1054.obj:def_src_handler_obj \
1055 .o:def_src_handler_obj \
1056.res:def_src_handler_obj
1057
1058## PROPS_TOOLS
1059# This is a subset of PROPS_SINGLE.
1060PROPS_TOOLS := TOOL CTOOL CXXTOOL OBJCTOOL OBJCXXTOOL ASTOOL RCTOOL ARTOOL LDTOOL FETCHTOOL UNPACKTOOL PATCHTOOL
1061
1062## PROPS_SINGLE
1063# The list of non-accumulative target properties.
1064# A Config.kmk file can add it's own properties to this list and kBuild
1065# will do the necessary inheritance for templates, sdks, tools and targets.
1066PROPS_SINGLE := $(PROPS_TOOLS) TEMPLATE INSTTYPE INST STAGE NOINST BLD_TYPE BLD_TRG BLD_TRG_ARCH BLD_TRG_CPU FETCHDIR \
1067 OBJSUFF COBJSUFF CXXOBJSUFF OBJCOBJSUFF OBJCXXOBJSUFF ASOBJSUFF RCOBJSUFF SYSSUFF BINSUFF EXESUFF DLLSUFF LIBSUFF ARLIBSUFF \
1068 MODE UID GID LD_DEBUG DEBUG_INSTTYPE DEBUG_INST DEBUG_STAGE
1069## PROPS_SINGLE_LNK
1070# Subset of PROPS_SINGLE which applies to all linkable targets.
1071PROPS_SINGLE_LNK := $(filter-out FETCHTOOL UNPACKTOOL PATCHTOOL FETCHDIR, $(PROPS_SINGLE))
1072
1073## PROPS_DEFERRED
1074# This list of non-accumulative target properties which are or may be
1075# functions, and thus should not be expanded until the very last moment.
1076PROPS_DEFERRED := INSTFUN INSTALLER PRE_CMDS POST_CMDS PRE_INST_CMDS POST_INST_CMDS \
1077 PRE_FILE_CMDS POST_FILE_CMDS PRE_SYMLINK_CMDS POST_SYMLINK_CMDS PRE_DIRECTORY_CMDS POST_DIRECTORY_CMDS \
1078 NAME SONAME
1079
1080## PROPS_ACCUMULATE_R
1081# The list of accumulative target properties where the right most value/flag
1082# is the 'most significant'.
1083# A Config.kmk file can add it's own properties to this list and kBuild
1084# will do the necessary inheritance from templates to targets.
1085PROPS_ACCUMULATE_R := \
1086 DEPS LNK_DEPS ORDERDEPS LNK_ORDERDEPS DEFS \
1087 ARFLAGS \
1088 CFLAGS CDEFS \
1089 CXXFLAGS CXXDEFS \
1090 OBJCFLAGS OBJCDEFS \
1091 OBJCXXFLAGS OBJCXXDEFS \
1092 ASFLAGS ASDEFS \
1093 RCFLAGS RCDEFS \
1094 LDFLAGS \
1095 IDFLAGS IFFLAGS EXEC_IFFLAGS ISFLAGS \
1096 FETCHFLAGS UNPACKFLAGS PATCHFLAGS
1097## PROPS_ACCUMULATE_R_LNK
1098# Subset of PROPS_ACCUMULATE_R which applies to all linkable targets.
1099PROPS_ACCUMULATE_R_LNK := $(filter-out ARFLAGS LDFLAGS EXEC_IFFLAGS FETCHFLAGS UNPACKFLAGS PATCHFLAGS, $(PROPS_ACCUMULATE_R))
1100
1101## PROPS_ACCUMULATE
1102# The list of accumulative target properties where the left most value/flag
1103# is the 'most significant'.
1104# A Config.kmk file can add it's own properties to this list and kBuild
1105# will do the necessary inheritance from templates to targets.
1106PROPS_ACCUMULATE_L := \
1107 SDKS USES SOURCES EXEC_SOURCES SRC_HANDLERS INTERMEDIATES \
1108 INCS CINCS CXXINCS OBJCINCS OBJCXXINCS ASINCS RCINCS \
1109 LIBS LIBPATH \
1110 DIRS BLDDIRS CLEAN
1111## PROPS_ACCUMULATE_L_LNK
1112# Subset of PROPS_ACCUMULATE_L which applies to all linkable targets.
1113PROPS_ACCUMULATE_L_LNK := $(filter-out LIBS LIBPATH EXEC_SOURCES DIRS, $(PROPS_ACCUMULATE_L))
1114
1115## PROPS_ALL
1116# List of all the properties.
1117PROPS_ALL = $(PROPS_SINGLE) $(PROPS_DEFERRED) $(PROPS_ACCUMULATE_L) $(PROPS_ACCUMULATE_R)
1118
1119## @name Properties valid on programs (BLDPROGS and PROGRAMS)
1120## @{
1121PROPS_PROGRAMS_SINGLE := $(PROPS_SINGLE_LNK) LDTOOL EXESUFF
1122PROPS_PROGRAMS_DEFERRED := $(PROPS_DEFERRED)
1123PROPS_PROGRAMS_ACCUMULATE_R := $(PROPS_ACCUMULATE_R_LNK) LDFLAGS
1124PROPS_PROGRAMS_ACCUMULATE_L := $(PROPS_ACCUMULATE_L_LNK) LIBS LIBPATH
1125## @}
1126
1127## @name Properties valid on libraries (LIBRARIES and IMPORT_LIBS)
1128## @{
1129PROPS_LIBRARIES_SINGLE := $(PROPS_SINGLE_LNK) ARTOOL LIBSUFF ARLIBSUFF LIBSUFF
1130PROPS_LIBRARIES_DEFERRED := $(filter-out SONAME,$(PROPS_DEFERRED))
1131PROPS_LIBRARIES_ACCUMULATE_R := $(PROPS_ACCUMULATE_R_LNK) ARFLAGS
1132PROPS_LIBRARIES_ACCUMULATE_L := $(PROPS_ACCUMULATE_L_LNK)
1133## @}
1134
1135## @name Properties valid on dlls (DLLS)
1136## @{
1137PROPS_DLLS_SINGLE := $(PROPS_SINGLE_LNK) LDTOOL DLLSUFF LIBSUFF
1138PROPS_DLLS_DEFERRED := $(PROPS_DEFERRED)
1139PROPS_DLLS_ACCUMULATE_R := $(PROPS_ACCUMULATE_R_LNK) LDFLAGS
1140PROPS_DLLS_ACCUMULATE_L := $(PROPS_ACCUMULATE_L_LNK) LIBS LIBPATH
1141## @}
1142
1143## @name Properties valid on system modules (SYSMODS)
1144## @{
1145PROPS_SYSMODS_SINGLE := $(PROPS_SINGLE_LNK) LDTOOL SYSSUFF
1146PROPS_SYSMODS_DEFERRED := $(PROPS_DEFERRED)
1147PROPS_SYSMODS_ACCUMULATE_R := $(PROPS_ACCUMULATE_R_LNK) LDFLAGS
1148PROPS_SYSMODS_ACCUMULATE_L := $(PROPS_ACCUMULATE_L_LNK) LIBS LIBPATH
1149## @}
1150
1151## @name Properties valid on misc binaries (MISCBINS)
1152## @{
1153PROPS_MISCBINS_SINGLE := $(PROPS_SINGLE_LNK) LDTOOL BINSUFF
1154PROPS_MISCBINS_DEFERRED := $(PROPS_DEFERRED)
1155PROPS_MISCBINS_ACCUMULATE_R := $(PROPS_ACCUMULATE_R_LNK) LDFLAGS
1156PROPS_MISCBINS_ACCUMULATE_L := $(PROPS_ACCUMULATE_L_LNK) LIBS LIBPATH
1157## @}
1158
1159## @name Properties valid on installs (INSTALLS)
1160## @{
1161PROPS_INSTALLS_SINGLE := TOOL TEMPLATE INSTTYPE INST STAGE NOINST BLD_TYPE BLD_TRG BLD_TRG_ARCH BLD_TRG_CPU MODE UID GID
1162PROPS_INSTALLS_DEFERRED := INSTFUN INSTALLER PRE_FILE_CMDS POST_FILE_CMDS PRE_SYMLINK_CMDS POST_SYMLINK_CMDS \
1163 PRE_DIRECTORY_CMDS POST_DIRECTORY_CMDS
1164PROPS_INSTALLS_ACCUMULATE_R := DEPS ORDERDEPS GOALS INST_ONLY_GOALS STAGE_ONLY_GOALS IFFLAGS EXEC_IFFLAGS
1165PROPS_INSTALLS_ACCUMULATE_L := SOURCES EXEC_SOURCES DIRS CLEAN
1166## @}
1167
1168## @name Properties valid on fetches (FETCHES)
1169## @{
1170PROPS_FETCHES_SINGLE := TOOL TEMPLATE FETCHTOOL UNPACKTOOL PATCHTOOL INST FETCHDIR
1171PROPS_FETCHES_DEFERRED :=
1172PROPS_FETCHES_ACCUMULATE_R := FETCHFLAGS UNPACKFLAGS PATCHFLAGS
1173PROPS_FETCHES_ACCUMULATE_L := SOURCES CLEAN
1174## @}
1175
1176## KBUILD_COMPILE_CATEGTORIES
1177# Tools categories for compiling.
1178KBUILD_COMPILE_CATEGTORIES := AS C CXX OBJC OBJCXX RC
1179
1180## KBUILD_GENERIC_CATEGORIES
1181# Generic tool categories.
1182KBUILD_GENERIC_CATEGORIES := FETCH UNPACK PATCH $(addprefix LINK_,LIBRARY PROGRAM DLL SYSMOD MISCBIN)
1183
1184## PROPS_TOOLS_ONLY
1185# Properties found only on tools.
1186# This is expanded in a deferred manner, so it will pick up changes made to
1187# KBUILD_COMPILE_CATEGTORIES and KBUILD_GENERIC_CATEGORIES made by units.
1188PROPS_TOOLS_ONLY = \
1189 $(foreach cat, $(KBUILD_COMPILE_CATEGTORIES), \
1190 COMPILE_$(cat)_CMDS \
1191 COMPILE_$(cat)_OUTPUT \
1192 COMPILE_$(cat)_OUTPUT_MAYBE \
1193 COMPILE_$(cat)_DEPEND \
1194 COMPILE_$(cat)_DEPORD \
1195 COMPILE_$(cat)_USES_KOBJCACHE ) \
1196 $(foreach cat, $(KBUILD_GENERIC_CATEGORIES), \
1197 $(cat)_CMDS \
1198 $(cat)_OUTPUT \
1199 $(cat)_OUTPUT_MAYBE \
1200 $(cat)_DEPEND \
1201 $(cat)_DEPORD ))
1202
1203
1204#
1205# Here is a special 'hack' to prevent innocent environment variables being
1206# picked up and treated as properties. (The most annoying example of why
1207# this is necessary is the Visual C++ commandline with it's LIBPATH.)
1208#
1209# Define KBUILD_DONT_KILL_ENV_PROPS in the env. or on the commandline to
1210# disable this 'hack'.
1211#
1212ifndef KBUILD_DONT_KILL_ENV_PROPS
1213
1214define def_nuke_environment_prop
1215ifeq ($(origin $(prop)),environment)
1216$(prop) =
1217endif
1218endef
1219$(foreach prop, $(PROPS_ALL) \
1220 FETCHES PATCHES BLDPROGS LIBRARIES IMPORT_LIBS DLLS PROGRAMS SYSMODS MISCBINS INSTALLS OTHERS \
1221 SUBDIRS MAKEFILES BLDDIRS \
1222 ,$(eval $(value def_nuke_environment_prop)))
1223
1224endif # KBUILD_DONT_KILL_ENV_PROPS
1225
1226
1227#
1228# Pass configuration.
1229#
1230# The PASS_<passname>_trgs variable is listing the targets.
1231# The PASS_<passname>_vars variable is listing the target variables.
1232# The PASS_<passname>_pass variable is the lowercased passname.
1233#
1234
1235## PASS: fetches
1236# This pass fetches and unpacks things needed to complete the build.
1237PASS_FETCHES := Fetches
1238PASS_FETCHES_trgs :=
1239PASS_FETCHES_vars := _FETCHES
1240PASS_FETCHES_pass := fetches
1241
1242## PASS: patches
1243# This pass applies patches.
1244PASS_PATCHES := Patches
1245PASS_PATCHES_trgs :=
1246PASS_PATCHES_vars := _PATCHES
1247PASS_PATCHES_pass := patches
1248
1249## PASS: bldprogs
1250# This pass builds targets which are required for building the rest.
1251PASS_BLDPROGS := Build Programs
1252PASS_BLDPROGS_trgs :=
1253PASS_BLDPROGS_vars := _BLDPROGS
1254PASS_BLDPROGS_pass := bldprogs
1255
1256## PASS: libraries
1257# This pass builds library targets.
1258PASS_LIBRARIES := Libraries
1259PASS_LIBRARIES_trgs :=
1260PASS_LIBRARIES_vars := _LIBS _IMPORT_LIBS _OTHER_LIBRARIES
1261PASS_LIBRARIES_pass := libraries
1262
1263## PASS: binaries
1264# This pass builds dll targets.
1265PASS_DLLS := DLLs
1266PASS_DLLS_trgs :=
1267PASS_DLLS_vars := _DLLS _OTHER_DLLS
1268PASS_DLLS_pass := dlls
1269
1270## PASS: binaries
1271# This pass builds binary targets, i.e. programs, system modules and stuff.
1272PASS_BINARIES := Programs
1273PASS_BINARIES_trgs :=
1274PASS_BINARIES_vars := _PROGRAMS _SYSMODS _MISC_BINS _OTHER_BINARIES
1275PASS_BINARIES_pass := binaries
1276
1277## PASS: others
1278# This pass builds other targets.
1279PASS_OTHERS := Other Stuff
1280PASS_OTHERS_trgs :=
1281PASS_OTHERS_vars := _OTHERS
1282PASS_OTHERS_pass := others
1283
1284## PASS: staging
1285# This pass installs the built entities to a sandbox area.
1286## @todo split this up into build install (to sandbox) and real installation.
1287PASS_STAGING := Staging
1288PASS_STAGING_trgs :=
1289PASS_STAGING_vars := _STAGE_DIRS _INSTALLS _STAGE_FILES _DEBUG_STAGE_DIRS _DEBUG_STAGE_FILES
1290PASS_STAGING_pass := staging
1291
1292## PASS: install
1293# This pass installs the built entities to where they will be used (using
1294# DESTROOT or PATH_INS to indicate where this is).
1295PASS_INSTALLS := Install
1296PASS_INSTALLS_trgs :=
1297PASS_INSTALLS_vars := _INSTALLS_DIRS _INSTALLS_FILES _DEBUG_INSTALL_DIRS _DEBUG_INSTALL_FILES
1298PASS_INSTALLS_pass := installs
1299
1300## PASS: testing
1301# This pass processes custom rules for executing tests.
1302PASS_TESTING := Tests
1303PASS_TESTING_trgs :=
1304PASS_TESTING_vars := _TESTING
1305PASS_TESTING_pass := testing
1306
1307## PASS: packing
1308# This pass processes custom packing rules.
1309PASS_PACKING := Packing
1310PASS_PACKING_trgs :=
1311PASS_PACKING_vars := _PACKING
1312PASS_PACKING_pass := packing
1313
1314## PASS: clean
1315# This pass removes all generated files.
1316PASS_CLEAN := Clean
1317PASS_CLEAN_trgs := do-clean
1318PASS_CLEAN_vars :=
1319PASS_CLEAN_pass := clean
1320
1321## PASS: nothing
1322# This pass just walks the tree.
1323PASS_NOTHING := Nothing
1324PASS_NOTHING_trgs := do-nothing
1325PASS_NOTHING_vars :=
1326PASS_NOTHING_pass := nothing
1327
1328## DEFAULT_PASSES
1329# The default passes and their order.
1330DEFAULT_PASSES := BLDPROGS LIBRARIES DLLS BINARIES OTHERS STAGING
1331
1332## PASSES
1333# The passes that should be defined. This must include
1334# all passes mentioned by DEFAULT_PASSES.
1335PASSES := FETCHES PATCHES $(DEFAULT_PASSES) INSTALLS TESTING PACKING CLEAN NOTHING
1336
1337
1338#
1339# Check for --pretty-command-printing before including the Config.kmk
1340# so that anyone overriding the message macros can take the implied
1341# verbosity level change into account.
1342#
1343ifndef KBUILD_VERBOSE
1344 ifndef KBUILD_QUIET
1345 ifeq ($(KMK_OPTS_PRETTY_COMMAND_PRINTING),1)
1346 export KBUILD_VERBOSE := 2
1347 endif
1348 endif
1349endif
1350
1351
1352#
1353# Legacy variable translation.
1354# These will be eliminated when switching to the next version.
1355#
1356ifdef USE_KOBJCACHE
1357 ifndef KBUILD_USE_KOBJCACHE
1358 export KBUILD_USE_KOBJCACHE := $(USE_KOBJCACHE)
1359 endif
1360endif
1361
1362
1363#
1364# Library path searching hints (target OS + arch).
1365#
1366# KBUILD_LIB_SEARCH_SUBS - Subdirs typically containing the right libraries.
1367# KBUILD_LIB_SEARCH_ROOTS - Roots to search for library subdirs.
1368# KBUILD_LIB_SEARCH_PATHS - ROOTS + SUBS.
1369#
1370ifeq ($(KBUILD_TARGET),darwin)
1371 KBUILD_LIB_SEARCH_ROOTS := \
1372 /usr/ \
1373 /Developer/usr/
1374 KBUILD_LIB_SEARCH_SUBS := lib/
1375
1376else if1of ($(KBUILD_TARGET), freebsd netbsd openbsd dragonfly)
1377 KBUILD_LIB_SEARCH_ROOTS := \
1378 / \
1379 /usr/ \
1380 /usr/local/
1381 KBUILD_LIB_SEARCH_SUBS := lib/
1382
1383else ifeq ($(KBUILD_TARGET),linux)
1384 ifeq ($(realpath /bin),/usr/bin)
1385 KBUILD_LIB_SEARCH_ROOTS := \
1386 /usr/ \
1387 / \
1388 /usr/local/
1389 else
1390 KBUILD_LIB_SEARCH_ROOTS := \
1391 / \
1392 /usr/ \
1393 /usr/local/
1394 endif
1395 ifeq ($(KBUILD_TARGET_ARCH),amd64)
1396 KBUILD_LIB_SEARCH_SUBS := \
1397 lib/x86_64-linux-gnu/ \
1398 lib64/ \
1399 lib/
1400 else ifeq ($(KBUILD_TARGET_ARCH),x86)
1401 KBUILD_LIB_SEARCH_SUBS := \
1402 lib/i686-linux-gnu/ \
1403 lib/i386-linux-gnu/ \
1404 lib32/ \
1405 lib/
1406 else
1407 KBUILD_LIB_SEARCH_SUBS := lib/
1408 endif
1409
1410else ifeq ($(KBUILD_TARGET),solaris)
1411 KBUILD_LIB_SEARCH_ROOTS := \
1412 / \
1413 /usr/ \
1414 /usr/sfw/ \
1415 /usr/local/ \
1416 /sw/
1417 ifeq ($(KBUILD_TARGET_ARCH),amd64)
1418 KBUILD_LIB_SEARCH_SUBS := lib/amd64/ lib/
1419 else ifeq ($(KBUILD_TARGET_ARCH),sparc64)
1420 KBUILD_LIB_SEARCH_SUBS := lib/sparcv9/ lib/
1421 else
1422 KBUILD_LIB_SEARCH_SUBS := lib/
1423 endif
1424
1425else
1426 KBUILD_LIB_SEARCH_SUBS :=
1427 KBUILD_LIB_SEARCH_ROOTS :=
1428endif
1429KBUILD_LIB_SEARCH_PATHS := $(foreach root, $(KBUILD_LIB_SEARCH_ROOTS), $(addprefix $(root),$(KBUILD_LIB_SEARCH_SUBS)))
1430
1431
1432#
1433# This is how we find the closest config.kmk.
1434# It's a little hacky but I think it works fine.
1435#
1436_CFGDIR := .
1437_CFGFILES := ./Config.kmk ./config.kmk
1438define def_include_config
1439$(eval _CFGDIR := $(_CFGDIR)/$(dir))
1440_CFGFILES += $(_CFGDIR)/Config.kmk $(_CFGDIR)/config.kmk
1441endef
1442# walk down the _RELATIVE_ path specified by DEPTH.
1443$(foreach dir,$(subst /, ,$(DEPTH)), $(eval $(def_include_config)) )
1444# add the default config file.
1445_CFGFILE := $(firstword $(wildcard $(_CFGFILES) $(FILE_KBUILD_CONFIG)))
1446_CFGFILES :=
1447_CFGDIR :=
1448ifeq ($(_CFGFILE),)
1449$(error kBuild: no Config.kmk file found! Check the DEPTH: DEPTH='$(DEPTH)' PATH_CURRENT='$(PATH_CURRENT)')
1450endif
1451
1452# Include the config.kmk we found file (or the default one).
1453ifdef KBUILD_PROFILE_SELF
1454 $(evalcall def_profile_self, including $(_CFGFILE))
1455 include $(_CFGFILE)
1456 $(evalcall def_profile_self, included $(_CFGFILE))
1457else
1458 include $(_CFGFILE)
1459endif
1460
1461
1462
1463#
1464# Finalize a the central path variables now that we've included the Config.kmk file.
1465#
1466# This prevents some trouble when users override the defaults for these
1467# variables and uses relative paths or paths with incorrect case.
1468#
1469PATH_OUT_BASE := $(abspath $(PATH_OUT_BASE))
1470PATH_OUT := $(abspath $(PATH_OUT))
1471PATH_OBJ := $(abspath $(PATH_OBJ))
1472PATH_TARGET := $(abspath $(PATH_TARGET))
1473PATH_INS := $(abspath $(PATH_INS))
1474PATH_STAGE := $(abspath $(PATH_STAGE))
1475
1476# Finalize the install and staging directory layouts.
1477define def_kbuild_finalize_inst
1478local val := $(strip $($(y)_$(x)))
1479ifeq ($(val),)
1480 $(error kBuild: '$(y)_$(x)' is set to an empty value.)
1481endif
1482ifneq ($(words $(val)),1)
1483 $(error kBuild: The '$(y)_$(x)' value '$(val)' should not contain spaces.)
1484endif
1485ifneq ($(pos \,$(val)), 0)
1486 $(error kBuild: The '$(y)_$(x)' value '$(val)' contains DOS slashes: not allowed.)
1487endif
1488ifneq ($(pos $(COLON),$(val)), 0)
1489 $(error kBuild: The '$(y)_$(x)' value '$(val)' contains colon: not allowed.)
1490endif
1491ifneq ($(substr $(val),-1), /)
1492 $(error kBuild: The '$(y)_$(x)' value '$(val)' has no trailing slash.)
1493endif
1494if $(pos /../,$(val)) != 0 || "$(substr $(val), 3)" == "../"
1495 $(error kBuild: The '$(y)_$(x)' value '$(val)' contains dot-dot escape.)
1496endif
1497$($(y)_$(x) := $(val)
1498
1499local val := $(strip $(PATH_$(y)_$(x)))
1500ifeq ($(val),)
1501 $(error kBuild: 'PATH_$(y)_$(x)' is set to an empty value.)
1502endif
1503PATH_$(y)_$(x) := $(val)
1504endef
1505$(foreach y, INST STAGE, $(foreach x, $(KBUILD_INST_PATHS), $(evalcall def_kbuild_finalize_inst)))
1506
1507# No abspath for devtools since they might've been referenced already and we
1508# don't want conflicting variable expansions.
1509KBUILD_DEVTOOLS := $(KBUILD_DEVTOOLS)
1510KBUILD_DEVTOOLS_TRG := $(KBUILD_DEVTOOLS_TRG)
1511KBUILD_DEVTOOLS_TRG_ALT := $(KBUILD_DEVTOOLS_TRG_ALT)
1512KBUILD_DEVTOOLS_HST := $(KBUILD_DEVTOOLS_HST)
1513KBUILD_DEVTOOLS_HST_ALT := $(KBUILD_DEVTOOLS_HST_ALT)
1514
1515
1516#
1517# Setup the message style. The default one is inlined.
1518#
1519# See kBuild/msgstyles for more styles or use KBUILD_MSG_STYLE_PATHS
1520# to create your own message style.
1521#
1522KBUILD_MSG_STYLE ?= default
1523ifeq ($(KBUILD_MSG_STYLE),default)
1524 #
1525 # The 'default' style.
1526 #
1527
1528 ## Fetch starting.
1529 # @param 1 Target name.
1530 MSG_FETCH ?= $(call MSG_L1,Fetching $1...)
1531 ## Re-fetch starting.
1532 # @param 1 Target name.
1533 MSG_REFETCH ?= $(call MSG_L1,Re-fetching $1...)
1534 ## Downloading a fetch component.
1535 # @param 1 Target name.
1536 # @param 2 The source URL.
1537 # @param 3 The destination file name.
1538 MSG_FETCH_DL ?= $(call MSG_L1,Downloading $1 - $2,=> $3)
1539 ## Checking a fetch component.
1540 # @param 1 Target name.
1541 # @param 2 The source URL.
1542 # @param 3 The destination file name.
1543 MSG_FETCH_CHK?= $(call MSG_L1,Checking $1 - $3, ($2))
1544 ## Unpacking a fetch component.
1545 # @param 1 Target name.
1546 # @param 2 The archive file name.
1547 # @param 3 The target directory.
1548 MSG_FETCH_UP ?= $(call MSG_L1,Unpacking $1 - $2 => $3)
1549 ## Fetch completed.
1550 # @param 1 Target name.
1551 MSG_FETCH_OK ?= $(call MSG_L1,Successfully fetched $1)
1552 ## Unfetch a fetch target.
1553 # @param 1 Target name.
1554 MSG_UNFETCH ?= $(call MSG_L1,Unfetching $1...)
1555 ## Compiling a source file.
1556 # @param 1 Target name.
1557 # @param 2 The source filename.
1558 # @param 3 The primary link output file name.
1559 # @param 4 The source type (C,CXX,OBJC,AS,RC,++).
1560 MSG_COMPILE ?= $(call MSG_L1,Compiling $1 - $2,=> $3)
1561 ## Tool
1562 # @param 1 The tool name (bin2c,...)
1563 # @param 2 Target name.
1564 # @param 3 The source filename.
1565 # @param 4 The primary output file name.
1566 MSG_TOOL ?= $(call MSG_L1,$1 $2 - $3,=> $4)
1567 ## Generate a file, typically a source file.
1568 # @param 1 Target name if applicable.
1569 # @param 2 Output file name.
1570 # @param 3 What it's generated from
1571 MSG_GENERATE ?= $(call MSG_L1,Generating $(if $1,$1 - )$2,$(if $3,from $3))
1572 ## Linking a bldprog/dll/program/sysmod target.
1573 # @param 1 Target name.
1574 # @param 2 The primary link output file name.
1575 # @param 3 The link tool operation (LINK_LIBRARY,LINK_PROGRAM,LINK_DLL,LINK_SYSMOD,++).
1576 MSG_LINK ?= $(call MSG_L1,Linking $1,=> $2)
1577 ## Merging a library into the target (during library linking).
1578 # @param 1 Target name.
1579 # @param 2 The output library name.
1580 # @param 3 The input library name.
1581 MSG_AR_MERGE ?= $(call MSG_L1,Merging $3 into $1, ($2))
1582 ## Creating a directory (build).
1583 # @param 1 Directory name.
1584 MSG_MKDIR ?= $(call MSG_L2,Creating directory $1)
1585 ## Cleaning.
1586 MSG_CLEAN ?= $(call MSG_L1,Cleaning...)
1587 ## Nothing.
1588 MSG_NOTHING ?= $(call MSG_L1,Did nothing in $(CURDIR))
1589 ## Pass
1590 # @param 1 The pass name.
1591 MSG_PASS ?= $(call MSG_L1,Pass - $1)
1592 ## Installing a bldprog/lib/dll/program/sysmod target.
1593 # @param 1 Target name.
1594 # @param 2 The source filename.
1595 # @param 3 The destination file name.
1596 MSG_INST_TRG ?= $(call MSG_L1,Installing $1 => $3)
1597 ## Installing a file (install target).
1598 # @param 1 The source filename.
1599 # @param 2 The destination filename.
1600 MSG_INST_FILE?= $(call MSG_L1,Installing $2,(<= $1))
1601 ## Installing a symlink.
1602 # @param 1 Symlink
1603 # @param 2 Link target
1604 MSG_INST_SYM ?= $(call MSG_L1,Installing symlink $1,=> $2)
1605 ## Installing a directory.
1606 # @param 1 Directory name.
1607 MSG_INST_DIR ?= $(call MSG_L1,Installing directory $1)
1608
1609else
1610 _KBUILD_MSG_STYLE_FILE := $(firstword $(foreach path, $(KBUILD_MSG_STYLE_PATHS) $(KBUILD_PATH)/msgstyles, $(wildcard $(path)/$(KBUILD_MSG_STYLE).kmk)))
1611 ifneq ($(_KBUILD_MSG_STYLE_FILE),)
1612 include $(_KBUILD_MSG_STYLE_FILE)
1613 else
1614 $(error kBuild: Can't find the style setup file for KBUILD_MSG_STYLE '$(KBUILD_MSG_STYLE)')
1615 endif
1616endif
1617
1618
1619#
1620# Message macros.
1621#
1622# This is done after including Config.kmk as to allow for
1623# KBUILD_QUIET and KBUILD_VERBOSE to be configurable.
1624#
1625ifdef KBUILD_QUIET
1626 # No output
1627 QUIET := @
1628 QUIET2:= @
1629 MSG_L1 =
1630 MSG_L2 =
1631else
1632 ifndef KBUILD_VERBOSE
1633 # Default output level.
1634 QUIET := @
1635 QUIET2 := @
1636 MSG_L1 ?= %@$(ECHO) "kBuild: $1"
1637 MSG_L2 =
1638 else ifeq ($(KBUILD_VERBOSE),1)
1639 # A bit more output
1640 QUIET := @
1641 QUIET2 := @
1642 MSG_L1 ?= %@$(ECHO) "kBuild: $1 $2"
1643 MSG_L2 =
1644 else ifeq ($(KBUILD_VERBOSE),2)
1645 # Lot more output
1646 QUIET :=
1647 QUIET2 := @
1648 MSG_L1 ?= %@$(ECHO) "kBuild: $1 $2"
1649 MSG_L2 ?= %@$(ECHO) "kBuild: $1"
1650 else
1651 # maximal output.
1652 QUIET :=
1653 QUIET2 :=
1654 MSG_L1 ?= %@$(ECHO) "kBuild: $1 $2"
1655 MSG_L2 ?= %@$(ECHO) "kBuild: $1"
1656 endif
1657endif
1658
1659
1660##
1661# An internal define used by subheader.kmk, subfooter.kmk, and
1662# KB_FN_PASS_0_ON_TARGET.
1663#
1664# @param target The target to process.
1665#
1666define def_subfooter_header_target_pass
1667 ifndef $(target)_PATH
1668 ifndef $(target)_DEFPATH
1669 $(target)_DEFPATH := $(PATH_SUB_CURRENT)
1670 endif
1671 $(call KB_FN_ASSIGN_DEPRECATED,$(target)_PATH,$($(target)_DEFPATH), $(target)_DEFPATH)
1672 else ifndef $(target)_DEFPATH
1673 $(target)_DEFPATH := $($(target)_PATH)
1674 endif
1675 ifndef $(target)_MAKEFILE
1676 $(target)_MAKEFILE := $(MAKEFILE_CURRENT)
1677 endif
1678 ifndef $(target)_0_OUTDIR
1679 $(target)_0_OUTDIR := $(call TARGET_PATH,$(target))
1680 $(call KB_FN_ASSIGN_DEPRECATED,PATH_$(target),$($(target)_0_OUTDIR), $(target)_0_OUTDIR)
1681 endif
1682endef
1683
1684##
1685# Function to call to set _0_OUTDIR, _DEFPATH, and _MAKEFILE earlier than subfooter.
1686# Can be used to avoid exploiting double expansion.
1687#
1688# @param 1 The target name.
1689KB_FN_DO_PASS0_ON_TARGET = $(foreach target,$1,$(if-expr defined($(target)_0_OUTDIR),,$(evalval def_subfooter_header_target_pass)))
1690
1691
1692#
1693# Validate any KBUILD_BLD_TYPES additions and finally the KBUILD_TYPE.
1694#
1695if1of ($(KBUILD_BLD_TYPES), $(KBUILD_OSES))
1696 $(error kBuild: found KBUILD_BLD_TYPES in KBUILD_OSES!)
1697endif
1698if1of ($(KBUILD_BLD_TYPES), $(KBUILD_ARCHES))
1699 $(error kBuild: found KBUILD_BLD_TYPES in KBUILD_ARCHES!)
1700endif
1701if1of ($(KBUILD_OSES), $(KBUILD_ARCHES))
1702 $(error kBuild: found KBUILD_OSES in KBUILD_ARCHES!)
1703endif
1704ifn1of ($(KBUILD_TYPE), $(KBUILD_BLD_TYPES))
1705 $(error kBuild: KBUILD_TYPE(=$(KBUILD_TYPE)) is not found in KBUILD_BLD_TYPES(=$(KBUILD_BLD_TYPES))!)
1706endif
1707
1708
1709#
1710# Mark the output and temporary directories as volatile on windows.
1711#
1712# This automatically means the directories not listed here are considered
1713# static and won't be invalidated once we start running compile jobs.
1714#
1715ifeq ($(KBUILD_HOST),win)
1716 if $(KBUILD_KMK_REVISION) >= 2886
1717 $(dircache-ctl volatile, $(PATH_OUT_BASE), $(PATH_OUT), $(TEMP), $(TMP), $(TMPDIR), $(TMP))
1718 endif
1719endif
1720
1721
1722ifdef KBUILD_PROFILE_SELF
1723 $(evalcall def_profile_self, end of header.kmk)
1724 _KBUILD_TS_HEADER_END := $(_KBUILD_TS_PREV)
1725endif
1726
1727# end-of-file-content
1728__header_kmk__ := 1
1729endif # !__header_kmk__
1730
Note: See TracBrowser for help on using the repository browser.