xref: /freebsd/share/mk/sys.mk (revision 5bd73b51076b5cb5a2c9810f76c1d7ed20c4460e)
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, support 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#
16MACHINE_CPUARCH=${MACHINE_ARCH:C/mips(n32|64)?(el)?/mips/:C/arm(v6)?(eb|hf)?/arm/:C/powerpc64/powerpc/}
17.endif
18
19# If the special target .POSIX appears (without prerequisites or
20# commands) before the first noncomment line in the makefile, make shall
21# process the makefile as specified by the Posix 1003.2 specification.
22# make(1) sets the special macro %POSIX in this case (to the actual
23# value "1003.2", for what it's worth).
24#
25# The rules below use this macro to distinguish between Posix-compliant
26# and default behaviour.
27
28.if defined(%POSIX)
29.SUFFIXES:	.o .c .y .l .a .sh .f
30.else
31.SUFFIXES:	.out .a .ln .o .c .cc .cpp .cxx .C .m .F .f .e .r .y .l .S .asm .s .cl .p .h .sh
32.endif
33
34AR		?=	ar
35.if defined(%POSIX)
36ARFLAGS		?=	-rv
37.else
38ARFLAGS		?=	-crD
39.endif
40RANLIB		?=	ranlib
41.if !defined(%POSIX)
42RANLIBFLAGS	?=	-D
43.endif
44
45AS		?=	as
46AFLAGS		?=
47ACFLAGS		?=
48
49.if defined(%POSIX)
50CC		?=	c89
51CFLAGS		?=	-O
52.else
53CC		?=	cc
54.if ${MACHINE_CPUARCH} == "arm" || ${MACHINE_CPUARCH} == "mips"
55CFLAGS		?=	-O -pipe
56.else
57CFLAGS		?=	-O2 -pipe
58.endif
59.if defined(NO_STRICT_ALIASING)
60CFLAGS		+=	-fno-strict-aliasing
61.endif
62.endif
63PO_CFLAGS	?=	${CFLAGS}
64
65# C Type Format data is required for DTrace
66CTFFLAGS	?=	-L VERSION
67
68CTFCONVERT	?=	ctfconvert
69CTFMERGE	?=	ctfmerge
70DTRACE		?=	dtrace
71.if defined(CFLAGS) && (${CFLAGS:M-g} != "")
72CTFFLAGS	+=	-g
73.endif
74
75CXX		?=	c++
76CXXFLAGS	?=	${CFLAGS:N-std=*:N-Wnested-externs:N-W*-prototypes:N-Wno-pointer-sign:N-Wold-style-definition}
77PO_CXXFLAGS	?=	${CXXFLAGS}
78
79CPP		?=	cpp
80
81.if empty(.MAKEFLAGS:M-s)
82ECHO		?=	echo
83ECHODIR		?=	echo
84.else
85ECHO		?=	true
86.if ${.MAKEFLAGS:M-s} == "-s"
87ECHODIR		?=	echo
88.else
89ECHODIR		?=	true
90.endif
91.endif
92
93.if defined(.PARSEDIR)
94# _+_ appears to be a workaround for the special src .MAKE not working.
95# setting it to + interferes with -N
96_+_		?=
97.elif !empty(.MAKEFLAGS:M-n) && ${.MAKEFLAGS:M-n} == "-n"
98# the check above matches only a single -n, so -n -n will result
99# in _+_ = +
100_+_		?=
101.else
102_+_		?=	+
103.endif
104
105.if defined(%POSIX)
106FC		?=	fort77
107FFLAGS		?=	-O 1
108.else
109FC		?=	f77
110FFLAGS		?=	-O
111.endif
112EFLAGS		?=
113
114INSTALL		?=	install
115
116LEX		?=	lex
117LFLAGS		?=
118
119LD		?=	ld
120LDFLAGS		?=				# LDFLAGS is for CC,
121_LDFLAGS	=	${LDFLAGS:S/-Wl,//g}	# strip -Wl, for LD
122
123LINT		?=	lint
124LINTFLAGS	?=	-cghapbx
125LINTKERNFLAGS	?=	${LINTFLAGS}
126LINTOBJFLAGS	?=	-cghapbxu -i
127LINTOBJKERNFLAGS?=	${LINTOBJFLAGS}
128LINTLIBFLAGS	?=	-cghapbxu -C ${LIB}
129
130MAKE		?=	make
131
132.if !defined(%POSIX)
133NM		?=	nm
134
135OBJC		?=	cc
136OBJCFLAGS	?=	${OBJCINCLUDES} ${CFLAGS} -Wno-import
137
138OBJCOPY		?=	objcopy
139
140PC		?=	pc
141PFLAGS		?=
142
143RC		?=	f77
144RFLAGS		?=
145.endif
146
147SHELL		?=	sh
148
149.if !defined(%POSIX)
150SIZE		?=	size
151.endif
152
153YACC		?=	yacc
154.if defined(%POSIX)
155YFLAGS		?=
156.else
157YFLAGS		?=	-d
158.endif
159
160.if defined(%POSIX)
161
162# Posix 1003.2 mandated rules
163#
164# Quoted directly from the Posix 1003.2 draft, only the macros
165# $@, $< and $* have been replaced by ${.TARGET}, ${.IMPSRC}, and
166# ${.PREFIX}, resp.
167
168# SINGLE SUFFIX RULES
169.c:
170	${CC} ${CFLAGS} ${LDFLAGS} -o ${.TARGET} ${.IMPSRC}
171
172.f:
173	${FC} ${FFLAGS} ${LDFLAGS} -o ${.TARGET} ${.IMPSRC}
174
175.sh:
176	cp -f ${.IMPSRC} ${.TARGET}
177	chmod a+x ${.TARGET}
178
179# DOUBLE SUFFIX RULES
180
181.c.o:
182	${CC} ${CFLAGS} -c ${.IMPSRC}
183
184.f.o:
185	${FC} ${FFLAGS} -c ${.IMPSRC}
186
187.y.o:
188	${YACC} ${YFLAGS} ${.IMPSRC}
189	${CC} ${CFLAGS} -c y.tab.c
190	rm -f y.tab.c
191	mv y.tab.o ${.TARGET}
192
193.l.o:
194	${LEX} ${LFLAGS} ${.IMPSRC}
195	${CC} ${CFLAGS} -c lex.yy.c
196	rm -f lex.yy.c
197	mv lex.yy.o ${.TARGET}
198
199.y.c:
200	${YACC} ${YFLAGS} ${.IMPSRC}
201	mv y.tab.c ${.TARGET}
202
203.l.c:
204	${LEX} ${LFLAGS} ${.IMPSRC}
205	mv lex.yy.c ${.TARGET}
206
207.c.a:
208	${CC} ${CFLAGS} -c ${.IMPSRC}
209	${AR} ${ARFLAGS} ${.TARGET} ${.PREFIX}.o
210	rm -f ${.PREFIX}.o
211
212.f.a:
213	${FC} ${FFLAGS} -c ${.IMPSRC}
214	${AR} ${ARFLAGS} ${.TARGET} ${.PREFIX}.o
215	rm -f ${.PREFIX}.o
216
217.else
218
219# non-Posix rule set
220
221.sh:
222	cp -fp ${.IMPSRC} ${.TARGET}
223	chmod a+x ${.TARGET}
224
225.c.ln:
226	${LINT} ${LINTOBJFLAGS} ${CFLAGS:M-[DIU]*} ${.IMPSRC} || \
227	    touch ${.TARGET}
228
229.cc.ln .C.ln .cpp.ln .cxx.ln:
230	${LINT} ${LINTOBJFLAGS} ${CXXFLAGS:M-[DIU]*} ${.IMPSRC} || \
231	    touch ${.TARGET}
232
233.c:
234	${CC} ${CFLAGS} ${LDFLAGS} ${.IMPSRC} ${LDLIBS} -o ${.TARGET}
235	${CTFCONVERT_CMD}
236
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# Pull in global settings.
319__MAKE_CONF?=/etc/make.conf
320.if exists(${__MAKE_CONF})
321.include "${__MAKE_CONF}"
322.endif
323
324# Setup anything for the FreeBSD source build, if we're building
325# inside the source tree. Needs to be after make.conf, but before
326# local stuff.
327.sinclude <src.sys.mk>
328
329# Set any local definitions first. Place this early, but it needs
330# MACHINE_CPUARCH to be defined.
331.sinclude <local.sys.mk>
332
333.if defined(__MAKE_SHELL) && !empty(__MAKE_SHELL)
334SHELL=	${__MAKE_SHELL}
335.SHELL: path=${__MAKE_SHELL}
336.endif
337
338.if !defined(.PARSEDIR)
339# We are not bmake, which is more aggressive about searching .PATH
340# It is sometime necessary to curb its enthusiasm with .NOPATH
341# The following allows us to quietly ignore .NOPATH when not using bmake.
342.NOTMAIN: .NOPATH
343.NOPATH:
344
345# Toggle on warnings
346.WARN: dirsyntax
347.else # is bmake
348# Tell bmake to expand -V VAR by default
349.MAKE.EXPAND_VARIABLES= yes
350
351# Tell bmake the makefile preference
352.MAKE.MAKEFILE_PREFERENCE= BSDmakefile makefile Makefile
353
354# By default bmake does *not* use set -e
355# when running target scripts, this is a problem for many makefiles here.
356# So define a shell that will do what FreeBSD expects.
357.ifndef WITHOUT_SHELL_ERRCTL
358.SHELL: name=sh \
359	quiet="set -" echo="set -v" filter="set -" \
360	hasErrCtl=yes check="set -e" ignore="set +e" \
361	echoFlag=v errFlag=e \
362	path=${__MAKE_SHELL:U/bin/sh}
363.endif
364.endif # bmake
365
366.include <bsd.cpu.mk>
367
368.endif # ! Posix
369