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 .MAKE.MODE= meta verbose
49 .if !exists(/dev/filemon)
50 .MAKE.MODE+= nofilemon
55 .if ${MK_AUTO_OBJ} == "yes"
56 # This needs to be done early - before .PATH is computed
57 # Don't do this for 'make showconfig' as it enables all options where meta mode
60 .sinclude <auto.obj.mk>
64 .include <bsd.mkopt.mk>
67 # If the special target .POSIX appears (without prerequisites or
68 # commands) before the first noncomment line in the makefile, make shall
69 # process the makefile as specified by the Posix 1003.2 specification.
70 # make(1) sets the special macro %POSIX in this case (to the actual
71 # value "1003.2", for what it's worth).
73 # The rules below use this macro to distinguish between Posix-compliant
74 # and default behaviour.
76 # This functionality is currently broken, since make(1) processes sys.mk
77 # before reading any other files, and consequently has no opportunity to
78 # set the %POSIX macro before we read this point.
81 .SUFFIXES: .o .c .y .l .a .sh .f
83 .SUFFIXES: .out .a .ln .o .c .cc .cpp .cxx .C .m .F .f .e .r .y .l .S .asm .s .cl .p .h .sh
106 .if ${MACHINE_CPUARCH} == "arm" || ${MACHINE_CPUARCH} == "mips"
111 .if defined(NO_STRICT_ALIASING)
112 CFLAGS += -fno-strict-aliasing
115 PO_CFLAGS ?= ${CFLAGS}
117 # cp(1) is used to copy source files to ${.OBJDIR}, make sure it can handle
118 # read-only files as non-root by passing -f.
123 # C Type Format data is required for DTrace
124 CTFFLAGS ?= -L VERSION
126 CTFCONVERT ?= ctfconvert
129 .if defined(CFLAGS) && (${CFLAGS:M-g} != "")
134 CXXFLAGS ?= ${CFLAGS:N-std=*:N-Wnested-externs:N-W*-prototypes:N-Wno-pointer-sign:N-Wold-style-definition}
135 PO_CXXFLAGS ?= ${CXXFLAGS}
138 DTRACEFLAGS ?= -C -x nolibs
140 .if empty(.MAKEFLAGS:M-s)
145 .if ${.MAKEFLAGS:M-s} == "-s"
152 .if ${.MAKEFLAGS:M-N}
153 # bmake -N is supposed to skip executing anything but it does not skip
154 # exeucting '+' commands. The '+' feature is used where .MAKE
155 # is not safe for the entire target. -N is intended to skip building sub-makes
156 # so it executing '+' commands is not right. Work around the bug by not
157 # setting '+' when -N is used.
178 LDFLAGS ?= # LDFLAGS is for CC,
179 _LDFLAGS = ${LDFLAGS:S/-Wl,//g} # strip -Wl, for LD
182 LINTFLAGS ?= -cghapbx
183 LINTKERNFLAGS ?= ${LINTFLAGS}
184 LINTOBJFLAGS ?= -cghapbxu -i
185 LINTOBJKERNFLAGS?= ${LINTOBJFLAGS}
186 LINTLIBFLAGS ?= -cghapbxu -C ${LIB}
195 OBJCFLAGS ?= ${OBJCINCLUDES} ${CFLAGS} -Wno-import
223 # Posix 1003.2 mandated rules
225 # Quoted directly from the Posix 1003.2 draft, only the macros
226 # $@, $< and $* have been replaced by ${.TARGET}, ${.IMPSRC}, and
229 # SINGLE SUFFIX RULES
231 ${CC} ${CFLAGS} ${LDFLAGS} -o ${.TARGET} ${.IMPSRC}
234 ${FC} ${FFLAGS} ${LDFLAGS} -o ${.TARGET} ${.IMPSRC}
237 cp -f ${.IMPSRC} ${.TARGET}
240 # DOUBLE SUFFIX RULES
243 ${CC} ${CFLAGS} -c ${.IMPSRC}
246 ${FC} ${FFLAGS} -c ${.IMPSRC}
249 ${YACC} ${YFLAGS} ${.IMPSRC}
250 ${CC} ${CFLAGS} -c y.tab.c
252 mv y.tab.o ${.TARGET}
255 ${LEX} ${LFLAGS} ${.IMPSRC}
256 ${CC} ${CFLAGS} -c lex.yy.c
258 mv lex.yy.o ${.TARGET}
261 ${YACC} ${YFLAGS} ${.IMPSRC}
262 mv y.tab.c ${.TARGET}
265 ${LEX} ${LFLAGS} ${.IMPSRC}
266 mv lex.yy.c ${.TARGET}
269 ${CC} ${CFLAGS} -c ${.IMPSRC}
270 ${AR} ${ARFLAGS} ${.TARGET} ${.PREFIX}.o
274 ${FC} ${FFLAGS} -c ${.IMPSRC}
275 ${AR} ${ARFLAGS} ${.TARGET} ${.PREFIX}.o
283 cp -fp ${.IMPSRC} ${.TARGET}
287 ${LINT} ${LINTOBJFLAGS} ${CFLAGS:M-[DIU]*} ${.IMPSRC} || \
290 .cc.ln .C.ln .cpp.ln .cxx.ln:
291 ${LINT} ${LINTOBJFLAGS} ${CXXFLAGS:M-[DIU]*} ${.IMPSRC} || \
295 ${CC} ${CFLAGS} ${LDFLAGS} ${.IMPSRC} ${LDLIBS} -o ${.TARGET}
299 ${CC} ${CFLAGS} -c ${.IMPSRC} -o ${.TARGET}
303 ${CXX} ${CXXFLAGS} ${LDFLAGS} ${.IMPSRC} ${LDLIBS} -o ${.TARGET}
305 .cc.o .cpp.o .cxx.o .C.o:
306 ${CXX} ${CXXFLAGS} -c ${.IMPSRC} -o ${.TARGET}
309 ${OBJC} ${OBJCFLAGS} -c ${.IMPSRC} -o ${.TARGET}
313 ${PC} ${PFLAGS} -c ${.IMPSRC} -o ${.TARGET}
317 ${FC} ${RFLAGS} ${EFLAGS} ${FFLAGS} ${LDFLAGS} ${.IMPSRC} ${LDLIBS} \
321 ${FC} ${RFLAGS} ${EFLAGS} ${FFLAGS} -c ${.IMPSRC} -o ${.TARGET}
324 ${CC:N${CCACHE_BIN}} ${CFLAGS} ${ACFLAGS} -c ${.IMPSRC} -o ${.TARGET}
328 ${CC:N${CCACHE_BIN}} -x assembler-with-cpp ${CFLAGS} ${ACFLAGS} -c ${.IMPSRC} \
333 ${AS} ${AFLAGS} -o ${.TARGET} ${.IMPSRC}
338 ${YACC} ${YFLAGS} ${.IMPSRC}
339 ${CC} ${CFLAGS} -c y.tab.c -o ${.TARGET}
344 ${LEX} -t ${LFLAGS} ${.IMPSRC} > ${.PREFIX}.tmp.c
345 ${CC} ${CFLAGS} -c ${.PREFIX}.tmp.c -o ${.TARGET}
346 rm -f ${.PREFIX}.tmp.c
351 ${YACC} ${YFLAGS} ${.IMPSRC}
352 mv y.tab.c ${.TARGET}
355 ${LEX} -t ${LFLAGS} ${.IMPSRC} > ${.TARGET}
357 .s.out .c.out .o.out:
358 ${CC} ${CFLAGS} ${LDFLAGS} ${.IMPSRC} ${LDLIBS} -o ${.TARGET}
361 .f.out .F.out .r.out .e.out:
362 ${FC} ${EFLAGS} ${RFLAGS} ${FFLAGS} ${LDFLAGS} ${.IMPSRC} \
363 ${LDLIBS} -o ${.TARGET}
369 ${YACC} ${YFLAGS} ${.IMPSRC}
370 ${CC} ${CFLAGS} ${LDFLAGS} y.tab.c ${LDLIBS} -ly -o ${.TARGET}
375 ${LEX} -t ${LFLAGS} ${.IMPSRC} > ${.PREFIX}.tmp.c
376 ${CC} ${CFLAGS} ${LDFLAGS} ${.PREFIX}.tmp.c ${LDLIBS} -ll -o ${.TARGET}
377 rm -f ${.PREFIX}.tmp.c
380 # Pull in global settings.
381 __MAKE_CONF?=/etc/make.conf
382 .if exists(${__MAKE_CONF})
383 .include "${__MAKE_CONF}"
386 # late include for customization
387 .sinclude <local.sys.mk>
389 .if defined(__MAKE_SHELL) && !empty(__MAKE_SHELL)
390 SHELL= ${__MAKE_SHELL}
391 .SHELL: path=${__MAKE_SHELL}
394 # Tell bmake to expand -V VAR by default
395 .MAKE.EXPAND_VARIABLES= yes
397 # Tell bmake the makefile preference
398 .MAKE.MAKEFILE_PREFERENCE= BSDmakefile makefile Makefile
400 # Tell bmake to always pass job tokens, regardless of target depending on
401 # .MAKE or looking like ${MAKE}/${.MAKE}/$(MAKE)/$(.MAKE)/make.
402 .MAKE.ALWAYS_PASS_JOB_QUEUE= yes
404 # By default bmake does *not* use set -e
405 # when running target scripts, this is a problem for many makefiles here.
406 # So define a shell that will do what FreeBSD expects.
407 .ifndef WITHOUT_SHELL_ERRCTL
408 __MAKE_SHELL?=/bin/sh
410 quiet="set -" echo="set -v" filter="set -" \
411 hasErrCtl=yes check="set -e" ignore="set +e" \
412 echoFlag=v errFlag=e \
416 # Hack for ports compatibility. Historically, ports makefiles have
417 # assumed they can examine MACHINE_CPU without including anything
418 # because this was automatically included in sys.mk. For /usr/src,
419 # this file has moved to being included from bsd.opts.mk. Until all
420 # the ports files are modernized, and a reasonable transition
421 # period has passed, include it while we're in a ports tree here
422 # to preserve historic behavior.
423 .if exists(${.CURDIR}/../../Mk/bsd.port.mk)
424 .include <bsd.cpu.mk>