3 AT_BANNER([Low level compiling/preprocessing macros.])
5 # Copyright (C) 2000-2001, 2003, 2005-2014 Free Software Foundation,
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 <http://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.
27 ## ------------------------------------- ##
28 ## AC_LANG, AC_LANG_PUSH & AC_LANG_POP. ##
29 ## ------------------------------------- ##
31 AT_SETUP([[AC_LANG, AC_LANG_PUSH & AC_LANG_POP]])
33 AT_DATA([configure.ac],
44 AC_LANG_PUSH([Erlang])
46 AC_LANG_PUSH([Fortran 77])
48 AC_LANG_POP([Fortran 77])
61 AT_CHECK([sed -n 's/^ac_ext=//p' configure], 0,
79 ## ---------------------- ##
80 ## AC_REQUIRE & AC_LANG. ##
81 ## ---------------------- ##
83 AT_SETUP([AC_REQUIRE & AC_LANG])
85 AT_DATA([configure.ac],
86 [[AC_DEFUN([AC_F77_1],
87 [AC_LANG_PUSH([Fortran 77])
88 if test $ac_ext != f; then
89 AC_MSG_ERROR([F77_1: current shell language is $ac_ext, expected Fortran])
96 [AC_LANG_PUSH([Fortran 77])
97 AC_REQUIRE([AC_F77_1])
98 if test $ac_ext != f; then
99 AC_MSG_ERROR([F77_2: current shell language is $ac_ext, expected Fortran])
115 ## ---------------- ##
116 ## AC_LANG_SOURCE. ##
117 ## ---------------- ##
119 AT_SETUP([AC_LANG_SOURCE])
121 AT_DATA([configure.ac],
122 [[AC_INIT([pkg], [1.0])
124 AC_COMPILE_IFELSE([AC_LANG_SOURCE([[#ifndef PACKAGE_NAME
131 ]], [], [AC_MSG_FAILURE([confdefs not included])])])
140 ## --------------------- ##
141 ## AC_LANG_SOURCE(C++). ##
142 ## --------------------- ##
144 AT_SETUP([AC_LANG_SOURCE(C++)])
146 AT_DATA([configure.ac],
147 [[AC_INIT([pkg], [1.0])
150 AC_COMPILE_IFELSE([AC_LANG_SOURCE([[#ifndef PACKAGE_NAME
157 ]], [], [AC_MSG_FAILURE([confdefs not included])])])
166 ## ------------------------ ##
167 ## AC_LANG_SOURCE example. ##
168 ## ------------------------ ##
170 AT_SETUP([AC_LANG_SOURCE example])
172 # Set CONFIG_SITE to a nonexistent file, so that there are
173 # no worries about configure output caused by sourcing a config.site.
174 CONFIG_SITE=no-such-file
177 AT_DATA([configure.ac],
178 [[# Taken from autoconf.texi:Generating Sources.
179 # The only change is to not fail if gcc doesn't work.
180 AC_INIT([Hello], [1.0], [bug-hello@example.org], [],
181 [http://www.example.org/])
182 AC_DEFINE([HELLO_WORLD], ["Hello, World\n"],
186 [AC_LANG_SOURCE([[const char hw[] = "Hello, World\n";]])])
187 gcc -E -dD conftest.c || AS_EXIT([77])
191 AT_CHECK_CONFIGURE([], [], [stdout])
192 # Taken from autoconf.texi:Generating Sources.
193 # Note that the output may contain more defines and lines matching
195 # so delete everything before the interesting output.
196 AT_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"
205 const char hw[] = "Hello, World\n";
211 ## ------------------------- ##
212 ## AC_LANG_PROGRAM example. ##
213 ## ------------------------- ##
215 AT_SETUP([AC_LANG_PROGRAM example])
217 # Set CONFIG_SITE to a nonexistent file, so that there are
218 # no worries about configure output caused by sourcing a config.site.
219 CONFIG_SITE=no-such-file
222 AT_DATA([configure.ac],
223 [[# Taken from autoconf.texi:Generating Sources.
224 # The only change is to not fail if gcc doesn't work.
225 AC_INIT([Hello], [1.0], [bug-hello@example.org], [],
226 [http://www.example.org/])
227 AC_DEFINE([HELLO_WORLD], ["Hello, World\n"],
230 [AC_LANG_PROGRAM([[const char hw[] = "Hello, World\n";]],
231 [[fputs (hw, stdout);]])])
232 gcc -E -dD conftest.c || AS_EXIT([77])
236 AT_CHECK_CONFIGURE([], [], [stdout])
237 # Taken from autoconf.texi:Generating Sources.
238 # Note that the output may contain more defines and lines matching
240 # so delete everything before the interesting output.
241 AT_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"
250 const char hw[] = "Hello, World\n";
263 ## ------------------- ##
264 ## AC_COMPILE_IFELSE. ##
265 ## ------------------- ##
267 AT_SETUP([AC_COMPILE_IFELSE])
268 AT_KEYWORDS([AC_LANG_DEFINES_PROVIDED])
270 AT_DATA([configure.ac],
272 AC_COMPILE_IFELSE([int main (void) { return 0; }], [],
273 [AC_MSG_ERROR([compiling trivial program failed])])
276 AT_CHECK_AUTOCONF([], [], [], [stderr])
277 AT_CHECK([grep 'no AC_LANG_SOURCE call detected in body' stderr], [], [ignore])
278 AT_CHECK_AUTOCONF([-W no-syntax])
279 AT_CHECK_CONFIGURE([-q])
281 AT_DATA([configure.ac],
283 AC_COMPILE_IFELSE([AC_LANG_DEFINES_PROVIDED()int main (void) { return 0; }], [],
284 [AC_MSG_ERROR([compiling trivial program failed])])
288 AT_CHECK_CONFIGURE([-q])
290 AT_DATA([configure.ac],
292 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [return 0])],
294 [AC_MSG_ERROR([compiling `return 0' failed])])
296 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [return 2])],
298 [AC_MSG_ERROR([compiling `return 2' failed])])
302 AT_CHECK_CONFIGURE([-q])
306 ## --------------- ##
308 ## --------------- ##
310 AT_SETUP([AC_RUN_IFELSE])
311 AT_KEYWORDS([AC_TRY_RUN])
313 AT_DATA([configure.ac],
316 AC_RUN_IFELSE([AC_LANG_PROGRAM([], [return 0])],
318 [AC_MSG_ERROR([saw `return 0' as a failure])])
320 AC_RUN_IFELSE([AC_LANG_PROGRAM([], [return 2])],
321 [AC_MSG_ERROR([saw `return 2' as a success])],
323 test $estatus != 2 &&
324 AC_MSG_ERROR([did not get as 2 exit status: $estatus])])
326 # The old stinky one.
327 AC_TRY_RUN([int main (void) { return 3; }],
328 [AC_MSG_ERROR([saw `return 3' as a success])],
330 test $estatus != 3 &&
331 AC_MSG_ERROR([did not get 3 as exit status: $estatus])])
336 AT_CHECK_CONFIGURE([-q])
340 ## -------------------------- ##
341 ## Order of `rm' and actions. ##
342 ## -------------------------- ##
344 AT_SETUP([Order of user actions and cleanup])
345 AT_DATA([configure.ac],
349 AC_PREPROC_IFELSE([AC_LANG_PROGRAM([int grepme;], [])],
350 [{ test -f conftest.err && grep grepme conftest.i; } || AS_EXIT([1])],
352 AC_PREPROC_IFELSE([AC_LANG_PROGRAM([#define 12 34 /*], [])],
354 [test -f conftest.err || AS_EXIT([1])])
356 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([int ok;], [])],
357 [test -f conftest.$ac_objext || AS_EXIT([1])],
359 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([int bad bad;], [])],
361 [test -f conftest.err || AS_EXIT([1])])
363 AC_LINK_IFELSE([AC_LANG_PROGRAM([int ok;], [])],
364 [test -f conftest$ac_exeext || AS_EXIT([1])],
366 AC_LINK_IFELSE([AC_LANG_PROGRAM([int bad bad;], [])],
368 [test -f conftest.err || AS_EXIT([1])])
370 AC_RUN_IFELSE([AC_LANG_PROGRAM([int ok;], [])],
371 [./conftest$ac_exeext || AS_EXIT([1])],
374 d@&t@nl conftest.err not generated by AC_RUN_IFELSE?
375 AC_RUN_IFELSE([AC_LANG_PROGRAM([int bad bad;], [])],
381 AT_CHECK_CONFIGURE([-q])
386 ## ------------------ ##
387 ## AC_TRY_LINK_FUNC. ##
388 ## ------------------ ##
390 AT_CHECK_MACRO([AC_TRY_LINK_FUNC],
391 [AC_TRY_LINK_FUNC(printf,,
392 [AC_MSG_ERROR([cannot find `printf'])])
393 AC_TRY_LINK_FUNC(Be_doomed_if_your_libc_has_a_function_named_like_this,
394 [AC_MSG_ERROR([found a nonexistent function])])])
396 ## -------------------- ##
397 ## Multiple languages. ##
398 ## -------------------- ##
400 AT_SETUP([Multiple languages])
402 # This test should be skipped if the C compiler is a C++ compiler.
403 AT_DATA([configure.ac],
412 ]])], [], AS_EXIT([77]))
418 # This test should be skipped on systems without a C++ compiler.
419 AT_DATA([configure.ac],
429 ]])], [], AS_EXIT([77]))
436 AT_DATA([configure.ac],
443 AC_MSG_CHECKING([a simple C program that is not valid C++])
444 AC_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])])
452 AC_MSG_CHECKING([a simple C++ program that is not valid C])
453 AC_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])])
458 AC_CHECK_HEADER([cstring])
463 AT_CHECK_CONFIGURE([-q])