History log of /freebsd-current/share/mk/bsd.sys.mk
Revision Date Author Comments
# 9bfd3b40 12-May-2024 Kyle Evans <kevans@FreeBSD.org>

Add a build knob for _FORTIFY_SOURCE

In the future, we will Default to _FORTIFY_SOURCE=2 if SSP is enabled,
otherwise default to _FORTIFY_SOURCE=0. For now we default it to 0
unconditionally to ease bisect across older versions without the new
symbols, and we'll put out a call for testing.

include/*.h include their ssp/*.h equivalents as needed based on the
knob. Programs and users are allowed to override FORTIFY_SOURCE in their
Makefiles or src.conf/make.conf to force it off.

Reviewed by: des, markj
Relnotes: yes
Sponsored by: Stormshield
Sponsored by: Klara, Inc.
Differential Revision: https://reviews.freebsd.org/D32308


# 28fc837b 14-Nov-2023 John Baldwin <jhb@FreeBSD.org>

bsd.sys.mk: Disable -Wdangling-reference for GCC 13+

GCC raises this warning for libc++'s istream. It raises false
positives in other cases as well (GCC bugs 109640, 109642, 109671).

Warning from <istream>:

/usr/include/c++/v1/istream:1464:34: error: possibly dangling reference to a temporary [-Werror=dangling-reference]
1464 | const ctype<_CharT>& __ct = std::use_facet<ctype<_CharT> >(__is.getloc());
| ^~~~
/usr/include/c++/v1/istream:1464:71: note: the temporary was destroyed at the end of the full expression 'std::__1::use_facet<ctype<char> >(std::__1::ios_base::getloc() const())'
1464 | const ctype<_CharT>& __ct = std::use_facet<ctype<_CharT> >(__is.getloc());
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~

Reviewed by: imp, emaste
Differential Revision: https://reviews.freebsd.org/D42579


# b45ab4b0 28-Sep-2023 Simon J. Gerraty <sjg@FreeBSD.org>

Move the adding of CFLAGS_LAST to bsd.sys.mk

The point of CFLAGS_LAST is to be the last thing in CFLAGS
so add it last.

For DIRDEPS_BUILD this can best be done via local.dirdeps-build.mk
which is guaranteed to be the last makefile read, but that does nothing
for non-DIRDEPS_BUILD

bsd.sys.mk is close enough to the end.

Reviewed by: obrien
Differential Revision: https://reviews.freebsd.org/D42001


# d0b2dbfa 16-Aug-2023 Warner Losh <imp@FreeBSD.org>

Remove $FreeBSD$: one-line sh pattern

Remove /^\s*#[#!]?\s*\$FreeBSD\$.*$\n/


# d036adc4 28-Jun-2023 John Baldwin <jhb@FreeBSD.org>

bsd.sys.mk: Re-enable -Wunused-but-set-variable for clang 13+.

Reviewed by: dim, emaste
Differential Revision: https://reviews.freebsd.org/D40674


# 39240ddf 28-Jun-2023 John Baldwin <jhb@FreeBSD.org>

bsd.sys.mk: Stop muting -Wunused-but-set-variable for GCC.

Reviewed by: emaste
Differential Revision: https://reviews.freebsd.org/D40662


# ad79b018 20-Jun-2023 John Baldwin <jhb@FreeBSD.org>

bsd.sys.mk: Add NO_WUNUSED_BUT_SET_VARIABLE helper variable.

This is already present in sys/conf/kern.mk and can be used to
selectively disable -Wunused-but-set-variable.

Reviewed by: emaste
Differential Revision: https://reviews.freebsd.org/D40663


# 3dad1c66 25-May-2023 John Baldwin <jhb@FreeBSD.org>

Enable -Wstrict-prototypes for all clang versions at WARNS >= 3.

Previously clang 15+ only enabled it for WARNS >= 5.

PR: 271072 (exp-run)
Reviewed by: emaste
Differential Revision: https://reviews.freebsd.org/D39732


# 7aab8fc5 25-Apr-2023 John Baldwin <jhb@FreeBSD.org>

clang: Enable -Wdeprecated-non-prototype by default.

PR: 270919 (exp-run)
Reviewed by: dim, emaste
Differential Revision: https://reviews.freebsd.org/D39535


# 5ef0969e 18-Apr-2023 Simon J. Gerraty <sjg@FreeBSD.org>

Handle libs that create linker scripts as libs

Eg ncurses creates libncursesw.ald
This is the only example so far, but if we are staging
handle it.

Reviewed by: stevek


# 4e8b87af 16-Jan-2023 Steve Kiernan <stevek@juniper.net>

Handle errors if WARNS is not defined.

One conditional outside of ifdef WARNS did not protect against an
unset WARNS. Default WARNS to 0 in conditional if not defined.

Obtained from: Juniper Networks, Inc.


# cd800d3c 11-Apr-2023 John Baldwin <jhb@FreeBSD.org>

Enable -Warray-parameter for clang.

I fixed many of these previously for GCC 12 and make tinderbox passes
with this enabled.

Differential Revision: https://reviews.freebsd.org/D39378


# d04c8671 19-Feb-2023 Warner Losh <imp@FreeBSD.org>

bsd.sys.mk: Add NO_WSTRICT_PROTOTYPES like in kernel

Also add NO_WSTRICT_PROTOTYPES like we do for the kernel.

Sponsored by: Netflix


# 5c336884 14-Feb-2023 Warner Losh <imp@FreeBSD.org>

arm: Remove armv5 supprt

This can only be true on armv5, so we can GC it.

Sponsored by: Netflix
Reviewed by: fuz@fuz.su, brooks, emaste
Differential Revision: https://reviews.freebsd.org/D38563


# 526f57bf 24-Jul-2022 Dimitry Andric <dim@FreeBSD.org>

Update CWARNFLAGS in bsd.sys.mk and CWARNEXTRA in kern.mk for clang 15.

MFC after: 3 days


# 9134d926 04-Dec-2022 John Baldwin <jhb@FreeBSD.org>

bsd.sys.mk: Add NO_WZERO_LENGTH_BOUNDS helper variable.

This variable expands to -Wno-zero-length-bounds on GCC 10+.

Reviewed by: imp, emaste
Differential Revision: https://reviews.freebsd.org/D37537


# ad96424e 04-Dec-2022 John Baldwin <jhb@FreeBSD.org>

bsd.sys.mk: Add NO_WDANGLING_POINTER helper variable.

This variable expands to -Wno-dangling-pointer on GCC 12+.

Reviewed by: imp, emaste
Differential Revision: https://reviews.freebsd.org/D37532


# 442295c1 30-Nov-2022 John Baldwin <jhb@FreeBSD.org>

Silence GCC warnings when using libc++ headers.

GCC 12 raises warnings about literal operator suffixes not preceded by
'_' in libc++ headers such as <string_view> as it doesn't recognize
libc++ headers being an implementation of the standard.

GCC 12 also warns about clang-specific pragmas in <locale>.

Disabling these warnings globally for all C++ code is not ideal, but
is a better option than patching libc++ headers to ignore these
warnings.

Reviewed by: emaste
Differential Revision: https://reviews.freebsd.org/D37530


# a8f92d24 09-Feb-2022 Ed Maste <emaste@FreeBSD.org>

Enable -Wdate-time warning

This produces an "expansion of date or time macro is not reproducible"
warning or error upon use of __DATE__ or __TIME__.

Provide NO_WDATE_TIME for ports or 3rd party software to opt out.

This is a recommit of 489d7a8528ca, which was reverted (by baf8cbcd97a6)
due to ports build failures.

PR: 267902 [exp-run]
Reviewed by: markj
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D29580


# 0ecb6161 30-Nov-2022 Warner Losh <imp@FreeBSD.org>

clang: Define NO_WDEPRECATED_NON_PROTOTYPE for clang 15

Clang 15 enforces function definitions using the C89 form rather than
the K&R form. While not strictly a prototype (which is only for a
declaration), use the name that mirror's clang's warning name. Much code
in contrib still uses K&R function definitions, so invent this for
compiling there.

Sponsored by: Netflix
Reviewed by: jhb
Differential Revision: https://reviews.freebsd.org/D37515


# 5115511e 22-Nov-2022 John Baldwin <jhb@FreeBSD.org>

Use __freebsd_kprintf__ with GCC 12+ similar to clang.


# 67b07512 03-Oct-2022 John Baldwin <jhb@FreeBSD.org>

bsd.sys.mk: Add NO_WUSE_AFTER_FREE helper variable.

This variable expands to -Wno-use-after-free on GCC 12+.

Reviewed by: imp, emaste
Differential Revision: https://reviews.freebsd.org/D36817


# 409dae26 28-Sep-2022 John Baldwin <jhb@FreeBSD.org>

bsd.sys.mk: Add NO_WARRAY_PARAMETER helper variable.

This variable expands to -Wno-array-parameter on GCC 11+.

Reviewed by: imp, emaste
Differential Revision: https://reviews.freebsd.org/D36756


# 4143e4fb 12-May-2022 Ed Maste <emaste@FreeBSD.org>

Hide -fuse-ld= not supported message for non-build targets

In some build configurations a warning about (an absolute path for)
-fuse-ld= not being supported by GCC was emitted during cleandir or
other non-build make targets.

For these non-build targets COMPILER_TYPE is set to "none" but we
treated the .else case for COMPILER_TYPE==clang as implying gcc.
Check instead for COMPILER_TYPE==gcc.

PR: 263913
Reported by: pstef
Reviewed by: pstef
MFC after: 2 weeks
Sponsored by: The FreeBSD Foundation


# baf8cbcd 20-Feb-2022 Ed Maste <emaste@FreeBSD.org>

Revert "Enable -Wdate-time warning"

This reverts commit 489d7a8528cae1adb7192c2563028e2d028c354b.

The flag leaks into some port builds, causing them to fail. I will
recommit it with some sort of opt-out later on.

Reported by: mi


# 2f6a8424 14-Feb-2022 John Baldwin <jhb@FreeBSD.org>

Disable -Wreturn-type on GCC.

GCC is more pedantic than clang about warning when a function doesn't
handle undefined enum values (see GCC bug 87950). Clang's warning
gives a more pragmatic coverage and should find any real bugs, so
disable the warning for GCC rather than adding __unreachable
annotations to appease GCC.

Reviewed by: imp, emaste
Differential Revision: https://reviews.freebsd.org/D34147


# 489d7a85 09-Feb-2022 Ed Maste <emaste@FreeBSD.org>

Enable -Wdate-time warning

This produces an "expansion of date or time macro is not reproducible"
warning or error upon use of __DATE__ or __TIME__.

Reviewed by: markj
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D29580


# 5f2aca83 08-Feb-2022 Dimitry Andric <dim@FreeBSD.org>

Disable clang 14 warning about bitwise operators in zstd

Parts of zstd, used in openzfs and other places, trigger a new clang 14
-Werror warning:

```
sys/contrib/zstd/lib/decompress/huf_decompress.c:889:25: error: use of bitwise '&' with boolean operands [-Werror,-Wbitwise-instead-of-logical]
(BIT_reloadDStreamFast(&bitD1) == BIT_DStream_unfinished)
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
```

While the warning is benign, it should ideally be fixed upstream and
then vendor-imported, but for now silence it selectively.

MFC after: 3 days


# c227269e 07-Feb-2022 John Baldwin <jhb@FreeBSD.org>

Stop adding -Wredundant-decls to CWARNFLAGS.

clang doesn't implement it, and Linux doesn't enforce it. As a
result, new instances keep cropping up both in FreeBSD's code and in
upstream sources from vendors.

Reviewed by: emaste
Differential Revision: https://reviews.freebsd.org/D34144


# 93d6fa53 13-Sep-2021 John Baldwin <jhb@FreeBSD.org>

Disable -Woverflow errors for i386 for GCC 9.

GCC 9 warns about floating point constants overflowing for i386.

Reviewed by: emaste
Differential Revision: https://reviews.freebsd.org/D26201


# 45feade3 26-Aug-2021 Dimitry Andric <dim@FreeBSD.org>

Add -Wno-error=unused-but-set-variable when building with Clang 13+

This warning triggers many times while building world. Downgrade it to a
warning until all occurrences have been fixed. Once the Clang warnings
have been fixed we should be able to turn it on for GCC as well. See
also f4fed768bba45a406f73ed1491d7e52fd1a8711d which did the same for the
kernel builds.

Reviewed by: arichardson, imp
MFC after: 3 days
Differential Revision: https://reviews.freebsd.org/D31927


# 22b8ab15 29-Aug-2021 Dimitry Andric <dim@FreeBSD.org>

Remove -simplifycfg-dup-ret from CLANG_OPT_SMALL flags for clang 13

After llvm/clang 13.0.0, the -simplifycfg-dup-ret backend flag is no
longer supported. This was part of CLANG_OPT_SMALL, which is only still
used for stand/i386/boot2 and stand/i386/isoboot, to achieve the very
small binary size required. Luckily clang 13.0.0 does not need any
additional flags for this (I get 240 bytes available when building
boot2).

MFC after: 3 days


# c8edd054 24-Aug-2021 Jessica Clarke <jrtc27@FreeBSD.org>

clang: Support building with GCC and DEBUG_FILES disabled

If MK_DEBUG_FILES=no then the Clang link rule has clang as .TARGET,
rather than clang.full, causing the implicit ${CFLAGS.${.TARGET:T}} to
be CFLAGS.clang, and thus pull in flags intended for when your compiler
is Clang, not when linking Clang itself. This doesn't matter if your
compiler is in fact Clang, but it breaks using GCC as, for example,
bsd.sys.mk adds -Qunused-arguments to CFLAGS.clang. This is seen when
trying to build a bootstrap toolchain on Linux where GCC is the system
compiler.

Thus, introduce a new internal NO_TARGET_FLAGS variable that is set by
Clang to disable the addition of these implicit flags. This is a bigger
hammer than necessary, as flags for .o files would be safe, but that is
not needed for Clang.

Note that the same problem does not arise for LDFLAGS when building LLD
with BFD, since our build produces a program called ld.lld, not plain
lld (unlike upstream, where ld.lld is a symlink to lld so they can
support multiple different flavours in one binary).

Suggested by: sjg
Fixes: 31ba4ce8898f ("Allow bootstrapping llvm-tblgen on macOS and Linux")
MFC after: 1 week
Reviewed by: dim, imp, emaste
Differential Revision: https://reviews.freebsd.org/D31532


# 47363e99 07-Aug-2021 Ed Maste <emaste@FreeBSD.org>

Enable compressed debug on little-endian targets

Compressed debug was enabled by default in commit c910570e7573, but
broke the build on big-endian targets, and so was disabled in
89ed2ecb14ce.

Older versions of LLD fail with big-endian compressed debug sections.
This was fixed in LLD upstream (commit c6ebc651b6fa) and merged to
FreeBSD main (commit d69d07569ee2) by dim.

External toolchains (e.g. the llvm12 package) will not yet have the fix.
These may be used to link against base system .a archives, so compressed
debug sections would cause trouble even though the base system is fixed.

Enable compressed debug sections again, for little-endian targets only.
As discussed on freebsd-hackers[1] I expect to undo this in the future
(using compressed debug everywhere), once fixed versions of lld are
widely available.

Note that to be pedantically correct we should check both the compiler
and the linker for compressed debug support, but given the external
toolchain constraint the extra complexity does not seem worthwhile.

[1] https://lists.freebsd.org/archives/freebsd-hackers/2021-August/000188.html

PR: 257638
Reported by: jrtc27 [impact of .a archives]
Discussed with: imp
Relnotes: Yes
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D31454

Revert "Disable compressed debug by default"

This reverts commit 89ed2ecb14ceabc27883282cf96559a9e7d52717.


# 89ed2ecb 05-Aug-2021 Ed Maste <emaste@FreeBSD.org>

Disable compressed debug by default

In c910570e7573 I enabled compressed debug sections, but it broke mips
and powerpc. Disable it for now.

Reported by: jenkins, manu
Sponsored by: The FreeBSD Foundation


# c910570e 28-Feb-2021 Ed Maste <emaste@FreeBSD.org>

Use compressed debug in standalone userland debug files by default

The compiler supports CFLAGS=-gz=zlib to compress .debug sections in
object files, libraries, and binaries. Enable it to reduce disk usage
for standalone debug files (and /usr/obj).

Reviewed by: dim, kevans
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D29002


# 1b8db4b4 04-Aug-2021 Mitchell Horne <mhorne@FreeBSD.org>

arm: enable stack-smashing protection

With current generation clang/llvm it can pass all of our tests in
libc/ssp.

While here, remove the extra MACHINE_CPUARCH check for mips. SSP is
included in BROKEN_OPTIONS for this architecture in src.opts.mk, which
is enough to ensure normal builds won't set SSP_CFLAGS.

Reviewed by: kevans, imp, emaste
MFC after: 2 weeks
Differential Revision: https://reviews.freebsd.org/D31400


# c8c62548 22-Mar-2021 Alex Richardson <arichardson@FreeBSD.org>

Don't add -Winline for WARNS=6

This warning is very rarely useful (inline is a hint and not mandatory).
This flag results in many warnings being printed when compiling C++
code that uses the standard library with GCC.

This flag was originally added in back in r94332 but the flag is a no-op
in Clang ("This diagnostic flag exists for GCC compatibility, and has no
effect in Clang"). Removing it should make the GCC build output slightly
more readable.

Reviewed By: jrtc27, imp
Differential Revision: https://reviews.freebsd.org/D29235


# 172a624f 04-Mar-2021 Alex Richardson <arichardson@FreeBSD.org>

Silence annoying and incorrect non-default linker warning with GCC

The CROSS_TOOLCHAIN GCC .mk files include -B${CROSS_BINUTILS_PREFIX}, so
GCC will select the right linker and we don't need to warn.
While here also apply 17b8b8fb5fc4acc832dabfe7ef11e3e1d399ad0f to kern.mk.

Test Plan: no more warning printed with CROSS_TOOLCHAIN=mips-gcc6
Reviewed By: jhb
Differential Revision: https://reviews.freebsd.org/D29015


# 7fa2f2a6 06-Jan-2021 Alex Richardson <Alexander.Richardson@cl.cam.ac.uk>

Rename NO_WERROR -> MK_WERROR=no

As suggested in D27598. This also supports MK_WERROR.clang=no and
MK_WERROR.gcc=no to support the existing NO_WERROR.<compiler> uses.

Reviewed By: brooks
Differential Revision: https://reviews.freebsd.org/D27601


# 78380908 29-Sep-2020 Brooks Davis <brooks@FreeBSD.org>

Hoist comment on fixup of ld path

Reported by: jrtc27
Differential Revision: https://reviews.freebsd.org/D26591


# 17b8b8fb 29-Sep-2020 Brooks Davis <brooks@FreeBSD.org>

Prefer --ld-path=/path/to/ld on clang >= 12

Clang 12 warns about passing a path to -fuse-ld and -Werror makes that
an error preventing building world without this change.

Reviewed by: arichardson, emaste
Sponsored by: DARPA
Differential Revision: https://reviews.freebsd.org/D26591


# fe815331 18-Sep-2020 Kyle Evans <kevans@FreeBSD.org>

build: provide a default WARNS for all in-tree builds

The current default is provided in various Makefile.inc in some top-level
directories and covers a good portion of the tree, but doesn't cover parts
of the build a little deeper (e.g. libcasper).

Provide a default in src.sys.mk and set WARNS to it in bsd.sys.mk if that
variable is defined. This lets us relatively cleanly provide a default WARNS
no matter where you're building in the src tree without breaking things
outside of the tree.

Crunchgen has been updated as a bootstrap tool to work on this change
because it needs r365605 at a minimum to succeed. The cleanup necessary to
successfully walk over this change on WITHOUT_CLEAN builds has been added.

There is a supplemental project to this to list all of the warnings that are
encountered when the environment has WARNS=6 NO_WERROR=yes:
https://warns.kevans.dev -- this project will hopefully eventually go away
in favor of CI doing a much better job than it.

Reviewed by: emaste, brooks, ngie (all earlier version)
Reviewed by: emaste, arichardson (depend-cleanup.sh change)
Differential Revision: https://reviews.freebsd.org/D26455


# 2a6803de 14-Sep-2020 Andrew Turner <andrew@FreeBSD.org>

Use MACHINE_CPUARCH when checking for arm64

Use MACHINE_CPUARCH with arm64 (aarch64) when we build code that could run
on any 64-bit Arm instruction set. This will simplify checks in downstream
consumers targeting prototype instruction sets.

The only place we check for MACHINE_ARCH == aarch64 is when building the
device tree blobs. As these are targeting current generation ISAs.

Sponsored by: Innovate UK
Differential Revision: https://reviews.freebsd.org/D26370


# 73fd212c 31-Aug-2020 John Baldwin <jhb@FreeBSD.org>

Suppress -Wempty-body warnings in GCC 6.x and later.

libc++ in LLVM 11 uses an empty else clause in
include/c++/v1/__thread_support which triggers this warning.

Reviewed by: dim, emaste
MFC after: 2 weeks
Differential Revision: https://reviews.freebsd.org/D26257


# 2d6bee8f 26-Aug-2020 Alex Richardson <arichardson@FreeBSD.org>

Fix builds that set LD=ld.lld after r364761

When using relative paths for the linker we have to transform the name
since clang does not like -fuse-ld=ld.lld and instead requires -fuse-ld=lld
(the same also applies for ld.bfd).


# 2b6ee34c 25-Aug-2020 Alex Richardson <arichardson@FreeBSD.org>

Pass -fuse-ld=/path/to/ld if ${LD} != "ld"

This is needed so that setting LD/XLD is not ignored when linking with $CC
instead of directly using $LD. Currently only clang accepts an absolute
path for -fuse-ld= (Clang 12+ will add a new --ld-path flag), so we now
warn when building with GCC and $LD != "ld" since that might result in the
wrong linker being used.

We have been setting XLD=/path/to/cheri/ld.lld in CheriBSD for a long time and
used a similar version of this patch to avoid linking with /usr/bin/ld.
This change is also required when building FreeBSD on an Ubuntu with Clang:
In that case we set XCC=/usr/lib/llvm-10/bin/clang and since
/usr/lib/llvm-10/bin/ does not contain a "ld" binary the build fails with
`clang: error: unable to execute command: Executable "ld" doesn't exist!`
unless we pass -fuse-ld=/usr/lib/llvm-10/bin/ld.lld.

This change passes -fuse-ld instead of copying ${XLD} to WOLRDTMP/bin/ld
since then we would have to ensure that this file does not exist while
building the bootstrap tools. The cross-linker might not be compatible with
the host linker (e.g. when building on macos: host-linker= Mach-O /usr/bin/ld,
cross-linker=LLVM ld.lld).

Reviewed By: brooks, emaste
Differential Revision: https://reviews.freebsd.org/D26055


# 776b260a 04-Aug-2020 John Baldwin <jhb@FreeBSD.org>

Disable errors for -Wsystem-headers for GCC on aarch64.

GCC's own arm_neon.h triggers multiple warnings on both GCC 6 and
GCC 9.

Differential Revision: https://reviews.freebsd.org/D25729


# 0ea6e510 04-Aug-2020 John Baldwin <jhb@FreeBSD.org>

Disable errors for -Wredundant-decls for GCC 6+.

GCC triggers warnings for this that clang does not for duplicate
declarations of yylex().

Differential Revision: https://reviews.freebsd.org/D25727


# a02fb762 04-Aug-2020 John Baldwin <jhb@FreeBSD.org>

Turn off errors for -Wmaybe-uninitialized in GCC 6+.

Recent changes to <sys/tree.h> trigger this warning and seem like a
false positive.

Differential Revision: https://reviews.freebsd.org/D25726


# 824214da 28-May-2020 Eric van Gyzen <vangyzen@FreeBSD.org>

Revert part of r360964

ports/devel/linux_libusb builds FreeBSD libusb with GCC 4.8.5
from devel/linux-c7-devtools. Restore the tests for older GCC
in bsd.sys.mk to accomodate such ports.

Reported by: tijl
Sponsored by: Dell EMC Isilon


# fac6dee9 12-May-2020 Eric van Gyzen <vangyzen@FreeBSD.org>

Remove tests for obsolete compilers in the build system

Assume gcc is at least 6.4, the oldest xtoolchain in the ports tree.
Assume clang is at least 6, which was in 11.2-RELEASE. Drop conditions
for older compilers.

Reviewed by: imp (earlier version), emaste, jhb
MFC after: 2 weeks
Sponsored by: Dell EMC Isilon
Differential Revision: https://reviews.freebsd.org/D24802


# cddd13a4 07-Apr-2020 Kyle Evans <kevans@FreeBSD.org>

Fix port/kernel builds after r359681

Submitted by: bdrewery
Reported by: bdrewery, sobomax, antoine


# f382bac4 06-Apr-2020 Brooks Davis <brooks@FreeBSD.org>

Fix compilation with upstream clang builtin headers.

By using -nobuiltininc and adding the clang builtin headers resource dir
to the end of the compiler header search path, we can still find headers
such as immintrin.h but find the FreeBSD version of stddef.h/stdarg.h/..
first.

This is a workaround until we are able to settle on and complete a plan
to harmonize guard macros with LLVM. We've mostly worked out this on
FreeBSD systems by removing select headers from the installed set of
devel/llvm*, but that isn't a good solution for cross build.

Submitted by: arichardson
Obtained from: CheriBSD
Sponsored by: DARPA, AFRL
Differential Revision: https://reviews.freebsd.org/D17002


# 47e9f42e 26-Feb-2020 Warner Losh <imp@FreeBSD.org>

Remove sparc64 specific buid-system hacks

Remove all the sparc64 hacks and tweaks to the build system. We don't
need them anymore.


# 533a4a62 31-Jan-2020 Dimitry Andric <dim@FreeBSD.org>

Disable new clang 10.0.0 warnings about misleading indentation in flex.

As this is contributed code with very messy indentation, which will
almost certainly never be upgraded, just disable the warning.

MFC after: 3 days


# fc41af14 20-Dec-2019 Ryan Libby <rlibby@FreeBSD.org>

gcc9: quiet Waddress-of-packed-member for user build

Disable the warning for WARNS <= 3. This is lame, but it's what we
already do for the clang build.

Reviewed by: dim
Sponsored by: Dell EMC Isilon
Differential Revision: https://reviews.freebsd.org/D22889


# 23e2b4d9 14-Sep-2019 Dimitry Andric <dim@FreeBSD.org>

Instead of disabling gcc's deprecated declaration warnings about e.g.
std::auto_ptr in a whole bunch of individual Makefiles, make the warning
globally non-fatal instead. This is similar to what was done to many
more non-fatal warnings from newer gcc versions.


# 6c30aa54 01-Sep-2019 Ed Maste <emaste@FreeBSD.org>

Remove CLANG_NO_IAS definition

CLANG_NO_IAS is not used anywhere in the tree.

Sponsored by: The FreeBSD Foundation


# 7574e857 23-Aug-2019 Warner Losh <imp@FreeBSD.org>

Turn off -Werror for gcc 4.2.1 for userland

As discussed on arch@, gcc 4.2.1 is on its way out. Turn off Werror on gcc
versions < 5.0 permantly. This will allow older platforms to continue to compile
w/o new errors once we take them out of universe by default. This will also free
developers from chasing down obsolete warnings that produce no beneficial
changes to the source.

Discussed on: arch@
Reviewed by: jhb@, emaste@, pfg@
Differential Revision: https://reviews.freebsd.org/D21378


# 47fec6f3 07-Aug-2019 Conrad Meyer <cem@FreeBSD.org>

r350739 try #2

For some inexplicable reason, C++ compilers reject the -Wno- flag, and also
(ab)use CWARNFLAGS.

Reported by: imp


# be3ab187 07-Aug-2019 Conrad Meyer <cem@FreeBSD.org>

Disable useless -Wformat-zero-length

It is part of -Wformat, which is enabled by -Wall. Empty format strings are
well defined and it is perfectly reasonable to expect them in a formatting
interface.


# 6b184f62 30-Jul-2019 Alan Somers <asomers@FreeBSD.org>

Add a CXXWARNFLAGS variable

Some warning flags are valid for C++ but not C. GCC 8 complains if you pass
such flags when building a C file. Using a separate variable for these
flags allows building both C and C++ files in the same directory (such as
the fusefs tests) under GCC.

Reviewed by: cem, emaste
MFC after: 2 weeks
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D21116


# 3b53f994 04-Jul-2019 Bryan Drewery <bdrewery@FreeBSD.org>

Consider *clean targets as non-build targets as well.

MFC after: 2 weeks
Sponsored by: DellEMC


# 8e0c3739 19-Jun-2019 Bryan Drewery <bdrewery@FreeBSD.org>

Follow-up r349065: Fix .TARGET flag ambiguity with PROGS which broke MK_TESTS.

X-MFC-With: r349065
Sponsored by: DellEMC


# 48da57b4 15-Jun-2019 Bryan Drewery <bdrewery@FreeBSD.org>

Add various CFLAGS/LDADD overrides for the output target file.

Sponsored by: DellEMC


# db933d76 22-Apr-2019 Enji Cooper <ngie@FreeBSD.org>

Fix up CXXSTD support originally added in r345708

r345708 worked for the base system, but unfortunately, caused a lot of
disruption for third-party packages that relied on C++, since bsd.sys.mk is
used by applications outside the base system. The defaults picked didn't match
the compiler's defaults and broke some builds that didn't specify a standard,
as well as some that overrode the value by setting `-std=gnu++14` (for
example) manually.

This change takes a more relaxed approach to appending `-std=${CXXSTD}` to
CXXFLAGS, by only doing so when the value is specified, as opposed to
overriding the standard set by an end-user. This avoids the need for having
to bake NOP default into bsd.sys.mk for supported compiler-toolchain
versions.

In order to make this change possible, add CXXSTD to Makefile snippets which
relied on the default value (c++11) added in r345708.

MFC after: 2 weeks
MFC with: r345708, r346574
Reviewed by: emaste
Reported by: jbeich
Differential Revision: https://reviews.freebsd.org/D19895 (as part of a larger change)


# e8067928 29-Mar-2019 Enji Cooper <ngie@FreeBSD.org>

Standardize `-std=c++* as `CXXSTD`

CXXSTD was added as the C++ analogue to CSTD.

CXXSTD defaults to `-std=c++11` with supporting compilers; `-std=gnu++98`,
otherwise for older versions of g++.

This change standardizes the CXXSTD variable, originally added to
googletest.test.inc.mk as part of r345203.

As part of this effort, convert all `CXXFLAGS+= -std=*` calls to use `CXXSTD`.

Notes:

This value is not sanity checked in bsd.sys.mk, however, given the two
most used C++ compilers on FreeBSD (clang++ and g++) support both modes, it is
likely to work with both toolchains. This method will be refined in the future
to support more variants of C++, as not all versions of clang++ and g++ (for
instance) support C++14, C++17, etc.

Any manual appending of `-std=*` to `CXXFLAGS` should be replaced with CXXSTD.
Example:

Before this commit:
```
CXXFLAGS+= -std=c++14
```

After this commit:
```
CXXSTD= c++14
```

Reviewed by: asomers
Approved by: emaste (mentor)
MFC after: 1 month
MFC with: r345203, r345704, r345705
Relnotes: yes
Tested with: make tinderbox
Differential Revision: https://reviews.freebsd.org/D19732


# bdbf3440 29-Mar-2019 Enji Cooper <ngie@FreeBSD.org>

Revert r345706: the third time will be the charm

When a review is closed via Phabricator it updates the patch attached to the
review. I downloaded the raw patch from Phabricator, applied it, and repeated
my mistake from r345704 by accident mixing content from D19732 and D19738.

For my own personal sanity, I will try not to mix reviews like this in the
future.

MFC after: 1 month
MFC with: r345706
Approved by: emaste (mentor, implicit)


# 760b1a81 29-Mar-2019 Enji Cooper <ngie@FreeBSD.org>

Standardize `-std=c++* as `CXXSTD`

CXXSTD was added as the C++ analogue to CSTD.

CXXSTD defaults to `-std=c++11` with supporting compilers; `-std=gnu++98`,
otherwise for older versions of g++.

This change standardizes the CXXSTD variable, originally added to
googletest.test.inc.mk as part of r345203.

As part of this effort, convert all `CXXFLAGS+= -std=*` calls to use `CXXSTD`.

Notes:

This value is not sanity checked in bsd.sys.mk, however, given the two
most used C++ compilers on FreeBSD (clang++ and g++) support both modes, it is
likely to work with both toolchains. This method will be refined in the future
to support more variants of C++, as not all versions of clang++ and g++ (for
instance) support C++14, C++17, etc.

Any manual appending of `-std=*` to `CXXFLAGS` should be replaced with CXXSTD.
Example:

Before this commit:
```
CXXFLAGS+= -std=c++14
```

After this commit:
```
CXXSTD= c++14
```

Reviewed by: asomers
Approved by: emaste (mentor)
MFC after: 1 month
MFC with: r345203, r345704, r345705
Relnotes: yes
Tested with: make tinderbox
Differential Revision: https://reviews.freebsd.org/D19732


# 752cabaa 29-Mar-2019 Enji Cooper <ngie@FreeBSD.org>

Revert r345704

I accidentally committed code from two reviews. I will reintroduce the code to
bsd.progs.mk as part of a separate commit from r345704.

Approved by: emaste (mentor, implicit)
MFC after: 2 months
MFC with: r345704


# 9a41926b 29-Mar-2019 Enji Cooper <ngie@FreeBSD.org>

CXXSTD is the C++ analogue to CSTD.

CXXSTD defaults to `-std=c++11` with supporting compilers; `-std=gnu++98`,
otherwise for older versions of g++.

This change standardizes the CXXSTD variable, originally added to
googletest.test.inc.mk as part of r345203.

As part of this effort, convert all `CXXFLAGS+= -std=*` calls to use `CXXSTD`.

Notes:

This value is not sanity checked in bsd.sys.mk, however, given the two
most used C++ compilers on FreeBSD (clang++ and g++) support both modes, it is
likely to work with both toolchains. This method will be refined in the future
to support more variants of C++, as not all versions of clang++ and g++ (for
instance) support C++14, C++17, etc.

Any manual appending of `-std=*` to `CXXFLAGS` should be replaced with CXXSTD.
Example:

Before this commit:
```
CXXFLAGS+= -std=c++14
```

After this commit:
```
CXXSTD= c++14
```

Reviewed by: asomers
Approved by: emaste (mentor)
MFC after: 1 month
Relnotes: yes
Differential Revision: https://reviews.freebsd.org/D19732


# c6552846 17-Sep-2018 Bryan Drewery <bdrewery@FreeBSD.org>

DIRS: installdirs should also be .PHONY

Sponsored by: Dell EMC
Approved by: re (gjb, kib)


# 767e12d0 05-Aug-2018 Dimitry Andric <dim@FreeBSD.org>

Disable the new clang 7.0.0 -Watomic-alignment warning ("misaligned or
large atomic operation may incur significant performance penalty" ) for
arm before armv6. Since on these older architectures atomic operations
are always translated to libcalls, and this is expected, the warning is
not really useful there.


# a6589ab7 02-Aug-2018 Simon J. Gerraty <sjg@FreeBSD.org>

Update dirdeps.mk et al to latest

dirdeps.mk and meta.autodep.mk will now look for
Makefile.depend.options
to handle optional dependencies, the work is all done by
dirdeps-options.mk

Also update to latest meta.stage.mk and gendirdeps.mk

Reviewed by: bdrewery
Differential Revision: https://reviews.freebsd.org/D15701


# f324fafc 27-Jul-2018 Eitan Adler <eadler@FreeBSD.org>

Feex a cuple of small typos


# 27c2ac11 18-Jul-2018 Ruslan Bukin <br@FreeBSD.org>

Add a GCC 7.1.0 no-error warning flag.

This is required to build libdevdctl.

Note this flag is not required for GCC 8.1.0.

Sponsored by: DARPA, AFRL


# c26e80e1 18-Jul-2018 Ruslan Bukin <br@FreeBSD.org>

Add a GCC 8.1 warning flag.

This is required to build ATF.

Sponsored by: DARPA, AFRL


# f41c578f 03-Jul-2018 Ruslan Bukin <br@FreeBSD.org>

Add GCC 8.1.0 compiler warning flags.

Sponsored by: DARPA, AFRL


# a8db1fa1 04-Jun-2018 Ruslan Bukin <br@FreeBSD.org>

Sort GCC warning flags and remove duplicates.

Sponsored by: DARPA, AFRL


# 12db4047 23-May-2018 Ed Maste <emaste@FreeBSD.org>

Revert r334081 (-Wmain) as it broke the build on gcc architectures


# 9a6efe4a 23-May-2018 Eitan Adler <eadler@FreeBSD.org>

bsd.sys.mk: add -Wmain to WARNS=1

Even in very low "WARNS" conditions, 'main' ought to be reasonable.


# 5d1ee539 23-May-2018 Eitan Adler <eadler@FreeBSD.org>

bsd.sys.mk: add links and update a bit

- add links to more modern resources
- remove 'k&r' which is unused in FreeBSD
- remove stray comment


# b25a46f7 19-Apr-2018 Ed Maste <emaste@FreeBSD.org>

Add support for linker-type-specific flags

r332090 added a LINKER_TYPE test to add the --no-rosegment flag when
linking the i386 loader components with lld. Instead, introduce a
general mechanism for setting LDFLAGS for a specific linker type,
and use it for --no-rosegment.

Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D14998


# 875b18b5 02-Feb-2018 Alex Richardson <arichardson@FreeBSD.org>

Revert r326375 since the warning has been turned off by default in clang

See https://reviews.llvm.org/D41512 and https://reviews.llvm.org/rL322901

Approved By: brooks (mentor)

Differential Revision: https://reviews.freebsd.org/D14171


# dd5c0d9d 24-Dec-2017 Dimitry Andric <dim@FreeBSD.org>

Follow-up to r326375, by moving the block that disables errors on the
new clang 6.0.0 -Wtautological-constant-compare warning to the WARNS <=
6 level. (This warning is still being worked on upstream to reduce
false positives, but it is currently still too trigger happy.)


# 97a4e589 29-Nov-2017 Alex Richardson <arichardson@FreeBSD.org>

Don't fail the build due to clang integer constant range warnings

This warning checks whether a constant is out of range of the integer
type. An example is `comparison of 'u_int' > 4294967295 is always false`
and in this case the warning makes sense.
However, when the type is a typedef that can be either 64 or 32 bits the
if condition is only tautological in some configurations so this should
not be a warning that fails the build.

Reviewed by: dim
Approved by: jhb (mentor)
Differential Revision: https://reviews.freebsd.org/D12912


# edaa206d 13-Sep-2017 Ryan Libby <rlibby@FreeBSD.org>

gcc builds: reenable -Wstrict-overflow for bsd.sys.mk

This effectively reverts r304877, after having relegated the warning
suppression to the zic(8) makefile in r323572.

Reviewed by: emaste
Sponsored by: Dell EMC Isilon
X-Differential Revision: https://reviews.freebsd.org/D12284


# de6feefd 23-Aug-2017 John Baldwin <jhb@FreeBSD.org>

Improve the coverage of debug symbols for MK_DEBUG_FILES.

- Include debug symbols in static libraries. This permits binaries
to include debug symbols for functions obtained from static libraries.
- Permit the C/C++ compiler flags added for MK_DEBUG_FILES to be
overridden by setting DEBUG_FILES_CFLAGS. Use this to limit the debug
information for llvm libraries and binaries.

Reviewed by: emaste
Sponsored by: DARPA / AFRL
Differential Revision: https://reviews.freebsd.org/D12025


# 1ec31f2c 21-Jul-2017 Ruslan Bukin <br@FreeBSD.org>

Add warning flags for GCC 7.1.0 compiler.

Sponsored by: DARPA, AFRL


# e6e7c786 08-Jan-2017 Dimitry Andric <dim@FreeBSD.org>

Disable -Waddress-of-packed-member for WARNS <= 3.


# a45fc83c 05-Jan-2017 Dimitry Andric <dim@FreeBSD.org>

Disable the new -Waddress-of-packed-member warning for WARNS <= 1.


# df5b485a 12-Nov-2016 Bryan Drewery <bdrewery@FreeBSD.org>

Fix 'rebuild during install' error to only trigger on 'make install'.

This allows 'make foo install' or 'make all install'. It is a similar
fix as r304697 did for reading dependency files.

MFC after: 2 weeks
Sponsored by: Dell EMC Isilon


# 73c6c5f7 30-Aug-2016 Dimitry Andric <dim@FreeBSD.org>

Revert r304954, which is no longer needed.


# 241fb95d 28-Aug-2016 Dimitry Andric <dim@FreeBSD.org>

Squelch -Wconstant-conversion for WARNS <= 2. In clang 3.9.0, this
warning has become more aggressive, and it usually turns up in decades
old code, where fixing it is more trouble than it is worth.


# f05ca6f3 26-Aug-2016 Baptiste Daroussin <bapt@FreeBSD.org>

Remove warning on struct-overflow on gcc 5.3.0 as zic(8) dies on it


# 9346408d 28-Jul-2016 Ruslan Bukin <br@FreeBSD.org>

Normalise the CWARNFLAGS inter-word spacing: remove all leading
and trailing space, and convert multiple consecutive spaces to
single space.

This helps to keep build output looking good.


# 8500b15f 24-Jul-2016 Ruslan Bukin <br@FreeBSD.org>

Fix style.


# b6f02827 22-Jul-2016 Ruslan Bukin <br@FreeBSD.org>

Add warn flags for GCC 6.1 compiler.

Sponsored by: DARPA, AFRL


# b38eb9ea 22-Jun-2016 Bryan Drewery <bdrewery@FreeBSD.org>

Add AFLAGS.IMPSRC and document A[C]FLAGS

Approved by: re (gjb)
Sponsored by: EMC / Isilon Storage Division


# f661dbee 29-May-2016 Bryan Drewery <bdrewery@FreeBSD.org>

GCC External: Revert r300886, r300904, r300917, r300918

The fix in r300873 is mostly enough. A fix for lib32 will be
committed.separately.


# 727dd78a 28-May-2016 Bryan Drewery <bdrewery@FreeBSD.org>

External GCC: Ensure our libstdc++ symlink to libc++ is found.

Similar to r300917, the search path for our symlink hack must come
before the =/usr/lib search path.

This fixes the atf-check build after r300886.


# c3c41672 28-May-2016 Bryan Drewery <bdrewery@FreeBSD.org>

GCC XCC -isystem hack: Ensure CXX search =/usr/include/c++1/v1 first.

The C++ header files must be searched before /usr/include.

The original code in Makefile.inc1 did this before the change in r297271 to
use -isystem. The libc++ import in r300770 fixed the bug introduced in
r297271 by swapping XCFLAGS and XCXXFLAGS ordering in CROSSENV.

Moving the code from Makefile.inc1 to bsd.sys.mk in r300886 also made it
more difficult to control the order of the flags. CXXFLAGS is based on
CFLAGS, so any additions to it will come after CFLAGS. The CROSSENV
code from Makefile.inc1 was such that it was ensured the CXXFLAGS came
first by setting them directly in CXX. Using CXXFLAGS+=-I would work
here, but instead continue to use -isystem by adding it to CXX so it
comes before CFLAGS.

Reported by: dim


# ce00342b 27-May-2016 Bryan Drewery <bdrewery@FreeBSD.org>

Move external GCC compiler hacks to bsd.sys.mk.

This allows respecting -nostdinc, -nostdinc++ and -nostdlib before
making the decision to add in -isystem, etc. The -isystem flags
are problematic for building lib/libc++ and lib/libcxxrt which wants
to only use its own headers.

More information the need of these flags can be found at
https://gcc.gnu.org/ml/gcc/2016-03/msg00219.html

This also reverts r300873.

Sponsored by: EMC / Isilon Storage Division


# 4a70acf1 21-Apr-2016 Bryan Drewery <bdrewery@FreeBSD.org>

Follow-up r298219: Don't error with 'make all install'.

Reported by: kib
Sponsored by: EMC / Isilon Storage Division


# 29fbb807 18-Apr-2016 Bryan Drewery <bdrewery@FreeBSD.org>

Cause an error during 'make install' if trying to compile with CC.

This is limited to src-tree builds, meaning not extended to ports or other
out-of-tree builds.

This will help ensure that read-only OBJDIRS will be respected at install-time
by causing a more consistent failure for those who don't use a read-only
OBJDIR. It also will cause Jenkins to yell. This is a better solution than
trying to see CC=false as has been attempted and discussed before.

Of course this is only relevant for files generated by CC.

Disable this for META_MODE since it will detect the CFLAGS/command
change and force a rebuild.

Sponsored by: EMC / Isilon Storage Division


# 94086cea 14-Apr-2016 Bryan Drewery <bdrewery@FreeBSD.org>

Rework META_TARGETS so that it automatically adds META_DEPS to the targets.

This will only be done if the target is defined, so if the target is
defined after bsd.sys.mk is included then it needs to manually add
${META_DEPS} still.

Sponsored by: EMC / Isilon Storage Division


# 59f6130d 25-Mar-2016 Bryan Drewery <bdrewery@FreeBSD.org>

Implement (ACFLAGS|CFLAGS|CXXFLAGS).SRC globally.

Sponsored by: EMC / Isilon Storage Division


# 1b337a34 25-Mar-2016 Bryan Drewery <bdrewery@FreeBSD.org>

Build libcompat (lib32) with a --sysroot pointing into its stage directory.

This overrides the cross-compiler's default sysroot to use the WORLD32's
sysroot for building the lib32 libraries. Previously the cross-compiler
would default the sysroot to the 64bit WORLDTMP and -B/-L/-isystem flags
were used to build using the lib32 files. This leads to multiple issues
discussed later. Some extra headers are now needed to be staged since the
64bit WORLDTMP is not referenced at all for headers. The 64bit WORLDTMP
is still used via PATH for build tools. Overriding the default
target/arch is retained in the CC/CXX overrides.

This allows reverting the LDSCRIPT rewriting in installworld from r296921 and
r235122, thus allowing read-only objdirs to work for installing again.

This removes the need for _LDSCRIPTROOT.

This allows progressing the change to always use --sysroot for the build
rather than only relying on the cross-compiler's default sysroot. The
work for that is in D3970 and needed to resolve WITHOUT_CROSS_COMPILER
not using a --sysroot [1].

PR: 196193 [1]
Sponsored by: EMC / Isilon Storage Division


# 54bc9e30 15-Mar-2016 Bryan Drewery <bdrewery@FreeBSD.org>

Partially revert r266227 and stop stripping paths in ldscripts.

Specifically this fixes /usr/lib/libc.so stripping the paths to the
libraries. The reason for this in r266227 was both likely because ld(1) did
not fully respect --sysroot until r291226 and because of the lib32
build. The lib32 build does not use --sysroot into the /usr/lib32 path,
rather it only uses -L and -B into the /usr/lib32 path and --sysroot
into the normal (64bit) /usr/lib. The _LDSCRIPTROOT was added with
the ldscript support in bsd.lib.mk so that it builds a 32-bit-sysrooted pathed
ldscript in the object directory and then installs a normal unprefixed
version in installworld. This commit also fixes the rebuild during
install which was broken in r266227. This commit would break DIRDEPS_BUILD
build of lib32 but it does not currently have a way to build it anyhow.

For example, before this change we had in /usr/lib/libc.so:
GROUP ( libc.so.7 libc_nonshared.a libssp_nonshared.a )
Now it is restored to pre-r266227:
GROUP ( /lib/libc.so.7 /usr/lib/libc_nonshared.a /usr/lib/libssp_nonshared.a )

The motivation for this is in testing of lld.
From emaste:
lld does not have built-in search paths (e.g. /lib, /usr/lib) and relies on
-L arguments passed by the caller. As the linker is nearly always invoked
from the clang driver this is fine other than the fact that /usr/lib/libc.so
is an ldscript that refers to libc.so.7 which is in /lib, not /usr/lib.

PR: 207980
Reported by: emaste
Submitted by: emaste (based on)
Differential Revision: https://reviews.freebsd.org/D5637


# 4d7ae5ef 11-Mar-2016 Bryan Drewery <bdrewery@FreeBSD.org>

DIRDEPS_BUILD: export DESTDIR for STAGING.

An example of where this is needed is in share/examples which for
'etc-examples' runs 'make -C SRCTOP/etc etc-examples' which installs
to the default DESTDIR otherwise.

Sponsored by: EMC / Isilon Storage Division


# fa3afecf 11-Mar-2016 Bryan Drewery <bdrewery@FreeBSD.org>

DIRDEPS_BUILD: Extend beforeinstall: staging hack.

Most beforeinstall: usage is not adding commands but only adding
targets, such as in share/sendmail.

Sponsored by: EMC / Isilon Storage Division


# 3cf3d039 08-Mar-2016 Bryan Drewery <bdrewery@FreeBSD.org>

DIRDEPS_BUILD+PROGS: Fix staging not respecting (BINDIR|PROGNAME)[._]${PROG}.

Observed in tests/sys/kern.

Sponsored by: EMC / Isilon Storage Division


# aae63957 26-Feb-2016 Bryan Drewery <bdrewery@FreeBSD.org>

Import bsd.clang-analyze.mk based on NetBSD's version.

This allows 'make analyze' or 'make OBJ.clang-analyzer' to run the
Clang static analyzer and present results on stdout.

Obtained from: NetBSD (CVS Rev. 1.3)
Sponsored by: EMC / Isilon Storage Division
Differential Revision: https://reviews.freebsd.org/D5449


# 4e47b95c 26-Feb-2016 Bryan Drewery <bdrewery@FreeBSD.org>

Remove more references to targets we've never had.

Sponsored by: EMC / Isilon Storage Division


# 71b7fa12 07-Feb-2016 Enji Cooper <ngie@FreeBSD.org>

Simplify running the FreeBSD test suite

Replace `make regress` (legacy test make target) and `make test` (incomplete
test make target added with the FreeBSD test suite) with make check as it's
consistent with other open source projects.

`make check` defaults to running tests from `.OBJDIR`, but can be overridden
with the `CHECKDIR` variable.

Add `make checkworld` target to simplify running the FreeBSD test suite from
`TESTSBASE` (i.e. the top-level tests directory), similar to buildworld.

Document `make check` and `make checkworld` in build(7).

Other minor changes:

- Rename intermediate file (`Kyuafile.auto`) to `Kyuafile` to simplify
`make check`.
- Remove terse warnings attached to `beforetest`/`aftertest`.
- Add kyua binary check to check target in suite.test.mk; error out if it's
not found

The MFC is [partly] contingent on other build related changes being MFCed.

Differential Revision: https://reviews.freebsd.org/D4406
MFC after: 2 months
X-MFC to: stable/10
Relnotes: yes
Reviewed by: bdrewery, Evan Cramer <eccramer@gmail.com>
Sponsored by: EMC / Isilon Storage Division


# ff7ea788 14-Jan-2016 Steven Hartland <smh@FreeBSD.org>

Allow file specific user-specified flag overrides

Allow user-specified warning flag overrides for specific files under
bsd.sys.mk, in the same way kern.mk does.

This will to be used by future commits.

MFC after: 2 weeks
X-MFC-With: r293268
Sponsored by: Multiplay


# 1fdcc5e5 11-Dec-2015 Ruslan Bukin <br@FreeBSD.org>

Start support for the RISC-V 64-bit architecture developed by UC Berkeley.

RISC-V is a new ISA designed to support computer research and education, and
is now become a standard open architecture for industry implementations.

This is a minimal set of changes required to run 'make kernel-toolchain'
using external (GNU) toolchain.

The FreeBSD/RISC-V project home: https://wiki.freebsd.org/riscv.

Reviewed by: andrew, bdrewery, emaste, imp
Sponsored by: DARPA, AFRL
Sponsored by: HEIF5
Differential Revision: https://reviews.freebsd.org/D4445


# 1da13532 19-Nov-2015 Bryan Drewery <bdrewery@FreeBSD.org>

META MODE: Don't stage INTERNALPROGs.

This is only for sys/boot. INTERNALPROG is not a build tool, it is just a way
to generate OBJS from a list of SRCS and use those objects elsewhere.

Sponsored by: EMC / Isilon Storage Division


# c04d716b 13-Nov-2015 Bryan Drewery <bdrewery@FreeBSD.org>

Revert r290740.

Discussing with sjg@, we agree the better fix is to be done in meta.stage.mk.

This also broke staging of SYMLINKS for non-shared libraries, such as for
lib/libcompiler_rt, which results in all Makefile.depend removing it.

Sponsored by: EMC / Isilon Storage Division


# e13d8c12 12-Nov-2015 Bryan Drewery <bdrewery@FreeBSD.org>

META MODE: Don't double stage SYMLINKS for libraries.

meta.stage.mk is handling ${SYMLINKS:T} for stage_libs already. The logic in
bsd.sys.mk to handle ${SYMLINKS} was brought in r247817 when it was moved out
of bsd.prog.mk and bsd.lib.mk into bsd.sys.mk. The logic previously was
limited to bsd.prog.mk.

This fixes a race, seen easily in lib/libthr, where libpthread_p.a is created
by both stage_libs and stage_symlinks resulting in 'ln: File exists'.

Sponsored by: EMC / Isilon Storage Division


# a52bef9c 17-Oct-2015 Enji Cooper <ngie@FreeBSD.org>

Only enable -fstack-protector-strong on gcc 4.9+ and default to -fstack-protector
when -fstack-protector-strong is not available, like it was implicitly before
r288669

As noted by antoine@, devel/gcc (which is 4.8.5) lacks -fstack-protector-strong
support, whereas 4.8.4i (devel/gcc48) has the support.

Until a version is available which has -fstack-protector-strong support, be
conservative and only enable support with 4.9+.

Reviewed by: pfg
X-MFC with: r288669, r289465
Differential Revision: https://reviews.freebsd.org/D3924


# 835f3289 17-Oct-2015 Enji Cooper <ngie@FreeBSD.org>

Only use -fstack-protector-strong with supported compilers

This includes clang 3.5.0+, gcc 4.2.1, gcc 4.8.4+

This allows me to do subdirectory makes again after setting
MAKESYSPATH on 10.2-RELEASE as it comes with clang 3.4.1.

As a sidenote: this isn't technically correct for all vintages
of gcc 4.2.1, but will be correct when gcc is rebuilt/reinstalled
after r286074, so this version check should be good enough.

X-MFC with: r288669
Differential Revision: https://reviews.freebsd.org/D3924
Reviewed by: emaste, pfg


# 08cf86fe 14-Oct-2015 Bryan Drewery <bdrewery@FreeBSD.org>

Add missing targets to PHONY_NOTMAIN.

- buildconfig, installconfig (missed in r289085)
- files (missed in r241298)

Sponsored by: EMC / Isilon Storage Division


# eef72759 06-Oct-2015 Simon J. Gerraty <sjg@FreeBSD.org>

In jobs mode we can use .ORDER to force stage_links to run after other
stage_* targets.
In non-jobs mode we can achieve the same result by simply introducing
the targets in the correct order.
Thus in bsd*.mk we simply add targets to STAGE_TARGETS which we
realize in meta.stage.mk

Reviewed by: bdrewery


# c621a626 04-Oct-2015 Pedro F. Giffuni <pfg@FreeBSD.org>

Bump the stack protector to level "strong".

The general stack protector is known to be weak and has pretty small
coverage. While setting stack-protector-all would give better protection
it would come with a performance cost: for this reason Google's Chrome OS
team developed a new stack-protector-strong variant.

In addition to the protections offered by -fstack-protector, the new option
will guard any function that declares any type or length of local array,
even those in structs or unions. It will also protect functions that use a
local variable's address in a function argument or on the right-hand side
of an assignment.

The option was introduced in GCC-4.9, but support for it has been
back-ported to our base GCC (r286074) and is also available in clang.

The change was tested with dbench and doesn't introduce performance
regressions. An exp-run over the ports tree revealed no failures when
using the stricter stack-protector-all. Thanks to all testers involved.

Reference:
https://outflux.net/blog/archives/2014/01/27/fstack-protector-strong/

Tested by: pho, portmgr (antoine)
Discussed with: secteam (delphij)

Differential Revision: https://reviews.freebsd.org/D3463
PR: 203394 (exp-run)

Relnotes: yes
MFC: no (not supported in older clang)


# db31773f 18-Sep-2015 Bryan Drewery <bdrewery@FreeBSD.org>

Garbage collect _SHLIBDIRPREFIX leftovers from r284898.

Sponsored by: EMC / Isilon Storage Division


# 944e1910 30-May-2015 Dimitry Andric <dim@FreeBSD.org>

From 3.7.0 onwards, we no longer need the -mllvm -enable-gvn=false hack
to compile boot2 successfully.


# ab0116f5 27-Mar-2015 Dimitry Andric <dim@FreeBSD.org>

Re-enable using -mllvm -enable-load-pre=false in CLANG_OPT_SMALL for
clang versions before 3.5.0. This should enable building head's version
of sys/boot/i386/boot2 on 9.x and 10.x again.

Reported by: bz


# 22a3c2dd 21-Mar-2015 Dimitry Andric <dim@FreeBSD.org>

Correctly pass the -mllvm -enable-gvn=false flag in CLANG_OPT_SMALL
(this has to be passed as a combination of two flags). Should fix the
case where the clang version is before 3.5.0.

Submitted by: Pedro Arthur <bygrandao@gmail.com>
X-MFC-With: r279018, r279378


# 1b398e4e 27-Feb-2015 David E. O'Brien <obrien@FreeBSD.org>

Update r279018 so it only applies to Clang version 3.5+ and not 3.4.[1-9].


# b4d70598 19-Feb-2015 Warner Losh <imp@FreeBSD.org>

Only disable gvn on clang 3.5 and newer.


# accc510a 28-Jan-2015 Dimitry Andric <dim@FreeBSD.org>

Since clang 3.6.0 now implements the archetype 'freebsd_kprintf' for
__attribute__((format(...))), and the -fformat-extensions flag was
removed, introduce a new macro in bsd.sys.mk to choose the right variant
of compile flag for the used compiler, and use it.

Also add something similar to kern.mk, since including bsd.sys.mk from
that file will anger Warner. :-)

Note that bsd.sys.mk does not support the MK_FORMAT_EXTENSIONS knob used
in kern.mk, since that knob is only available in kern.opts.mk, not in
src.opts.mk. We might want to add it later, to more easily support
external compilers for building world (in particular, sys/boot).


# e004ed02 28-Jan-2015 Dimitry Andric <dim@FreeBSD.org>

Disable the new -Wunused-local-typedef warning for WARNS <= 3, since it
triggers way too many times for the version of libc++ we have in base at
this point. While here, fix the compiler version check for
-Wno-unused-const-variable.


# 8f610c09 01-Jan-2015 Warner Losh <imp@FreeBSD.org>

Put the conditional back. For the default case it isn't really needed,
but for the gcc case it still is on i386 and amd64's build of
sys/boot.

Submited by: dim@


# 7ed11c5e 31-Dec-2014 Warner Losh <imp@FreeBSD.org>

Fix module builds on arm (and maybe others) by turning off a whole
raft of new warnings that appear to be on by default in clang 3.5.0.
Fix RPI-B build issues with new clang not liking the ability to pass
arbitrary flags to as, since some flags are more arbitrary (and thus
verboten) than others.

These warnings should be actually fixed in the code, but this is a
band-aide to get things (almost) building again.


# a58b2989 24-Nov-2014 Dimitry Andric <dim@FreeBSD.org>

Ensure boot2 stays below the limit, by applying a patch from Roman
Divacky which shrinks the code, and by using the custom llvm option to
disable the Global Value Numbering optimization pass.


# 13b7412d 01-Sep-2014 Ed Schouten <ed@FreeBSD.org>

Add -Wthread-safety to WARNS=6.

While there, add a NO_WTHREAD_SAFETY flag that can be used to disable
this specific warning flag. Disable it for auditdistd. We can easily
patch up auditdistd to have the right annotations to build, but as
auditdistd is intended to be portable across other operating systems,
it's not worth the effort.

Approved by: brueffer@


# e7d939bd 06-Jul-2014 Marcel Moolenaar <marcel@FreeBSD.org>

Remove ia64.

This includes:
o All directories named *ia64*
o All files named *ia64*
o All ia64-specific code guarded by __ia64__
o All ia64-specific makefile logic
o Mention of ia64 in comments and documentation

This excludes:
o Everything under contrib/
o Everything under crypto/
o sys/xen/interface
o sys/sys/elf_common.h

Discussed at: BSDcan


# f187ca8c 16-May-2014 Simon J. Gerraty <sjg@FreeBSD.org>

Using lib*.so as a linker script ...
the paths can be avoided, making the file mobile, so generate during build
and we need to handle staging it.


# dfd11a44 10-May-2014 Warner Losh <imp@FreeBSD.org>

g/c unmaintained, uninstalled bsd.pkg.mk. It tied into the ports
system, as it existed 9 years ago, and has been obsolete for a long
time.


# 7273339d 10-May-2014 Warner Losh <imp@FreeBSD.org>

Eliminate EARLY_BUILD flag. It is redundant and means MK_CLANG_FULL=no
and MK_LLDB=no, so set those explicitly (now that we can do
that). Simplify tests for these variables as well, since we know they
will always be defined regardless of the phase of the build.


# ab72ce6b 10-May-2014 Warner Losh <imp@FreeBSD.org>

Migrate NO_WARN to MK_WARN. Support legacy NO_WARN usage. Remove a
check for EARLY_BUILD because it isn't necessary (MK_WARN=no will
always be defined for that).


# 99929852 10-May-2014 Warner Losh <imp@FreeBSD.org>

Support, to the extent we generate proper command lines, compiling
with clang 3.3. Useful for test building -current on a -stable system
in individual directories. Potentially useful if we ever want to
support, say, gcc 4.8 or 4.9's new warnings when building with an
external toolchain (but such support not yet committed). Document
the bsd.compiler.mk interface.


# 41603b83 05-May-2014 Warner Losh <imp@FreeBSD.org>

Simplify use of the semi-bogus EARLY_BUILD variable. Also, simplify
use of semi-bogus NO_WARNS variable. Both of these, in this case,
should collapse to WITHOUT_WARNS in a future commit.


# a18673d4 05-May-2014 Warner Losh <imp@FreeBSD.org>

Introduce CWARNFLAGS.${COMPILER_TYPE} and use that to simplify the
thicket of .if ${COMPILER_TYPE} == "clang" that controls
warnings. Also, use CFLAGS.clang in a couple places in preference to
having a similar construct that's related to the CWARNFLAGS changes.


# 1c19778e 01-May-2014 Simon J. Gerraty <sjg@FreeBSD.org>

Some warnings depened on the version of clang, allow us to check.

Reviewed by: obrien


# 2ded1ea2 25-Apr-2014 Warner Losh <imp@FreeBSD.org>

Generalize FOO.clang to FOO.${COMPILER_TYPE}. There's no reason these
need to be clang specific. Also generalize things a bit.


# c34a97a0 02-Mar-2014 Andrey A. Chernov <ache@FreeBSD.org>

Add fetch and patch to .PHONY and .NOTMAIN only if PORTNAME is defined.
Unconditional addition cause real fetch(1) and patch(1) programs are
builded every time.

MFC after: 1 week


# 2879baf2 21-Feb-2014 Dimitry Andric <dim@FreeBSD.org>

Move the part in bsd.own.mk that sets -Wno-c++11-extensions for clang to
bsd.sys.mk, where it really belongs. This also causes the flag to get
added when clang is *not* the default system compiler, but is still
used, e.g. by setting WITH_CLANG_IS_CC manually.

MFC after: 3 days


# 7e4113e2 21-Feb-2014 Dimitry Andric <dim@FreeBSD.org>

In case source files are compiled with -g, tell clang not to emit .cfi
directives, since on sparc64 we must still GNU as, which does not
support those directives.

Note there are several programs and libraries in our tree, which are
always compiled with -g, even if DEBUG_FLAGS is not set by the user!


# f66aed32 06-Jan-2014 Dimitry Andric <dim@FreeBSD.org>

Apply band-aid for 32-bit compat libs failures after r260334: put back
-Qunused-arguments for clang for now, until I can figure out a way to
make it unneeded in all scenarios. Sorry about the breakage.


# 4abd7edc 05-Jan-2014 Dimitry Andric <dim@FreeBSD.org>

Split the last gcc-specific flags off into CFLAGS.gcc. This also
removes the need to use -Qunused-arguments for clang throughout the
tree.

MFC after: 3 days


# 20dcbdb6 05-Jan-2014 Dimitry Andric <dim@FreeBSD.org>

In addition to r260102, also define GCC_MS_EXTENSIONS in bsd.sys.mk,
since kernel module builds do not use kern.pre.mk.

MFC after: 3 days
X-MFC-With: r260102


# b294993d 22-Dec-2013 Dimitry Andric <dim@FreeBSD.org>

To avoid having to explicitly test COMPILER_TYPE for setting
clang-specific or gcc-specific flags, introduce the following new
variables for use in Makefiles:

CFLAGS.clang
CFLAGS.gcc
CXXFLAGS.clang
CXXFLAGS.gcc

In bsd.sys.mk, these get appended to the regular CFLAGS or CXXFLAGS for
the right compiler.

MFC after: 1 week


# e33625bf 07-Dec-2013 Dimitry Andric <dim@FreeBSD.org>

For WARNS <= 3, change the clang warning flag -Wno-conversion to
-Wno-enum-conversion. In earlier clang versions (before 3.2), the
latter did not exist, and suppressing enum conversion warnings was
really the goal of this warning suppression flag.

This should enable the same kind of warning again as was fixed by
r259072 ("incompatible integer to pointer conversion passing 'Elf_Addr'
(aka 'unsigned int') to parameter of type 'void *'"), and which was only
emitted by gcc.

Noticed by: kib
MFC after: 3 days


# 72484446 12-Oct-2013 Simon J. Gerraty <sjg@FreeBSD.org>

Ensure that $PROG isn't make .PHONY
Also add some additional control over staging (for use by bsd.test.mk)


# 7e659f94 19-Apr-2013 Ed Schouten <ed@FreeBSD.org>

Add the Clang specific -Wmissing-variable-declarations to WARNS=6.

This compiler flag enforces that that people either mark variables
static or use an external declarations for the variable, similar to how
-Wmissing-prototypes works for functions.

Due to the fact that Yacc/Lex generate code that cannot trivially be
changed to not warn because of this (lots of yy* variables), add a
NO_WMISSING_VARIABLE_DECLARATIONS that can be used to turn off this
specific compiler warning.

Announced on: toolchain@


# b023fdc4 14-Mar-2013 Simon J. Gerraty <sjg@FreeBSD.org>

We want meta.stage.mk when cleaning


# 8fe4beee 08-Mar-2013 Simon J. Gerraty <sjg@FreeBSD.org>

Allow staging to be help up (by .WAIT) until other
bits of all: are done.


# 92054a53 07-Mar-2013 Simon J. Gerraty <sjg@FreeBSD.org>

Ensure natural order of stage_*: matches the .ORDER in meta.stage.mk


# 57bf5f75 04-Mar-2013 Simon J. Gerraty <sjg@FreeBSD.org>

Move STAGING related setup to bsd.sys.mk


# a7449e3c 16-Feb-2013 Dimitry Andric <dim@FreeBSD.org>

Since clang 3.2 now has an option to suppress warnings about implicitly
promoted K&R parameters, remove the workarounds added for sendmail
components in r228558.

MFC after: 1 week


# 0815243c 06-Oct-2012 Marcel Moolenaar <marcel@FreeBSD.org>

Add support for bmake. This includes:
1. Don't do upgrade_checks when using bmake. As long as we have WITH_BMAKE,
there's a bootstrap complication in ths respect. Avoid it. Make the
necessary changes to have upgrade_checks work wth bmake anyway.
2. Remove the use of -E. It's not needed in our build because we use ?= for
the respective variables, which means that we'll take the environment
value (if any) anyway.
3. Properly declare phony targets as phony as bmake is a lot smarter (and
thus agressive) about build avoidance.
4. Make sure CLEANFILES is complete and use it on .NOPATH. bmake is a lot
smarter about build avoidance and should not find files we generate in
the source tree. We should not have files in the repository we want to
generate, but this is an easier way to cross this hurdle.
5. Have behavior under bmake the same as it is under make with respect to
halting when sub-commands fail. Add "set -e" to compound commands so
that bmake is informed when sub-commands fail.
6. Make sure crunchgen uses the same make as the rest of the build. This
is important when the make utility isn't called make (but bmake for
example).
7. While here, add support for using MAKEOBJDIR to set the object tree
location. It's the second alternative bmake looks for when determining
the actual object directory (= .OBJDIR).

Submitted by: Simon Gerraty <sjg@juniper.net>
Submitted by: John Van Horne <jvanhorne@juniper.net>


# 9215d178 13-Sep-2012 Brooks Davis <brooks@FreeBSD.org>

Introduce a new make variable COMPILER_TYPE that specifies what
type of compiler is being used (currently clang or gcc). COMPILER_TYPE
is set in the new bsd.compiler.mk file based on the value of the CC
variable or, should it prove informative, by running ${CC} --version
and examining the output.

To avoid negative performance impacts in the default case and correct
value for COMPILER_TYPE type is determined and passed in the environment
of submake instances while building world.

Replace adhoc attempts at determining the compiler type by examining
CC or MK_CLANG_IS_CC with checks of COMPILER_TYPE. This eliminates
bootstrapping complications when first setting WITH_CLANG_IS_CC.

Sponsored by: DARPA, AFRL
Reviewed by: Yamaya Takashi <yamayan@kbh.biglobe.ne.jp>, imp, linimon
(with some modifications post review)
MFC after: 2 weeks


# 7750ad47 22-Aug-2012 Marcel Moolenaar <marcel@FreeBSD.org>

Sync FreeBSD's bmake branch with Juniper's internal bmake branch.

Requested by: Simon Gerraty <sjg@juniper.net>


# 883e0f87 03-Jun-2012 Dimitry Andric <dim@FreeBSD.org>

During buildworld and buildkernel, define EARLY_BUILD in the earlier
stages (build-tools, cross-tools, etc) of the build, so we can detect in
bsd.*.mk whether to pass compiler-specific flags to ${CC}.

In particular, this commit will allow using WITH_CLANG_IS_CC when the
base compiler is still gcc, and when ${CC}, ${CXX} and ${CPP} are left
at their defaults. The early stages will then be built using gcc, and
no clang-specific flags will be passed to it. The later stages will be
built as usual.

The EARLY_BUILD define can also serve other uses, such as building the
world stage C++ executables with libc++ instead of libstdc++: during the
early build stages, we cannot assume libc++ is already available, so we
must still build with libstdc++ at that time.

MFC after: 1 week


# 3b05e58b 16-Mar-2012 Dimitry Andric <dim@FreeBSD.org>

Change the style of share/mk/bsd.sys.mk to that of the other bsd.*.mk
files, and style.Makefile(5), where applicable. While here, update the
link to the gcc warning documentation.

No functional change.

MFC after: 1 week


# de9dec16 09-Mar-2012 Jung-uk Kim <jkim@FreeBSD.org>

Make boot2 build with Clang again.

Submitted by: dim (bsd.sys.mk)
Reviewed by: dim, jhb


# 2651e350 03-Mar-2012 Dimitry Andric <dim@FreeBSD.org>

Revert r232473. I have been convinced by Doug Barton and Bjoern Zeeb
that it is better to error out when people attempt to build using the
wrong bsd.*.mk files, than to silently ignore the problem.

This means, that after this commit, if you want to build kernel modules
by hand (or via a port) from a head source tree, you *must* make sure
the files in /usr/share/mk are in sync with that tree. If that isn't
possible, for example when you are running on an older FreeBSD branch,
you can:

- Run "make buildenv" from your head source tree, to have the correct
environment setup. (It's advisable to have run "make buildworld", or
at a minimum "make toolchain" first.)
- Alternatively, set MAKESYSPATH to the share/mk directory under your
head source tree. If your build tools are too old, other problems may
still occur.
- Alternatively, use "make -m" and specify the share/mk directory under
your head source tree. Again, build tools that are too old may still
result in trouble.

MFC after: 2 weeks


# 2677e7fe 03-Mar-2012 Dimitry Andric <dim@FreeBSD.org>

After r232322, it turned out many people (and some ports) are building
kernel modules using their old installed /usr/share/mk/bsd.*.mk files,
instead of the updated ones in their source tree. This leads to errors
like:

"sys/conf/kmod.mk", line 111: Malformed conditional (${MK_CLANG_IS_CC} == "no" && ${CC:T:Mclang} != "clang")

Obviously, these errors will go away after a "make installworld", or
alternatively, by using "make buildenv" before attempting to manually
build modules.

However, since it is apparently an expected use case to build using old
.mk files, change the way we test for clang, so it also works when the
MK_CLANG_IS_CC macro doesn't exist.

Note the conditional expressions are becoming rather unreadable now, but
I will attempt to fix that on a followup commit.

MFC after: 2 weeks


# dfbaea83 29-Feb-2012 Dimitry Andric <dim@FreeBSD.org>

Add a WITH_CLANG_IS_CC option for src.conf(5), disabled by default, that
installs clang as /usr/bin/cc, /usr/bin/c++ and /usr/bin/cpp.

Note this does *not* disable building and installing gcc, which will
still be available as /usr/bin/gcc, /usr/bin/g++ and /usr/bin/gcpp. If
you want to disable gcc completely, you must use WITHOUT_GCC.

MFC after: 2 weeks


# 07b202a8 28-Feb-2012 Dimitry Andric <dim@FreeBSD.org>

Define several extra macros in bsd.sys.mk and sys/conf/kern.pre.mk, to
get rid of testing explicitly for clang (using ${CC:T:Mclang}) in
individual Makefiles.

Instead, use the following extra macros, for use with clang:
- NO_WERROR.clang (disables -Werror)
- NO_WCAST_ALIGN.clang (disables -Wcast-align)
- NO_WFORMAT.clang (disables -Wformat and friends)
- CLANG_NO_IAS (disables integrated assembler)
- CLANG_OPT_SMALL (adds flags for extra small size optimizations)

As a side effect, this enables setting CC/CXX/CPP in src.conf instead of
make.conf! For clang, use the following:

CC=clang
CXX=clang++
CPP=clang-cpp

MFC after: 2 weeks


# c09186a2 17-Dec-2011 Dimitry Andric <dim@FreeBSD.org>

Disable another clang warning (-Wempty-body) when WARNS <= 2.

MFC after: 1 week


# ac7472ad 17-Dec-2011 Dimitry Andric <dim@FreeBSD.org>

Disable yet another clang warning (-Wconversion) when WARNS <= 3.

MFC after: 1 week


# 9b9c36a3 16-Dec-2011 Dimitry Andric <dim@FreeBSD.org>

Disable yet another clang warning when WARNS <= 3.

MFC after: 1 week


# c9009f9f 16-Dec-2011 Dimitry Andric <dim@FreeBSD.org>

Add a NO_WARRAY_BOUNDS setting to bsd.sys.mk, only applicable to clang,
to selectively work around warnings in programs that don't use flexible
array members, but instead define arrays of length 1 at the end of the
struct, and then access those beyond their declared bounds.

MFC after: 1 week


# c792b7e8 15-Dec-2011 Dimitry Andric <dim@FreeBSD.org>

Disable one more clang warning when WARNS <= 3.

MFC after: 1 week


# e2325c4a 15-Dec-2011 Dimitry Andric <dim@FreeBSD.org>

Clang has more warnings enabled by default, and when using -Wall, so if WARNS
is set to low values, some of them have to be disabled explicitly.

MFC after: 1 week


# 58ff0f42 19-Apr-2011 Dimitry Andric <dim@FreeBSD.org>

Remove support for the Intel C Compiler from the build infrastructure.
This support has not worked for several years, and is not likely to work
again, unless Intel decides to release a native FreeBSD version of their
compiler. ;)


# a6c0f1f2 07-Mar-2011 Pawel Jakub Dawidek <pjd@FreeBSD.org>

To be able to use printf extensions we need to turn off gcc format checking.
Following the convention of NO_WERROR and NO_WCAST_ALIGN add NO_WFORMAT,
which, when defined in Makefile, turns off compile-time format checking
(by adding -Wno-format), but still allows to use high WARNS level.

MFC after: 2 weeks


# a7d5f7eb 19-Oct-2010 Jamie Gritton <jamie@FreeBSD.org>

A new jail(8) with a configuration file, to replace the work currently done
by /etc/rc.d/jail.


# 25faff34 23-Aug-2010 Warner Losh <imp@FreeBSD.org>

MFtbemd:

Prefer MACHNE_CPUARCH to MACHINE_ARCH in most contexts where you want
to test of all the CPUs of a given family conform.


# 187278ca 17-Aug-2010 Rui Paulo <rpaulo@FreeBSD.org>

For every instance of '.if ${CC} == "foo"' or '.if ${CC} != "foo"' in
Makefiles or *.mk files, use ${CC:T:Mfoo} instead, so only the basename
of the compiler command (excluding any arguments) is considered.

This allows you to use, for example, CC="/nondefault/path/clang -xxx",
and still have the various tests in bsd.*.mk identify your compiler as
clang correctly.

ICC if cases were also changed.

Submitted by: Dimitry Andric <dimitry at andric.com>


# fe0506d7 09-Mar-2010 Marcel Moolenaar <marcel@FreeBSD.org>

Create the altix project branch. The altix project will add support
for the SGI Altix 350 to FreeBSD/ia64. The hardware used for porting
is a two-module system, consisting of a base compute module and a
CPU expansion module. SGI's NUMAFlex architecture can be an excellent
platform to test CPU affinity and NUMA-aware features in FreeBSD.


# c9a900ed 17-Feb-2010 Marcel Moolenaar <marcel@FreeBSD.org>

Allow suppression of -Wcast-align for WARNS>=4 by defining
NO_WCAST_ALIGN. The headers of the standard C++ library are
not 64-bit clean and trigger the warning. This prevents use
of WARNS>=4 on ia64 for example.


# e73a17cf 18-Jan-2010 Edward Tomasz Napierala <trasz@FreeBSD.org>

Undo r169961, removing WITH_GCC3, added as a temporary workaround three
years ago.


# 03bc68ca 30-Dec-2009 Ed Schouten <ed@FreeBSD.org>

Disable K&R style function definitions for WARNS=6.

Unfortunately there are two slight problems with that:

- Yacc and lex might generate code that generates warnings because of
this. Require yacc and lex to be rebuilt during bootstrap. I'm not
incrementing __FreeBSD_version here, because I assume someone else
will do this eventually.

- When running `make buildkernel', it uses share/mk from the source
treeo to build aicasm. Because aicasm also depends on lex, this would
break. Lower WARNS to 5 for now. We should just increment it to 6
again somewhere in the very far future.


# b48db8e1 22-Oct-2009 Ruslan Ermilov <ru@FreeBSD.org>

Unbreak NO_WARNS, keeping CSTD effect on CFLAGS out of its control.
Unbreak compiles with icc.


# 9448b439 21-Oct-2009 Roman Divacky <rdivacky@FreeBSD.org>

Set CSTD in all cases except when CC=icc and NO_WARNS is set. This
way we can set desired C standard even for cross tools etc.

Tested by: make universe
Approved by: ed (maintainer)
OK by: das


# 300d03a8 14-Mar-2009 Roman Divacky <rdivacky@FreeBSD.org>

Switch over to gnu99 compilation on default for userland.

Tested by: make universe
Tested by: ports exp build (done by pav)
Reviewed by: ru
Reviewed by: silence on arch
Approved by: ed (mentor)


# d7f03759 19-Oct-2008 Ulf Lilleengen <lulf@FreeBSD.org>

- Import the HEAD csup code which is the basis for the cvsmode work.


# a678ba4e 23-Jul-2008 Warner Losh <imp@FreeBSD.org>

Turn of SSP for mips for now until support is added to the base
architecture.


# ad8abd6c 18-Jul-2008 Olivier Houchard <cognet@FreeBSD.org>

Disable SSP on arm for the time being.
The segfaults when using SSP seem to be a gcc bug, a patch is available
in the gcc bugzilla, and will be imported once it's committed
into the official gcc tree.


# 042df2e2 25-Jun-2008 Ruslan Ermilov <ru@FreeBSD.org>

Enable GCC stack protection (aka Propolice) for userland:
- It is opt-out for now so as to give it maximum testing, but it may be
turned opt-in for stable branches depending on the consensus. You
can turn it off with WITHOUT_SSP.
- WITHOUT_SSP was previously used to disable the build of GNU libssp.
It is harmless to steal the knob as SSP symbols have been provided
by libc for a long time, GNU libssp should not have been much used.
- SSP is disabled in a few corners such as system bootstrap programs
(sys/boot), process bootstrap code (rtld, csu) and SSP symbols themselves.
- It should be safe to use -fstack-protector-all to build world, however
libc will be automatically downgraded to -fstack-protector because it
breaks rtld otherwise.
- This option is unavailable on ia64.

Enable GCC stack protection (aka Propolice) for kernel:
- It is opt-out for now so as to give it maximum testing.
- Do not compile your kernel with -fstack-protector-all, it won't work.

Submitted by: Jeremie Le Hen <jeremie@le-hen.org>


# cfb5b325 22-Nov-2007 John Birrell <jb@FreeBSD.org>

Re-enable -Werror again.

This time, change the default CFLAGS to match the simple defaults that
the tinderboxes use. That is, don't use -fno-strict-aliasing by default.

My last attempt to re-anable -Werror gave me a lesson in what strict
aliasing is all about. There was code in libthr that wasn't 64-bit clean.
The default use of -fno-strict-aliasing hid that.

By using -fno-strict-aliasing by default we were choosing to ignore
problems in code which had the potential to shoot ourselves in the
foot. Sometimes it would be the 64-bit foot. I have both feet. The left
ones are 32 bits and the right ones are 64 bits. Don't ask about my
endian orientation. :-)

The -fno-strict-aliasing compiler arg can still be used if NO_STRING_ALIASING
is define in make.

We are early in the FreeBSD 8 development, so we have the opportunity to
wait and see if this works for us. I am sure that people will complain.
We can easily revert this. All I ask is that we take sides: clean code or
not. YMMV.

Note that by using -fno-strict-aliasing the build won't actually break.
Only where WARNS is set (and -Werror is used) will a compiler warning break
the build. The use of WARNS levels implies (to me at least) that the
developer has taken some care to make the code pass basic checks. This
commit makes those checks just a little bit more strict.


# f9f50330 19-Nov-2007 John Birrell <jb@FreeBSD.org>

Unfortunately the tinderbox setup uses custom CFLAGS which are a big
obstacle to enabling -Werror. I'll continue to work on cleaning up the
code so that we can keep this enabled.

If the tinderboxes would just use the default CFLAGS set in this file,
all would be fine and we'd be able to make use of -Werror.


# 76f9e2ec 19-Nov-2007 John Birrell <jb@FreeBSD.org>

Re-enable -Werror ins WARNS as it was roughly 6 months ago before
being disabled while gcc 4.2 was bedded in.

Tested with 'make release' (amd64 arm i386 ia64 pc98 powerpc sparc64 sun4v)


# 9eef6e33 24-May-2007 David E. O'Brien <obrien@FreeBSD.org>

Temporarily add 'WITH_GCC3' that removes -Wno-pointer-sign from the
compiler invocation. This is just to help get over the hump of people
tracking down bugs that may cross the GCC 4.2 upgrade.
It is envisioned that this option goes away after a suitable amount
of time.


# d9e2d1a3 18-May-2007 Alexander Kabaev <kan@FreeBSD.org>

Universally disable -Werror until src/ is in better shape for GCC 4.2.
There are new warnings that kill the build otherwise.

Disable pointer destination sign mismatch warning alltogether. Our tree
is in no shape to have that enabled yet.


# f4c93e2c 03-Nov-2006 John Birrell <jb@FreeBSD.org>

Allow a makefile to set IGNORE_PRAGMA so that OpenSolaris code can
be built with other gcc warnings enabled.

Every Solaris source file has a #pragma ident in it. We can just
ignore those definitions.


# 513f04ca 11-Aug-2006 Dag-Erling Smørgrav <des@FreeBSD.org>

Reintroduce CSTD, which allows a Makefile to specify the precise dialect
of C in which the program or library is written.

Note that this is *not* intended to be used across the whole tree. It
is intended to be used for individual libraries or programs which use
specific language features which the compiler must know about in order
to produce correct warnings at high WARNS levels.

MFC after: 1 month


# 8d918dbd 16-Jan-2005 David E. O'Brien <obrien@FreeBSD.org>

Move -Wunused-parameter from WARNS level 3 level 4.

Also break long lines -- note that the '\' must be up against the last
character of a line to keep command-line spacing proper.

Requested by: rwatson


# 626cba20 16-Jan-2005 David E. O'Brien <obrien@FreeBSD.org>

Use >= so we can use the actual WARNS levels.


# 06d6e4fc 12-Mar-2004 Tom Rhodes <trhodes@FreeBSD.org>

This are the build infrastructure changes to allow to use the
Intel C/C++ compiler (lang/icc) to build the kernel.

The icc CPUTYPE CFLAGS use icc v7 syntax, icc v8 moans about them, but
doesn't abort. They also produce CPU specific code (new instructions
of the CPU, not only CPU specific scheduling), so if you get coredumps
with signal 4 (SIGILL, illegal instruction) you've used the wrong
CPUTYPE.

Incarnations of this patch survive gcc compiles and my make universe.
I use it on my desktop.

To use it update share/mk, add
/usr/local/intel/compiler70/ia32/bin (icc v7, works)
or
/usr/local/intel_cc_80/bin (icc v8, doesn't work)
to your PATH, make sure you have a new kernel compile directory
(e.g. MYKERNEL_icc) and run
CFLAGS="-O2 -ip" CC=icc make depend
CFLAGS="-O2 -ip" CC=icc make
in it.

Don't compile with -ipo, the build infrastructure uses ld directly to
link the kernel and the modules, but -ipo needs the link step to be
performed with Intel's linker.

Problems with icc v8:
- panic: npx0 cannot be emulated on an SMP system
- UP: first start of /bin/sh results in a FP exception

Parts of this commit contains suggestions or submissions from
Marius Strobl <marius@alchemy.franken.de>.

Reviewed by: silence on -arch
Submitted by: netchild


# 5193980c 16-Feb-2004 Dag-Erling Smørgrav <des@FreeBSD.org>

Remove -Wbad-function-cast. Its main purpose is to catch bugs that we
already catch with -Wstrict-prototypes, and it causes spurious warnings
for some perfectly legitimate constructs.


# 80451781 11-Jan-2004 Ruslan Ermilov <ru@FreeBSD.org>

Put the warning flags to where they belong (into CWARNFLAGS).
This allows us to easily override them when necessary, e.g.,
to selectively disable warnings in libc/ contributed sources.


# 139c58b3 14-Jun-2003 Warner Losh <imp@FreeBSD.org>

Put on the core hat and back out all of the CSTD= changes. Core will
deal with working with the parties to define a coherent definition for
CSTD that doesn't break things.

Core hat seconded by: markm


# b6723d4d 14-Jun-2003 Dag-Erling Smørgrav <des@FreeBSD.org>

Revert to a known-good state. Anyone desiring to experiment with stricter
global settings is free to do so in his or her own source tree.


# 333c9db6 13-Jun-2003 Peter Wemm <peter@FreeBSD.org>

We cannot use c99 on amd64 either due to lack of alloca(). libc:strptime()
uses alloca() and alloca is impossible to implement as a callable function
on amd64. It has to be a compiler builtin. Note that the bigger problem
is that libc is not c99 clean internally.


# 10f7bcc5 07-Jun-2003 David E. O'Brien <obrien@FreeBSD.org>

Be C std strict on i386 and amd64 as we can. Be loose on Alpha and ia64.


# b307c742 06-Jun-2003 David E. O'Brien <obrien@FreeBSD.org>

Compile our code as C99 w/GNU extensions by default.
We can't use straight "c99" due to the lack of alloca.S for non-i386 platforms.


# b9c19cc2 02-Jun-2003 David E. O'Brien <obrien@FreeBSD.org>

I got a bazzar bug report


# 1cd2abf7 02-Jun-2003 David E. O'Brien <obrien@FreeBSD.org>

Turn back on c99, the tree should be ready for it now.


# 479b5433 01-Jun-2003 David E. O'Brien <obrien@FreeBSD.org>

To quote Tony Maher <tonymaher@optushome.com.au>, "maybe 3rd time lucky ;-)"
*sigh* Just can't get a brake when trying to react too quickly and fix the build.


# f14fd87c 01-Jun-2003 David E. O'Brien <obrien@FreeBSD.org>

Temperarly turn off building the tree with c99.
I swore this made it thru a 'make world', but I don't know what happened.


# 28c3f28e 01-Jun-2003 David E. O'Brien <obrien@FreeBSD.org>

Use a bigger hammer -- keep all -std= out of CXXFLAGS.
Also allow for "CSTD=" in a Makefile.


# 5622a7e0 01-Jun-2003 David E. O'Brien <obrien@FreeBSD.org>

Do not set a C standard for the C++ compiler.


# 58908299 01-Jun-2003 David E. O'Brien <obrien@FreeBSD.org>

Compile our code as C99 by default.


# cf459fc3 31-May-2003 David E. O'Brien <obrien@FreeBSD.org>

CSTD is virtually worthless for WARNS=2-5. Return -pedantic to WARNS=6+.


# 239e385f 31-May-2003 David E. O'Brien <obrien@FreeBSD.org>

Make CSTD style match the rest of file.


# a3f59e65 05-May-2003 Dag-Erling Smørgrav <des@FreeBSD.org>

Whitespace cleanup (1.15 had spaces instead of tabs)


# 9820f41c 05-May-2003 Dag-Erling Smørgrav <des@FreeBSD.org>

Don't use -pedantic unless we also set -std of some kind.


# 77695b34 01-May-2003 Dag-Erling Smørgrav <des@FreeBSD.org>

Add a mechanism to allow Makefiles to specify the particular C dialect
in which the source code is written. This is controlled by the CSTD
variable, which can have one of the following values:

- "k&r" => -traditional
- "c89" or "c90" => -std=iso9899:1990
- "c94" or "c95" => -std=iso9899:199409
- "c99" => -std=iso9899:1999

The corresponding option is added to CFLAGS regardless of WARNS level.
This also removes -ansi from WARNS level 6, but adds -Wno-long-long to
work around a weird gcc bug (-ansi, which is supposedly equivalent to
-std=iso9899:1990, seems to turn long long warnings off instead of on)

If CSTD is undefined, CFLAGS are unchanged except for the -ansi /
-Wno-long-long change mentioned above for WARNS level 6.


# 30aaff11 05-Apr-2003 Warner Losh <imp@FreeBSD.org>

Migrate to a new way of dealing with building from old revisions of
FreeBSD. This method attempts to centralize all the necessary hacks
or work arounds in one of two places in the tree (src/Makefile.inc1
and src/tools/build). We build a small compatibility library
(libbuild.a) as well as selectively installing necessary include
files. We then include this directory when building host binaries.

This removes all the past release compatibilty hacks from various
places in the tree. We still build on tip of stable and current. I
will work with those that want to support more, although I anticipate
it will just work.

Many thanks to ru@, obrien@ and jhb@ for providing valuable input at
various stage of implementation, as well as for working together to
positively effect a change for the better.


# 0e80a2f6 04-Apr-2003 Ruslan Ermilov <ru@FreeBSD.org>

-Wall implies -Wuninitialized if -O is also in effect.
-Wuninitialized does not work without -O.

This fixes the ${WARNS} > 4 compilations with -O0.

Spotted by: marcel


# effd19ed 31-Mar-2003 Ruslan Ermilov <ru@FreeBSD.org>

Enable cpp(1) warnings in system headers. GCC is oriented on
glibc which is externally maintained, so GCC ships with these
warnings turned off by default. This is also consistent with
the src/contrib/gcc/c-lex.c,v 1.2 change.


# 40c6b893 13-Nov-2002 Ruslan Ermilov <ru@FreeBSD.org>

Take __FreeBSD_version into account when BOOTSTRAPPING.


# bf4ca100 07-Jul-2002 David E. O'Brien <obrien@FreeBSD.org>

Be more strict with WARNS now -- the GCC 3.1 turmoil is behind us.


# be5181d5 19-May-2002 David E. O'Brien <obrien@FreeBSD.org>

Tweak the WARNS levels a tad.


# b0b7c216 09-May-2002 David E. O'Brien <obrien@FreeBSD.org>

Gcc 3.1 has different -Wx flags.


# 89d1cbc7 09-Apr-2002 David E. O'Brien <obrien@FreeBSD.org>

Add WARNS levels 5 and 6:
5 gives us -Wuninitialized rather than -Wno-uninitialized
6 gives us full BDECFLAGS


# 7cf143f7 07-Apr-2002 Ruslan Ermilov <ru@FreeBSD.org>

FreeBSD prior to 4.5-RELEASE and older versions of 5.0-CURRENT do not
have the __FBSDID() macro in <sys/cdefs.h>. Fix this once and for all
for tools that need to be bootstrapped.

PR: bin/36747
MFC after: 3 days
Prodded by: obrien


# 3ad920fe 05-Jan-2002 David Malone <dwmalone@FreeBSD.org>

Put -Wno-uninitialized at the end of the warns flags as it may be enabeled
by several flags (in this case -W and -Wall).

Reviewed by: bde


# 328c7f1d 14-Dec-2001 David E. O'Brien <obrien@FreeBSD.org>

Add some granularity to the WARNS levels.
1: add -Werror
2: -Wall [only], as this is the most used warnings setting by developers
3: our old `1'
4: our old `2'


# 45703321 19-May-2001 Kris Kennaway <kris@FreeBSD.org>

Only add -Werror if in fact we have set WARNS or WFORMAT to >0


# d510ecb4 19-May-2001 Kris Kennaway <kris@FreeBSD.org>

Bring in the WARNS directive from NetBSD, localized in a new bsd.sys.mk
to avoid polluting sys.mk. This directive controls the addition of
compiler warning flags to CFLAGS in a relatively compiler-neutral manner.

The idea is that WARNS can be set in Makefile.inc or in individual
Makefiles as they become clean, to prevent the introduction of new
warnings in the code. -Werror is added by default