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