xref: /freebsd/share/mk/sys.mk (revision 23090366f729c56cab62de74c7a51792357e98a9)
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)?/arm/:C/powerpc64/powerpc/}
17.endif
18
19# Set any local definitions first. Place this early, but it needs
20# MACHINE_CPUARCH to be defined.
21.sinclude <local.sys.mk>
22
23# If the special target .POSIX appears (without prerequisites or
24# commands) before the first noncomment line in the makefile, make shall
25# process the makefile as specified by the Posix 1003.2 specification.
26# make(1) sets the special macro %POSIX in this case (to the actual
27# value "1003.2", for what it's worth).
28#
29# The rules below use this macro to distinguish between Posix-compliant
30# and default behaviour.
31
32.if defined(%POSIX)
33.SUFFIXES:	.o .c .y .l .a .sh .f
34.else
35.SUFFIXES:	.out .a .ln .o .c .cc .cpp .cxx .C .m .F .f .e .r .y .l .S .asm .s .cl .p .h .sh
36.endif
37
38AR		?=	ar
39.if defined(%POSIX)
40ARFLAGS		?=	-rv
41.else
42ARFLAGS		?=	rl
43.endif
44RANLIB		?=	ranlib
45
46AS		?=	as
47AFLAGS		?=
48ACFLAGS		?=
49
50.if defined(%POSIX)
51CC		?=	c89
52CFLAGS		?=	-O
53.else
54CC		?=	cc
55.if ${MACHINE_CPUARCH} == "arm" || ${MACHINE_CPUARCH} == "mips"
56CFLAGS		?=	-O -pipe
57.else
58CFLAGS		?=	-O2 -pipe
59.endif
60.if defined(NO_STRICT_ALIASING)
61CFLAGS		+=	-fno-strict-aliasing
62.endif
63.endif
64PO_CFLAGS	?=	${CFLAGS}
65
66# C Type Format data is required for DTrace
67CTFFLAGS	?=	-L VERSION
68
69CTFCONVERT	?=	ctfconvert
70CTFMERGE	?=	ctfmerge
71DTRACE		?=	dtrace
72.if defined(CFLAGS) && (${CFLAGS:M-g} != "")
73CTFFLAGS	+=	-g
74.else
75# XXX: What to do here? Is removing the CFLAGS part completely ok here?
76# For now comment it out to not compile with -g unconditionally.
77#CFLAGS		+=	-g
78.endif
79
80CXX		?=	c++
81CXXFLAGS	?=	${CFLAGS:N-std=*:N-Wnested-externs:N-W*-prototypes:N-Wno-pointer-sign:N-Wold-style-definition}
82PO_CXXFLAGS	?=	${CXXFLAGS}
83
84CPP		?=	cpp
85
86.if empty(.MAKEFLAGS:M-s)
87ECHO		?=	echo
88ECHODIR		?=	echo
89.else
90ECHO		?=	true
91.if ${.MAKEFLAGS:M-s} == "-s"
92ECHODIR		?=	echo
93.else
94ECHODIR		?=	true
95.endif
96.endif
97
98.if !empty(.MAKEFLAGS:M-n) && ${.MAKEFLAGS:M-n} == "-n"
99_+_		?=
100.else
101_+_		?=	+
102.endif
103
104.if defined(%POSIX)
105FC		?=	fort77
106FFLAGS		?=	-O 1
107.else
108FC		?=	f77
109FFLAGS		?=	-O
110.endif
111EFLAGS		?=
112
113INSTALL		?=	install
114
115LEX		?=	lex
116LFLAGS		?=
117
118LD		?=	ld
119LDFLAGS		?=
120
121LINT		?=	lint
122LINTFLAGS	?=	-cghapbx
123LINTKERNFLAGS	?=	${LINTFLAGS}
124LINTOBJFLAGS	?=	-cghapbxu -i
125LINTOBJKERNFLAGS?=	${LINTOBJFLAGS}
126LINTLIBFLAGS	?=	-cghapbxu -C ${LIB}
127
128MAKE		?=	make
129
130.if !defined(%POSIX)
131NM		?=	nm
132.endif
133
134OBJC		?=	cc
135OBJCFLAGS	?=	${OBJCINCLUDES} ${CFLAGS} -Wno-import
136
137PC		?=	pc
138PFLAGS		?=
139
140RC		?=	f77
141RFLAGS		?=
142
143SHELL		?=	sh
144
145YACC		?=	yacc
146.if defined(%POSIX)
147YFLAGS		?=
148.else
149YFLAGS		?=	-d
150.endif
151
152.if defined(%POSIX)
153
154# Posix 1003.2 mandated rules
155#
156# Quoted directly from the Posix 1003.2 draft, only the macros
157# $@, $< and $* have been replaced by ${.TARGET}, ${.IMPSRC}, and
158# ${.PREFIX}, resp.
159
160# SINGLE SUFFIX RULES
161.c:
162	${CC} ${CFLAGS} ${LDFLAGS} -o ${.TARGET} ${.IMPSRC}
163	${CTFCONVERT_CMD}
164
165.f:
166	${FC} ${FFLAGS} ${LDFLAGS} -o ${.TARGET} ${.IMPSRC}
167	${CTFCONVERT_CMD}
168
169.sh:
170	cp -f ${.IMPSRC} ${.TARGET}
171	chmod a+x ${.TARGET}
172
173# DOUBLE SUFFIX RULES
174
175.c.o:
176	${CC} ${CFLAGS} -c ${.IMPSRC}
177	${CTFCONVERT_CMD}
178
179.f.o:
180	${FC} ${FFLAGS} -c ${.IMPSRC}
181	${CTFCONVERT_CMD}
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	${CTFCONVERT_CMD}
189
190.l.o:
191	${LEX} ${LFLAGS} ${.IMPSRC}
192	${CC} ${CFLAGS} -c lex.yy.c
193	rm -f lex.yy.c
194	mv lex.yy.o ${.TARGET}
195	${CTFCONVERT_CMD}
196
197.y.c:
198	${YACC} ${YFLAGS} ${.IMPSRC}
199	mv y.tab.c ${.TARGET}
200
201.l.c:
202	${LEX} ${LFLAGS} ${.IMPSRC}
203	mv lex.yy.c ${.TARGET}
204
205.c.a:
206	${CC} ${CFLAGS} -c ${.IMPSRC}
207	${AR} ${ARFLAGS} ${.TARGET} ${.PREFIX}.o
208	rm -f ${.PREFIX}.o
209
210.f.a:
211	${FC} ${FFLAGS} -c ${.IMPSRC}
212	${AR} ${ARFLAGS} ${.TARGET} ${.PREFIX}.o
213	rm -f ${.PREFIX}.o
214
215.else
216
217# non-Posix rule set
218
219.sh:
220	cp -fp ${.IMPSRC} ${.TARGET}
221	chmod a+x ${.TARGET}
222
223.c.ln:
224	${LINT} ${LINTOBJFLAGS} ${CFLAGS:M-[DIU]*} ${.IMPSRC} || \
225	    touch ${.TARGET}
226
227.cc.ln .C.ln .cpp.ln .cxx.ln:
228	${LINT} ${LINTOBJFLAGS} ${CXXFLAGS:M-[DIU]*} ${.IMPSRC} || \
229	    touch ${.TARGET}
230
231.c:
232	${CC} ${CFLAGS} ${LDFLAGS} ${.IMPSRC} ${LDLIBS} -o ${.TARGET}
233	${CTFCONVERT_CMD}
234
235.c.o:
236	${CC} ${CFLAGS} -c ${.IMPSRC}
237	${CTFCONVERT_CMD}
238
239.cc .cpp .cxx .C:
240	${CXX} ${CXXFLAGS} ${LDFLAGS} ${.IMPSRC} ${LDLIBS} -o ${.TARGET}
241
242.cc.o .cpp.o .cxx.o .C.o:
243	${CXX} ${CXXFLAGS} -c ${.IMPSRC}
244
245.m.o:
246	${OBJC} ${OBJCFLAGS} -c ${.IMPSRC}
247	${CTFCONVERT_CMD}
248
249.p.o:
250	${PC} ${PFLAGS} -c ${.IMPSRC}
251	${CTFCONVERT_CMD}
252
253.e .r .F .f:
254	${FC} ${RFLAGS} ${EFLAGS} ${FFLAGS} ${LDFLAGS} ${.IMPSRC} ${LDLIBS} \
255	    -o ${.TARGET}
256
257.e.o .r.o .F.o .f.o:
258	${FC} ${RFLAGS} ${EFLAGS} ${FFLAGS} -c ${.IMPSRC}
259
260.S.o:
261	${CC} ${CFLAGS} ${ACFLAGS} -c ${.IMPSRC}
262	${CTFCONVERT_CMD}
263
264.asm.o:
265	${CC} -x assembler-with-cpp ${CFLAGS} ${ACFLAGS} -c ${.IMPSRC}
266	${CTFCONVERT_CMD}
267
268.s.o:
269	${AS} ${AFLAGS} -o ${.TARGET} ${.IMPSRC}
270	${CTFCONVERT_CMD}
271
272# XXX not -j safe
273.y.o:
274	${YACC} ${YFLAGS} ${.IMPSRC}
275	${CC} ${CFLAGS} -c y.tab.c -o ${.TARGET}
276	rm -f y.tab.c
277	${CTFCONVERT_CMD}
278
279.l.o:
280	${LEX} -t ${LFLAGS} ${.IMPSRC} > ${.PREFIX}.tmp.c
281	${CC} ${CFLAGS} -c ${.PREFIX}.tmp.c -o ${.TARGET}
282	rm -f ${.PREFIX}.tmp.c
283	${CTFCONVERT_CMD}
284
285# XXX not -j safe
286.y.c:
287	${YACC} ${YFLAGS} ${.IMPSRC}
288	mv y.tab.c ${.TARGET}
289
290.l.c:
291	${LEX} -t ${LFLAGS} ${.IMPSRC} > ${.TARGET}
292
293.s.out .c.out .o.out:
294	${CC} ${CFLAGS} ${LDFLAGS} ${.IMPSRC} ${LDLIBS} -o ${.TARGET}
295	${CTFCONVERT_CMD}
296
297.f.out .F.out .r.out .e.out:
298	${FC} ${EFLAGS} ${RFLAGS} ${FFLAGS} ${LDFLAGS} ${.IMPSRC} \
299	    ${LDLIBS} -o ${.TARGET}
300	rm -f ${.PREFIX}.o
301	${CTFCONVERT_CMD}
302
303# XXX not -j safe
304.y.out:
305	${YACC} ${YFLAGS} ${.IMPSRC}
306	${CC} ${CFLAGS} ${LDFLAGS} y.tab.c ${LDLIBS} -ly -o ${.TARGET}
307	rm -f y.tab.c
308	${CTFCONVERT_CMD}
309
310.l.out:
311	${LEX} -t ${LFLAGS} ${.IMPSRC} > ${.PREFIX}.tmp.c
312	${CC} ${CFLAGS} ${LDFLAGS} ${.PREFIX}.tmp.c ${LDLIBS} -ll -o ${.TARGET}
313	rm -f ${.PREFIX}.tmp.c
314	${CTFCONVERT_CMD}
315
316# FreeBSD build pollution.  Hide it in the non-POSIX part of the ifdef.
317__MAKE_CONF?=/etc/make.conf
318.if exists(${__MAKE_CONF})
319.include "${__MAKE_CONF}"
320.endif
321
322.if defined(__MAKE_SHELL) && !empty(__MAKE_SHELL)
323SHELL=	${__MAKE_SHELL}
324.SHELL: path=${__MAKE_SHELL}
325.endif
326
327# Default executable format
328# XXX hint for bsd.port.mk
329OBJFORMAT?=	elf
330
331# Tell bmake to expand -V VAR by default
332.MAKE.EXPAND_VARIABLES= yes
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.endif
344
345.endif
346
347.include <bsd.compat.mk>
348.include <bsd.cpu.mk>
349