xref: /freebsd/share/mk/sys.mk (revision 78ae60b4)
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
156# cp(1) is used to copy source files to ${.OBJDIR}, make sure it can handle
157# read-only files as non-root by passing -f.
158CP		?=	cp -f
159
160CPP		?=	cpp
161
162# C Type Format data is required for DTrace
163CTFFLAGS	?=	-L VERSION
164
165CTFCONVERT	?=	ctfconvert
166CTFMERGE	?=	ctfmerge
167
168.if defined(CFLAGS) && (${CFLAGS:M-g} != "")
169CTFFLAGS	+=	-g
170.endif
171
172CXX		?=	c++
173CXXFLAGS	?=	${CFLAGS:N-std=*:N-Wnested-externs:N-W*-prototypes:N-Wno-pointer-sign:N-Wold-style-definition}
174IR_CXXFLAGS	?=	${STATIC_CXXFLAGS:N-O*} ${CXXFLAGS:N-O*}
175PO_CXXFLAGS	?=	${CXXFLAGS}
176
177DTRACE		?=	dtrace
178DTRACEFLAGS	?=	-C -x nolibs
179
180.if empty(.MAKEFLAGS:M-s)
181ECHO		?=	echo
182ECHODIR		?=	echo
183.else
184ECHO		?=	true
185.if ${.MAKEFLAGS:M-s} == "-s"
186ECHODIR		?=	echo
187.else
188ECHODIR		?=	true
189.endif
190.endif
191
192ELFCTL		?=	elfctl
193
194.if ${.MAKEFLAGS:M-N}
195# bmake -N is supposed to skip executing anything but it does not skip
196# exeucting '+' commands.  The '+' feature is used where .MAKE
197# is not safe for the entire target.  -N is intended to skip building sub-makes
198# so it executing '+' commands is not right.  Work around the bug by not
199# setting '+' when -N is used.
200_+_		?=
201.else
202_+_		?=	+
203.endif
204
205.if defined(%POSIX)
206FC		?=	fort77
207FFLAGS		?=	-O 1
208.else
209FC		?=	f77
210FFLAGS		?=	-O
211.endif
212EFLAGS		?=
213
214INSTALL		?=	${INSTALL_CMD:Uinstall}
215
216LEX		?=	lex
217LFLAGS		?=
218
219# LDFLAGS is for CC, _LDFLAGS is for LD.  Generate _LDFLAGS from
220# LDFLAGS by stripping -Wl, from pass-through arguments and dropping
221# compiler driver flags (e.g. -mabi=*) that conflict with flags to LD.
222LD		?=	ld
223LDFLAGS		?=
224_LDFLAGS	=	${LDFLAGS:S/-Wl,//g:N-mabi=*:N-fuse-ld=*:N--ld-path=*:N-fsanitize=*:N-fno-sanitize=*}
225
226MAKE		?=	make
227
228.if !defined(%POSIX)
229LLVM_LINK	?=	llvm-link
230
231LORDER		?=	lorder
232
233NM		?=	nm
234NMFLAGS		?=
235
236OBJC		?=	cc
237OBJCFLAGS	?=	${OBJCINCLUDES} ${CFLAGS} -Wno-import
238
239OBJCOPY		?=	objcopy
240
241PC		?=	pc
242PFLAGS		?=
243
244RC		?=	f77
245RFLAGS		?=
246
247TSORT		?=	tsort
248TSORTFLAGS	?=	-q
249.endif
250
251SHELL		?=	sh
252
253.if !defined(%POSIX)
254SIZE		?=	size
255STRIPBIN	?=	strip
256.endif
257
258YACC		?=	yacc
259.if defined(%POSIX)
260YFLAGS		?=
261.else
262YFLAGS		?=	-d
263.endif
264
265.if defined(%POSIX)
266
267.include "bsd.suffixes-posix.mk"
268
269.else
270
271# non-Posix rule set
272.include "bsd.suffixes.mk"
273
274# Pull in global settings.
275__MAKE_CONF?=/etc/make.conf
276.if exists(${__MAKE_CONF})
277.include "${__MAKE_CONF}"
278.endif
279
280# late include for customization
281.sinclude <local.sys.mk>
282
283.if defined(META_MODE)
284META_MODE:=	${META_MODE:O:u}
285.endif
286
287.if defined(__MAKE_SHELL) && !empty(__MAKE_SHELL)
288SHELL=	${__MAKE_SHELL}
289.SHELL: path=${__MAKE_SHELL}
290.endif
291
292# Tell bmake to expand -V VAR by default
293.MAKE.EXPAND_VARIABLES= yes
294
295# Tell bmake the makefile preference
296MAKEFILE_PREFERENCE?= BSDmakefile makefile Makefile
297.MAKE.MAKEFILE_PREFERENCE= ${MAKEFILE_PREFERENCE}
298
299# Tell bmake to always pass job tokens, regardless of target depending on
300# .MAKE or looking like ${MAKE}/${.MAKE}/$(MAKE)/$(.MAKE)/make.
301.MAKE.ALWAYS_PASS_JOB_QUEUE= yes
302
303# By default bmake does *not* use set -e
304# when running target scripts, this is a problem for many makefiles here.
305# So define a shell that will do what FreeBSD expects.
306.ifndef WITHOUT_SHELL_ERRCTL
307__MAKE_SHELL?=/bin/sh
308.SHELL: name=sh \
309	quiet="set -" echo="set -v" filter="set -" \
310	hasErrCtl=yes check="set -e" ignore="set +e" \
311	echoFlag=v errFlag=e \
312	path=${__MAKE_SHELL}
313.endif
314
315# Hack for ports compatibility. Historically, ports makefiles have
316# assumed they can examine MACHINE_CPU without including anything
317# because this was automatically included in sys.mk. For /usr/src,
318# this file has moved to being included from bsd.opts.mk. Until all
319# the ports files are modernized, and a reasonable transition
320# period has passed, include it while we're in a ports tree here
321# to preserve historic behavior.
322.if exists(${.CURDIR}/../../Mk/bsd.port.mk)
323.include <bsd.cpu.mk>
324.endif
325
326.endif # ! Posix
327