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"
54 .if empty(.MAKEFLAGS:M-s)
55 # verbose will show .MAKE.META.PREFIX for each target.
58 .if !defined(NO_META_MISSING)
59 META_MODE+= missing-meta=yes
61 # silent will hide command output if a .meta file is created.
62 .if !defined(NO_SILENT)
63 META_MODE+= silent=yes
65 .if !exists(/dev/filemon) || defined(NO_FILEMON)
68 # Require filemon data with bmake
69 .if empty(META_MODE:Mnofilemon)
70 META_MODE+= missing-filemon=yes
75 .MAKE.MODE?= ${META_MODE}
76 .if !empty(.MAKE.MODE:Mmeta) && !defined(NO_META_IGNORE_HOST)
77 # Ignore host file changes that will otherwise cause
78 # buildworld -> installworld -> buildworld to rebuild everything.
79 # Since the build is self-reliant and bootstraps everything it needs,
80 # this should not be a real problem for incremental builds.
81 # XXX: This relies on the existing host tools retaining ABI compatibility
82 # through upgrades since they won't be rebuilt on header/library changes.
83 # Note that these are prefix matching, so /lib matches /libexec.
84 .MAKE.META.IGNORE_PATHS+= \
97 .if !empty(.MAKE.MODE:Mmeta)
98 # We do not want everything out-of-date just because
99 # some unrelated shared lib updated this.
100 .MAKE.META.IGNORE_PATHS+= /usr/local/etc/libmap.d
103 .if ${MK_AUTO_OBJ} == "yes"
104 # This needs to be done early - before .PATH is computed
105 # Don't do this for 'make showconfig' as it enables all options where meta mode
107 .if !make(showconfig) && !make(print-dir)
108 .sinclude <auto.obj.mk>
112 .include <bsd.mkopt.mk>
115 # If the special target .POSIX appears (without prerequisites or
116 # commands) before the first noncomment line in the makefile, make shall
117 # process the makefile as specified by the Posix 1003.2 specification.
118 # make(1) sets the special macro %POSIX in this case (to the actual
119 # value "1003.2", for what it's worth).
121 # The rules below use this macro to distinguish between Posix-compliant
122 # and default behaviour.
124 # This functionality is currently broken, since make(1) processes sys.mk
125 # before reading any other files, and consequently has no opportunity to
126 # set the %POSIX macro before we read this point.
129 .SUFFIXES: .o .c .y .l .a .sh .f
131 .SUFFIXES: .out .a .ln .o .c .cc .cpp .cxx .C .m .F .f .e .r .y .l .S .asm .s .cl .p .h .sh
154 .if ${MACHINE_CPUARCH} == "arm" || ${MACHINE_CPUARCH} == "mips"
159 .if defined(NO_STRICT_ALIASING)
160 CFLAGS += -fno-strict-aliasing
163 PO_CFLAGS ?= ${CFLAGS}
165 # cp(1) is used to copy source files to ${.OBJDIR}, make sure it can handle
166 # read-only files as non-root by passing -f.
171 # C Type Format data is required for DTrace
172 CTFFLAGS ?= -L VERSION
174 CTFCONVERT ?= ctfconvert
177 .if defined(CFLAGS) && (${CFLAGS:M-g} != "")
182 CXXFLAGS ?= ${CFLAGS:N-std=*:N-Wnested-externs:N-W*-prototypes:N-Wno-pointer-sign:N-Wold-style-definition}
183 PO_CXXFLAGS ?= ${CXXFLAGS}
186 DTRACEFLAGS ?= -C -x nolibs
188 .if empty(.MAKEFLAGS:M-s)
193 .if ${.MAKEFLAGS:M-s} == "-s"
200 .if ${.MAKEFLAGS:M-N}
201 # bmake -N is supposed to skip executing anything but it does not skip
202 # exeucting '+' commands. The '+' feature is used where .MAKE
203 # is not safe for the entire target. -N is intended to skip building sub-makes
204 # so it executing '+' commands is not right. Work around the bug by not
205 # setting '+' when -N is used.
226 LDFLAGS ?= # LDFLAGS is for CC,
227 _LDFLAGS = ${LDFLAGS:S/-Wl,//g} # strip -Wl, for LD
230 LINTFLAGS ?= -cghapbx
231 LINTKERNFLAGS ?= ${LINTFLAGS}
232 LINTOBJFLAGS ?= -cghapbxu -i
233 LINTOBJKERNFLAGS?= ${LINTOBJFLAGS}
234 LINTLIBFLAGS ?= -cghapbxu -C ${LIB}
243 OBJCFLAGS ?= ${OBJCINCLUDES} ${CFLAGS} -Wno-import
271 # Posix 1003.2 mandated rules
273 # Quoted directly from the Posix 1003.2 draft, only the macros
274 # $@, $< and $* have been replaced by ${.TARGET}, ${.IMPSRC}, and
277 # SINGLE SUFFIX RULES
279 ${CC} ${CFLAGS} ${LDFLAGS} -o ${.TARGET} ${.IMPSRC}
282 ${FC} ${FFLAGS} ${LDFLAGS} -o ${.TARGET} ${.IMPSRC}
285 cp -f ${.IMPSRC} ${.TARGET}
288 # DOUBLE SUFFIX RULES
291 ${CC} ${CFLAGS} -c ${.IMPSRC}
294 ${FC} ${FFLAGS} -c ${.IMPSRC}
297 ${YACC} ${YFLAGS} ${.IMPSRC}
298 ${CC} ${CFLAGS} -c y.tab.c
300 mv y.tab.o ${.TARGET}
303 ${LEX} ${LFLAGS} ${.IMPSRC}
304 ${CC} ${CFLAGS} -c lex.yy.c
306 mv lex.yy.o ${.TARGET}
309 ${YACC} ${YFLAGS} ${.IMPSRC}
310 mv y.tab.c ${.TARGET}
313 ${LEX} ${LFLAGS} ${.IMPSRC}
314 mv lex.yy.c ${.TARGET}
317 ${CC} ${CFLAGS} -c ${.IMPSRC}
318 ${AR} ${ARFLAGS} ${.TARGET} ${.PREFIX}.o
322 ${FC} ${FFLAGS} -c ${.IMPSRC}
323 ${AR} ${ARFLAGS} ${.TARGET} ${.PREFIX}.o
331 cp -f ${.IMPSRC} ${.TARGET}
335 ${LINT} ${LINTOBJFLAGS} ${CFLAGS:M-[DIU]*} ${.IMPSRC} || \
338 .cc.ln .C.ln .cpp.ln .cxx.ln:
339 ${LINT} ${LINTOBJFLAGS} ${CXXFLAGS:M-[DIU]*} ${.IMPSRC} || \
343 ${CC} ${CFLAGS} ${LDFLAGS} ${.IMPSRC} ${LDLIBS} -o ${.TARGET}
347 ${CC} ${CFLAGS} -c ${.IMPSRC} -o ${.TARGET}
351 ${CXX} ${CXXFLAGS} ${LDFLAGS} ${.IMPSRC} ${LDLIBS} -o ${.TARGET}
353 .cc.o .cpp.o .cxx.o .C.o:
354 ${CXX} ${CXXFLAGS} -c ${.IMPSRC} -o ${.TARGET}
357 ${OBJC} ${OBJCFLAGS} -c ${.IMPSRC} -o ${.TARGET}
361 ${PC} ${PFLAGS} -c ${.IMPSRC} -o ${.TARGET}
365 ${FC} ${RFLAGS} ${EFLAGS} ${FFLAGS} ${LDFLAGS} ${.IMPSRC} ${LDLIBS} \
369 ${FC} ${RFLAGS} ${EFLAGS} ${FFLAGS} -c ${.IMPSRC} -o ${.TARGET}
372 ${CC:N${CCACHE_BIN}} ${CFLAGS} ${ACFLAGS} -c ${.IMPSRC} -o ${.TARGET}
376 ${CC:N${CCACHE_BIN}} -x assembler-with-cpp ${CFLAGS} ${ACFLAGS} -c ${.IMPSRC} \
381 ${AS} ${AFLAGS} -o ${.TARGET} ${.IMPSRC}
386 ${YACC} ${YFLAGS} ${.IMPSRC}
387 ${CC} ${CFLAGS} -c y.tab.c -o ${.TARGET}
392 ${LEX} -t ${LFLAGS} ${.IMPSRC} > ${.PREFIX}.tmp.c
393 ${CC} ${CFLAGS} -c ${.PREFIX}.tmp.c -o ${.TARGET}
394 rm -f ${.PREFIX}.tmp.c
399 ${YACC} ${YFLAGS} ${.IMPSRC}
400 mv y.tab.c ${.TARGET}
403 ${LEX} -t ${LFLAGS} ${.IMPSRC} > ${.TARGET}
405 .s.out .c.out .o.out:
406 ${CC} ${CFLAGS} ${LDFLAGS} ${.IMPSRC} ${LDLIBS} -o ${.TARGET}
409 .f.out .F.out .r.out .e.out:
410 ${FC} ${EFLAGS} ${RFLAGS} ${FFLAGS} ${LDFLAGS} ${.IMPSRC} \
411 ${LDLIBS} -o ${.TARGET}
417 ${YACC} ${YFLAGS} ${.IMPSRC}
418 ${CC} ${CFLAGS} ${LDFLAGS} y.tab.c ${LDLIBS} -ly -o ${.TARGET}
423 ${LEX} -t ${LFLAGS} ${.IMPSRC} > ${.PREFIX}.tmp.c
424 ${CC} ${CFLAGS} ${LDFLAGS} ${.PREFIX}.tmp.c ${LDLIBS} -ll -o ${.TARGET}
425 rm -f ${.PREFIX}.tmp.c
428 # Pull in global settings.
429 __MAKE_CONF?=/etc/make.conf
430 .if exists(${__MAKE_CONF})
431 .include "${__MAKE_CONF}"
434 # late include for customization
435 .sinclude <local.sys.mk>
437 .if defined(META_MODE)
438 META_MODE:= ${META_MODE:O:u}
441 .if defined(__MAKE_SHELL) && !empty(__MAKE_SHELL)
442 SHELL= ${__MAKE_SHELL}
443 .SHELL: path=${__MAKE_SHELL}
446 # Tell bmake to expand -V VAR by default
447 .MAKE.EXPAND_VARIABLES= yes
449 # Tell bmake the makefile preference
450 MAKEFILE_PREFERENCE?= BSDmakefile makefile Makefile
451 .MAKE.MAKEFILE_PREFERENCE= ${MAKEFILE_PREFERENCE}
453 # Tell bmake to always pass job tokens, regardless of target depending on
454 # .MAKE or looking like ${MAKE}/${.MAKE}/$(MAKE)/$(.MAKE)/make.
455 .MAKE.ALWAYS_PASS_JOB_QUEUE= yes
457 # By default bmake does *not* use set -e
458 # when running target scripts, this is a problem for many makefiles here.
459 # So define a shell that will do what FreeBSD expects.
460 .ifndef WITHOUT_SHELL_ERRCTL
461 __MAKE_SHELL?=/bin/sh
463 quiet="set -" echo="set -v" filter="set -" \
464 hasErrCtl=yes check="set -e" ignore="set +e" \
465 echoFlag=v errFlag=e \
469 # Hack for ports compatibility. Historically, ports makefiles have
470 # assumed they can examine MACHINE_CPU without including anything
471 # because this was automatically included in sys.mk. For /usr/src,
472 # this file has moved to being included from bsd.opts.mk. Until all
473 # the ports files are modernized, and a reasonable transition
474 # period has passed, include it while we're in a ports tree here
475 # to preserve historic behavior.
476 .if exists(${.CURDIR}/../../Mk/bsd.port.mk)
477 .include <bsd.cpu.mk>