xref: /dragonfly/contrib/bmake/mk/sys.mk (revision ef2687d4)
1# $Id: sys.mk,v 1.36 2014/05/11 00:30:19 sjg Exp $
2#
3#	@(#) Copyright (c) 2003-2009, Simon J. Gerraty
4#
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
10#	left intact.
11#
12#	Please send copies of changes and bug-fixes to:
13#	sjg@crufty.net
14#
15
16# Avoid putting anything platform specific in here.
17
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.
21#
22# _this ?= ${.PARSEFILE}
23# .if !target(__${_this}__)
24# __${_this}__:
25#
26.if ${MAKE_VERSION:U0} > 20100408
27_this = ${.PARSEDIR:tA}/${.PARSEFILE}
28.else
29_this = ${.PARSEDIR}/${.PARSEFILE}
30.endif
31
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
38#
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}}
45.else
46_DEBUG_MAKE_FLAGS = ${DEBUG_MAKE_FLAGS}
47_DEBUG_MAKE_SYS_DIRS = ${DEBUG_MAKE_SYS_DIRS}
48_DEBUG_MAKE_DIRS = ${DEBUG_MAKE_DIRS}
49.endif
50
51.if !empty(_DEBUG_MAKE_FLAGS)
52.if ${_DEBUG_MAKE_SYS_DIRS:Uno:@x@${.CURDIR:M$x}@} != ""
53.MAKEFLAGS: ${_DEBUG_MAKE_FLAGS}
54.endif
55.endif
56
57# if this is an ancient version of bmake
58MAKE_VERSION ?= 0
59.if ${MAKE_VERSION:M*make-*}
60# turn it into what we want - just the date
61MAKE_VERSION := ${MAKE_VERSION:[1]:C,.*-,,}
62.endif
63
64# some useful modifiers
65
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,}}
69M_ListToMatch = L:@m@$${V:M$$m}@
70# match against our initial targets (see above)
71M_L_TARGETS = ${M_ListToMatch:S,V,_TARGETS,}
72
73# turn a list into a set of :N modifiers
74# NskipFoo = ${Foo:${M_ListToSkip}}
75M_ListToSkip= O:u:ts::S,:,:N,g:S,^,N,
76
77# type should be a builtin in any sh since about 1980,
78# AUTOCONF := ${autoconf:L:${M_whence}}
79M_type = @x@(type $$x 2> /dev/null); echo;@:sh:[0]:N* found*:[@]:C,[()],,g
80M_whence = ${M_type}:M/*:[1]
81
82# convert a path to a valid shell variable
83M_P2V = tu:C,[./-],_,g
84
85# convert path to absolute
86.if ${MAKE_VERSION:U0} > 20100408
87M_tA = tA
88.else
89M_tA = C,.*,('cd' & \&\& 'pwd') 2> /dev/null || echo &,:sh
90.endif
91
92# absoulte path to what we are reading.
93_PARSEDIR = ${.PARSEDIR:${M_tA}}
94
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>
100.endif
101
102# we need HOST_TARGET etc below.
103.include <host-target.mk>
104
105# find the OS specifics
106.if defined(SYS_OS_MK)
107.include <${SYS_OS_MK}>
108.else
109_sys_mk =
110.for x in ${HOST_OSTYPE} ${HOST_TARGET} ${HOST_OS} ${MACHINE} Generic
111.if empty(_sys_mk)
112.-include <sys/$x.mk>
113_sys_mk := ${.MAKE.MAKEFILES:M*/$x.mk}
114.if !empty(_sys_mk)
115_sys_mk := sys/${_sys_mk:T}
116.endif
117.endif
118.if empty(_sys_mk)
119# might be an old style
120.-include <$x.sys.mk>
121_sys_mk := ${.MAKE.MAKEFILES:M*/$x.sys.mk:T}
122.endif
123.endfor
124
125SYS_OS_MK := ${_sys_mk}
126.export SYS_OS_MK
127.endif
128
129# allow customization without editing.
130.-include <local.sys.mk>
131
132# if you want objdirs make them automatic
133.if ${MKOBJDIRS:Uno} == "auto"
134.include <auto.obj.mk>
135.endif
136
137.if !empty(SRCTOP)
138.if ${.CURDIR} == ${SRCTOP}
139RELDIR = .
140.elif ${.CURDIR:M${SRCTOP}/*}
141RELDIR := ${.CURDIR:S,${SRCTOP}/,,}
142.endif
143.endif
144
145MACHINE_ARCH.host ?= ${_HOST_ARCH}
146MACHINE_ARCH.${MACHINE} ?= ${MACHINE}
147.if empty(MACHINE_ARCH)
148MACHINE_ARCH = ${MACHINE_ARCH.${MACHINE}}
149.endif
150
151.ifndef ROOT_GROUP
152ROOT_GROUP != sed -n /:0:/s/:.*//p /etc/group
153.export ROOT_GROUP
154.endif
155
156unix ?= We run ${_HOST_OSNAME}.
157
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.
163Mkdirs= Mkdirs() { \
164	for d in $$*; do \
165		for i in 1 2 3 4 5 6; do \
166			mkdir -p $$d; \
167			test -d $$d && return 0; \
168		done; \
169		mkdir $$d || exit $$?; \
170	done; }
171
172# this often helps with debugging
173.SUFFIXES:      .cpp-out
174
175.c.cpp-out:
176	@${COMPILE.c:N-c} -E ${.IMPSRC} | grep -v '^[ 	]*$$'
177
178.cc.cpp-out:
179	@${COMPILE.cc:N-c} -E ${.IMPSRC} | grep -v '^[ 	]*$$'
180
181# we don't include own.mk but user can expect -DWITH_META_MODE to work
182.if defined(WITHOUT_META_MODE)
183USE_META= no
184.elif defined(WITH_META_MODE)
185USE_META= yes
186.endif
187.if ${USE_META:Uno} == "yes"
188.-include <meta.sys.mk>
189.endif
190# make sure we have a harmless value
191.MAKE.MODE ?= normal
192
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}
198.endif
199.endif
200