source: trunk/kBuild/header.kmk@ 2551

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

header.kmk: Property list fixes.

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