output: macho -- Add support for N_PEXT in macho output
[nasm.git] / aclocal.m4
blob43649e70b47e2834dfe02fc745d099f77ab8b486
1 dnl --------------------------------------------------------------------------
2 dnl PA_SYM(prefix, string)
3 dnl
4 dnl Convert a (semi-) arbitrary string to a CPP symbol
5 dnl --------------------------------------------------------------------------
6 AC_DEFUN(PA_SYM,
7 [[$1]m4_bpatsubsts(m4_toupper([$2]),[[^ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789]+],[_],[^._?\(.*\)_.$],[[\1]])])
9 dnl --------------------------------------------------------------------------
10 dnl PA_ADD_CFLAGS(flag [,actual_flag])
11 dnl
12 dnl Attempt to add the given option to CFLAGS, if it doesn't break
13 dnl compilation.  If the option to be tested is different than the
14 dnl option that should actually be added, add the option to be
15 dnl actually added as a second argument.
16 dnl --------------------------------------------------------------------------
17 AC_DEFUN(PA_ADD_CFLAGS,
18 [AC_MSG_CHECKING([if $CC accepts $1])
19  pa_add_cflags__old_cflags="$CFLAGS"
20  CFLAGS="$CFLAGS $1"
21  AC_TRY_LINK(AC_INCLUDES_DEFAULT,
22  [printf("Hello, World!\n");],
23  [AC_MSG_RESULT([yes])
24   CFLAGS="$pa_add_cflags__old_cflags ifelse([$2],[],[$1],[$2])"
25   AC_DEFINE(PA_SYM([CFLAG_],[$1]), 1,
26    [Define to 1 if compiled with the `$1' compiler flag])],
27  [AC_MSG_RESULT([no])
28   CFLAGS="$pa_add_cflags__old_cflags"])])
30 dnl --------------------------------------------------------------------------
31 dnl PA_ADD_CLDFLAGS(flag [,actual_flag])
32 dnl
33 dnl Attempt to add the given option to CFLAGS and LDFLAGS,
34 dnl if it doesn't break compilation
35 dnl --------------------------------------------------------------------------
36 AC_DEFUN(PA_ADD_CLDFLAGS,
37 [AC_MSG_CHECKING([if $CC accepts $1])
38  pa_add_cldflags__old_cflags="$CFLAGS"
39  CFLAGS="$CFLAGS $1"
40  pa_add_cldflags__old_ldflags="$LDFLAGS"
41  LDFLAGS="$LDFLAGS $1"
42  AC_TRY_LINK(AC_INCLUDES_DEFAULT,
43  [printf("Hello, World!\n");],
44  [AC_MSG_RESULT([yes])
45   CFLAGS="$pa_add_cldflags__old_cflags ifelse([$2],[],[$1],[$2])"
46   LDFLAGS="$pa_add_cldflags__old_ldflags ifelse([$2],[],[$1],[$2])"
47   AC_DEFINE(PA_SYM([CFLAG_],[$1]), 1,
48    [Define to 1 if compiled with the `$1' compiler flag])],
49  [AC_MSG_RESULT([no])
50   CFLAGS="$pa_add_cldflags__old_cflags"
51   LDFLAGS="$pa_add_cldflags__old_ldflags"])])
53 dnl --------------------------------------------------------------------------
54 dnl PA_HAVE_FUNC(func_name)
55 dnl
56 dnl Look for a function with the specified arguments which could be
57 dnl a builtin/intrinsic function.
58 dnl --------------------------------------------------------------------------
59 AC_DEFUN(PA_HAVE_FUNC,
60 [AC_MSG_CHECKING([for $1])
61  AC_LINK_IFELSE([AC_LANG_SOURCE([
62 AC_INCLUDES_DEFAULT
63 int main(void) {
64     (void)$1$2;
65     return 0;
67  ])],
68  [AC_MSG_RESULT([yes])
69   AC_DEFINE(AS_TR_CPP([HAVE_$1]), 1,
70   [Define to 1 if you have the `$1' intrinsic function.])],
71  [AC_MSG_RESULT([no])])
74 dnl --------------------------------------------------------------------------
75 dnl PA_LIBEXT
76 dnl
77 dnl Guess the library extension based on the object extension
78 dnl --------------------------------------------------------------------------
79 AC_DEFUN(PA_LIBEXT,
80 [AC_MSG_CHECKING([for suffix of library files])
81 if test x"$LIBEXT" = x; then
82   case "$OBJEXT" in
83     obj )
84       LIBEXT=lib
85       ;;
86     *)
87       LIBEXT=a
88       ;;
89   esac
91 AC_MSG_RESULT([$LIBEXT])
92 AC_SUBST([LIBEXT])])
94 dnl --------------------------------------------------------------------------
95 dnl PA_FUNC_ATTRIBUTE(attribute_name)
96 dnl
97 dnl See if this compiler supports the equivalent of a specific gcc
98 dnl attribute on a function, using the __attribute__(()) syntax.
99 dnl All arguments except the attribute name are optional.
100 dnl PA_FUNC_ATTRIBUTE(attribute, attribute_opts, return_type,
101 dnl                   prototype_args, call_args)
102 dnl --------------------------------------------------------------------------
103 AC_DEFUN(PA_FUNC_ATTRIBUTE,
104 [AC_MSG_CHECKING([if $CC supports the $1 function attribute])
105  AC_COMPILE_IFELSE([AC_LANG_SOURCE([
106 AC_INCLUDES_DEFAULT
107 extern ifelse([$3],[],[void *],[$3])  __attribute__(($1$2))
108   bar(ifelse([$4],[],[int],[$4]));
109 void *foo(void);
110 void *foo(void)
112         return bar(ifelse([$5],[],[1],[$5]));
114  ])],
115  [AC_MSG_RESULT([yes])
116   AC_DEFINE(PA_SYM([HAVE_FUNC_ATTRIBUTE_],[$1]), 1,
117     [Define to 1 if your compiler supports __attribute__(($1)) on functions])],
118  [AC_MSG_RESULT([no])])
121 dnl --------------------------------------------------------------------------
122 dnl PA_FUNC_ATTRIBUTE_ERROR
124 dnl See if this compiler supports __attribute__((error("foo")))
125 dnl The generic version of this doesn't work as it makes the compiler
126 dnl throw an error by design.
127 dnl --------------------------------------------------------------------------
128 AC_DEFUN(PA_FUNC_ATTRIBUTE_ERROR,
129 [AC_MSG_CHECKING([if $CC supports the error function attribute])
130  AC_COMPILE_IFELSE([AC_LANG_SOURCE([
131 AC_INCLUDES_DEFAULT
132 extern void __attribute__((error("message"))) barf(void);
133 void foo(void);
134 void foo(void)
136         if (0)
137                 barf();
139  ])],
140  [AC_MSG_RESULT([yes])
141   AC_DEFINE([HAVE_FUNC_ATTRIBUTE_ERROR], 1,
142     [Define to 1 if your compiler supports __attribute__((error)) on functions])],
143  [AC_MSG_RESULT([no])])
146 dnl --------------------------------------------------------------------------
147 dnl PA_ARG_ENABLED(option, helptext [,enabled_action [,disabled_action]])
148 dnl PA_ARG_DISABLED(option, helptext [,disabled_action [,enabled_action]])
150 dnl  Simpler-to-use versions of AC_ARG_ENABLED, that include the
151 dnl  test for $enableval and the AS_HELP_STRING definition
152 dnl --------------------------------------------------------------------------
153 AC_DEFUN(PA_ARG_ENABLED,
154 [AC_ARG_ENABLE([$1], [AS_HELP_STRING([--enable-$1],[$2])], [], [enableval=no])
155  AS_IF([test x"$enableval" != xno], [$3], [$4])
158 AC_DEFUN(PA_ARG_DISABLED,
159 [AC_ARG_ENABLE([$1],[AS_HELP_STRING([--disable-$1],[$2])], [], [enableval=yes])
160  AS_IF([test x"$enableval" = xno], [$3], [$4])
163 dnl --------------------------------------------------------------------------
164 dnl PA_ADD_HEADERS(headers...)
166 dnl Call AC_CHECK_HEADERS(), and add to ac_includes_default if found
167 dnl --------------------------------------------------------------------------
168 AC_DEFUN(_PA_ADD_HEADER,
169 [AC_CHECK_HEADERS([$1],[ac_includes_default="$ac_includes_default
170 #include <$1>"
171 ])])
173 AC_DEFUN(PA_ADD_HEADERS,
174 [m4_map_args_w([$1],[_PA_ADD_HEADER(],[)])])
176 dnl --------------------------------------------------------------------------
177 dnl PA_CHECK_BAD_STDC_INLINE
179 dnl Some versions of gcc seem to apply -Wmissing-prototypes to C99
180 dnl inline functions, which means we need to use GNU inline syntax
181 dnl --------------------------------------------------------------------------
182 AC_DEFUN(PA_CHECK_BAD_STDC_INLINE,
183 [AC_MSG_CHECKING([if $CC supports C99 external inlines])
184  AC_COMPILE_IFELSE([AC_LANG_SOURCE([
185 AC_INCLUDES_DEFAULT
187 /* Don't mistake GNU inlines for c99 */
188 #ifdef __GNUC_GNU_INLINE__
189 # error "Using gnu inline standard"
190 #endif
192 inline int foo(int x)
194         return x+1;
196  ])],
197  [AC_MSG_RESULT([yes])
198   AC_DEFINE(HAVE_STDC_INLINE, 1,
199     [Define to 1 if your compiler supports C99 extern inline])],
200  [AC_MSG_RESULT([no])
201   PA_ADD_CFLAGS([-fgnu89-inline])])])
203 dnl --------------------------------------------------------------------------
204 dnl PA_CHECK_FALLTHROUGH_ATTRIBUTE
205 dnl --------------------------------------------------------------------------
206 AC_DEFUN(PA_CHECK_FALLTHROUGH_ATTRIBUTE,
207 [AC_MSG_CHECKING([if $CC supports fallthrough attribute])
208  AC_COMPILE_IFELSE([AC_LANG_SOURCE([
209 AC_INCLUDES_DEFAULT
210 int main(int argc, char **argv)
212         switch (argc) {
213         case 1:
214                 (void)argc;
215                 __attribute__((fallthrough));
216         default:
217                 (void)argv;
218                 break;
219         }
220         return argc;
222  ])],
223  [AC_MSG_RESULT([yes])
224   AC_DEFINE([HAVE_FALLTHROUGH_ATTRIBUTE], 1,
225     [Define to 1 if your compiler supports __attribute__((fallthrough))])],
226  [AC_MSG_RESULT([no])])