source: trunk/kBuild/header.kmk@ 2519

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

header.kmk: Added PERCENT.

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