source: trunk/kBuild/header.kmk@ 2488

Last change on this file since 2488 was 2488, checked in by bird, 14 years ago

footer.kmk,header.kmk: Fixed multile install/staging destinations for link targets (busted by recent changes).

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