Skip to content

Commit a16a45e

Browse files
author
H. Peter Anvin
committed
autoconf: modernize autoconf and update a lot of m4 macros
1 parent a916e41 commit a16a45e

18 files changed

+261
-117
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,3 +108,4 @@ TAGS
108108
/autoconf/compile
109109
/autoconf/config.*
110110
/autoconf/install-sh
111+
/autoconf/clean.sh

autoconf/attribute.h

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Define a macro for compiler attributes. Use either gcc
3+
* syntax if __GNUC__ is defined, or try to look for the
4+
* modern standard [[x]] attributes.
5+
*
6+
* Unfortunately [[x]] doesn't always work when it comes to
7+
* GNUC-specific attributes, and some compilers support GCC
8+
* syntax without __attribute__ just to be confusing.
9+
* Therefore, this also needs an autoconf module to test
10+
* the validity.
11+
*
12+
* Use #ifdef and not defined() here; some compilers do the wrong
13+
* thing in the latter case.
14+
*/
15+
16+
#ifndef ATTRIBUTE
17+
# define MODERN_ATTRIBUTE(x) [[x]]
18+
# ifndef __GNUC__
19+
# ifdef __cplusplus
20+
# ifdef __has_cpp_attribute
21+
# define ATTRIBUTE(x) MODERN_ATTRIBUTE(x)
22+
# endif
23+
# endif
24+
# ifndef ATTRIBUTE
25+
# ifdef __has_c_attribute
26+
# define ATTRIBUTE(x) MODERN_ATTRIBUTE(x)
27+
# endif
28+
# endif
29+
# ifndef ATTRIBUTE
30+
# ifdef __has_attribute
31+
# define ATTRIBUTE(x) MODERN_ATTRIBUTE(x)
32+
# endif
33+
# endif
34+
# endif
35+
# ifndef ATTRIBUTE
36+
# define ATTRIBUTE(x) __attribute__((x))
37+
# endif
38+
#endif

autoconf/m4/pa_add_langflags.m4

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
dnl --------------------------------------------------------------------------
2+
dnl PA_ADD_LANGFLAGS(flag...)
3+
dnl
4+
dnl Attempt to add the option in the given list to each compiler flags
5+
dnl (CFLAGS, CXXFLAGS, ...), if it doesn't break compilation.
6+
dnl --------------------------------------------------------------------------
7+
m4_defun([_PA_LANGFLAG_VAR],
8+
[m4_case([$1],
9+
[C], [CFLAGS],
10+
[C++], [CXXFLAGS],
11+
[Fortran 77], [FFLAGS],
12+
[Fortran], [FCFLAGS],
13+
[Erlang], [ERLCFLAGS],
14+
[Objective C], [OBJCFLAGS],
15+
[Objective C++], [OBJCXXFLAGS],
16+
[Go], [GOFLAGS],
17+
[m4_fatal([PA_ADD_LANGFLAGS: Unknown language: $1])])])
18+
19+
AC_DEFUN([PA_ADD_LANGFLAGS],
20+
[m4_set_foreach(PA_LANG_SEEN_SET, [lang],
21+
[_pa_flag_found=no
22+
m4_foreach_w([flag], [$1],
23+
[AS_IF([test $_pa_flag_found = no],
24+
[PA_ADD_FLAGS(_PA_LANGFLAG_VAR(lang),flag,[],[_pa_flag_found=yes])])
25+
])])])

autoconf/m4/pa_attribute_syntax.m4

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
dnl --------------------------------------------------------------------------
2+
dnl PA_ATTRIBUTE_SYNTAX
3+
dnl
4+
dnl Source code fragment to test for attribute syntax
5+
dnl The use of #ifdef rather than defined() here is intentional:
6+
dnl defined() is known to not always work right.
7+
8+
dnl --------------------------------------------------------------------------
9+
AC_DEFUN([PA_ATTRIBUTE_SYNTAX],
10+
[#include "autoconf/attribute.h"
11+
])

