12340Sbde#	from: @(#)sys.mk	8.2 (Berkeley) 3/21/94
250476Speter# $FreeBSD: stable/10/share/mk/sys.mk 330425 2018-03-04 23:34:04Z bdrewery $
31638Srgrimes
42340Sbdeunix		?=	We run FreeBSD, not UNIX.
578347Sobrien.FreeBSD	?=	true
61638Srgrimes
7209024Simp.if !defined(%POSIX)
8209024Simp#
9209024Simp# MACHINE_CPUARCH defines a collection of MACHINE_ARCH.  Machines with
10215149Sdim# the same MACHINE_ARCH can run each other's binaries, so it necessarily
11215149Sdim# has word size and endian swizzled in.  However, support files for
12215149Sdim# these machines often are shared amongst all combinations of size
13215149Sdim# and/or endian.  This is called MACHINE_CPU in NetBSD, but that's used
14215149Sdim# for something different in FreeBSD.
15209024Simp#
16239272SgonzoMACHINE_CPUARCH=${MACHINE_ARCH:C/mips(n32|64)?(el)?/mips/:C/arm(v6)?(eb)?/arm/:C/powerpc64/powerpc/}
17209024Simp.endif
18209024Simp
19241298Smarcel# Set any local definitions first. Place this early, but it needs
20241298Smarcel# MACHINE_CPUARCH to be defined.
21241298Smarcel.sinclude <local.sys.mk>
22241298Smarcel
2319343Ssteve# If the special target .POSIX appears (without prerequisites or
2419343Ssteve# commands) before the first noncomment line in the makefile, make shall
2519343Ssteve# process the makefile as specified by the Posix 1003.2 specification.
2619343Ssteve# make(1) sets the special macro %POSIX in this case (to the actual
2719343Ssteve# value "1003.2", for what it's worth).
2819343Ssteve#
2919343Ssteve# The rules below use this macro to distinguish between Posix-compliant
3019343Ssteve# and default behaviour.
3119343Ssteve
3219343Ssteve.if defined(%POSIX)
3319343Ssteve.SUFFIXES:	.o .c .y .l .a .sh .f
3419343Ssteve.else
35117173Sru.SUFFIXES:	.out .a .ln .o .c .cc .cpp .cxx .C .m .F .f .e .r .y .l .S .asm .s .cl .p .h .sh
3619343Ssteve.endif
371638Srgrimes
382340SbdeAR		?=	ar
3919343Ssteve.if defined(%POSIX)
4019343SsteveARFLAGS		?=	-rv
4119343Ssteve.else
42270484SdesARFLAGS		?=	-crD
4319343Ssteve.endif
442340SbdeRANLIB		?=	ranlib
45270484Sdes.if !defined(%POSIX)
46270484SdesRANLIBFLAGS	?=	-D
47270484Sdes.endif
481638Srgrimes
492340SbdeAS		?=	as
502340SbdeAFLAGS		?=
51217100SkibACFLAGS		?=
521638Srgrimes
5319343Ssteve.if defined(%POSIX)
5419343SsteveCC		?=	c89
55125445SbdeCFLAGS		?=	-O
5619343Ssteve.else
572340SbdeCC		?=	cc
58209024Simp.if ${MACHINE_CPUARCH} == "arm" || ${MACHINE_CPUARCH} == "mips"
59177865SobrienCFLAGS		?=	-O -pipe
60173375Scognet.else
61177865SobrienCFLAGS		?=	-O2 -pipe
6219343Ssteve.endif
63173850Sjb.if defined(NO_STRICT_ALIASING)
64173850SjbCFLAGS		+=	-fno-strict-aliasing
65173375Scognet.endif
66173850Sjb.endif
67202807SsepotvinPO_CFLAGS	?=	${CFLAGS}
681638Srgrimes
69179184Sjb# C Type Format data is required for DTrace
70179184SjbCTFFLAGS	?=	-L VERSION
71179184Sjb
72179184SjbCTFCONVERT	?=	ctfconvert
73179184SjbCTFMERGE	?=	ctfmerge
74212422SrpauloDTRACE		?=	dtrace
75179184Sjb.if defined(CFLAGS) && (${CFLAGS:M-g} != "")
76179184SjbCTFFLAGS	+=	-g
77179184Sjb.else
78206082Snetchild# XXX: What to do here? Is removing the CFLAGS part completely ok here?
79206082Snetchild# For now comment it out to not compile with -g unconditionally.
80206082Snetchild#CFLAGS		+=	-g
81179184Sjb.endif
82179184Sjb
832419SpaulCXX		?=	c++
84204024SmarcelCXXFLAGS	?=	${CFLAGS:N-std=*:N-Wnested-externs:N-W*-prototypes:N-Wno-pointer-sign:N-Wold-style-definition}
85202807SsepotvinPO_CXXFLAGS	?=	${CXXFLAGS}
861638Srgrimes
872340SbdeCPP		?=	cpp
881638Srgrimes
89125119Sru.if empty(.MAKEFLAGS:M-s)
902340SbdeECHO		?=	echo
912340SbdeECHODIR		?=	echo
922340Sbde.else
932340SbdeECHO		?=	true
942340Sbde.if ${.MAKEFLAGS:M-s} == "-s"
952340SbdeECHODIR		?=	echo
962340Sbde.else
972340SbdeECHODIR		?=	true
982340Sbde.endif
992340Sbde.endif
1001638Srgrimes
101251748Ssjg.if defined(.PARSEDIR)
102251748Ssjg# _+_ appears to be a workaround for the special src .MAKE not working.
103251748Ssjg# setting it to + interferes with -N
104133369Sharti_+_		?=
105251748Ssjg.elif !empty(.MAKEFLAGS:M-n) && ${.MAKEFLAGS:M-n} == "-n"
106251748Ssjg# the check above matches only a single -n, so -n -n will result
107251748Ssjg# in _+_ = +
108251748Ssjg_+_		?=
109133369Sharti.else
110133369Sharti_+_		?=	+
111133369Sharti.endif
112133369Sharti
11319343Ssteve.if defined(%POSIX)
11419343SsteveFC		?=	fort77
11519343SsteveFFLAGS		?=	-O 1
11619343Ssteve.else
1172340SbdeFC		?=	f77
1182340SbdeFFLAGS		?=	-O
11919343Ssteve.endif
1202340SbdeEFLAGS		?=
1211638Srgrimes
1225257SacheINSTALL		?=	install
1235257Sache
1242340SbdeLEX		?=	lex
1252340SbdeLFLAGS		?=
1261638Srgrimes
1272340SbdeLD		?=	ld
1282340SbdeLDFLAGS		?=
1291638Srgrimes
1302340SbdeLINT		?=	lint
13192813SruLINTFLAGS	?=	-cghapbx
13292491SmarkmLINTKERNFLAGS	?=	${LINTFLAGS}
13392491SmarkmLINTOBJFLAGS	?=	-cghapbxu -i
134120485SmarkmLINTOBJKERNFLAGS?=	${LINTOBJFLAGS}
13592491SmarkmLINTLIBFLAGS	?=	-cghapbxu -C ${LIB}
1361638Srgrimes
1372340SbdeMAKE		?=	make
1381638Srgrimes
139234575Simp.if !defined(%POSIX)
140234575SimpNM		?=	nm
141234575Simp
14236054SbdeOBJC		?=	cc
14336054SbdeOBJCFLAGS	?=	${OBJCINCLUDES} ${CFLAGS} -Wno-import
14436054Sbde
145244236SemasteOBJCOPY		?=	objcopy
146244236Semaste
147294064SsmhOBJDUMP		?=	objdump
148294064Ssmh
1492340SbdePC		?=	pc
1502340SbdePFLAGS		?=
1511638Srgrimes
1522340SbdeRC		?=	f77
1532340SbdeRFLAGS		?=
154244366Semaste.endif
1551638Srgrimes
1562340SbdeSHELL		?=	sh
1572340Sbde
1582340SbdeYACC		?=	yacc
15919343Ssteve.if defined(%POSIX)
16019343SsteveYFLAGS		?=
16119343Ssteve.else
1622340SbdeYFLAGS		?=	-d
16319343Ssteve.endif
1642340Sbde
16519343Ssteve.if defined(%POSIX)
166129163Sbde
16719343Ssteve# Posix 1003.2 mandated rules
16819343Ssteve#
16919343Ssteve# Quoted directly from the Posix 1003.2 draft, only the macros
17019343Ssteve# $@, $< and $* have been replaced by ${.TARGET}, ${.IMPSRC}, and
17119343Ssteve# ${.PREFIX}, resp.
17219343Ssteve
17319343Ssteve# SINGLE SUFFIX RULES
17411613Sbde.c:
17519481Salex	${CC} ${CFLAGS} ${LDFLAGS} -o ${.TARGET} ${.IMPSRC}
176228137Sfjoe	${CTFCONVERT_CMD}
17719343Ssteve
17819343Ssteve.f:
17919481Salex	${FC} ${FFLAGS} ${LDFLAGS} -o ${.TARGET} ${.IMPSRC}
180228137Sfjoe	${CTFCONVERT_CMD}
18119343Ssteve
18219343Ssteve.sh:
183211243Swill	cp -f ${.IMPSRC} ${.TARGET}
18419343Ssteve	chmod a+x ${.TARGET}
18519343Ssteve
18619343Ssteve# DOUBLE SUFFIX RULES
18719343Ssteve
18819343Ssteve.c.o:
18919481Salex	${CC} ${CFLAGS} -c ${.IMPSRC}
190228137Sfjoe	${CTFCONVERT_CMD}
19119343Ssteve
19219343Ssteve.f.o:
19319481Salex	${FC} ${FFLAGS} -c ${.IMPSRC}
194228137Sfjoe	${CTFCONVERT_CMD}
19519343Ssteve
19619343Ssteve.y.o:
19719481Salex	${YACC} ${YFLAGS} ${.IMPSRC}
19819481Salex	${CC} ${CFLAGS} -c y.tab.c
19939208Sobrien	rm -f y.tab.c
20019343Ssteve	mv y.tab.o ${.TARGET}
201228137Sfjoe	${CTFCONVERT_CMD}
20219343Ssteve
20319343Ssteve.l.o:
20419481Salex	${LEX} ${LFLAGS} ${.IMPSRC}
20519481Salex	${CC} ${CFLAGS} -c lex.yy.c
20639208Sobrien	rm -f lex.yy.c
20719343Ssteve	mv lex.yy.o ${.TARGET}
208228137Sfjoe	${CTFCONVERT_CMD}
20919343Ssteve
21019343Ssteve.y.c:
21119481Salex	${YACC} ${YFLAGS} ${.IMPSRC}
21219343Ssteve	mv y.tab.c ${.TARGET}
21319343Ssteve
21419343Ssteve.l.c:
21519481Salex	${LEX} ${LFLAGS} ${.IMPSRC}
21619343Ssteve	mv lex.yy.c ${.TARGET}
21719343Ssteve
21819343Ssteve.c.a:
21919481Salex	${CC} ${CFLAGS} -c ${.IMPSRC}
22019481Salex	${AR} ${ARFLAGS} ${.TARGET} ${.PREFIX}.o
22139208Sobrien	rm -f ${.PREFIX}.o
22219343Ssteve
22319343Ssteve.f.a:
22419481Salex	${FC} ${FFLAGS} -c ${.IMPSRC}
22519481Salex	${AR} ${ARFLAGS} ${.TARGET} ${.PREFIX}.o
22639208Sobrien	rm -f ${.PREFIX}.o
22719343Ssteve
22819343Ssteve.else
22919343Ssteve
23019343Ssteve# non-Posix rule set
23119343Ssteve
23211613Sbde.sh:
233211243Swill	cp -fp ${.IMPSRC} ${.TARGET}
23411613Sbde	chmod a+x ${.TARGET}
23511613Sbde
236103713Smarkm.c.ln:
237103713Smarkm	${LINT} ${LINTOBJFLAGS} ${CFLAGS:M-[DIU]*} ${.IMPSRC} || \
238103713Smarkm	    touch ${.TARGET}
239103713Smarkm
240103713Smarkm.cc.ln .C.ln .cpp.ln .cxx.ln:
241103713Smarkm	${LINT} ${LINTOBJFLAGS} ${CXXFLAGS:M-[DIU]*} ${.IMPSRC} || \
242103713Smarkm	    touch ${.TARGET}
243103713Smarkm
24477817Sobrien.c:
24577817Sobrien	${CC} ${CFLAGS} ${LDFLAGS} ${.IMPSRC} ${LDLIBS} -o ${.TARGET}
246228137Sfjoe	${CTFCONVERT_CMD}
24777817Sobrien
2481638Srgrimes.c.o:
249280329Sdim	${CC} ${CFLAGS} -c ${.IMPSRC} -o ${.TARGET}
250228137Sfjoe	${CTFCONVERT_CMD}
2511638Srgrimes
25277817Sobrien.cc .cpp .cxx .C:
25377817Sobrien	${CXX} ${CXXFLAGS} ${LDFLAGS} ${.IMPSRC} ${LDLIBS} -o ${.TARGET}
25477817Sobrien
25536673Sdt.cc.o .cpp.o .cxx.o .C.o:
256280329Sdim	${CXX} ${CXXFLAGS} -c ${.IMPSRC} -o ${.TARGET}
2571844Swollman
25836054Sbde.m.o:
259280329Sdim	${OBJC} ${OBJCFLAGS} -c ${.IMPSRC} -o ${.TARGET}
260228137Sfjoe	${CTFCONVERT_CMD}
26136054Sbde
2621638Srgrimes.p.o:
263280329Sdim	${PC} ${PFLAGS} -c ${.IMPSRC} -o ${.TARGET}
264228137Sfjoe	${CTFCONVERT_CMD}
2651638Srgrimes
26677818Sobrien.e .r .F .f:
26777818Sobrien	${FC} ${RFLAGS} ${EFLAGS} ${FFLAGS} ${LDFLAGS} ${.IMPSRC} ${LDLIBS} \
26877818Sobrien	    -o ${.TARGET}
26977818Sobrien
2701638Srgrimes.e.o .r.o .F.o .f.o:
271280329Sdim	${FC} ${RFLAGS} ${EFLAGS} ${FFLAGS} -c ${.IMPSRC} -o ${.TARGET}
2721638Srgrimes
2733292Srgrimes.S.o:
274280329Sdim	${CC} ${CFLAGS} ${ACFLAGS} -c ${.IMPSRC} -o ${.TARGET}
275228137Sfjoe	${CTFCONVERT_CMD}
2763292Srgrimes
277117173Sru.asm.o:
278280329Sdim	${CC} -x assembler-with-cpp ${CFLAGS} ${ACFLAGS} -c ${.IMPSRC} \
279280329Sdim	    -o ${.TARGET}
280228137Sfjoe	${CTFCONVERT_CMD}
281117173Sru
282117173Sru.s.o:
2831638Srgrimes	${AS} ${AFLAGS} -o ${.TARGET} ${.IMPSRC}
284228137Sfjoe	${CTFCONVERT_CMD}
2851638Srgrimes
28616068Sphk# XXX not -j safe
2871638Srgrimes.y.o:
28816068Sphk	${YACC} ${YFLAGS} ${.IMPSRC}
28916068Sphk	${CC} ${CFLAGS} -c y.tab.c -o ${.TARGET}
29039208Sobrien	rm -f y.tab.c
291228137Sfjoe	${CTFCONVERT_CMD}
2921638Srgrimes
2931638Srgrimes.l.o:
29415959Sphk	${LEX} -t ${LFLAGS} ${.IMPSRC} > ${.PREFIX}.tmp.c
29515959Sphk	${CC} ${CFLAGS} -c ${.PREFIX}.tmp.c -o ${.TARGET}
29639208Sobrien	rm -f ${.PREFIX}.tmp.c
297228137Sfjoe	${CTFCONVERT_CMD}
2981638Srgrimes
29921582Ssteve# XXX not -j safe
3001638Srgrimes.y.c:
30121582Ssteve	${YACC} ${YFLAGS} ${.IMPSRC}
30221582Ssteve	mv y.tab.c ${.TARGET}
3031638Srgrimes
3041638Srgrimes.l.c:
30515959Sphk	${LEX} -t ${LFLAGS} ${.IMPSRC} > ${.TARGET}
3061638Srgrimes
3071638Srgrimes.s.out .c.out .o.out:
30811613Sbde	${CC} ${CFLAGS} ${LDFLAGS} ${.IMPSRC} ${LDLIBS} -o ${.TARGET}
309228137Sfjoe	${CTFCONVERT_CMD}
3101638Srgrimes
3111638Srgrimes.f.out .F.out .r.out .e.out:
31211613Sbde	${FC} ${EFLAGS} ${RFLAGS} ${FFLAGS} ${LDFLAGS} ${.IMPSRC} \
3131638Srgrimes	    ${LDLIBS} -o ${.TARGET}
31439208Sobrien	rm -f ${.PREFIX}.o
315228137Sfjoe	${CTFCONVERT_CMD}
3161638Srgrimes
31716068Sphk# XXX not -j safe
3181638Srgrimes.y.out:
31916068Sphk	${YACC} ${YFLAGS} ${.IMPSRC}
32016068Sphk	${CC} ${CFLAGS} ${LDFLAGS} y.tab.c ${LDLIBS} -ly -o ${.TARGET}
32139208Sobrien	rm -f y.tab.c
322228137Sfjoe	${CTFCONVERT_CMD}
3231638Srgrimes
3241638Srgrimes.l.out:
32515959Sphk	${LEX} -t ${LFLAGS} ${.IMPSRC} > ${.PREFIX}.tmp.c
32615959Sphk	${CC} ${CFLAGS} ${LDFLAGS} ${.PREFIX}.tmp.c ${LDLIBS} -ll -o ${.TARGET}
32739208Sobrien	rm -f ${.PREFIX}.tmp.c
328228137Sfjoe	${CTFCONVERT_CMD}
3291844Swollman
330129163Sbde# FreeBSD build pollution.  Hide it in the non-POSIX part of the ifdef.
33192546Simp__MAKE_CONF?=/etc/make.conf
33292546Simp.if exists(${__MAKE_CONF})
33392546Simp.include "${__MAKE_CONF}"
3341844Swollman.endif
33536609Sjb
336173075Syar.if defined(__MAKE_SHELL) && !empty(__MAKE_SHELL)
337173075SyarSHELL=	${__MAKE_SHELL}
338173075Syar.SHELL: path=${__MAKE_SHELL}
339173075Syar.endif
340173075Syar
341241298Smarcel.if !defined(.PARSEDIR)
342241298Smarcel# We are not bmake, which is more aggressive about searching .PATH
343241298Smarcel# It is sometime necessary to curb its enthusiasm with .NOPATH
344241298Smarcel# The following allows us to quietly ignore .NOPATH when not using bmake.
345241298Smarcel.NOTMAIN: .NOPATH
346241298Smarcel.NOPATH:
347241298Smarcel
348145681Sharti# Toggle on warnings
349145681Sharti.WARN: dirsyntax
350241298Smarcel.endif
351145681Sharti
352129163Sbde.endif
353129163Sbde
354254980Ssjg.if defined(.PARSEDIR)
355254980Ssjg# Tell bmake to expand -V VAR by default
356254980Ssjg.MAKE.EXPAND_VARIABLES= yes
357254980Ssjg
358254980Ssjg# Tell bmake the makefile preference
359330425SbdreweryMAKEFILE_PREFERENCE?= BSDmakefile makefile Makefile
360330425Sbdrewery.MAKE.MAKEFILE_PREFERENCE= ${MAKEFILE_PREFERENCE}
361254980Ssjg
362254980Ssjg# By default bmake does *not* use set -e
363254980Ssjg# when running target scripts, this is a problem for many makefiles here.
364254980Ssjg# So define a shell that will do what FreeBSD expects.
365254980Ssjg.ifndef WITHOUT_SHELL_ERRCTL
366254980Ssjg.SHELL: name=sh \
367254980Ssjg	quiet="set -" echo="set -v" filter="set -" \
368254980Ssjg	hasErrCtl=yes check="set -e" ignore="set +e" \
369254980Ssjg	echoFlag=v errFlag=e \
370254980Ssjg	path=${__MAKE_SHELL:U/bin/sh}
371254980Ssjg.endif
372254980Ssjg
373254980Ssjg.endif
374254980Ssjg
375129163Sbde.include <bsd.cpu.mk>
376