xref: /freebsd/share/mk/sys.mk (revision e62ff34a6761025203b77ffb241c926ac8d218c8)
1afe61c15SRodney W. Grimes
2415bccaaSBruce Evansunix		?=	We run FreeBSD, not UNIX.
33f5a93f6SDavid E. O'Brien.FreeBSD	?=	true
4afe61c15SRodney W. Grimes
56fc3ead1SWarner Losh.if !defined(%POSIX)
66fc3ead1SWarner Losh#
76fc3ead1SWarner Losh# MACHINE_CPUARCH defines a collection of MACHINE_ARCH.  Machines with
8bd4473b8SDimitry Andric# the same MACHINE_ARCH can run each other's binaries, so it necessarily
97709b2aeSWarner Losh# has word size and endian swizzled in.  However, the source files for
10bd4473b8SDimitry Andric# these machines often are shared amongst all combinations of size
11bd4473b8SDimitry Andric# and/or endian.  This is called MACHINE_CPU in NetBSD, but that's used
12bd4473b8SDimitry Andric# for something different in FreeBSD.
136fc3ead1SWarner Losh#
141ca12bd9SJohn Baldwin__TO_CPUARCH=C/arm(v[67])?/arm/:C/powerpc(64|64le|spe)/powerpc/:C/riscv64/riscv/
157709b2aeSWarner LoshMACHINE_CPUARCH=${MACHINE_ARCH:${__TO_CPUARCH}}
166b14aaa4SWarner Losh.endif
170815243cSMarcel Moolenaar
18dfa09989SBryan Drewery__DEFAULT_YES_OPTIONS+= \
19dfa09989SBryan Drewery	UNIFIED_OBJDIR
20ccfb9654SSimon J. Gerraty
21615a1e70SBryan Drewery# src.sys.obj.mk enables AUTO_OBJ by default if possible but it is otherwise
22615a1e70SBryan Drewery# disabled.  Ensure src.conf.5 shows it as default on.
23615a1e70SBryan Drewery.if make(showconfig)
24615a1e70SBryan Drewery__DEFAULT_YES_OPTIONS+= AUTO_OBJ
25615a1e70SBryan Drewery.endif
26ccfb9654SSimon J. Gerraty
27ccfb9654SSimon J. Gerraty# Some options we need now
28ccfb9654SSimon J. Gerraty__DEFAULT_NO_OPTIONS= \
29948f327eSSimon J. Gerraty	DIRDEPS_BUILD \
30dba62d8dSSimon J. Gerraty	DIRDEPS_CACHE
31ccfb9654SSimon J. Gerraty
32ccfb9654SSimon J. Gerraty__DEFAULT_DEPENDENT_OPTIONS= \
33948f327eSSimon J. Gerraty	AUTO_OBJ/DIRDEPS_BUILD \
34bee3d4bfSSimon J. Gerraty	META_ERROR_TARGET/DIRDEPS_BUILD \
35dba62d8dSSimon J. Gerraty	META_MODE/DIRDEPS_BUILD \
36948f327eSSimon J. Gerraty	STAGING/DIRDEPS_BUILD \
37948f327eSSimon J. Gerraty	SYSROOT/DIRDEPS_BUILD
38ccfb9654SSimon J. Gerraty
39da6e996dSBryan Drewery__ENV_ONLY_OPTIONS:= \
40da6e996dSBryan Drewery	${__DEFAULT_NO_OPTIONS} \
41da6e996dSBryan Drewery	${__DEFAULT_YES_OPTIONS} \
42da6e996dSBryan Drewery	${__DEFAULT_DEPENDENT_OPTIONS:H}
43da6e996dSBryan Drewery
44daf514d0SSimon J. Gerraty# early include for customization
45daf514d0SSimon J. Gerraty# see local.sys.mk below
46b9d0791fSWarner Losh.sinclude <local.sys.env.mk>
47ccfb9654SSimon J. Gerraty
48232af795SBryan Drewery.include <bsd.mkopt.mk>
49232af795SBryan Drewery
5037250e48SBryan Drewery# Disable MK_META_MODE with make -B
5137250e48SBryan Drewery.if ${MK_META_MODE} == "yes" && defined(.MAKEFLAGS) && ${.MAKEFLAGS:M-B}
5237250e48SBryan DreweryMK_META_MODE=	no
5337250e48SBryan Drewery.endif
5437250e48SBryan Drewery
55948f327eSSimon J. Gerraty.if ${MK_DIRDEPS_BUILD} == "yes"
56bee3d4bfSSimon J. Gerraty.-include <sys.dirdeps.mk>
57718edb15SBryan Drewery.endif
58bee3d4bfSSimon J. Gerraty.if ${MK_META_MODE} == "yes"
599369f357SBryan Drewery.if !exists(/dev/filemon) || defined(NO_FILEMON)
6064923b11SBryan DreweryMETA_MODE+= nofilemon
61952de59dSBryan Drewery.endif
62bee3d4bfSSimon J. Gerraty.-include <meta.sys.mk>
63ccfb9654SSimon J. Gerraty.endif
6464923b11SBryan DreweryMETA_MODE?= normal
6564923b11SBryan Drewery.export META_MODE
6664923b11SBryan Drewery.MAKE.MODE?= ${META_MODE}
67ffe0978fSBryan Drewery.if !empty(.MAKE.MODE:Mmeta)
68ffe0978fSBryan Drewery.if !defined(NO_META_IGNORE_HOST)
697f17cd1cSBryan Drewery# Ignore host file changes that will otherwise cause
707f17cd1cSBryan Drewery# buildworld -> installworld -> buildworld to rebuild everything.
717f17cd1cSBryan Drewery# Since the build is self-reliant and bootstraps everything it needs,
727f17cd1cSBryan Drewery# this should not be a real problem for incremental builds.
73799483e4SBryan Drewery# XXX: This relies on the existing host tools retaining ABI compatibility
74799483e4SBryan Drewery# through upgrades since they won't be rebuilt on header/library changes.
751a9cc831SBryan Drewery# This is mitigated by Makefile.inc1 for known-ABI-breaking revisions.
767f17cd1cSBryan Drewery# Note that these are prefix matching, so /lib matches /libexec.
777f17cd1cSBryan Drewery.MAKE.META.IGNORE_PATHS+= \
787f17cd1cSBryan Drewery	${__MAKE_SHELL} \
797f17cd1cSBryan Drewery	/bin \
807f17cd1cSBryan Drewery	/lib \
817f17cd1cSBryan Drewery	/rescue \
827f17cd1cSBryan Drewery	/sbin \
837f17cd1cSBryan Drewery	/usr/bin \
847f17cd1cSBryan Drewery	/usr/lib \
857f17cd1cSBryan Drewery	/usr/sbin \
867f17cd1cSBryan Drewery	/usr/share \
877f17cd1cSBryan Drewery
88ffe0978fSBryan Drewery.else
89ffe0978fSBryan DreweryNO_META_IGNORE_HOST_HEADERS=	1
907f17cd1cSBryan Drewery.endif
91ffe0978fSBryan Drewery.if !defined(NO_META_IGNORE_HOST_HEADERS)
92ffe0978fSBryan Drewery.MAKE.META.IGNORE_PATHS+= /usr/include
93ffe0978fSBryan Drewery.endif
9453b3b059SBryan Drewery# We do not want everything out-of-date just because
9553b3b059SBryan Drewery# some unrelated shared lib updated this.
9653b3b059SBryan Drewery.MAKE.META.IGNORE_PATHS+= /usr/local/etc/libmap.d
97ffe0978fSBryan Drewery.endif	# !empty(.MAKE.MODE:Mmeta)
980b6ba3f2SBryan Drewery
99ccfb9654SSimon J. Gerraty.if ${MK_AUTO_OBJ} == "yes"
100ccfb9654SSimon J. Gerraty# This needs to be done early - before .PATH is computed
101bb8cd0c6SBryan Drewery# Don't do this for 'make showconfig' as it enables all options where meta mode
102bb8cd0c6SBryan Drewery# is not expected.
1036e6be2bbSBryan Drewery.if !make(showconfig) && !make(print-dir) && !make(test-system-*) && \
1046e6be2bbSBryan Drewery    empty(.MAKEFLAGS:M-[nN])
105b9d0791fSWarner Losh.sinclude <auto.obj.mk>
1068d4b8102SBryan Drewery.endif
10740a54c51SBryan Drewery.endif	# ${MK_AUTO_OBJ} == "yes"
108ccfb9654SSimon J. Gerraty
1092be2be74SSteve Price# If the special target .POSIX appears (without prerequisites or
1102be2be74SSteve Price# commands) before the first noncomment line in the makefile, make shall
1112be2be74SSteve Price# process the makefile as specified by the Posix 1003.2 specification.
1122be2be74SSteve Price# make(1) sets the special macro %POSIX in this case (to the actual
1132be2be74SSteve Price# value "1003.2", for what it's worth).
1142be2be74SSteve Price#
1152be2be74SSteve Price# The rules below use this macro to distinguish between Posix-compliant
1162be2be74SSteve Price# and default behaviour.
11767292978SColin Percival#
11867292978SColin Percival# This functionality is currently broken, since make(1) processes sys.mk
11967292978SColin Percival# before reading any other files, and consequently has no opportunity to
12067292978SColin Percival# set the %POSIX macro before we read this point.
1212be2be74SSteve Price
1222be2be74SSteve Price.if defined(%POSIX)
1232be2be74SSteve Price.SUFFIXES:	.o .c .y .l .a .sh .f
1242be2be74SSteve Price.else
1251cbb5888SWarner Losh.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
1262be2be74SSteve Price.endif
127afe61c15SRodney W. Grimes
128415bccaaSBruce EvansAR		?=	ar
1292be2be74SSteve Price.if defined(%POSIX)
1302be2be74SSteve PriceARFLAGS		?=	-rv
1312be2be74SSteve Price.else
1320e1e341bSAlex RichardsonARFLAGS		?=	-crsD
1332be2be74SSteve Price.endif
134415bccaaSBruce EvansRANLIB		?=	ranlib
135f1c8f60bSDag-Erling Smørgrav.if !defined(%POSIX)
136f1c8f60bSDag-Erling SmørgravRANLIBFLAGS	?=	-D
137f1c8f60bSDag-Erling Smørgrav.endif
138afe61c15SRodney W. Grimes
139415bccaaSBruce EvansAS		?=	as
140415bccaaSBruce EvansAFLAGS		?=
1415ada7d99SKonstantin BelousovACFLAGS		?=
142afe61c15SRodney W. Grimes
1432be2be74SSteve Price.if defined(%POSIX)
1442be2be74SSteve PriceCC		?=	c89
145d17387acSBruce EvansCFLAGS		?=	-O
1462be2be74SSteve Price.else
147415bccaaSBruce EvansCC		?=	cc
14820c46652SDavid E. O'BrienCFLAGS		?=	-O2 -pipe
149cfb5b325SJohn Birrell.if defined(NO_STRICT_ALIASING)
150cfb5b325SJohn BirrellCFLAGS		+=	-fno-strict-aliasing
151d17387acSBruce Evans.endif
152cdc162feSOlivier Houchard.endif
153c867306eSJonathan AndersonIR_CFLAGS	?=	${STATIC_CFLAGS:N-O*} ${CFLAGS:N-O*}
154424b4e66SStephane E. PotvinPO_CFLAGS	?=	${CFLAGS}
155afe61c15SRodney W. Grimes
1563abd36c6SStephen J. KiernanHOST_CC		?=	${CC}
1573abd36c6SStephen J. Kiernan
1580c76c8aaSMark Johnston# cp(1) is used to copy source files to ${.OBJDIR}, make sure it can handle
1590c76c8aaSMark Johnston# read-only files as non-root by passing -f.
1600c76c8aaSMark JohnstonCP		?=	cp -f
1610c76c8aaSMark Johnston
1620c76c8aaSMark JohnstonCPP		?=	cpp
1630c76c8aaSMark Johnston
164770ac3b2SJohn Birrell# C Type Format data is required for DTrace
165770ac3b2SJohn BirrellCTFFLAGS	?=	-L VERSION
166770ac3b2SJohn Birrell
167770ac3b2SJohn BirrellCTFCONVERT	?=	ctfconvert
168770ac3b2SJohn BirrellCTFMERGE	?=	ctfmerge
1697a37b5fcSWill Andrews
170770ac3b2SJohn Birrell.if defined(CFLAGS) && (${CFLAGS:M-g} != "")
171770ac3b2SJohn BirrellCTFFLAGS	+=	-g
172770ac3b2SJohn Birrell.endif
173770ac3b2SJohn Birrell
174443dced5SPaul RichardsCXX		?=	c++
17596f2d85eSMarcel MoolenaarCXXFLAGS	?=	${CFLAGS:N-std=*:N-Wnested-externs:N-W*-prototypes:N-Wno-pointer-sign:N-Wold-style-definition}
176c867306eSJonathan AndersonIR_CXXFLAGS	?=	${STATIC_CXXFLAGS:N-O*} ${CXXFLAGS:N-O*}
177424b4e66SStephane E. PotvinPO_CXXFLAGS	?=	${CXXFLAGS}
178afe61c15SRodney W. Grimes
1790c76c8aaSMark JohnstonDTRACE		?=	dtrace
1800c76c8aaSMark JohnstonDTRACEFLAGS	?=	-C -x nolibs
181afe61c15SRodney W. Grimes
18265d2bdc6SRuslan Ermilov.if empty(.MAKEFLAGS:M-s)
183415bccaaSBruce EvansECHO		?=	echo
184415bccaaSBruce EvansECHODIR		?=	echo
185415bccaaSBruce Evans.else
186415bccaaSBruce EvansECHO		?=	true
187415bccaaSBruce Evans.if ${.MAKEFLAGS:M-s} == "-s"
188415bccaaSBruce EvansECHODIR		?=	echo
189415bccaaSBruce Evans.else
190415bccaaSBruce EvansECHODIR		?=	true
191415bccaaSBruce Evans.endif
192415bccaaSBruce Evans.endif
193afe61c15SRodney W. Grimes
194c6081deaSMarcin WojtasELFCTL		?=	elfctl
195c6081deaSMarcin Wojtas
19656585ab5SBryan Drewery.if ${.MAKEFLAGS:M-N}
19756585ab5SBryan Drewery# bmake -N is supposed to skip executing anything but it does not skip
19856585ab5SBryan Drewery# exeucting '+' commands.  The '+' feature is used where .MAKE
19956585ab5SBryan Drewery# is not safe for the entire target.  -N is intended to skip building sub-makes
20056585ab5SBryan Drewery# so it executing '+' commands is not right.  Work around the bug by not
20156585ab5SBryan Drewery# setting '+' when -N is used.
202acabf29aSHartmut Brandt_+_		?=
203acabf29aSHartmut Brandt.else
204acabf29aSHartmut Brandt_+_		?=	+
205acabf29aSHartmut Brandt.endif
206acabf29aSHartmut Brandt
2072be2be74SSteve Price.if defined(%POSIX)
2082be2be74SSteve PriceFC		?=	fort77
2092be2be74SSteve PriceFFLAGS		?=	-O 1
2102be2be74SSteve Price.else
211415bccaaSBruce EvansFC		?=	f77
212415bccaaSBruce EvansFFLAGS		?=	-O
2132be2be74SSteve Price.endif
214415bccaaSBruce EvansEFLAGS		?=
215afe61c15SRodney W. Grimes
216a8b8edb2SMaxim SobolevINSTALL		?=	${INSTALL_CMD:Uinstall}
217c7499507SAndrey A. Chernov
218415bccaaSBruce EvansLEX		?=	lex
219415bccaaSBruce EvansLFLAGS		?=
220afe61c15SRodney W. Grimes
221ea22493aSJohn Baldwin# LDFLAGS is for CC, _LDFLAGS is for LD.  Generate _LDFLAGS from
222ea22493aSJohn Baldwin# LDFLAGS by stripping -Wl, from pass-through arguments and dropping
223ea22493aSJohn Baldwin# compiler driver flags (e.g. -mabi=*) that conflict with flags to LD.
224415bccaaSBruce EvansLD		?=	ld
225ea22493aSJohn BaldwinLDFLAGS		?=
2267bc797e3SAlex Richardson_LDFLAGS	=	${LDFLAGS:S/-Wl,//g:N-mabi=*:N-fuse-ld=*:N--ld-path=*:N-fsanitize=*:N-fno-sanitize=*}
227afe61c15SRodney W. Grimes
228415bccaaSBruce EvansMAKE		?=	make
229afe61c15SRodney W. Grimes
2306f1d6967SWarner Losh.if !defined(%POSIX)
231e4195e2eSJonathan AndersonLLVM_LINK	?=	llvm-link
232e4195e2eSJonathan Anderson
233e7c08366SMarcel MoolenaarLORDER		?=	lorder
234e7c08366SMarcel Moolenaar
2356f1d6967SWarner LoshNM		?=	nm
23625ec8c92SRui PauloNMFLAGS		?=
2376f1d6967SWarner Losh
23870a6e331SBruce EvansOBJC		?=	cc
23970a6e331SBruce EvansOBJCFLAGS	?=	${OBJCINCLUDES} ${CFLAGS} -Wno-import
24070a6e331SBruce Evans
241e97696b5SEd MasteOBJCOPY		?=	objcopy
242e97696b5SEd Maste
243415bccaaSBruce EvansPC		?=	pc
244415bccaaSBruce EvansPFLAGS		?=
245afe61c15SRodney W. Grimes
246415bccaaSBruce EvansRC		?=	f77
247415bccaaSBruce EvansRFLAGS		?=
248e7c08366SMarcel Moolenaar
249e7c08366SMarcel MoolenaarTSORT		?=	tsort
250e7c08366SMarcel MoolenaarTSORTFLAGS	?=	-q
25144383aa3SEd Maste.endif
252415bccaaSBruce Evans
253415bccaaSBruce EvansSHELL		?=	sh
254415bccaaSBruce Evans
25578abccfcSBaptiste Daroussin.if !defined(%POSIX)
25678abccfcSBaptiste DaroussinSIZE		?=	size
2571a18ab42SAlex RichardsonSTRIPBIN	?=	strip
25878abccfcSBaptiste Daroussin.endif
25978abccfcSBaptiste Daroussin
260415bccaaSBruce EvansYACC		?=	yacc
2612be2be74SSteve Price.if defined(%POSIX)
2622be2be74SSteve PriceYFLAGS		?=
2632be2be74SSteve Price.else
264415bccaaSBruce EvansYFLAGS		?=	-d
2652be2be74SSteve Price.endif
2662be2be74SSteve Price
2672be2be74SSteve Price.if defined(%POSIX)
2688d962594SBruce Evans
269808b18e4SJonathan Anderson.include "bsd.suffixes-posix.mk"
2702be2be74SSteve Price
2712be2be74SSteve Price.else
2722be2be74SSteve Price
2732be2be74SSteve Price# non-Posix rule set
274808b18e4SJonathan Anderson.include "bsd.suffixes.mk"
2753585b293SGarrett Wollman
276daf514d0SSimon J. Gerraty# Pull in global settings.
277daf514d0SSimon J. Gerraty__MAKE_CONF?=/etc/make.conf
278daf514d0SSimon J. Gerraty.if exists(${__MAKE_CONF})
279daf514d0SSimon J. Gerraty.include "${__MAKE_CONF}"
280daf514d0SSimon J. Gerraty.endif
281daf514d0SSimon J. Gerraty
282daf514d0SSimon J. Gerraty# late include for customization
283b9d0791fSWarner Losh.sinclude <local.sys.mk>
28434bbee43SWarner Losh
2853ea2c169SBryan Drewery.if defined(META_MODE)
2863ea2c169SBryan DreweryMETA_MODE:=	${META_MODE:O:u}
2873ea2c169SBryan Drewery.endif
2883ea2c169SBryan Drewery
289a39cea66SYaroslav Tykhiy.if defined(__MAKE_SHELL) && !empty(__MAKE_SHELL)
290a39cea66SYaroslav TykhiySHELL=	${__MAKE_SHELL}
291a39cea66SYaroslav Tykhiy.SHELL: path=${__MAKE_SHELL}
292a39cea66SYaroslav Tykhiy.endif
293a39cea66SYaroslav Tykhiy
294a0f1aa83SSimon J. Gerraty# Tell bmake to expand -V VAR by default
295a0f1aa83SSimon J. Gerraty.MAKE.EXPAND_VARIABLES= yes
296a0f1aa83SSimon J. Gerraty
297a0f1aa83SSimon J. Gerraty# Tell bmake the makefile preference
298a12a1b47SBryan DreweryMAKEFILE_PREFERENCE?= BSDmakefile makefile Makefile
299a12a1b47SBryan Drewery.MAKE.MAKEFILE_PREFERENCE= ${MAKEFILE_PREFERENCE}
300a0f1aa83SSimon J. Gerraty
301c41b6218SBryan Drewery# Tell bmake to always pass job tokens, regardless of target depending on
302c41b6218SBryan Drewery# .MAKE or looking like ${MAKE}/${.MAKE}/$(MAKE)/$(.MAKE)/make.
303c41b6218SBryan Drewery.MAKE.ALWAYS_PASS_JOB_QUEUE= yes
304c41b6218SBryan Drewery
305a0f1aa83SSimon J. Gerraty# By default bmake does *not* use set -e
306a0f1aa83SSimon J. Gerraty# when running target scripts, this is a problem for many makefiles here.
307a0f1aa83SSimon J. Gerraty# So define a shell that will do what FreeBSD expects.
308a0f1aa83SSimon J. Gerraty.ifndef WITHOUT_SHELL_ERRCTL
309b9d0791fSWarner Losh__MAKE_SHELL?=/bin/sh
310a0f1aa83SSimon J. Gerraty.SHELL: name=sh \
311a0f1aa83SSimon J. Gerraty	quiet="set -" echo="set -v" filter="set -" \
312a0f1aa83SSimon J. Gerraty	hasErrCtl=yes check="set -e" ignore="set +e" \
313a0f1aa83SSimon J. Gerraty	echoFlag=v errFlag=e \
314b9d0791fSWarner Losh	path=${__MAKE_SHELL}
315a0f1aa83SSimon J. Gerraty.endif
316a0f1aa83SSimon J. Gerraty
3179ca54343SWarner Losh# Hack for ports compatibility. Historically, ports makefiles have
318682d8404SMarcelo Araujo# assumed they can examine MACHINE_CPU without including anything
3199ca54343SWarner Losh# because this was automatically included in sys.mk. For /usr/src,
3209ca54343SWarner Losh# this file has moved to being included from bsd.opts.mk. Until all
321682d8404SMarcelo Araujo# the ports files are modernized, and a reasonable transition
3229ca54343SWarner Losh# period has passed, include it while we're in a ports tree here
3239ca54343SWarner Losh# to preserve historic behavior.
324*e62ff34aSBrooks Davis.if exists(${.CURDIR}/../../Mk/Uses)
3258d962594SBruce Evans.include <bsd.cpu.mk>
3269ca54343SWarner Losh.endif
327be4646cfSWarner Losh
328be4646cfSWarner Losh.endif # ! Posix
329