* lib/autoconf/general.m4 (_AC_INIT_CONFIG_LOG): Close
[autoconf.git] / tests / semantics.at
blob312e6cdad97a8291173d36d465e969d477638ed9
1 #                                                       -*- Autotest -*-
3 AT_BANNER([Semantics.])
5 # Copyright (C) 2000, 2001, 2002, 2004, 2005, 2006 Free Software
6 # Foundation, Inc.
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 2, or (at your option)
11 # 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, write to the Free Software
20 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 # 02110-1301, USA.
24 ## -------------------------------- ##
25 ## Members of the AC_CHECK family.  ##
26 ## -------------------------------- ##
29 # AC_CHECK_LIB
30 # ------------
31 # Well, I can't imagine a system where `cos' is neither in libc, nor
32 # in libm.  Nor can I imagine a lib more likely to exists than libm.
33 # But there are systems without libm, on which we don't want to have
34 # this test fail, so exit successfully if `cos' is in libc.
35 AT_CHECK_MACRO([AC_CHECK_LIB],
36 [AC_TRY_LINK_FUNC(cos,
37                   [AC_MSG_ERROR([`cos' is in `libc'], 77)])
39 AC_CHECK_LIB(m, cos,,
40              [AC_MSG_ERROR([cannot find `cos' in `libm'])])
42 # No kidding, using variables was broken in 2.50 :(
43 ac_sin=sin
44 AC_CHECK_LIB(m, $ac_sin,,
45       [AC_MSG_ERROR([cannot find `\$ac_sin' (= `$ac_sin') in `libm'])])
47 ac_m=m
48 AC_CHECK_LIB($ac_m, acos,,
49       [AC_MSG_ERROR([cannot find `acos' in `\$ac_m' (= `$ac_m')])])
51 ac_asin=asin
52 AC_CHECK_LIB($ac_m, $ac_asin,,
53       [AC_MSG_ERROR([cannot find `\$ac_asin' (= `$ac_asin') in `\$ac_m' (= `$at_m')])])
55 # But if the bug is in the caching mechanism, then be sure we
56 # correctly detect failures.
58 AC_CHECK_LIB(m, cossack,
59              [AC_MSG_ERROR([found `cossack' in `libm'])])
61 # No kidding, using variables was broken in 2.50 :(
62 ac_sinner=sinner
63 AC_CHECK_LIB(m, $ac_sinner,
64       [AC_MSG_ERROR([found `\$ac_sinner' (= `$ac_sinner') in `libm'])])
66 ac_m=m
67 AC_CHECK_LIB($ac_m, acossack,
68       [AC_MSG_ERROR([found `acossack' in `\$ac_m' (= `$ac_m')])])
70 ac_asinner=asinner
71 AC_CHECK_LIB($ac_m, $ac_asinner,
72       [AC_MSG_ERROR([found `\$ac_asinner' (= `$ac_asinner') in `\$ac_m' (= `$at_m')])])
77 # AC_SEARCH_LIBS
78 # --------------
79 AT_CHECK_MACRO([AC_SEARCH_LIBS],
81 AC_SEARCH_LIBS(cos, oser m ust,,
82              [AC_MSG_ERROR([cannot find `cos'])])
84 case "$ac_cv_search_cos" in
85   -loser|-lust) AC_MSG_ERROR([jeez, $ac_cv_search_cos must be a cool library!]) ;;
86 esac
90 # AC_SEARCH_LIBS (none needed)
91 # ----------------------------
92 AT_CHECK_MACRO([AC_SEARCH_LIBS (none needed)],
94 AC_SEARCH_LIBS(printf, oser c ust,,
95              [AC_MSG_ERROR([cannot find `printf'])])
97 case "$ac_cv_search_printf" in
98   -loser|-lust) AC_MSG_ERROR([jeez, $ac_cv_search_printf must be a cool library!]) ;;
99   -lc) AC_MSG_ERROR([huh, you need to give -lc?])
100 esac
104 # AC_CHECK_DECLS
105 # --------------
106 # Check that it performs the correct actions:
107 # Must define NEED_NO_DECL, but not NEED_YES_DECL.
108 AT_CHECK_MACRO([AC_CHECK_DECLS],
109 [[AC_CHECK_DECLS([yes, no],,,
110                  [int yes = 1;])]],
111 [AT_CHECK_DEFINES(
112 [#define HAVE_DECL_NO 0
113 #define HAVE_DECL_YES 1
114 ])])
117 # AC_CHECK_FUNCS
118 # --------------
119 # Check that it performs the correct actions:
120 # Must define HAVE_PRINTF, but not HAVE_AUTOCONF_FTNIRP
121 AT_CHECK_MACRO([AC_CHECK_FUNCS],
122 [AC_CHECK_FUNCS(printf autoconf_ftnirp)],
123 [AT_CHECK_DEFINES(
124 [/* #undef HAVE_AUTOCONF_FTNIRP */
125 #define HAVE_PRINTF 1
126 ])])
129 # AC_REPLACE_FUNCS
130 # ----------------
131 # Check that it performs the correct actions: autoconf_ftnirp.c must
132 # be compiled, and must define HAVE_PRINTF, but not HAVE_AUTOCONF_FTNIRP
133 # FIXME: Maybe check the traces?
134 AT_SETUP([AC_REPLACE_FUNCS])
136 AT_DATA([config.in],
137 [@LIBOBJS@
140 AT_CONFIGURE_AC(
141 [AC_CONFIG_FILES(config.libobjs:config.in)
142 AC_REPLACE_FUNCS(printf autoconf_ftnirp)])
144 AT_CHECK_AUTOCONF([-W obsolete])
145 AT_CHECK_AUTOHEADER
146 AT_CHECK_CONFIGURE
147 AT_CHECK_ENV
148 AT_CHECK_DEFINES(
149 [/* #undef HAVE_AUTOCONF_FTNIRP */
150 #define HAVE_PRINTF 1
153 AT_CHECK([sed 's/  */ /g;s/^ //;s/ $//' config.libobjs], [],
154          [${LIBOBJDIR}autoconf_ftnirp$U.o
157 AT_CLEANUP([config.libobjs])
160 # AC_CHECK_HEADERS
161 # ----------------
162 # Check that it performs the correct actions:
163 # Must define HAVE_STDIO_H, but not HAVE_AUTOCONF_IO_H.
164 AT_CHECK_MACRO([AC_CHECK_HEADERS],
165 [AC_CHECK_HEADERS(stdio.h autoconf_io.h)],
166 [AT_CHECK_DEFINES(
167 [/* #undef HAVE_AUTOCONF_IO_H */
168 #define HAVE_STDIO_H 1
169 ])])
172 # AC_CHECK_HEADERS_OLD
173 # --------------------
174 # Check that it performs the correct actions:
175 # Must not check prerequisites, hence define header2.h
176 AT_SETUP([AC_CHECK_HEADERS_OLD])
178 AT_DATA([header1.h],
179 [typedef int foo;
182 AT_DATA([header2.h],
183 [typedef foo bar;
186 AT_CONFIGURE_AC([AC_CHECK_HEADERS(header2.h, [], [], -)])
188 AT_CHECK_AUTOCONF([-W obsolete])
189 AT_CHECK_AUTOHEADER
190 AT_CHECK_CONFIGURE([CPPFLAGS=-I.])
191 AT_CHECK_ENV
192 AT_CHECK_DEFINES(
193 [#define HAVE_HEADER2_H 1
196 AT_CLEANUP([header1.h header2.h])
199 # AC_CHECK_HEADERS_NEW
200 # --------------------
201 # Check that it performs the correct actions:
202 # Must check prerequisites, hence define header2.h but not header3.h
203 AT_SETUP([AC_CHECK_HEADERS_NEW])
205 AT_DATA([header1.h],
206 [typedef int foo;
209 AT_DATA([header2.h],
210 [typedef foo bar;
213 AT_DATA([header3.h],
214 [typedef bar wow;
217 AT_CONFIGURE_AC(
218 [AC_CHECK_HEADERS(header2.h header3.h, [], [], [[@%:@include "header1.h"]])])
220 AT_CHECK_AUTOCONF([-W obsolete])
221 AT_CHECK_AUTOHEADER
222 AT_CHECK_CONFIGURE([CPPFLAGS=-I.])
223 AT_CHECK_ENV
224 AT_CHECK_DEFINES(
225 [#define HAVE_HEADER2_H 1
226 /* #undef HAVE_HEADER3_H */
229 AT_CLEANUP([header1.h header2.h header3.h])
232 # AC_CHECK_MEMBERS
233 # ----------------
234 # Check that it performs the correct actions.
235 # Must define HAVE_STRUCT_YES_S_YES, but not HAVE_STRUCT_YES_S_NO.
236 AT_CHECK_MACRO([AC_CHECK_MEMBERS],
237 [[AC_CHECK_MEMBERS([struct yes_s.yes, struct yes_s.no],,,
238                    [struct yes_s { int yes ;} ;])]],
239 [AT_CHECK_DEFINES(
240 [/* #undef HAVE_STRUCT_YES_S_NO */
241 #define HAVE_STRUCT_YES_S_YES 1
242 ])])
245 # AC_CHECK_ALIGNOF
246 # ----------------
247 AT_CHECK_MACRO_CROSS([AC_CHECK_ALIGNOF],
248 [[AC_CHECK_ALIGNOF(char)
249 AC_CHECK_ALIGNOF(charchar,
250 [[#include <stddef.h>
251 #include <stdio.h>
252 typedef char charchar[2];]])
253 AC_CHECK_ALIGNOF(charcharchar)
255 [AT_CHECK_DEFINES(
256 [#define ALIGNOF_CHAR 1
257 #define ALIGNOF_CHARCHAR 1
258 #define ALIGNOF_CHARCHARCHAR 0
259 ])])
262 # AC_CHECK_ALIGNOF struct
263 # -----------------------
264 AT_CHECK_MACRO_CROSS([AC_CHECK_ALIGNOF struct],
265 [[AC_CHECK_ALIGNOF([struct { char c; }])
266 AC_CHECK_ALIGNOF([struct nosuchstruct])
268 [AT_CHECK([[grep "#define ALIGNOF_STRUCT___CHAR_C___ [^0]" config.h]],
269          0, ignore)
270 AT_CHECK([[grep "#define ALIGNOF_STRUCT_NOSUCHSTRUCT 0" config.h]],
271          0, ignore)
274 # AC_CHECK_SIZEOF
275 # ---------------
276 AT_CHECK_MACRO_CROSS([AC_CHECK_SIZEOF],
277 [[AC_CHECK_SIZEOF(char)
278 AC_CHECK_SIZEOF(charchar,,
279 [[#include <stdio.h>
280 typedef char charchar[2];]])
281 AC_CHECK_SIZEOF(charcharchar)
283 [AT_CHECK_DEFINES(
284 [#define SIZEOF_CHAR 1
285 #define SIZEOF_CHARCHAR 2
286 #define SIZEOF_CHARCHARCHAR 0
287 ])])
290 # AC_CHECK_SIZEOF struct
291 # ----------------------
292 AT_CHECK_MACRO_CROSS([AC_CHECK_SIZEOF struct],
293 [[AC_C_CONST
294 AC_CHECK_SIZEOF([struct { char c; int x; }])
295 AC_CHECK_SIZEOF([const struct { const char *p; int x; }])
296 AC_CHECK_SIZEOF([struct nosuchstruct])
298 [AT_CHECK([[grep "#define SIZEOF_STRUCT___CHAR_C__INT_X___ [^0]" config.h]],
299          0, ignore)
300 AT_CHECK([[grep "#define SIZEOF_CONST_STRUCT___CONST_CHAR_PP__INT_X___ [^0]" config.h]],
301          0, ignore)
302 AT_CHECK([[grep "#define SIZEOF_STRUCT_NOSUCHSTRUCT 0" config.h]],
303          0, ignore)
307 # AC_CHECK_TYPES
308 # --------------
309 # Check that it performs the correct actions.
310 # Must define HAVE_STRUCT_YES_S, HAVE_INT, but not HAVE_STRUCT_NO_S.
311 # `int' and `struct yes_s' are both checked to test both the compiler
312 # builtin types, and defined types.
313 AT_CHECK_MACRO([AC_CHECK_TYPES],
314 [[AC_CHECK_TYPES([int, struct yes_s, struct no_s],,,
315                  [struct yes_s { int yes ;} ;])]],
316 [AT_CHECK_DEFINES(
317 [#define HAVE_INT 1
318 /* #undef HAVE_STRUCT_NO_S */
319 #define HAVE_STRUCT_YES_S 1
320 ])])
323 # AC_CHECK_TYPES
324 # --------------
325 # Check that we properly dispatch properly to the old implementation
326 # or to the new one.
327 AT_SETUP([AC_CHECK_TYPES: backward compatibility])
329 AT_DATA([configure.ac],
330 [[AC_INIT
331 define([_AC_CHECK_TYPE_NEW], [NEW])
332 define([_AC_CHECK_TYPE_OLD], [OLD])
333 #(cut-from-here
334 AC_CHECK_TYPE(ptrdiff_t)
335 AC_CHECK_TYPE(ptrdiff_t, int)
336 AC_CHECK_TYPE(quad, long long int)
337 AC_CHECK_TYPE(table_42, [int[42]])
338 # Nice machine!
339 AC_CHECK_TYPE(uint8_t, uint65536_t)
340 AC_CHECK_TYPE(a,b,c,d)
341 #to-here)
342 AC_OUTPUT
345 AT_CHECK_AUTOCONF
346 AT_CHECK([[sed -e '/^#(cut-from-here/,/^#to-here)/!d' -e '/^#/d' configure]],
347          0,
348          [NEW
356 AT_CLEANUP
359 # AC_CHECK_FILES
360 # --------------
361 # FIXME: To really test HAVE_AC_EXISTS2 and HAVE_AC_MISSING2 we need to
362 # open AH_TEMPLATE to `configure.ac', which is not yet the case.
363 AT_CHECK_MACRO([AC_CHECK_FILES],
364 [touch at-exists1 at-exists2
365 ac_exists2=at-exists2
366 ac_missing2=at-missing2
367 AC_CHECK_FILES(at-exists1 at-missing1 $ac_exists2 $ac_missing2)
368 rm at-exists1 at-exists2],
369 [AT_CHECK_DEFINES(
370 [#define HAVE_AT_EXISTS1 1
371 /* #undef HAVE_AT_MISSING1 */
372 ])])
376 ## ------------------------------ ##
377 ## AC_CHECK_PROG & AC_PATH_PROG.  ##
378 ## ------------------------------ ##
381 # AT_CHECK_PROGS_PREPARE
382 # ----------------------
383 # Create a sub directory `path' with 6 subdirs which all 7 contain
384 # an executable `tool'. `6' contains a `better' tool.
385 m4_define([AT_CHECK_PROGS_PREPARE],
386 [mkdir path
388 cat >path/tool <<\EOF
389 #! /bin/sh
390 exit 0
392 chmod +x path/tool
394 for i in 1 2 3 4 5 6
396   mkdir path/$i
397   cp path/tool path/$i
398 done
399 cp path/tool path/6/better])
402 # -------------------------------- #
403 # AC_CHECK_PROG & AC_CHECK_PROGS.  #
404 # -------------------------------- #
406 AT_SETUP([AC_CHECK_PROG & AC_CHECK_PROGS])
408 AT_CHECK_PROGS_PREPARE
410 AT_DATA([configure.ac],
411 [[AC_INIT
412 pwd=`pwd`
413 p="1${PATH_SEPARATOR}2${PATH_SEPARATOR}3${PATH_SEPARATOR}4${PATH_SEPARATOR}5${PATH_SEPARATOR}6"
414 path=`echo $p | sed -e 's,\([[0-9]]\),'"$pwd"'/path/\1,g'`
415 fail=false
417 AC_CHECK_PROG(TOOL1, tool, found, not-found, $path)
418 test "$TOOL1" = found || fail=:
420 # Yes, the semantics of this macro is weird.
421 AC_CHECK_PROG(TOOL2, tool,, not-found, $path)
422 test "$TOOL2" = not-found || fail=:
424 AC_CHECK_PROG(TOOL3, tool, tool, not-found, $path, $pwd/path/1/tool)
425 test "$TOOL3" = "$pwd/path/2/tool" || fail=:
427 AC_CHECK_PROG(TOOL4, better, better, not-found, $path, $pwd/path/1/tool)
428 test "$TOOL4" = better || fail=:
430 # When a tool is not found, and no value is given for not-found,
431 # the variable is left empty.
432 AC_CHECK_PROGS(TOOL5, missing,, $path)
433 test -z "$TOOL5" || fail=:
435 AC_CHECK_PROGS(TOOL6, missing tool better,, $path)
436 test "$TOOL6" = tool || fail=:
438 # No AC-OUTPUT, we don't need config.status.
439 $fail &&
440   AC_MSG_ERROR([[CHECK_PROG failed]])
441 AS_EXIT(0)
444 AT_CHECK_AUTOCONF
445 AT_CHECK_CONFIGURE
447 AT_CLEANUP(path)
451 ## ---------------- ##
452 ## AC_C_BIGENDIAN.  ##
453 ## ---------------- ##
455 AT_SETUP([AC_C_BIGENDIAN])
456 AT_KEYWORDS([cross])
458 # Make sure that AC_C_BIGENDIAN behave the same whether we are
459 # cross-compiling or not.
461 _AT_CHECK_AC_MACRO(
462   [[AC_C_BIGENDIAN([ac_endian=big],[ac_endian=little],[ac_endian=unknown])
463    echo $ac_endian > at-endian
466 rm -f config.hin  # So that next run of autoheader is quiet.
467 _AT_CHECK_AC_MACRO(
468   [[# Force cross compiling.
469    cross_compiling=yes
470    ac_tool_warned=yes
471    AC_C_BIGENDIAN([ac_endian=big],[ac_endian=little],[ac_endian=unknown])
472    ac_prevendian=`cat at-endian`
473    # Check that we have found the same result as in the previous run
474    # or unknown (because the cross-compiling check is allowed to fail;
475    # although it might be interesting to suppress this comparison, just
476    # to know on which system it fails if it ever does).
477    if test $ac_endian != $ac_prevendian && test $ac_endian != unknown; then
478      AC_MSG_ERROR([unexpected endianness: first run found '$ac_prevendian' but second run found '$ac_endian'])
479    fi
482 # Make sure AC_C_BIGENDIAN with no argument will define WORDS_BIGENDIAN
483 AT_CONFIGURE_AC([[AC_C_BIGENDIAN]])
484 # --force is necessary, the computer might be too fast.
485 AT_CHECK_AUTOHEADER([--force])
486 AT_CHECK([grep WORDS_BIGENDIAN config.hin], [], [ignore])
488 AT_CLEANUP(at-endian)
491 # ------------------------------ #
492 # AC_PATH_PROG & AC_PATH_PROGS.  #
493 # ------------------------------ #
495 AT_SETUP([AC_PATH_PROG & AC_PATH_PROGS])
497 AT_CHECK_PROGS_PREPARE
499 AT_DATA([configure.ac],
500 [[AC_INIT
501 pwd=`pwd`
502 p="1${PATH_SEPARATOR}2${PATH_SEPARATOR}3${PATH_SEPARATOR}4${PATH_SEPARATOR}5${PATH_SEPARATOR}6"
503 path=`echo $p | sed -e 's,\([[0-9]]\),'"$pwd"'/path/\1,g'`
504 fail=false
506 AC_PATH_PROG(TOOL1, tool, not-found, $path)
507 test "$TOOL1" = "$pwd/path/1/tool" || fail=:
509 AC_PATH_PROG(TOOL2, better, not-found, $path)
510 test "$TOOL2" = "$pwd/path/6/better" || fail=:
512 # When a tool is not found, and no value is given for not-found,
513 # the variable is left empty.
514 AC_PATH_PROGS(TOOL3, missing,, $path)
515 test -z "$TOOL3" || fail=:
517 AC_PATH_PROGS(TOOL4, missing tool better,, $path)
518 test "$TOOL4" = "$pwd/path/1/tool" || fail=:
520 # No AC-OUTPUT, we don't need config.status.
521 $fail &&
522   AC_MSG_ERROR([[PATH_PROG failed]])
523 AS_EXIT(0)
526 AT_CHECK_AUTOCONF
527 AT_CHECK_CONFIGURE
529 AT_CLEANUP(path)
534 ## -------------- ##
535 ## AC_PATH_XTRA.  ##
536 ## -------------- ##
539 AT_SETUP([AC_PATH_XTRA])
541 _AT_CHECK_AC_MACRO([AC_PATH_XTRA])
543 # Check X_DISPLAY_MISSING.
544 AT_CHECK_CONFIGURE([--without-x])
545 AT_CHECK_DEFINES(
546 [#define X_DISPLAY_MISSING 1
549 AT_CLEANUP
552 ## ------------------------------- ##
553 ## Obsolete non-updatable macros.  ##
554 ## ------------------------------- ##
557 AT_CHECK_MACRO([AC_SYS_RESTARTABLE_SYSCALLS], , ,[-W no-obsolete])
558 AT_CHECK_MACRO([AC_FUNC_WAIT3], , ,[-W no-obsolete])