c.at 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418
  1. # -*- Autotest -*-
  2. AT_BANNER([C low level compiling/preprocessing macros.])
  3. # Copyright (C) 2000-2006, 2008-2012 Free Software Foundation, Inc.
  4. #
  5. # This program is free software: you can redistribute it and/or modify
  6. # it under the terms of the GNU General Public License as published by
  7. # the Free Software Foundation, either version 3 of the License, or
  8. # (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. # Since the macros which compile are required by most tests, check
  18. # them first. But remember that looking for a compiler is even more
  19. # primitive, so check those first.
  20. ## ------------ ##
  21. ## Extensions. ##
  22. ## ------------ ##
  23. # As far as we know only `foo', `foo.exe' are possible executable,
  24. # and `foo.o', `foo.obj' are possible object files. Autoconf must not
  25. # know that, but it is OK for the test suite to take this into account.
  26. AT_CHECK_MACRO([Extensions],
  27. [[AC_PROG_CC
  28. case $ac_exeext in
  29. '' | '.exe' ) ;;
  30. * ) AC_MSG_ERROR([suspicious executable suffix: $ac_exeext]);;
  31. esac
  32. case $ac_objext in
  33. 'o' | 'obj' ) ;;
  34. * ) AC_MSG_ERROR([suspicious object suffix: $ac_objext]);;
  35. esac
  36. ]])
  37. ## -------------------------- ##
  38. ## Broken/missing compilers. ##
  39. ## -------------------------- ##
  40. # Check that Autoconf correctly diagnoses broken compilers, and in
  41. # particular, if it does not exit 77, the test suite is in trouble...
  42. # FIXME: Once a precise message decided, check stderr of configure.
  43. AT_SETUP([Broken/missing compilers])
  44. AT_DATA([configure.ac],
  45. [[AC_INIT
  46. CC=no-such-compiler
  47. AC_PROG_CC
  48. ]])
  49. AT_CHECK_AUTOCONF
  50. AT_CHECK_CONFIGURE([], 77, ignore, ignore)
  51. AT_CLEANUP
  52. ## ------------ ##
  53. ## C keywords. ##
  54. ## ------------ ##
  55. # GCC supports `const', `typeof', and `volatile'.
  56. AT_CHECK_MACRO([C keywords],
  57. [[AC_PROG_CC
  58. AC_C_CONST
  59. AC_C_TYPEOF
  60. AC_C_VOLATILE
  61. case $GCC,$ac_cv_c_const,$ac_cv_c_typeof,$ac_cv_c_volatile in
  62. yes,*no*)
  63. AC_MSG_ERROR([failed to detect `const', `typeof', or `volatile' support]);;
  64. esac
  65. ]])
  66. ## --------------------------------- ##
  67. ## AC_PROG_CPP requires AC_PROG_CC. ##
  68. ## --------------------------------- ##
  69. # Must invoke AC_PROG_CC.
  70. AT_CHECK_MACRO([AC_PROG_CPP requires AC_PROG_CC],
  71. [[AC_PROG_CPP
  72. test -z "$CC" &&
  73. AC_MSG_ERROR([looked for a C preprocessor without looking for a compiler])
  74. ]])
  75. ## --------------------------- ##
  76. ## AC_PROG_CPP with warnings. ##
  77. ## --------------------------- ##
  78. # It's Ok for strict preprocessors to produce warnings.
  79. AT_SETUP([AC_PROG_CPP with warnings])
  80. AT_DATA([mycpp],
  81. [[#! /bin/sh
  82. echo noise >&2
  83. exec "$@"
  84. ]])
  85. chmod +x mycpp
  86. _AT_CHECK_AC_MACRO(
  87. [[AC_PROG_CPP
  88. # If the preprocessor is not strict, just ignore
  89. test "x$ac_c_preproc_warn_flag" = xyes &&
  90. AC_MSG_ERROR([preprocessor has no warning option], 77)
  91. CPP="./mycpp $CPP"
  92. # Exercise CPP.
  93. AC_CHECK_HEADERS(stdio.h autoconf_io.h, [], [], [-])]])
  94. AT_CHECK_DEFINES(
  95. [/* #undef HAVE_AUTOCONF_IO_H */
  96. #define HAVE_STDIO_H 1
  97. ])
  98. AT_CLEANUP
  99. ## ------------------------------ ##
  100. ## AC_PROG_CPP without warnings. ##
  101. ## ------------------------------ ##
  102. AT_SETUP([AC_PROG_CPP without warnings])
  103. # Ignore if /lib/cpp doesn't work
  104. AT_CHECK([[echo '#include <stdio.h>' | /lib/cpp || exit 77]],
  105. [], [ignore], [ignore])
  106. # A cpp which exit status is meaningless.
  107. AT_DATA([mycpp],
  108. [[#! /bin/sh
  109. /lib/cpp "$@"
  110. exit 0
  111. ]])
  112. chmod +x mycpp
  113. _AT_CHECK_AC_MACRO(
  114. [[CPP=./mycpp
  115. AC_PROG_CPP
  116. test "x$ac_c_preproc_warn_flag" != xyes &&
  117. AC_MSG_ERROR([failed to detect preprocessor warning option])
  118. # Exercise CPP.
  119. AC_CHECK_HEADERS(stdio.h autoconf_io.h, [], [], [-])]])
  120. AT_CHECK_DEFINES(
  121. [/* #undef HAVE_AUTOCONF_IO_H */
  122. #define HAVE_STDIO_H 1
  123. ])
  124. AT_CLEANUP
  125. ## -------------------- ##
  126. ## AC_PROG_CPP via CC. ##
  127. ## -------------------- ##
  128. # It's Ok for strict preprocessors to produce warnings.
  129. AT_SETUP([AC_PROG_CPP via CC])
  130. # Ignore if /lib/cpp doesn't work
  131. AT_CHECK([[echo '#include <stdio.h>' | /lib/cpp || exit 77]],
  132. [], [ignore], [ignore])
  133. AT_DATA([mycc],
  134. [[#! /bin/sh
  135. echo "Annoying copyright message" >&2
  136. exec "$@"
  137. ]])
  138. chmod +x mycc
  139. # We go through the following contortions, in order to have the
  140. # configure script go down the same codepaths as it would during a
  141. # normal CPP selection check. If we explicitly set CPP, it goes down
  142. # a different codepath.
  143. _AT_CHECK_AC_MACRO(
  144. [[AC_PROG_CC
  145. CC="./mycc $CC"
  146. AC_PROG_CPP
  147. # The test $CC compiler should have been selected.
  148. test "$CPP" != "$CC -E" &&
  149. AC_MSG_ERROR([error messages on stderr cause the preprocessor selection to fail])
  150. # Exercise CPP.
  151. AC_CHECK_HEADERS(stdio.h autoconf_io.h, [], [], [-])]])
  152. AT_CHECK_DEFINES(
  153. [/* #undef HAVE_AUTOCONF_IO_H */
  154. #define HAVE_STDIO_H 1
  155. ])
  156. AT_CLEANUP
  157. ## ------------------------------------ ##
  158. ## AC_NO_EXECUTABLES (working linker). ##
  159. ## ------------------------------------ ##
  160. AT_CHECK_MACRO([AC_NO_EXECUTABLES (working linker)],
  161. [AC_NO_EXECUTABLES
  162. AC_PROG_CC
  163. ])
  164. ## ----------------------------------- ##
  165. ## AC_NO_EXECUTABLES (broken linker). ##
  166. ## ----------------------------------- ##
  167. AT_CHECK_MACRO([AC_NO_EXECUTABLES (broken linker)],
  168. [LDFLAGS=-lnosuchlibrary
  169. AC_NO_EXECUTABLES
  170. AC_PROG_CC
  171. ])
  172. ## -------------------------- ##
  173. ## AC_USE_SYSTEM_EXTENSIONS. ##
  174. ## -------------------------- ##
  175. AT_SETUP([AC_USE_SYSTEM_EXTENSIONS])
  176. # Some existing configure.ac mixed AC_AIX (now an alias for
  177. # AC_USE_SYSTEM_EXTENSIONS) and AC_DEFINE([__EXTENSIONS__]), which
  178. # broke autoheader in 2.62. Test that this is supported.
  179. _AT_CHECK_AC_MACRO(
  180. [[AC_AIX
  181. AC_DEFINE([__EXTENSIONS__], [1], [Manually defined for Solaris])
  182. ]])
  183. _AT_CHECK_AC_MACRO(
  184. [[AC_USE_SYSTEM_EXTENSIONS
  185. AC_DEFINE([__EXTENSIONS__], [1], [Manually defined for Solaris])
  186. ]])
  187. AT_CLEANUP
  188. ## ----------------------- ##
  189. ## AC_C_RESTRICT and C++. ##
  190. ## ----------------------- ##
  191. AT_SETUP([AC_C_RESTRICT and C++])
  192. # In some compiler suites, the left hand doesn't know about everything
  193. # the right hand does; or the user mixes the C compiler from one suite
  194. # with the C++ compiler from another. In this case, Sun WorkShop CC
  195. # not like the _Restrict accepted by cc.
  196. AT_DATA([configure.ac],
  197. [[AC_INIT
  198. AC_PROG_CC
  199. AC_PROG_CXX
  200. AC_C_RESTRICT
  201. AC_CONFIG_HEADERS([config.h])
  202. AC_CONFIG_FILES([Makefile])
  203. AC_OUTPUT
  204. ]])
  205. AT_DATA([Makefile.in],
  206. [[CC = @CC@
  207. CXX = @CXX@
  208. CFLAGS = @CFLAGS@
  209. CXXFLAGS = @CXXFLAGS@
  210. CPPFLAGS = -I. @CPPFLAGS@
  211. OBJEXT = @OBJEXT@
  212. all: foo.$(OBJEXT) bar.$(OBJEXT)
  213. cpp-works:
  214. $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c cpp-works.cpp
  215. foo.$(OBJEXT): foo.c
  216. $(CC) $(CPPFLAGS) $(CFLAGS) -c foo.c
  217. bar.$(OBJEXT): bar.cpp
  218. $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c bar.cpp
  219. ]])
  220. AT_DATA([foo.c],
  221. [[#include <config.h>
  222. int foo (int * restrict i1, int * restrict i2)
  223. {
  224. return i1[0] + i2[0];
  225. }
  226. ]])
  227. cp foo.c bar.cpp
  228. AT_DATA([cpp-works.cpp],
  229. [[// This file is just to test whether we have a working C++ compiler at all
  230. class foo { int x; };
  231. class foo foobar;
  232. ]])
  233. AT_CHECK([autoconf])
  234. AT_CHECK([autoheader])
  235. AT_CHECK([./configure $configure_options], [], [ignore], [ignore])
  236. AT_CHECK([${MAKE-make} cpp-works || exit 77], [], [ignore], [ignore])
  237. AT_CHECK([${MAKE-make}], [], [ignore], [ignore])
  238. AT_CLEANUP
  239. ## ---------------- ##
  240. ## AC_OPENMP and C. ##
  241. ## ---------------- ##
  242. AT_SETUP([AC_OPENMP and C])
  243. AT_DATA([configure.ac],
  244. [[AC_INIT
  245. AC_PROG_CC
  246. AC_OPENMP
  247. if test "X$ac_cv_prog_c_openmp" = Xunsupported; then
  248. AS_EXIT([77])
  249. fi
  250. CFLAGS="$CFLAGS $OPENMP_CFLAGS"
  251. CPPFLAGS="$CPPFLAGS $OPENMP_CFLAGS"
  252. AC_CONFIG_FILES([Makefile])
  253. AC_OUTPUT
  254. ]])
  255. AT_DATA([Makefile.in],
  256. [[foo@EXEEXT@: foo.@OBJEXT@
  257. @CC@ @CFLAGS@ @LDFLAGS@ -o $@ foo.@OBJEXT@
  258. foo.@OBJEXT@: foo.c
  259. @CC@ @CPPFLAGS@ @CFLAGS@ -c foo.c
  260. ]])
  261. AT_DATA([foo.c],
  262. [[#ifdef _OPENMP
  263. #include <omp.h>
  264. #endif
  265. #include <stdio.h>
  266. int main ()
  267. {
  268. #ifdef _OPENMP
  269. #pragma omp parallel
  270. {
  271. int id = omp_get_thread_num ();
  272. printf ("hello omp world from %d\n", id);
  273. }
  274. #endif
  275. return 0;
  276. }
  277. ]])
  278. : "${MAKE=make}"
  279. AT_CHECK([env ACLOCAL=true autoreconf -vi], [], [ignore], [ignore])
  280. AT_CHECK([./configure $configure_options], [], [ignore], [ignore])
  281. AT_CHECK([$MAKE], [], [ignore], [ignore])
  282. AT_CLEANUP
  283. ## ------------------ ##
  284. ## AC_OPENMP anc C++. ##
  285. ## ------------------ ##
  286. AT_SETUP([AC_OPENMP and C++])
  287. AT_DATA([configure.ac],
  288. [[AC_INIT
  289. AC_PROG_CXX
  290. AC_LANG([C++])
  291. AC_OPENMP
  292. if test "X$ac_cv_prog_cxx_openmp" = Xunsupported; then
  293. AS_EXIT([77])
  294. fi
  295. CXXFLAGS="$CXXFLAGS $OPENMP_CXXFLAGS"
  296. CPPFLAGS="$CPPFLAGS $OPENMP_CXXFLAGS"
  297. AC_CONFIG_FILES([Makefile])
  298. AC_OUTPUT
  299. ]])
  300. AT_DATA([Makefile.in],
  301. [[foo@EXEEXT@: foo.@OBJEXT@
  302. @CXX@ @CXXFLAGS@ @LDFLAGS@ -o $@ foo.@OBJEXT@
  303. foo.@OBJEXT@: foo.cpp
  304. @CXX@ @CPPFLAGS@ @CXXFLAGS@ -c foo.cpp
  305. ]])
  306. AT_DATA([foo.cpp],
  307. [[int main ()
  308. {
  309. return 0;
  310. }
  311. ]])
  312. : "${MAKE=make}"
  313. AT_CHECK([env ACLOCAL=true autoreconf -vi], [], [ignore], [ignore])
  314. AT_CHECK([./configure $configure_options], [], [ignore], [ignore])
  315. AT_CHECK([$MAKE], [], [ignore], [ignore])
  316. AT_CLEANUP