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