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