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 <hpa@zytor.com>
This commit is contained in:
H. Peter Anvin 2024-04-16 16:30:48 -07:00
parent b11802c425
commit 2d2ae91d7a
5 changed files with 25 additions and 8 deletions

View File

@ -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],
[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([flag], [$1],
m4_foreach_w([_pa_flag], _pa_langflags,
[AS_IF([test $_pa_flag_found = no],
[PA_ADD_FLAGS(_PA_LANGFLAG_VAR(lang),flag,[],[_pa_flag_found=yes])])
])])])
[PA_ADD_FLAGS(_PA_LANGFLAG_VAR(_pa_lang),_pa_flag,[],[_pa_flag_found=yes])])
])])
m4_popdef([_pa_langflags])])

View File

@ -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; }'`

13
autoconf/m4/pa_prog_cc.m4 Normal file
View File

@ -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"])])

View File

@ -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

View File

@ -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], [], [],