sys.mk revision 251506
1139825Simp#	from: @(#)sys.mk	8.2 (Berkeley) 3/21/94
21541Srgrimes# $FreeBSD: head/share/mk/sys.mk 251506 2013-06-07 19:45:04Z sjg $
31541Srgrimes
41541Srgrimesunix		?=	We run FreeBSD, not UNIX.
51541Srgrimes.FreeBSD	?=	true
61541Srgrimes
71541Srgrimes.if !defined(%POSIX)
81541Srgrimes#
91541Srgrimes# MACHINE_CPUARCH defines a collection of MACHINE_ARCH.  Machines with
101541Srgrimes# the same MACHINE_ARCH can run each other's binaries, so it necessarily
111541Srgrimes# has word size and endian swizzled in.  However, support files for
121541Srgrimes# these machines often are shared amongst all combinations of size
131541Srgrimes# and/or endian.  This is called MACHINE_CPU in NetBSD, but that's used
141541Srgrimes# for something different in FreeBSD.
151541Srgrimes#
161541SrgrimesMACHINE_CPUARCH=${MACHINE_ARCH:C/mips(n32|64)?(el)?/mips/:C/arm(v6)?(eb)?/arm/:C/powerpc64/powerpc/}
171541Srgrimes.endif
181541Srgrimes
191541Srgrimes# Set any local definitions first. Place this early, but it needs
201541Srgrimes# MACHINE_CPUARCH to be defined.
211541Srgrimes.sinclude <local.sys.mk>
221541Srgrimes
231541Srgrimes# If the special target .POSIX appears (without prerequisites or
241541Srgrimes# commands) before the first noncomment line in the makefile, make shall
251541Srgrimes# process the makefile as specified by the Posix 1003.2 specification.
261541Srgrimes# make(1) sets the special macro %POSIX in this case (to the actual
271541Srgrimes# value "1003.2", for what it's worth).
281541Srgrimes#
291541Srgrimes# The rules below use this macro to distinguish between Posix-compliant
301541Srgrimes# and default behaviour.
311541Srgrimes
321541Srgrimes.if defined(%POSIX)
331541Srgrimes.SUFFIXES:	.o .c .y .l .a .sh .f
3422521Sdyson.else
351541Srgrimes.SUFFIXES:	.out .a .ln .o .c .cc .cpp .cxx .C .m .F .f .e .r .y .l .S .asm .s .cl .p .h .sh
361541Srgrimes.endif
37116192Sobrien
38116192SobrienAR		?=	ar
39116192Sobrien.if defined(%POSIX)
4013260SwollmanARFLAGS		?=	-rv
4199101Siedowse.else
4213260SwollmanARFLAGS		?=	cru
431541Srgrimes.endif
4476166SmarkmRANLIB		?=	ranlib
4541059Speter
4676166SmarkmAS		?=	as
4776166SmarkmAFLAGS		?=
4876166SmarkmACFLAGS		?=
4965557Sjasone
5076166Smarkm.if defined(%POSIX)
511541SrgrimesCC		?=	c89
521541SrgrimesCFLAGS		?=	-O
5359241Srwatson.else
541541SrgrimesCC		?=	cc
551541Srgrimes.if ${MACHINE_CPUARCH} == "arm" || ${MACHINE_CPUARCH} == "mips"
561541SrgrimesCFLAGS		?=	-O -pipe
571541Srgrimes.else
5899101SiedowseCFLAGS		?=	-O2 -pipe
5999101Siedowse.endif
6099101Siedowse.if defined(NO_STRICT_ALIASING)
6199101SiedowseCFLAGS		+=	-fno-strict-aliasing
621541Srgrimes.endif
63151897Srwatson.endif
641541SrgrimesPO_CFLAGS	?=	${CFLAGS}
651541Srgrimes
661541Srgrimes# C Type Format data is required for DTrace
671541SrgrimesCTFFLAGS	?=	-L VERSION
681541Srgrimes
69191990SattilioCTFCONVERT	?=	ctfconvert
701541SrgrimesCTFMERGE	?=	ctfmerge
71144056SjeffDTRACE		?=	dtrace
721541Srgrimes.if defined(CFLAGS) && (${CFLAGS:M-g} != "")
731541SrgrimesCTFFLAGS	+=	-g
741541Srgrimes.else
751541Srgrimes# XXX: What to do here? Is removing the CFLAGS part completely ok here?
761541Srgrimes# For now comment it out to not compile with -g unconditionally.
77144056Sjeff#CFLAGS		+=	-g
783427Sphk.endif
791541Srgrimes
801541SrgrimesCXX		?=	c++
811541SrgrimesCXXFLAGS	?=	${CFLAGS:N-std=*:N-Wnested-externs:N-W*-prototypes:N-Wno-pointer-sign:N-Wold-style-definition}
821541SrgrimesPO_CXXFLAGS	?=	${CXXFLAGS}
831541Srgrimes
841541SrgrimesCPP		?=	cpp
851541Srgrimes
861541Srgrimes.if empty(.MAKEFLAGS:M-s)
871541SrgrimesECHO		?=	echo
88191990SattilioECHODIR		?=	echo
891541Srgrimes.else
901541SrgrimesECHO		?=	true
91166381Smpp.if ${.MAKEFLAGS:M-s} == "-s"
92153400SdesECHODIR		?=	echo
931541Srgrimes.else
941541SrgrimesECHODIR		?=	true
951541Srgrimes.endif
961541Srgrimes.endif
97191990Sattilio
983427Sphk.if !empty(.MAKEFLAGS:M-n) && ${.MAKEFLAGS:M-n} == "-n"
993427Sphk_+_		?=
100191990Sattilio.else
1011541Srgrimes_+_		?=	+
1026992Sdg.endif
103166381Smpp
104166381Smpp.if defined(%POSIX)
105166381SmppFC		?=	fort77
106166381SmppFFLAGS		?=	-O 1
107166381Smpp.else
108166381SmppFC		?=	f77
109166381SmppFFLAGS		?=	-O
110166381Smpp.endif
111166381SmppEFLAGS		?=
112166381Smpp
113166381SmppINSTALL		?=	install
114166381Smpp
115166381SmppLEX		?=	lex
116166381SmppLFLAGS		?=
117166381Smpp
1181541SrgrimesLD		?=	ld
1191541SrgrimesLDFLAGS		?=
120116384Srwatson
1211541SrgrimesLINT		?=	lint
1221541SrgrimesLINTFLAGS	?=	-cghapbx
12383366SjulianLINTKERNFLAGS	?=	${LINTFLAGS}
12422521SdysonLINTOBJFLAGS	?=	-cghapbxu -i
1251541SrgrimesLINTOBJKERNFLAGS?=	${LINTOBJFLAGS}
1261541SrgrimesLINTLIBFLAGS	?=	-cghapbxu -C ${LIB}
12783366Sjulian
12822521SdysonMAKE		?=	make
1291541Srgrimes
130207736Smckusick.if !defined(%POSIX)
131207736SmckusickNM		?=	nm
132207736Smckusick
133207736SmckusickOBJC		?=	cc
134207736SmckusickOBJCFLAGS	?=	${OBJCINCLUDES} ${CFLAGS} -Wno-import
135207736Smckusick
136207736SmckusickOBJCOPY		?=	objcopy
137207736Smckusick
138207736SmckusickPC		?=	pc
139207736SmckusickPFLAGS		?=
140207736Smckusick
141207736SmckusickRC		?=	f77
1421541SrgrimesRFLAGS		?=
143166381Smpp.endif
14422521Sdyson
1451541SrgrimesSHELL		?=	sh
1461541Srgrimes
147166381SmppYACC		?=	yacc
14822521Sdyson.if defined(%POSIX)
1491541SrgrimesYFLAGS		?=
1501541Srgrimes.else
151166381SmppYFLAGS		?=	-d
15222521Sdyson.endif
1531541Srgrimes
154207736Smckusick.if defined(%POSIX)
155207736Smckusick
156207736Smckusick# Posix 1003.2 mandated rules
157207736Smckusick#
1581541Srgrimes# Quoted directly from the Posix 1003.2 draft, only the macros
1591541Srgrimes# $@, $< and $* have been replaced by ${.TARGET}, ${.IMPSRC}, and
16022521Sdyson# ${.PREFIX}, resp.
1611541Srgrimes
1621541Srgrimes# SINGLE SUFFIX RULES
16322521Sdyson.c:
16422521Sdyson	${CC} ${CFLAGS} ${LDFLAGS} -o ${.TARGET} ${.IMPSRC}
1651541Srgrimes	${CTFCONVERT_CMD}
16622521Sdyson
1671541Srgrimes.f:
1681541Srgrimes	${FC} ${FFLAGS} ${LDFLAGS} -o ${.TARGET} ${.IMPSRC}
1691541Srgrimes	${CTFCONVERT_CMD}
1701541Srgrimes
17122521Sdyson.sh:
17222521Sdyson	cp -f ${.IMPSRC} ${.TARGET}
17322521Sdyson	chmod a+x ${.TARGET}
17422521Sdyson
17522521Sdyson# DOUBLE SUFFIX RULES
17622521Sdyson
17722521Sdyson.c.o:
17822521Sdyson	${CC} ${CFLAGS} -c ${.IMPSRC}
17922521Sdyson	${CTFCONVERT_CMD}
18022521Sdyson
18199101Siedowse.f.o:
18299101Siedowse	${FC} ${FFLAGS} -c ${.IMPSRC}
18399101Siedowse	${CTFCONVERT_CMD}
18422521Sdyson
18522521Sdyson.y.o:
18622521Sdyson	${YACC} ${YFLAGS} ${.IMPSRC}
18722521Sdyson	${CC} ${CFLAGS} -c y.tab.c
18899101Siedowse	rm -f y.tab.c
18999101Siedowse	mv y.tab.o ${.TARGET}
19099101Siedowse	${CTFCONVERT_CMD}
19199101Siedowse
19299101Siedowse.l.o:
19399101Siedowse	${LEX} ${LFLAGS} ${.IMPSRC}
19499101Siedowse	${CC} ${CFLAGS} -c lex.yy.c
19599101Siedowse	rm -f lex.yy.c
19699101Siedowse	mv lex.yy.o ${.TARGET}
19799101Siedowse	${CTFCONVERT_CMD}
19899101Siedowse
19999101Siedowse.y.c:
20099101Siedowse	${YACC} ${YFLAGS} ${.IMPSRC}
20199101Siedowse	mv y.tab.c ${.TARGET}
20299101Siedowse
20399101Siedowse.l.c:
20499101Siedowse	${LEX} ${LFLAGS} ${.IMPSRC}
2051541Srgrimes	mv lex.yy.c ${.TARGET}
2061541Srgrimes
2071541Srgrimes.c.a:
20851138Salfred	${CC} ${CFLAGS} -c ${.IMPSRC}
2091541Srgrimes	${AR} ${ARFLAGS} ${.TARGET} ${.PREFIX}.o
2101541Srgrimes	rm -f ${.PREFIX}.o
211222167Srmacklem
21296482Sphk.f.a:
2131541Srgrimes	${FC} ${FFLAGS} -c ${.IMPSRC}
214222167Srmacklem	${AR} ${ARFLAGS} ${.TARGET} ${.PREFIX}.o
2151541Srgrimes	rm -f ${.PREFIX}.o
2161541Srgrimes
21796482Sphk.else
2181541Srgrimes
2191541Srgrimes# non-Posix rule set
2201541Srgrimes
221222196Srmacklem.sh:
2223427Sphk	cp -fp ${.IMPSRC} ${.TARGET}
2231541Srgrimes	chmod a+x ${.TARGET}
2241541Srgrimes
2251541Srgrimes.c.ln:
2261541Srgrimes	${LINT} ${LINTOBJFLAGS} ${CFLAGS:M-[DIU]*} ${.IMPSRC} || \
22796873Siedowse	    touch ${.TARGET}
22896873Siedowse
2291541Srgrimes.cc.ln .C.ln .cpp.ln .cxx.ln:
2301541Srgrimes	${LINT} ${LINTOBJFLAGS} ${CXXFLAGS:M-[DIU]*} ${.IMPSRC} || \
2311541Srgrimes	    touch ${.TARGET}
2321541Srgrimes
2331541Srgrimes.c:
234140962Speadar	${CC} ${CFLAGS} ${LDFLAGS} ${.IMPSRC} ${LDLIBS} -o ${.TARGET}
23551138Salfred	${CTFCONVERT_CMD}
23651138Salfred
237.c.o:
238	${CC} ${CFLAGS} -c ${.IMPSRC}
239	${CTFCONVERT_CMD}
240
241.cc .cpp .cxx .C:
242	${CXX} ${CXXFLAGS} ${LDFLAGS} ${.IMPSRC} ${LDLIBS} -o ${.TARGET}
243
244.cc.o .cpp.o .cxx.o .C.o:
245	${CXX} ${CXXFLAGS} -c ${.IMPSRC}
246
247.m.o:
248	${OBJC} ${OBJCFLAGS} -c ${.IMPSRC}
249	${CTFCONVERT_CMD}
250
251.p.o:
252	${PC} ${PFLAGS} -c ${.IMPSRC}
253	${CTFCONVERT_CMD}
254
255.e .r .F .f:
256	${FC} ${RFLAGS} ${EFLAGS} ${FFLAGS} ${LDFLAGS} ${.IMPSRC} ${LDLIBS} \
257	    -o ${.TARGET}
258
259.e.o .r.o .F.o .f.o:
260	${FC} ${RFLAGS} ${EFLAGS} ${FFLAGS} -c ${.IMPSRC}
261
262.S.o:
263	${CC} ${CFLAGS} ${ACFLAGS} -c ${.IMPSRC}
264	${CTFCONVERT_CMD}
265
266.asm.o:
267	${CC} -x assembler-with-cpp ${CFLAGS} ${ACFLAGS} -c ${.IMPSRC}
268	${CTFCONVERT_CMD}
269
270.s.o:
271	${AS} ${AFLAGS} -o ${.TARGET} ${.IMPSRC}
272	${CTFCONVERT_CMD}
273
274# XXX not -j safe
275.y.o:
276	${YACC} ${YFLAGS} ${.IMPSRC}
277	${CC} ${CFLAGS} -c y.tab.c -o ${.TARGET}
278	rm -f y.tab.c
279	${CTFCONVERT_CMD}
280
281.l.o:
282	${LEX} -t ${LFLAGS} ${.IMPSRC} > ${.PREFIX}.tmp.c
283	${CC} ${CFLAGS} -c ${.PREFIX}.tmp.c -o ${.TARGET}
284	rm -f ${.PREFIX}.tmp.c
285	${CTFCONVERT_CMD}
286
287# XXX not -j safe
288.y.c:
289	${YACC} ${YFLAGS} ${.IMPSRC}
290	mv y.tab.c ${.TARGET}
291
292.l.c:
293	${LEX} -t ${LFLAGS} ${.IMPSRC} > ${.TARGET}
294
295.s.out .c.out .o.out:
296	${CC} ${CFLAGS} ${LDFLAGS} ${.IMPSRC} ${LDLIBS} -o ${.TARGET}
297	${CTFCONVERT_CMD}
298
299.f.out .F.out .r.out .e.out:
300	${FC} ${EFLAGS} ${RFLAGS} ${FFLAGS} ${LDFLAGS} ${.IMPSRC} \
301	    ${LDLIBS} -o ${.TARGET}
302	rm -f ${.PREFIX}.o
303	${CTFCONVERT_CMD}
304
305# XXX not -j safe
306.y.out:
307	${YACC} ${YFLAGS} ${.IMPSRC}
308	${CC} ${CFLAGS} ${LDFLAGS} y.tab.c ${LDLIBS} -ly -o ${.TARGET}
309	rm -f y.tab.c
310	${CTFCONVERT_CMD}
311
312.l.out:
313	${LEX} -t ${LFLAGS} ${.IMPSRC} > ${.PREFIX}.tmp.c
314	${CC} ${CFLAGS} ${LDFLAGS} ${.PREFIX}.tmp.c ${LDLIBS} -ll -o ${.TARGET}
315	rm -f ${.PREFIX}.tmp.c
316	${CTFCONVERT_CMD}
317
318# FreeBSD build pollution.  Hide it in the non-POSIX part of the ifdef.
319__MAKE_CONF?=/etc/make.conf
320.if exists(${__MAKE_CONF})
321.include "${__MAKE_CONF}"
322.endif
323
324.if defined(__MAKE_SHELL) && !empty(__MAKE_SHELL)
325SHELL=	${__MAKE_SHELL}
326.SHELL: path=${__MAKE_SHELL}
327.endif
328
329# Default executable format
330# XXX hint for bsd.port.mk
331OBJFORMAT?=	elf
332
333# Tell bmake to expand -V VAR by default
334.MAKE.EXPAND_VARIABLES= yes
335
336# Tell bmake the makefile preference
337.MAKE.MAKEFILE_PREFERENCE= BSDmakefile makefile Makefile
338
339.if !defined(.PARSEDIR)
340# We are not bmake, which is more aggressive about searching .PATH
341# It is sometime necessary to curb its enthusiasm with .NOPATH
342# The following allows us to quietly ignore .NOPATH when not using bmake.
343.NOTMAIN: .NOPATH
344.NOPATH:
345
346# Toggle on warnings
347.WARN: dirsyntax
348.endif
349
350.endif
351
352.include <bsd.cpu.mk>
353