| 1 |
# -*- Autotest -*- |
| 2 |
|
| 3 |
AT_BANNER([Low level compiling/preprocessing macros.]) |
| 4 |
|
| 5 |
# Copyright (C) 2000-2001, 2003, 2005-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 |
## AC_LANG, AC_LANG_PUSH & AC_LANG_POP. ## |
| 29 |
## ------------------------------------- ## |
| 30 |
|
| 31 |
AT_SETUP([[AC_LANG, AC_LANG_PUSH & AC_LANG_POP]]) |
| 32 |
|
| 33 |
AT_DATA([configure.ac], |
| 34 |
[[AC_INIT |
| 35 |
# C |
| 36 |
AC_LANG([C]) |
| 37 |
# C |
| 38 |
AC_LANG_PUSH([C]) |
| 39 |
# C C |
| 40 |
AC_LANG_PUSH([C++]) |
| 41 |
# C++ C C |
| 42 |
AC_LANG([C++]) |
| 43 |
# C++ C C |
| 44 |
AC_LANG_PUSH([Erlang]) |
| 45 |
# Erlang C++ C C |
| 46 |
AC_LANG_PUSH([Fortran 77]) |
| 47 |
# F77 Erlang C++ C C |
| 48 |
AC_LANG_POP([Fortran 77]) |
| 49 |
# Erlang C++ C C |
| 50 |
AC_LANG_POP([Erlang]) |
| 51 |
# C++ C C |
| 52 |
AC_LANG([C++]) |
| 53 |
# C++ C C |
| 54 |
AC_LANG_POP([C++]) |
| 55 |
# C C |
| 56 |
AC_LANG_POP([C]) |
| 57 |
# C |
| 58 |
AC_OUTPUT |
| 59 |
]]) |
| 60 |
|
| 61 |
AT_CHECK_AUTOCONF |
| 62 |
AT_CHECK([sed -n 's/^ac_ext=//p' configure], 0, |
| 63 |
[c |
| 64 |
c |
| 65 |
c |
| 66 |
cpp |
| 67 |
cpp |
| 68 |
erl |
| 69 |
f |
| 70 |
erl |
| 71 |
cpp |
| 72 |
cpp |
| 73 |
c |
| 74 |
c |
| 75 |
]) |
| 76 |
|
| 77 |
AT_CLEANUP |
| 78 |
|
| 79 |
|
| 80 |
## ---------------------- ## |
| 81 |
## AC_REQUIRE & AC_LANG. ## |
| 82 |
## ---------------------- ## |
| 83 |
|
| 84 |
AT_SETUP([AC_REQUIRE & AC_LANG]) |
| 85 |
|
| 86 |
AT_DATA([configure.ac], |
| 87 |
[[AC_DEFUN([AC_F77_1], |
| 88 |
[AC_LANG_PUSH([Fortran 77]) |
| 89 |
if test $ac_ext != f; then |
| 90 |
AC_MSG_ERROR([F77_1: current shell language is $ac_ext, expected Fortran]) |
| 91 |
fi |
| 92 |
AC_LANG_POP |
| 93 |
]) |
| 94 |
|
| 95 |
|
| 96 |
AC_DEFUN([AC_F77_2], |
| 97 |
[AC_LANG_PUSH([Fortran 77]) |
| 98 |
AC_REQUIRE([AC_F77_1]) |
| 99 |
if test $ac_ext != f; then |
| 100 |
AC_MSG_ERROR([F77_2: current shell language is $ac_ext, expected Fortran]) |
| 101 |
fi |
| 102 |
AC_LANG_POP |
| 103 |
]) |
| 104 |
|
| 105 |
AC_INIT |
| 106 |
AC_F77_2 |
| 107 |
AS_EXIT(0) |
| 108 |
]]) |
| 109 |
|
| 110 |
AT_CHECK_AUTOCONF([], [0], [], |
| 111 |
[[trailer.m4: warning: AC_OUTPUT was never used |
| 112 |
]]) |
| 113 |
|
| 114 |
AT_CHECK_CONFIGURE |
| 115 |
|
| 116 |
AT_CLEANUP |
| 117 |
|
| 118 |
|
| 119 |
## ---------------- ## |
| 120 |
## AC_LANG_SOURCE. ## |
| 121 |
## ---------------- ## |
| 122 |
|
| 123 |
AT_SETUP([AC_LANG_SOURCE]) |
| 124 |
|
| 125 |
AT_DATA([configure.ac], |
| 126 |
[[AC_INIT([pkg], [1.0]) |
| 127 |
AC_PROG_CC |
| 128 |
AC_COMPILE_IFELSE([AC_LANG_SOURCE([[#ifndef PACKAGE_NAME |
| 129 |
choke me |
| 130 |
#endif |
| 131 |
int main (void) |
| 132 |
{ |
| 133 |
return 0; |
| 134 |
} |
| 135 |
]], [], [AC_MSG_FAILURE([confdefs not included])])]) |
| 136 |
AC_OUTPUT |
| 137 |
]]) |
| 138 |
|
| 139 |
AT_CHECK_AUTOCONF |
| 140 |
AT_CHECK_CONFIGURE |
| 141 |
|
| 142 |
AT_CLEANUP |
| 143 |
|
| 144 |
|
| 145 |
## --------------------- ## |
| 146 |
## AC_LANG_SOURCE(C++). ## |
| 147 |
## --------------------- ## |
| 148 |
|
| 149 |
AT_SETUP([AC_LANG_SOURCE(C++)]) |
| 150 |
|
| 151 |
AT_DATA([configure.ac], |
| 152 |
[[AC_INIT([pkg], [1.0]) |
| 153 |
AC_PROG_CXX |
| 154 |
AC_LANG([C++]) |
| 155 |
AC_COMPILE_IFELSE([AC_LANG_SOURCE([[#ifndef PACKAGE_NAME |
| 156 |
choke me |
| 157 |
#endif |
| 158 |
int main (void) |
| 159 |
{ |
| 160 |
return 0; |
| 161 |
} |
| 162 |
]], [], [AC_MSG_FAILURE([confdefs not included])])]) |
| 163 |
AC_OUTPUT |
| 164 |
]]) |
| 165 |
|
| 166 |
AT_CHECK_AUTOCONF |
| 167 |
AT_CHECK_CONFIGURE |
| 168 |
|
| 169 |
AT_CLEANUP |
| 170 |
|
| 171 |
|
| 172 |
## ------------------------ ## |
| 173 |
## AC_LANG_SOURCE example. ## |
| 174 |
## ------------------------ ## |
| 175 |
|
| 176 |
AT_SETUP([AC_LANG_SOURCE example]) |
| 177 |
|
| 178 |
AT_DATA([configure.ac], |
| 179 |
[[# Taken from autoconf.texi:Generating Sources. |
| 180 |
# The only change is to not fail if gcc doesn't work. |
| 181 |
AC_INIT([Hello], [1.0], [[email protected]], [], |
| 182 |
[https://www.example.org/]) |
| 183 |
AC_DEFINE([HELLO_WORLD], ["Hello, World\n"], |
| 184 |
[Greetings string.]) |
| 185 |
AC_LANG([C]) |
| 186 |
AC_LANG_CONFTEST( |
| 187 |
[AC_LANG_SOURCE([[const char hw[] = "Hello, World\n";]])]) |
| 188 |
gcc -E -dD conftest.c || AS_EXIT([77]) |
| 189 |
AC_OUTPUT |
| 190 |
]]) |
| 191 |
|
| 192 |
AT_CHECK_AUTOCONF |
| 193 |
AT_CHECK_CONFIGURE([], [], [stdout]) |
| 194 |
# Taken from autoconf.texi:Generating Sources. |
| 195 |
# Note that the output may contain more defines and lines matching |
| 196 |
# # 1 "conftest.c" |
| 197 |
# so delete everything before the interesting output. |
| 198 |
AT_CHECK([sed -n 's/ *$//; /^configure: /d; /#define PACKAGE/,$p' stdout], [], |
| 199 |
[[#define PACKAGE_NAME "Hello" |
| 200 |
#define PACKAGE_TARNAME "hello" |
| 201 |
#define PACKAGE_VERSION "1.0" |
| 202 |
#define PACKAGE_STRING "Hello 1.0" |
| 203 |
#define PACKAGE_BUGREPORT "[email protected]" |
| 204 |
#define PACKAGE_URL "https://www.example.org/" |
| 205 |
#define HELLO_WORLD "Hello, World\n" |
| 206 |
|
| 207 |
const char hw[] = "Hello, World\n"; |
| 208 |
]]) |
| 209 |
|
| 210 |
AT_CLEANUP |
| 211 |
|
| 212 |
|
| 213 |
## ------------------------- ## |
| 214 |
## AC_LANG_PROGRAM example. ## |
| 215 |
## ------------------------- ## |
| 216 |
|
| 217 |
AT_SETUP([AC_LANG_PROGRAM example]) |
| 218 |
|
| 219 |
AT_DATA([configure.ac], |
| 220 |
[[# Taken from autoconf.texi:Generating Sources. |
| 221 |
# The only change is to not fail if gcc doesn't work. |
| 222 |
AC_INIT([Hello], [1.0], [[email protected]], [], |
| 223 |
[https://www.example.org/]) |
| 224 |
AC_DEFINE([HELLO_WORLD], ["Hello, World\n"], |
| 225 |
[Greetings string.]) |
| 226 |
AC_LANG_CONFTEST( |
| 227 |
[AC_LANG_PROGRAM([[const char hw[] = "Hello, World\n";]], |
| 228 |
[[fputs (hw, stdout);]])]) |
| 229 |
gcc -E -dD conftest.c || AS_EXIT([77]) |
| 230 |
AC_OUTPUT |
| 231 |
]]) |
| 232 |
|
| 233 |
AT_CHECK_AUTOCONF |
| 234 |
AT_CHECK_CONFIGURE([], [], [stdout]) |
| 235 |
# Taken from autoconf.texi:Generating Sources. |
| 236 |
# Note that the output may contain more defines and lines matching |
| 237 |
# # 1 "conftest.c" |
| 238 |
# so delete everything before the interesting output. |
| 239 |
AT_CHECK([sed -n 's/ *$//; /^configure: /d; /#define PACKAGE/,$p' stdout], [], |
| 240 |
[[#define PACKAGE_NAME "Hello" |
| 241 |
#define PACKAGE_TARNAME "hello" |
| 242 |
#define PACKAGE_VERSION "1.0" |
| 243 |
#define PACKAGE_STRING "Hello 1.0" |
| 244 |
#define PACKAGE_BUGREPORT "[email protected]" |
| 245 |
#define PACKAGE_URL "https://www.example.org/" |
| 246 |
#define HELLO_WORLD "Hello, World\n" |
| 247 |
|
| 248 |
const char hw[] = "Hello, World\n"; |
| 249 |
int |
| 250 |
main (void) |
| 251 |
{ |
| 252 |
fputs (hw, stdout); |
| 253 |
; |
| 254 |
return 0; |
| 255 |
} |
| 256 |
]]) |
| 257 |
|
| 258 |
AT_CLEANUP |
| 259 |
|
| 260 |
|
| 261 |
## ------------------- ## |
| 262 |
## AC_COMPILE_IFELSE. ## |
| 263 |
## ------------------- ## |
| 264 |
|
| 265 |
AT_SETUP([AC_COMPILE_IFELSE]) |
| 266 |
AT_KEYWORDS([AC_LANG_DEFINES_PROVIDED]) |
| 267 |
|
| 268 |
AT_DATA([configure.ac], |
| 269 |
[[AC_INIT |
| 270 |
AC_COMPILE_IFELSE([int main (void) { return 0; }], [], |
| 271 |
[AC_MSG_ERROR([compiling trivial program failed])]) |
| 272 |
AC_OUTPUT |
| 273 |
]]) |
| 274 |
|
| 275 |
AT_CHECK_AUTOCONF([], [], [], [stderr]) |
| 276 |
AT_CHECK([grep 'no AC_LANG_SOURCE call detected in body' stderr], [], [ignore]) |
| 277 |
AT_CHECK_AUTOCONF([-W no-syntax]) |
| 278 |
AT_CHECK_CONFIGURE([-q]) |
| 279 |
|
| 280 |
AT_DATA([configure.ac], |
| 281 |
[[AC_INIT |
| 282 |
AC_COMPILE_IFELSE([AC_LANG_DEFINES_PROVIDED()int main (void) { return 0; }], [], |
| 283 |
[AC_MSG_ERROR([compiling trivial program failed])]) |
| 284 |
AC_OUTPUT |
| 285 |
]]) |
| 286 |
|
| 287 |
AT_CHECK_AUTOCONF |
| 288 |
AT_CHECK_CONFIGURE([-q]) |
| 289 |
|
| 290 |
AT_DATA([configure.ac], |
| 291 |
[[AC_INIT |
| 292 |
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [return 0])], |
| 293 |
[], |
| 294 |
[AC_MSG_ERROR([compiling 'return 0' failed])]) |
| 295 |
|
| 296 |
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [return 2])], |
| 297 |
[], |
| 298 |
[AC_MSG_ERROR([compiling 'return 2' failed])]) |
| 299 |
AC_OUTPUT |
| 300 |
]]) |
| 301 |
|
| 302 |
AT_CHECK_AUTOCONF |
| 303 |
AT_CHECK_CONFIGURE([-q]) |
| 304 |
|
| 305 |
AT_CLEANUP |
| 306 |
|
| 307 |
## --------------- ## |
| 308 |
## AC_RUN_IFELSE. ## |
| 309 |
## --------------- ## |
| 310 |
|
| 311 |
AT_SETUP([AC_RUN_IFELSE]) |
| 312 |
AT_KEYWORDS([AC_TRY_RUN]) |
| 313 |
|
| 314 |
AT_DATA([configure.ac], |
| 315 |
[[AC_INIT |
| 316 |
|
| 317 |
AC_RUN_IFELSE([AC_LANG_PROGRAM([], [return 0])], |
| 318 |
[], |
| 319 |
[AC_MSG_ERROR([saw 'return 0' as a failure])]) |
| 320 |
|
| 321 |
AC_RUN_IFELSE([AC_LANG_PROGRAM([], [return 2])], |
| 322 |
[AC_MSG_ERROR([saw 'return 2' as a success])], |
| 323 |
[estatus=$? |
| 324 |
test $estatus != 2 && |
| 325 |
AC_MSG_ERROR([did not get 2 as exit status: $estatus])]) |
| 326 |
|
| 327 |
# The old stinky one. |
| 328 |
AC_TRY_RUN([int main (void) { return 3; }], |
| 329 |
[AC_MSG_ERROR([saw 'return 3' as a success])], |
| 330 |
[estatus=$? |
| 331 |
test $estatus != 3 && |
| 332 |
AC_MSG_ERROR([did not get 3 as exit status: $estatus])]) |
| 333 |
|
| 334 |
AC_OUTPUT |
| 335 |
]]) |
| 336 |
|
| 337 |
AT_CHECK_AUTOCONF([], 0, [], |
| 338 |
[[configure.ac:14: warning: The macro 'AC_TRY_RUN' is obsolete. |
| 339 |
configure.ac:14: You should run autoupdate. |
| 340 |
general.m4: AC_TRY_RUN is expanded from... |
| 341 |
configure.ac:14: the top level |
| 342 |
]]) |
| 343 |
AT_CHECK_CONFIGURE([-q]) |
| 344 |
|
| 345 |
AT_CLEANUP |
| 346 |
|
| 347 |
## -------------------------- ## |
| 348 |
## Order of 'rm' and actions. ## |
| 349 |
## -------------------------- ## |
| 350 |
|
| 351 |
AT_SETUP([Order of user actions and cleanup]) |
| 352 |
AT_DATA([configure.ac], |
| 353 |
[[AC_INIT |
| 354 |
AC_PROG_CC |
| 355 |
|
| 356 |
AC_PREPROC_IFELSE([AC_LANG_PROGRAM([int grepme;], [])], |
| 357 |
[{ test -f conftest.err && grep grepme conftest.i; } || AS_EXIT([1])], |
| 358 |
[AS_EXIT([1])]) |
| 359 |
AC_PREPROC_IFELSE([AC_LANG_PROGRAM([#define 12 34 /*], [])], |
| 360 |
[AS_EXIT([1])], |
| 361 |
[test -f conftest.err || AS_EXIT([1])]) |
| 362 |
|
| 363 |
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([int ok;], [])], |
| 364 |
[test -f conftest.$ac_objext || AS_EXIT([1])], |
| 365 |
[AS_EXIT([1])]) |
| 366 |
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([int bad bad;], [])], |
| 367 |
[AS_EXIT([1])], |
| 368 |
[test -f conftest.err || AS_EXIT([1])]) |
| 369 |
|
| 370 |
AC_LINK_IFELSE([AC_LANG_PROGRAM([int ok;], [])], |
| 371 |
[test -f conftest$ac_exeext || AS_EXIT([1])], |
| 372 |
[AS_EXIT([1])]) |
| 373 |
AC_LINK_IFELSE([AC_LANG_PROGRAM([int bad bad;], [])], |
| 374 |
[AS_EXIT([1])], |
| 375 |
[test -f conftest.err || AS_EXIT([1])]) |
| 376 |
|
| 377 |
AC_RUN_IFELSE([AC_LANG_PROGRAM([int ok;], [])], |
| 378 |
[./conftest$ac_exeext || AS_EXIT([1])], |
| 379 |
[AS_EXIT([1])]) |
| 380 |
|
| 381 |
d@&t@nl conftest.err not generated by AC_RUN_IFELSE? |
| 382 |
AC_RUN_IFELSE([AC_LANG_PROGRAM([int bad bad;], [])], |
| 383 |
[AS_EXIT([1])], |
| 384 |
[]) |
| 385 |
|
| 386 |
AC_OUTPUT |
| 387 |
]]) |
| 388 |
|
| 389 |
AT_CHECK_AUTOCONF |
| 390 |
AT_CHECK_CONFIGURE([-q]) |
| 391 |
|
| 392 |
AT_CLEANUP |
| 393 |
|
| 394 |
|
| 395 |
## ------------------ ## |
| 396 |
## AC_TRY_LINK_FUNC. ## |
| 397 |
## ------------------ ## |
| 398 |
|
| 399 |
AT_CHECK_MACRO([AC_TRY_LINK_FUNC], |
| 400 |
[AC_TRY_LINK_FUNC(printf,, |
| 401 |
[AC_MSG_ERROR([cannot find 'printf'])]) |
| 402 |
AC_TRY_LINK_FUNC(Be_doomed_if_your_libc_has_a_function_named_like_this, |
| 403 |
[AC_MSG_ERROR([found a nonexistent function])])]) |
| 404 |
|
| 405 |
## -------------------- ## |
| 406 |
## Multiple languages. ## |
| 407 |
## -------------------- ## |
| 408 |
|
| 409 |
AT_SETUP([Multiple languages]) |
| 410 |
|
| 411 |
# This test should be skipped if the C compiler is a C++ compiler. |
| 412 |
AT_DATA([configure.ac], |
| 413 |
[[AC_INIT |
| 414 |
|
| 415 |
AC_PROG_CC |
| 416 |
AC_COMPILE_IFELSE([ |
| 417 |
AC_LANG_PROGRAM([[ |
| 418 |
#ifdef __cplusplus |
| 419 |
choke me |
| 420 |
#endif |
| 421 |
]])], [], AS_EXIT([77])) |
| 422 |
|
| 423 |
AC_OUTPUT |
| 424 |
]]) |
| 425 |
|
| 426 |
AT_CHECK_AUTOCONF |
| 427 |
AT_CHECK_CONFIGURE |
| 428 |
|
| 429 |
# This test should be skipped on systems without a C++ compiler. |
| 430 |
AT_DATA([configure.ac], |
| 431 |
[[AC_INIT |
| 432 |
|
| 433 |
AC_PROG_CXX |
| 434 |
AC_LANG_PUSH([C++]) |
| 435 |
AC_COMPILE_IFELSE([ |
| 436 |
AC_LANG_PROGRAM([[ |
| 437 |
#ifndef __cplusplus |
| 438 |
choke me |
| 439 |
#endif |
| 440 |
]])], [], AS_EXIT([77])) |
| 441 |
AC_LANG_POP([C++]) |
| 442 |
|
| 443 |
AC_OUTPUT |
| 444 |
]]) |
| 445 |
|
| 446 |
AT_CHECK_AUTOCONF |
| 447 |
AT_CHECK_CONFIGURE |
| 448 |
|
| 449 |
AT_DATA([configure.ac], |
| 450 |
[[AC_INIT |
| 451 |
|
| 452 |
AC_PROG_CC |
| 453 |
AC_PROG_CXX |
| 454 |
|
| 455 |
AC_LANG_PUSH([C]) |
| 456 |
AC_MSG_CHECKING([a simple C program that is not valid C++]) |
| 457 |
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([enum a { A, B, C }; |
| 458 |
enum a f(enum a in) { return in++; }], [])], |
| 459 |
[AC_MSG_RESULT([ok])], |
| 460 |
[AC_MSG_RESULT([failed]) |
| 461 |
AC_MSG_ERROR([could not compile test program])]) |
| 462 |
AC_LANG_POP([C]) |
| 463 |
|
| 464 |
AC_LANG_PUSH([C++]) |
| 465 |
AC_MSG_CHECKING([a simple C++ program that is not valid C]) |
| 466 |
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([class A {};], [])], |
| 467 |
[AC_MSG_RESULT([ok])], |
| 468 |
[AC_MSG_RESULT([failed]) |
| 469 |
AC_MSG_ERROR([could not compile test program])]) |
| 470 |
|
| 471 |
AC_CHECK_HEADER([cstring]) |
| 472 |
AC_LANG_POP([C++]) |
| 473 |
|
| 474 |
AC_OUTPUT |
| 475 |
]]) |
| 476 |
|
| 477 |
AT_CHECK_AUTOCONF |
| 478 |
AT_CHECK_CONFIGURE([-q]) |
| 479 |
|
| 480 |
AT_CLEANUP |