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