autoconf: modernize autoconf and update a lot of m4 macros

This commit is contained in:
H. Peter Anvin 2023-10-11 10:19:16 -07:00
parent b9528913aa
commit 0e96487608
18 changed files with 261 additions and 117 deletions

1
.gitignore vendored
View File

@ -108,3 +108,4 @@ TAGS
/autoconf/compile
/autoconf/config.*
/autoconf/install-sh
/autoconf/clean.sh

38
autoconf/attribute.h Normal file
View File

@ -0,0 +1,38 @@
/*
* Define a macro for compiler attributes. Use either gcc
* syntax if __GNUC__ is defined, or try to look for the
* modern standard [[x]] attributes.
*
* Unfortunately [[x]] doesn't always work when it comes to
* GNUC-specific attributes, and some compilers support GCC
* syntax without __attribute__ just to be confusing.
* Therefore, this also needs an autoconf module to test
* the validity.
*
* Use #ifdef and not defined() here; some compilers do the wrong
* thing in the latter case.
*/
#ifndef ATTRIBUTE
# define MODERN_ATTRIBUTE(x) [[x]]
# ifndef __GNUC__
# ifdef __cplusplus
# ifdef __has_cpp_attribute
# define ATTRIBUTE(x) MODERN_ATTRIBUTE(x)
# endif
# endif
# ifndef ATTRIBUTE
# ifdef __has_c_attribute
# define ATTRIBUTE(x) MODERN_ATTRIBUTE(x)
# endif
# endif
# ifndef ATTRIBUTE
# ifdef __has_attribute
# define ATTRIBUTE(x) MODERN_ATTRIBUTE(x)
# endif
# endif
# endif
# ifndef ATTRIBUTE
# define ATTRIBUTE(x) __attribute__((x))
# endif
#endif

View File

@ -0,0 +1,25 @@
dnl --------------------------------------------------------------------------
dnl PA_ADD_LANGFLAGS(flag...)
dnl
dnl Attempt to add the option in the given list to each compiler flags
dnl (CFLAGS, CXXFLAGS, ...), if it doesn't break compilation.
dnl --------------------------------------------------------------------------
m4_defun([_PA_LANGFLAG_VAR],
[m4_case([$1],
[C], [CFLAGS],
[C++], [CXXFLAGS],
[Fortran 77], [FFLAGS],
[Fortran], [FCFLAGS],
[Erlang], [ERLCFLAGS],
[Objective C], [OBJCFLAGS],
[Objective C++], [OBJCXXFLAGS],
[Go], [GOFLAGS],
[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])])
])])])

View File

@ -0,0 +1,11 @@
dnl --------------------------------------------------------------------------
dnl PA_ATTRIBUTE_SYNTAX
dnl
dnl Source code fragment to test for attribute syntax
dnl The use of #ifdef rather than defined() here is intentional:
dnl defined() is known to not always work right.
dnl --------------------------------------------------------------------------
AC_DEFUN([PA_ATTRIBUTE_SYNTAX],
[#include "autoconf/attribute.h"
])

View File

@ -0,0 +1,19 @@
dnl --------------------------------------------------------------------------
dnl PA_COMMON_ATTRIBUTES
dnl
dnl Test for a bunch of common function attributes and define macros for them.
dnl --------------------------------------------------------------------------
AC_DEFUN([PA_COMMON_ATTRIBUTES],
[PA_ADD_CPPFLAGS([-Werror=attributes])
PA_FUNC_ATTRIBUTE(noreturn)
PA_FUNC_ATTRIBUTE(returns_nonnull,,[void *],,,never_null)
PA_FUNC_ATTRIBUTE(malloc,,[void *])
PA_FUNC_ATTRIBUTE(alloc_size,[1],[void *],[int],[80])
PA_FUNC_ATTRIBUTE(alloc_size,[1,2],[void *],[int,int],[20,40])
PA_FUNC_ATTRIBUTE(sentinel,,,[const char *, ...],["a","b",NULL],end_with_null)
PA_FUNC_ATTRIBUTE(format,[printf,1,2],int,[const char *, ...],["%d",1])
PA_FUNC_ATTRIBUTE(const)
PA_FUNC_ATTRIBUTE(pure)
PA_FUNC_ATTRIBUTE(cold,,,,,unlikely_func)
PA_FUNC_ATTRIBUTE(unused)
PA_FUNC_ATTRIBUTE_ERROR])

