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