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 .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.
49 META_MODE= meta verbose
50 # silent will hide command output if a .meta file is created.
51 .if !defined(NO_SILENT)
52 META_MODE+= silent=yes
54 .if !exists(/dev/filemon)
60 .MAKE.MODE?= ${META_MODE}
62 .if ${MK_AUTO_OBJ} == "yes"
63 # This needs to be done early - before .PATH is computed
64 # Don't do this for 'make showconfig' as it enables all options where meta mode
67 .sinclude <auto.obj.mk>
71 .include <bsd.mkopt.mk>
74 # If the special target .POSIX appears (without prerequisites or
75 # commands) before the first noncomment line in the makefile, make shall
76 # process the makefile as specified by the Posix 1003.2 specification.
77 # make(1) sets the special macro %POSIX in this case (to the actual
78 # value "1003.2", for what it's worth).
80 # The rules below use this macro to distinguish between Posix-compliant
81 # and default behaviour.
83 # This functionality is currently broken, since make(1) processes sys.mk
84 # before reading any other files, and consequently has no opportunity to
85 # set the %POSIX macro before we read this point.
88 .SUFFIXES: .o .c .y .l .a .sh .f
90 .SUFFIXES: .out .a .ln .o .c .cc .cpp .cxx .C .m .F .f .e .r .y .l .S .asm .s .cl .p .h .sh
113 .if ${MACHINE_CPUARCH} == "arm" || ${MACHINE_CPUARCH} == "mips"
118 .if defined(NO_STRICT_ALIASING)
119 CFLAGS += -fno-strict-aliasing
122 PO_CFLAGS ?= ${CFLAGS}
124 # cp(1) is used to copy source files to ${.OBJDIR}, make sure it can handle
125 # read-only files as non-root by passing -f.
130 # C Type Format data is required for DTrace
131 CTFFLAGS ?= -L VERSION
133 CTFCONVERT ?= ctfconvert
136 .if defined(CFLAGS) && (${CFLAGS:M-g} != "")
141 CXXFLAGS ?= ${CFLAGS:N-std=*:N-Wnested-externs:N-W*-prototypes:N-Wno-pointer-sign:N-Wold-style-definition}
142 PO_CXXFLAGS ?= ${CXXFLAGS}
145 DTRACEFLAGS ?= -C -x nolibs
147 .if empty(.MAKEFLAGS:M-s)
152 .if ${.MAKEFLAGS:M-s} == "-s"
159 .if ${.MAKEFLAGS:M-N}
160 # bmake -N is supposed to skip executing anything but it does not skip
161 # exeucting '+' commands. The '+' feature is used where .MAKE
162 # is not safe for the entire target. -N is intended to skip building sub-makes
163 # so it executing '+' commands is not right. Work around the bug by not
164 # setting '+' when -N is used.
185 LDFLAGS ?= # LDFLAGS is for CC,
186 _LDFLAGS = ${LDFLAGS:S/-Wl,//g} # strip -Wl, for LD
189 LINTFLAGS ?= -cghapbx
190 LINTKERNFLAGS ?= ${LINTFLAGS}
191 LINTOBJFLAGS ?= -cghapbxu -i
192 LINTOBJKERNFLAGS?= ${LINTOBJFLAGS}
193 LINTLIBFLAGS ?= -cghapbxu -C ${LIB}
202 OBJCFLAGS ?= ${OBJCINCLUDES} ${CFLAGS} -Wno-import
230 # Posix 1003.2 mandated rules
232 # Quoted directly from the Posix 1003.2 draft, only the macros
233 # $@, $< and $* have been replaced by ${.TARGET}, ${.IMPSRC}, and
236 # SINGLE SUFFIX RULES
238 ${CC} ${CFLAGS} ${LDFLAGS} -o ${.TARGET} ${.IMPSRC}
241 ${FC} ${FFLAGS} ${LDFLAGS} -o ${.TARGET} ${.IMPSRC}
244 cp -f ${.IMPSRC} ${.TARGET}
247 # DOUBLE SUFFIX RULES
250 ${CC} ${CFLAGS} -c ${.IMPSRC}
253 ${FC} ${FFLAGS} -c ${.IMPSRC}
256 ${YACC} ${YFLAGS} ${.IMPSRC}
257 ${CC} ${CFLAGS} -c y.tab.c
259 mv y.tab.o ${.TARGET}
262 ${LEX} ${LFLAGS} ${.IMPSRC}
263 ${CC} ${CFLAGS} -c lex.yy.c
265 mv lex.yy.o ${.TARGET}
268 ${YACC} ${YFLAGS} ${.IMPSRC}
269 mv y.tab.c ${.TARGET}
272 ${LEX} ${LFLAGS} ${.IMPSRC}
273 mv lex.yy.c ${.TARGET}
276 ${CC} ${CFLAGS} -c ${.IMPSRC}
277 ${AR} ${ARFLAGS} ${.TARGET} ${.PREFIX}.o
281 ${FC} ${FFLAGS} -c ${.IMPSRC}
282 ${AR} ${ARFLAGS} ${.TARGET} ${.PREFIX}.o
290 cp -f ${.IMPSRC} ${.TARGET}
294 ${LINT} ${LINTOBJFLAGS} ${CFLAGS:M-[DIU]*} ${.IMPSRC} || \
297 .cc.ln .C.ln .cpp.ln .cxx.ln:
298 ${LINT} ${LINTOBJFLAGS} ${CXXFLAGS:M-[DIU]*} ${.IMPSRC} || \
302 ${CC} ${CFLAGS} ${LDFLAGS} ${.IMPSRC} ${LDLIBS} -o ${.TARGET}
306 ${CC} ${CFLAGS} -c ${.IMPSRC} -o ${.TARGET}
310 ${CXX} ${CXXFLAGS} ${LDFLAGS} ${.IMPSRC} ${LDLIBS} -o ${.TARGET}
312 .cc.o .cpp.o .cxx.o .C.o:
313 ${CXX} ${CXXFLAGS} -c ${.IMPSRC} -o ${.TARGET}
316 ${OBJC} ${OBJCFLAGS} -c ${.IMPSRC} -o ${.TARGET}
320 ${PC} ${PFLAGS} -c ${.IMPSRC} -o ${.TARGET}
324 ${FC} ${RFLAGS} ${EFLAGS} ${FFLAGS} ${LDFLAGS} ${.IMPSRC} ${LDLIBS} \
328 ${FC} ${RFLAGS} ${EFLAGS} ${FFLAGS} -c ${.IMPSRC} -o ${.TARGET}
331 ${CC:N${CCACHE_BIN}} ${CFLAGS} ${ACFLAGS} -c ${.IMPSRC} -o ${.TARGET}
335 ${CC:N${CCACHE_BIN}} -x assembler-with-cpp ${CFLAGS} ${ACFLAGS} -c ${.IMPSRC} \
340 ${AS} ${AFLAGS} -o ${.TARGET} ${.IMPSRC}
345 ${YACC} ${YFLAGS} ${.IMPSRC}
346 ${CC} ${CFLAGS} -c y.tab.c -o ${.TARGET}
351 ${LEX} -t ${LFLAGS} ${.IMPSRC} > ${.PREFIX}.tmp.c
352 ${CC} ${CFLAGS} -c ${.PREFIX}.tmp.c -o ${.TARGET}
353 rm -f ${.PREFIX}.tmp.c
358 ${YACC} ${YFLAGS} ${.IMPSRC}
359 mv y.tab.c ${.TARGET}
362 ${LEX} -t ${LFLAGS} ${.IMPSRC} > ${.TARGET}
364 .s.out .c.out .o.out:
365 ${CC} ${CFLAGS} ${LDFLAGS} ${.IMPSRC} ${LDLIBS} -o ${.TARGET}
368 .f.out .F.out .r.out .e.out:
369 ${FC} ${EFLAGS} ${RFLAGS} ${FFLAGS} ${LDFLAGS} ${.IMPSRC} \
370 ${LDLIBS} -o ${.TARGET}
376 ${YACC} ${YFLAGS} ${.IMPSRC}
377 ${CC} ${CFLAGS} ${LDFLAGS} y.tab.c ${LDLIBS} -ly -o ${.TARGET}
382 ${LEX} -t ${LFLAGS} ${.IMPSRC} > ${.PREFIX}.tmp.c
383 ${CC} ${CFLAGS} ${LDFLAGS} ${.PREFIX}.tmp.c ${LDLIBS} -ll -o ${.TARGET}
384 rm -f ${.PREFIX}.tmp.c
387 # Pull in global settings.
388 __MAKE_CONF?=/etc/make.conf
389 .if exists(${__MAKE_CONF})
390 .include "${__MAKE_CONF}"
393 # late include for customization
394 .sinclude <local.sys.mk>
396 .if defined(__MAKE_SHELL) && !empty(__MAKE_SHELL)
397 SHELL= ${__MAKE_SHELL}
398 .SHELL: path=${__MAKE_SHELL}
401 # Tell bmake to expand -V VAR by default
402 .MAKE.EXPAND_VARIABLES= yes
404 # Tell bmake the makefile preference
405 .MAKE.MAKEFILE_PREFERENCE= BSDmakefile makefile Makefile
407 # Tell bmake to always pass job tokens, regardless of target depending on
408 # .MAKE or looking like ${MAKE}/${.MAKE}/$(MAKE)/$(.MAKE)/make.
409 .MAKE.ALWAYS_PASS_JOB_QUEUE= yes
411 # By default bmake does *not* use set -e
412 # when running target scripts, this is a problem for many makefiles here.
413 # So define a shell that will do what FreeBSD expects.
414 .ifndef WITHOUT_SHELL_ERRCTL
415 __MAKE_SHELL?=/bin/sh
417 quiet="set -" echo="set -v" filter="set -" \
418 hasErrCtl=yes check="set -e" ignore="set +e" \
419 echoFlag=v errFlag=e \
423 # Hack for ports compatibility. Historically, ports makefiles have
424 # assumed they can examine MACHINE_CPU without including anything
425 # because this was automatically included in sys.mk. For /usr/src,
426 # this file has moved to being included from bsd.opts.mk. Until all
427 # the ports files are modernized, and a reasonable transition
428 # period has passed, include it while we're in a ports tree here
429 # to preserve historic behavior.
430 .if exists(${.CURDIR}/../../Mk/bsd.port.mk)
431 .include <bsd.cpu.mk>