summaryrefslogtreecommitdiff
path: root/aclocal.m4
blob: 5d27844862476f469f9dda86f19dfac0782edf54 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
dnl --------------------------------------------------------------------------
dnl PA_ADD_CFLAGS()
dnl
dnl Attempt to add the given option to CFLAGS, if it doesn't break compilation
dnl --------------------------------------------------------------------------
AC_DEFUN(PA_ADD_CFLAGS,
[AC_MSG_CHECKING([if $CC accepts $1])
 pa_add_cflags__old_cflags="$CFLAGS"
 CFLAGS="$CFLAGS $1"
 AC_TRY_LINK(AC_INCLUDES_DEFAULT,
 [printf("Hello, World!\n");],
 AC_MSG_RESULT([yes])
 CFLAGS="$pa_add_cflags__old_cflags ifelse([$2],[],[$1],[$2])",
 AC_MSG_RESULT([no])
 CFLAGS="$pa_add_cflags__old_cflags")])

dnl --------------------------------------------------------------------------
dnl PA_ADD_CLDFLAGS()
dnl
dnl Attempt to add the given option to CFLAGS and LDFLAGS,
dnl if it doesn't break compilation
dnl --------------------------------------------------------------------------
AC_DEFUN(PA_ADD_CLDFLAGS,
[AC_MSG_CHECKING([if $CC accepts $1])
 pa_add_cldflags__old_cflags="$CFLAGS"
 CFLAGS="$CFLAGS $1"
 pa_add_cldflags__old_ldflags="$LDFLAGS"
 LDFLAGS="$LDFLAGS $1"
 AC_TRY_LINK(AC_INCLUDES_DEFAULT,
 [printf("Hello, World!\n");],
 AC_MSG_RESULT([yes])
 CFLAGS="$pa_add_cldflags__old_cflags ifelse([$2],[],[$1],[$2])"
 LDFLAGS="$pa_add_cldflags__old_ldflags ifelse([$2],[],[$1],[$2])",
 AC_MSG_RESULT([no])
 CFLAGS="$pa_add_cldflags__old_cflags"
 LDFLAGS="$pa_add_cldflags__old_ldflags")])

dnl --------------------------------------------------------------------------
dnl PA_VAR
dnl
dnl Canonicalize a variable name: upper case, and fold non-C characters
dnl to underscores.
dnl --------------------------------------------------------------------------
AC_DEFUN(PA_VAR, [patsubst(m4_toupper([$1]),[[^A-Za-z0-9_]],[_])])

dnl --------------------------------------------------------------------------
dnl PA_HAVE_FUNC
dnl
dnl Look for a function with the specified arguments which could be
dnl a builtin/intrinsic function.
dnl --------------------------------------------------------------------------
AC_DEFUN(PA_HAVE_FUNC,
[AC_MSG_CHECKING([for $1])
AC_TRY_LINK(AC_INCLUDES_DEFAULT, [(void)$1$2;],
AC_MSG_RESULT([yes])
AC_DEFINE(PA_VAR([HAVE_$1]), [1],
  [Define to 1 if you have the `$1' intrinsic function.]),
AC_MSG_RESULT([no]))])

dnl --------------------------------------------------------------------------
dnl PA_LIBEXT
dnl
dnl Guess the library extension based on the object extension
dnl --------------------------------------------------------------------------
AC_DEFUN(PA_LIBEXT,
[AC_MSG_CHECKING([for suffix of library files])
if test x"$LIBEXT" = x; then
  case "$OBJEXT" in
    obj )
      LIBEXT=lib
      ;;
    *)
      LIBEXT=a
      ;;
  esac
fi
AC_MSG_RESULT([$LIBEXT])
AC_SUBST([LIBEXT])])

dnl --------------------------------------------------------------------------
dnl PA_FUNC_ATTRIBUTE
dnl
dnl See if this compiler supports the equivalent of a specific gcc
dnl attribute on a function, using the __attribute__(()) syntax.
dnl All arguments except the attribute name are optional.
dnl PA_FUNC_ATTRIBUTE(attribute, attribute_opts, return_type,
dnl                   prototype_args, call_args)
dnl --------------------------------------------------------------------------
AC_DEFUN(PA_FUNC_ATTRIBUTE,
[AC_MSG_CHECKING([if $CC supports the $1 function attribute])
 AC_COMPILE_IFELSE([AC_LANG_SOURCE([
AC_INCLUDES_DEFAULT
extern ifelse([$3],[],[void *],[$3])  __attribute__(($1$2))
  bar(ifelse([$4],[],[int],[$4]));
void *foo(void);
void *foo(void)
{
	return bar(ifelse([$5],[],[1],[$5]));
}
 ])],
 [AC_MSG_RESULT([yes])
  AC_DEFINE(PA_VAR([HAVE_FUNC_ATTRIBUTE_$1]), 1,
    [Define to 1 if your compiler supports __attribute__(($1)) on functions])],
 [AC_MSG_RESULT([no])])
])

dnl --------------------------------------------------------------------------
dnl PA_FUNC_ATTRIBUTE_ERROR
dnl
dnl See if this compiler supports __attribute__((error("foo")))
dnl The generic version of this doesn't work as it makes the compiler
dnl throw an error by design.
dnl --------------------------------------------------------------------------
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);
void foo(void);
void foo(void)
{
	if (0)
		barf();
}
 ])],
 [AC_MSG_RESULT([yes])
  AC_DEFINE(PA_VAR([HAVE_FUNC_ATTRIBUTE_ERROR]), 1,
    [Define to 1 if your compiler supports __attribute__((error)) on functions])],
 [AC_MSG_RESULT([no])])
])

dnl --------------------------------------------------------------------------
dnl PA_ARG_ENABLED
dnl PA_ARG_DISABLED
dnl
dnl  Simpler-to-use versions of AC_ARG_ENABLED, that include the
dnl  test for $enableval and the AS_HELP_STRING definition
dnl --------------------------------------------------------------------------
AC_DEFUN(PA_ARG_ENABLED,
[AC_ARG_ENABLE([$1],
 [AS_HELP_STRING([--enable-$1],[$2])], [], [enableval=no])
  AS_IF([test x"$enableval" != xno], [$3], [$4])
])

AC_DEFUN(PA_ARG_DISABLED,
[AC_ARG_ENABLE([$1],
 [AS_HELP_STRING([--disable-$1],[$2])], [], [enableval=yes])
  AS_IF([test x"$enableval" = xno], [$3], [$4])
])

dnl --------------------------------------------------------------------------
dnl PA_ADD_HEADERS()
dnl
dnl Call AC_CHECK_HEADERS(), and add to ac_includes_default if found
dnl --------------------------------------------------------------------------
AC_DEFUN(_PA_ADD_HEADER,
[AC_CHECK_HEADERS([$1],[ac_includes_default="$ac_includes_default
#include <$1>"])])

AC_DEFUN(PA_ADD_HEADERS,
[m4_map_args_w([$1],[_PA_ADD_HEADER(],[)])])