Describe a Solaris /bin/sh bug w.r.t. for loops.
[autoconf.git] / tests / c.at
blob8e772336d55e67c0c6c898a54e492e981b577733
1 #                                                       -*- Autotest -*-
3 AT_BANNER([C low level compiling/preprocessing macros.])
5 # Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2008, 2009,
6 # 2010 Free Software Foundation, Inc.
8 # This program is free software: you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation, either version 3 of the License, or
11 # (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
22 # Since the macros which compile are required by most tests, check
23 # them first.  But remember that looking for a compiler is even more
24 # primitive, so check those first.
27 ## ------------ ##
28 ## Extensions.  ##
29 ## ------------ ##
31 # As far as we know only `foo', `foo.exe' are possible executable,
32 # and `foo.o', `foo.obj' are possible object files.  Autoconf must not
33 # know that, but it is OK for the test suite to take this into account.
34 AT_CHECK_MACRO([Extensions],
35 [[AC_PROG_CC
36 case $ac_exeext in
37   '' | '.exe' ) ;;
38   * ) AC_MSG_ERROR([suspicious executable suffix: $ac_exeext]);;
39 esac
41 case $ac_objext in
42   'o' | 'obj' ) ;;
43   * ) AC_MSG_ERROR([suspicious object suffix: $ac_objext]);;
44 esac
45 ]])
49 ## -------------------------- ##
50 ## Broken/missing compilers.  ##
51 ## -------------------------- ##
54 # Check that Autoconf correctly diagnoses broken compilers, and in
55 # particular, if it does not exit 77, the test suite is in trouble...
56 # FIXME: Once a precise message decided, check stderr of configure.
57 AT_SETUP([Broken/missing compilers])
59 AT_DATA([configure.ac],
60 [[AC_INIT
61 CC=no-such-compiler
62 AC_PROG_CC
63 ]])
65 AT_CHECK_AUTOCONF
66 AT_CHECK_CONFIGURE([], 77, ignore, ignore)
68 AT_CLEANUP
71 ## ------------ ##
72 ## C keywords.  ##
73 ## ------------ ##
75 # GCC supports `const', `typeof', and `volatile'.
76 AT_CHECK_MACRO([C keywords],
77 [[AC_PROG_CC
78 AC_C_CONST
79 AC_C_TYPEOF
80 AC_C_VOLATILE
81 case $GCC,$ac_cv_c_const,$ac_cv_c_typeof,$ac_cv_c_volatile in
82  yes,*no*)
83    AC_MSG_ERROR([failed to detect `const', `typeof', or `volatile' support]);;
84 esac
85 ]])
89 ## --------------------------------- ##
90 ## AC_PROG_CPP requires AC_PROG_CC.  ##
91 ## --------------------------------- ##
93 # Must invoke AC_PROG_CC.
94 AT_CHECK_MACRO([AC_PROG_CPP requires AC_PROG_CC],
95 [[AC_PROG_CPP
96 test -z "$CC" &&
97    AC_MSG_ERROR([looked for a C preprocessor without looking for a compiler])
98 ]])
102 ## --------------------------- ##
103 ## AC_PROG_CPP with warnings.  ##
104 ## --------------------------- ##
107 # It's Ok for strict preprocessors to produce warnings.
109 AT_SETUP([AC_PROG_CPP with warnings])
111 AT_DATA([mycpp],
112 [[#! /bin/sh
113 echo noise >&2
114 exec "$@"
117 chmod +x mycpp
119 _AT_CHECK_AC_MACRO(
120 [[AC_PROG_CPP
121 # If the preprocessor is not strict, just ignore
122 test "x$ac_c_preproc_warn_flag" = xyes &&
123   AC_MSG_ERROR([preprocessor has no warning option], 77)
124 CPP="./mycpp $CPP"
126 # Exercise CPP.
127 AC_CHECK_HEADERS(stdio.h autoconf_io.h, [], [], [-])]])
129 AT_CHECK_DEFINES(
130 [/* #undef HAVE_AUTOCONF_IO_H */
131 #define HAVE_STDIO_H 1
134 AT_CLEANUP
137 ## ------------------------------ ##
138 ## AC_PROG_CPP without warnings.  ##
139 ## ------------------------------ ##
141 AT_SETUP([AC_PROG_CPP without warnings])
143 # Ignore if /lib/cpp doesn't work
144 AT_CHECK([[echo '#include <stdio.h>' | /lib/cpp || exit 77]],
145   [], [ignore], [ignore])
147 # A cpp which exit status is meaningless.
148 AT_DATA([mycpp],
149 [[#! /bin/sh
150 /lib/cpp "$@"
151 exit 0
154 chmod +x mycpp
156 _AT_CHECK_AC_MACRO(
157 [[CPP=./mycpp
158 AC_PROG_CPP
159 test "x$ac_c_preproc_warn_flag" != xyes &&
160   AC_MSG_ERROR([failed to detect preprocessor warning option])
162 # Exercise CPP.
163 AC_CHECK_HEADERS(stdio.h autoconf_io.h, [], [], [-])]])
165 AT_CHECK_DEFINES(
166 [/* #undef HAVE_AUTOCONF_IO_H */
167 #define HAVE_STDIO_H 1
170 AT_CLEANUP
174 ## -------------------- ##
175 ## AC_PROG_CPP via CC.  ##
176 ## -------------------- ##
179 # It's Ok for strict preprocessors to produce warnings.
181 AT_SETUP([AC_PROG_CPP via CC])
183 # Ignore if /lib/cpp doesn't work
184 AT_CHECK([[echo '#include <stdio.h>' | /lib/cpp || exit 77]],
185   [], [ignore], [ignore])
187 AT_DATA([mycc],
188 [[#! /bin/sh
189 echo "Annoying copyright message" >&2
190 exec "$@"
193 chmod +x mycc
195 # We go through the following contortions, in order to have the
196 # configure script go down the same codepaths as it would during a
197 # normal CPP selection check.  If we explicitly set CPP, it goes down
198 # a different codepath.
199 _AT_CHECK_AC_MACRO(
200 [[AC_PROG_CC
201 CC="./mycc $CC"
202 AC_PROG_CPP
203 # The test $CC compiler should have been selected.
204 test "$CPP" != "$CC -E" &&
205   AC_MSG_ERROR([error messages on stderr cause the preprocessor selection to fail])
207 # Exercise CPP.
208 AC_CHECK_HEADERS(stdio.h autoconf_io.h, [], [], [-])]])
210 AT_CHECK_DEFINES(
211 [/* #undef HAVE_AUTOCONF_IO_H */
212 #define HAVE_STDIO_H 1
215 AT_CLEANUP
218 ## ------------------------------------ ##
219 ## AC_NO_EXECUTABLES (working linker).  ##
220 ## ------------------------------------ ##
222 AT_CHECK_MACRO([AC_NO_EXECUTABLES (working linker)],
223 [AC_NO_EXECUTABLES
224 AC_PROG_CC
228 ## ----------------------------------- ##
229 ## AC_NO_EXECUTABLES (broken linker).  ##
230 ## ----------------------------------- ##
232 AT_CHECK_MACRO([AC_NO_EXECUTABLES (broken linker)],
233 [LDFLAGS=-lnosuchlibrary
234 AC_NO_EXECUTABLES
235 AC_PROG_CC
239 ## -------------------------- ##
240 ## AC_USE_SYSTEM_EXTENSIONS.  ##
241 ## -------------------------- ##
243 AT_SETUP([AC_USE_SYSTEM_EXTENSIONS])
245 # Some existing configure.ac mixed AC_AIX (now an alias for
246 # AC_USE_SYSTEM_EXTENSIONS) and AC_DEFINE([__EXTENSIONS__]), which
247 # broke autoheader in 2.62.  Test that this is supported.
249 _AT_CHECK_AC_MACRO(
250 [[AC_AIX
251 AC_DEFINE([__EXTENSIONS__], [1], [Manually defined for Solaris])
254 _AT_CHECK_AC_MACRO(
255 [[AC_USE_SYSTEM_EXTENSIONS
256 AC_DEFINE([__EXTENSIONS__], [1], [Manually defined for Solaris])
259 AT_CLEANUP
262 ## ----------------------- ##
263 ## AC_C_RESTRICT and C++.  ##
264 ## ----------------------- ##
266 AT_SETUP([AC_C_RESTRICT and C++])
268 # In some compiler suites, the left hand doesn't know about everything
269 # the right hand does; or the user mixes the C compiler from one suite
270 # with the C++ compiler from another.  In this case, Sun WorkShop CC
271 # not like the _Restrict accepted by cc.
273 AT_DATA([configure.ac],
274 [[AC_INIT
275 AC_PROG_CC
276 AC_PROG_CXX
277 AC_C_RESTRICT
278 AC_CONFIG_HEADERS([config.h])
279 AC_CONFIG_FILES([Makefile])
280 AC_OUTPUT
283 AT_DATA([Makefile.in],
284 [[CC = @CC@
285 CXX = @CXX@
286 CFLAGS = @CFLAGS@
287 CXXFLAGS = @CXXFLAGS@
288 CPPFLAGS = -I. @CPPFLAGS@
289 OBJEXT = @OBJEXT@
290 all: foo.$(OBJEXT) bar.$(OBJEXT)
291 cpp-works:
292         $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c cpp-works.cpp
293 foo.$(OBJEXT): foo.c
294         $(CC) $(CPPFLAGS) $(CFLAGS) -c foo.c
295 bar.$(OBJEXT): bar.cpp
296         $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c bar.cpp
299 AT_DATA([foo.c],
300 [[#include <config.h>
302 int foo (int * restrict i1, int * restrict i2)
304   return i1[0] + i2[0];
308 cp foo.c bar.cpp
310 AT_DATA([cpp-works.cpp],
311 [[// This file is just to test whether we have a working C++ compiler at all
312 class foo { int x; };
313 class foo foobar;
316 AT_CHECK([autoconf])
317 AT_CHECK([autoheader])
318 AT_CHECK([./configure $configure_options], [], [ignore], [ignore])
319 AT_CHECK([${MAKE-make} cpp-works || exit 77], [], [ignore], [ignore])
320 AT_CHECK([${MAKE-make}], [], [ignore], [ignore])
322 AT_CLEANUP
325 ## ---------------- ##
326 ## AC_OPENMP and C. ##
327 ## ---------------- ##
329 AT_SETUP([AC_OPENMP and C])
331 AT_DATA([configure.ac],
332 [[AC_INIT
333 AC_PROG_CC
334 AC_OPENMP
335 if test "X$ac_cv_prog_c_openmp" = Xunsupported; then
336   AS_EXIT([77])
338 CFLAGS="$CFLAGS $OPENMP_CFLAGS"
339 CPPFLAGS="$CPPFLAGS $OPENMP_CFLAGS"
340 AC_CONFIG_FILES([Makefile])
341 AC_OUTPUT
344 AT_DATA([Makefile.in],
345 [[foo@EXEEXT@: foo.@OBJEXT@
346         @CC@ @CFLAGS@ @LDFLAGS@ -o $@ foo.@OBJEXT@
348 foo.@OBJEXT@: foo.c
349         @CC@ @CPPFLAGS@ @CFLAGS@ -c foo.c
352 AT_DATA([foo.c],
353 [[#ifdef _OPENMP
354 #include <omp.h>
355 #endif
356 #include <stdio.h>
358 int main ()
360 #ifdef _OPENMP
361 #pragma omp parallel
362   {
363     int id = omp_get_thread_num ();
364     printf ("hello omp world from %d\n", id);
365   }
366 #endif
367   return 0;
371 : ${MAKE=make}
372 AT_CHECK([env ACLOCAL=true autoreconf -vi], [], [ignore], [ignore])
373 AT_CHECK([./configure $configure_options], [], [ignore], [ignore])
374 AT_CHECK([$MAKE], [], [ignore], [ignore])
376 AT_CLEANUP
379 ## ------------------ ##
380 ## AC_OPENMP anc C++. ##
381 ## ------------------ ##
383 AT_SETUP([AC_OPENMP and C++])
385 AT_DATA([configure.ac],
386 [[AC_INIT
387 AC_PROG_CXX
388 AC_LANG([C++])
389 AC_OPENMP
390 if test "X$ac_cv_prog_cxx_openmp" = Xunsupported; then
391   AS_EXIT([77])
393 CXXFLAGS="$CXXFLAGS $OPENMP_CXXFLAGS"
394 CPPFLAGS="$CPPFLAGS $OPENMP_CXXFLAGS"
395 AC_CONFIG_FILES([Makefile])
396 AC_OUTPUT
399 AT_DATA([Makefile.in],
400 [[foo@EXEEXT@: foo.@OBJEXT@
401         @CXX@ @CXXFLAGS@ @LDFLAGS@ -o $@ foo.@OBJEXT@
403 foo.@OBJEXT@: foo.cpp
404         @CXX@ @CPPFLAGS@ @CXXFLAGS@ -c foo.cpp
407 AT_DATA([foo.cpp],
408 [[int main ()
410   return 0;
414 : ${MAKE=make}
415 AT_CHECK([env ACLOCAL=true autoreconf -vi], [], [ignore], [ignore])
416 AT_CHECK([./configure $configure_options], [], [ignore], [ignore])
417 AT_CHECK([$MAKE], [], [ignore], [ignore])
419 AT_CLEANUP