1 # $Id: sys.mk,v 1.35 2012/11/12 06:27:51 sjg Exp $
3 # @(#) Copyright (c) 2003-2009, Simon J. Gerraty
5 # This file is provided in the hope that it will
6 # be of use. There is absolutely NO WARRANTY.
7 # Permission to copy, redistribute or otherwise
8 # use this file is hereby granted provided that
9 # the above copyright notice and this notice are
12 # Please send copies of changes and bug-fixes to:
16 # Avoid putting anything platform specific in here.
18 # We use the following paradigm for preventing multiple inclusion.
19 # It relies on the fact that conditionals and dependencies are resolved
20 # at the time they are read.
22 # _this ?= ${.PARSEFILE}
23 # .if !target(__${_this}__)
26 .if ${MAKE_VERSION:U0} > 20100408
27 _this = ${.PARSEDIR:tA}/${.PARSEFILE}
29 _this = ${.PARSEDIR}/${.PARSEFILE}
32 # Sometimes we want to turn on debugging in just one or two places
33 # if .CURDIR is matched by any entry in DEBUG_MAKE_SYS_DIRS we
34 # will apply DEBUG_MAKE_FLAGS now.
35 # if an entry in DEBUG_MAKE_DIRS matches, we at the end of sys.mk
36 # eg. DEBUG_MAKE_FLAGS=-dv DEBUG_MAKE_SYS_DIRS="*lib/sjg"
37 # use DEBUG_MAKE_FLAGS0 to apply only to .MAKE.LEVEL 0
39 .if ${.MAKE.LEVEL:U1} == 0
40 # we use indirection, to simplify the tests below, and incase
41 # DEBUG_* were given on our command line.
42 _DEBUG_MAKE_FLAGS = ${DEBUG_MAKE_FLAGS0}
43 _DEBUG_MAKE_SYS_DIRS = ${DEBUG_MAKE_SYS_DIRS0:U${DEBUG_MAKE_SYS_DIRS}}
44 _DEBUG_MAKE_DIRS = ${DEBUG_MAKE_DIRS0:U${DEBUG_MAKE_DIRS}}
46 _DEBUG_MAKE_FLAGS = ${DEBUG_MAKE_FLAGS}
47 _DEBUG_MAKE_SYS_DIRS = ${DEBUG_MAKE_SYS_DIRS}
48 _DEBUG_MAKE_DIRS = ${DEBUG_MAKE_DIRS}
51 .if !empty(_DEBUG_MAKE_FLAGS)
52 .if ${_DEBUG_MAKE_SYS_DIRS:Uno:@x@${.CURDIR:M$x}@} != ""
53 .MAKEFLAGS: ${_DEBUG_MAKE_FLAGS}
57 # if this is an ancient version of bmake
59 .if ${MAKE_VERSION:M*make-*}
60 # turn it into what we want - just the date
61 MAKE_VERSION := ${MAKE_VERSION:[1]:C,.*-,,}
64 # some useful modifiers
66 # A useful trick for testing multiple :M's against something
67 # :L says to use the variable's name as its value - ie. literal
68 # got = ${clean* destroy:${M_ListToMatch:S,V,.TARGETS,}}
69 M_ListToMatch = L:@m@$${V:M$$m}@
70 # match against our initial targets (see above)
71 M_L_TARGETS = ${M_ListToMatch:S,V,_TARGETS,}
73 # turn a list into a set of :N modifiers
74 # NskipFoo = ${Foo:${M_ListToSkip}}
75 M_ListToSkip= O:u:ts::S,:,:N,g:S,^,N,
77 # type should be a builtin in any sh since about 1980,
78 # AUTOCONF := ${autoconf:L:${M_whence}}
79 M_type = @x@(type $$x 2> /dev/null); echo;@:sh:[0]:N* found*:[@]:C,[()],,g
80 M_whence = ${M_type}:M/*
82 # convert a path to a valid shell variable
83 M_P2V = tu:C,[./-],_,g
85 # convert path to absolute
86 .if ${MAKE_VERSION:U0} > 20100408
89 M_tA = C,.*,('cd' & \&\& 'pwd') 2> /dev/null || echo &,:sh
92 # absoulte path to what we are reading.
93 _PARSEDIR = ${.PARSEDIR:${M_tA}}
95 # we expect a recent bmake
96 .if !defined(_TARGETS)
97 # some things we do only once
98 _TARGETS := ${.TARGETS}
99 .-include <sys.env.mk>
102 # we need HOST_TARGET etc below.
103 .include <host-target.mk>
105 # find the OS specifics
106 .if defined(SYS_OS_MK)
107 .include <${SYS_OS_MK}>
110 .for x in ${HOST_OSTYPE} ${HOST_TARGET} ${HOST_OS} ${MACHINE} Generic
112 .-include <sys/$x.mk>
113 _sys_mk := ${.MAKE.MAKEFILES:M*/$x.mk}
115 _sys_mk := sys/${_sys_mk:T}
119 # might be an old style
120 .-include <$x.sys.mk>
121 _sys_mk := ${.MAKE.MAKEFILES:M*/$x.sys.mk:T}
125 SYS_OS_MK := ${_sys_mk}
129 # allow customization without editing.
130 .-include <local.sys.mk>
132 # if you want objdirs make them automatic
133 .if ${MKOBJDIRS:Uno} == "auto"
134 .include <auto.obj.mk>
138 .if ${.CURDIR} == ${SRCTOP}
140 .elif ${.CURDIR:M${SRCTOP}/*}
141 RELDIR := ${.CURDIR:S,${SRCTOP}/,,}
145 MACHINE_ARCH.host ?= ${_HOST_ARCH}
146 MACHINE_ARCH.${MACHINE} ?= ${MACHINE}
147 .if empty(MACHINE_ARCH)
148 MACHINE_ARCH = ${MACHINE_ARCH.${MACHINE}}
152 ROOT_GROUP != sed -n /:0:/s/:.*//p /etc/group
156 unix ?= We run ${_HOST_OSNAME}.
158 # A race condition in mkdir, means that it can bail if another
159 # process made a dir that mkdir expected to.
160 # We repeat the mkdir -p a number of times to try and work around this.
161 # We stop looping as soon as the dir exists.
162 # If we get to the end of the loop, a plain mkdir will issue an error.
165 for i in 1 2 3 4 5 6; do \
167 test -d $$d && return 0; \
169 mkdir $$d || exit $$?; \
172 # this often helps with debugging
176 @${COMPILE.c:N-c} -E ${.IMPSRC} | grep -v '^[ ]*$$'
179 @${COMPILE.cc:N-c} -E ${.IMPSRC} | grep -v '^[ ]*$$'
181 # we don't include own.mk but user can expect -DWITH_META_MODE to work
182 .if defined(WITHOUT_META_MODE)
184 .elif defined(WITH_META_MODE)
187 .if ${USE_META:Uno} == "yes"
188 .-include <meta.sys.mk>
190 # make sure we have a harmless value
193 # if .CURDIR is matched by any entry in DEBUG_MAKE_DIRS we
194 # will apply DEBUG_MAKE_FLAGS, now.
195 .if !empty(_DEBUG_MAKE_FLAGS)
196 .if ${_DEBUG_MAKE_DIRS:Uno:@x@${.CURDIR:M$x}@} != ""
197 .MAKEFLAGS: ${_DEBUG_MAKE_FLAGS}