aclocal.m4 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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]])])
  8. dnl --------------------------------------------------------------------------
  9. dnl PA_ADD_CFLAGS(flag [,actual_flag])
  10. dnl
  11. dnl Attempt to add the given option to CFLAGS, if it doesn't break
  12. dnl compilation. If the option to be tested is different than the
  13. dnl option that should actually be added, add the option to be
  14. dnl actually added as a second argument.
  15. dnl --------------------------------------------------------------------------
  16. AC_DEFUN(PA_ADD_CFLAGS,
  17. [AC_MSG_CHECKING([if $CC accepts $1])
  18. pa_add_cflags__old_cflags="$CFLAGS"
  19. CFLAGS="$CFLAGS $1"
  20. AC_TRY_LINK(AC_INCLUDES_DEFAULT,
  21. [printf("Hello, World!\n");],
  22. [AC_MSG_RESULT([yes])
  23. CFLAGS="$pa_add_cflags__old_cflags ifelse([$2],[],[$1],[$2])"
  24. AC_DEFINE(PA_SYM([CFLAG_],[$1]), 1,
  25. [Define to 1 if compiled with the `$1' compiler flag])],
  26. [AC_MSG_RESULT([no])
  27. CFLAGS="$pa_add_cflags__old_cflags"])])
  28. dnl --------------------------------------------------------------------------
  29. dnl PA_ADD_CLDFLAGS(flag [,actual_flag])
  30. dnl
  31. dnl Attempt to add the given option to CFLAGS and LDFLAGS,
  32. dnl if it doesn't break compilation
  33. dnl --------------------------------------------------------------------------
  34. AC_DEFUN(PA_ADD_CLDFLAGS,
  35. [AC_MSG_CHECKING([if $CC accepts $1])
  36. pa_add_cldflags__old_cflags="$CFLAGS"
  37. CFLAGS="$CFLAGS $1"
  38. pa_add_cldflags__old_ldflags="$LDFLAGS"
  39. LDFLAGS="$LDFLAGS $1"
  40. AC_TRY_LINK(AC_INCLUDES_DEFAULT,
  41. [printf("Hello, World!\n");],
  42. [AC_MSG_RESULT([yes])
  43. CFLAGS="$pa_add_cldflags__old_cflags ifelse([$2],[],[$1],[$2])"
  44. LDFLAGS="$pa_add_cldflags__old_ldflags ifelse([$2],[],[$1],[$2])"
  45. AC_DEFINE(PA_SYM([CFLAG_],[$1]), 1,
  46. [Define to 1 if compiled with the `$1' compiler flag])],
  47. [AC_MSG_RESULT([no])
  48. CFLAGS="$pa_add_cldflags__old_cflags"
  49. LDFLAGS="$pa_add_cldflags__old_ldflags"])])
  50. dnl --------------------------------------------------------------------------
  51. dnl PA_HAVE_FUNC(func_name)
  52. dnl
  53. dnl Look for a function with the specified arguments which could be
  54. dnl a builtin/intrinsic function.
  55. dnl --------------------------------------------------------------------------
  56. AC_DEFUN(PA_HAVE_FUNC,
  57. [AC_MSG_CHECKING([for $1])
  58. AC_LINK_IFELSE([AC_LANG_SOURCE([
  59. AC_INCLUDES_DEFAULT
  60. int main(void) {
  61. (void)$1$2;
  62. return 0;
  63. }
  64. ])],
  65. [AC_MSG_RESULT([yes])
  66. AC_DEFINE(AS_TR_CPP([HAVE_$1]), 1,
  67. [Define to 1 if you have the `$1' intrinsic function.])],
  68. [AC_MSG_RESULT([no])])
  69. ])
  70. dnl --------------------------------------------------------------------------
  71. dnl PA_LIBEXT
  72. dnl
  73. dnl Guess the library extension based on the object extension
  74. dnl --------------------------------------------------------------------------
  75. AC_DEFUN(PA_LIBEXT,
  76. [AC_MSG_CHECKING([for suffix of library files])
  77. if test x"$LIBEXT" = x; then
  78. case "$OBJEXT" in
  79. obj )
  80. LIBEXT=lib
  81. ;;
  82. *)
  83. LIBEXT=a
  84. ;;
  85. esac
  86. fi
  87. AC_MSG_RESULT([$LIBEXT])
  88. AC_SUBST([LIBEXT])])
  89. dnl --------------------------------------------------------------------------
  90. dnl PA_FUNC_ATTRIBUTE(attribute_name)
  91. dnl
  92. dnl See if this compiler supports the equivalent of a specific gcc
  93. dnl attribute on a function, using the __attribute__(()) syntax.
  94. dnl All arguments except the attribute name are optional.
  95. dnl PA_FUNC_ATTRIBUTE(attribute, attribute_opts, return_type,
  96. dnl prototype_args, call_args)
  97. dnl --------------------------------------------------------------------------
  98. AC_DEFUN(PA_FUNC_ATTRIBUTE,
  99. [AC_MSG_CHECKING([if $CC supports the $1 function attribute])
  100. AC_COMPILE_IFELSE([AC_LANG_SOURCE([
  101. AC_INCLUDES_DEFAULT
  102. extern ifelse([$3],[],[void *],[$3]) __attribute__(($1$2))
  103. bar(ifelse([$4],[],[int],[$4]));
  104. ifelse([$3],[],[void *],[$3]) foo(void);
  105. ifelse([$3],[],[void *],[$3]) foo(void)
  106. {
  107. ifelse([$3],[void],[],[return])
  108. bar(ifelse([$5],[],[1],[$5]));
  109. }
  110. ])],
  111. [AC_MSG_RESULT([yes])
  112. AC_DEFINE(PA_SYM([HAVE_FUNC_ATTRIBUTE_],[$1]), 1,
  113. [Define to 1 if your compiler supports __attribute__(($1)) on functions])],
  114. [AC_MSG_RESULT([no])])
  115. ])
  116. dnl --------------------------------------------------------------------------
  117. dnl PA_FUNC_ATTRIBUTE_ERROR
  118. dnl
  119. dnl See if this compiler supports __attribute__((error("foo")))
  120. dnl The generic version of this doesn't work as it makes the compiler
  121. dnl throw an error by design.
  122. dnl --------------------------------------------------------------------------
  123. AC_DEFUN(PA_FUNC_ATTRIBUTE_ERROR,
  124. [AC_MSG_CHECKING([if $CC supports the error function attribute])
  125. AC_COMPILE_IFELSE([AC_LANG_SOURCE([
  126. AC_INCLUDES_DEFAULT
  127. extern void __attribute__((error("message"))) barf(void);
  128. void foo(void);
  129. void foo(void)
  130. {
  131. if (0)
  132. barf();
  133. }
  134. ])],
  135. [AC_MSG_RESULT([yes])
  136. AC_DEFINE([HAVE_FUNC_ATTRIBUTE_ERROR], 1,
  137. [Define to 1 if your compiler supports __attribute__((error)) on functions])],
  138. [AC_MSG_RESULT([no])])
  139. ])
  140. dnl --------------------------------------------------------------------------
  141. dnl PA_ARG_ENABLED(option, helptext [,enabled_action [,disabled_action]])
  142. dnl PA_ARG_DISABLED(option, helptext [,disabled_action [,enabled_action]])
  143. dnl
  144. dnl Simpler-to-use versions of AC_ARG_ENABLED, that include the
  145. dnl test for $enableval and the AS_HELP_STRING definition
  146. dnl --------------------------------------------------------------------------
  147. AC_DEFUN(PA_ARG_ENABLED,
  148. [AC_ARG_ENABLE([$1], [AS_HELP_STRING([--enable-$1],[$2])], [], [enableval=no])
  149. AS_IF([test x"$enableval" != xno], [$3], [$4])
  150. ])
  151. AC_DEFUN(PA_ARG_DISABLED,
  152. [AC_ARG_ENABLE([$1],[AS_HELP_STRING([--disable-$1],[$2])], [], [enableval=yes])
  153. AS_IF([test x"$enableval" = xno], [$3], [$4])
  154. ])
  155. dnl --------------------------------------------------------------------------
  156. dnl PA_ADD_HEADERS(headers...)
  157. dnl
  158. dnl Call AC_CHECK_HEADERS(), and add to ac_includes_default if found
  159. dnl --------------------------------------------------------------------------
  160. AC_DEFUN(_PA_ADD_HEADER,
  161. [AC_CHECK_HEADERS([$1],[ac_includes_default="$ac_includes_default
  162. #include <$1>"
  163. ])])
  164. AC_DEFUN(PA_ADD_HEADERS,
  165. [m4_map_args_w([$1],[_PA_ADD_HEADER(],[)])])
  166. dnl --------------------------------------------------------------------------
  167. dnl PA_CHECK_BAD_STDC_INLINE
  168. dnl
  169. dnl Some versions of gcc seem to apply -Wmissing-prototypes to C99
  170. dnl inline functions, which means we need to use GNU inline syntax
  171. dnl --------------------------------------------------------------------------
  172. AC_DEFUN(PA_CHECK_BAD_STDC_INLINE,
  173. [AC_MSG_CHECKING([if $CC supports C99 external inlines])
  174. AC_COMPILE_IFELSE([AC_LANG_SOURCE([
  175. AC_INCLUDES_DEFAULT
  176. /* Don't mistake GNU inlines for c99 */
  177. #ifdef __GNUC_GNU_INLINE__
  178. # error "Using gnu inline standard"
  179. #endif
  180. inline int foo(int x)
  181. {
  182. return x+1;
  183. }
  184. ])],
  185. [AC_MSG_RESULT([yes])
  186. AC_DEFINE(HAVE_STDC_INLINE, 1,
  187. [Define to 1 if your compiler supports C99 extern inline])],
  188. [AC_MSG_RESULT([no])
  189. PA_ADD_CFLAGS([-fgnu89-inline])])])