source: trunk/kBuild/header.kmk@ 2344

Last change on this file since 2344 was 2344, checked in by bird, 16 years ago

header.kmk: Added USES and INTERMEDIATES to PROPS_ACCUMULATE_L_LNK, been missing and messing up for a good while. Backport candidate.

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