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