1# from: @(#)sys.mk 8.2 (Berkeley) 3/21/94 2# $FreeBSD: stable/11/share/mk/sys.mk 330424 2018-03-04 23:34:02Z bdrewery $ 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" 53META_MODE+= meta 54.if empty(.MAKEFLAGS:M-s) 55# verbose will show .MAKE.META.PREFIX for each target. 56META_MODE+= verbose 57.endif 58.if !defined(NO_META_MISSING) 59META_MODE+= missing-meta=yes 60.endif 61# silent will hide command output if a .meta file is created. 62.if !defined(NO_SILENT) 63META_MODE+= silent=yes 64.endif 65.if !exists(/dev/filemon) || defined(NO_FILEMON) 66META_MODE+= nofilemon 67.endif 68# Require filemon data with bmake 69.if empty(META_MODE:Mnofilemon) 70META_MODE+= missing-filemon=yes 71.endif 72.endif 73META_MODE?= normal 74.export META_MODE 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+= \ 85 ${__MAKE_SHELL} \ 86 /bin \ 87 /lib \ 88 /rescue \ 89 /sbin \ 90 /usr/bin \ 91 /usr/include \ 92 /usr/lib \ 93 /usr/sbin \ 94 /usr/share \ 95 96.endif 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 101.endif 102 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 106# is not expected. 107.if !make(showconfig) && !make(print-dir) 108.sinclude <auto.obj.mk> 109.endif 110.endif 111.else # bmake 112.include <bsd.mkopt.mk> 113.endif 114 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). 120# 121# The rules below use this macro to distinguish between Posix-compliant 122# and default behaviour. 123# 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. 127 128.if defined(%POSIX) 129.SUFFIXES: .o .c .y .l .a .sh .f 130.else 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 132.endif 133 134AR ?= ar 135.if defined(%POSIX) 136ARFLAGS ?= -rv 137.else 138ARFLAGS ?= -crD 139.endif 140RANLIB ?= ranlib 141.if !defined(%POSIX) 142RANLIBFLAGS ?= -D 143.endif 144 145AS ?= as 146AFLAGS ?= 147ACFLAGS ?= 148 149.if defined(%POSIX) 150CC ?= c89 151CFLAGS ?= -O 152.else 153CC ?= cc 154.if ${MACHINE_CPUARCH} == "arm" || ${MACHINE_CPUARCH} == "mips" 155CFLAGS ?= -O -pipe 156.else 157CFLAGS ?= -O2 -pipe 158.endif 159.if defined(NO_STRICT_ALIASING) 160CFLAGS += -fno-strict-aliasing 161.endif 162.endif 163PO_CFLAGS ?= ${CFLAGS} 164 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. 167CP ?= cp -f 168 169CPP ?= cpp 170 171# C Type Format data is required for DTrace 172CTFFLAGS ?= -L VERSION 173 174CTFCONVERT ?= ctfconvert 175CTFMERGE ?= ctfmerge 176 177.if defined(CFLAGS) && (${CFLAGS:M-g} != "") 178CTFFLAGS += -g 179.endif 180 181CXX ?= c++ 182CXXFLAGS ?= ${CFLAGS:N-std=*:N-Wnested-externs:N-W*-prototypes:N-Wno-pointer-sign:N-Wold-style-definition} 183PO_CXXFLAGS ?= ${CXXFLAGS} 184 185DTRACE ?= dtrace 186DTRACEFLAGS ?= -C -x nolibs 187 188.if empty(.MAKEFLAGS:M-s) 189ECHO ?= echo 190ECHODIR ?= echo 191.else 192ECHO ?= true 193.if ${.MAKEFLAGS:M-s} == "-s" 194ECHODIR ?= echo 195.else 196ECHODIR ?= true 197.endif 198.endif 199 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. 206_+_ ?= 207.else 208_+_ ?= + 209.endif 210 211.if defined(%POSIX) 212FC ?= fort77 213FFLAGS ?= -O 1 214.else 215FC ?= f77 216FFLAGS ?= -O 217.endif 218EFLAGS ?= 219 220INSTALL ?= install 221 222LEX ?= lex 223LFLAGS ?= 224 225LD ?= ld 226LDFLAGS ?= # LDFLAGS is for CC, 227_LDFLAGS = ${LDFLAGS:S/-Wl,//g} # strip -Wl, for LD 228 229LINT ?= lint 230LINTFLAGS ?= -cghapbx 231LINTKERNFLAGS ?= ${LINTFLAGS} 232LINTOBJFLAGS ?= -cghapbxu -i 233LINTOBJKERNFLAGS?= ${LINTOBJFLAGS} 234LINTLIBFLAGS ?= -cghapbxu -C ${LIB} 235 236MAKE ?= make 237 238.if !defined(%POSIX) 239NM ?= nm 240NMFLAGS ?= 241 242OBJC ?= cc 243OBJCFLAGS ?= ${OBJCINCLUDES} ${CFLAGS} -Wno-import 244 245OBJCOPY ?= objcopy 246 247OBJDUMP ?= objdump 248 249PC ?= pc 250PFLAGS ?= 251 252RC ?= f77 253RFLAGS ?= 254.endif 255 256SHELL ?= sh 257 258.if !defined(%POSIX) 259SIZE ?= size 260.endif 261 262YACC ?= yacc 263.if defined(%POSIX) 264YFLAGS ?= 265.else 266YFLAGS ?= -d 267.endif 268 269.if defined(%POSIX) 270 271# Posix 1003.2 mandated rules 272# 273# Quoted directly from the Posix 1003.2 draft, only the macros 274# $@, $< and $* have been replaced by ${.TARGET}, ${.IMPSRC}, and 275# ${.PREFIX}, resp. 276 277# SINGLE SUFFIX RULES 278.c: 279 ${CC} ${CFLAGS} ${LDFLAGS} -o ${.TARGET} ${.IMPSRC} 280 281.f: 282 ${FC} ${FFLAGS} ${LDFLAGS} -o ${.TARGET} ${.IMPSRC} 283 284.sh: 285 cp -f ${.IMPSRC} ${.TARGET} 286 chmod a+x ${.TARGET} 287 288# DOUBLE SUFFIX RULES 289 290.c.o: 291 ${CC} ${CFLAGS} -c ${.IMPSRC} 292 293.f.o: 294 ${FC} ${FFLAGS} -c ${.IMPSRC} 295 296.y.o: 297 ${YACC} ${YFLAGS} ${.IMPSRC} 298 ${CC} ${CFLAGS} -c y.tab.c 299 rm -f y.tab.c 300 mv y.tab.o ${.TARGET} 301 302.l.o: 303 ${LEX} ${LFLAGS} ${.IMPSRC} 304 ${CC} ${CFLAGS} -c lex.yy.c 305 rm -f lex.yy.c 306 mv lex.yy.o ${.TARGET} 307 308.y.c: 309 ${YACC} ${YFLAGS} ${.IMPSRC} 310 mv y.tab.c ${.TARGET} 311 312.l.c: 313 ${LEX} ${LFLAGS} ${.IMPSRC} 314 mv lex.yy.c ${.TARGET} 315 316.c.a: 317 ${CC} ${CFLAGS} -c ${.IMPSRC} 318 ${AR} ${ARFLAGS} ${.TARGET} ${.PREFIX}.o 319 rm -f ${.PREFIX}.o 320 321.f.a: 322 ${FC} ${FFLAGS} -c ${.IMPSRC} 323 ${AR} ${ARFLAGS} ${.TARGET} ${.PREFIX}.o 324 rm -f ${.PREFIX}.o 325 326.else 327 328# non-Posix rule set 329 330.sh: 331 cp -f ${.IMPSRC} ${.TARGET} 332 chmod a+x ${.TARGET} 333 334.c.ln: 335 ${LINT} ${LINTOBJFLAGS} ${CFLAGS:M-[DIU]*} ${.IMPSRC} || \ 336 touch ${.TARGET} 337 338.cc.ln .C.ln .cpp.ln .cxx.ln: 339 ${LINT} ${LINTOBJFLAGS} ${CXXFLAGS:M-[DIU]*} ${.IMPSRC} || \ 340 touch ${.TARGET} 341 342.c: 343 ${CC} ${CFLAGS} ${LDFLAGS} ${.IMPSRC} ${LDLIBS} -o ${.TARGET} 344 ${CTFCONVERT_CMD} 345 346.c.o: 347 ${CC} ${CFLAGS} -c ${.IMPSRC} -o ${.TARGET} 348 ${CTFCONVERT_CMD} 349 350.cc .cpp .cxx .C: 351 ${CXX} ${CXXFLAGS} ${LDFLAGS} ${.IMPSRC} ${LDLIBS} -o ${.TARGET} 352 353.cc.o .cpp.o .cxx.o .C.o: 354 ${CXX} ${CXXFLAGS} -c ${.IMPSRC} -o ${.TARGET} 355 356.m.o: 357 ${OBJC} ${OBJCFLAGS} -c ${.IMPSRC} -o ${.TARGET} 358 ${CTFCONVERT_CMD} 359 360.p.o: 361 ${PC} ${PFLAGS} -c ${.IMPSRC} -o ${.TARGET} 362 ${CTFCONVERT_CMD} 363 364.e .r .F .f: 365 ${FC} ${RFLAGS} ${EFLAGS} ${FFLAGS} ${LDFLAGS} ${.IMPSRC} ${LDLIBS} \ 366 -o ${.TARGET} 367 368.e.o .r.o .F.o .f.o: 369 ${FC} ${RFLAGS} ${EFLAGS} ${FFLAGS} -c ${.IMPSRC} -o ${.TARGET} 370 371.S.o: 372 ${CC:N${CCACHE_BIN}} ${CFLAGS} ${ACFLAGS} -c ${.IMPSRC} -o ${.TARGET} 373 ${CTFCONVERT_CMD} 374 375.asm.o: 376 ${CC:N${CCACHE_BIN}} -x assembler-with-cpp ${CFLAGS} ${ACFLAGS} -c ${.IMPSRC} \ 377 -o ${.TARGET} 378 ${CTFCONVERT_CMD} 379 380.s.o: 381 ${AS} ${AFLAGS} -o ${.TARGET} ${.IMPSRC} 382 ${CTFCONVERT_CMD} 383 384# XXX not -j safe 385.y.o: 386 ${YACC} ${YFLAGS} ${.IMPSRC} 387 ${CC} ${CFLAGS} -c y.tab.c -o ${.TARGET} 388 rm -f y.tab.c 389 ${CTFCONVERT_CMD} 390 391.l.o: 392 ${LEX} -t ${LFLAGS} ${.IMPSRC} > ${.PREFIX}.tmp.c 393 ${CC} ${CFLAGS} -c ${.PREFIX}.tmp.c -o ${.TARGET} 394 rm -f ${.PREFIX}.tmp.c 395 ${CTFCONVERT_CMD} 396 397# XXX not -j safe 398.y.c: 399 ${YACC} ${YFLAGS} ${.IMPSRC} 400 mv y.tab.c ${.TARGET} 401 402.l.c: 403 ${LEX} -t ${LFLAGS} ${.IMPSRC} > ${.TARGET} 404 405.s.out .c.out .o.out: 406 ${CC} ${CFLAGS} ${LDFLAGS} ${.IMPSRC} ${LDLIBS} -o ${.TARGET} 407 ${CTFCONVERT_CMD} 408 409.f.out .F.out .r.out .e.out: 410 ${FC} ${EFLAGS} ${RFLAGS} ${FFLAGS} ${LDFLAGS} ${.IMPSRC} \ 411 ${LDLIBS} -o ${.TARGET} 412 rm -f ${.PREFIX}.o 413 ${CTFCONVERT_CMD} 414 415# XXX not -j safe 416.y.out: 417 ${YACC} ${YFLAGS} ${.IMPSRC} 418 ${CC} ${CFLAGS} ${LDFLAGS} y.tab.c ${LDLIBS} -ly -o ${.TARGET} 419 rm -f y.tab.c 420 ${CTFCONVERT_CMD} 421 422.l.out: 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 426 ${CTFCONVERT_CMD} 427 428# Pull in global settings. 429__MAKE_CONF?=/etc/make.conf 430.if exists(${__MAKE_CONF}) 431.include "${__MAKE_CONF}" 432.endif 433 434# late include for customization 435.sinclude <local.sys.mk> 436 437.if defined(META_MODE) 438META_MODE:= ${META_MODE:O:u} 439.endif 440 441.if defined(__MAKE_SHELL) && !empty(__MAKE_SHELL) 442SHELL= ${__MAKE_SHELL} 443.SHELL: path=${__MAKE_SHELL} 444.endif 445 446# Tell bmake to expand -V VAR by default 447.MAKE.EXPAND_VARIABLES= yes 448 449# Tell bmake the makefile preference 450MAKEFILE_PREFERENCE?= BSDmakefile makefile Makefile 451.MAKE.MAKEFILE_PREFERENCE= ${MAKEFILE_PREFERENCE} 452 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 456 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 462.SHELL: name=sh \ 463 quiet="set -" echo="set -v" filter="set -" \ 464 hasErrCtl=yes check="set -e" ignore="set +e" \ 465 echoFlag=v errFlag=e \ 466 path=${__MAKE_SHELL} 467.endif 468 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> 478.endif 479 480.endif # ! Posix 481