[gnome-builder] build: fix building with lto and gcc
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] build: fix building with lto and gcc
- Date: Sat, 9 May 2015 22:50:25 +0000 (UTC)
commit be6d9270689e709004904b0c0f4055ce2d80c620
Author: Patrick Griffis <tingping tingping se>
Date: Sat May 9 18:06:49 2015 -0400
build: fix building with lto and gcc
build/autotools/ax_compiler_vendor.m4 | 87 +++++++++++++++++++++++++++++++++
build/autotools/gb_enable_lto.m4 | 78 +++++++++++++++++++++++++++++
configure.ac | 10 ++--
3 files changed, 171 insertions(+), 4 deletions(-)
---
diff --git a/build/autotools/ax_compiler_vendor.m4 b/build/autotools/ax_compiler_vendor.m4
new file mode 100644
index 0000000..39ca3c0
--- /dev/null
+++ b/build/autotools/ax_compiler_vendor.m4
@@ -0,0 +1,87 @@
+# ===========================================================================
+# http://www.gnu.org/software/autoconf-archive/ax_compiler_vendor.html
+# ===========================================================================
+#
+# SYNOPSIS
+#
+# AX_COMPILER_VENDOR
+#
+# DESCRIPTION
+#
+# Determine the vendor of the C/C++ compiler, e.g., gnu, intel, ibm, sun,
+# hp, borland, comeau, dec, cray, kai, lcc, metrowerks, sgi, microsoft,
+# watcom, etc. The vendor is returned in the cache variable
+# $ax_cv_c_compiler_vendor for C and $ax_cv_cxx_compiler_vendor for C++.
+#
+# LICENSE
+#
+# Copyright (c) 2008 Steven G. Johnson <stevenj alum mit edu>
+# Copyright (c) 2008 Matteo Frigo
+#
+# This program is free software: you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by the
+# Free Software Foundation, either version 3 of the License, or (at your
+# option) any later version.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
+# Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+# As a special exception, the respective Autoconf Macro's copyright owner
+# gives unlimited permission to copy, distribute and modify the configure
+# scripts that are the output of Autoconf when processing the Macro. You
+# need not follow the terms of the GNU General Public License when using
+# or distributing such scripts, even though portions of the text of the
+# Macro appear in them. The GNU General Public License (GPL) does govern
+# all other use of the material that constitutes the Autoconf Macro.
+#
+# This special exception to the GPL applies to versions of the Autoconf
+# Macro released by the Autoconf Archive. When you make and distribute a
+# modified version of the Autoconf Macro, you may extend this special
+# exception to the GPL to apply to your modified version as well.
+
+#serial 15
+
+AC_DEFUN([AX_COMPILER_VENDOR],
+[AC_CACHE_CHECK([for _AC_LANG compiler vendor], ax_cv_[]_AC_LANG_ABBREV[]_compiler_vendor,
+ dnl Please add if possible support to ax_compiler_version.m4
+ [# note: don't check for gcc first since some other compilers define __GNUC__
+ vendors="intel: __ICC,__ECC,__INTEL_COMPILER
+ ibm: __xlc__,__xlC__,__IBMC__,__IBMCPP__
+ pathscale: __PATHCC__,__PATHSCALE__
+ clang: __clang__
+ cray: _CRAYC
+ fujitsu: __FUJITSU
+ gnu: __GNUC__
+ sun: __SUNPRO_C,__SUNPRO_CC
+ hp: __HP_cc,__HP_aCC
+ dec: __DECC,__DECCXX,__DECC_VER,__DECCXX_VER
+ borland: __BORLANDC__,__CODEGEARC__,__TURBOC__
+ comeau: __COMO__
+ kai: __KCC
+ lcc: __LCC__
+ sgi: __sgi,sgi
+ microsoft: _MSC_VER
+ metrowerks: __MWERKS__
+ watcom: __WATCOMC__
+ portland: __PGI
+ tcc: __TINYC__
+ unknown: UNKNOWN"
+ for ventest in $vendors; do
+ case $ventest in
+ *:) vendor=$ventest; continue ;;
+ *) vencpp="defined("`echo $ventest | sed 's/,/) || defined(/g'`")" ;;
+ esac
+ AC_COMPILE_IFELSE([AC_LANG_PROGRAM(,[
+ #if !($vencpp)
+ thisisanerror;
+ #endif
+ ])], [break])
+ done
+ ax_cv_[]_AC_LANG_ABBREV[]_compiler_vendor=`echo $vendor | cut -d: -f1`
+ ])
+])
diff --git a/build/autotools/gb_enable_lto.m4 b/build/autotools/gb_enable_lto.m4
new file mode 100644
index 0000000..3bdead7
--- /dev/null
+++ b/build/autotools/gb_enable_lto.m4
@@ -0,0 +1,78 @@
+#
+# SYNOPSIS
+#
+# GB_ENABLE_LTO
+#
+# DESCRIPTION
+#
+# Enables support for link time optimization. $LTO_CFLAGS and $enable_lto
+# is exported for you to use.
+#
+# Note: This may or may not override some variables such as AR,
+# RANLIB, or NM.
+#
+# LICENSE
+#
+# Copyright (c) 2015 Patrick Griffis <tingping tingping se>
+#
+# This program is free software: you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by the
+# Free Software Foundation, either version 3 of the License, or (at your
+# option) any later version.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
+# Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+# As a special exception, the respective Autoconf Macro's copyright owner
+# gives unlimited permission to copy, distribute and modify the configure
+# scripts that are the output of Autoconf when processing the Macro. You
+# need not follow the terms of the GNU General Public License when using
+# or distributing such scripts, even though portions of the text of the
+# Macro appear in them. The GNU General Public License (GPL) does govern
+# all other use of the material that constitutes the Autoconf Macro.
+#
+# This special exception to the GPL applies to versions of the Autoconf
+# Macro released by the Autoconf Archive. When you make and distribute a
+# modified version of the Autoconf Macro, you may extend this special
+# exception to the GPL to apply to your modified version as well.
+
+#serial 4
+
+AC_DEFUN([GB_ENABLE_LTO], [
+ AC_ARG_ENABLE([lto], [AC_HELP_STRING([--enable-lto], [turn on link time optimizations [default=no]])],
+ [enable_lto=$enableval], [enable_lto=no])
+
+ AX_REQUIRE_DEFINED([AX_CHECK_COMPILE_FLAG])
+ AX_REQUIRE_DEFINED([AX_COMPILER_VENDOR])
+
+ AS_IF([test "$enable_lto" = "yes"], [
+ AX_COMPILER_VENDOR
+ AS_CASE([$ax_cv_c_compiler_vendor],
+ [gnu], [
+ AC_PATH_PROG([GCC_AR], [gcc-ar], [no])
+ AC_PATH_PROG([GCC_NM], [gcc-nm], [no])
+ AC_PATH_PROG([GCC_RANLIB], [gcc-ranlib], [no])
+ AX_CHECK_COMPILE_FLAG([-flto], [LTO_CFLAGS=-flto], [LTO_CLFAGS=no])
+ AS_IF([test "$GCC_AR" = "no" || test "$GCC_NM" = "no" || test "$GCC_RANLIB" = "no" ||
test "$LTO_CFLAGS" = "no"], [
+ enable_lto=no
+ ], [
+ dnl this just overwrites variables which may not be ideal..
+ AR="$GCC_AR"
+ NM="$GCC_NM"
+ RANLIB="$GCC_RANLIB"
+ AC_SUBST([AR])
+ AC_SUBST([NM])
+ AC_SUBST([RANLIB])
+ AC_SUBST([LTO_CFLAGS])
+ ])
+ ], [
+ AC_MSG_ERROR([Currently only gcc is supported for --enable-lto])
+ ])
+ ])
+])
+
diff --git a/configure.ac b/configure.ac
index 894be32..f34ed33 100644
--- a/configure.ac
+++ b/configure.ac
@@ -205,7 +205,6 @@ LT_PREREQ([2.2])
LT_INIT
-
dnl ***********************************************************************
dnl Additional C Compiler Flags
dnl ***********************************************************************
@@ -298,10 +297,13 @@ OPTIMIZE_LDFLAGS=""
AS_IF([test "$enable_optimizations" != "no"],
[AX_CHECK_LINK_FLAG([-Wl,-Bsymbolic],
[OPTIMIZE_LDFLAGS="$OPTIMIZE_LDFLAGS -Wl,-Bsymbolic"])])
+
+
# Enable Link-Time-Optimization
-AS_IF([test "$enable_lto" = "yes"], [
- AX_CHECK_COMPILE_FLAG([-flto], [OPTIMIZE_CFLAGS="$OPTIMIZE_CFLAGS -flto"], [enable_lto=no])
-])
+GB_ENABLE_LTO
+OPTIMIZE_CFLAGS="$OPTIMIZE_CFLAGS $LTO_CFLAGS"
+
+
AC_SUBST(OPTIMIZE_CFLAGS)
AC_SUBST(OPTIMIZE_LDFLAGS)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]