xref: /freebsd/share/mk/sys.mk (revision 70a8349311934f20fcb65e763b8ac80134446796)
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/mips(n32|64)?(el)?(hf)?/mips/:C/arm(v[67])?(eb)?/arm/:C/powerpc(64|spe)/powerpc/:C/riscv64(sf)?/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_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.sinclude <meta.sys.mk>
61.elif ${MK_META_MODE} == "yes"
62META_MODE+=	meta
63.if empty(.MAKEFLAGS:M-s)
64# verbose will show .MAKE.META.PREFIX for each target.
65META_MODE+=	verbose
66.endif
67.if !defined(NO_META_MISSING)
68META_MODE+=	missing-meta=yes
69.endif
70# silent will hide command output if a .meta file is created.
71.if !defined(NO_SILENT)
72META_MODE+=	silent=yes
73.endif
74.if !exists(/dev/filemon) || defined(NO_FILEMON)
75META_MODE+= nofilemon
76.endif
77# Require filemon data with bmake
78.if empty(META_MODE:Mnofilemon)
79META_MODE+= missing-filemon=yes
80.endif
81.endif
82META_MODE?= normal
83.export META_MODE
84.MAKE.MODE?= ${META_MODE}
85.if !empty(.MAKE.MODE:Mmeta)
86.if !defined(NO_META_IGNORE_HOST)
87# Ignore host file changes that will otherwise cause
88# buildworld -> installworld -> buildworld to rebuild everything.
89# Since the build is self-reliant and bootstraps everything it needs,
90# this should not be a real problem for incremental builds.
91# XXX: This relies on the existing host tools retaining ABI compatibility
92# through upgrades since they won't be rebuilt on header/library changes.
93# This is mitigated by Makefile.inc1 for known-ABI-breaking revisions.
94# Note that these are prefix matching, so /lib matches /libexec.
95.MAKE.META.IGNORE_PATHS+= \
96	${__MAKE_SHELL} \
97	/bin \
98	/lib \
99	/rescue \
100	/sbin \
101	/usr/bin \
102	/usr/lib \
103	/usr/sbin \
104	/usr/share \
105
106.else
107NO_META_IGNORE_HOST_HEADERS=	1
108.endif
109.if !defined(NO_META_IGNORE_HOST_HEADERS)
110.MAKE.META.IGNORE_PATHS+= /usr/include
111.endif
112# We do not want everything out-of-date just because
113# some unrelated shared lib updated this.
114.MAKE.META.IGNORE_PATHS+= /usr/local/etc/libmap.d
115.endif	# !empty(.MAKE.MODE:Mmeta)
116
117.if ${MK_AUTO_OBJ} == "yes"
118# This needs to be done early - before .PATH is computed
119# Don't do this for 'make showconfig' as it enables all options where meta mode
120# is not expected.
121.if !make(showconfig) && !make(print-dir)
122.sinclude <auto.obj.mk>
123# The .OBJDIR was not set, disable MK_AUTO_OBJ so downstream checks won't
124# assume .OBJDIR is proper.
125.if defined(__objdir) && ${.OBJDIR} != ${__objdir}
126.MAKEOVERRIDES+= MK_AUTO_OBJ
127MK_AUTO_OBJ=	no
128.endif
129.endif
130.endif	# ${MK_AUTO_OBJ} == "yes"
131.else # bmake
132.include <bsd.mkopt.mk>
133.endif
134
135# If the special target .POSIX appears (without prerequisites or
136# commands) before the first noncomment line in the makefile, make shall
137# process the makefile as specified by the Posix 1003.2 specification.
138# make(1) sets the special macro %POSIX in this case (to the actual
139# value "1003.2", for what it's worth).
140#
141# The rules below use this macro to distinguish between Posix-compliant
142# and default behaviour.
143#
144# This functionality is currently broken, since make(1) processes sys.mk
145# before reading any other files, and consequently has no opportunity to
146# set the %POSIX macro before we read this point.
147
148.if defined(%POSIX)
149.SUFFIXES:	.o .c .y .l .a .sh .f
150.else
151.SUFFIXES:	.out .a .ln .o .bco .llo .c .cc .cpp .cxx .C .m .F .f .e .r .y .l .S .asm .s .cl .p .h .sh
152.endif
153
154AR		?=	ar
155.if defined(%POSIX)
156ARFLAGS		?=	-rv
157.else
158ARFLAGS		?=	-crD
159.endif
160RANLIB		?=	ranlib
161.if !defined(%POSIX)
162RANLIBFLAGS	?=	-D
163.endif
164
165AS		?=	as
166AFLAGS		?=
167ACFLAGS		?=
168
169.if defined(%POSIX)
170CC		?=	c89
171CFLAGS		?=	-O
172.else
173CC		?=	cc
174.if ${MACHINE_CPUARCH} == "arm" || ${MACHINE_CPUARCH} == "mips"
175CFLAGS		?=	-O -pipe
176.else
177CFLAGS		?=	-O2 -pipe
178.endif
179.if defined(NO_STRICT_ALIASING)
180CFLAGS		+=	-fno-strict-aliasing
181.endif
182.endif
183IR_CFLAGS	?=	${STATIC_CFLAGS:N-O*} ${CFLAGS:N-O*}
184PO_CFLAGS	?=	${CFLAGS}
185
186# cp(1) is used to copy source files to ${.OBJDIR}, make sure it can handle
187# read-only files as non-root by passing -f.
188CP		?=	cp -f
189
190CPP		?=	cpp
191
192# C Type Format data is required for DTrace
193CTFFLAGS	?=	-L VERSION
194
195CTFCONVERT	?=	ctfconvert
196CTFMERGE	?=	ctfmerge
197
198.if defined(CFLAGS) && (${CFLAGS:M-g} != "")
199CTFFLAGS	+=	-g
200.endif
201
202CXX		?=	c++
203CXXFLAGS	?=	${CFLAGS:N-std=*:N-Wnested-externs:N-W*-prototypes:N-Wno-pointer-sign:N-Wold-style-definition}
204IR_CXXFLAGS	?=	${STATIC_CXXFLAGS:N-O*} ${CXXFLAGS:N-O*}
205PO_CXXFLAGS	?=	${CXXFLAGS}
206
207DTRACE		?=	dtrace
208DTRACEFLAGS	?=	-C -x nolibs
209
210.if empty(.MAKEFLAGS:M-s)
211ECHO		?=	echo
212ECHODIR		?=	echo
213.else
214ECHO		?=	true
215.if ${.MAKEFLAGS:M-s} == "-s"
216ECHODIR		?=	echo
217.else
218ECHODIR		?=	true
219.endif
220.endif
221
222.if ${.MAKEFLAGS:M-N}
223# bmake -N is supposed to skip executing anything but it does not skip
224# exeucting '+' commands.  The '+' feature is used where .MAKE
225# is not safe for the entire target.  -N is intended to skip building sub-makes
226# so it executing '+' commands is not right.  Work around the bug by not
227# setting '+' when -N is used.
228_+_		?=
229.else
230_+_		?=	+
231.endif
232
233.if defined(%POSIX)
234FC		?=	fort77
235FFLAGS		?=	-O 1
236.else
237FC		?=	f77
238FFLAGS		?=	-O
239.endif
240EFLAGS		?=
241
242INSTALL		?=	install
243
244LEX		?=	lex
245LFLAGS		?=
246
247# LDFLAGS is for CC, _LDFLAGS is for LD.  Generate _LDFLAGS from
248# LDFLAGS by stripping -Wl, from pass-through arguments and dropping
249# compiler driver flags (e.g. -mabi=*) that conflict with flags to LD.
250LD		?=	ld
251LDFLAGS		?=
252_LDFLAGS	=	${LDFLAGS:S/-Wl,//g:N-mabi=*}
253
254LINT		?=	lint
255LINTFLAGS	?=	-cghapbx
256LINTKERNFLAGS	?=	${LINTFLAGS}
257LINTOBJFLAGS	?=	-cghapbxu -i
258LINTOBJKERNFLAGS?=	${LINTOBJFLAGS}
259LINTLIBFLAGS	?=	-cghapbxu -C ${LIB}
260
261MAKE		?=	make
262
263.if !defined(%POSIX)
264LLVM_LINK	?=	llvm-link
265
266LORDER		?=	lorder
267
268NM		?=	nm
269NMFLAGS		?=
270
271OBJC		?=	cc
272OBJCFLAGS	?=	${OBJCINCLUDES} ${CFLAGS} -Wno-import
273
274OBJCOPY		?=	objcopy
275
276PC		?=	pc
277PFLAGS		?=
278
279RC		?=	f77
280RFLAGS		?=
281
282TSORT		?=	tsort
283TSORTFLAGS	?=	-q
284.endif
285
286SHELL		?=	sh
287
288.if !defined(%POSIX)
289SIZE		?=	size
290.endif
291
292YACC		?=	yacc
293.if defined(%POSIX)
294YFLAGS		?=
295.else
296YFLAGS		?=	-d
297.endif
298
299.if defined(%POSIX)
300
301.include "bsd.suffixes-posix.mk"
302
303.else
304
305# non-Posix rule set
306.include "bsd.suffixes.mk"
307
308# Pull in global settings.
309__MAKE_CONF?=/etc/make.conf
310.if exists(${__MAKE_CONF})
311.include "${__MAKE_CONF}"
312.endif
313
314# late include for customization
315.sinclude <local.sys.mk>
316
317.if defined(META_MODE)
318META_MODE:=	${META_MODE:O:u}
319.endif
320
321.if defined(__MAKE_SHELL) && !empty(__MAKE_SHELL)
322SHELL=	${__MAKE_SHELL}
323.SHELL: path=${__MAKE_SHELL}
324.endif
325
326# Tell bmake to expand -V VAR by default
327.MAKE.EXPAND_VARIABLES= yes
328
329# Tell bmake the makefile preference
330.MAKE.MAKEFILE_PREFERENCE= BSDmakefile makefile Makefile
331
332# Tell bmake to always pass job tokens, regardless of target depending on
333# .MAKE or looking like ${MAKE}/${.MAKE}/$(MAKE)/$(.MAKE)/make.
334.MAKE.ALWAYS_PASS_JOB_QUEUE= yes
335
336# By default bmake does *not* use set -e
337# when running target scripts, this is a problem for many makefiles here.
338# So define a shell that will do what FreeBSD expects.
339.ifndef WITHOUT_SHELL_ERRCTL
340__MAKE_SHELL?=/bin/sh
341.SHELL: name=sh \
342	quiet="set -" echo="set -v" filter="set -" \
343	hasErrCtl=yes check="set -e" ignore="set +e" \
344	echoFlag=v errFlag=e \
345	path=${__MAKE_SHELL}
346.endif
347
348# Hack for ports compatibility. Historically, ports makefiles have
349# assumed they can examine MACHINE_CPU without including anything
350# because this was automatically included in sys.mk. For /usr/src,
351# this file has moved to being included from bsd.opts.mk. Until all
352# the ports files are modernized, and a reasonable transition
353# period has passed, include it while we're in a ports tree here
354# to preserve historic behavior.
355.if exists(${.CURDIR}/../../Mk/bsd.port.mk)
356.include <bsd.cpu.mk>
357.endif
358
359.endif # ! Posix
360