xref: /freebsd/share/mk/sys.mk (revision c36e54bb328697af1e6113812caecbd3bac89fe0)
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
20# Some options we need now
21__DEFAULT_NO_OPTIONS= \
22	DIRDEPS_CACHE \
23	META_MODE \
24	META_FILES \
25
26
27__DEFAULT_DEPENDENT_OPTIONS= \
28	AUTO_OBJ/META_MODE \
29	STAGING/META_MODE \
30	SYSROOT/META_MODE
31
32.include <bsd.mkopt.mk>
33
34# early include for customization
35# see local.sys.mk below
36.-include <local.sys.env.mk>
37
38.if ${MK_META_MODE} == "yes"
39.-include <meta.sys.mk>
40.elif ${MK_META_FILES} == "yes" && ${.MAKEFLAGS:U:M-B} == ""
41.MAKE.MODE= meta verbose
42.endif
43.if ${MK_AUTO_OBJ} == "yes"
44# This needs to be done early - before .PATH is computed
45.-include <auto.obj.mk>
46.endif
47
48# If the special target .POSIX appears (without prerequisites or
49# commands) before the first noncomment line in the makefile, make shall
50# process the makefile as specified by the Posix 1003.2 specification.
51# make(1) sets the special macro %POSIX in this case (to the actual
52# value "1003.2", for what it's worth).
53#
54# The rules below use this macro to distinguish between Posix-compliant
55# and default behaviour.
56
57.if defined(%POSIX)
58.SUFFIXES:	.o .c .y .l .a .sh .f
59.else
60.SUFFIXES:	.out .a .ln .o .c .cc .cpp .cxx .C .m .F .f .e .r .y .l .S .asm .s .cl .p .h .sh
61.endif
62
63AR		?=	ar
64.if defined(%POSIX)
65ARFLAGS		?=	-rv
66.else
67ARFLAGS		?=	-crD
68.endif
69RANLIB		?=	ranlib
70.if !defined(%POSIX)
71RANLIBFLAGS	?=	-D
72.endif
73
74AS		?=	as
75AFLAGS		?=
76ACFLAGS		?=
77
78.if defined(%POSIX)
79CC		?=	c89
80CFLAGS		?=	-O
81.else
82CC		?=	cc
83.if ${MACHINE_CPUARCH} == "arm" || ${MACHINE_CPUARCH} == "mips"
84CFLAGS		?=	-O -pipe
85.else
86CFLAGS		?=	-O2 -pipe
87.endif
88.if defined(NO_STRICT_ALIASING)
89CFLAGS		+=	-fno-strict-aliasing
90.endif
91.endif
92PO_CFLAGS	?=	${CFLAGS}
93
94# cp(1) is used to copy source files to ${.OBJDIR}, make sure it can handle
95# read-only files as non-root by passing -f.
96CP		?=	cp -f
97
98CPP		?=	cpp
99
100# C Type Format data is required for DTrace
101CTFFLAGS	?=	-L VERSION
102
103CTFCONVERT	?=	ctfconvert
104CTFMERGE	?=	ctfmerge
105
106.if defined(CFLAGS) && (${CFLAGS:M-g} != "")
107CTFFLAGS	+=	-g
108.endif
109
110CXX		?=	c++
111CXXFLAGS	?=	${CFLAGS:N-std=*:N-Wnested-externs:N-W*-prototypes:N-Wno-pointer-sign:N-Wold-style-definition}
112PO_CXXFLAGS	?=	${CXXFLAGS}
113
114DTRACE		?=	dtrace
115DTRACEFLAGS	?=	-C -x nolibs
116
117.if empty(.MAKEFLAGS:M-s)
118ECHO		?=	echo
119ECHODIR		?=	echo
120.else
121ECHO		?=	true
122.if ${.MAKEFLAGS:M-s} == "-s"
123ECHODIR		?=	echo
124.else
125ECHODIR		?=	true
126.endif
127.endif
128
129.if defined(.PARSEDIR)
130# _+_ appears to be a workaround for the special src .MAKE not working.
131# setting it to + interferes with -N
132_+_		?=
133.elif !empty(.MAKEFLAGS:M-n) && ${.MAKEFLAGS:M-n} == "-n"
134# the check above matches only a single -n, so -n -n will result
135# in _+_ = +
136_+_		?=
137.else
138_+_		?=	+
139.endif
140
141.if defined(%POSIX)
142FC		?=	fort77
143FFLAGS		?=	-O 1
144.else
145FC		?=	f77
146FFLAGS		?=	-O
147.endif
148EFLAGS		?=
149
150INSTALL		?=	install
151
152LEX		?=	lex
153LFLAGS		?=
154
155LD		?=	ld
156LDFLAGS		?=				# LDFLAGS is for CC,
157_LDFLAGS	=	${LDFLAGS:S/-Wl,//g}	# strip -Wl, for LD
158
159LINT		?=	lint
160LINTFLAGS	?=	-cghapbx
161LINTKERNFLAGS	?=	${LINTFLAGS}
162LINTOBJFLAGS	?=	-cghapbxu -i
163LINTOBJKERNFLAGS?=	${LINTOBJFLAGS}
164LINTLIBFLAGS	?=	-cghapbxu -C ${LIB}
165
166MAKE		?=	make
167
168.if !defined(%POSIX)
169NM		?=	nm
170
171OBJC		?=	cc
172OBJCFLAGS	?=	${OBJCINCLUDES} ${CFLAGS} -Wno-import
173
174OBJCOPY		?=	objcopy
175
176OBJDUMP		?=	objdump
177
178PC		?=	pc
179PFLAGS		?=
180
181RC		?=	f77
182RFLAGS		?=
183.endif
184
185SHELL		?=	sh
186
187.if !defined(%POSIX)
188SIZE		?=	size
189.endif
190
191YACC		?=	yacc
192.if defined(%POSIX)
193YFLAGS		?=
194.else
195YFLAGS		?=	-d
196.endif
197
198.if defined(%POSIX)
199
200# Posix 1003.2 mandated rules
201#
202# Quoted directly from the Posix 1003.2 draft, only the macros
203# $@, $< and $* have been replaced by ${.TARGET}, ${.IMPSRC}, and
204# ${.PREFIX}, resp.
205
206# SINGLE SUFFIX RULES
207.c:
208	${CC} ${CFLAGS} ${LDFLAGS} -o ${.TARGET} ${.IMPSRC}
209
210.f:
211	${FC} ${FFLAGS} ${LDFLAGS} -o ${.TARGET} ${.IMPSRC}
212
213.sh:
214	cp -f ${.IMPSRC} ${.TARGET}
215	chmod a+x ${.TARGET}
216
217# DOUBLE SUFFIX RULES
218
219.c.o:
220	${CC} ${CFLAGS} -c ${.IMPSRC}
221
222.f.o:
223	${FC} ${FFLAGS} -c ${.IMPSRC}
224
225.y.o:
226	${YACC} ${YFLAGS} ${.IMPSRC}
227	${CC} ${CFLAGS} -c y.tab.c
228	rm -f y.tab.c
229	mv y.tab.o ${.TARGET}
230
231.l.o:
232	${LEX} ${LFLAGS} ${.IMPSRC}
233	${CC} ${CFLAGS} -c lex.yy.c
234	rm -f lex.yy.c
235	mv lex.yy.o ${.TARGET}
236
237.y.c:
238	${YACC} ${YFLAGS} ${.IMPSRC}
239	mv y.tab.c ${.TARGET}
240
241.l.c:
242	${LEX} ${LFLAGS} ${.IMPSRC}
243	mv lex.yy.c ${.TARGET}
244
245.c.a:
246	${CC} ${CFLAGS} -c ${.IMPSRC}
247	${AR} ${ARFLAGS} ${.TARGET} ${.PREFIX}.o
248	rm -f ${.PREFIX}.o
249
250.f.a:
251	${FC} ${FFLAGS} -c ${.IMPSRC}
252	${AR} ${ARFLAGS} ${.TARGET} ${.PREFIX}.o
253	rm -f ${.PREFIX}.o
254
255.else
256
257# non-Posix rule set
258
259.sh:
260	cp -fp ${.IMPSRC} ${.TARGET}
261	chmod a+x ${.TARGET}
262
263.c.ln:
264	${LINT} ${LINTOBJFLAGS} ${CFLAGS:M-[DIU]*} ${.IMPSRC} || \
265	    touch ${.TARGET}
266
267.cc.ln .C.ln .cpp.ln .cxx.ln:
268	${LINT} ${LINTOBJFLAGS} ${CXXFLAGS:M-[DIU]*} ${.IMPSRC} || \
269	    touch ${.TARGET}
270
271.c:
272	${CC} ${CFLAGS} ${LDFLAGS} ${.IMPSRC} ${LDLIBS} -o ${.TARGET}
273	${CTFCONVERT_CMD}
274
275.c.o:
276	${CC} ${CFLAGS} -c ${.IMPSRC} -o ${.TARGET}
277	${CTFCONVERT_CMD}
278
279.cc .cpp .cxx .C:
280	${CXX} ${CXXFLAGS} ${LDFLAGS} ${.IMPSRC} ${LDLIBS} -o ${.TARGET}
281
282.cc.o .cpp.o .cxx.o .C.o:
283	${CXX} ${CXXFLAGS} -c ${.IMPSRC} -o ${.TARGET}
284
285.m.o:
286	${OBJC} ${OBJCFLAGS} -c ${.IMPSRC} -o ${.TARGET}
287	${CTFCONVERT_CMD}
288
289.p.o:
290	${PC} ${PFLAGS} -c ${.IMPSRC} -o ${.TARGET}
291	${CTFCONVERT_CMD}
292
293.e .r .F .f:
294	${FC} ${RFLAGS} ${EFLAGS} ${FFLAGS} ${LDFLAGS} ${.IMPSRC} ${LDLIBS} \
295	    -o ${.TARGET}
296
297.e.o .r.o .F.o .f.o:
298	${FC} ${RFLAGS} ${EFLAGS} ${FFLAGS} -c ${.IMPSRC} -o ${.TARGET}
299
300.S.o:
301	${CC} ${CFLAGS} ${ACFLAGS} -c ${.IMPSRC} -o ${.TARGET}
302	${CTFCONVERT_CMD}
303
304.asm.o:
305	${CC} -x assembler-with-cpp ${CFLAGS} ${ACFLAGS} -c ${.IMPSRC} \
306	    -o ${.TARGET}
307	${CTFCONVERT_CMD}
308
309.s.o:
310	${AS} ${AFLAGS} -o ${.TARGET} ${.IMPSRC}
311	${CTFCONVERT_CMD}
312
313# XXX not -j safe
314.y.o:
315	${YACC} ${YFLAGS} ${.IMPSRC}
316	${CC} ${CFLAGS} -c y.tab.c -o ${.TARGET}
317	rm -f y.tab.c
318	${CTFCONVERT_CMD}
319
320.l.o:
321	${LEX} -t ${LFLAGS} ${.IMPSRC} > ${.PREFIX}.tmp.c
322	${CC} ${CFLAGS} -c ${.PREFIX}.tmp.c -o ${.TARGET}
323	rm -f ${.PREFIX}.tmp.c
324	${CTFCONVERT_CMD}
325
326# XXX not -j safe
327.y.c:
328	${YACC} ${YFLAGS} ${.IMPSRC}
329	mv y.tab.c ${.TARGET}
330
331.l.c:
332	${LEX} -t ${LFLAGS} ${.IMPSRC} > ${.TARGET}
333
334.s.out .c.out .o.out:
335	${CC} ${CFLAGS} ${LDFLAGS} ${.IMPSRC} ${LDLIBS} -o ${.TARGET}
336	${CTFCONVERT_CMD}
337
338.f.out .F.out .r.out .e.out:
339	${FC} ${EFLAGS} ${RFLAGS} ${FFLAGS} ${LDFLAGS} ${.IMPSRC} \
340	    ${LDLIBS} -o ${.TARGET}
341	rm -f ${.PREFIX}.o
342	${CTFCONVERT_CMD}
343
344# XXX not -j safe
345.y.out:
346	${YACC} ${YFLAGS} ${.IMPSRC}
347	${CC} ${CFLAGS} ${LDFLAGS} y.tab.c ${LDLIBS} -ly -o ${.TARGET}
348	rm -f y.tab.c
349	${CTFCONVERT_CMD}
350
351.l.out:
352	${LEX} -t ${LFLAGS} ${.IMPSRC} > ${.PREFIX}.tmp.c
353	${CC} ${CFLAGS} ${LDFLAGS} ${.PREFIX}.tmp.c ${LDLIBS} -ll -o ${.TARGET}
354	rm -f ${.PREFIX}.tmp.c
355	${CTFCONVERT_CMD}
356
357# Pull in global settings.
358__MAKE_CONF?=/etc/make.conf
359.if exists(${__MAKE_CONF})
360.include "${__MAKE_CONF}"
361.endif
362
363# late include for customization
364.-include <local.sys.mk>
365
366.if defined(__MAKE_SHELL) && !empty(__MAKE_SHELL)
367SHELL=	${__MAKE_SHELL}
368.SHELL: path=${__MAKE_SHELL}
369.endif
370
371# Tell bmake to expand -V VAR by default
372.MAKE.EXPAND_VARIABLES= yes
373
374# Tell bmake the makefile preference
375.MAKE.MAKEFILE_PREFERENCE= BSDmakefile makefile Makefile
376
377# By default bmake does *not* use set -e
378# when running target scripts, this is a problem for many makefiles here.
379# So define a shell that will do what FreeBSD expects.
380.ifndef WITHOUT_SHELL_ERRCTL
381.SHELL: name=sh \
382	quiet="set -" echo="set -v" filter="set -" \
383	hasErrCtl=yes check="set -e" ignore="set +e" \
384	echoFlag=v errFlag=e \
385	path=${__MAKE_SHELL:U/bin/sh}
386.endif
387
388.include <bsd.cpu.mk>
389
390.endif # ! Posix
391