autoconf/m4/pa_common_attributes.m4

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
dnl --------------------------------------------------------------------------
2+
dnl PA_COMMON_ATTRIBUTES
3+
dnl
4+
dnl Test for a bunch of common function attributes and define macros for them.
5+
dnl --------------------------------------------------------------------------
6+
AC_DEFUN([PA_COMMON_ATTRIBUTES],
7+
[PA_ADD_CPPFLAGS([-Werror=attributes])
8+
PA_FUNC_ATTRIBUTE(noreturn)
9+
PA_FUNC_ATTRIBUTE(returns_nonnull,,[void *],,,never_null)
10+
PA_FUNC_ATTRIBUTE(malloc,,[void *])
11+
PA_FUNC_ATTRIBUTE(alloc_size,[1],[void *],[int],[80])
12+
PA_FUNC_ATTRIBUTE(alloc_size,[1,2],[void *],[int,int],[20,40])
13+
PA_FUNC_ATTRIBUTE(sentinel,,,[const char *, ...],["a","b",NULL],end_with_null)
14+
PA_FUNC_ATTRIBUTE(format,[printf,1,2],int,[const char *, ...],["%d",1])
15+
PA_FUNC_ATTRIBUTE(const)
16+
PA_FUNC_ATTRIBUTE(pure)
17+
PA_FUNC_ATTRIBUTE(cold,,,,,unlikely_func)
18+
PA_FUNC_ATTRIBUTE(unused)
19+
PA_FUNC_ATTRIBUTE_ERROR])

autoconf/m4/pa_endian.m4

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
dnl --------------------------------------------------------------------------
2+
dnl PA_ENDIAN
3+
dnl
4+
dnl Test for a bunch of variants of endian tests and byteorder functions.
5+
dnl --------------------------------------------------------------------------
6+
AC_DEFUN([PA_ENDIAN],
7+
[AC_C_BIGENDIAN(AC_DEFINE(WORDS_BIGENDIAN),AC_DEFINE(WORDS_LITTLEENDIAN),,)
8+
AH_TEMPLATE(WORDS_BIGENDIAN,
9+
[Define to 1 if your processor stores words with the most significant
10+
byte first (like Motorola and SPARC, unlike Intel and VAX).])
11+
AH_TEMPLATE(WORDS_LITTLEENDIAN,
12+
[Define to 1 if your processor stores words with the least significant
13+
byte first (like Intel and VAX, unlike Motorola and SPARC).])
14+
PA_ADD_HEADERS(endian.h sys/endian.h machine/endian.h)
15+
PA_HAVE_FUNC(cpu_to_le16, (0))
16+
PA_HAVE_FUNC(cpu_to_le32, (0))
17+
PA_HAVE_FUNC(cpu_to_le64, (0))
18+
PA_HAVE_FUNC(__cpu_to_le16, (0))
19+
PA_HAVE_FUNC(__cpu_to_le32, (0))
20+
PA_HAVE_FUNC(__cpu_to_le64, (0))
21+
PA_HAVE_FUNC(htole16, (0))
22+
PA_HAVE_FUNC(htole32, (0))
23+
PA_HAVE_FUNC(htole64, (0))
24+
PA_HAVE_FUNC(__bswap_16, (0))
25+
PA_HAVE_FUNC(__bswap_32, (0))
26+
PA_HAVE_FUNC(__bswap_64, (0))
27+
PA_HAVE_FUNC(__builtin_bswap16, (0))
28+
PA_HAVE_FUNC(__builtin_bswap32, (0))
29+
PA_HAVE_FUNC(__builtin_bswap64, (0))
30+
PA_HAVE_FUNC(_byteswap_ushort, (0))
31+
PA_HAVE_FUNC(_byteswap_ulong, (0))
32+
PA_HAVE_FUNC(_byteswap_uint64, (0))])

