acsite.m4 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  1. #These defines are needed because CentOS5 uses a old version of autoconf
  2. #
  3. AC_DEFUN([AC_TYPE_INT8_T], [_AC_TYPE_INT(8)])
  4. AC_DEFUN([AC_TYPE_INT16_T], [_AC_TYPE_INT(16)])
  5. AC_DEFUN([AC_TYPE_INT32_T], [_AC_TYPE_INT(32)])
  6. AC_DEFUN([AC_TYPE_INT64_T], [_AC_TYPE_INT(64)])
  7. AC_DEFUN([AC_TYPE_UINT8_T], [_AC_TYPE_UNSIGNED_INT(8)])
  8. AC_DEFUN([AC_TYPE_UINT16_T], [_AC_TYPE_UNSIGNED_INT(16)])
  9. AC_DEFUN([AC_TYPE_UINT32_T], [_AC_TYPE_UNSIGNED_INT(32)])
  10. AC_DEFUN([AC_TYPE_UINT64_T], [_AC_TYPE_UNSIGNED_INT(64)])
  11. AC_DEFUN([AC_TYPE_UINT], [_AC_TYPE_UTYPE(u_int)])
  12. AC_DEFUN([AC_TYPE_ULONG], [_AC_TYPE_UTYPE(u_long)])
  13. AC_DEFUN([AC_TYPE_UCHAR], [_AC_TYPE_UTYPE(u_char)])
  14. AC_DEFUN([AC_TYPE_USHORT], [_AC_TYPE_UTYPE(u_short)])
  15. # _AC_TYPE_UTYPE(BASE)
  16. # -------------------
  17. AC_DEFUN([_AC_TYPE_UTYPE],
  18. [
  19. AC_CACHE_CHECK([for $1], [ac_cv_c_$1],
  20. [ac_cv_c_$1=no
  21. case $1 in
  22. "u_long")
  23. ac_cv_c_$1_type="U_LONG"
  24. ;;
  25. "u_int")
  26. ac_cv_c_$1_type="U_INT"
  27. ;;
  28. "u_short")
  29. ac_cv_c_$1_type="U_SHORT"
  30. ;;
  31. "u_char")
  32. ac_cv_c_$1_type="U_CHAR"
  33. ;;
  34. *)
  35. ;;
  36. esac
  37. AC_COMPILE_IFELSE(
  38. [AC_LANG_BOOL_COMPILE_TRY(
  39. [AC_INCLUDES_DEFAULT],
  40. [[($1) -1 >> ((sizeof($1) * 8) - 1) == 1]])],
  41. [AS_CASE([$1], [$1],
  42. [ac_cv_c_$1=yes],
  43. [ac_cv_c_$1=no])])
  44. ])
  45. case $ac_cv_c_$1 in #(
  46. no)
  47. AC_DEFINE_UNQUOTED([HAVE_TYPE_$ac_cv_c_$1_type_NOT_DEFINED], [1], [$1 is undefined])
  48. ;;
  49. *)
  50. ;;
  51. esac
  52. ])# _AC_TYPE_UTYPE
  53. # _AC_TYPE_INT(NBITS)
  54. # -------------------
  55. AC_DEFUN([_AC_TYPE_INT],
  56. [
  57. AC_CACHE_CHECK([for int$1_t], [ac_cv_c_int$1_t],
  58. [ac_cv_c_int$1_t=no
  59. for ac_type in 'int$1_t' 'int' 'long int' \
  60. 'long long int' 'short int' 'signed char'; do
  61. AC_COMPILE_IFELSE(
  62. [AC_LANG_BOOL_COMPILE_TRY(
  63. [AC_INCLUDES_DEFAULT],
  64. [[0 < ($ac_type) (((($ac_type) 1 << ($1 - 2)) - 1) * 2 + 1)]])],
  65. [AC_COMPILE_IFELSE(
  66. [AC_LANG_BOOL_COMPILE_TRY(
  67. [AC_INCLUDES_DEFAULT],
  68. [[($ac_type) (((($ac_type) 1 << ($1 - 2)) - 1) * 2 + 1)
  69. < ($ac_type) (((($ac_type) 1 << ($1 - 2)) - 1) * 2 + 2)]])],
  70. [],
  71. [AS_CASE([$ac_type], [int$1_t],
  72. [ac_cv_c_int$1_t=yes],
  73. [ac_cv_c_int$1_t=$ac_type])])])
  74. test "$ac_cv_c_int$1_t" != no && break
  75. done])
  76. case $ac_cv_c_int$1_t in #(
  77. no|yes) ;; #(
  78. *)
  79. AC_DEFINE_UNQUOTED([int$1_t], [$ac_cv_c_int$1_t],
  80. [Define to the type of a signed integer type of width exactly $1 bits
  81. if such a type exists and the standard includes do not define it.]);;
  82. esac
  83. ])# _AC_TYPE_INT
  84. # _AC_TYPE_UNSIGNED_INT(NBITS)
  85. # ----------------------------
  86. AC_DEFUN([_AC_TYPE_UNSIGNED_INT],
  87. [
  88. AC_CACHE_CHECK([for uint$1_t], [ac_cv_c_uint$1_t],
  89. [ac_cv_c_uint$1_t=no
  90. for ac_type in 'uint$1_t' 'unsigned int' 'unsigned long int' \
  91. 'unsigned long long int' 'unsigned short int' 'unsigned char'; do
  92. AC_COMPILE_IFELSE(
  93. [AC_LANG_BOOL_COMPILE_TRY(
  94. [AC_INCLUDES_DEFAULT],
  95. [[($ac_type) -1 >> ($1 - 1) == 1]])],
  96. [AS_CASE([$ac_type], [uint$1_t],
  97. [ac_cv_c_uint$1_t=yes],
  98. [ac_cv_c_uint$1_t=$ac_type])])
  99. test "$ac_cv_c_uint$1_t" != no && break
  100. done])
  101. case $ac_cv_c_uint$1_t in #(
  102. no|yes) ;; #(
  103. *)
  104. m4_bmatch([$1], [^\(8\|32\|64\)$],
  105. [AC_DEFINE([_UINT$1_T], 1,
  106. [Define for Solaris 2.5.1 so the uint$1_t typedef from
  107. <sys/synch.h>, <pthread.h>, or <semaphore.h> is not used.
  108. If the typedef was allowed, the #define below would cause a
  109. syntax error.])])
  110. AC_DEFINE_UNQUOTED([uint$1_t], [$ac_cv_c_uint$1_t],
  111. [Define to the type of an unsigned integer type of width exactly $1 bits
  112. if such a type exists and the standard includes do not define it.]);;
  113. esac
  114. ])# _AC_TYPE_UNSIGNED_INT
  115. # AS_CASE(WORD, [PATTERN1], [IF-MATCHED1]...[DEFAULT])
  116. # ----------------------------------------------------
  117. # Expand into
  118. # | case WORD in
  119. # | PATTERN1) IF-MATCHED1 ;;
  120. # | ...
  121. # | *) DEFAULT ;;
  122. # | esac
  123. m4_define([_AS_CASE],
  124. [m4_if([$#], 0, [m4_fatal([$0: too few arguments: $#])],
  125. [$#], 1, [ *) $1 ;;],
  126. [$#], 2, [ $1) m4_default([$2], [:]) ;;],
  127. [ $1) m4_default([$2], [:]) ;;
  128. $0(m4_shiftn(2, $@))])dnl
  129. ])
  130. m4_defun([AS_CASE],
  131. [m4_ifval([$2$3],
  132. [case $1 in
  133. _AS_CASE(m4_shift($@))
  134. esac
  135. ])dnl
  136. ])# AS_CASE
  137. # _AC_PROG_CC_C99 ([ACTION-IF-AVAILABLE], [ACTION-IF-UNAVAILABLE])
  138. # ----------------------------------------------------------------
  139. # If the C compiler is not in ISO C99 mode by default, try to add an
  140. # option to output variable CC to make it so. This macro tries
  141. # various options that select ISO C99 on some system or another. It
  142. # considers the compiler to be in ISO C99 mode if it handles _Bool,
  143. # // comments, flexible array members, inline, long long int, mixed
  144. # code and declarations, named initialization of structs, restrict,
  145. # va_copy, varargs macros, variable declarations in for loops and
  146. # variable length arrays.
  147. AC_DEFUN([_AC_PROG_CC_C99],
  148. [_AC_C_STD_TRY([c99],
  149. [[#include <stdarg.h>
  150. #include <stdbool.h>
  151. #include <stdlib.h>
  152. #include <wchar.h>
  153. #include <stdio.h>
  154. // Check varargs macros. These examples are taken from C99 6.10.3.5.
  155. #define debug(...) fprintf (stderr, __VA_ARGS__)
  156. #define showlist(...) puts (#__VA_ARGS__)
  157. #define report(test,...) ((test) ? puts (#test) : printf (__VA_ARGS__))
  158. static void
  159. test_varargs_macros (void)
  160. {
  161. int x = 1234;
  162. int y = 5678;
  163. debug ("Flag");
  164. debug ("X = %d\n", x);
  165. showlist (The first, second, and third items.);
  166. report (x>y, "x is %d but y is %d", x, y);
  167. }
  168. // Check long long types.
  169. #define BIG64 18446744073709551615ull
  170. #define BIG32 4294967295ul
  171. #define BIG_OK (BIG64 / BIG32 == 4294967297ull && BIG64 % BIG32 == 0)
  172. #if !BIG_OK
  173. your preprocessor is broken;
  174. #endif
  175. #if BIG_OK
  176. #else
  177. your preprocessor is broken;
  178. #endif
  179. static long long int bignum = -9223372036854775807LL;
  180. static unsigned long long int ubignum = BIG64;
  181. struct incomplete_array
  182. {
  183. int datasize;
  184. double data[];
  185. };
  186. struct named_init {
  187. int number;
  188. const wchar_t *name;
  189. double average;
  190. };
  191. typedef const char *ccp;
  192. static inline int
  193. test_restrict (ccp restrict text)
  194. {
  195. // See if C++-style comments work.
  196. // Iterate through items via the restricted pointer.
  197. // Also check for declarations in for loops.
  198. for (unsigned int i = 0; *(text+i) != '\0'; ++i)
  199. continue;
  200. return 0;
  201. }
  202. // Check varargs and va_copy.
  203. static void
  204. test_varargs (const char *format, ...)
  205. {
  206. va_list args;
  207. va_start (args, format);
  208. va_list args_copy;
  209. va_copy (args_copy, args);
  210. const char *str;
  211. int number;
  212. float fnumber;
  213. while (*format)
  214. {
  215. switch (*format++)
  216. {
  217. case 's': // string
  218. str = va_arg (args_copy, const char *);
  219. break;
  220. case 'd': // int
  221. number = va_arg (args_copy, int);
  222. break;
  223. case 'f': // float
  224. fnumber = va_arg (args_copy, double);
  225. break;
  226. default:
  227. break;
  228. }
  229. }
  230. va_end (args_copy);
  231. va_end (args);
  232. }
  233. ]],
  234. [[
  235. // Check bool.
  236. _Bool success = false;
  237. // Check restrict.
  238. if (test_restrict ("String literal") == 0)
  239. success = true;
  240. char *restrict newvar = "Another string";
  241. // Check varargs.
  242. test_varargs ("s, d' f .", "string", 65, 34.234);
  243. test_varargs_macros ();
  244. // Check flexible array members.
  245. struct incomplete_array *ia =
  246. malloc (sizeof (struct incomplete_array) + (sizeof (double) * 10));
  247. ia->datasize = 10;
  248. for (int i = 0; i < ia->datasize; ++i)
  249. ia->data[i] = i * 1.234;
  250. // Check named initializers.
  251. struct named_init ni = {
  252. .number = 34,
  253. .name = L"Test wide string",
  254. .average = 543.34343,
  255. };
  256. ni.number = 58;
  257. int dynamic_array[ni.number];
  258. dynamic_array[ni.number - 1] = 543;
  259. // work around unused variable warnings
  260. return (!success || bignum == 0LL || ubignum == 0uLL || newvar[0] == 'x'
  261. || dynamic_array[ni.number - 1] != 543);
  262. ]],
  263. dnl Try
  264. dnl GCC -std=gnu99 (unused restrictive modes: -std=c99 -std=iso9899:1999)
  265. dnl AIX -qlanglvl=extc99 (unused restrictive mode: -qlanglvl=stdc99)
  266. dnl HP cc -AC99
  267. dnl Intel ICC -std=c99, -c99 (deprecated)
  268. dnl IRIX -c99
  269. dnl Solaris -xc99=all (Forte Developer 7 C mishandles -xc99 on Solaris 9,
  270. dnl as it incorrectly assumes C99 semantics for library functions)
  271. dnl Tru64 -c99
  272. dnl with extended modes being tried first.
  273. [[-std=gnu99 -std=c99 -c99 -AC99 -xc99=all -qlanglvl=extc99]], [$1], [$2])[]dnl
  274. ])# _AC_PROG_CC_C99
  275. # AC_PROG_CC_C89
  276. # --------------
  277. AC_DEFUN([AC_PROG_CC_C89],
  278. [ AC_REQUIRE([AC_PROG_CC])dnl
  279. _AC_PROG_CC_C89
  280. ])
  281. # AC_PROG_CC_C99
  282. # --------------
  283. AC_DEFUN([AC_PROG_CC_C99],
  284. [ AC_REQUIRE([AC_PROG_CC])dnl
  285. _AC_PROG_CC_C99
  286. ])
  287. # AC_PROG_CC_STDC
  288. # ---------------
  289. AC_DEFUN([AC_PROG_CC_STDC],
  290. [ AC_REQUIRE([AC_PROG_CC])dnl
  291. AS_CASE([$ac_cv_prog_cc_stdc],
  292. [no], [ac_cv_prog_cc_c99=no; ac_cv_prog_cc_c89=no],
  293. [_AC_PROG_CC_C99([ac_cv_prog_cc_stdc=$ac_cv_prog_cc_c99],
  294. [_AC_PROG_CC_C89([ac_cv_prog_cc_stdc=$ac_cv_prog_cc_c89],
  295. [ac_cv_prog_cc_stdc=no])])])dnl
  296. AC_MSG_CHECKING([for $CC option to accept ISO Standard C])
  297. AC_CACHE_VAL([ac_cv_prog_cc_stdc], [])
  298. AS_CASE([$ac_cv_prog_cc_stdc],
  299. [no], [AC_MSG_RESULT([unsupported])],
  300. [''], [AC_MSG_RESULT([none needed])],
  301. [AC_MSG_RESULT([$ac_cv_prog_cc_stdc])])
  302. ])
  303. # _AC_C_STD_TRY(STANDARD, TEST-PROLOGUE, TEST-BODY, OPTION-LIST,
  304. # ACTION-IF-AVAILABLE, ACTION-IF-UNAVAILABLE)
  305. # --------------------------------------------------------------
  306. # Check whether the C compiler accepts features of STANDARD (e.g `c89', `c99')
  307. # by trying to compile a program of TEST-PROLOGUE and TEST-BODY. If this fails,
  308. # try again with each compiler option in the space-separated OPTION-LIST; if one
  309. # helps, append it to CC. If eventually successful, run ACTION-IF-AVAILABLE,
  310. # else ACTION-IF-UNAVAILABLE.
  311. AC_DEFUN([_AC_C_STD_TRY],
  312. [AC_MSG_CHECKING([for $CC option to accept ISO ]m4_translit($1, [c], [C]))
  313. AC_CACHE_VAL(ac_cv_prog_cc_$1,
  314. [ac_cv_prog_cc_$1=no
  315. ac_save_CC=$CC
  316. AC_LANG_CONFTEST([AC_LANG_PROGRAM([$2], [$3])])
  317. for ac_arg in '' $4
  318. do
  319. CC="$ac_save_CC $ac_arg"
  320. _AC_COMPILE_IFELSE([], [ac_cv_prog_cc_$1=$ac_arg])
  321. test "x$ac_cv_prog_cc_$1" != "xno" && break
  322. done
  323. rm -f conftest.$ac_ext
  324. CC=$ac_save_CC
  325. ])# AC_CACHE_VAL
  326. case "x$ac_cv_prog_cc_$1" in
  327. x)
  328. AC_MSG_RESULT([none needed]) ;;
  329. xno)
  330. AC_MSG_RESULT([unsupported]) ;;
  331. *)
  332. CC="$CC $ac_cv_prog_cc_$1"
  333. AC_MSG_RESULT([$ac_cv_prog_cc_$1]) ;;
  334. esac
  335. AS_IF([test "x$ac_cv_prog_cc_$1" != xno], [$5], [$6])
  336. ])# _AC_C_STD_TRY