+AC_ARG_ENABLE(link-time-optimization,
+[AS_HELP_STRING([--enable-link-time-optimization],
+ [build emacs with link-time optimization.
+ This requires GCC 4.5.0 or later, or clang.
+ (Note that clang support is experimental - see INSTALL.)
+ It also makes Emacs harder to debug, and when we tried it
+ with GCC 4.9.0 x86-64 it made Emacs slower, so it's not
+ recommended for typical use.])],
+if test "${enableval}" != "no"; then
+ ac_lto_supported=no
+ if test $emacs_cv_clang = yes; then
+ AC_MSG_CHECKING([whether link-time optimization is supported by clang])
+ GOLD_PLUGIN=`$CC -print-file-name=LLVMgold.so 2>/dev/null`
+ if test -x "$GOLD_PLUGIN"; then
+ LTO="-flto"
+ fi
+ elif test x$GCC = xyes; then
+ AC_MSG_CHECKING([whether link-time optimization is supported by gcc])
+ CPUS=`getconf _NPROCESSORS_ONLN 2>/dev/null`
+ if test x$CPUS != x; then
+ LTO="-flto=$CPUS"
+ else
+ LTO="-flto"
+ fi
+ else
+ AC_MSG_ERROR([Link-time optimization is not supported with your compiler.])
+ fi
+ if test -z "$LTO"; then
+ ac_lto_supported=no
+ else
+ old_CFLAGS=$CFLAGS
+ CFLAGS="$CFLAGS $LTO"
+ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
+ [ac_lto_supported=yes], [ac_lto_supported=no])
+ CFLAGS="$old_CFLAGS"
+ fi
+ AC_MSG_RESULT([$ac_lto_supported])
+ if test "$ac_lto_supported" = "yes"; then
+ CFLAGS="$CFLAGS $LTO"
+ if test x$emacs_cv_clang = xyes; then
+ AC_MSG_WARN([Please read INSTALL before using link-time optimization with clang])
+ # WARNING: 'ar --plugin ...' doesn't work without
+ # command, so plugin name is appended to ARFLAGS.
+ ARFLAGS="cru --plugin $GOLD_PLUGIN"
+ RANLIB="$RANLIB --plugin $GOLD_PLUGIN"
+ else
+ dnl The following is needed for GCC 4.9.0. The GCC 4.9.0 release notes
+ dnl suggest that instead of -ffat-lto-objects we should use gcc-ar and
+ dnl gcc-ranlib in place of ar and ranlib, but gcc-ar makes /usr/bin/ar
+ dnl dump core on Fedora 20, so play it safe for now.
+ gl_COMPILER_OPTION_IF([-ffat-lto-objects],
+ [CFLAGS="$CFLAGS -ffat-lto-objects"])
+ fi
+ fi
+fi)