From 2d2ae91d7aec3097a43a896b66ba5c6952ea743a Mon Sep 17 00:00:00 2001 From: "H. Peter Anvin" Date: Tue, 16 Apr 2024 16:30:48 -0700 Subject: [PATCH] autoconf: unbreak --enable-lto, fix some language macros PA_ADD_LANGFLAGS() was broken, resulting in among other things --enable-lto not working. Make autogen.sh fail if aclocal return error. Signed-off-by: H. Peter Anvin --- autoconf/m4/pa_add_langflags.m4 | 14 ++++++++------ autoconf/m4/pa_option_lto.m4 | 3 ++- autoconf/m4/pa_prog_cc.m4 | 13 +++++++++++++ autogen.sh | 1 + configure.ac | 2 +- 5 files changed, 25 insertions(+), 8 deletions(-) create mode 100644 autoconf/m4/pa_prog_cc.m4 diff --git a/autoconf/m4/pa_add_langflags.m4 b/autoconf/m4/pa_add_langflags.m4 index cc2baded..05c3114f 100644 --- a/autoconf/m4/pa_add_langflags.m4 +++ b/autoconf/m4/pa_add_langflags.m4 @@ -17,9 +17,11 @@ m4_defun([_PA_LANGFLAG_VAR], [m4_fatal([PA_ADD_LANGFLAGS: Unknown language: $1])])]) AC_DEFUN([PA_ADD_LANGFLAGS], -[m4_set_foreach(PA_LANG_SEEN_SET, [lang], - [_pa_flag_found=no - m4_foreach_w([flag], [$1], - [AS_IF([test $_pa_flag_found = no], - [PA_ADD_FLAGS(_PA_LANGFLAG_VAR(lang),flag,[],[_pa_flag_found=yes])]) - ])])]) +[m4_pushdef([_pa_langflags],m4_dquote($1))dnl +m4_set_foreach(_PA_LANG_SEEN_SET,[_pa_lang],dnl +[_pa_flag_found=no + m4_foreach_w([_pa_flag], _pa_langflags, + [AS_IF([test $_pa_flag_found = no], + [PA_ADD_FLAGS(_PA_LANGFLAG_VAR(_pa_lang),_pa_flag,[],[_pa_flag_found=yes])]) + ])]) +m4_popdef([_pa_langflags])]) diff --git a/autoconf/m4/pa_option_lto.m4 b/autoconf/m4/pa_option_lto.m4 index b33b9c09..ea5456b6 100644 --- a/autoconf/m4/pa_option_lto.m4 +++ b/autoconf/m4/pa_option_lto.m4 @@ -10,7 +10,8 @@ AC_DEFUN([PA_OPTION_LTO], [PA_ARG_BOOL([lto], [Try to enable link-time optimization for this compiler], [$1], - [PA_ADD_LANGFLAGS([-flto]) + [PA_ADD_LANGFLAGS([-flto=auto -flto]) +PA_ADD_LANGFLAGS([-ffat-lto-objects]) 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; }'` diff --git a/autoconf/m4/pa_prog_cc.m4 b/autoconf/m4/pa_prog_cc.m4 new file mode 100644 index 00000000..0debe5d4 --- /dev/null +++ b/autoconf/m4/pa_prog_cc.m4 @@ -0,0 +1,13 @@ +dnl -------------------------------------------------------------------------- +dnl PA_PROG_CC() +dnl +dnl Similar to AC_PROG_CC, but add a prototype for main() to +dnl AC_INCLUDES_DEFAULT to avoid -Werror from breaking compilation. +dnl -------------------------------------------------------------------------- +AC_DEFUN([PA_PROG_CC], +[AC_PROG_CC + AS_IF([test x$ac_cv_prog != xno], + [ac_includes_default="$ac_includes_default +#ifndef __cplusplus +extern int main(void); +#endif"])]) diff --git a/autogen.sh b/autogen.sh index 4260471c..0c892cc2 100755 --- a/autogen.sh +++ b/autogen.sh @@ -53,6 +53,7 @@ if test ! -f autoconf/aclocal.m4; then # aclocal failed, revert to previous files mv -f autoconf/m4.old/*.m4 autoconf/m4/ mv -f autoconf/aclocal.m4.old autoconf/aclocal.m4 + exit 1 fi rm -rf autoconf/*m4.old "$AUTOHEADER" -B autoconf diff --git a/configure.ac b/configure.ac index e30125b2..77c72be5 100644 --- a/configure.ac +++ b/configure.ac @@ -18,7 +18,7 @@ dnl the best very slow and doesn't buy us a single thing at all. PA_CROSS_COMPILE dnl Enable any available C extensions -AC_PROG_CC +PA_PROG_CC AC_USE_SYSTEM_EXTENSIONS PA_ADD_CPPFLAGS([-std=c17], [], [], [PA_ADD_CPPFLAGS([-std=c11], [], [],