| 1 |
# -*- Autotest -*- |
| 2 |
|
| 3 |
AT_BANNER([C low level compiling/preprocessing macros.]) |
| 4 |
|
| 5 |
# Copyright (C) 2000-2006, 2008-2017, 2020-2026 Free Software |
| 6 |
# Foundation, Inc. |
| 7 |
# |
| 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. |
| 12 |
# |
| 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. |
| 17 |
# |
| 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/>. |
| 20 |
|
| 21 |
|
| 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. |
| 25 |
|
| 26 |
|
| 27 |
## ------------ ## |
| 28 |
## Extensions. ## |
| 29 |
## ------------ ## |
| 30 |
|
| 31 |
AT_CHECK_CONFIGURE_AC([Object file extensions], |
| 32 |
[[AC_PROG_CC |
| 33 |
|
| 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], |
| 38 |
['' | '.exe'], |
| 39 |
[], |
| 40 |
[AC_MSG_ERROR([suspicious executable suffix: $ac_exeext])]) |
| 41 |
|
| 42 |
AS@&t@_CASE([$ac_objext], |
| 43 |
['o' | 'obj'], |
| 44 |
[], |
| 45 |
[AC_MSG_ERROR([suspicious object suffix: $ac_objext])]) |
| 46 |
|
| 47 |
AC_OUTPUT |
| 48 |
]]) |
| 49 |
|
| 50 |
|
| 51 |
## -------------------------- ## |
| 52 |
## Broken/missing compilers. ## |
| 53 |
## -------------------------- ## |
| 54 |
|
| 55 |
|
| 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]) |
| 60 |
|
| 61 |
AT_DATA([configure.ac], |
| 62 |
[[AC_INIT |
| 63 |
AC_PROG_CC |
| 64 |
AC_OUTPUT |
| 65 |
]]) |
| 66 |
|
| 67 |
AT_CHECK_AUTOCONF |
| 68 |
AT_CHECK_CONFIGURE([CC=no-such-compiler], 77, ignore, ignore) |
| 69 |
|
| 70 |
AT_CLEANUP |
| 71 |
|
| 72 |
|
| 73 |
## ------------ ## |
| 74 |
## C keywords. ## |
| 75 |
## ------------ ## |
| 76 |
|
| 77 |
AT_CHECK_CONFIGURE_AC([C keywords], |
| 78 |
[[AC_PROG_CC |
| 79 |
|
| 80 |
AC_C_CONST |
| 81 |
AC_C_TYPEOF |
| 82 |
AC_C_VOLATILE |
| 83 |
|
| 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 |
| 87 |
yes,*no*) |
| 88 |
AC_MSG_ERROR([failed to detect 'const', 'typeof', or 'volatile' support]);; |
| 89 |
esac |
| 90 |
]]) |
| 91 |
|
| 92 |
|
| 93 |
## --------------------------------- ## |
| 94 |
## AC_PROG_CPP requires AC_PROG_CC. ## |
| 95 |
## --------------------------------- ## |
| 96 |
|
| 97 |
AT_CHECK_CONFIGURE_AC([AC_PROG_CPP requires AC_PROG_CC], |
| 98 |
[[AC_PROG_CPP |
| 99 |
|
| 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]) |
| 103 |
fi |
| 104 |
]]) |
| 105 |
|
| 106 |
|
| 107 |
## --------------------------- ## |
| 108 |
## AC_PROG_CPP with warnings. ## |
| 109 |
## --------------------------- ## |
| 110 |
|
| 111 |
|
| 112 |
# It's Ok for strict preprocessors to produce warnings. |
| 113 |
|
| 114 |
AT_SETUP([AC_PROG_CPP with warnings]) |
| 115 |
|
| 116 |
AT_DATA([mycpp], |
| 117 |
[[#! /bin/sh |
| 118 |
echo noise >&2 |
| 119 |
exec "$@" |
| 120 |
]]) |
| 121 |
|
| 122 |
chmod +x mycpp |
| 123 |
|
| 124 |
_AT_CHECK_AC_MACRO( |
| 125 |
[[AC_PROG_CPP |
| 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) |
| 129 |
CPP="./mycpp $CPP" |
| 130 |
|
| 131 |
# Exercise CPP. |
| 132 |
|
| 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])]) |
| 137 |
]]) |
| 138 |
AT_CHECK_DEFINES( |
| 139 |
[/* #undef HAVE_AUTOCONF_IO_H */ |
| 140 |
#define HAVE_FLOAT_H 1 |
| 141 |
]) |
| 142 |
|
| 143 |
AT_CLEANUP |
| 144 |
|
| 145 |
|
| 146 |
## ------------------------------ ## |
| 147 |
## AC_PROG_CPP without warnings. ## |
| 148 |
## ------------------------------ ## |
| 149 |
|
| 150 |
AT_SETUP([AC_PROG_CPP without warnings]) |
| 151 |
|
| 152 |
# Ignore if the cpp in $PATH doesn't work |
| 153 |
AT_CHECK([[echo '#include <stdio.h>' | cpp || exit 77]], |
| 154 |
[], [ignore], [ignore]) |
| 155 |
|
| 156 |
# A cpp which exit status is meaningless. |
| 157 |
AT_DATA([mycpp], |
| 158 |
[[#! /bin/sh |
| 159 |
cpp "$@" |
| 160 |
exit 0 |
| 161 |
]]) |
| 162 |
|
| 163 |
chmod +x mycpp |
| 164 |
|
| 165 |
_AT_CHECK_AC_MACRO( |
| 166 |
[[CPP=./mycpp |
| 167 |
AC_PROG_CPP |
| 168 |
test "x$ac_c_preproc_warn_flag" != xyes && |
| 169 |
AC_MSG_ERROR([failed to detect preprocessor warning option]) |
| 170 |
|
| 171 |
# Exercise CPP. |
| 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])]) |
| 176 |
]]) |
| 177 |
|
| 178 |
AT_CHECK_DEFINES( |
| 179 |
[/* #undef HAVE_AUTOCONF_IO_H */ |
| 180 |
#define HAVE_FLOAT_H 1 |
| 181 |
]) |
| 182 |
|
| 183 |
AT_CLEANUP |
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
## -------------------- ## |
| 188 |
## AC_PROG_CPP via CC. ## |
| 189 |
## -------------------- ## |
| 190 |
|
| 191 |
|
| 192 |
# It's Ok for strict preprocessors to produce warnings. |
| 193 |
|
| 194 |
AT_SETUP([AC_PROG_CPP via CC]) |
| 195 |
|
| 196 |
# Ignore if the cpp in $PATH doesn't work |
| 197 |
AT_CHECK([[echo '#include <stdio.h>' | cpp || exit 77]], |
| 198 |
[], [ignore], [ignore]) |
| 199 |
|
| 200 |
AT_DATA([mycc], |
| 201 |
[[#! /bin/sh |
| 202 |
echo "Annoying copyright message" >&2 |
| 203 |
exec "$@" |
| 204 |
]]) |
| 205 |
|
| 206 |
chmod +x mycc |
| 207 |
|
| 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. |
| 212 |
_AT_CHECK_AC_MACRO( |
| 213 |
[[AC_PROG_CC |
| 214 |
CC="./mycc $CC" |
| 215 |
AC_PROG_CPP |
| 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]) |
| 219 |
|
| 220 |
# Exercise CPP. |
| 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])]) |
| 225 |
]]) |
| 226 |
|
| 227 |
AT_CHECK_DEFINES( |
| 228 |
[/* #undef HAVE_AUTOCONF_IO_H */ |
| 229 |
#define HAVE_FLOAT_H 1 |
| 230 |
]) |
| 231 |
|
| 232 |
AT_CLEANUP |
| 233 |
|
| 234 |
|
| 235 |
## ----------------------------------- ## |
| 236 |
## AC_PROG_EGREP and AC_EGREP_HEADER. ## |
| 237 |
## ----------------------------------- ## |
| 238 |
|
| 239 |
AT_SETUP([AC_PROG_EGREP and AC_EGREP_HEADER]) |
| 240 |
|
| 241 |
_AT_CHECK_AC_MACRO( |
| 242 |
[[AC_PROG_CPP |
| 243 |
AC_PROG_EGREP |
| 244 |
|
| 245 |
# Although this code is incorrect (it should use AS_IF), |
| 246 |
# it follows a too-common real world pattern. |
| 247 |
# For now, test for it; we may remove this test later. |
| 248 |
if false; then |
| 249 |
AC_EGREP_HEADER([^], [limits.h]) |
| 250 |
fi |
| 251 |
|
| 252 |
AC_EGREP_HEADER([$], [limits.h], [], |
| 253 |
[AC_MSG_ERROR([[egrep-related macros do not tolerate misuse of 'if']])]) |
| 254 |
]]) |
| 255 |
|
| 256 |
AT_CLEANUP |
| 257 |
|
| 258 |
|
| 259 |
## ------------------------------------ ## |
| 260 |
## AC_NO_EXECUTABLES (working linker). ## |
| 261 |
## ------------------------------------ ## |
| 262 |
|
| 263 |
AT_CHECK_CONFIGURE_AC([AC_NO_EXECUTABLES (working linker)], |
| 264 |
[[AC_NO_EXECUTABLES |
| 265 |
AC_PROG_CC |
| 266 |
]]) |
| 267 |
|
| 268 |
|
| 269 |
## ----------------------------------- ## |
| 270 |
## AC_NO_EXECUTABLES (broken linker). ## |
| 271 |
## ----------------------------------- ## |
| 272 |
|
| 273 |
AT_CHECK_CONFIGURE_AC([AC_NO_EXECUTABLES (broken linker)], |
| 274 |
[[LDFLAGS=-lnosuchlibrary |
| 275 |
AC_NO_EXECUTABLES |
| 276 |
AC_PROG_CC |
| 277 |
]]) |
| 278 |
|
| 279 |
|
| 280 |
## -------------------------- ## |
| 281 |
## AC_USE_SYSTEM_EXTENSIONS. ## |
| 282 |
## -------------------------- ## |
| 283 |
|
| 284 |
AT_SETUP([AC_USE_SYSTEM_EXTENSIONS]) |
| 285 |
|
| 286 |
# Some existing configure.ac mixed AC_AIX (now an alias for |
| 287 |
# AC_USE_SYSTEM_EXTENSIONS) and AC_DEFINE([__EXTENSIONS__]), which |
| 288 |
# broke autoheader in 2.62. Test that this is supported. |
| 289 |
|
| 290 |
_AT_CHECK_AC_MACRO( |
| 291 |
[[AC_AIX |
| 292 |
AC_DEFINE([__EXTENSIONS__], [1], [Manually defined for Solaris]) |
| 293 |
]], [], [-Wno-obsolete]) |
| 294 |
|
| 295 |
_AT_CHECK_AC_MACRO( |
| 296 |
[[AC_USE_SYSTEM_EXTENSIONS |
| 297 |
AC_DEFINE([__EXTENSIONS__], [1], [Manually defined for Solaris]) |
| 298 |
]]) |
| 299 |
|
| 300 |
AT_CLEANUP |
| 301 |
|
| 302 |
|
| 303 |
## ----------------------- ## |
| 304 |
## AC_C_RESTRICT and C++. ## |
| 305 |
## ----------------------- ## |
| 306 |
|
| 307 |
AT_SETUP([AC_C_RESTRICT and C++]) |
| 308 |
|
| 309 |
# In some compiler suites, the left hand doesn't know about everything |
| 310 |
# the right hand does; or the user mixes the C compiler from one suite |
| 311 |
# with the C++ compiler from another. In this case, Sun WorkShop CC |
| 312 |
# not like the _Restrict accepted by cc. |
| 313 |
|
| 314 |
AT_DATA([configure.ac], |
| 315 |
[[AC_INIT |
| 316 |
AC_PROG_CC |
| 317 |
AC_PROG_CXX |
| 318 |
AC_C_RESTRICT |
| 319 |
AC_CONFIG_HEADERS([config.h]) |
| 320 |
AC_CONFIG_FILES([Makefile]) |
| 321 |
AC_OUTPUT |
| 322 |
]]) |
| 323 |
|
| 324 |
AT_DATA([Makefile.in], |
| 325 |
[[CC = @CC@ |
| 326 |
CXX = @CXX@ |
| 327 |
CFLAGS = @CFLAGS@ |
| 328 |
CXXFLAGS = @CXXFLAGS@ |
| 329 |
CPPFLAGS = -I. @CPPFLAGS@ |
| 330 |
OBJEXT = @OBJEXT@ |
| 331 |
all: foo.$(OBJEXT) bar.$(OBJEXT) |
| 332 |
cpp-works: |
| 333 |
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c cpp-works.cpp |
| 334 |
foo.$(OBJEXT): foo.c |
| 335 |
$(CC) $(CPPFLAGS) $(CFLAGS) -c foo.c |
| 336 |
bar.$(OBJEXT): bar.cpp |
| 337 |
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c bar.cpp |
| 338 |
]]) |
| 339 |
|
| 340 |
AT_DATA([foo.c], |
| 341 |
[[#include <config.h> |
| 342 |
|
| 343 |
int foo (int * restrict i1, int * restrict i2) |
| 344 |
{ |
| 345 |
return i1[0] + i2[0]; |
| 346 |
} |
| 347 |
]]) |
| 348 |
|
| 349 |
cp foo.c bar.cpp |
| 350 |
|
| 351 |
AT_DATA([cpp-works.cpp], |
| 352 |
[[// This file is just to test whether we have a working C++ compiler at all |
| 353 |
class foo { int x; }; |
| 354 |
class foo foobar; |
| 355 |
]]) |
| 356 |
|
| 357 |
AT_CHECK_AUTOCONF |
| 358 |
AT_CHECK_AUTOHEADER([], [restrict]) |
| 359 |
AT_CHECK_CONFIGURE |
| 360 |
AT_CHECK_MAKE([cpp-works || exit 77]) |
| 361 |
AT_CHECK_MAKE |
| 362 |
|
| 363 |
AT_CLEANUP |
| 364 |
|
| 365 |
|
| 366 |
## ---------------- ## |
| 367 |
## AC_OPENMP and C. ## |
| 368 |
## ---------------- ## |
| 369 |
|
| 370 |
AT_SETUP([AC_OPENMP and C]) |
| 371 |
|
| 372 |
AT_DATA([configure.ac], |
| 373 |
[[AC_INIT |
| 374 |
AC_PROG_CC |
| 375 |
AC_OPENMP |
| 376 |
if test "X$ac_cv_prog_c_openmp" = Xunsupported; then |
| 377 |
AS_EXIT([77]) |
| 378 |
fi |
| 379 |
CFLAGS="$CFLAGS $OPENMP_CFLAGS" |
| 380 |
CPPFLAGS="$CPPFLAGS $OPENMP_CFLAGS" |
| 381 |
AC_CONFIG_FILES([Makefile]) |
| 382 |
AC_OUTPUT |
| 383 |
]]) |
| 384 |
|
| 385 |
AT_DATA([Makefile.in], |
| 386 |
[[foo@EXEEXT@: foo.@OBJEXT@ |
| 387 |
@CC@ @CFLAGS@ @LDFLAGS@ -o $@ foo.@OBJEXT@ |
| 388 |
|
| 389 |
foo.@OBJEXT@: foo.c |
| 390 |
@CC@ @CPPFLAGS@ @CFLAGS@ -c foo.c |
| 391 |
]]) |
| 392 |
|
| 393 |
AT_DATA([foo.c], |
| 394 |
[[#ifdef _OPENMP |
| 395 |
#include <omp.h> |
| 396 |
#endif |
| 397 |
#include <stdio.h> |
| 398 |
|
| 399 |
int main (void) |
| 400 |
{ |
| 401 |
#ifdef _OPENMP |
| 402 |
#pragma omp parallel |
| 403 |
{ |
| 404 |
int id = omp_get_thread_num (); |
| 405 |
printf ("hello omp world from %d\n", id); |
| 406 |
} |
| 407 |
#endif |
| 408 |
return 0; |
| 409 |
} |
| 410 |
]]) |
| 411 |
|
| 412 |
AT_CHECK_AUTOCONF |
| 413 |
AT_CHECK_CONFIGURE |
| 414 |
AT_CHECK_MAKE |
| 415 |
|
| 416 |
AT_CLEANUP |
| 417 |
|
| 418 |
|
| 419 |
## ------------------ ## |
| 420 |
## AC_OPENMP anc C++. ## |
| 421 |
## ------------------ ## |
| 422 |
|
| 423 |
AT_SETUP([AC_OPENMP and C++]) |
| 424 |
|
| 425 |
AT_DATA([configure.ac], |
| 426 |
[[AC_INIT |
| 427 |
AC_PROG_CXX |
| 428 |
AC_LANG([C++]) |
| 429 |
AC_OPENMP |
| 430 |
if test "X$ac_cv_prog_cxx_openmp" = Xunsupported; then |
| 431 |
AS_EXIT([77]) |
| 432 |
fi |
| 433 |
CXXFLAGS="$CXXFLAGS $OPENMP_CXXFLAGS" |
| 434 |
CPPFLAGS="$CPPFLAGS $OPENMP_CXXFLAGS" |
| 435 |
AC_CONFIG_FILES([Makefile]) |
| 436 |
AC_OUTPUT |
| 437 |
]]) |
| 438 |
|
| 439 |
AT_DATA([Makefile.in], |
| 440 |
[[foo@EXEEXT@: foo.@OBJEXT@ |
| 441 |
@CXX@ @CXXFLAGS@ @LDFLAGS@ -o $@ foo.@OBJEXT@ |
| 442 |
|
| 443 |
foo.@OBJEXT@: foo.cpp |
| 444 |
@CXX@ @CPPFLAGS@ @CXXFLAGS@ -c foo.cpp |
| 445 |
]]) |
| 446 |
|
| 447 |
AT_DATA([foo.cpp], |
| 448 |
[[int main (void) |
| 449 |
{ |
| 450 |
return 0; |
| 451 |
} |
| 452 |
]]) |
| 453 |
|
| 454 |
AT_CHECK_AUTOCONF |
| 455 |
AT_CHECK_CONFIGURE |
| 456 |
AT_CHECK_MAKE |
| 457 |
|
| 458 |
AT_CLEANUP |