1
2unix		?=	We run FreeBSD, not UNIX.
3.FreeBSD	?=	true
4
5.if !defined(%POSIX)
6#
7# MACHINE_CPUARCH defines a collection of MACHINE_ARCH.  Machines with
8# the same MACHINE_ARCH can run each other's binaries, so it necessarily
9# has word size and endian swizzled in.  However, the source files for
10# these machines often are shared amongst all combinations of size
11# and/or endian.  This is called MACHINE_CPU in NetBSD, but that's used
12# for something different in FreeBSD.
13#
14__TO_CPUARCH=C/arm(v[67])?/arm/:C/powerpc(64|64le|spe)/powerpc/:C/riscv64/riscv/
15MACHINE_CPUARCH=${MACHINE_ARCH:${__TO_CPUARCH}}
16.endif
17
18__DEFAULT_YES_OPTIONS+= \
19	UNIFIED_OBJDIR
20
21# src.sys.obj.mk enables AUTO_OBJ by default if possible but it is otherwise
22# disabled.  Ensure src.conf.5 shows it as default on.
23.if make(showconfig)
24__DEFAULT_YES_OPTIONS+= AUTO_OBJ
25.endif
26
27# Some options we need now
28__DEFAULT_NO_OPTIONS= \
29	DIRDEPS_BUILD \
30	DIRDEPS_CACHE
31
32__DEFAULT_DEPENDENT_OPTIONS= \
33	AUTO_OBJ/DIRDEPS_BUILD \
34	META_ERROR_TARGET/DIRDEPS_BUILD \
35	META_MODE/DIRDEPS_BUILD \
36	STAGING/DIRDEPS_BUILD \
37	SYSROOT/DIRDEPS_BUILD
38
39__ENV_ONLY_OPTIONS:= \
40	${__DEFAULT_NO_OPTIONS} \
41	${__DEFAULT_YES_OPTIONS} \
42	${__DEFAULT_DEPENDENT_OPTIONS:H}
43
44# early include for customization
45# see local.sys.mk below
46.sinclude <local.sys.env.mk>
47
48.include <bsd.mkopt.mk>
49
50# Disable MK_META_MODE with make -B
51.if ${MK_META_MODE} == "yes" && defined(.MAKEFLAGS) && ${.MAKEFLAGS:M-B}
52MK_META_MODE=	no
53.endif
54
55.if ${MK_DIRDEPS_BUILD} == "yes"
56.-include <sys.dirdeps.mk>
57.endif
58.if ${MK_META_MODE} == "yes"
59.if !exists(/dev/filemon) || defined(NO_FILEMON)
60META_MODE+= nofilemon
61.endif
62.-include <meta.sys.mk>
63.endif
64META_MODE?= normal
65.export META_MODE
66.MAKE.MODE?= ${META_MODE}
67.if !empty(.MAKE.MODE:Mmeta)
68.if !defined(NO_META_IGNORE_HOST)
69# Ignore host file changes that will otherwise cause
70# buildworld -> installworld -> buildworld to rebuild everything.
71# Since the build is self-reliant and bootstraps everything it needs,
72# this should not be a real problem for incremental builds.
73# XXX: This relies on the existing host tools retaining ABI compatibility
74# through upgrades since they won't be rebuilt on header/library changes.
75# This is mitigated by Makefile.inc1 for known-ABI-breaking revisions.
76# Note that these are prefix matching, so /lib matches /libexec.
77.MAKE.META.IGNORE_PATHS+= \
78	${__MAKE_SHELL} \
79	/bin \
80	/lib \
81	/rescue \
82	/sbin \
83	/usr/bin \
84	/usr/lib \
85	/usr/sbin \
86	/usr/share \
87
88.else
89NO_META_IGNORE_HOST_HEADERS=	1
90.endif
91.if !defined(NO_META_IGNORE_HOST_HEADERS)
92.MAKE.META.IGNORE_PATHS+= /usr/include
93.endif
94# We do not want everything out-of-date just because
95# some unrelated shared lib updated this.
96.MAKE.META.IGNORE_PATHS+= /usr/local/etc/libmap.d
97.endif	# !empty(.MAKE.MODE:Mmeta)
98
99.if ${MK_AUTO_OBJ} == "yes"
100# This needs to be done early - before .PATH is computed
101# Don't do this for 'make showconfig' as it enables all options where meta mode
102# is not expected.
103.if !make(showconfig) && !make(print-dir) && !make(test-system-*) && \
104    empty(.MAKEFLAGS:M-[nN])
105.sinclude <auto.obj.mk>
106.endif
107.endif	# ${MK_AUTO_OBJ} == "yes"
108
109# If the special target .POSIX appears (without prerequisites or
110# commands) before the first noncomment line in the makefile, make shall
111# process the makefile as specified by the Posix 1003.2 specification.
112# make(1) sets the special macro %POSIX in this case (to the actual
113# value "1003.2", for what it's worth).
114#
115# The rules below use this macro to distinguish between Posix-compliant
116# and default behaviour.
117#
118# This functionality is currently broken, since make(1) processes sys.mk
119# before reading any other files, and consequently has no opportunity to
120# set the %POSIX macro before we read this point.
121
122.if defined(%POSIX)
123.SUFFIXES:	.o .c .y .l .a .sh .f
124.else
125.SUFFIXES:	.out .a .o .bco .llo .c .cc .cpp .cxx .C .m .F .f .e .r .y .l .S .asm .s .cl .p .h .sh
126.endif
127
128AR		?=	ar
129.if defined(%POSIX)
130ARFLAGS		?=	-rv
131.else
132ARFLAGS		?=	-crsD
133.endif
134RANLIB		?=	ranlib
135.if !defined(%POSIX)
136RANLIBFLAGS	?=	-D
137.endif
138
139AS		?=	as
140AFLAGS		?=
141ACFLAGS		?=
142
143.if defined(%POSIX)
144CC		?=	c89
145CFLAGS		?=	-O
146.else
147CC		?=	cc
148CFLAGS		?=	-O2 -pipe
149.if defined(NO_STRICT_ALIASING)
150CFLAGS		+=	-fno-strict-aliasing
151.endif
152.endif
153IR_CFLAGS	?=	${STATIC_CFLAGS:N-O*} ${CFLAGS:N-O*}
154PO_CFLAGS	?=	${CFLAGS}
155
156HOST_CC		?=	${CC}
157
158# cp(1) is used to copy source files to ${.OBJDIR}, make sure it can handle
159# read-only files as non-root by passing -f.
160CP		?=	cp -f
161
162CPP		?=	cpp
163
164# C Type Format data is required for DTrace
165CTFFLAGS	?=	-L VERSION
166
167CTFCONVERT	?=	ctfconvert
168CTFMERGE	?=	ctfmerge
169
170.if defined(CFLAGS) && (${CFLAGS:M-g} != "")
171CTFFLAGS	+=	-g
172.endif
173
174CXX		?=	c++
175CXXFLAGS	?=	${CFLAGS:N-std=*:N-Wnested-externs:N-W*-prototypes:N-Wno-pointer-sign:N-Wold-style-definition}
176IR_CXXFLAGS	?=	${STATIC_CXXFLAGS:N-O*} ${CXXFLAGS:N-O*}
177PO_CXXFLAGS	?=	${CXXFLAGS}
178
179DTRACE		?=	dtrace
180DTRACEFLAGS	?=	-C -x nolibs
181
182.if empty(.MAKEFLAGS:M-s)
183ECHO		?=	echo
184ECHODIR		?=	echo
185.else
186ECHO		?=	true
187.if ${.MAKEFLAGS:M-s} == "-s"
188ECHODIR		?=	echo
189.else
190ECHODIR		?=	true
191.endif
192.endif
193
194ELFCTL		?=	elfctl
195
196.if ${.MAKEFLAGS:M-N}
197# bmake -N is supposed to skip executing anything but it does not skip
198# exeucting '+' commands.  The '+' feature is used where .MAKE
199# is not safe for the entire target.  -N is intended to skip building sub-makes
200# so it executing '+' commands is not right.  Work around the bug by not
201# setting '+' when -N is used.
202_+_		?=
203.else
204_+_		?=	+
205.endif
206
207.if defined(%POSIX)
208FC		?=	fort77
209FFLAGS		?=	-O 1
210.else
211FC		?=	f77
212FFLAGS		?=	-O
213.endif
214EFLAGS		?=
215
216INSTALL		?=	${INSTALL_CMD:Uinstall}
217
218LEX		?=	lex
219LFLAGS		?=
220
221# LDFLAGS is for CC, _LDFLAGS is for LD.  Generate _LDFLAGS from
222# LDFLAGS by stripping -Wl, from pass-through arguments and dropping
223# compiler driver flags (e.g. -mabi=*) that conflict with flags to LD.
224LD		?=	ld
225LDFLAGS		?=
226_LDFLAGS	=	${LDFLAGS:S/-Wl,//g:N-mabi=*:N-fuse-ld=*:N--ld-path=*:N-fsanitize=*:N-fno-sanitize=*}
227
228MAKE		?=	make
229
230.if !defined(%POSIX)
231LLVM_LINK	?=	llvm-link
232
233LORDER		?=	lorder
234
235NM		?=	nm
236NMFLAGS		?=
237
238OBJC		?=	cc
239OBJCFLAGS	?=	${OBJCINCLUDES} ${CFLAGS} -Wno-import
240
241OBJCOPY		?=	objcopy
242
243PC		?=	pc
244PFLAGS		?=
245
246RC		?=	f77
247RFLAGS		?=
248
249TSORT		?=	tsort
250TSORTFLAGS	?=	-q
251.endif
252
253SHELL		?=	sh
254
255.if !defined(%POSIX)
256SIZE		?=	size
257STRIPBIN	?=	strip
258.endif
259
260YACC		?=	yacc
261.if defined(%POSIX)
262YFLAGS		?=
263.else
264YFLAGS		?=	-d
265.endif
266
267.if defined(%POSIX)
268
269.include "bsd.suffixes-posix.mk"
270
271.else
272
273# non-Posix rule set
274.include "bsd.suffixes.mk"
275
276# Pull in global settings.
277__MAKE_CONF?=/etc/make.conf
278.if exists(${__MAKE_CONF})
279.include "${__MAKE_CONF}"
280.endif
281
282# late include for customization
283.sinclude <local.sys.mk>
284
285.if defined(META_MODE)
286META_MODE:=	${META_MODE:O:u}
287.endif
288
289.if defined(__MAKE_SHELL) && !empty(__MAKE_SHELL)
290SHELL=	${__MAKE_SHELL}
291.SHELL: path=${__MAKE_SHELL}
292.endif
293
294# Tell bmake to expand -V VAR by default
295.MAKE.EXPAND_VARIABLES= yes
296
297# Tell bmake the makefile preference
298MAKEFILE_PREFERENCE?= BSDmakefile makefile Makefile
299.MAKE.MAKEFILE_PREFERENCE= ${MAKEFILE_PREFERENCE}
300
301# Tell bmake to always pass job tokens, regardless of target depending on
302# .MAKE or looking like ${MAKE}/${.MAKE}/$(MAKE)/$(.MAKE)/make.
303.MAKE.ALWAYS_PASS_JOB_QUEUE= yes
304
305# By default bmake does *not* use set -e
306# when running target scripts, this is a problem for many makefiles here.
307# So define a shell that will do what FreeBSD expects.
308.ifndef WITHOUT_SHELL_ERRCTL
309__MAKE_SHELL?=/bin/sh
310.SHELL: name=sh \
311	quiet="set -" echo="set -v" filter="set -" \
312	hasErrCtl=yes check="set -e" ignore="set +e" \
313	echoFlag=v errFlag=e \
314	path=${__MAKE_SHELL}
315.endif
316
317# Hack for ports compatibility. Historically, ports makefiles have
318# assumed they can examine MACHINE_CPU without including anything
319# because this was automatically included in sys.mk. For /usr/src,
320# this file has moved to being included from bsd.opts.mk. Until all
321# the ports files are modernized, and a reasonable transition
322# period has passed, include it while we're in a ports tree here
323# to preserve historic behavior.
324.if exists(${.CURDIR}/../../Mk/bsd.port.mk)
325.include <bsd.cpu.mk>
326.endif
327
328.endif # ! Posix
329