diff -r c49ff8dbf907 Makefile.pre.in --- a/Makefile.pre.in Wed Sep 07 01:21:14 2016 +0200 +++ b/Makefile.pre.in Tue Sep 06 17:01:22 2016 -0700 @@ -459,7 +459,7 @@ # Rules # Default target -all: build_all +all: @DEF_MAKE_ALL_RULE@ build_all: $(BUILDPYTHON) oldsharedmods sharedmods gdbhooks Programs/_testembed python-config # Compile a binary with profile guided optimization. @@ -483,7 +483,7 @@ $(MAKE) profile-removal build_all_generate_profile: - $(MAKE) all CFLAGS_NODIST="$(CFLAGS) $(PGO_PROF_GEN_FLAG) @LTOFLAGS@" LDFLAGS="$(LDFLAGS) $(PGO_PROF_GEN_FLAG) @LTOFLAGS@" LIBS="$(LIBS)" + $(MAKE) @DEF_MAKE_RULE@ CFLAGS_NODIST="$(CFLAGS) $(PGO_PROF_GEN_FLAG) @LTOFLAGS@" LDFLAGS="$(LDFLAGS) $(PGO_PROF_GEN_FLAG) @LTOFLAGS@" LIBS="$(LIBS)" run_profile_task: : # FIXME: can't run for a cross build @@ -493,14 +493,14 @@ $(LLVM_PROF_MERGER) build_all_use_profile: - $(MAKE) all CFLAGS_NODIST="$(CFLAGS) $(PGO_PROF_USE_FLAG) @LTOFLAGS@" LDFLAGS="$(LDFLAGS) @LTOFLAGS@" + $(MAKE) @DEF_MAKE_RULE@ CFLAGS_NODIST="$(CFLAGS) $(PGO_PROF_USE_FLAG) @LTOFLAGS@" LDFLAGS="$(LDFLAGS) @LTOFLAGS@" # Compile and run with gcov .PHONY=coverage coverage-lcov coverage-report coverage: @echo "Building with support for coverage checking:" $(MAKE) clean profile-removal - $(MAKE) all CFLAGS="$(CFLAGS) -O0 -pg -fprofile-arcs -ftest-coverage" LIBS="$(LIBS) -lgcov" + $(MAKE) @DEF_MAKE_RULE@ CFLAGS="$(CFLAGS) -O0 -pg -fprofile-arcs -ftest-coverage" LIBS="$(LIBS) -lgcov" coverage-lcov: @echo "Creating Coverage HTML report with LCOV:" diff -r c49ff8dbf907 configure.ac --- a/configure.ac Wed Sep 07 01:21:14 2016 +0200 +++ b/configure.ac Tue Sep 06 17:01:22 2016 -0700 @@ -1282,6 +1282,37 @@ fi], [AC_MSG_RESULT(no)]) +# Enable optimization flags +AC_SUBST(DEF_MAKE_ALL_RULE) +AC_SUBST(DEF_MAKE_RULE) +Py_OPT='false' +AC_MSG_CHECKING(for --with-optimizations) +AC_ARG_WITH(optimizations, AS_HELP_STRING([--with-optimizations], [Enable all optimizations when available (LTO, PGO, etc). Disabled by default.]), +[ +if test "$withval" != no +then + Py_OPT='true' + AC_MSG_RESULT(yes); +else + Py_OPT='false' + AC_MSG_RESULT(no); +fi], +[AC_MSG_RESULT(no)]) +if test "$Py_OPT" = 'true' ; then + Py_LTO='true' + case $ac_sys_system in + Darwin*) + # At least on macOS El Capitan, LTO does not work with PGO. + Py_LTO='false' + ;; + esac + DEF_MAKE_ALL_RULE="profile-opt" + DEF_MAKE_RULE="build_all" +else + DEF_MAKE_ALL_RULE="build_all" + DEF_MAKE_RULE="all" +fi + # Enable LTO flags AC_SUBST(LTOFLAGS) AC_MSG_CHECKING(for --with-lto) @@ -5337,3 +5368,13 @@ -s Modules Modules/Setup.config \ Modules/Setup.local Modules/Setup mv config.c Modules + +if test "$Py_OPT" = 'false' -a "$Py_DEBUG" != 'true'; then + echo "" >&AS_MESSAGE_FD + echo "" >&AS_MESSAGE_FD + echo "If you want a release build with all optimizations active (LTO, PGO, etc)," + echo "please run ./configure --with-optimizations" >&AS_MESSAGE_FD + echo "" >&AS_MESSAGE_FD + echo "" >&AS_MESSAGE_FD +fi +