headers.m4 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895
  1. # This file is part of Autoconf. -*- Autoconf -*-
  2. # Checking for headers.
  3. #
  4. # Copyright (C) 1988, 1999-2004, 2006, 2008-2012 Free Software
  5. # Foundation, Inc.
  6. # This file is part of Autoconf. This program is free
  7. # software; you can redistribute it and/or modify it under the
  8. # terms of the GNU General Public License as published by the
  9. # Free Software Foundation, either version 3 of the License, or
  10. # (at your option) any later version.
  11. #
  12. # This program is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU General Public License for more details.
  16. #
  17. # Under Section 7 of GPL version 3, you are granted additional
  18. # permissions described in the Autoconf Configure Script Exception,
  19. # version 3.0, as published by the Free Software Foundation.
  20. #
  21. # You should have received a copy of the GNU General Public License
  22. # and a copy of the Autoconf Configure Script Exception along with
  23. # this program; see the files COPYINGv3 and COPYING.EXCEPTION
  24. # respectively. If not, see <http://www.gnu.org/licenses/>.
  25. # Written by David MacKenzie, with help from
  26. # Franc,ois Pinard, Karl Berry, Richard Pixley, Ian Lance Taylor,
  27. # Roland McGrath, Noah Friedman, david d zuhn, and many others.
  28. # Table of contents
  29. #
  30. # 1. Generic tests for headers
  31. # 2. Default includes
  32. # 3. Headers to tests with AC_CHECK_HEADERS
  33. # 4. Tests for specific headers
  34. ## ------------------------------ ##
  35. ## 1. Generic tests for headers. ##
  36. ## ------------------------------ ##
  37. # AC_CHECK_HEADER(HEADER-FILE,
  38. # [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND],
  39. # [INCLUDES])
  40. # ---------------------------------------------------------
  41. # We are slowly moving to checking headers with the compiler instead
  42. # of the preproc, so that we actually learn about the usability of a
  43. # header instead of its mere presence. But since users are used to
  44. # the old semantics, they check for headers in random order and
  45. # without providing prerequisite headers. This macro implements the
  46. # transition phase, and should be cleaned up latter to use compilation
  47. # only.
  48. #
  49. # If INCLUDES is empty, then check both via the compiler and preproc.
  50. # If the results are different, issue a warning, but keep the preproc
  51. # result.
  52. #
  53. # If INCLUDES is `-', keep only the old semantics.
  54. #
  55. # If INCLUDES is specified and different from `-', then use the new
  56. # semantics only.
  57. #
  58. # The m4_indir allows for fewer expansions of $@.
  59. AC_DEFUN([AC_CHECK_HEADER],
  60. [m4_indir(m4_case([$4],
  61. [], [[_AC_CHECK_HEADER_MONGREL]],
  62. [-], [[_AC_CHECK_HEADER_PREPROC]],
  63. [[_AC_CHECK_HEADER_COMPILE]]), $@)
  64. ])# AC_CHECK_HEADER
  65. # _AC_CHECK_HEADER_MONGREL_BODY
  66. # -----------------------------
  67. # Shell function body for _AC_CHECK_HEADER_MONGREL
  68. m4_define([_AC_CHECK_HEADER_MONGREL_BODY],
  69. [ AS_LINENO_PUSH([$[]1])
  70. AS_VAR_SET_IF([$[]3],
  71. [AC_CACHE_CHECK([for $[]2], [$[]3], [])],
  72. [# Is the header compilable?
  73. AC_MSG_CHECKING([$[]2 usability])
  74. AC_COMPILE_IFELSE([AC_LANG_SOURCE([$[]4
  75. @%:@include <$[]2>])],
  76. [ac_header_compiler=yes],
  77. [ac_header_compiler=no])
  78. AC_MSG_RESULT([$ac_header_compiler])
  79. # Is the header present?
  80. AC_MSG_CHECKING([$[]2 presence])
  81. AC_PREPROC_IFELSE([AC_LANG_SOURCE([@%:@include <$[]2>])],
  82. [ac_header_preproc=yes],
  83. [ac_header_preproc=no])
  84. AC_MSG_RESULT([$ac_header_preproc])
  85. # So? What about this header?
  86. case $ac_header_compiler:$ac_header_preproc:$ac_[]_AC_LANG_ABBREV[]_preproc_warn_flag in #((
  87. yes:no: )
  88. AC_MSG_WARN([$[]2: accepted by the compiler, rejected by the preprocessor!])
  89. AC_MSG_WARN([$[]2: proceeding with the compiler's result])
  90. ;;
  91. no:yes:* )
  92. AC_MSG_WARN([$[]2: present but cannot be compiled])
  93. AC_MSG_WARN([$[]2: check for missing prerequisite headers?])
  94. AC_MSG_WARN([$[]2: see the Autoconf documentation])
  95. AC_MSG_WARN([$[]2: section "Present But Cannot Be Compiled"])
  96. AC_MSG_WARN([$[]2: proceeding with the compiler's result])
  97. m4_ifset([AC_PACKAGE_BUGREPORT],
  98. [m4_n([( AS_BOX([Report this to ]AC_PACKAGE_BUGREPORT)
  99. ) | sed "s/^/$as_me: WARNING: /" >&2])])dnl
  100. ;;
  101. esac
  102. AC_CACHE_CHECK([for $[]2], [$[]3],
  103. [AS_VAR_SET([$[]3], [$ac_header_compiler])])])
  104. AS_LINENO_POP
  105. ])#_AC_CHECK_HEADER_MONGREL_BODY
  106. # _AC_CHECK_HEADER_MONGREL(HEADER-FILE,
  107. # [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND],
  108. # [INCLUDES = DEFAULT-INCLUDES])
  109. # ------------------------------------------------------------------
  110. # Check using both the compiler and the preprocessor. If they disagree,
  111. # warn, and the preproc wins.
  112. #
  113. # This is not based on _AC_CHECK_HEADER_COMPILE and _AC_CHECK_HEADER_PREPROC
  114. # because it obfuscate the code to try to factor everything, in particular
  115. # because of the cache variables, and the `checking ...' messages.
  116. AC_DEFUN([_AC_CHECK_HEADER_MONGREL],
  117. [AC_REQUIRE_SHELL_FN([ac_fn_]_AC_LANG_ABBREV[_check_header_mongrel],
  118. [AS_FUNCTION_DESCRIBE([ac_fn_]_AC_LANG_ABBREV[_check_header_mongrel],
  119. [LINENO HEADER VAR INCLUDES],
  120. [Tests whether HEADER exists, giving a warning if it cannot be compiled
  121. using the include files in INCLUDES and setting the cache variable VAR
  122. accordingly.])],
  123. [$0_BODY])]dnl
  124. [AS_VAR_PUSHDEF([ac_Header], [ac_cv_header_$1])]dnl
  125. [ac_fn_[]_AC_LANG_ABBREV[]_check_header_mongrel ]dnl
  126. ["$LINENO" "$1" "ac_Header" "AS_ESCAPE([AC_INCLUDES_DEFAULT([$4])], [""])"
  127. AS_VAR_IF([ac_Header], [yes], [$2], [$3])
  128. AS_VAR_POPDEF([ac_Header])])# _AC_CHECK_HEADER_MONGREL
  129. # _AC_CHECK_HEADER_COMPILE_BODY
  130. # -----------------------------
  131. # Shell function body for _AC_CHECK_HEADER_COMPILE
  132. m4_define([_AC_CHECK_HEADER_COMPILE_BODY],
  133. [ AS_LINENO_PUSH([$[]1])
  134. AC_CACHE_CHECK([for $[]2], [$[]3],
  135. [AC_COMPILE_IFELSE([AC_LANG_SOURCE([$[]4
  136. @%:@include <$[]2>])],
  137. [AS_VAR_SET([$[]3], [yes])],
  138. [AS_VAR_SET([$[]3], [no])])])
  139. AS_LINENO_POP
  140. ])# _AC_CHECK_HEADER_COMPILE_BODY
  141. # _AC_CHECK_HEADER_COMPILE(HEADER-FILE,
  142. # [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND],
  143. # [INCLUDES = DEFAULT-INCLUDES])
  144. # --------------------------------------------------------------
  145. # Check the compiler accepts HEADER-FILE. The INCLUDES are defaulted.
  146. AC_DEFUN([_AC_CHECK_HEADER_COMPILE],
  147. [AC_REQUIRE_SHELL_FN([ac_fn_]_AC_LANG_ABBREV[_check_header_compile],
  148. [AS_FUNCTION_DESCRIBE([ac_fn_]_AC_LANG_ABBREV[_check_header_compile],
  149. [LINENO HEADER VAR INCLUDES],
  150. [Tests whether HEADER exists and can be compiled using the include files
  151. in INCLUDES, setting the cache variable VAR accordingly.])],
  152. [$0_BODY])]dnl
  153. [AS_VAR_PUSHDEF([ac_Header], [ac_cv_header_$1])]dnl
  154. [ac_fn_[]_AC_LANG_ABBREV[]_check_header_compile ]dnl
  155. ["$LINENO" "$1" "ac_Header" "AS_ESCAPE([AC_INCLUDES_DEFAULT([$4])], [""])"
  156. AS_VAR_IF([ac_Header], [yes], [$2], [$3])
  157. AS_VAR_POPDEF([ac_Header])])# _AC_CHECK_HEADER_COMPILE
  158. # _AC_CHECK_HEADER_PREPROC_BODY
  159. # -----------------------------
  160. # Shell function body for _AC_CHECK_HEADER_PREPROC.
  161. m4_define([_AC_CHECK_HEADER_PREPROC_BODY],
  162. [ AS_LINENO_PUSH([$[]1])
  163. AC_CACHE_CHECK([for $[]2], [$[]3],
  164. [AC_PREPROC_IFELSE([AC_LANG_SOURCE([@%:@include <$[]2>])],
  165. [AS_VAR_SET([$[]3], [yes])],
  166. [AS_VAR_SET([$[]3], [no])])])
  167. AS_LINENO_POP
  168. ])# _AC_CHECK_HEADER_PREPROC_BODY
  169. # _AC_CHECK_HEADER_PREPROC(HEADER-FILE,
  170. # [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
  171. # --------------------------------------------------------------
  172. # Check the preprocessor accepts HEADER-FILE.
  173. AC_DEFUN([_AC_CHECK_HEADER_PREPROC],
  174. [AC_REQUIRE_SHELL_FN([ac_fn_]_AC_LANG_ABBREV[_check_header_preproc],
  175. [AS_FUNCTION_DESCRIBE([ac_fn_]_AC_LANG_ABBREV[_check_header_preproc],
  176. [LINENO HEADER VAR],
  177. [Tests whether HEADER is present, setting the cache variable VAR accordingly.])],
  178. [$0_BODY])]dnl
  179. [AS_VAR_PUSHDEF([ac_Header], [ac_cv_header_$1])]dnl
  180. [ac_fn_[]_AC_LANG_ABBREV[]_check_header_preproc "$LINENO" "$1" "ac_Header"
  181. AS_VAR_IF([ac_Header], [yes], [$2], [$3])
  182. AS_VAR_POPDEF([ac_Header])dnl
  183. ])# _AC_CHECK_HEADER_PREPROC
  184. # _AC_CHECK_HEADER_OLD(HEADER-FILE, [ACTION-IF-FOUND],
  185. # [ACTION-IF-NOT-FOUND])
  186. # _AC_CHECK_HEADER_NEW(HEADER-FILE, [ACTION-IF-FOUND],
  187. # [ACTION-IF-NOT-FOUND])
  188. # ----------------------------------------------------
  189. # Some packages used these undocumented macros. Even worse, gcc
  190. # redefined AC_CHECK_HEADER in terms of _AC_CHECK_HEADER_OLD, so we
  191. # can't do the simpler:
  192. # AU_DEFUN([_AC_CHECK_HEADER_OLD],
  193. # [AC_CHECK_HEADER([$1], [$2], [$3], [-])])
  194. AC_DEFUN([_AC_CHECK_HEADER_OLD],
  195. [AC_DIAGNOSE([obsolete], [The macro `$0' is obsolete.
  196. You should use AC_CHECK_HEADER with a fourth argument.])]dnl
  197. [_AC_CHECK_HEADER_PREPROC($@)])
  198. AC_DEFUN([_AC_CHECK_HEADER_NEW],
  199. [AC_DIAGNOSE([obsolete], [The macro `$0' is obsolete.
  200. You should use AC_CHECK_HEADER with a fourth argument.])]dnl
  201. [_AC_CHECK_HEADER_COMPILE($@)])
  202. # _AH_CHECK_HEADER(HEADER-FILE)
  203. # -----------------------------
  204. # Prepare the autoheader snippet for HEADER-FILE.
  205. m4_define([_AH_CHECK_HEADER],
  206. [AH_TEMPLATE(AS_TR_CPP([HAVE_$1]),
  207. [Define to 1 if you have the <$1> header file.])])
  208. # AH_CHECK_HEADERS(HEADER-FILE...)
  209. # --------------------------------
  210. m4_define([AH_CHECK_HEADERS],
  211. [m4_foreach_w([AC_Header], [$1], [_AH_CHECK_HEADER(m4_defn([AC_Header]))])])
  212. # AC_CHECK_HEADERS(HEADER-FILE...,
  213. # [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND],
  214. # [INCLUDES])
  215. # ----------------------------------------------------------
  216. # Check for each whitespace-separated HEADER-FILE (omitting the <> or
  217. # ""), and perform ACTION-IF-FOUND or ACTION-IF-NOT-FOUND for each
  218. # header. INCLUDES is as for AC_CHECK_HEADER. Additionally, make the
  219. # preprocessor definition HAVE_HEADER_FILE available for each found
  220. # header. Either ACTION may include `break' to stop the search.
  221. AC_DEFUN([AC_CHECK_HEADERS],
  222. [m4_map_args_w([$1], [_AH_CHECK_HEADER(], [)])]dnl
  223. [AS_FOR([AC_header], [ac_header], [$1],
  224. [AC_CHECK_HEADER(AC_header,
  225. [AC_DEFINE_UNQUOTED(AS_TR_CPP([HAVE_]AC_header)) $2],
  226. [$3], [$4])dnl])
  227. ])# AC_CHECK_HEADERS
  228. # _AC_CHECK_HEADER_ONCE(HEADER-FILE)
  229. # ----------------------------------
  230. # Check for a single HEADER-FILE once.
  231. m4_define([_AC_CHECK_HEADER_ONCE],
  232. [_AH_CHECK_HEADER([$1])AC_DEFUN([_AC_Header_]m4_translit([[$1]],
  233. [./-], [___]),
  234. [m4_divert_text([INIT_PREPARE], [AS_VAR_APPEND([ac_header_list], [" $1"])])
  235. _AC_HEADERS_EXPANSION])AC_REQUIRE([_AC_Header_]m4_translit([[$1]],
  236. [./-], [___]))])
  237. # AC_CHECK_HEADERS_ONCE(HEADER-FILE...)
  238. # -------------------------------------
  239. # Add each whitespace-separated name in HEADER-FILE to the list of
  240. # headers to check once.
  241. AC_DEFUN([AC_CHECK_HEADERS_ONCE],
  242. [m4_map_args_w([$1], [_AC_CHECK_HEADER_ONCE(], [)])])
  243. m4_define([_AC_HEADERS_EXPANSION],
  244. [
  245. m4_divert_text([DEFAULTS], [ac_header_list=])
  246. AC_CHECK_HEADERS([$ac_header_list], [], [], [AC_INCLUDES_DEFAULT])
  247. m4_define([_AC_HEADERS_EXPANSION], [])
  248. ])
  249. ## --------------------- ##
  250. ## 2. Default includes. ##
  251. ## --------------------- ##
  252. # Always use the same set of default headers for all the generic
  253. # macros. It is easier to document, to extend, and to understand than
  254. # having specific defaults for each macro.
  255. # _AC_INCLUDES_DEFAULT_REQUIREMENTS
  256. # ---------------------------------
  257. # Required when AC_INCLUDES_DEFAULT uses its default branch.
  258. AC_DEFUN([_AC_INCLUDES_DEFAULT_REQUIREMENTS],
  259. [m4_divert_text([DEFAULTS],
  260. [# Factoring default headers for most tests.
  261. dnl If ever you change this variable, please keep autoconf.texi in sync.
  262. ac_includes_default="\
  263. #include <stdio.h>
  264. #ifdef HAVE_SYS_TYPES_H
  265. # include <sys/types.h>
  266. #endif
  267. #ifdef HAVE_SYS_STAT_H
  268. # include <sys/stat.h>
  269. #endif
  270. #ifdef STDC_HEADERS
  271. # include <stdlib.h>
  272. # include <stddef.h>
  273. #else
  274. # ifdef HAVE_STDLIB_H
  275. # include <stdlib.h>
  276. # endif
  277. #endif
  278. #ifdef HAVE_STRING_H
  279. # if !defined STDC_HEADERS && defined HAVE_MEMORY_H
  280. # include <memory.h>
  281. # endif
  282. # include <string.h>
  283. #endif
  284. #ifdef HAVE_STRINGS_H
  285. # include <strings.h>
  286. #endif
  287. #ifdef HAVE_INTTYPES_H
  288. # include <inttypes.h>
  289. #endif
  290. #ifdef HAVE_STDINT_H
  291. # include <stdint.h>
  292. #endif
  293. #ifdef HAVE_UNISTD_H
  294. # include <unistd.h>
  295. #endif"
  296. ])dnl
  297. AC_REQUIRE([AC_HEADER_STDC])dnl
  298. # On IRIX 5.3, sys/types and inttypes.h are conflicting.
  299. AC_CHECK_HEADERS([sys/types.h sys/stat.h stdlib.h string.h memory.h strings.h \
  300. inttypes.h stdint.h unistd.h],
  301. [], [], $ac_includes_default)
  302. ])# _AC_INCLUDES_DEFAULT_REQUIREMENTS
  303. # AC_INCLUDES_DEFAULT([INCLUDES])
  304. # -------------------------------
  305. # If INCLUDES is empty, expand in default includes, otherwise in
  306. # INCLUDES.
  307. # In most cases INCLUDES is not double quoted as it should, and if
  308. # for instance INCLUDES = `#include <stdio.h>' then unless we force
  309. # a newline, the hash will swallow the closing paren etc. etc.
  310. # The usual failure.
  311. # Take no risk: for the newline.
  312. AC_DEFUN([AC_INCLUDES_DEFAULT],
  313. [m4_ifval([$1], [$1
  314. ],
  315. [AC_REQUIRE([_AC_INCLUDES_DEFAULT_REQUIREMENTS])dnl
  316. $ac_includes_default])])
  317. ## ------------------------------------------- ##
  318. ## 3. Headers to check with AC_CHECK_HEADERS. ##
  319. ## ------------------------------------------- ##
  320. # errno.h is portable.
  321. AN_HEADER([OS.h], [AC_CHECK_HEADERS])
  322. AN_HEADER([argz.h], [AC_CHECK_HEADERS])
  323. AN_HEADER([arpa/inet.h], [AC_CHECK_HEADERS])
  324. AN_HEADER([fcntl.h], [AC_CHECK_HEADERS])
  325. AN_HEADER([fenv.h], [AC_CHECK_HEADERS])
  326. AN_HEADER([float.h], [AC_CHECK_HEADERS])
  327. AN_HEADER([fs_info.h], [AC_CHECK_HEADERS])
  328. AN_HEADER([inttypes.h], [AC_CHECK_HEADERS])
  329. AN_HEADER([langinfo.h], [AC_CHECK_HEADERS])
  330. AN_HEADER([libintl.h], [AC_CHECK_HEADERS])
  331. AN_HEADER([limits.h], [AC_CHECK_HEADERS])
  332. AN_HEADER([locale.h], [AC_CHECK_HEADERS])
  333. AN_HEADER([mach/mach.h], [AC_CHECK_HEADERS])
  334. AN_HEADER([malloc.h], [AC_CHECK_HEADERS])
  335. AN_HEADER([memory.h], [AC_CHECK_HEADERS])
  336. AN_HEADER([mntent.h], [AC_CHECK_HEADERS])
  337. AN_HEADER([mnttab.h], [AC_CHECK_HEADERS])
  338. AN_HEADER([netdb.h], [AC_CHECK_HEADERS])
  339. AN_HEADER([netinet/in.h], [AC_CHECK_HEADERS])
  340. AN_HEADER([nl_types.h], [AC_CHECK_HEADERS])
  341. AN_HEADER([nlist.h], [AC_CHECK_HEADERS])
  342. AN_HEADER([paths.h], [AC_CHECK_HEADERS])
  343. AN_HEADER([sgtty.h], [AC_CHECK_HEADERS])
  344. AN_HEADER([shadow.h], [AC_CHECK_HEADERS])
  345. AN_HEADER([stddef.h], [AC_CHECK_HEADERS])
  346. AN_HEADER([stdint.h], [AC_CHECK_HEADERS])
  347. AN_HEADER([stdio_ext.h], [AC_CHECK_HEADERS])
  348. AN_HEADER([stdlib.h], [AC_CHECK_HEADERS])
  349. AN_HEADER([string.h], [AC_CHECK_HEADERS])
  350. AN_HEADER([strings.h], [AC_CHECK_HEADERS])
  351. AN_HEADER([sys/acl.h], [AC_CHECK_HEADERS])
  352. AN_HEADER([sys/file.h], [AC_CHECK_HEADERS])
  353. AN_HEADER([sys/filsys.h], [AC_CHECK_HEADERS])
  354. AN_HEADER([sys/fs/s5param.h], [AC_CHECK_HEADERS])
  355. AN_HEADER([sys/fs_types.h], [AC_CHECK_HEADERS])
  356. AN_HEADER([sys/fstyp.h], [AC_CHECK_HEADERS])
  357. AN_HEADER([sys/ioctl.h], [AC_CHECK_HEADERS])
  358. AN_HEADER([sys/mntent.h], [AC_CHECK_HEADERS])
  359. AN_HEADER([sys/mount.h], [AC_CHECK_HEADERS])
  360. AN_HEADER([sys/param.h], [AC_CHECK_HEADERS])
  361. AN_HEADER([sys/socket.h], [AC_CHECK_HEADERS])
  362. AN_HEADER([sys/statfs.h], [AC_CHECK_HEADERS])
  363. AN_HEADER([sys/statvfs.h], [AC_CHECK_HEADERS])
  364. AN_HEADER([sys/systeminfo.h], [AC_CHECK_HEADERS])
  365. AN_HEADER([sys/time.h], [AC_CHECK_HEADERS])
  366. AN_HEADER([sys/timeb.h], [AC_CHECK_HEADERS])
  367. AN_HEADER([sys/vfs.h], [AC_CHECK_HEADERS])
  368. AN_HEADER([sys/window.h], [AC_CHECK_HEADERS])
  369. AN_HEADER([syslog.h], [AC_CHECK_HEADERS])
  370. AN_HEADER([termio.h], [AC_CHECK_HEADERS])
  371. AN_HEADER([termios.h], [AC_CHECK_HEADERS])
  372. AN_HEADER([unistd.h], [AC_CHECK_HEADERS])
  373. AN_HEADER([utime.h], [AC_CHECK_HEADERS])
  374. AN_HEADER([utmp.h], [AC_CHECK_HEADERS])
  375. AN_HEADER([utmpx.h], [AC_CHECK_HEADERS])
  376. AN_HEADER([values.h], [AC_CHECK_HEADERS])
  377. AN_HEADER([wchar.h], [AC_CHECK_HEADERS])
  378. AN_HEADER([wctype.h], [AC_CHECK_HEADERS])
  379. ## ------------------------------- ##
  380. ## 4. Tests for specific headers. ##
  381. ## ------------------------------- ##
  382. # AC_HEADER_ASSERT
  383. # ----------------
  384. # Check whether to enable assertions.
  385. AC_DEFUN_ONCE([AC_HEADER_ASSERT],
  386. [
  387. AC_MSG_CHECKING([whether to enable assertions])
  388. AC_ARG_ENABLE([assert],
  389. [AS_HELP_STRING([--disable-assert], [turn off assertions])],
  390. [ac_enable_assert=$enableval
  391. AS_IF(dnl
  392. [test "x$enableval" = xno],
  393. [AC_DEFINE([NDEBUG], [1],
  394. [Define to 1 if assertions should be disabled.])],
  395. [test "x$enableval" != xyes],
  396. [AC_MSG_WARN([invalid argument supplied to --enable-assert])
  397. ac_enable_assert=yes])],
  398. [ac_enable_assert=yes])
  399. AC_MSG_RESULT([$ac_enable_assert])
  400. ])
  401. # _AC_CHECK_HEADER_DIRENT(HEADER-FILE,
  402. # [ACTION-IF-FOUND], [ACTION-IF-NOT_FOUND])
  403. # -----------------------------------------------------------------
  404. # Like AC_CHECK_HEADER, except also make sure that HEADER-FILE
  405. # defines the type `DIR'. dirent.h on NextStep 3.2 doesn't.
  406. m4_define([_AC_CHECK_HEADER_DIRENT],
  407. [AS_VAR_PUSHDEF([ac_Header], [ac_cv_header_dirent_$1])dnl
  408. AC_CACHE_CHECK([for $1 that defines DIR], [ac_Header],
  409. [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include <sys/types.h>
  410. #include <$1>
  411. ],
  412. [if ((DIR *) 0)
  413. return 0;])],
  414. [AS_VAR_SET([ac_Header], [yes])],
  415. [AS_VAR_SET([ac_Header], [no])])])
  416. AS_VAR_IF([ac_Header], [yes], [$2], [$3])
  417. AS_VAR_POPDEF([ac_Header])dnl
  418. ])# _AC_CHECK_HEADER_DIRENT
  419. # _AH_CHECK_HEADER_DIRENT(HEADERS)
  420. # --------------------------------
  421. # Like _AH_CHECK_HEADER, but tuned to a dirent provider.
  422. m4_define([_AH_CHECK_HEADER_DIRENT],
  423. [AH_TEMPLATE(AS_TR_CPP([HAVE_$1]),
  424. [Define to 1 if you have the <$1> header file, and it defines `DIR'.])])
  425. # AC_HEADER_DIRENT
  426. # ----------------
  427. AC_DEFUN([AC_HEADER_DIRENT],
  428. [m4_map_args([_AH_CHECK_HEADER_DIRENT], [dirent.h], [sys/ndir.h],
  429. [sys/dir.h], [ndir.h])]dnl
  430. [ac_header_dirent=no
  431. for ac_hdr in dirent.h sys/ndir.h sys/dir.h ndir.h; do
  432. _AC_CHECK_HEADER_DIRENT($ac_hdr,
  433. [AC_DEFINE_UNQUOTED(AS_TR_CPP(HAVE_$ac_hdr), 1)
  434. ac_header_dirent=$ac_hdr; break])
  435. done
  436. # Two versions of opendir et al. are in -ldir and -lx on SCO Xenix.
  437. if test $ac_header_dirent = dirent.h; then
  438. AC_SEARCH_LIBS(opendir, dir)
  439. else
  440. AC_SEARCH_LIBS(opendir, x)
  441. fi
  442. ])# AC_HEADER_DIRENT
  443. # AC_HEADER_MAJOR
  444. # ---------------
  445. AN_FUNCTION([major], [AC_HEADER_MAJOR])
  446. AN_FUNCTION([makedev], [AC_HEADER_MAJOR])
  447. AN_FUNCTION([minor], [AC_HEADER_MAJOR])
  448. AN_HEADER([sys/mkdev.h], [AC_HEADER_MAJOR])
  449. AC_DEFUN([AC_HEADER_MAJOR],
  450. [AC_CACHE_CHECK(whether sys/types.h defines makedev,
  451. ac_cv_header_sys_types_h_makedev,
  452. [AC_LINK_IFELSE([AC_LANG_PROGRAM([[@%:@include <sys/types.h>]],
  453. [[return makedev(0, 0);]])],
  454. [ac_cv_header_sys_types_h_makedev=yes],
  455. [ac_cv_header_sys_types_h_makedev=no])
  456. ])
  457. if test $ac_cv_header_sys_types_h_makedev = no; then
  458. AC_CHECK_HEADER(sys/mkdev.h,
  459. [AC_DEFINE(MAJOR_IN_MKDEV, 1,
  460. [Define to 1 if `major', `minor', and `makedev' are
  461. declared in <mkdev.h>.])])
  462. if test $ac_cv_header_sys_mkdev_h = no; then
  463. AC_CHECK_HEADER(sys/sysmacros.h,
  464. [AC_DEFINE(MAJOR_IN_SYSMACROS, 1,
  465. [Define to 1 if `major', `minor', and `makedev'
  466. are declared in <sysmacros.h>.])])
  467. fi
  468. fi
  469. ])# AC_HEADER_MAJOR
  470. # AC_HEADER_RESOLV
  471. # ----------------
  472. # According to http://www.mcsr.olemiss.edu/cgi-bin/man-cgi?resolver+3
  473. # (or http://www.chemie.fu-berlin.de/cgi-bin/man/sgi_irix?resolver+3),
  474. # sys/types.h, netinet/in.h and arpa/nameser.h are required on IRIX.
  475. # netinet/in.h is needed on Cygwin, too.
  476. # With Solaris 9, netdb.h is required, to get symbols like HOST_NOT_FOUND.
  477. #
  478. AN_HEADER(resolv.h, [AC_HEADER_RESOLV])
  479. AC_DEFUN([AC_HEADER_RESOLV],
  480. [AC_CHECK_HEADERS(sys/types.h netinet/in.h arpa/nameser.h netdb.h resolv.h,
  481. [], [],
  482. [[#ifdef HAVE_SYS_TYPES_H
  483. # include <sys/types.h>
  484. #endif
  485. #ifdef HAVE_NETINET_IN_H
  486. # include <netinet/in.h> /* inet_ functions / structs */
  487. #endif
  488. #ifdef HAVE_ARPA_NAMESER_H
  489. # include <arpa/nameser.h> /* DNS HEADER struct */
  490. #endif
  491. #ifdef HAVE_NETDB_H
  492. # include <netdb.h>
  493. #endif]])
  494. ])# AC_HEADER_RESOLV
  495. # AC_HEADER_STAT
  496. # --------------
  497. # FIXME: Shouldn't this be named AC_HEADER_SYS_STAT?
  498. AC_DEFUN([AC_HEADER_STAT],
  499. [AC_CACHE_CHECK(whether stat file-mode macros are broken,
  500. ac_cv_header_stat_broken,
  501. [AC_COMPILE_IFELSE([AC_LANG_SOURCE([[#include <sys/types.h>
  502. #include <sys/stat.h>
  503. #if defined S_ISBLK && defined S_IFDIR
  504. extern char c1[S_ISBLK (S_IFDIR) ? -1 : 1];
  505. #endif
  506. #if defined S_ISBLK && defined S_IFCHR
  507. extern char c2[S_ISBLK (S_IFCHR) ? -1 : 1];
  508. #endif
  509. #if defined S_ISLNK && defined S_IFREG
  510. extern char c3[S_ISLNK (S_IFREG) ? -1 : 1];
  511. #endif
  512. #if defined S_ISSOCK && defined S_IFREG
  513. extern char c4[S_ISSOCK (S_IFREG) ? -1 : 1];
  514. #endif
  515. ]])], ac_cv_header_stat_broken=no, ac_cv_header_stat_broken=yes)])
  516. if test $ac_cv_header_stat_broken = yes; then
  517. AC_DEFINE(STAT_MACROS_BROKEN, 1,
  518. [Define to 1 if the `S_IS*' macros in <sys/stat.h> do not
  519. work properly.])
  520. fi
  521. ])# AC_HEADER_STAT
  522. # AC_CHECK_HEADER_STDBOOL
  523. # -----------------
  524. # Check for stdbool.h that conforms to C99.
  525. AN_IDENTIFIER([bool], [AC_CHECK_HEADER_STDBOOL])
  526. AN_IDENTIFIER([true], [AC_CHECK_HEADER_STDBOOL])
  527. AN_IDENTIFIER([false],[AC_CHECK_HEADER_STDBOOL])
  528. AC_DEFUN([AC_CHECK_HEADER_STDBOOL],
  529. [AC_CACHE_CHECK([for stdbool.h that conforms to C99],
  530. [ac_cv_header_stdbool_h],
  531. [AC_COMPILE_IFELSE(
  532. [AC_LANG_PROGRAM(
  533. [[
  534. #include <stdbool.h>
  535. #ifndef bool
  536. "error: bool is not defined"
  537. #endif
  538. #ifndef false
  539. "error: false is not defined"
  540. #endif
  541. #if false
  542. "error: false is not 0"
  543. #endif
  544. #ifndef true
  545. "error: true is not defined"
  546. #endif
  547. #if true != 1
  548. "error: true is not 1"
  549. #endif
  550. #ifndef __bool_true_false_are_defined
  551. "error: __bool_true_false_are_defined is not defined"
  552. #endif
  553. struct s { _Bool s: 1; _Bool t; } s;
  554. char a[true == 1 ? 1 : -1];
  555. char b[false == 0 ? 1 : -1];
  556. char c[__bool_true_false_are_defined == 1 ? 1 : -1];
  557. char d[(bool) 0.5 == true ? 1 : -1];
  558. /* See body of main program for 'e'. */
  559. char f[(_Bool) 0.0 == false ? 1 : -1];
  560. char g[true];
  561. char h[sizeof (_Bool)];
  562. char i[sizeof s.t];
  563. enum { j = false, k = true, l = false * true, m = true * 256 };
  564. /* The following fails for
  565. HP aC++/ANSI C B3910B A.05.55 [Dec 04 2003]. */
  566. _Bool n[m];
  567. char o[sizeof n == m * sizeof n[0] ? 1 : -1];
  568. char p[-1 - (_Bool) 0 < 0 && -1 - (bool) 0 < 0 ? 1 : -1];
  569. /* Catch a bug in an HP-UX C compiler. See
  570. http://gcc.gnu.org/ml/gcc-patches/2003-12/msg02303.html
  571. http://lists.gnu.org/archive/html/bug-coreutils/2005-11/msg00161.html
  572. */
  573. _Bool q = true;
  574. _Bool *pq = &q;
  575. ]],
  576. [[
  577. bool e = &s;
  578. *pq |= q;
  579. *pq |= ! q;
  580. /* Refer to every declared value, to avoid compiler optimizations. */
  581. return (!a + !b + !c + !d + !e + !f + !g + !h + !i + !!j + !k + !!l
  582. + !m + !n + !o + !p + !q + !pq);
  583. ]])],
  584. [ac_cv_header_stdbool_h=yes],
  585. [ac_cv_header_stdbool_h=no])])
  586. AC_CHECK_TYPES([_Bool])
  587. ])# AC_CHECK_HEADER_STDBOOL
  588. # AC_HEADER_STDBOOL
  589. # -----------------
  590. # Define HAVE_STDBOOL_H if tdbool.h that conforms to C99.
  591. AC_DEFUN([AC_HEADER_STDBOOL],
  592. [AC_CHECK_HEADER_STDBOOL
  593. if test $ac_cv_header_stdbool_h = yes; then
  594. AC_DEFINE(HAVE_STDBOOL_H, 1, [Define to 1 if stdbool.h conforms to C99.])
  595. fi
  596. ])# AC_HEADER_STDBOOL
  597. # AC_HEADER_STDC
  598. # --------------
  599. AC_DEFUN([AC_HEADER_STDC],
  600. [AC_CACHE_CHECK(for ANSI C header files, ac_cv_header_stdc,
  601. [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <stdlib.h>
  602. #include <stdarg.h>
  603. #include <string.h>
  604. #include <float.h>
  605. ]])],
  606. [ac_cv_header_stdc=yes],
  607. [ac_cv_header_stdc=no])
  608. if test $ac_cv_header_stdc = yes; then
  609. # SunOS 4.x string.h does not declare mem*, contrary to ANSI.
  610. AC_EGREP_HEADER(memchr, string.h, , ac_cv_header_stdc=no)
  611. fi
  612. if test $ac_cv_header_stdc = yes; then
  613. # ISC 2.0.2 stdlib.h does not declare free, contrary to ANSI.
  614. AC_EGREP_HEADER(free, stdlib.h, , ac_cv_header_stdc=no)
  615. fi
  616. if test $ac_cv_header_stdc = yes; then
  617. # /bin/cc in Irix-4.0.5 gets non-ANSI ctype macros unless using -ansi.
  618. AC_RUN_IFELSE([AC_LANG_SOURCE(
  619. [[#include <ctype.h>
  620. #include <stdlib.h>
  621. #if ((' ' & 0x0FF) == 0x020)
  622. # define ISLOWER(c) ('a' <= (c) && (c) <= 'z')
  623. # define TOUPPER(c) (ISLOWER(c) ? 'A' + ((c) - 'a') : (c))
  624. #else
  625. # define ISLOWER(c) \
  626. (('a' <= (c) && (c) <= 'i') \
  627. || ('j' <= (c) && (c) <= 'r') \
  628. || ('s' <= (c) && (c) <= 'z'))
  629. # define TOUPPER(c) (ISLOWER(c) ? ((c) | 0x40) : (c))
  630. #endif
  631. #define XOR(e, f) (((e) && !(f)) || (!(e) && (f)))
  632. int
  633. main ()
  634. {
  635. int i;
  636. for (i = 0; i < 256; i++)
  637. if (XOR (islower (i), ISLOWER (i))
  638. || toupper (i) != TOUPPER (i))
  639. return 2;
  640. return 0;
  641. }]])], , ac_cv_header_stdc=no, :)
  642. fi])
  643. if test $ac_cv_header_stdc = yes; then
  644. AC_DEFINE(STDC_HEADERS, 1,
  645. [Define to 1 if you have the ANSI C header files.])
  646. fi
  647. ])# AC_HEADER_STDC
  648. # AC_HEADER_SYS_WAIT
  649. # ------------------
  650. AC_DEFUN([AC_HEADER_SYS_WAIT],
  651. [AC_CACHE_CHECK([for sys/wait.h that is POSIX.1 compatible],
  652. ac_cv_header_sys_wait_h,
  653. [AC_COMPILE_IFELSE(
  654. [AC_LANG_PROGRAM([#include <sys/types.h>
  655. #include <sys/wait.h>
  656. #ifndef WEXITSTATUS
  657. # define WEXITSTATUS(stat_val) ((unsigned int) (stat_val) >> 8)
  658. #endif
  659. #ifndef WIFEXITED
  660. # define WIFEXITED(stat_val) (((stat_val) & 255) == 0)
  661. #endif
  662. ],
  663. [ int s;
  664. wait (&s);
  665. s = WIFEXITED (s) ? WEXITSTATUS (s) : 1;])],
  666. [ac_cv_header_sys_wait_h=yes],
  667. [ac_cv_header_sys_wait_h=no])])
  668. if test $ac_cv_header_sys_wait_h = yes; then
  669. AC_DEFINE(HAVE_SYS_WAIT_H, 1,
  670. [Define to 1 if you have <sys/wait.h> that is POSIX.1 compatible.])
  671. fi
  672. ])# AC_HEADER_SYS_WAIT
  673. # AC_HEADER_TIME
  674. # --------------
  675. AC_DEFUN([AC_HEADER_TIME],
  676. [AC_CACHE_CHECK([whether time.h and sys/time.h may both be included],
  677. ac_cv_header_time,
  678. [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include <sys/types.h>
  679. #include <sys/time.h>
  680. #include <time.h>
  681. ],
  682. [if ((struct tm *) 0)
  683. return 0;])],
  684. [ac_cv_header_time=yes],
  685. [ac_cv_header_time=no])])
  686. if test $ac_cv_header_time = yes; then
  687. AC_DEFINE(TIME_WITH_SYS_TIME, 1,
  688. [Define to 1 if you can safely include both <sys/time.h>
  689. and <time.h>.])
  690. fi
  691. ])# AC_HEADER_TIME
  692. # _AC_HEADER_TIOCGWINSZ_IN_TERMIOS_H
  693. # ----------------------------------
  694. m4_define([_AC_HEADER_TIOCGWINSZ_IN_TERMIOS_H],
  695. [AC_CACHE_CHECK([whether termios.h defines TIOCGWINSZ],
  696. ac_cv_sys_tiocgwinsz_in_termios_h,
  697. [AC_EGREP_CPP([yes],
  698. [#include <sys/types.h>
  699. #include <termios.h>
  700. #ifdef TIOCGWINSZ
  701. yes
  702. #endif
  703. ],
  704. ac_cv_sys_tiocgwinsz_in_termios_h=yes,
  705. ac_cv_sys_tiocgwinsz_in_termios_h=no)])
  706. ])# _AC_HEADER_TIOCGWINSZ_IN_TERMIOS_H
  707. # _AC_HEADER_TIOCGWINSZ_IN_SYS_IOCTL
  708. # ----------------------------------
  709. m4_define([_AC_HEADER_TIOCGWINSZ_IN_SYS_IOCTL],
  710. [AC_CACHE_CHECK([whether sys/ioctl.h defines TIOCGWINSZ],
  711. ac_cv_sys_tiocgwinsz_in_sys_ioctl_h,
  712. [AC_EGREP_CPP([yes],
  713. [#include <sys/types.h>
  714. #include <sys/ioctl.h>
  715. #ifdef TIOCGWINSZ
  716. yes
  717. #endif
  718. ],
  719. ac_cv_sys_tiocgwinsz_in_sys_ioctl_h=yes,
  720. ac_cv_sys_tiocgwinsz_in_sys_ioctl_h=no)])
  721. ])# _AC_HEADER_TIOCGWINSZ_IN_SYS_IOCTL
  722. # AC_HEADER_TIOCGWINSZ
  723. # --------------------
  724. # Look for a header that defines TIOCGWINSZ.
  725. # FIXME: Is this the proper name? Is this the proper implementation?
  726. # I need more help.
  727. AC_DEFUN([AC_HEADER_TIOCGWINSZ],
  728. [_AC_HEADER_TIOCGWINSZ_IN_TERMIOS_H
  729. if test $ac_cv_sys_tiocgwinsz_in_termios_h != yes; then
  730. _AC_HEADER_TIOCGWINSZ_IN_SYS_IOCTL
  731. if test $ac_cv_sys_tiocgwinsz_in_sys_ioctl_h = yes; then
  732. AC_DEFINE(GWINSZ_IN_SYS_IOCTL,1,
  733. [Define to 1 if `TIOCGWINSZ' requires <sys/ioctl.h>.])
  734. fi
  735. fi
  736. ])# AC_HEADER_TIOCGWINSZ
  737. # AU::AC_UNISTD_H
  738. # ---------------
  739. AU_DEFUN([AC_UNISTD_H],
  740. [AC_CHECK_HEADERS(unistd.h)])
  741. # AU::AC_USG
  742. # ----------
  743. # Define `USG' if string functions are in strings.h.
  744. AU_DEFUN([AC_USG],
  745. [AC_MSG_CHECKING([for BSD string and memory functions])
  746. AC_LINK_IFELSE([AC_LANG_PROGRAM([[@%:@include <strings.h>]],
  747. [[rindex(0, 0); bzero(0, 0);]])],
  748. [AC_MSG_RESULT(yes)],
  749. [AC_MSG_RESULT(no)
  750. AC_DEFINE(USG, 1,
  751. [Define to 1 if you do not have <strings.h>, index,
  752. bzero, etc... This symbol is obsolete, you should
  753. not depend upon it.])])
  754. AC_CHECK_HEADERS(string.h)],
  755. [Remove `AC_MSG_CHECKING', `AC_LINK_IFELSE' and this warning
  756. when you adjust your code to use HAVE_STRING_H.])
  757. # AU::AC_MEMORY_H
  758. # ---------------
  759. # To be precise this macro used to be:
  760. #
  761. # | AC_MSG_CHECKING(whether string.h declares mem functions)
  762. # | AC_EGREP_HEADER(memchr, string.h, ac_found=yes, ac_found=no)
  763. # | AC_MSG_RESULT($ac_found)
  764. # | if test $ac_found = no; then
  765. # | AC_CHECK_HEADER(memory.h, [AC_DEFINE(NEED_MEMORY_H)])
  766. # | fi
  767. #
  768. # But it is better to check for both headers, and alias NEED_MEMORY_H to
  769. # HAVE_MEMORY_H.
  770. AU_DEFUN([AC_MEMORY_H],
  771. [AC_CHECK_HEADER(memory.h,
  772. [AC_DEFINE([NEED_MEMORY_H], 1,
  773. [Same as `HAVE_MEMORY_H', don't depend on me.])])
  774. AC_CHECK_HEADERS(string.h memory.h)],
  775. [Remove this warning and
  776. `AC_CHECK_HEADER(memory.h, AC_DEFINE(...))' when you adjust your code to
  777. use HAVE_STRING_H and HAVE_MEMORY_H, not NEED_MEMORY_H.])
  778. # AU::AC_DIR_HEADER
  779. # -----------------
  780. # Like calling `AC_HEADER_DIRENT' and `AC_FUNC_CLOSEDIR_VOID', but
  781. # defines a different set of C preprocessor macros to indicate which
  782. # header file is found.
  783. AU_DEFUN([AC_DIR_HEADER],
  784. [AC_HEADER_DIRENT
  785. AC_FUNC_CLOSEDIR_VOID
  786. test ac_cv_header_dirent_dirent_h &&
  787. AC_DEFINE([DIRENT], 1, [Same as `HAVE_DIRENT_H', don't depend on me.])
  788. test ac_cv_header_dirent_sys_ndir_h &&
  789. AC_DEFINE([SYSNDIR], 1, [Same as `HAVE_SYS_NDIR_H', don't depend on me.])
  790. test ac_cv_header_dirent_sys_dir_h &&
  791. AC_DEFINE([SYSDIR], 1, [Same as `HAVE_SYS_DIR_H', don't depend on me.])
  792. test ac_cv_header_dirent_ndir_h &&
  793. AC_DEFINE([NDIR], 1, [Same as `HAVE_NDIR_H', don't depend on me.])],
  794. [Remove this warning and the four `AC_DEFINE' when you
  795. adjust your code to use `AC_HEADER_DIRENT'.])