@@ -1327,95 +1327,97 @@ make_compiler_cflags() {
fi
# rdynamic is used to get useful stack traces from crash reports.
ldflags="$ldflags -rdynamic"
else
# Enable some things only for certain GCC versions
cc_version=`$1 -dumpversion | cut -c 1,3`
if [ $cc_version -lt 33 ]; then
# cc_version = major_version * 100 + minor_version
# For example: "3.3" -> 303, "4.9.2" -> 409, "6" -> 600, "23.5" -> 2305
cc_version=`$1 -dumpversion | $awk -F . '{printf "%d%02d", $1, $2}'`
if [ $cc_version -lt 303 ]; then
log 1 "configure: error: gcc older than 3.3 can't compile OpenTTD because of its poor template support"
exit 1
flags="$flags -Wall -Wno-multichar -Wsign-compare -Wundef"
flags="$flags -Wwrite-strings -Wpointer-arith"
flags="$flags -W -Wno-unused-parameter -Wredundant-decls"
flags="$flags -Wformat=2 -Wformat-security"
if [ $enable_assert -eq 0 ]; then
# Do not warn about unused variables when building without asserts
flags="$flags -Wno-unused-variable"
if [ $cc_version -ge 46 ]; then
if [ $cc_version -ge 406 ]; then
# GCC 4.6 gives more warnings, disable them too
flags="$flags -Wno-unused-but-set-variable"
flags="$flags -Wno-unused-but-set-parameter"
if [ $cc_version -ge 34 ]; then
if [ $cc_version -ge 304 ]; then
# Warn when a variable is used to initialise itself:
# int a = a;
flags="$flags -Winit-self"
if [ $cc_version -ge 40 ]; then
if [ $cc_version -ge 400 ]; then
# GCC 4.0+ complains about that we break strict-aliasing.
# On most places we don't see how to fix it, and it doesn't
# break anything. So disable strict-aliasing to make the
# compiler all happy.
flags="$flags -fno-strict-aliasing"
# Warn about casting-out 'const' with regular C-style cast.
# The preferred way is const_cast<>() which doesn't warn.
flags="$flags -Wcast-qual"
if [ $cc_version -ge 42 ]; then
if [ $cc_version -ge 402 ]; then
# GCC 4.2+ automatically assumes that signed overflows do
# not occur in signed arithmetics, whereas we are not
# sure that they will not happen. It furthermore complains
# about its own optimized code in some places.
flags="$flags -fno-strict-overflow"
# GCC 4.2 no longer includes -Wnon-virtual-dtor in -Wall.
# Enable it in order to be consistent with older GCC versions.
flags="$flags -Wnon-virtual-dtor"
if [ $cc_version -ge 43 ] && [ $cc_version -lt 60 ]; then
if [ $cc_version -ge 403 ] && [ $cc_version -lt 600 ]; then
# Use gnu++0x mode so static_assert() is available.
# Don't use c++0x, it breaks mingw (with gcc 4.4.0).
cxxflags="$cxxflags -std=gnu++0x"
if [ $cc_version -eq 45 ]; then
if [ $cc_version -eq 405 ]; then
# Prevent optimisation supposing enums are in a range specified by the standard
# For details, see http://gcc.gnu.org/PR43680
flags="$flags -fno-tree-vrp"
if [ $cc_version -ge 47 ]; then
if [ $cc_version -ge 407 ]; then
# Disable -Wnarrowing which gives many warnings, such as:
# warning: narrowing conversion of '...' from 'unsigned int' to 'int' inside { } [-Wnarrowing]
# They are valid according to the C++ standard, but useless.
cxxflags="$cxxflags -Wno-narrowing"
# Disable bogus 'attempt to free a non-heap object' warning
flags="$flags -Wno-free-nonheap-object"
if [ $cc_version -ge 60 ]; then
if [ $cc_version -ge 600 ]; then
# -flifetime-dse=2 (default since GCC 6) doesn't play
# well with our custom pool item allocator
cxxflags="$cxxflags -flifetime-dse=1 -std=gnu++14"
if [ "$enable_lto" != "0" ]; then
# GCC 4.5 outputs '%{flto}', GCC 4.6 outputs '%{flto*}'
has_lto=`$1 -dumpspecs | grep '\%{flto'`
if [ -n "$has_lto" ]; then
# Use LTO only if we see LTO exists and is requested
if [ $cc_version -lt 46 ]; then
if [ $cc_version -lt 406 ]; then
flags="$flags -flto"
flags="$flags -flto=jobserver"
ldflags="$ldflags -fwhole-program"
features="$features lto"
@@ -1508,13 +1510,13 @@ make_cflags_and_ldflags() {
if [ -n "$cc_build_is_gcc" ]; then
# Just add -O1 to the tools needed for building.
CFLAGS_BUILD="$CFLAGS_BUILD -D_FORTIFY_SOURCE=2 -O1"
if [ "$os" = "OSX" ] && [ $cc_version -eq 40 ]; then
if [ "$os" = "OSX" ] && [ $cc_version -eq 400 ]; then
# Apple's GCC 4.0 has a compiler bug for x86_64 with (higher) optimization,
# wrongly optimizing ^= in loops. This disables the failing optimisation.
CFLAGS="$CFLAGS -fno-expensive-optimizations"
if [ "$enable_profiling" != "0" ]; then
@@ -1532,29 +1534,29 @@ make_cflags_and_ldflags() {
if [ "`echo $1 | cut -c 1-3`" != "icc" ]; then
if [ "$os" = "CYGWIN" ]; then
flags="$flags -mwin32"
LDFLAGS="$LDFLAGS -mwin32"
if [ "$os" = "MINGW" ] || [ "$os" = "CYGWIN" ]; then
flags="$flags -mno-cygwin"
LDFLAGS="$LDFLAGS -mno-cygwin"
if [ "$enable_console" != "0" ]; then
LDFLAGS="$LDFLAGS -Wl,--subsystem,console"
LDFLAGS="$LDFLAGS -Wl,--subsystem,windows"
LIBS="$LIBS -lws2_32 -lwinmm -lgdi32 -ldxguid -lole32 -limm32"
if [ $cc_version -ge 44 ]; then
LDFLAGS_BUILD="$LDFLAGS_BUILD -static-libgcc -static-libstdc++"
CFLAGS="$CFLAGS -mno-ms-bitfields"
if [ "$os" != "CYGWIN" ] && [ "$os" != "HAIKU" ] && [ "$os" != "OPENBSD" ] && [ "$os" != "MINGW" ] && [ "$os" != "MORPHOS" ] && [ "$os" != "OSX" ] && [ "$os" != "DOS" ] && [ "$os" != "WINCE" ] && [ "$os" != "PSP" ] && [ "$os" != "OS2" ]; then
Status change: