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