# Author: Alecsandru Patrascu diff -r da934a19855b Makefile.pre.in --- a/Makefile.pre.in Sun Jan 03 18:07:06 2016 -0800 +++ b/Makefile.pre.in Mon Jan 04 16:59:58 2016 +0200 @@ -73,12 +73,12 @@ # Compiler options OPT= @OPT@ BASECFLAGS= @BASECFLAGS@ -CFLAGS= $(BASECFLAGS) @CFLAGS@ $(OPT) $(EXTRA_CFLAGS) +CFLAGS= $(BASECFLAGS) @CFLAGS@ $(OPT) @LTOFLAGS@ $(EXTRA_CFLAGS) # Both CPPFLAGS and LDFLAGS need to contain the shell's value for setup.py to # be able to build extension modules using the directories specified in the # environment variables CPPFLAGS= -I. -IInclude -I$(srcdir)/Include @CPPFLAGS@ -LDFLAGS= @LDFLAGS@ +LDFLAGS= @LDFLAGS@ @LTOFLAGS@ LDLAST= @LDLAST@ SGI_ABI= @SGI_ABI@ CCSHARED= @CCSHARED@ diff -r da934a19855b configure --- a/configure Sun Jan 03 18:07:06 2016 -0800 +++ b/configure Mon Jan 04 16:59:58 2016 +0200 @@ -667,6 +667,7 @@ LLVM_PROF_MERGER PGO_PROF_USE_FLAG PGO_PROF_GEN_FLAG +LTOFLAGS UNIVERSAL_ARCH_FLAGS BASECFLAGS OPT @@ -795,6 +796,7 @@ enable_shared enable_profiling with_pydebug +with_lto enable_toolbox_glue with_libs with_system_expat @@ -1476,6 +1478,7 @@ compiler --with-suffix=.exe set executable suffix --with-pydebug build with Py_DEBUG defined + --with-lto Enable Link Time Optimizations. Disabled by default. --with-libs='lib1 ...' link against additional libs --with-system-expat build pyexpat module using an installed expat library @@ -6365,6 +6368,49 @@ fi +# Enable LTO flags + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for --with-lto" >&5 +$as_echo_n "checking for --with-lto... " >&6; } + +# Check whether --with-lto was given. +if test "${with_lto+set}" = set; then : + withval=$with_lto; +if test "$withval" != no +then + Py_LTO='true' + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; }; +else + Py_LTO='false' + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; }; +fi +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + +if test "$Py_LTO" = 'true' ; then + case $CC in + *clang*) + # Any changes made here should be reflected in the GCC+Darwin case below + LTOFLAGS="-flto" + ;; + *gcc*) + case $ac_sys_system in + Darwin*) + LTOFLAGS="-flto" + ;; + *) + LTOFLAGS="-flto -fuse-linker-plugin -ffat-lto-objects -flto-partition=none" + ;; + esac + ;; + esac +fi + + # Enable PGO flags. diff -r da934a19855b configure.ac --- a/configure.ac Sun Jan 03 18:07:06 2016 -0800 +++ b/configure.ac Mon Jan 04 16:59:58 2016 +0200 @@ -1376,6 +1376,40 @@ fi +# Enable LTO flags +AC_SUBST(LTOFLAGS) +AC_MSG_CHECKING(for --with-lto) +AC_ARG_WITH(lto, AS_HELP_STRING([--with-lto], [Enable Link Time Optimizations. Disabled by default.]), +[ +if test "$withval" != no +then + Py_LTO='true' + AC_MSG_RESULT(yes); +else + Py_LTO='false' + AC_MSG_RESULT(no); +fi], +[AC_MSG_RESULT(no)]) +if test "$Py_LTO" = 'true' ; then + case $CC in + *clang*) + # Any changes made here should be reflected in the GCC+Darwin case below + LTOFLAGS="-flto" + ;; + *gcc*) + case $ac_sys_system in + Darwin*) + LTOFLAGS="-flto" + ;; + *) + LTOFLAGS="-flto -fuse-linker-plugin -ffat-lto-objects -flto-partition=none" + ;; + esac + ;; + esac +fi + + # Enable PGO flags. AC_SUBST(PGO_PROF_GEN_FLAG) AC_SUBST(PGO_PROF_USE_FLAG)