xref: /freebsd/share/mk/sys.mk (revision ff0ba87247820afbdfdc1b307c803f7923d0e4d3)
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
140OBJDUMP		?=	objdump
141
142PC		?=	pc
143PFLAGS		?=
144
145RC		?=	f77
146RFLAGS		?=
147.endif
148
149SHELL		?=	sh
150
151.if !defined(%POSIX)
152SIZE		?=	size
153.endif
154
155YACC		?=	yacc
156.if defined(%POSIX)
157YFLAGS		?=
158.else
159YFLAGS		?=	-d
160.endif
161
162.if defined(%POSIX)
163
164# Posix 1003.2 mandated rules
165#
166# Quoted directly from the Posix 1003.2 draft, only the macros
167# $@, $< and $* have been replaced by ${.TARGET}, ${.IMPSRC}, and
168# ${.PREFIX}, resp.
169
170# SINGLE SUFFIX RULES
171.c:
172	${CC} ${CFLAGS} ${LDFLAGS} -o ${.TARGET} ${.IMPSRC}
173
174.f:
175	${FC} ${FFLAGS} ${LDFLAGS} -o ${.TARGET} ${.IMPSRC}
176
177.sh:
178	cp -f ${.IMPSRC} ${.TARGET}
179	chmod a+x ${.TARGET}
180
181# DOUBLE SUFFIX RULES
182
183.c.o:
184	${CC} ${CFLAGS} -c ${.IMPSRC}
185
186.f.o:
187	${FC} ${FFLAGS} -c ${.IMPSRC}
188
189.y.o:
190	${YACC} ${YFLAGS} ${.IMPSRC}
191	${CC} ${CFLAGS} -c y.tab.c
192	rm -f y.tab.c
193	mv y.tab.o ${.TARGET}
194
195.l.o:
196	${LEX} ${LFLAGS} ${.IMPSRC}
197	${CC} ${CFLAGS} -c lex.yy.c
198	rm -f lex.yy.c
199	mv lex.yy.o ${.TARGET}
200
201.y.c:
202	${YACC} ${YFLAGS} ${.IMPSRC}
203	mv y.tab.c ${.TARGET}
204
205.l.c:
206	${LEX} ${LFLAGS} ${.IMPSRC}
207	mv lex.yy.c ${.TARGET}
208
209.c.a:
210	${CC} ${CFLAGS} -c ${.IMPSRC}
211	${AR} ${ARFLAGS} ${.TARGET} ${.PREFIX}.o
212	rm -f ${.PREFIX}.o
213
214.f.a:
215	${FC} ${FFLAGS} -c ${.IMPSRC}
216	${AR} ${ARFLAGS} ${.TARGET} ${.PREFIX}.o
217	rm -f ${.PREFIX}.o
218
219.else
220
221# non-Posix rule set
222
223.sh:
224	cp -fp ${.IMPSRC} ${.TARGET}
225	chmod a+x ${.TARGET}
226
227.c.ln:
228	${LINT} ${LINTOBJFLAGS} ${CFLAGS:M-[DIU]*} ${.IMPSRC} || \
229	    touch ${.TARGET}
230
231.cc.ln .C.ln .cpp.ln .cxx.ln:
232	${LINT} ${LINTOBJFLAGS} ${CXXFLAGS:M-[DIU]*} ${.IMPSRC} || \
233	    touch ${.TARGET}
234
235.c:
236	${CC} ${CFLAGS} ${LDFLAGS} ${.IMPSRC} ${LDLIBS} -o ${.TARGET}
237	${CTFCONVERT_CMD}
238
239.c.o:
240	${CC} ${CFLAGS} -c ${.IMPSRC}
241	${CTFCONVERT_CMD}
242
243.cc .cpp .cxx .C:
244	${CXX} ${CXXFLAGS} ${LDFLAGS} ${.IMPSRC} ${LDLIBS} -o ${.TARGET}
245
246.cc.o .cpp.o .cxx.o .C.o:
247	${CXX} ${CXXFLAGS} -c ${.IMPSRC}
248
249.m.o:
250	${OBJC} ${OBJCFLAGS} -c ${.IMPSRC}
251	${CTFCONVERT_CMD}
252
253.p.o:
254	${PC} ${PFLAGS} -c ${.IMPSRC}
255	${CTFCONVERT_CMD}
256
257.e .r .F .f:
258	${FC} ${RFLAGS} ${EFLAGS} ${FFLAGS} ${LDFLAGS} ${.IMPSRC} ${LDLIBS} \
259	    -o ${.TARGET}
260
261.e.o .r.o .F.o .f.o:
262	${FC} ${RFLAGS} ${EFLAGS} ${FFLAGS} -c ${.IMPSRC}
263
264.S.o:
265	${CC} ${CFLAGS} ${ACFLAGS} -c ${.IMPSRC}
266	${CTFCONVERT_CMD}
267
268.asm.o:
269	${CC} -x assembler-with-cpp ${CFLAGS} ${ACFLAGS} -c ${.IMPSRC}
270	${CTFCONVERT_CMD}
271
272.s.o:
273	${AS} ${AFLAGS} -o ${.TARGET} ${.IMPSRC}
274	${CTFCONVERT_CMD}
275
276# XXX not -j safe
277.y.o:
278	${YACC} ${YFLAGS} ${.IMPSRC}
279	${CC} ${CFLAGS} -c y.tab.c -o ${.TARGET}
280	rm -f y.tab.c
281	${CTFCONVERT_CMD}
282
283.l.o:
284	${LEX} -t ${LFLAGS} ${.IMPSRC} > ${.PREFIX}.tmp.c
285	${CC} ${CFLAGS} -c ${.PREFIX}.tmp.c -o ${.TARGET}
286	rm -f ${.PREFIX}.tmp.c
287	${CTFCONVERT_CMD}
288
289# XXX not -j safe
290.y.c:
291	${YACC} ${YFLAGS} ${.IMPSRC}
292	mv y.tab.c ${.TARGET}
293
294.l.c:
295	${LEX} -t ${LFLAGS} ${.IMPSRC} > ${.TARGET}
296
297.s.out .c.out .o.out:
298	${CC} ${CFLAGS} ${LDFLAGS} ${.IMPSRC} ${LDLIBS} -o ${.TARGET}
299	${CTFCONVERT_CMD}
300
301.f.out .F.out .r.out .e.out:
302	${FC} ${EFLAGS} ${RFLAGS} ${FFLAGS} ${LDFLAGS} ${.IMPSRC} \
303	    ${LDLIBS} -o ${.TARGET}
304	rm -f ${.PREFIX}.o
305	${CTFCONVERT_CMD}
306
307# XXX not -j safe
308.y.out:
309	${YACC} ${YFLAGS} ${.IMPSRC}
310	${CC} ${CFLAGS} ${LDFLAGS} y.tab.c ${LDLIBS} -ly -o ${.TARGET}
311	rm -f y.tab.c
312	${CTFCONVERT_CMD}
313
314.l.out:
315	${LEX} -t ${LFLAGS} ${.IMPSRC} > ${.PREFIX}.tmp.c
316	${CC} ${CFLAGS} ${LDFLAGS} ${.PREFIX}.tmp.c ${LDLIBS} -ll -o ${.TARGET}
317	rm -f ${.PREFIX}.tmp.c
318	${CTFCONVERT_CMD}
319
320# Pull in global settings.
321__MAKE_CONF?=/etc/make.conf
322.if exists(${__MAKE_CONF})
323.include "${__MAKE_CONF}"
324.endif
325
326# Setup anything for the FreeBSD source build, if we're building
327# inside the source tree. Needs to be after make.conf, but before
328# local stuff.
329.sinclude <src.sys.mk>
330
331# Set any local definitions first. Place this early, but it needs
332# MACHINE_CPUARCH to be defined.
333.sinclude <local.sys.mk>
334
335.if defined(__MAKE_SHELL) && !empty(__MAKE_SHELL)
336SHELL=	${__MAKE_SHELL}
337.SHELL: path=${__MAKE_SHELL}
338.endif
339
340.if !defined(.PARSEDIR)
341# We are not bmake, which is more aggressive about searching .PATH
342# It is sometime necessary to curb its enthusiasm with .NOPATH
343# The following allows us to quietly ignore .NOPATH when not using bmake.
344.NOTMAIN: .NOPATH
345.NOPATH:
346
347# Toggle on warnings
348.WARN: dirsyntax
349.else # is bmake
350# Tell bmake to expand -V VAR by default
351.MAKE.EXPAND_VARIABLES= yes
352
353# Tell bmake the makefile preference
354.MAKE.MAKEFILE_PREFERENCE= BSDmakefile makefile Makefile
355
356# By default bmake does *not* use set -e
357# when running target scripts, this is a problem for many makefiles here.
358# So define a shell that will do what FreeBSD expects.
359.ifndef WITHOUT_SHELL_ERRCTL
360.SHELL: name=sh \
361	quiet="set -" echo="set -v" filter="set -" \
362	hasErrCtl=yes check="set -e" ignore="set +e" \
363	echoFlag=v errFlag=e \
364	path=${__MAKE_SHELL:U/bin/sh}
365.endif
366.endif # bmake
367
368.include <bsd.cpu.mk>
369
370.endif # ! Posix
371