3 AT_BANNER([Low level compiling/preprocessing macros.])
5 # Copyright (C) 2000-2001, 2003, 2005-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.
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])
62 AT_CHECK([sed -n 's/^ac_ext=//p' configure], 0,
80 ## ---------------------- ##
81 ## AC_REQUIRE & AC_LANG. ##
82 ## ---------------------- ##
84 AT_SETUP([AC_REQUIRE & AC_LANG])
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])
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])
110 AT_CHECK_AUTOCONF([], [0], [],
111 [[trailer.m4: warning: AC_OUTPUT was never used
119 ## ---------------- ##
120 ## AC_LANG_SOURCE. ##
121 ## ---------------- ##
123 AT_SETUP([AC_LANG_SOURCE])
125 AT_DATA([configure.ac],
126 [[AC_INIT([pkg], [1.0])
128 AC_COMPILE_IFELSE([AC_LANG_SOURCE([[#ifndef PACKAGE_NAME
135 ]], [], [AC_MSG_FAILURE([confdefs not included])])])
145 ## --------------------- ##
146 ## AC_LANG_SOURCE(C++). ##
147 ## --------------------- ##
149 AT_SETUP([AC_LANG_SOURCE(C++)])
151 AT_DATA([configure.ac],
152 [[AC_INIT([pkg], [1.0])
155 AC_COMPILE_IFELSE([AC_LANG_SOURCE([[#ifndef PACKAGE_NAME
162 ]], [], [AC_MSG_FAILURE([confdefs not included])])])
172 ## ------------------------ ##
173 ## AC_LANG_SOURCE example. ##
174 ## ------------------------ ##
176 AT_SETUP([AC_LANG_SOURCE example])
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], [bug-hello@example.org], [],
182 [https://www.example.org/])
183 AC_DEFINE([HELLO_WORLD], ["Hello, World\n"],
187 [AC_LANG_SOURCE([[const char hw[] = "Hello, World\n";]])])
188 gcc -E -dD conftest.c || AS_EXIT([77])
193 AT_CHECK_CONFIGURE([], [], [stdout])
194 # Taken from autoconf.texi:Generating Sources.
195 # Note that the output may contain more defines and lines matching
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 "bug-hello@example.org"
204 #define PACKAGE_URL "https://www.example.org/"
205 #define HELLO_WORLD "Hello, World\n"
207 const char hw[] = "Hello, World\n";
213 ## ------------------------- ##
214 ## AC_LANG_PROGRAM example. ##
215 ## ------------------------- ##
217 AT_SETUP([AC_LANG_PROGRAM example])
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], [bug-hello@example.org], [],
223 [https://www.example.org/])
224 AC_DEFINE([HELLO_WORLD], ["Hello, World\n"],
227 [AC_LANG_PROGRAM([[const char hw[] = "Hello, World\n";]],
228 [[fputs (hw, stdout);]])])
229 gcc -E -dD conftest.c || AS_EXIT([77])
234 AT_CHECK_CONFIGURE([], [], [stdout])
235 # Taken from autoconf.texi:Generating Sources.
236 # Note that the output may contain more defines and lines matching
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 "bug-hello@example.org"
245 #define PACKAGE_URL "https://www.example.org/"
246 #define HELLO_WORLD "Hello, World\n"
248 const char hw[] = "Hello, World\n";
261 ## ------------------- ##
262 ## AC_COMPILE_IFELSE. ##
263 ## ------------------- ##
265 AT_SETUP([AC_COMPILE_IFELSE])
266 AT_KEYWORDS([AC_LANG_DEFINES_PROVIDED])
268 AT_DATA([configure.ac],
270 AC_COMPILE_IFELSE([int main (void) { return 0; }], [],
271 [AC_MSG_ERROR([compiling trivial program failed])])
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])
280 AT_DATA([configure.ac],
282 AC_COMPILE_IFELSE([AC_LANG_DEFINES_PROVIDED()int main (void) { return 0; }], [],
283 [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])])
303 AT_CHECK_CONFIGURE([-q])
307 ## --------------- ##
309 ## --------------- ##
311 AT_SETUP([AC_RUN_IFELSE])
312 AT_KEYWORDS([AC_TRY_RUN])
314 AT_DATA([configure.ac],
317 AC_RUN_IFELSE([AC_LANG_PROGRAM([], [return 0])],
319 [AC_MSG_ERROR([saw 'return 0' as a failure])])
321 AC_RUN_IFELSE([AC_LANG_PROGRAM([], [return 2])],
322 [AC_MSG_ERROR([saw 'return 2' as a success])],
324 test $estatus != 2 &&
325 AC_MSG_ERROR([did not get 2 as exit status: $estatus])])
327 # The old stinky one.
328 AC_TRY_RUN([int main (void) { return 3; }],
329 [AC_MSG_ERROR([saw 'return 3' as a success])],
331 test $estatus != 3 &&
332 AC_MSG_ERROR([did not get 3 as exit status: $estatus])])
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
343 AT_CHECK_CONFIGURE([-q])
347 ## -------------------------- ##
348 ## Order of 'rm' and actions. ##
349 ## -------------------------- ##
351 AT_SETUP([Order of user actions and cleanup])
352 AT_DATA([configure.ac],
356 AC_PREPROC_IFELSE([AC_LANG_PROGRAM([int grepme;], [])],
357 [{ test -f conftest.err && grep grepme conftest.i; } || AS_EXIT([1])],
359 AC_PREPROC_IFELSE([AC_LANG_PROGRAM([#define 12 34 /*], [])],
361 [test -f conftest.err || AS_EXIT([1])])
363 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([int ok;], [])],
364 [test -f conftest.$ac_objext || AS_EXIT([1])],
366 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([int bad bad;], [])],
368 [test -f conftest.err || AS_EXIT([1])])
370 AC_LINK_IFELSE([AC_LANG_PROGRAM([int ok;], [])],
371 [test -f conftest$ac_exeext || AS_EXIT([1])],
373 AC_LINK_IFELSE([AC_LANG_PROGRAM([int bad bad;], [])],
375 [test -f conftest.err || AS_EXIT([1])])
377 AC_RUN_IFELSE([AC_LANG_PROGRAM([int ok;], [])],
378 [./conftest$ac_exeext || AS_EXIT([1])],
381 d@&t@nl conftest.err not generated by AC_RUN_IFELSE?
382 AC_RUN_IFELSE([AC_LANG_PROGRAM([int bad bad;], [])],
390 AT_CHECK_CONFIGURE([-q])
395 ## ------------------ ##
396 ## AC_TRY_LINK_FUNC. ##
397 ## ------------------ ##
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])])])
405 ## -------------------- ##
406 ## Multiple languages. ##
407 ## -------------------- ##
409 AT_SETUP([Multiple languages])
411 # This test should be skipped if the C compiler is a C++ compiler.
412 AT_DATA([configure.ac],
421 ]])], [], AS_EXIT([77]))
429 # This test should be skipped on systems without a C++ compiler.
430 AT_DATA([configure.ac],
440 ]])], [], AS_EXIT([77]))
449 AT_DATA([configure.ac],
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])])
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])])
471 AC_CHECK_HEADER([cstring])
478 AT_CHECK_CONFIGURE([-q])