1 # from: @(#)sys.mk 8.2 (Berkeley) 3/21/94
4 unix ?= We run FreeBSD, not UNIX.
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.
16 MACHINE_CPUARCH=${MACHINE_ARCH:C/mips(n32|64)?(el)?/mips/:C/arm(v6)?(eb|hf)?/arm/:C/powerpc64/powerpc/:C/riscv64/riscv/}
20 # Some options we need now
21 __DEFAULT_NO_OPTIONS= \
25 __DEFAULT_DEPENDENT_OPTIONS= \
26 AUTO_OBJ/DIRDEPS_BUILD \
27 META_MODE/DIRDEPS_BUILD \
28 STAGING/DIRDEPS_BUILD \
31 __ENV_ONLY_OPTIONS:= \
32 ${__DEFAULT_NO_OPTIONS} \
33 ${__DEFAULT_YES_OPTIONS} \
34 ${__DEFAULT_DEPENDENT_OPTIONS:H}
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>
43 .include <bsd.mkopt.mk>
45 # Disable MK_META_MODE with make -B
46 .if ${MK_META_MODE} == "yes" && defined(.MAKEFLAGS) && ${.MAKEFLAGS:M-B}
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.
54 META_MODE+= meta verbose
55 .if !defined(NO_META_MISSING)
56 META_MODE+= missing-meta=yes
58 # silent will hide command output if a .meta file is created.
59 .if !defined(NO_SILENT)
60 META_MODE+= silent=yes
62 .if !exists(/dev/filemon)
65 # Require filemon data with bmake
66 .if empty(META_MODE:Mnofilemon)
67 META_MODE+= missing-filemon=yes
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+= \
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
100 .if !make(showconfig) && !make(print-dir)
101 .sinclude <auto.obj.mk>
105 .include <bsd.mkopt.mk>
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).
114 # The rules below use this macro to distinguish between Posix-compliant
115 # and default behaviour.
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.
122 .SUFFIXES: .o .c .y .l .a .sh .f
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
147 .if ${MACHINE_CPUARCH} == "arm" || ${MACHINE_CPUARCH} == "mips"
152 .if defined(NO_STRICT_ALIASING)
153 CFLAGS += -fno-strict-aliasing
156 PO_CFLAGS ?= ${CFLAGS}
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.
164 # C Type Format data is required for DTrace
165 CTFFLAGS ?= -L VERSION
167 CTFCONVERT ?= ctfconvert
170 .if defined(CFLAGS) && (${CFLAGS:M-g} != "")
175 CXXFLAGS ?= ${CFLAGS:N-std=*:N-Wnested-externs:N-W*-prototypes:N-Wno-pointer-sign:N-Wold-style-definition}
176 PO_CXXFLAGS ?= ${CXXFLAGS}
179 DTRACEFLAGS ?= -C -x nolibs
181 .if empty(.MAKEFLAGS:M-s)
186 .if ${.MAKEFLAGS:M-s} == "-s"
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.
219 LDFLAGS ?= # LDFLAGS is for CC,
220 _LDFLAGS = ${LDFLAGS:S/-Wl,//g} # strip -Wl, for LD
223 LINTFLAGS ?= -cghapbx
224 LINTKERNFLAGS ?= ${LINTFLAGS}
225 LINTOBJFLAGS ?= -cghapbxu -i
226 LINTOBJKERNFLAGS?= ${LINTOBJFLAGS}
227 LINTLIBFLAGS ?= -cghapbxu -C ${LIB}
236 OBJCFLAGS ?= ${OBJCINCLUDES} ${CFLAGS} -Wno-import
262 # Posix 1003.2 mandated rules
264 # Quoted directly from the Posix 1003.2 draft, only the macros
265 # $@, $< and $* have been replaced by ${.TARGET}, ${.IMPSRC}, and
268 # SINGLE SUFFIX RULES
270 ${CC} ${CFLAGS} ${LDFLAGS} -o ${.TARGET} ${.IMPSRC}
273 ${FC} ${FFLAGS} ${LDFLAGS} -o ${.TARGET} ${.IMPSRC}
276 cp -f ${.IMPSRC} ${.TARGET}
279 # DOUBLE SUFFIX RULES
282 ${CC} ${CFLAGS} -c ${.IMPSRC}
285 ${FC} ${FFLAGS} -c ${.IMPSRC}
288 ${YACC} ${YFLAGS} ${.IMPSRC}
289 ${CC} ${CFLAGS} -c y.tab.c
291 mv y.tab.o ${.TARGET}
294 ${LEX} ${LFLAGS} ${.IMPSRC}
295 ${CC} ${CFLAGS} -c lex.yy.c
297 mv lex.yy.o ${.TARGET}
300 ${YACC} ${YFLAGS} ${.IMPSRC}
301 mv y.tab.c ${.TARGET}
304 ${LEX} ${LFLAGS} ${.IMPSRC}
305 mv lex.yy.c ${.TARGET}
308 ${CC} ${CFLAGS} -c ${.IMPSRC}
309 ${AR} ${ARFLAGS} ${.TARGET} ${.PREFIX}.o
313 ${FC} ${FFLAGS} -c ${.IMPSRC}
314 ${AR} ${ARFLAGS} ${.TARGET} ${.PREFIX}.o
322 cp -f ${.IMPSRC} ${.TARGET}
326 ${LINT} ${LINTOBJFLAGS} ${CFLAGS:M-[DIU]*} ${.IMPSRC} || \
329 .cc.ln .C.ln .cpp.ln .cxx.ln:
330 ${LINT} ${LINTOBJFLAGS} ${CXXFLAGS:M-[DIU]*} ${.IMPSRC} || \
334 ${CC} ${CFLAGS} ${LDFLAGS} ${.IMPSRC} ${LDLIBS} -o ${.TARGET}
338 ${CC} ${CFLAGS} -c ${.IMPSRC} -o ${.TARGET}
342 ${CXX} ${CXXFLAGS} ${LDFLAGS} ${.IMPSRC} ${LDLIBS} -o ${.TARGET}
344 .cc.o .cpp.o .cxx.o .C.o:
345 ${CXX} ${CXXFLAGS} -c ${.IMPSRC} -o ${.TARGET}
348 ${OBJC} ${OBJCFLAGS} -c ${.IMPSRC} -o ${.TARGET}
352 ${PC} ${PFLAGS} -c ${.IMPSRC} -o ${.TARGET}
356 ${FC} ${RFLAGS} ${EFLAGS} ${FFLAGS} ${LDFLAGS} ${.IMPSRC} ${LDLIBS} \
360 ${FC} ${RFLAGS} ${EFLAGS} ${FFLAGS} -c ${.IMPSRC} -o ${.TARGET}
363 ${CC:N${CCACHE_BIN}} ${CFLAGS} ${ACFLAGS} -c ${.IMPSRC} -o ${.TARGET}
367 ${CC:N${CCACHE_BIN}} -x assembler-with-cpp ${CFLAGS} ${ACFLAGS} -c ${.IMPSRC} \
372 ${AS} ${AFLAGS} -o ${.TARGET} ${.IMPSRC}
377 ${YACC} ${YFLAGS} ${.IMPSRC}
378 ${CC} ${CFLAGS} -c y.tab.c -o ${.TARGET}
383 ${LEX} -t ${LFLAGS} ${.IMPSRC} > ${.PREFIX}.tmp.c
384 ${CC} ${CFLAGS} -c ${.PREFIX}.tmp.c -o ${.TARGET}
385 rm -f ${.PREFIX}.tmp.c
390 ${YACC} ${YFLAGS} ${.IMPSRC}
391 mv y.tab.c ${.TARGET}
394 ${LEX} -t ${LFLAGS} ${.IMPSRC} > ${.TARGET}
396 .s.out .c.out .o.out:
397 ${CC} ${CFLAGS} ${LDFLAGS} ${.IMPSRC} ${LDLIBS} -o ${.TARGET}
400 .f.out .F.out .r.out .e.out:
401 ${FC} ${EFLAGS} ${RFLAGS} ${FFLAGS} ${LDFLAGS} ${.IMPSRC} \
402 ${LDLIBS} -o ${.TARGET}
408 ${YACC} ${YFLAGS} ${.IMPSRC}
409 ${CC} ${CFLAGS} ${LDFLAGS} y.tab.c ${LDLIBS} -ly -o ${.TARGET}
414 ${LEX} -t ${LFLAGS} ${.IMPSRC} > ${.PREFIX}.tmp.c
415 ${CC} ${CFLAGS} ${LDFLAGS} ${.PREFIX}.tmp.c ${LDLIBS} -ll -o ${.TARGET}
416 rm -f ${.PREFIX}.tmp.c
419 # Pull in global settings.
420 __MAKE_CONF?=/etc/make.conf
421 .if exists(${__MAKE_CONF})
422 .include "${__MAKE_CONF}"
425 # late include for customization
426 .sinclude <local.sys.mk>
428 .if defined(META_MODE)
429 META_MODE:= ${META_MODE:O:u}
432 .if defined(__MAKE_SHELL) && !empty(__MAKE_SHELL)
433 SHELL= ${__MAKE_SHELL}
434 .SHELL: path=${__MAKE_SHELL}
437 # Tell bmake to expand -V VAR by default
438 .MAKE.EXPAND_VARIABLES= yes
440 # Tell bmake the makefile preference
441 .MAKE.MAKEFILE_PREFERENCE= BSDmakefile makefile Makefile
443 # Tell bmake to always pass job tokens, regardless of target depending on
444 # .MAKE or looking like ${MAKE}/${.MAKE}/$(MAKE)/$(.MAKE)/make.
445 .MAKE.ALWAYS_PASS_JOB_QUEUE= yes
447 # By default bmake does *not* use set -e
448 # when running target scripts, this is a problem for many makefiles here.
449 # So define a shell that will do what FreeBSD expects.
450 .ifndef WITHOUT_SHELL_ERRCTL
451 __MAKE_SHELL?=/bin/sh
453 quiet="set -" echo="set -v" filter="set -" \
454 hasErrCtl=yes check="set -e" ignore="set +e" \
455 echoFlag=v errFlag=e \
459 # Hack for ports compatibility. Historically, ports makefiles have
460 # assumed they can examine MACHINE_CPU without including anything
461 # because this was automatically included in sys.mk. For /usr/src,
462 # this file has moved to being included from bsd.opts.mk. Until all
463 # the ports files are modernized, and a reasonable transition
464 # period has passed, include it while we're in a ports tree here
465 # to preserve historic behavior.
466 .if exists(${.CURDIR}/../../Mk/bsd.port.mk)
467 .include <bsd.cpu.mk>