build/autoconf/compiler-opts.m4

Wed, 31 Dec 2014 07:16:47 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 07:16:47 +0100
branch
TOR_BUG_9701
changeset 3
141e0f1194b1
permissions
-rw-r--r--

Revert simplistic fix pending revisit of Mozilla integration attempt.

michael@0 1 dnl This Source Code Form is subject to the terms of the Mozilla Public
michael@0 2 dnl License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 3 dnl file, You can obtain one at http://mozilla.org/MPL/2.0/.
michael@0 4
michael@0 5 dnl Add compiler specific options
michael@0 6
michael@0 7 AC_DEFUN([MOZ_DEFAULT_COMPILER],
michael@0 8 [
michael@0 9 dnl set DEVELOPER_OPTIONS early; MOZ_DEFAULT_COMPILER is usually the first non-setup directive
michael@0 10 if test -z "$MOZILLA_OFFICIAL"; then
michael@0 11 DEVELOPER_OPTIONS=1
michael@0 12 fi
michael@0 13 MOZ_ARG_ENABLE_BOOL(release,
michael@0 14 [ --enable-release Build with more conservative, release engineering-oriented options.
michael@0 15 This may slow down builds.],
michael@0 16 DEVELOPER_OPTIONS=,
michael@0 17 DEVELOPER_OPTIONS=1)
michael@0 18
michael@0 19 AC_SUBST(DEVELOPER_OPTIONS)
michael@0 20
michael@0 21 dnl Default to MSVC for win32 and gcc-4.2 for darwin
michael@0 22 dnl ==============================================================
michael@0 23 if test -z "$CROSS_COMPILE"; then
michael@0 24 case "$target" in
michael@0 25 *-mingw*)
michael@0 26 if test -z "$CC"; then CC=cl; fi
michael@0 27 if test -z "$CXX"; then CXX=cl; fi
michael@0 28 if test -z "$CPP"; then CPP="cl -E -nologo"; fi
michael@0 29 if test -z "$CXXCPP"; then CXXCPP="cl -TP -E -nologo"; ac_cv_prog_CXXCPP="$CXXCPP"; fi
michael@0 30 if test -z "$LD"; then LD=link; fi
michael@0 31 if test -z "$AS"; then
michael@0 32 case "${target_cpu}" in
michael@0 33 i*86)
michael@0 34 AS=ml;
michael@0 35 ;;
michael@0 36 x86_64)
michael@0 37 AS=ml64;
michael@0 38 ;;
michael@0 39 esac
michael@0 40 fi
michael@0 41 if test -z "$MIDL"; then MIDL=midl; fi
michael@0 42
michael@0 43 # need override this flag since we don't use $(LDFLAGS) for this.
michael@0 44 if test -z "$HOST_LDFLAGS" ; then
michael@0 45 HOST_LDFLAGS=" "
michael@0 46 fi
michael@0 47 ;;
michael@0 48 *-darwin*)
michael@0 49 # GCC on darwin is based on gcc 4.2 and we don't support it anymore.
michael@0 50 if test -z "$CC"; then
michael@0 51 MOZ_PATH_PROGS(CC, clang)
michael@0 52 fi
michael@0 53 if test -z "$CXX"; then
michael@0 54 MOZ_PATH_PROGS(CXX, clang++)
michael@0 55 fi
michael@0 56 IS_GCC=$($CC -v 2>&1 | grep gcc)
michael@0 57 if test -n "$IS_GCC"
michael@0 58 then
michael@0 59 echo gcc is known to be broken on OS X, please use clang.
michael@0 60 echo see http://developer.mozilla.org/en-US/docs/Developer_Guide/Build_Instructions/Mac_OS_X_Prerequisites
michael@0 61 echo for more information.
michael@0 62 exit 1
michael@0 63 fi
michael@0 64 ;;
michael@0 65 esac
michael@0 66 fi
michael@0 67 ])
michael@0 68
michael@0 69 dnl ============================================================================
michael@0 70 dnl C++ rtti
michael@0 71 dnl We don't use it in the code, but it can be usefull for debugging, so give
michael@0 72 dnl the user the option of enabling it.
michael@0 73 dnl ============================================================================
michael@0 74 AC_DEFUN([MOZ_RTTI],
michael@0 75 [
michael@0 76 MOZ_ARG_ENABLE_BOOL(cpp-rtti,
michael@0 77 [ --enable-cpp-rtti Enable C++ RTTI ],
michael@0 78 [ _MOZ_USE_RTTI=1 ],
michael@0 79 [ _MOZ_USE_RTTI= ])
michael@0 80
michael@0 81 if test -z "$_MOZ_USE_RTTI"; then
michael@0 82 if test "$GNU_CC"; then
michael@0 83 CXXFLAGS="$CXXFLAGS -fno-rtti"
michael@0 84 else
michael@0 85 case "$target" in
michael@0 86 *-mingw*)
michael@0 87 CXXFLAGS="$CXXFLAGS -GR-"
michael@0 88 esac
michael@0 89 fi
michael@0 90 fi
michael@0 91 ])
michael@0 92
michael@0 93 dnl ========================================================
michael@0 94 dnl =
michael@0 95 dnl = Debugging Options
michael@0 96 dnl =
michael@0 97 dnl ========================================================
michael@0 98 AC_DEFUN([MOZ_DEBUGGING_OPTS],
michael@0 99 [
michael@0 100 dnl Debug info is ON by default.
michael@0 101 if test -z "$MOZ_DEBUG_FLAGS"; then
michael@0 102 if test -n "$_MSC_VER"; then
michael@0 103 MOZ_DEBUG_FLAGS="-Zi"
michael@0 104 else
michael@0 105 MOZ_DEBUG_FLAGS="-g"
michael@0 106 fi
michael@0 107 fi
michael@0 108
michael@0 109 AC_SUBST(MOZ_DEBUG_FLAGS)
michael@0 110
michael@0 111 MOZ_ARG_ENABLE_STRING(debug,
michael@0 112 [ --enable-debug[=DBG] Enable building with developer debug info
michael@0 113 (using compiler flags DBG)],
michael@0 114 [ if test "$enableval" != "no"; then
michael@0 115 MOZ_DEBUG=1
michael@0 116 if test -n "$enableval" -a "$enableval" != "yes"; then
michael@0 117 MOZ_DEBUG_FLAGS=`echo $enableval | sed -e 's|\\\ | |g'`
michael@0 118 _MOZ_DEBUG_FLAGS_SET=1
michael@0 119 fi
michael@0 120 else
michael@0 121 MOZ_DEBUG=
michael@0 122 fi ],
michael@0 123 MOZ_DEBUG=)
michael@0 124
michael@0 125 MOZ_DEBUG_ENABLE_DEFS="-DDEBUG -D_DEBUG -DTRACING"
michael@0 126 MOZ_ARG_WITH_STRING(debug-label,
michael@0 127 [ --with-debug-label=LABELS
michael@0 128 Define DEBUG_<value> for each comma-separated
michael@0 129 value given.],
michael@0 130 [ for option in `echo $withval | sed 's/,/ /g'`; do
michael@0 131 MOZ_DEBUG_ENABLE_DEFS="$MOZ_DEBUG_ENABLE_DEFS -DDEBUG_${option}"
michael@0 132 done])
michael@0 133
michael@0 134 MOZ_DEBUG_DISABLE_DEFS="-DNDEBUG -DTRIMMED"
michael@0 135
michael@0 136 if test -n "$MOZ_DEBUG"; then
michael@0 137 AC_MSG_CHECKING([for valid debug flags])
michael@0 138 _SAVE_CFLAGS=$CFLAGS
michael@0 139 CFLAGS="$CFLAGS $MOZ_DEBUG_FLAGS"
michael@0 140 AC_TRY_COMPILE([#include <stdio.h>],
michael@0 141 [printf("Hello World\n");],
michael@0 142 _results=yes,
michael@0 143 _results=no)
michael@0 144 AC_MSG_RESULT([$_results])
michael@0 145 if test "$_results" = "no"; then
michael@0 146 AC_MSG_ERROR([These compiler flags are invalid: $MOZ_DEBUG_FLAGS])
michael@0 147 fi
michael@0 148 CFLAGS=$_SAVE_CFLAGS
michael@0 149 fi
michael@0 150
michael@0 151 dnl ========================================================
michael@0 152 dnl = Enable generation of debug symbols
michael@0 153 dnl ========================================================
michael@0 154 MOZ_ARG_ENABLE_STRING(debug-symbols,
michael@0 155 [ --enable-debug-symbols[=DBG]
michael@0 156 Enable debugging symbols (using compiler flags DBG)],
michael@0 157 [ if test "$enableval" != "no"; then
michael@0 158 MOZ_DEBUG_SYMBOLS=1
michael@0 159 if test -n "$enableval" -a "$enableval" != "yes"; then
michael@0 160 if test -z "$_MOZ_DEBUG_FLAGS_SET"; then
michael@0 161 MOZ_DEBUG_FLAGS=`echo $enableval | sed -e 's|\\\ | |g'`
michael@0 162 else
michael@0 163 AC_MSG_ERROR([--enable-debug-symbols flags cannot be used with --enable-debug flags])
michael@0 164 fi
michael@0 165 fi
michael@0 166 else
michael@0 167 MOZ_DEBUG_SYMBOLS=
michael@0 168 fi ],
michael@0 169 MOZ_DEBUG_SYMBOLS=1)
michael@0 170
michael@0 171 if test -n "$MOZ_DEBUG" -o -n "$MOZ_DEBUG_SYMBOLS"; then
michael@0 172 AC_DEFINE(MOZ_DEBUG_SYMBOLS)
michael@0 173 export MOZ_DEBUG_SYMBOLS
michael@0 174 fi
michael@0 175
michael@0 176 ])
michael@0 177
michael@0 178 dnl A high level macro for selecting compiler options.
michael@0 179 AC_DEFUN([MOZ_COMPILER_OPTS],
michael@0 180 [
michael@0 181 if test "${MOZ_PSEUDO_DERECURSE-unset}" = unset; then
michael@0 182 dnl Don't enable on pymake, because of bug 918652. Bug 912979 is an annoyance
michael@0 183 dnl with pymake, too.
michael@0 184 MOZ_PSEUDO_DERECURSE=no-pymake
michael@0 185 fi
michael@0 186
michael@0 187 MOZ_DEBUGGING_OPTS
michael@0 188 MOZ_RTTI
michael@0 189 if test "$CLANG_CXX"; then
michael@0 190 ## We disable return-type-c-linkage because jsval is defined as a C++ type but is
michael@0 191 ## returned by C functions. This is possible because we use knowledge about the ABI
michael@0 192 ## to typedef it to a C type with the same layout when the headers are included
michael@0 193 ## from C.
michael@0 194 ##
michael@0 195 ## mismatched-tags is disabled (bug 780474) mostly because it's useless.
michael@0 196 ## Worse, it's not supported by gcc, so it will cause tryserver bustage
michael@0 197 ## without any easy way for non-Clang users to check for it.
michael@0 198 _WARNINGS_CXXFLAGS="${_WARNINGS_CXXFLAGS} -Wno-unknown-warning-option -Wno-return-type-c-linkage -Wno-mismatched-tags"
michael@0 199 fi
michael@0 200
michael@0 201 AC_MSG_CHECKING([whether the C++ compiler ($CXX $CXXFLAGS $LDFLAGS) actually is a C++ compiler])
michael@0 202 AC_LANG_SAVE
michael@0 203 AC_LANG_CPLUSPLUS
michael@0 204 _SAVE_LIBS=$LIBS
michael@0 205 LIBS=
michael@0 206 AC_TRY_LINK([#include <new>], [int *foo = new int;],,
michael@0 207 AC_MSG_RESULT([no])
michael@0 208 AC_MSG_ERROR([$CXX $CXXFLAGS $LDFLAGS failed to compile and link a simple C++ source.]))
michael@0 209 LIBS=$_SAVE_LIBS
michael@0 210 AC_LANG_RESTORE
michael@0 211 AC_MSG_RESULT([yes])
michael@0 212
michael@0 213 if test -z "$GNU_CC"; then
michael@0 214 case "$target" in
michael@0 215 *-mingw*)
michael@0 216 ## Warning 4099 (equivalent of mismatched-tags) is disabled (bug 780474)
michael@0 217 ## for the same reasons as above.
michael@0 218 _WARNINGS_CXXFLAGS="${_WARNINGS_CXXFLAGS} -wd4099"
michael@0 219 esac
michael@0 220 fi
michael@0 221
michael@0 222 if test -n "$DEVELOPER_OPTIONS"; then
michael@0 223 MOZ_FORCE_GOLD=1
michael@0 224 fi
michael@0 225
michael@0 226 MOZ_ARG_ENABLE_BOOL(gold,
michael@0 227 [ --enable-gold Enable GNU Gold Linker when it is not already the default],
michael@0 228 MOZ_FORCE_GOLD=1,
michael@0 229 MOZ_FORCE_GOLD=
michael@0 230 )
michael@0 231
michael@0 232 if test "$GNU_CC" -a -n "$MOZ_FORCE_GOLD"; then
michael@0 233 dnl if the default linker is BFD ld, check if gold is available and try to use it
michael@0 234 dnl for local builds only.
michael@0 235 if $CC -Wl,--version 2>&1 | grep -q "GNU ld"; then
michael@0 236 GOLD=$($CC -print-prog-name=ld.gold)
michael@0 237 case "$GOLD" in
michael@0 238 /*)
michael@0 239 ;;
michael@0 240 *)
michael@0 241 GOLD=$(which $GOLD)
michael@0 242 ;;
michael@0 243 esac
michael@0 244 if test -n "$GOLD"; then
michael@0 245 mkdir -p $_objdir/build/unix/gold
michael@0 246 rm -f $_objdir/build/unix/gold/ld
michael@0 247 ln -s "$GOLD" $_objdir/build/unix/gold/ld
michael@0 248 if $CC -B $_objdir/build/unix/gold -Wl,--version 2>&1 | grep -q "GNU gold"; then
michael@0 249 LDFLAGS="$LDFLAGS -B $_objdir/build/unix/gold"
michael@0 250 else
michael@0 251 rm -rf $_objdir/build/unix/gold
michael@0 252 fi
michael@0 253 fi
michael@0 254 fi
michael@0 255 fi
michael@0 256
michael@0 257 if test "$GNU_CC"; then
michael@0 258 if test -z "$DEVELOPER_OPTIONS"; then
michael@0 259 CFLAGS="$CFLAGS -ffunction-sections -fdata-sections"
michael@0 260 CXXFLAGS="$CXXFLAGS -ffunction-sections -fdata-sections"
michael@0 261 fi
michael@0 262 CFLAGS="$CFLAGS -fno-math-errno"
michael@0 263 CXXFLAGS="$CXXFLAGS -fno-exceptions -fno-math-errno"
michael@0 264 fi
michael@0 265
michael@0 266 dnl ========================================================
michael@0 267 dnl = Identical Code Folding
michael@0 268 dnl ========================================================
michael@0 269
michael@0 270 MOZ_ARG_DISABLE_BOOL(icf,
michael@0 271 [ --disable-icf Disable Identical Code Folding],
michael@0 272 MOZ_DISABLE_ICF=1,
michael@0 273 MOZ_DISABLE_ICF= )
michael@0 274
michael@0 275 if test "$GNU_CC" -a "$GCC_USE_GNU_LD" -a -z "$MOZ_DISABLE_ICF" -a -z "$DEVELOPER_OPTIONS"; then
michael@0 276 AC_CACHE_CHECK([whether the linker supports Identical Code Folding],
michael@0 277 LD_SUPPORTS_ICF,
michael@0 278 [echo 'int foo() {return 42;}' \
michael@0 279 'int bar() {return 42;}' \
michael@0 280 'int main() {return foo() - bar();}' > conftest.${ac_ext}
michael@0 281 # If the linker supports ICF, foo and bar symbols will have
michael@0 282 # the same address
michael@0 283 if AC_TRY_COMMAND([${CC-cc} -o conftest${ac_exeext} $LDFLAGS -Wl,--icf=safe -ffunction-sections conftest.${ac_ext} $LIBS 1>&2]) &&
michael@0 284 test -s conftest${ac_exeext} &&
michael@0 285 objdump -t conftest${ac_exeext} | awk changequote(<<, >>)'{a[<<$>>6] = <<$>>1} END {if (a["foo"] && (a["foo"] != a["bar"])) { exit 1 }}'changequote([, ]); then
michael@0 286 LD_SUPPORTS_ICF=yes
michael@0 287 else
michael@0 288 LD_SUPPORTS_ICF=no
michael@0 289 fi
michael@0 290 rm -rf conftest*])
michael@0 291 if test "$LD_SUPPORTS_ICF" = yes; then
michael@0 292 _SAVE_LDFLAGS="$LDFLAGS -Wl,--icf=safe"
michael@0 293 LDFLAGS="$LDFLAGS -Wl,--icf=safe -Wl,--print-icf-sections"
michael@0 294 AC_TRY_LINK([], [],
michael@0 295 [LD_PRINT_ICF_SECTIONS=-Wl,--print-icf-sections],
michael@0 296 [LD_PRINT_ICF_SECTIONS=])
michael@0 297 AC_SUBST([LD_PRINT_ICF_SECTIONS])
michael@0 298 LDFLAGS="$_SAVE_LDFLAGS"
michael@0 299 fi
michael@0 300 fi
michael@0 301
michael@0 302 dnl ========================================================
michael@0 303 dnl = Automatically remove dead symbols
michael@0 304 dnl ========================================================
michael@0 305
michael@0 306 if test "$GNU_CC" -a "$GCC_USE_GNU_LD" -a -z "$DEVELOPER_OPTIONS"; then
michael@0 307 if test -n "$MOZ_DEBUG_FLAGS"; then
michael@0 308 dnl See bug 670659
michael@0 309 AC_CACHE_CHECK([whether removing dead symbols breaks debugging],
michael@0 310 GC_SECTIONS_BREAKS_DEBUG_RANGES,
michael@0 311 [echo 'int foo() {return 42;}' \
michael@0 312 'int bar() {return 1;}' \
michael@0 313 'int main() {return foo();}' > conftest.${ac_ext}
michael@0 314 if AC_TRY_COMMAND([${CC-cc} -o conftest.${ac_objext} $CFLAGS $MOZ_DEBUG_FLAGS -c conftest.${ac_ext} 1>&2]) &&
michael@0 315 AC_TRY_COMMAND([${CC-cc} -o conftest${ac_exeext} $LDFLAGS $MOZ_DEBUG_FLAGS -Wl,--gc-sections conftest.${ac_objext} $LIBS 1>&2]) &&
michael@0 316 test -s conftest${ac_exeext} -a -s conftest.${ac_objext}; then
michael@0 317 if test "`$PYTHON -m mozbuild.configure.check_debug_ranges conftest.${ac_objext} conftest.${ac_ext}`" = \
michael@0 318 "`$PYTHON -m mozbuild.configure.check_debug_ranges conftest${ac_exeext} conftest.${ac_ext}`"; then
michael@0 319 GC_SECTIONS_BREAKS_DEBUG_RANGES=no
michael@0 320 else
michael@0 321 GC_SECTIONS_BREAKS_DEBUG_RANGES=yes
michael@0 322 fi
michael@0 323 else
michael@0 324 dnl We really don't expect to get here, but just in case
michael@0 325 GC_SECTIONS_BREAKS_DEBUG_RANGES="no, but it's broken in some other way"
michael@0 326 fi
michael@0 327 rm -rf conftest*])
michael@0 328 if test "$GC_SECTIONS_BREAKS_DEBUG_RANGES" = no; then
michael@0 329 DSO_LDOPTS="$DSO_LDOPTS -Wl,--gc-sections"
michael@0 330 fi
michael@0 331 else
michael@0 332 DSO_LDOPTS="$DSO_LDOPTS -Wl,--gc-sections"
michael@0 333 fi
michael@0 334 fi
michael@0 335 ])
michael@0 336
michael@0 337 dnl GCC and clang will fail if given an unknown warning option like -Wfoobar.
michael@0 338 dnl But later versions won't fail if given an unknown negated warning option
michael@0 339 dnl like -Wno-foobar. So when we are check for support of negated warning
michael@0 340 dnl options, we actually test the positive form, but add the negated form to
michael@0 341 dnl the flags variable.
michael@0 342
michael@0 343 AC_DEFUN([MOZ_C_SUPPORTS_WARNING],
michael@0 344 [
michael@0 345 AC_CACHE_CHECK(whether the C compiler supports $1$2, $3,
michael@0 346 [
michael@0 347 AC_LANG_SAVE
michael@0 348 AC_LANG_C
michael@0 349 _SAVE_CFLAGS="$CFLAGS"
michael@0 350 CFLAGS="$CFLAGS -Werror -W$2"
michael@0 351 AC_TRY_COMPILE([],
michael@0 352 [return(0);],
michael@0 353 $3="yes",
michael@0 354 $3="no")
michael@0 355 CFLAGS="$_SAVE_CFLAGS"
michael@0 356 AC_LANG_RESTORE
michael@0 357 ])
michael@0 358 if test "${$3}" = "yes"; then
michael@0 359 _WARNINGS_CFLAGS="${_WARNINGS_CFLAGS} $1$2"
michael@0 360 fi
michael@0 361 ])
michael@0 362
michael@0 363 AC_DEFUN([MOZ_CXX_SUPPORTS_WARNING],
michael@0 364 [
michael@0 365 AC_CACHE_CHECK(whether the C++ compiler supports $1$2, $3,
michael@0 366 [
michael@0 367 AC_LANG_SAVE
michael@0 368 AC_LANG_CPLUSPLUS
michael@0 369 _SAVE_CXXFLAGS="$CXXFLAGS"
michael@0 370 CXXFLAGS="$CXXFLAGS -Werror -W$2"
michael@0 371 AC_TRY_COMPILE([],
michael@0 372 [return(0);],
michael@0 373 $3="yes",
michael@0 374 $3="no")
michael@0 375 CXXFLAGS="$_SAVE_CXXFLAGS"
michael@0 376 AC_LANG_RESTORE
michael@0 377 ])
michael@0 378 if test "${$3}" = "yes"; then
michael@0 379 _WARNINGS_CXXFLAGS="${_WARNINGS_CXXFLAGS} $1$2"
michael@0 380 fi
michael@0 381 ])

mercurial