autoconf/m4/pa_func_attribute.m4

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ AC_DEFUN([_PA_FUNC_ATTRIBUTE],
2020
AC_MSG_CHECKING([if $CC supports the $1]_pa_faa[ function attribute])
2121
AC_COMPILE_IFELSE([AC_LANG_SOURCE([
2222
AC_INCLUDES_DEFAULT
23-
extern ifelse([$3],[],[void *],[$3]) __attribute__(([$1]_pa_faa))
23+
PA_ATTRIBUTE_SYNTAX
24+
25+
extern ifelse([$3],[],[void *],[$3]) ATTRIBUTE([$1]_pa_faa)
2426
bar(ifelse([$4],[],[int],[$4]));
2527
ifelse([$3],[],[void *],[$3]) foo(void);
2628
ifelse([$3],[],[void *],[$3]) foo(void)
@@ -31,12 +33,12 @@ ifelse([$3],[],[void *],[$3]) foo(void)
3133
])],
3234
[AC_MSG_RESULT([yes])
3335
AC_DEFINE(PA_SYM([HAVE_FUNC_ATTRIBUTE],_pa_suf,[_$1]), 1,
34-
[Define to 1 if your compiler supports __attribute__(($1)) on functions])],
36+
[Define to 1 if your compiler supports the $1 function attribute])],
3537
[AC_MSG_RESULT([no])])
3638
AH_BOTTOM(m4_quote(m4_join([],
3739
[#ifndef ],_pa_mac,[
3840
# ifdef ],PA_SYM([HAVE_FUNC_ATTRIBUTE],_pa_suf,[_$1]),[
39-
# define ],_pa_mac,m4_quote(_pa_fam),[ __attribute__(($1],m4_quote(_pa_fam),[))
41+
# define ],_pa_mac,m4_quote(_pa_fam),[ ATTRIBUTE($1],m4_quote(_pa_fam),[)
4042
# else
4143
# define ],_pa_mac,m4_quote(_pa_fam),[
4244
# endif
@@ -51,7 +53,9 @@ AC_DEFUN([_PA_FUNC_PTR_ATTRIBUTE],
5153
AC_MSG_CHECKING([if $CC supports the $1]_pa_faa[ function attribute on pointers])
5254
AC_COMPILE_IFELSE([AC_LANG_SOURCE([
5355
AC_INCLUDES_DEFAULT
54-
extern ifelse([$3],[],[void *],[$3]) __attribute__(([$1]_pa_faa))
56+
PA_ATTRIBUTE_SYNTAX
57+
58+
extern ifelse([$3],[],[void *],[$3]) ATTRIBUTE([$1]_pa_faa)
5559
(*bar1)(ifelse([$4],[],[int],[$4]));
5660
ifelse([$3],[],[void *],[$3]) foo1(void);
5761
ifelse([$3],[],[void *],[$3]) foo1(void)
@@ -60,7 +64,7 @@ ifelse([$3],[],[void *],[$3]) foo1(void)
6064
bar1(ifelse([$5],[],[1],[$5]));
6165
}
6266
63-
typedef ifelse([$3],[],[void *],[$3]) __attribute__(([$1]_pa_faa))
67+
typedef ifelse([$3],[],[void *],[$3]) ATTRIBUTE([$1]_pa_faa)
6468
(*bar_t)(ifelse([$4],[],[int],[$4]));
6569
extern bar_t bar2;
6670
ifelse([$3],[],[void *],[$3]) foo2(void);
@@ -72,12 +76,12 @@ ifelse([$3],[],[void *],[$3]) foo2(void)
7276
])],
7377
[AC_MSG_RESULT([yes])
7478
AC_DEFINE(PA_SYM([HAVE_FUNC_PTR_ATTRIBUTE],_pa_suf,[_$1]), 1,
75-
[Define to 1 if your compiler supports __attribute__(($1)) on function pointers])],
79+
[Define to 1 if your compiler supports the $1 attribute on function pointers])],
7680
[AC_MSG_RESULT([no])])
7781
AH_BOTTOM(m4_quote(m4_join([],
7882
[#ifndef ],_pa_mac,[
7983
# ifdef ],PA_SYM([HAVE_FUNC_PTR_ATTRIBUTE],_pa_suf,[_$1]),[
80-
# define ],_pa_mac,m4_quote(_pa_fam),[ __attribute__(($1],m4_quote(_pa_fam),[))
84+
# define ],_pa_mac,m4_quote(_pa_fam),[ ATTRIBUTE($1],m4_quote(_pa_fam),[)
8185
# else
8286
# define ],_pa_mac,m4_quote(_pa_fam),[
8387
# endif

autoconf/m4/pa_func_attribute_error.m4

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
dnl --------------------------------------------------------------------------
22
dnl PA_FUNC_ATTRIBUTE_ERROR
33
dnl
4-
dnl See if this compiler supports __attribute__((error("foo")))
4+
dnl See if this compiler supports __attribute__((error("foo"))) *and*
5+
dnl does *not* error if the erroneous call is unreachable.
6+
dnl
57
dnl The generic version of this doesn't work as it makes the compiler
68
dnl throw an error by design.
79
dnl
@@ -12,7 +14,9 @@ AC_DEFUN([PA_FUNC_ATTRIBUTE_ERROR],
1214
[AC_MSG_CHECKING([if $CC supports the error function attribute])
1315
AC_COMPILE_IFELSE([AC_LANG_SOURCE([
1416
AC_INCLUDES_DEFAULT
15-
extern void __attribute__((error("message"))) barf(void);
17+
PA_ATTRIBUTE_SYNTAX
18+
19+
extern ATTRIBUTE(error("message")) void barf(void);
1620
void foo(void);
1721
void foo(void)
1822
{
@@ -22,6 +26,6 @@ void foo(void)
2226
])],
2327
[AC_MSG_RESULT([yes])
2428
AC_DEFINE([HAVE_FUNC_ATTRIBUTE_ERROR], 1,
25-
[Define to 1 if your compiler supports __attribute__((error)) on functions])],
29+
[Define to 1 if your compiler supports the error attribute on functions])],
2630
[AC_MSG_RESULT([no])])
2731
])

autoconf/m4/pa_option_debug.m4

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
dnl --------------------------------------------------------------------------
2+
dnl PA_OPTION_DEBUG(with_debug, without_debug)
3+
dnl
4+
dnl Set debug flags and optimization flags depending on if
5+
dnl --enable-debug is set or not. Some flags are set regardless...
6+
dnl --------------------------------------------------------------------------
7+
AC_DEFUN([PA_OPTION_DEBUG],
8+
[PA_ARG_DISABLED([gdb], [disable gdb debug extensions],
9+
[PA_ADD_LANGFLAGS([-g3])], [PA_ADD_LANGFLAGS([-ggdb3 -g3])])
10+
PA_ARG_ENABLED([debug], [optimize for debugging],
11+
[PA_ADD_LANGFLAGS([-Og -O0])
12+
$1],
13+
[$2])])

autoconf/m4/pa_option_gc.m4

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
dnl --------------------------------------------------------------------------
2+
dnl PA_OPTION_GC
3+
dnl
4+
dnl Option to compile with garbage collection; currently only supports
5+
dnl gcc/ELF. Enabled by default.
6+
dnl --------------------------------------------------------------------------
7+
AC_DEFUN([PA_OPTION_GC],
8+
[PA_ARG_DISABLED([gc],
9+
[do not compile with dead code garbage collection support],
10+
[],
11+
[PA_ADD_LDFLAGS([-Wl,--as-needed])
12+
PA_ADD_CFLAGS([-ffunction-sections])
13+
PA_ADD_CFLAGS([-fdata-sections])
14+
PA_ADD_LDFLAGS([-Wl,--gc-sections])])])

0 commit comments

Comments
 (0)