xref: /freebsd/share/mk/sys.mk (revision ee7231c92936b17c592ad9d4dd92a560ff320191)
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|64le|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) && !make(test-system-*) && \
122    empty(.MAKEFLAGS:M-[nN])
123.sinclude <auto.obj.mk>
124.endif
125.endif	# ${MK_AUTO_OBJ} == "yes"
126.else # bmake
127.include <bsd.mkopt.mk>
128.endif
129
130# If the special target .POSIX appears (without prerequisites or
131# commands) before the first noncomment line in the makefile, make shall
132# process the makefile as specified by the Posix 1003.2 specification.
133# make(1) sets the special macro %POSIX in this case (to the actual
134# value "1003.2", for what it's worth).
135#
136# The rules below use this macro to distinguish between Posix-compliant
137# and default behaviour.
138#
139# This functionality is currently broken, since make(1) processes sys.mk
140# before reading any other files, and consequently has no opportunity to
141# set the %POSIX macro before we read this point.
142
143.if defined(%POSIX)
144.SUFFIXES:	.o .c .y .l .a .sh .f
145.else
146.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
147.endif
148
149AR		?=	ar
150.if defined(%POSIX)
151ARFLAGS		?=	-rv
152.else
153ARFLAGS		?=	-crsD
154.endif
155RANLIB		?=	ranlib
156.if !defined(%POSIX)
157RANLIBFLAGS	?=	-D
158.endif
159
160AS		?=	as
161AFLAGS		?=
162ACFLAGS		?=
163
164.if defined(%POSIX)
165CC		?=	c89
166CFLAGS		?=	-O
167.else
168CC		?=	cc
169.if ${MACHINE_CPUARCH} == "mips" && ${COMPILER_TYPE} == "gcc"
170# Note: there are currently issues generating code gcc-6.x targeting
171# code for at least mips32.  The system hits infinite page faults
172# when starting /sbin/init if -O2 is used.
173CFLAGS		?=	-O -pipe
174.else
175CFLAGS		?=	-O2 -pipe
176.endif
177.if defined(NO_STRICT_ALIASING)
178CFLAGS		+=	-fno-strict-aliasing
179.endif
180.endif
181IR_CFLAGS	?=	${STATIC_CFLAGS:N-O*} ${CFLAGS:N-O*}
182PO_CFLAGS	?=	${CFLAGS}
183
184# cp(1) is used to copy source files to ${.OBJDIR}, make sure it can handle
185# read-only files as non-root by passing -f.
186CP		?=	cp -f
187
188CPP		?=	cpp
189
190# C Type Format data is required for DTrace
191CTFFLAGS	?=	-L VERSION
192
193CTFCONVERT	?=	ctfconvert
194CTFMERGE	?=	ctfmerge
195
196.if defined(CFLAGS) && (${CFLAGS:M-g} != "")
197CTFFLAGS	+=	-g
198.endif
199
200CXX		?=	c++
201CXXFLAGS	?=	${CFLAGS:N-std=*:N-Wnested-externs:N-W*-prototypes:N-Wno-pointer-sign:N-Wold-style-definition}
202IR_CXXFLAGS	?=	${STATIC_CXXFLAGS:N-O*} ${CXXFLAGS:N-O*}
203PO_CXXFLAGS	?=	${CXXFLAGS}
204
205DTRACE		?=	dtrace
206DTRACEFLAGS	?=	-C -x nolibs
207
208.if empty(.MAKEFLAGS:M-s)
209ECHO		?=	echo
210ECHODIR		?=	echo
211.else
212ECHO		?=	true
213.if ${.MAKEFLAGS:M-s} == "-s"
214ECHODIR		?=	echo
215.else
216ECHODIR		?=	true
217.endif
218.endif
219
220.if ${.MAKEFLAGS:M-N}
221# bmake -N is supposed to skip executing anything but it does not skip
222# exeucting '+' commands.  The '+' feature is used where .MAKE
223# is not safe for the entire target.  -N is intended to skip building sub-makes
224# so it executing '+' commands is not right.  Work around the bug by not
225# setting '+' when -N is used.
226_+_		?=
227.else
228_+_		?=	+
229.endif
230
231.if defined(%POSIX)
232FC		?=	fort77
233FFLAGS		?=	-O 1
234.else
235FC		?=	f77
236FFLAGS		?=	-O
237.endif
238EFLAGS		?=
239
240INSTALL		?=	${INSTALL_CMD:Uinstall}
241
242LEX		?=	lex
243LFLAGS		?=
244
245# LDFLAGS is for CC, _LDFLAGS is for LD.  Generate _LDFLAGS from
246# LDFLAGS by stripping -Wl, from pass-through arguments and dropping
247# compiler driver flags (e.g. -mabi=*) that conflict with flags to LD.
248LD		?=	ld
249LDFLAGS		?=
250_LDFLAGS	=	${LDFLAGS:S/-Wl,//g:N-mabi=*:N-fuse-ld=*:N--ld-path=*}
251
252MAKE		?=	make
253
254.if !defined(%POSIX)
255LLVM_LINK	?=	llvm-link
256
257LORDER		?=	lorder
258
259NM		?=	nm
260NMFLAGS		?=
261
262OBJC		?=	cc
263OBJCFLAGS	?=	${OBJCINCLUDES} ${CFLAGS} -Wno-import
264
265OBJCOPY		?=	objcopy
266
267PC		?=	pc
268PFLAGS		?=
269
270RC		?=	f77
271RFLAGS		?=
272
273TSORT		?=	tsort
274TSORTFLAGS	?=	-q
275.endif
276
277SHELL		?=	sh
278
279.if !defined(%POSIX)
280SIZE		?=	size
281STRIPBIN	?=	strip
282.endif
283
284YACC		?=	yacc
285.if defined(%POSIX)
286YFLAGS		?=
287.else
288YFLAGS		?=	-d
289.endif
290
291.if defined(%POSIX)
292
293.include "bsd.suffixes-posix.mk"
294
295.else
296
297# non-Posix rule set
298.include "bsd.suffixes.mk"
299
300# Pull in global settings.
301__MAKE_CONF?=/etc/make.conf
302.if exists(${__MAKE_CONF})
303.include "${__MAKE_CONF}"
304.endif
305
306# late include for customization
307.sinclude <local.sys.mk>
308
309.if defined(META_MODE)
310META_MODE:=	${META_MODE:O:u}
311.endif
312
313.if defined(__MAKE_SHELL) && !empty(__MAKE_SHELL)
314SHELL=	${__MAKE_SHELL}
315.SHELL: path=${__MAKE_SHELL}
316.endif
317
318# Tell bmake to expand -V VAR by default
319.MAKE.EXPAND_VARIABLES= yes
320
321# Tell bmake the makefile preference
322MAKEFILE_PREFERENCE?= BSDmakefile makefile Makefile
323.MAKE.MAKEFILE_PREFERENCE= ${MAKEFILE_PREFERENCE}
324
325# Tell bmake to always pass job tokens, regardless of target depending on
326# .MAKE or looking like ${MAKE}/${.MAKE}/$(MAKE)/$(.MAKE)/make.
327.MAKE.ALWAYS_PASS_JOB_QUEUE= yes
328
329# By default bmake does *not* use set -e
330# when running target scripts, this is a problem for many makefiles here.
331# So define a shell that will do what FreeBSD expects.
332.ifndef WITHOUT_SHELL_ERRCTL
333__MAKE_SHELL?=/bin/sh
334.SHELL: name=sh \
335	quiet="set -" echo="set -v" filter="set -" \
336	hasErrCtl=yes check="set -e" ignore="set +e" \
337	echoFlag=v errFlag=e \
338	path=${__MAKE_SHELL}
339.endif
340
341# Hack for ports compatibility. Historically, ports makefiles have
342# assumed they can examine MACHINE_CPU without including anything
343# because this was automatically included in sys.mk. For /usr/src,
344# this file has moved to being included from bsd.opts.mk. Until all
345# the ports files are modernized, and a reasonable transition
346# period has passed, include it while we're in a ports tree here
347# to preserve historic behavior.
348.if exists(${.CURDIR}/../../Mk/bsd.port.mk)
349.include <bsd.cpu.mk>
350.endif
351
352.endif # ! Posix
353