32
autoconf/m4/pa_endian.m4 Normal file
View File

@ -0,0 +1,32 @@
dnl --------------------------------------------------------------------------
dnl PA_ENDIAN
dnl
dnl Test for a bunch of variants of endian tests and byteorder functions.
dnl --------------------------------------------------------------------------
AC_DEFUN([PA_ENDIAN],
[AC_C_BIGENDIAN(AC_DEFINE(WORDS_BIGENDIAN),AC_DEFINE(WORDS_LITTLEENDIAN),,)
AH_TEMPLATE(WORDS_BIGENDIAN,
[Define to 1 if your processor stores words with the most significant
byte first (like Motorola and SPARC, unlike Intel and VAX).])
AH_TEMPLATE(WORDS_LITTLEENDIAN,
[Define to 1 if your processor stores words with the least significant
byte first (like Intel and VAX, unlike Motorola and SPARC).])
PA_ADD_HEADERS(endian.h sys/endian.h machine/endian.h)
PA_HAVE_FUNC(cpu_to_le16, (0))
PA_HAVE_FUNC(cpu_to_le32, (0))
PA_HAVE_FUNC(cpu_to_le64, (0))
PA_HAVE_FUNC(__cpu_to_le16, (0))
PA_HAVE_FUNC(__cpu_to_le32, (0))
PA_HAVE_FUNC(__cpu_to_le64, (0))
PA_HAVE_FUNC(htole16, (0))
PA_HAVE_FUNC(htole32, (0))
PA_HAVE_FUNC(htole64, (0))
PA_HAVE_FUNC(__bswap_16, (0))
PA_HAVE_FUNC(__bswap_32, (0))
PA_HAVE_FUNC(__bswap_64, (0))
PA_HAVE_FUNC(__builtin_bswap16, (0))
PA_HAVE_FUNC(__builtin_bswap32, (0))
PA_HAVE_FUNC(__builtin_bswap64, (0))
PA_HAVE_FUNC(_byteswap_ushort, (0))
PA_HAVE_FUNC(_byteswap_ulong, (0))
PA_HAVE_FUNC(_byteswap_uint64, (0))])

View File

