Makefile: make it possible to compile with gcc link-time optimization

Put in the necessary machinery to compile with gcc link-time
optimization.  This means compiling and linking with -flto, as well as
using gcc-ar and gcc-ranlib instead of the normal tools.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
This commit is contained in:
H. Peter Anvin 2017-02-28 18:48:01 -08:00
parent 2d6a3101f9
commit 5fe847e590
2 changed files with 38 additions and 2 deletions

21
aclocal.m4 vendored
View file

@ -14,6 +14,27 @@ AC_DEFUN(PA_ADD_CFLAGS,
AC_MSG_RESULT([no])
CFLAGS="$pa_add_cflags__old_cflags")])
dnl --------------------------------------------------------------------------
dnl PA_ADD_CLDFLAGS()
dnl
dnl Attempt to add the given option to CFLAGS and LDFLAGS,
dnl if it doesn't break compilation
dnl --------------------------------------------------------------------------
AC_DEFUN(PA_ADD_CLDFLAGS,
[AC_MSG_CHECKING([if $CC accepts $1])
pa_add_cldflags__old_cflags="$CFLAGS"
CFLAGS="$CFLAGS $1"
pa_add_cldflags__old_ldflags="$LDFLAGS"
LDFLAGS="$LDFLAGS $1"
AC_TRY_LINK([#include <stdio.h>],
[printf("Hello, World!\n");],
AC_MSG_RESULT([yes])
CFLAGS="$pa_add_cldflags__old_cflags ifelse([$2],[],[$1],[$2])"
LDFLAGS="$pa_add_cldflags__old_ldflags ifelse([$2],[],[$1],[$2])",
AC_MSG_RESULT([no])
CFLAGS="$pa_add_cldflags__old_cflags"
LDFLAGS="$pa_add_cldflags__old_ldflags")])
dnl --------------------------------------------------------------------------
dnl PA_HAVE_FUNC
dnl

View file

@ -148,13 +148,28 @@ PA_FUNC_ATTRIBUTE(pure)
PA_FUNC_ATTRIBUTE_ERROR
dnl
dnl support cchace
dnl support ccache
dnl
AC_ARG_ENABLE([ccache],
[AC_HELP_STRING([--with-ccache], [compile with ccache])],
[AC_HELP_STRING([--enable-ccache], [compile with ccache])],
[CC="ccache $CC"],
[])
dnl
dnl support LTO
dnl
AC_ARG_ENABLE([lto],
[AC_HELP_STRING([--enable-lto], [compile with gcc link time optimization])],
[PA_ADD_CLDFLAGS([-flto])
dnl Note: we use _PROG rather than _TOOL since we are prepending the full
dnl CC name which ought to already contain the host triplet if needed
ccbase=`echo "$CC" | awk '{ print $1; }'`
AC_CHECK_PROG(CC_AR, [${ccbase}-ar], [${ccbase}-ar], [$ac_cv_prog_AR])
AR="$CC_AR"
AC_CHECK_PROG(CC_RANLIB, [${ccbase}-ranlib], [${ccbase}-ranlib], [$ac_cv_prog_RANLIB])
RANLIB="$CC_RANLIB"
], [])
dnl If we have gcc, add appropriate code cleanliness options
PA_ADD_CFLAGS([-W])
PA_ADD_CFLAGS([-Wall])