maint: update copyright year
[autoconf.git] / tests / c.at
blob7bf80520ef33d5cf8033f155325589c064768821
1 #                                                       -*- Autotest -*-
3 AT_BANNER([C low level compiling/preprocessing macros.])
5 # Copyright (C) 2000-2006, 2008-2011 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.
126 AC_CHECK_HEADERS(stdio.h autoconf_io.h, [], [], [-])]])
128 AT_CHECK_DEFINES(
129 [/* #undef HAVE_AUTOCONF_IO_H */
130 #define HAVE_STDIO_H 1
133 AT_CLEANUP
136 ## ------------------------------ ##
137 ## AC_PROG_CPP without warnings.  ##
138 ## ------------------------------ ##
140 AT_SETUP([AC_PROG_CPP without warnings])
142 # Ignore if /lib/cpp doesn't work
143 AT_CHECK([[echo '#include <stdio.h>' | /lib/cpp || exit 77]],
144   [], [ignore], [ignore])
146 # A cpp which exit status is meaningless.
147 AT_DATA([mycpp],
148 [[#! /bin/sh
149 /lib/cpp "$@"
150 exit 0
153 chmod +x mycpp
155 _AT_CHECK_AC_MACRO(
156 [[CPP=./mycpp
157 AC_PROG_CPP
158 test "x$ac_c_preproc_warn_flag" != xyes &&
159   AC_MSG_ERROR([failed to detect preprocessor warning option])
161 # Exercise CPP.
162 AC_CHECK_HEADERS(stdio.h autoconf_io.h, [], [], [-])]])
164 AT_CHECK_DEFINES(
165 [/* #undef HAVE_AUTOCONF_IO_H */
166 #define HAVE_STDIO_H 1
169 AT_CLEANUP
173 ## -------------------- ##
174 ## AC_PROG_CPP via CC.  ##
175 ## -------------------- ##
178 # It's Ok for strict preprocessors to produce warnings.
180 AT_SETUP([AC_PROG_CPP via CC])
182 # Ignore if /lib/cpp doesn't work
183 AT_CHECK([[echo '#include <stdio.h>' | /lib/cpp || exit 77]],
184   [], [ignore], [ignore])
186 AT_DATA([mycc],
187 [[#! /bin/sh
188 echo "Annoying copyright message" >&2
189 exec "$@"
192 chmod +x mycc
194 # We go through the following contortions, in order to have the
195 # configure script go down the same codepaths as it would during a
196 # normal CPP selection check.  If we explicitly set CPP, it goes down
197 # a different codepath.
198 _AT_CHECK_AC_MACRO(
199 [[AC_PROG_CC
200 CC="./mycc $CC"
201 AC_PROG_CPP
202 # The test $CC compiler should have been selected.
203 test "$CPP" != "$CC -E" &&
204   AC_MSG_ERROR([error messages on stderr cause the preprocessor selection to fail])
206 # Exercise CPP.
207 AC_CHECK_HEADERS(stdio.h autoconf_io.h, [], [], [-])]])
209 AT_CHECK_DEFINES(
210 [/* #undef HAVE_AUTOCONF_IO_H */
211 #define HAVE_STDIO_H 1
214 AT_CLEANUP
217 ## ------------------------------------ ##
218 ## AC_NO_EXECUTABLES (working linker).  ##
219 ## ------------------------------------ ##
221 AT_CHECK_MACRO([AC_NO_EXECUTABLES (working linker)],
222 [AC_NO_EXECUTABLES
223 AC_PROG_CC
227 ## ----------------------------------- ##
228 ## AC_NO_EXECUTABLES (broken linker).  ##
229 ## ----------------------------------- ##
231 AT_CHECK_MACRO([AC_NO_EXECUTABLES (broken linker)],
232 [LDFLAGS=-lnosuchlibrary
233 AC_NO_EXECUTABLES
234 AC_PROG_CC
238 ## -------------------------- ##
239 ## AC_USE_SYSTEM_EXTENSIONS.  ##
240 ## -------------------------- ##
242 AT_SETUP([AC_USE_SYSTEM_EXTENSIONS])
244 # Some existing configure.ac mixed AC_AIX (now an alias for
245 # AC_USE_SYSTEM_EXTENSIONS) and AC_DEFINE([__EXTENSIONS__]), which
246 # broke autoheader in 2.62.  Test that this is supported.
248 _AT_CHECK_AC_MACRO(
249 [[AC_AIX
250 AC_DEFINE([__EXTENSIONS__], [1], [Manually defined for Solaris])
253 _AT_CHECK_AC_MACRO(
254 [[AC_USE_SYSTEM_EXTENSIONS
255 AC_DEFINE([__EXTENSIONS__], [1], [Manually defined for Solaris])
258 AT_CLEANUP
261 ## ----------------------- ##
262 ## AC_C_RESTRICT and C++.  ##
263 ## ----------------------- ##
265 AT_SETUP([AC_C_RESTRICT and C++])
267 # In some compiler suites, the left hand doesn't know about everything
268 # the right hand does; or the user mixes the C compiler from one suite
269 # with the C++ compiler from another.  In this case, Sun WorkShop CC
270 # not like the _Restrict accepted by cc.
272 AT_DATA([configure.ac],
273 [[AC_INIT
274 AC_PROG_CC
275 AC_PROG_CXX
276 AC_C_RESTRICT
277 AC_CONFIG_HEADERS([config.h])
278 AC_CONFIG_FILES([Makefile])
279 AC_OUTPUT
282 AT_DATA([Makefile.in],
283 [[CC = @CC@
284 CXX = @CXX@
285 CFLAGS = @CFLAGS@
286 CXXFLAGS = @CXXFLAGS@
287 CPPFLAGS = -I. @CPPFLAGS@
288 OBJEXT = @OBJEXT@
289 all: foo.$(OBJEXT) bar.$(OBJEXT)
290 cpp-works:
291         $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c cpp-works.cpp
292 foo.$(OBJEXT): foo.c
293         $(CC) $(CPPFLAGS) $(CFLAGS) -c foo.c
294 bar.$(OBJEXT): bar.cpp
295         $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c bar.cpp
298 AT_DATA([foo.c],
299 [[#include <config.h>
301 int foo (int * restrict i1, int * restrict i2)
303   return i1[0] + i2[0];
307 cp foo.c bar.cpp
309 AT_DATA([cpp-works.cpp],
310 [[// This file is just to test whether we have a working C++ compiler at all
311 class foo { int x; };
312 class foo foobar;
315 AT_CHECK([autoconf])
316 AT_CHECK([autoheader])
317 AT_CHECK([./configure $configure_options], [], [ignore], [ignore])
318 AT_CHECK([${MAKE-make} cpp-works || exit 77], [], [ignore], [ignore])
319 AT_CHECK([${MAKE-make}], [], [ignore], [ignore])
321 AT_CLEANUP
324 ## ---------------- ##
325 ## AC_OPENMP and C. ##
326 ## ---------------- ##
328 AT_SETUP([AC_OPENMP and C])
330 AT_DATA([configure.ac],
331 [[AC_INIT
332 AC_PROG_CC
333 AC_OPENMP
334 if test "X$ac_cv_prog_c_openmp" = Xunsupported; then
335   AS_EXIT([77])
337 CFLAGS="$CFLAGS $OPENMP_CFLAGS"
338 CPPFLAGS="$CPPFLAGS $OPENMP_CFLAGS"
339 AC_CONFIG_FILES([Makefile])
340 AC_OUTPUT
343 AT_DATA([Makefile.in],
344 [[foo@EXEEXT@: foo.@OBJEXT@
345         @CC@ @CFLAGS@ @LDFLAGS@ -o $@ foo.@OBJEXT@
347 foo.@OBJEXT@: foo.c
348         @CC@ @CPPFLAGS@ @CFLAGS@ -c foo.c
351 AT_DATA([foo.c],
352 [[#ifdef _OPENMP
353 #include <omp.h>
354 #endif
355 #include <stdio.h>
357 int main ()
359 #ifdef _OPENMP
360 #pragma omp parallel
361   {
362     int id = omp_get_thread_num ();
363     printf ("hello omp world from %d\n", id);
364   }
365 #endif
366   return 0;
370 : "${MAKE=make}"
371 AT_CHECK([env ACLOCAL=true autoreconf -vi], [], [ignore], [ignore])
372 AT_CHECK([./configure $configure_options], [], [ignore], [ignore])
373 AT_CHECK([$MAKE], [], [ignore], [ignore])
375 AT_CLEANUP
378 ## ------------------ ##
379 ## AC_OPENMP anc C++. ##
380 ## ------------------ ##
382 AT_SETUP([AC_OPENMP and C++])
384 AT_DATA([configure.ac],
385 [[AC_INIT
386 AC_PROG_CXX
387 AC_LANG([C++])
388 AC_OPENMP
389 if test "X$ac_cv_prog_cxx_openmp" = Xunsupported; then
390   AS_EXIT([77])
392 CXXFLAGS="$CXXFLAGS $OPENMP_CXXFLAGS"
393 CPPFLAGS="$CPPFLAGS $OPENMP_CXXFLAGS"
394 AC_CONFIG_FILES([Makefile])
395 AC_OUTPUT
398 AT_DATA([Makefile.in],
399 [[foo@EXEEXT@: foo.@OBJEXT@
400         @CXX@ @CXXFLAGS@ @LDFLAGS@ -o $@ foo.@OBJEXT@
402 foo.@OBJEXT@: foo.cpp
403         @CXX@ @CPPFLAGS@ @CXXFLAGS@ -c foo.cpp
406 AT_DATA([foo.cpp],
407 [[int main ()
409   return 0;
413 : "${MAKE=make}"
414 AT_CHECK([env ACLOCAL=true autoreconf -vi], [], [ignore], [ignore])
415 AT_CHECK([./configure $configure_options], [], [ignore], [ignore])
416 AT_CHECK([$MAKE], [], [ignore], [ignore])
418 AT_CLEANUP