source: trunk/kBuild/header.kmk@ 2475

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

kBuild/footer+header.kmk: Reworking installation.

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