tests: avoid spurious test failure with libtool 2.4.3
[autoconf.git] / tests / c.at
blobb500faa2181b0394ed60ccb87ed771fd8bb07852
1 #                                                       -*- Autotest -*-
3 AT_BANNER([C low level compiling/preprocessing macros.])
5 # Copyright (C) 2000-2006, 2008-2014 Free Software Foundation, Inc.
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
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.
17 # You should have received a copy of the GNU General Public License
18 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
21 # Since the macros which compile are required by most tests, check
22 # them first.  But remember that looking for a compiler is even more
23 # primitive, so check those first.
26 ## ------------ ##
27 ## Extensions.  ##
28 ## ------------ ##
30 # As far as we know only `foo', `foo.exe' are possible executable,
31 # and `foo.o', `foo.obj' are possible object files.  Autoconf must not
32 # know that, but it is OK for the test suite to take this into account.
33 AT_CHECK_MACRO([Extensions],
34 [[AC_PROG_CC
35 case $ac_exeext in
36   '' | '.exe' ) ;;
37   * ) AC_MSG_ERROR([suspicious executable suffix: $ac_exeext]);;
38 esac
40 case $ac_objext in
41   'o' | 'obj' ) ;;
42   * ) AC_MSG_ERROR([suspicious object suffix: $ac_objext]);;
43 esac
44 ]])
48 ## -------------------------- ##
49 ## Broken/missing compilers.  ##
50 ## -------------------------- ##
53 # Check that Autoconf correctly diagnoses broken compilers, and in
54 # particular, if it does not exit 77, the test suite is in trouble...
55 # FIXME: Once a precise message decided, check stderr of configure.
56 AT_SETUP([Broken/missing compilers])
58 AT_DATA([configure.ac],
59 [[AC_INIT
60 CC=no-such-compiler
61 AC_PROG_CC
62 ]])
64 AT_CHECK_AUTOCONF
65 AT_CHECK_CONFIGURE([], 77, ignore, ignore)
67 AT_CLEANUP
70 ## ------------ ##
71 ## C keywords.  ##
72 ## ------------ ##
74 # GCC supports `const', `typeof', and `volatile'.
75 AT_CHECK_MACRO([C keywords],
76 [[AC_PROG_CC
77 AC_C_CONST
78 AC_C_TYPEOF
79 AC_C_VOLATILE
80 case $GCC,$ac_cv_c_const,$ac_cv_c_typeof,$ac_cv_c_volatile in
81  yes,*no*)
82    AC_MSG_ERROR([failed to detect `const', `typeof', or `volatile' support]);;
83 esac
84 ]])
88 ## --------------------------------- ##
89 ## AC_PROG_CPP requires AC_PROG_CC.  ##
90 ## --------------------------------- ##
92 # Must invoke AC_PROG_CC.
93 AT_CHECK_MACRO([AC_PROG_CPP requires AC_PROG_CC],
94 [[AC_PROG_CPP
95 test -z "$CC" &&
96    AC_MSG_ERROR([looked for a C preprocessor without looking for a compiler])
97 ]])
101 ## --------------------------- ##
102 ## AC_PROG_CPP with warnings.  ##
103 ## --------------------------- ##
106 # It's Ok for strict preprocessors to produce warnings.
108 AT_SETUP([AC_PROG_CPP with warnings])
110 AT_DATA([mycpp],
111 [[#! /bin/sh
112 echo noise >&2
113 exec "$@"
116 chmod +x mycpp
118 _AT_CHECK_AC_MACRO(
119 [[AC_PROG_CPP
120 # If the preprocessor is not strict, just ignore
121 test "x$ac_c_preproc_warn_flag" = xyes &&
122   AC_MSG_ERROR([preprocessor has no warning option], 77)
123 CPP="./mycpp $CPP"
125 # Exercise CPP.
127 AC_PREPROC_IFELSE([AC_LANG_SOURCE([[#include <stdio.h>]])],
128   [AC_DEFINE([HAVE_STDIO_H], [1], [Define if you have stdio.h])])
129 AC_PREPROC_IFELSE([AC_LANG_SOURCE([[#include <autoconf_io.h>]])],
130   [AC_DEFINE([HAVE_AUTOCONF_IO_H], [1], [Define if you have autoconf_io.h])])
132 AT_CHECK_DEFINES(
133 [/* #undef HAVE_AUTOCONF_IO_H */
134 #define HAVE_STDIO_H 1
137 AT_CLEANUP
140 ## ------------------------------ ##
141 ## AC_PROG_CPP without warnings.  ##
142 ## ------------------------------ ##
144 AT_SETUP([AC_PROG_CPP without warnings])
146 # Ignore if the cpp in $PATH doesn't work
147 AT_CHECK([[echo '#include <stdio.h>' | cpp || exit 77]],
148   [], [ignore], [ignore])
150 # A cpp which exit status is meaningless.
151 AT_DATA([mycpp],
152 [[#! /bin/sh
153 cpp "$@"
154 exit 0
157 chmod +x mycpp
159 _AT_CHECK_AC_MACRO(
160 [[CPP=./mycpp
161 AC_PROG_CPP
162 test "x$ac_c_preproc_warn_flag" != xyes &&
163   AC_MSG_ERROR([failed to detect preprocessor warning option])
165 # Exercise CPP.
166 AC_PREPROC_IFELSE([AC_LANG_SOURCE([[#include <stdio.h>]])],
167   [AC_DEFINE([HAVE_STDIO_H], [1], [Define if you have stdio.h])])
168 AC_PREPROC_IFELSE([AC_LANG_SOURCE([[#include <autoconf_io.h>]])],
169   [AC_DEFINE([HAVE_AUTOCONF_IO_H], [1], [Define if you have autoconf_io.h])])
172 AT_CHECK_DEFINES(
173 [/* #undef HAVE_AUTOCONF_IO_H */
174 #define HAVE_STDIO_H 1
177 AT_CLEANUP
181 ## -------------------- ##
182 ## AC_PROG_CPP via CC.  ##
183 ## -------------------- ##
186 # It's Ok for strict preprocessors to produce warnings.
188 AT_SETUP([AC_PROG_CPP via CC])
190 # Ignore if the cpp in $PATH doesn't work
191 AT_CHECK([[echo '#include <stdio.h>' | cpp || exit 77]],
192   [], [ignore], [ignore])
194 AT_DATA([mycc],
195 [[#! /bin/sh
196 echo "Annoying copyright message" >&2
197 exec "$@"
200 chmod +x mycc
202 # We go through the following contortions, in order to have the
203 # configure script go down the same codepaths as it would during a
204 # normal CPP selection check.  If we explicitly set CPP, it goes down
205 # a different codepath.
206 _AT_CHECK_AC_MACRO(
207 [[AC_PROG_CC
208 CC="./mycc $CC"
209 AC_PROG_CPP
210 # The test $CC compiler should have been selected.
211 test "$CPP" != "$CC -E" &&
212   AC_MSG_ERROR([error messages on stderr cause the preprocessor selection to fail])
214 # Exercise CPP.
215 AC_PREPROC_IFELSE([AC_LANG_SOURCE([[#include <stdio.h>]])],
216   [AC_DEFINE([HAVE_STDIO_H], [1], [Define if you have stdio.h])])
217 AC_PREPROC_IFELSE([AC_LANG_SOURCE([[#include <autoconf_io.h>]])],
218   [AC_DEFINE([HAVE_AUTOCONF_IO_H], [1], [Define if you have autoconf_io.h])])
221 AT_CHECK_DEFINES(
222 [/* #undef HAVE_AUTOCONF_IO_H */
223 #define HAVE_STDIO_H 1
226 AT_CLEANUP
229 ## ------------------------------------ ##
230 ## AC_NO_EXECUTABLES (working linker).  ##
231 ## ------------------------------------ ##
233 AT_CHECK_MACRO([AC_NO_EXECUTABLES (working linker)],
234 [AC_NO_EXECUTABLES
235 AC_PROG_CC
239 ## ----------------------------------- ##
240 ## AC_NO_EXECUTABLES (broken linker).  ##
241 ## ----------------------------------- ##
243 AT_CHECK_MACRO([AC_NO_EXECUTABLES (broken linker)],
244 [LDFLAGS=-lnosuchlibrary
245 AC_NO_EXECUTABLES
246 AC_PROG_CC
250 ## -------------------------- ##
251 ## AC_USE_SYSTEM_EXTENSIONS.  ##
252 ## -------------------------- ##
254 AT_SETUP([AC_USE_SYSTEM_EXTENSIONS])
256 # Some existing configure.ac mixed AC_AIX (now an alias for
257 # AC_USE_SYSTEM_EXTENSIONS) and AC_DEFINE([__EXTENSIONS__]), which
258 # broke autoheader in 2.62.  Test that this is supported.
260 _AT_CHECK_AC_MACRO(
261 [[AC_AIX
262 AC_DEFINE([__EXTENSIONS__], [1], [Manually defined for Solaris])
265 _AT_CHECK_AC_MACRO(
266 [[AC_USE_SYSTEM_EXTENSIONS
267 AC_DEFINE([__EXTENSIONS__], [1], [Manually defined for Solaris])
270 AT_CLEANUP
273 ## ----------------------- ##
274 ## AC_C_RESTRICT and C++.  ##
275 ## ----------------------- ##
277 AT_SETUP([AC_C_RESTRICT and C++])
279 # In some compiler suites, the left hand doesn't know about everything
280 # the right hand does; or the user mixes the C compiler from one suite
281 # with the C++ compiler from another.  In this case, Sun WorkShop CC
282 # not like the _Restrict accepted by cc.
284 AT_DATA([configure.ac],
285 [[AC_INIT
286 AC_PROG_CC
287 AC_PROG_CXX
288 AC_C_RESTRICT
289 AC_CONFIG_HEADERS([config.h])
290 AC_CONFIG_FILES([Makefile])
291 AC_OUTPUT
294 AT_DATA([Makefile.in],
295 [[CC = @CC@
296 CXX = @CXX@
297 CFLAGS = @CFLAGS@
298 CXXFLAGS = @CXXFLAGS@
299 CPPFLAGS = -I. @CPPFLAGS@
300 OBJEXT = @OBJEXT@
301 all: foo.$(OBJEXT) bar.$(OBJEXT)
302 cpp-works:
303         $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c cpp-works.cpp
304 foo.$(OBJEXT): foo.c
305         $(CC) $(CPPFLAGS) $(CFLAGS) -c foo.c
306 bar.$(OBJEXT): bar.cpp
307         $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c bar.cpp
310 AT_DATA([foo.c],
311 [[#include <config.h>
313 int foo (int * restrict i1, int * restrict i2)
315   return i1[0] + i2[0];
319 cp foo.c bar.cpp
321 AT_DATA([cpp-works.cpp],
322 [[// This file is just to test whether we have a working C++ compiler at all
323 class foo { int x; };
324 class foo foobar;
327 AT_CHECK([autoconf])
328 AT_CHECK([autoheader])
329 AT_CHECK([./configure $configure_options], [], [ignore], [ignore])
330 AT_CHECK([${MAKE-make} cpp-works || exit 77], [], [ignore], [ignore])
331 AT_CHECK([${MAKE-make}], [], [ignore], [ignore])
333 AT_CLEANUP
336 ## ---------------- ##
337 ## AC_OPENMP and C. ##
338 ## ---------------- ##
340 AT_SETUP([AC_OPENMP and C])
342 AT_DATA([configure.ac],
343 [[AC_INIT
344 AC_PROG_CC
345 AC_OPENMP
346 if test "X$ac_cv_prog_c_openmp" = Xunsupported; then
347   AS_EXIT([77])
349 CFLAGS="$CFLAGS $OPENMP_CFLAGS"
350 CPPFLAGS="$CPPFLAGS $OPENMP_CFLAGS"
351 AC_CONFIG_FILES([Makefile])
352 AC_OUTPUT
355 AT_DATA([Makefile.in],
356 [[foo@EXEEXT@: foo.@OBJEXT@
357         @CC@ @CFLAGS@ @LDFLAGS@ -o $@ foo.@OBJEXT@
359 foo.@OBJEXT@: foo.c
360         @CC@ @CPPFLAGS@ @CFLAGS@ -c foo.c
363 AT_DATA([foo.c],
364 [[#ifdef _OPENMP
365 #include <omp.h>
366 #endif
367 #include <stdio.h>
369 int main (void)
371 #ifdef _OPENMP
372 #pragma omp parallel
373   {
374     int id = omp_get_thread_num ();
375     printf ("hello omp world from %d\n", id);
376   }
377 #endif
378   return 0;
382 : "${MAKE=make}"
383 AT_CHECK([env ACLOCAL=true autoreconf -vi], [], [ignore], [ignore])
384 AT_CHECK([./configure $configure_options], [], [ignore], [ignore])
385 AT_CHECK([$MAKE], [], [ignore], [ignore])
387 AT_CLEANUP
390 ## ------------------ ##
391 ## AC_OPENMP anc C++. ##
392 ## ------------------ ##
394 AT_SETUP([AC_OPENMP and C++])
396 AT_DATA([configure.ac],
397 [[AC_INIT
398 AC_PROG_CXX
399 AC_LANG([C++])
400 AC_OPENMP
401 if test "X$ac_cv_prog_cxx_openmp" = Xunsupported; then
402   AS_EXIT([77])
404 CXXFLAGS="$CXXFLAGS $OPENMP_CXXFLAGS"
405 CPPFLAGS="$CPPFLAGS $OPENMP_CXXFLAGS"
406 AC_CONFIG_FILES([Makefile])
407 AC_OUTPUT
410 AT_DATA([Makefile.in],
411 [[foo@EXEEXT@: foo.@OBJEXT@
412         @CXX@ @CXXFLAGS@ @LDFLAGS@ -o $@ foo.@OBJEXT@
414 foo.@OBJEXT@: foo.cpp
415         @CXX@ @CPPFLAGS@ @CXXFLAGS@ -c foo.cpp
418 AT_DATA([foo.cpp],
419 [[int main (void)
421   return 0;
425 : "${MAKE=make}"
426 AT_CHECK([env ACLOCAL=true autoreconf -vi], [], [ignore], [ignore])
427 AT_CHECK([./configure $configure_options], [], [ignore], [ignore])
428 AT_CHECK([$MAKE], [], [ignore], [ignore])
430 AT_CLEANUP