3 AT_BANNER([C low level compiling/preprocessing macros.])
5 # Copyright (C) 2000-2006, 2008-2017, 2020-2023 Free Software
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 <https://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.
31 AT_CHECK_CONFIGURE_AC([Object file extensions],
34 # As far as we know only 'foo', 'foo.exe' are possible executable,
35 # and 'foo.o', 'foo.obj' are possible object files. Autoconf must not
36 # know that, but it is OK for the test suite to take this into account.
37 AS@&t@_CASE([$ac_exeext],
40 [AC_MSG_ERROR([suspicious executable suffix: $ac_exeext])])
42 AS@&t@_CASE([$ac_objext],
45 [AC_MSG_ERROR([suspicious object suffix: $ac_objext])])
51 ## -------------------------- ##
52 ## Broken/missing compilers. ##
53 ## -------------------------- ##
56 # Check that Autoconf correctly diagnoses broken compilers, and in
57 # particular, if it does not exit 77, the test suite is in trouble...
58 # FIXME: Once a precise message decided, check stderr of configure.
59 AT_SETUP([Broken/missing compilers])
61 AT_DATA([configure.ac],
68 AT_CHECK_CONFIGURE([CC=no-such-compiler], 77, ignore, ignore)
77 AT_CHECK_CONFIGURE_AC([C keywords],
84 # If the C compiler is GCC, AC_C_{CONST,TYPEOF,VOLATILE} ought to all
85 # detect support for their respective keyword.
86 case $GCC,$ac_cv_c_const,$ac_cv_c_typeof,$ac_cv_c_volatile in
88 AC_MSG_ERROR([failed to detect 'const', 'typeof', or 'volatile' support]);;
93 ## --------------------------------- ##
94 ## AC_PROG_CPP requires AC_PROG_CC. ##
95 ## --------------------------------- ##
97 AT_CHECK_CONFIGURE_AC([AC_PROG_CPP requires AC_PROG_CC],
100 # AC_PROG_CPP should have AC_REQUIREd AC_PROG_CC.
101 if test -z "$CC"; then
102 AC_MSG_ERROR([looked for a C preprocessor without looking for a compiler])
107 ## --------------------------- ##
108 ## AC_PROG_CPP with warnings. ##
109 ## --------------------------- ##
112 # It's Ok for strict preprocessors to produce warnings.
114 AT_SETUP([AC_PROG_CPP with warnings])
126 # If the preprocessor is not strict, just ignore
127 test "x$ac_c_preproc_warn_flag" = xyes &&
128 AC_MSG_ERROR([preprocessor has no warning option], 77)
133 AC_PREPROC_IFELSE([AC_LANG_SOURCE([[#include <float.h>]])],
134 [AC_DEFINE([HAVE_FLOAT_H], [1], [Define if you have float.h])])
135 AC_PREPROC_IFELSE([AC_LANG_SOURCE([[#include <autoconf_io.h>]])],
136 [AC_DEFINE([HAVE_AUTOCONF_IO_H], [1], [Define if you have autoconf_io.h])])
139 [/* #undef HAVE_AUTOCONF_IO_H */
140 #define HAVE_FLOAT_H 1
146 ## ------------------------------ ##
147 ## AC_PROG_CPP without warnings. ##
148 ## ------------------------------ ##
150 AT_SETUP([AC_PROG_CPP without warnings])
152 # Ignore if the cpp in $PATH doesn't work
153 AT_CHECK([[echo '#include <stdio.h>' | cpp || exit 77]],
154 [], [ignore], [ignore])
156 # A cpp which exit status is meaningless.
168 test "x$ac_c_preproc_warn_flag" != xyes &&
169 AC_MSG_ERROR([failed to detect preprocessor warning option])
172 AC_PREPROC_IFELSE([AC_LANG_SOURCE([[#include <float.h>]])],
173 [AC_DEFINE([HAVE_FLOAT_H], [1], [Define if you have float.h])])
174 AC_PREPROC_IFELSE([AC_LANG_SOURCE([[#include <autoconf_io.h>]])],
175 [AC_DEFINE([HAVE_AUTOCONF_IO_H], [1], [Define if you have autoconf_io.h])])
179 [/* #undef HAVE_AUTOCONF_IO_H */
180 #define HAVE_FLOAT_H 1
187 ## -------------------- ##
188 ## AC_PROG_CPP via CC. ##
189 ## -------------------- ##
192 # It's Ok for strict preprocessors to produce warnings.
194 AT_SETUP([AC_PROG_CPP via CC])
196 # Ignore if the cpp in $PATH doesn't work
197 AT_CHECK([[echo '#include <stdio.h>' | cpp || exit 77]],
198 [], [ignore], [ignore])
202 echo "Annoying copyright message" >&2
208 # We go through the following contortions, in order to have the
209 # configure script go down the same codepaths as it would during a
210 # normal CPP selection check. If we explicitly set CPP, it goes down
211 # a different codepath.
216 # The test $CC compiler should have been selected.
217 test "$CPP" != "$CC -E" &&
218 AC_MSG_ERROR([error messages on stderr cause the preprocessor selection to fail])
221 AC_PREPROC_IFELSE([AC_LANG_SOURCE([[#include <float.h>]])],
222 [AC_DEFINE([HAVE_FLOAT_H], [1], [Define if you have float.h])])
223 AC_PREPROC_IFELSE([AC_LANG_SOURCE([[#include <autoconf_io.h>]])],
224 [AC_DEFINE([HAVE_AUTOCONF_IO_H], [1], [Define if you have autoconf_io.h])])
228 [/* #undef HAVE_AUTOCONF_IO_H */
229 #define HAVE_FLOAT_H 1
235 ## ------------------------------------ ##
236 ## AC_NO_EXECUTABLES (working linker). ##
237 ## ------------------------------------ ##
239 AT_CHECK_CONFIGURE_AC([AC_NO_EXECUTABLES (working linker)],
245 ## ----------------------------------- ##
246 ## AC_NO_EXECUTABLES (broken linker). ##
247 ## ----------------------------------- ##
249 AT_CHECK_CONFIGURE_AC([AC_NO_EXECUTABLES (broken linker)],
250 [[LDFLAGS=-lnosuchlibrary
256 ## -------------------------- ##
257 ## AC_USE_SYSTEM_EXTENSIONS. ##
258 ## -------------------------- ##
260 AT_SETUP([AC_USE_SYSTEM_EXTENSIONS])
262 # Some existing configure.ac mixed AC_AIX (now an alias for
263 # AC_USE_SYSTEM_EXTENSIONS) and AC_DEFINE([__EXTENSIONS__]), which
264 # broke autoheader in 2.62. Test that this is supported.
268 AC_DEFINE([__EXTENSIONS__], [1], [Manually defined for Solaris])
269 ]], [], [-Wno-obsolete])
272 [[AC_USE_SYSTEM_EXTENSIONS
273 AC_DEFINE([__EXTENSIONS__], [1], [Manually defined for Solaris])
279 ## ----------------------- ##
280 ## AC_C_RESTRICT and C++. ##
281 ## ----------------------- ##
283 AT_SETUP([AC_C_RESTRICT and C++])
285 # In some compiler suites, the left hand doesn't know about everything
286 # the right hand does; or the user mixes the C compiler from one suite
287 # with the C++ compiler from another. In this case, Sun WorkShop CC
288 # not like the _Restrict accepted by cc.
290 AT_DATA([configure.ac],
295 AC_CONFIG_HEADERS([config.h])
296 AC_CONFIG_FILES([Makefile])
300 AT_DATA([Makefile.in],
304 CXXFLAGS = @CXXFLAGS@
305 CPPFLAGS = -I. @CPPFLAGS@
307 all: foo.$(OBJEXT) bar.$(OBJEXT)
309 $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c cpp-works.cpp
311 $(CC) $(CPPFLAGS) $(CFLAGS) -c foo.c
312 bar.$(OBJEXT): bar.cpp
313 $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c bar.cpp
317 [[#include <config.h>
319 int foo (int * restrict i1, int * restrict i2)
321 return i1[0] + i2[0];
327 AT_DATA([cpp-works.cpp],
328 [[// This file is just to test whether we have a working C++ compiler at all
329 class foo { int x; };
334 AT_CHECK_AUTOHEADER([], [restrict])
336 AT_CHECK_MAKE([cpp-works || exit 77])
342 ## ---------------- ##
343 ## AC_OPENMP and C. ##
344 ## ---------------- ##
346 AT_SETUP([AC_OPENMP and C])
348 AT_DATA([configure.ac],
352 if test "X$ac_cv_prog_c_openmp" = Xunsupported; then
355 CFLAGS="$CFLAGS $OPENMP_CFLAGS"
356 CPPFLAGS="$CPPFLAGS $OPENMP_CFLAGS"
357 AC_CONFIG_FILES([Makefile])
361 AT_DATA([Makefile.in],
362 [[foo@EXEEXT@: foo.@OBJEXT@
363 @CC@ @CFLAGS@ @LDFLAGS@ -o $@ foo.@OBJEXT@
366 @CC@ @CPPFLAGS@ @CFLAGS@ -c foo.c
380 int id = omp_get_thread_num ();
381 printf ("hello omp world from %d\n", id);
395 ## ------------------ ##
396 ## AC_OPENMP anc C++. ##
397 ## ------------------ ##
399 AT_SETUP([AC_OPENMP and C++])
401 AT_DATA([configure.ac],
406 if test "X$ac_cv_prog_cxx_openmp" = Xunsupported; then
409 CXXFLAGS="$CXXFLAGS $OPENMP_CXXFLAGS"
410 CPPFLAGS="$CPPFLAGS $OPENMP_CXXFLAGS"
411 AC_CONFIG_FILES([Makefile])
415 AT_DATA([Makefile.in],
416 [[foo@EXEEXT@: foo.@OBJEXT@
417 @CXX@ @CXXFLAGS@ @LDFLAGS@ -o $@ foo.@OBJEXT@
419 foo.@OBJEXT@: foo.cpp
420 @CXX@ @CPPFLAGS@ @CXXFLAGS@ -c foo.cpp