xref: /freebsd/share/mk/sys.mk (revision 9fe48b8076ae9c6dc486d713c468ff03ec056eda)
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# cp(1) is used to copy source files to ${.OBJDIR}, make sure it can handle
66# read-only files as non-root by passing -f.
67CP		?=	cp -f
68
69CPP		?=	cpp
70
71# C Type Format data is required for DTrace
72CTFFLAGS	?=	-L VERSION
73
74CTFCONVERT	?=	ctfconvert
75CTFMERGE	?=	ctfmerge
76
77.if defined(CFLAGS) && (${CFLAGS:M-g} != "")
78CTFFLAGS	+=	-g
79.endif
80
81CXX		?=	c++
82CXXFLAGS	?=	${CFLAGS:N-std=*:N-Wnested-externs:N-W*-prototypes:N-Wno-pointer-sign:N-Wold-style-definition}
83PO_CXXFLAGS	?=	${CXXFLAGS}
84
85DTRACE		?=	dtrace
86DTRACEFLAGS	?=	-C -x nolibs
87
88.if empty(.MAKEFLAGS:M-s)
89ECHO		?=	echo
90ECHODIR		?=	echo
91.else
92ECHO		?=	true
93.if ${.MAKEFLAGS:M-s} == "-s"
94ECHODIR		?=	echo
95.else
96ECHODIR		?=	true
97.endif
98.endif
99
100.if defined(.PARSEDIR)
101# _+_ appears to be a workaround for the special src .MAKE not working.
102# setting it to + interferes with -N
103_+_		?=
104.elif !empty(.MAKEFLAGS:M-n) && ${.MAKEFLAGS:M-n} == "-n"
105# the check above matches only a single -n, so -n -n will result
106# in _+_ = +
107_+_		?=
108.else
109_+_		?=	+
110.endif
111
112.if defined(%POSIX)
113FC		?=	fort77
114FFLAGS		?=	-O 1
115.else
116FC		?=	f77
117FFLAGS		?=	-O
118.endif
119EFLAGS		?=
120
121INSTALL		?=	install
122
123LEX		?=	lex
124LFLAGS		?=
125
126LD		?=	ld
127LDFLAGS		?=				# LDFLAGS is for CC,
128_LDFLAGS	=	${LDFLAGS:S/-Wl,//g}	# strip -Wl, for LD
129
130LINT		?=	lint
131LINTFLAGS	?=	-cghapbx
132LINTKERNFLAGS	?=	${LINTFLAGS}
133LINTOBJFLAGS	?=	-cghapbxu -i
134LINTOBJKERNFLAGS?=	${LINTOBJFLAGS}
135LINTLIBFLAGS	?=	-cghapbxu -C ${LIB}
136
137MAKE		?=	make
138
139.if !defined(%POSIX)
140NM		?=	nm
141
142OBJC		?=	cc
143OBJCFLAGS	?=	${OBJCINCLUDES} ${CFLAGS} -Wno-import
144
145OBJCOPY		?=	objcopy
146
147OBJDUMP		?=	objdump
148
149PC		?=	pc
150PFLAGS		?=
151
152RC		?=	f77
153RFLAGS		?=
154.endif
155
156SHELL		?=	sh
157
158.if !defined(%POSIX)
159SIZE		?=	size
160.endif
161
162YACC		?=	yacc
163.if defined(%POSIX)
164YFLAGS		?=
165.else
166YFLAGS		?=	-d
167.endif
168
169.if defined(%POSIX)
170
171# Posix 1003.2 mandated rules
172#
173# Quoted directly from the Posix 1003.2 draft, only the macros
174# $@, $< and $* have been replaced by ${.TARGET}, ${.IMPSRC}, and
175# ${.PREFIX}, resp.
176
177# SINGLE SUFFIX RULES
178.c:
179	${CC} ${CFLAGS} ${LDFLAGS} -o ${.TARGET} ${.IMPSRC}
180
181.f:
182	${FC} ${FFLAGS} ${LDFLAGS} -o ${.TARGET} ${.IMPSRC}
183
184.sh:
185	cp -f ${.IMPSRC} ${.TARGET}
186	chmod a+x ${.TARGET}
187
188# DOUBLE SUFFIX RULES
189
190.c.o:
191	${CC} ${CFLAGS} -c ${.IMPSRC}
192
193.f.o:
194	${FC} ${FFLAGS} -c ${.IMPSRC}
195
196.y.o:
197	${YACC} ${YFLAGS} ${.IMPSRC}
198	${CC} ${CFLAGS} -c y.tab.c
199	rm -f y.tab.c
200	mv y.tab.o ${.TARGET}
201
202.l.o:
203	${LEX} ${LFLAGS} ${.IMPSRC}
204	${CC} ${CFLAGS} -c lex.yy.c
205	rm -f lex.yy.c
206	mv lex.yy.o ${.TARGET}
207
208.y.c:
209	${YACC} ${YFLAGS} ${.IMPSRC}
210	mv y.tab.c ${.TARGET}
211
212.l.c:
213	${LEX} ${LFLAGS} ${.IMPSRC}
214	mv lex.yy.c ${.TARGET}
215
216.c.a:
217	${CC} ${CFLAGS} -c ${.IMPSRC}
218	${AR} ${ARFLAGS} ${.TARGET} ${.PREFIX}.o
219	rm -f ${.PREFIX}.o
220
221.f.a:
222	${FC} ${FFLAGS} -c ${.IMPSRC}
223	${AR} ${ARFLAGS} ${.TARGET} ${.PREFIX}.o
224	rm -f ${.PREFIX}.o
225
226.else
227
228# non-Posix rule set
229
230.sh:
231	cp -fp ${.IMPSRC} ${.TARGET}
232	chmod a+x ${.TARGET}
233
234.c.ln:
235	${LINT} ${LINTOBJFLAGS} ${CFLAGS:M-[DIU]*} ${.IMPSRC} || \
236	    touch ${.TARGET}
237
238.cc.ln .C.ln .cpp.ln .cxx.ln:
239	${LINT} ${LINTOBJFLAGS} ${CXXFLAGS:M-[DIU]*} ${.IMPSRC} || \
240	    touch ${.TARGET}
241
242.c:
243	${CC} ${CFLAGS} ${LDFLAGS} ${.IMPSRC} ${LDLIBS} -o ${.TARGET}
244	${CTFCONVERT_CMD}
245
246.c.o:
247	${CC} ${CFLAGS} -c ${.IMPSRC} -o ${.TARGET}
248	${CTFCONVERT_CMD}
249
250.cc .cpp .cxx .C:
251	${CXX} ${CXXFLAGS} ${LDFLAGS} ${.IMPSRC} ${LDLIBS} -o ${.TARGET}
252
253.cc.o .cpp.o .cxx.o .C.o:
254	${CXX} ${CXXFLAGS} -c ${.IMPSRC} -o ${.TARGET}
255
256.m.o:
257	${OBJC} ${OBJCFLAGS} -c ${.IMPSRC} -o ${.TARGET}
258	${CTFCONVERT_CMD}
259
260.p.o:
261	${PC} ${PFLAGS} -c ${.IMPSRC} -o ${.TARGET}
262	${CTFCONVERT_CMD}
263
264.e .r .F .f:
265	${FC} ${RFLAGS} ${EFLAGS} ${FFLAGS} ${LDFLAGS} ${.IMPSRC} ${LDLIBS} \
266	    -o ${.TARGET}
267
268.e.o .r.o .F.o .f.o:
269	${FC} ${RFLAGS} ${EFLAGS} ${FFLAGS} -c ${.IMPSRC} -o ${.TARGET}
270
271.S.o:
272	${CC} ${CFLAGS} ${ACFLAGS} -c ${.IMPSRC} -o ${.TARGET}
273	${CTFCONVERT_CMD}
274
275.asm.o:
276	${CC} -x assembler-with-cpp ${CFLAGS} ${ACFLAGS} -c ${.IMPSRC} \
277	    -o ${.TARGET}
278	${CTFCONVERT_CMD}
279
280.s.o:
281	${AS} ${AFLAGS} -o ${.TARGET} ${.IMPSRC}
282	${CTFCONVERT_CMD}
283
284# XXX not -j safe
285.y.o:
286	${YACC} ${YFLAGS} ${.IMPSRC}
287	${CC} ${CFLAGS} -c y.tab.c -o ${.TARGET}
288	rm -f y.tab.c
289	${CTFCONVERT_CMD}
290
291.l.o:
292	${LEX} -t ${LFLAGS} ${.IMPSRC} > ${.PREFIX}.tmp.c
293	${CC} ${CFLAGS} -c ${.PREFIX}.tmp.c -o ${.TARGET}
294	rm -f ${.PREFIX}.tmp.c
295	${CTFCONVERT_CMD}
296
297# XXX not -j safe
298.y.c:
299	${YACC} ${YFLAGS} ${.IMPSRC}
300	mv y.tab.c ${.TARGET}
301
302.l.c:
303	${LEX} -t ${LFLAGS} ${.IMPSRC} > ${.TARGET}
304
305.s.out .c.out .o.out:
306	${CC} ${CFLAGS} ${LDFLAGS} ${.IMPSRC} ${LDLIBS} -o ${.TARGET}
307	${CTFCONVERT_CMD}
308
309.f.out .F.out .r.out .e.out:
310	${FC} ${EFLAGS} ${RFLAGS} ${FFLAGS} ${LDFLAGS} ${.IMPSRC} \
311	    ${LDLIBS} -o ${.TARGET}
312	rm -f ${.PREFIX}.o
313	${CTFCONVERT_CMD}
314
315# XXX not -j safe
316.y.out:
317	${YACC} ${YFLAGS} ${.IMPSRC}
318	${CC} ${CFLAGS} ${LDFLAGS} y.tab.c ${LDLIBS} -ly -o ${.TARGET}
319	rm -f y.tab.c
320	${CTFCONVERT_CMD}
321
322.l.out:
323	${LEX} -t ${LFLAGS} ${.IMPSRC} > ${.PREFIX}.tmp.c
324	${CC} ${CFLAGS} ${LDFLAGS} ${.PREFIX}.tmp.c ${LDLIBS} -ll -o ${.TARGET}
325	rm -f ${.PREFIX}.tmp.c
326	${CTFCONVERT_CMD}
327
328# Pull in global settings.
329__MAKE_CONF?=/etc/make.conf
330.if exists(${__MAKE_CONF})
331.include "${__MAKE_CONF}"
332.endif
333
334# Setup anything for the FreeBSD source build, if we're building
335# inside the source tree. Needs to be after make.conf, but before
336# local stuff.
337.sinclude <src.sys.mk>
338
339# Set any local definitions first. Place this early, but it needs
340# MACHINE_CPUARCH to be defined.
341.sinclude <local.sys.mk>
342
343.if defined(__MAKE_SHELL) && !empty(__MAKE_SHELL)
344SHELL=	${__MAKE_SHELL}
345.SHELL: path=${__MAKE_SHELL}
346.endif
347
348.if !defined(.PARSEDIR)
349# We are not bmake, which is more aggressive about searching .PATH
350# It is sometime necessary to curb its enthusiasm with .NOPATH
351# The following allows us to quietly ignore .NOPATH when not using bmake.
352.NOTMAIN: .NOPATH
353.NOPATH:
354
355# Toggle on warnings
356.WARN: dirsyntax
357.else # is bmake
358# Tell bmake to expand -V VAR by default
359.MAKE.EXPAND_VARIABLES= yes
360
361# Tell bmake the makefile preference
362.MAKE.MAKEFILE_PREFERENCE= BSDmakefile makefile Makefile
363
364# By default bmake does *not* use set -e
365# when running target scripts, this is a problem for many makefiles here.
366# So define a shell that will do what FreeBSD expects.
367.ifndef WITHOUT_SHELL_ERRCTL
368.SHELL: name=sh \
369	quiet="set -" echo="set -v" filter="set -" \
370	hasErrCtl=yes check="set -e" ignore="set +e" \
371	echoFlag=v errFlag=e \
372	path=${__MAKE_SHELL:U/bin/sh}
373.endif
374.endif # bmake
375
376.include <bsd.cpu.mk>
377
378.endif # ! Posix
379