labels: allocation of a segment number counts as a change
[nasm.git] / aclocal.m4
blob1af2dd5d760aa960f947d2f8cfd4e128c24aece9
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 ifelse([$3],[],[void *],[$3]) foo(void);
110 ifelse([$3],[],[void *],[$3]) foo(void)
112         ifelse([$3],[void],[],[return])
113                 bar(ifelse([$5],[],[1],[$5]));
115  ])],
116  [AC_MSG_RESULT([yes])
117   AC_DEFINE(PA_SYM([HAVE_FUNC_ATTRIBUTE_],[$1]), 1,
118     [Define to 1 if your compiler supports __attribute__(($1)) on functions])],
119  [AC_MSG_RESULT([no])])
122 dnl --------------------------------------------------------------------------
123 dnl PA_FUNC_ATTRIBUTE_ERROR
125 dnl See if this compiler supports __attribute__((error("foo")))
126 dnl The generic version of this doesn't work as it makes the compiler
127 dnl throw an error by design.
128 dnl --------------------------------------------------------------------------
129 AC_DEFUN(PA_FUNC_ATTRIBUTE_ERROR,
130 [AC_MSG_CHECKING([if $CC supports the error function attribute])
131  AC_COMPILE_IFELSE([AC_LANG_SOURCE([
132 AC_INCLUDES_DEFAULT
133 extern void __attribute__((error("message"))) barf(void);
134 void foo(void);
135 void foo(void)
137         if (0)
138                 barf();
140  ])],
141  [AC_MSG_RESULT([yes])
142   AC_DEFINE([HAVE_FUNC_ATTRIBUTE_ERROR], 1,
143     [Define to 1 if your compiler supports __attribute__((error)) on functions])],
144  [AC_MSG_RESULT([no])])
147 dnl --------------------------------------------------------------------------
148 dnl PA_ARG_ENABLED(option, helptext [,enabled_action [,disabled_action]])
149 dnl PA_ARG_DISABLED(option, helptext [,disabled_action [,enabled_action]])
151 dnl  Simpler-to-use versions of AC_ARG_ENABLED, that include the
152 dnl  test for $enableval and the AS_HELP_STRING definition
153 dnl --------------------------------------------------------------------------
154 AC_DEFUN(PA_ARG_ENABLED,
155 [AC_ARG_ENABLE([$1], [AS_HELP_STRING([--enable-$1],[$2])], [], [enableval=no])
156  AS_IF([test x"$enableval" != xno], [$3], [$4])
159 AC_DEFUN(PA_ARG_DISABLED,
160 [AC_ARG_ENABLE([$1],[AS_HELP_STRING([--disable-$1],[$2])], [], [enableval=yes])
161  AS_IF([test x"$enableval" = xno], [$3], [$4])
164 dnl --------------------------------------------------------------------------
165 dnl PA_ADD_HEADERS(headers...)
167 dnl Call AC_CHECK_HEADERS(), and add to ac_includes_default if found
168 dnl --------------------------------------------------------------------------
169 AC_DEFUN(_PA_ADD_HEADER,
170 [AC_CHECK_HEADERS([$1],[ac_includes_default="$ac_includes_default
171 #include <$1>"
172 ])])
174 AC_DEFUN(PA_ADD_HEADERS,
175 [m4_map_args_w([$1],[_PA_ADD_HEADER(],[)])])
177 dnl --------------------------------------------------------------------------
178 dnl PA_CHECK_BAD_STDC_INLINE
180 dnl Some versions of gcc seem to apply -Wmissing-prototypes to C99
181 dnl inline functions, which means we need to use GNU inline syntax
182 dnl --------------------------------------------------------------------------
183 AC_DEFUN(PA_CHECK_BAD_STDC_INLINE,
184 [AC_MSG_CHECKING([if $CC supports C99 external inlines])
185  AC_COMPILE_IFELSE([AC_LANG_SOURCE([
186 AC_INCLUDES_DEFAULT
188 /* Don't mistake GNU inlines for c99 */
189 #ifdef __GNUC_GNU_INLINE__
190 # error "Using gnu inline standard"
191 #endif
193 inline int foo(int x)
195         return x+1;
197  ])],
198  [AC_MSG_RESULT([yes])
199   AC_DEFINE(HAVE_STDC_INLINE, 1,
200     [Define to 1 if your compiler supports C99 extern inline])],
201  [AC_MSG_RESULT([no])
202   PA_ADD_CFLAGS([-fgnu89-inline])])])