1 # $Id: sys.mk,v 1.41 2015/11/14 20:20:34 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 # but sadly there are exceptions!
79 .if ${.MAKE.OS:Unknown:NBSD/OS} == ""
82 # AUTOCONF := ${autoconf:L:${M_whence}}
83 M_type = @x@(${_type_sh:Utype} $$x) 2> /dev/null; echo;@:sh:[0]:N* found*:[@]:C,[()],,g
84 M_whence = ${M_type}:M/*:[1]
86 # convert a path to a valid shell variable
87 M_P2V = tu:C,[./-],_,g
89 # convert path to absolute
90 .if ${MAKE_VERSION:U0} > 20100408
93 M_tA = C,.*,('cd' & \&\& 'pwd') 2> /dev/null || echo &,:sh
96 # absoulte path to what we are reading.
97 _PARSEDIR = ${.PARSEDIR:${M_tA}}
99 # we expect a recent bmake
100 .if !defined(_TARGETS)
101 # some things we do only once
102 _TARGETS := ${.TARGETS}
103 .-include <sys.env.mk>
106 # we need HOST_TARGET etc below.
107 .include <host-target.mk>
109 # early customizations
110 .-include <local.sys.env.mk>
112 # find the OS specifics
113 .if defined(SYS_OS_MK)
114 .include <${SYS_OS_MK}>
117 .for x in ${HOST_OSTYPE} ${HOST_TARGET} ${HOST_OS} ${MACHINE} Generic
119 .-include <sys/$x.mk>
120 _sys_mk := ${.MAKE.MAKEFILES:M*/$x.mk}
122 _sys_mk := sys/${_sys_mk:T}
126 # might be an old style
127 .-include <$x.sys.mk>
128 _sys_mk := ${.MAKE.MAKEFILES:M*/$x.sys.mk:T}
132 SYS_OS_MK := ${_sys_mk}
136 # some options we need to know early
137 OPTIONS_DEFAULT_NO += \
142 OPTIONS_DEFAULT_DEPENDENT += \
143 AUTO_OBJ/DIRDEPS_BUILD \
144 STAGING/DIRDEPS_BUILD \
146 .-include "options.mk"
148 .if ${MK_DIRDEPS_BUILD:Uno} == "yes"
150 .-include <meta.sys.mk>
151 .elif ${MK_META_MODE:Uno} == "yes"
152 .MAKE.MODE = meta verbose
154 # make sure we have a harmless value
157 # if you want objdirs make them automatic
158 # and do it early before we compute .PATH
159 .if ${MK_AUTO_OBJ:Uno} == "yes" || ${MKOBJDIRS:Uno} == "auto"
160 .include <auto.obj.mk>
164 .if ${.CURDIR} == ${SRCTOP}
166 .elif ${.CURDIR:M${SRCTOP}/*}
167 RELDIR := ${.CURDIR:S,${SRCTOP}/,,}
171 MACHINE_ARCH.host ?= ${_HOST_ARCH}
172 MACHINE_ARCH.${MACHINE} ?= ${MACHINE}
173 .if empty(MACHINE_ARCH)
174 MACHINE_ARCH = ${MACHINE_ARCH.${MACHINE}}
178 ROOT_GROUP != sed -n /:0:/s/:.*//p /etc/group
182 unix ?= We run ${_HOST_OSNAME}.
184 # A race condition in mkdir, means that it can bail if another
185 # process made a dir that mkdir expected to.
186 # We repeat the mkdir -p a number of times to try and work around this.
187 # We stop looping as soon as the dir exists.
188 # If we get to the end of the loop, a plain mkdir will issue an error.
191 for i in 1 2 3 4 5 6; do \
193 test -d $$d && return 0; \
195 mkdir $$d || exit $$?; \
198 # this often helps with debugging
202 @${COMPILE.c:N-c} -E ${.IMPSRC} | grep -v '^[ ]*$$'
205 @${COMPILE.cc:N-c} -E ${.IMPSRC} | grep -v '^[ ]*$$'
207 # late customizations
208 .-include <local.sys.mk>
210 # if .CURDIR is matched by any entry in DEBUG_MAKE_DIRS we
211 # will apply DEBUG_MAKE_FLAGS, now.
212 .if !empty(_DEBUG_MAKE_FLAGS)
213 .if ${_DEBUG_MAKE_DIRS:Uno:@x@${.CURDIR:M$x}@} != ""
214 .MAKEFLAGS: ${_DEBUG_MAKE_FLAGS}