@ -20,7 +20,9 @@ AC_DEFUN([_PA_FUNC_ATTRIBUTE],
AC_MSG_CHECKING([if $CC supports the $1]_pa_faa[ function attribute])
AC_COMPILE_IFELSE([AC_LANG_SOURCE([
AC_INCLUDES_DEFAULT
extern ifelse([$3],[],[void *],[$3]) __attribute__(([$1]_pa_faa))
PA_ATTRIBUTE_SYNTAX
extern ifelse([$3],[],[void *],[$3]) ATTRIBUTE([$1]_pa_faa)
bar(ifelse([$4],[],[int],[$4]));
ifelse([$3],[],[void *],[$3]) foo(void);
ifelse([$3],[],[void *],[$3]) foo(void)
@ -31,12 +33,12 @@ ifelse([$3],[],[void *],[$3]) foo(void)
])],
[AC_MSG_RESULT([yes])
AC_DEFINE(PA_SYM([HAVE_FUNC_ATTRIBUTE],_pa_suf,[_$1]), 1,
[Define to 1 if your compiler supports __attribute__(($1)) on functions])],
[Define to 1 if your compiler supports the $1 function attribute])],
[AC_MSG_RESULT([no])])
AH_BOTTOM(m4_quote(m4_join([],
[#ifndef ],_pa_mac,[
# ifdef ],PA_SYM([HAVE_FUNC_ATTRIBUTE],_pa_suf,[_$1]),[
# define ],_pa_mac,m4_quote(_pa_fam),[ __attribute__(($1],m4_quote(_pa_fam),[))
# define ],_pa_mac,m4_quote(_pa_fam),[ ATTRIBUTE($1],m4_quote(_pa_fam),[)
# else
# define ],_pa_mac,m4_quote(_pa_fam),[
# endif
@ -51,7 +53,9 @@ AC_DEFUN([_PA_FUNC_PTR_ATTRIBUTE],
AC_MSG_CHECKING([if $CC supports the $1]_pa_faa[ function attribute on pointers])
AC_COMPILE_IFELSE([AC_LANG_SOURCE([
AC_INCLUDES_DEFAULT
extern ifelse([$3],[],[void *],[$3]) __attribute__(([$1]_pa_faa))
PA_ATTRIBUTE_SYNTAX
extern ifelse([$3],[],[void *],[$3]) ATTRIBUTE([$1]_pa_faa)
(*bar1)(ifelse([$4],[],[int],[$4]));
ifelse([$3],[],[void *],[$3]) foo1(void);
ifelse([$3],[],[void *],[$3]) foo1(void)
@ -60,7 +64,7 @@ ifelse([$3],[],[void *],[$3]) foo1(void)
bar1(ifelse([$5],[],[1],[$5]));
}
typedef ifelse([$3],[],[void *],[$3]) __attribute__(([$1]_pa_faa))
typedef ifelse([$3],[],[void *],[$3]) ATTRIBUTE([$1]_pa_faa)
(*bar_t)(ifelse([$4],[],[int],[$4]));
extern bar_t bar2;
ifelse([$3],[],[void *],[$3]) foo2(void);
@ -72,12 +76,12 @@ ifelse([$3],[],[void *],[$3]) foo2(void)
])],
[AC_MSG_RESULT([yes])
AC_DEFINE(PA_SYM([HAVE_FUNC_PTR_ATTRIBUTE],_pa_suf,[_$1]), 1,
[Define to 1 if your compiler supports __attribute__(($1)) on function pointers])],
[Define to 1 if your compiler supports the $1 attribute on function pointers])],
[AC_MSG_RESULT([no])])
AH_BOTTOM(m4_quote(m4_join([],
[#ifndef ],_pa_mac,[
# ifdef ],PA_SYM([HAVE_FUNC_PTR_ATTRIBUTE],_pa_suf,[_$1]),[
# define ],_pa_mac,m4_quote(_pa_fam),[ __attribute__(($1],m4_quote(_pa_fam),[))
# define ],_pa_mac,m4_quote(_pa_fam),[ ATTRIBUTE($1],m4_quote(_pa_fam),[)
# else
# define ],_pa_mac,m4_quote(_pa_fam),[
# endif

View File

@ -1,7 +1,9 @@
dnl --------------------------------------------------------------------------
dnl PA_FUNC_ATTRIBUTE_ERROR
dnl
dnl See if this compiler supports __attribute__((error("foo")))
dnl See if this compiler supports __attribute__((error("foo"))) *and*
dnl does *not* error if the erroneous call is unreachable.
dnl
dnl The generic version of this doesn't work as it makes the compiler
dnl throw an error by design.
dnl
@ -12,7 +14,9 @@ AC_DEFUN([PA_FUNC_ATTRIBUTE_ERROR],
[AC_MSG_CHECKING([if $CC supports the error function attribute])
AC_COMPILE_IFELSE([AC_LANG_SOURCE([
AC_INCLUDES_DEFAULT
extern void __attribute__((error("message"))) barf(void);
PA_ATTRIBUTE_SYNTAX
extern ATTRIBUTE(error("message")) void barf(void);
void foo(void);
void foo(void)
{
@ -22,6 +26,6 @@ void foo(void)
])],
[AC_MSG_RESULT([yes])
AC_DEFINE([HAVE_FUNC_ATTRIBUTE_ERROR], 1,
[Define to 1 if your compiler supports __attribute__((error)) on functions])],
[Define to 1 if your compiler supports the error attribute on functions])],
[AC_MSG_RESULT([no])])
])

View File

@ -0,0 +1,13 @@
dnl --------------------------------------------------------------------------
dnl PA_OPTION_DEBUG(with_debug, without_debug)
dnl
dnl Set debug flags and optimization flags depending on if
dnl --enable-debug is set or not. Some flags are set regardless...
dnl --------------------------------------------------------------------------
AC_DEFUN([PA_OPTION_DEBUG],
[PA_ARG_DISABLED([gdb], [disable gdb debug extensions],
[PA_ADD_LANGFLAGS([-g3])], [PA_ADD_LANGFLAGS([-ggdb3 -g3])])
PA_ARG_ENABLED([debug], [optimize for debugging],
[PA_ADD_LANGFLAGS([-Og -O0])
$1],
[$2])])

View File

@ -0,0 +1,14 @@
dnl --------------------------------------------------------------------------
dnl PA_OPTION_GC
dnl
dnl Option to compile with garbage collection; currently only supports
dnl gcc/ELF. Enabled by default.
dnl --------------------------------------------------------------------------
AC_DEFUN([PA_OPTION_GC],
[PA_ARG_DISABLED([gc],
[do not compile with dead code garbage collection support],
[],
[PA_ADD_LDFLAGS([-Wl,--as-needed])
PA_ADD_CFLAGS([-ffunction-sections])
PA_ADD_CFLAGS([-fdata-sections])
PA_ADD_LDFLAGS([-Wl,--gc-sections])])])

View File

@ -0,0 +1,20 @@
dnl --------------------------------------------------------------------------
dnl PA_OPTION_LTO(default)
dnl
dnl Try to enable link-time optimization. Enable it by default if
dnl the "default" argument is set to "yes"; currently the default is "no",
dnl but that could change in the future -- to force disabled by default,
dnl set to "no".
dnl --------------------------------------------------------------------------
AC_DEFUN([PA_OPTION_LTO],
[PA_ARG_BOOL([lto],
[Try to enable link-time optimization for this compiler],
[$1],
[PA_ADD_LANGFLAGS([-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_PROGS(CC_AR, [${ccbase}-ar], [$ac_cv_prog_AR])
AR="$CC_AR"
AC_CHECK_PROGS(CC_RANLIB, [${ccbase}-ranlib], [$ac_cv_prog_RANLIB])
RANLIB="$CC_RANLIB"])])

View File

@ -0,0 +1,8 @@
dnl --------------------------------------------------------------------------
dnl PA_OPTION_PROFILING(with_profiling, without_profiling)
dnl
dnl Try to enable profiling if --enable-profiling is set.
dnl --------------------------------------------------------------------------
AC_DEFUN([PA_OPTION_PROFILING],
[PA_ARG_ENABLED([profiling], [compile with profiling (-pg option)],
[PA_ADD_LANGFLAGS([-pg])])])

View File

@ -0,0 +1,11 @@
dnl --------------------------------------------------------------------------
dnl PA_OPTION_SANITIZER
dnl
dnl Option to compile with sanitizers enabled.
dnl --------------------------------------------------------------------------
AC_DEFUN([PA_OPTION_SANITIZER],
[PA_ARG_ENABLED([sanitizer],
[compile with sanitizers enabled],
[PA_ADD_CFLAGS([-fno-omit-frame-pointer])
PA_ADD_CFLAGS([-fsanitize=address])
PA_ADD_CFLAGS([-fsanitize=undefined])])])

View File

@ -2,7 +2,10 @@ dnl --------------------------------------------------------------------------
dnl PA_SYM(prefix, string)
dnl
dnl Convert a (semi-) arbitrary string to a CPP symbol
dnl Compact underscores and convert non-C characters to underscore,
dnl except + which is converted to X (so C++ -> CXX).
dnl --------------------------------------------------------------------------
AC_DEFUN([PA_SYM],
[m4_bpatsubsts(m4_quote(m4_toupper([$*])),
[,],[],[[^ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789]+],[_],[^._?\(.*\)_.$],[[\1]])])
[,],[],[\+],[X],[[^ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789]+],[_],dnl
[^._?\(.*\)_.$],[[\1]])])

View File

@ -57,8 +57,21 @@ fi
rm -rf autoconf/*m4.old
"$AUTOHEADER" -B autoconf
"$AUTOCONF" -B autoconf
rm -rf autom4te.cache config.log config.status \
config/config.h Makefile doc/Makefile
(
echo '#!/bin/sh'
"$AUTOCONF" -B autoconf \
-t AC_CONFIG_HEADERS:'rm -f $*' \
-t AC_CONFIG_FILES:'rm -f $*'
echo 'rm -f config.log config.status'
echo 'rm -rf autom4te.cache'
) > autoconf/clean.sh
sh autoconf/clean.sh
# Try to regenerate unconfig.h if Perl is available and unconfig.pl
# is present in the autoconf directory.
if [ -n "$(which perl)" -a -f autoconf/unconfig.pl ]; then
perl autoconf/unconfig.pl . config/config.h.in config/unconfig.h
fi
if $recheck; then
# This bizarre statement has to do with how config.status quotes its output

View File

@ -5,7 +5,7 @@
#ifndef alloc_size_func2
# ifdef HAVE_FUNC_ATTRIBUTE2_ALLOC_SIZE
# define alloc_size_func2(x1,x2) __attribute__((alloc_size(x1,x2)))
# define alloc_size_func2(x1,x2) ATTRIBUTE(alloc_size(x1,x2))
# else
# define alloc_size_func2(x1,x2)
# endif
@ -13,7 +13,7 @@
#ifndef alloc_size_func2_ptr
# ifdef HAVE_FUNC_PTR_ATTRIBUTE2_ALLOC_SIZE
# define alloc_size_func2_ptr(x1,x2) __attribute__((alloc_size(x1,x2)))
# define alloc_size_func2_ptr(x1,x2) ATTRIBUTE(alloc_size(x1,x2))
# else
# define alloc_size_func2_ptr(x1,x2)
# endif
@ -21,7 +21,7 @@
#ifndef end_with_null
# ifdef HAVE_FUNC_ATTRIBUTE_SENTINEL
# define end_with_null __attribute__((sentinel))
# define end_with_null ATTRIBUTE(sentinel)
# else
# define end_with_null
# endif
@ -29,7 +29,7 @@
#ifndef end_with_null_ptr
# ifdef HAVE_FUNC_PTR_ATTRIBUTE_SENTINEL
# define end_with_null_ptr __attribute__((sentinel))
# define end_with_null_ptr ATTRIBUTE(sentinel)
# else
# define end_with_null_ptr
# endif
@ -37,7 +37,7 @@
#ifndef format_func3
# ifdef HAVE_FUNC_ATTRIBUTE3_FORMAT
# define format_func3(x1,x2,x3) __attribute__((format(x1,x2,x3)))
# define format_func3(x1,x2,x3) ATTRIBUTE(format(x1,x2,x3))
# else
# define format_func3(x1,x2,x3)
# endif
@ -45,7 +45,7 @@
#ifndef format_func3_ptr
# ifdef HAVE_FUNC_PTR_ATTRIBUTE3_FORMAT
# define format_func3_ptr(x1,x2,x3) __attribute__((format(x1,x2,x3)))
# define format_func3_ptr(x1,x2,x3) ATTRIBUTE(format(x1,x2,x3))
# else
# define format_func3_ptr(x1,x2,x3)
# endif
@ -53,7 +53,7 @@
#ifndef const_func
# ifdef HAVE_FUNC_ATTRIBUTE_CONST
# define const_func __attribute__((const))
# define const_func ATTRIBUTE(const)
# else
# define const_func
# endif
@ -61,7 +61,7 @@
#ifndef const_func_ptr
# ifdef HAVE_FUNC_PTR_ATTRIBUTE_CONST
# define const_func_ptr __attribute__((const))
# define const_func_ptr ATTRIBUTE(const)
# else
# define const_func_ptr
# endif
@ -69,7 +69,7 @@
#ifndef pure_func
# ifdef HAVE_FUNC_ATTRIBUTE_PURE
# define pure_func __attribute__((pure))
# define pure_func ATTRIBUTE(pure)
# else
# define pure_func
# endif
@ -77,7 +77,7 @@
#ifndef pure_func_ptr
# ifdef HAVE_FUNC_PTR_ATTRIBUTE_PURE
# define pure_func_ptr __attribute__((pure))
# define pure_func_ptr ATTRIBUTE(pure)
# else
# define pure_func_ptr
# endif
@ -85,7 +85,7 @@
#ifndef noreturn_func
# ifdef HAVE_FUNC_ATTRIBUTE_NORETURN
# define noreturn_func __attribute__((noreturn))
# define noreturn_func ATTRIBUTE(noreturn)
# else
# define noreturn_func
# endif
@ -93,7 +93,7 @@
#ifndef unlikely_func
# ifdef HAVE_FUNC_ATTRIBUTE_COLD
# define unlikely_func __attribute__((cold))
# define unlikely_func ATTRIBUTE(cold)
# else
# define unlikely_func
# endif
@ -101,7 +101,7 @@
#ifndef unlikely_func_ptr
# ifdef HAVE_FUNC_PTR_ATTRIBUTE_COLD
# define unlikely_func_ptr __attribute__((cold))
# define unlikely_func_ptr ATTRIBUTE(cold)
# else
# define unlikely_func_ptr
# endif
@ -109,7 +109,7 @@
#ifndef unused_func
# ifdef HAVE_FUNC_ATTRIBUTE_UNUSED
# define unused_func __attribute__((unused))
# define unused_func ATTRIBUTE(unused)
# else
# define unused_func
# endif
@ -117,7 +117,7 @@
#ifndef unused_func_ptr
# ifdef HAVE_FUNC_PTR_ATTRIBUTE_UNUSED
# define unused_func_ptr __attribute__((unused))
# define unused_func_ptr ATTRIBUTE(unused)
# else
# define unused_func_ptr
# endif
@ -125,7 +125,7 @@
#ifndef noreturn_func_ptr
# ifdef HAVE_FUNC_PTR_ATTRIBUTE_NORETURN
# define noreturn_func_ptr __attribute__((noreturn))
# define noreturn_func_ptr ATTRIBUTE(noreturn)
# else
# define noreturn_func_ptr
# endif
@ -133,7 +133,7 @@
#ifndef never_null
# ifdef HAVE_FUNC_ATTRIBUTE_RETURNS_NONNULL
# define never_null __attribute__((returns_nonnull))
# define never_null ATTRIBUTE(returns_nonnull)
# else
# define never_null
# endif
@ -141,7 +141,7 @@
#ifndef never_null_ptr
# ifdef HAVE_FUNC_PTR_ATTRIBUTE_RETURNS_NONNULL
# define never_null_ptr __attribute__((returns_nonnull))
# define never_null_ptr ATTRIBUTE(returns_nonnull)
# else
# define never_null_ptr
# endif
@ -149,7 +149,7 @@
#ifndef malloc_func
# ifdef HAVE_FUNC_ATTRIBUTE_MALLOC
# define malloc_func __attribute__((malloc))
# define malloc_func ATTRIBUTE(malloc)
# else
# define malloc_func
# endif
@ -157,7 +157,7 @@
#ifndef malloc_func_ptr
# ifdef HAVE_FUNC_PTR_ATTRIBUTE_MALLOC
# define malloc_func_ptr __attribute__((malloc))
# define malloc_func_ptr ATTRIBUTE(malloc)
# else
# define malloc_func_ptr
# endif
@ -165,7 +165,7 @@
#ifndef alloc_size_func1
# ifdef HAVE_FUNC_ATTRIBUTE1_ALLOC_SIZE
# define alloc_size_func1(x1) __attribute__((alloc_size(x1)))
# define alloc_size_func1(x1) ATTRIBUTE(alloc_size(x1))
# else
# define alloc_size_func1(x1)
# endif
@ -173,7 +173,7 @@
#ifndef alloc_size_func1_ptr
# ifdef HAVE_FUNC_PTR_ATTRIBUTE1_ALLOC_SIZE
# define alloc_size_func1_ptr(x1) __attribute__((alloc_size(x1)))
# define alloc_size_func1_ptr(x1) ATTRIBUTE(alloc_size(x1))
# else
# define alloc_size_func1_ptr(x1)
# endif

View File

@ -1,4 +1,4 @@
dnl Process this file with autoconf 2.69 or later to produce
dnl Process this file with autoconf 2.71 or later to produce
dnl a configure script.
AC_PREREQ([2.71])
AC_INIT
@ -28,21 +28,9 @@ PA_ADD_CPPFLAGS([-std=c17], [], [],
[PA_ADD_CPPFLAGS([-std=c11], [], [],
[PA_ADD_CPPFLAGS([-std=c99])])])
dnl Compile and link with gdb debug extensions
PA_ARG_ENABLED([gdb],
[compile with extra debug information for GDB debugger],
[PA_ADD_CFLAGS([-ggdb3])])
dnl Disable optimization
PA_ARG_DISABLED([optimization],
[compile without optimization (-O0) to help debugging],
[PA_ADD_CFLAGS([-O0])
PA_ADD_CFLAGS([-fno-omit-frame-pointer])])
dnl Profiling
PA_ARG_ENABLED([profiling],
[compile with profiling (-pg option)],
[PA_ADD_CFLAGS([-pg])])
dnl Options for debugging and profiling
PA_OPTION_DEBUG
PA_OPTION_PROFILING
dnl Large files
AC_SYS_LARGEFILE
@ -56,13 +44,6 @@ AH_TEMPLATE(ABORT_ON_PANIC,
dnl Checks for typedefs, structures, and compiler characteristics.
AC_TYPE_SIZE_T
AC_C_BIGENDIAN(AC_DEFINE(WORDS_BIGENDIAN),AC_DEFINE(WORDS_LITTLEENDIAN),,)
AH_TEMPLATE(WORDS_BIGENDIAN,
[Define to 1 if your processor stores words with the most significant
byte first (like Motorola and SPARC, unlike Intel and VAX).])
AH_TEMPLATE(WORDS_LITTLEENDIAN,
[Define to 1 if your processor stores words with the least significant
byte first (like Intel and VAX, unlike Motorola and SPARC).])
dnl LLVM doesn't error out on invalid -W options unless this option is
dnl specified first. Enable this so this script can actually discover
@ -170,7 +151,7 @@ AC_CHECK_INCLUDES_DEFAULT
PA_ADD_HEADERS(string.h)
PA_ADD_HEADERS(stdarg.h)
AC_CHECK_HEADERS(inttypes.h)
PA_ADD_HEADERS(inttypes.h)
AC_CHECK_HEADERS(strings.h)
AC_HEADER_STDBOOL
AC_CHECK_HEADERS(stdnoreturn.h)
@ -261,25 +242,7 @@ AC_SUBST([PDFOPT])
dnl
dnl Look for byte-swapping support...
dnl
PA_ADD_HEADERS(endian.h sys/endian.h machine/endian.h)
PA_HAVE_FUNC(cpu_to_le16, (0))
PA_HAVE_FUNC(cpu_to_le32, (0))
PA_HAVE_FUNC(cpu_to_le64, (0))
PA_HAVE_FUNC(__cpu_to_le16, (0))
PA_HAVE_FUNC(__cpu_to_le32, (0))
PA_HAVE_FUNC(__cpu_to_le64, (0))
PA_HAVE_FUNC(htole16, (0))
PA_HAVE_FUNC(htole32, (0))
PA_HAVE_FUNC(htole64, (0))
PA_HAVE_FUNC(__bswap_16, (0))
PA_HAVE_FUNC(__bswap_32, (0))
PA_HAVE_FUNC(__bswap_64, (0))
PA_HAVE_FUNC(__builtin_bswap16, (0))
PA_HAVE_FUNC(__builtin_bswap32, (0))
PA_HAVE_FUNC(__builtin_bswap64, (0))
PA_HAVE_FUNC(_byteswap_ushort, (0))
PA_HAVE_FUNC(_byteswap_ulong, (0))
PA_HAVE_FUNC(_byteswap_uint64, (0))
PA_ENDIAN
dnl
dnl Some rather useful gcc extensions...
@ -293,52 +256,22 @@ dnl support these, but don't define __GNUC__ as they don't support
dnl some other features of gcc.
dnl
PA_ADD_CFLAGS([-Werror=attributes])
PA_FUNC_ATTRIBUTE(noreturn)
PA_FUNC_ATTRIBUTE(returns_nonnull,,,,,never_null)
PA_FUNC_ATTRIBUTE(malloc)
PA_FUNC_ATTRIBUTE(alloc_size,[1])
PA_FUNC_ATTRIBUTE(alloc_size,[1,2])
PA_FUNC_ATTRIBUTE(sentinel,,, [const char *, ...], ["a","b",NULL],end_with_null)
PA_FUNC_ATTRIBUTE(format, [printf,1,2], int, [const char *, ...], ["%d",1])
PA_FUNC_ATTRIBUTE(const)
PA_FUNC_ATTRIBUTE(pure)
PA_FUNC_ATTRIBUTE(cold,,,,,unlikely_func)
PA_FUNC_ATTRIBUTE(unused)
PA_FUNC_ATTRIBUTE_ERROR
PA_COMMON_ATTRIBUTES
dnl
dnl support function sections (if available)
dnl
PA_ARG_DISABLED([sections],
[do not try to compile with function/data section support],
[],
[PA_ADD_CFLAGS([-ffunction-sections])
PA_ADD_CFLAGS([-fdata-sections])
PA_ADD_LDFLAGS([-Wl,--gc-sections])]
)
PA_OPTION_GC
dnl
dnl support LTO
dnl
PA_ARG_ENABLED([lto],
[compile with gcc-style link time optimization],
[PA_ADD_CFLAGS([-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_PROGS(CC_AR, [${ccbase}-ar], [$ac_cv_prog_AR])
AR="$CC_AR"
AC_CHECK_PROGS(CC_RANLIB, [${ccbase}-ranlib], [$ac_cv_prog_RANLIB])
RANLIB="$CC_RANLIB"], [])
PA_OPTION_LTO
dnl
dnl support sanitizers (if available)
dnl
PA_ARG_ENABLED([sanitizer],
[compile with sanitizers enabled],
[PA_ADD_CFLAGS([-fno-omit-frame-pointer])
PA_ADD_CFLAGS([-fsanitize=address])
PA_ADD_CFLAGS([-fsanitize=undefined])])
PA_OPTION_SANITIZER
dnl
dnl Don't make symbols visible, there is no point and it just
@ -408,10 +341,5 @@ dnl
PA_CHECK_BAD_STDC_INLINE
PA_C_TYPEOF
dnl
dnl support ccache
dnl
PA_ARG_ENABLED([ccache], [compile with ccache], [CC="ccache $CC"], [])
AC_CONFIG_FILES([Makefile doc/Makefile])
AC_OUTPUT