typos in the manual
[autoconf.git] / tests / semantics.at
blobb71f74b180a8d9660cd88335aebbb74fea7d7e18
1 #                                                       -*- Autotest -*-
3 AT_BANNER([Semantics.])
5 # Copyright (C) 2000, 2001, 2002, 2004, 2005 Free Software Foundation, Inc.
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2, or (at your option)
10 # any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
20 # 02111-1307, USA.
23 ## -------------------------------- ##
24 ## Members of the AC_CHECK family.  ##
25 ## -------------------------------- ##
28 # AC_CHECK_LIB
29 # ------------
30 # Well, I can't imagine a system where `cos' is neither in libc, nor
31 # in libm.  Nor can I imagine a lib more likely to exists than libm.
32 # But there are systems without libm, on which we don't want to have
33 # this test fail, so exit successfully if `cos' is in libc.
34 AT_CHECK_MACRO([AC_CHECK_LIB],
35 [AC_TRY_LINK_FUNC(cos,
36                   [AC_MSG_ERROR([`cos' is in `libc'], 77)])
38 AC_CHECK_LIB(m, cos,,
39              [AC_MSG_ERROR([cannot find `cos' in `libm'])])
41 # No kidding, using variables was broken in 2.50 :(
42 ac_sin=sin
43 AC_CHECK_LIB(m, $ac_sin,,
44       [AC_MSG_ERROR([cannot find `\$ac_sin' (= `$ac_sin') in `libm'])])
46 ac_m=m
47 AC_CHECK_LIB($ac_m, acos,,
48       [AC_MSG_ERROR([cannot find `acos' in `\$ac_m' (= `$ac_m')])])
50 ac_asin=asin
51 AC_CHECK_LIB($ac_m, $ac_asin,,
52       [AC_MSG_ERROR([cannot find `\$ac_asin' (= `$ac_asin') in `\$ac_m' (= `$at_m')])])
54 # But if the bug is in the caching mechanism, then be sure we
55 # correctly detect failures.
57 AC_CHECK_LIB(m, cossack,
58              [AC_MSG_ERROR([found `cossack' in `libm'])])
60 # No kidding, using variables was broken in 2.50 :(
61 ac_sinner=sinner
62 AC_CHECK_LIB(m, $ac_sinner,
63       [AC_MSG_ERROR([found `\$ac_sinner' (= `$ac_sinner') in `libm'])])
65 ac_m=m
66 AC_CHECK_LIB($ac_m, acossack,
67       [AC_MSG_ERROR([found `acossack' in `\$ac_m' (= `$ac_m')])])
69 ac_asinner=asinner
70 AC_CHECK_LIB($ac_m, $ac_asinner,
71       [AC_MSG_ERROR([found `\$ac_asinner' (= `$ac_asinner') in `\$ac_m' (= `$at_m')])])
76 # AC_SEARCH_LIBS
77 # --------------
78 AT_CHECK_MACRO([AC_SEARCH_LIBS],
80 AC_SEARCH_LIBS(cos, oser m ust,,
81              [AC_MSG_ERROR([cannot find `cos'])])
83 case "$ac_cv_search_cos" in
84   -loser|-lust) AC_MSG_ERROR([jeez, $ac_cv_search_cos must be a cool library!]) ;;
85 esac
87 AC_SEARCH_LIBS(printf, oser c ust,,
88              [AC_MSG_ERROR([cannot find `printf'])])
90 case "$ac_cv_search_printf" in
91   -loser|-lust) AC_MSG_ERROR([jeez, $ac_cv_search_printf must be a cool library!]) ;;
92   -lc) AC_MSG_ERROR([huh, you need to give -lc?])
93 esac
98 # AC_CHECK_DECLS
99 # --------------
100 # Check that it performs the correct actions:
101 # Must define NEED_NO_DECL, but not NEED_YES_DECL.
102 AT_CHECK_MACRO([AC_CHECK_DECLS],
103 [[AC_CHECK_DECLS([yes, no],,,
104                  [int yes = 1;])]],
105 [AT_CHECK_DEFINES(
106 [#define HAVE_DECL_NO 0
107 #define HAVE_DECL_YES 1
108 ])])
111 # AC_CHECK_FUNCS
112 # --------------
113 # Check that it performs the correct actions:
114 # Must define HAVE_PRINTF, but not HAVE_AUTOCONF_FTNIRP
115 AT_CHECK_MACRO([AC_CHECK_FUNCS],
116 [AC_CHECK_FUNCS(printf autoconf_ftnirp)],
117 [AT_CHECK_DEFINES(
118 [/* #undef HAVE_AUTOCONF_FTNIRP */
119 #define HAVE_PRINTF 1
120 ])])
123 # AC_REPLACE_FUNCS
124 # ----------------
125 # Check that it performs the correct actions: autoconf_ftnirp.c must
126 # be compiled, and must define HAVE_PRINTF, but not HAVE_AUTOCONF_FTNIRP
127 # FIXME: Maybe check the traces?
128 AT_SETUP([AC_REPLACE_FUNCS])
130 AT_DATA([config.in],
131 [@LIBOBJS@
134 AT_CONFIGURE_AC(
135 [AC_CONFIG_FILES(config.libobjs:config.in)
136 AC_REPLACE_FUNCS(printf autoconf_ftnirp)])
138 AT_CHECK_AUTOCONF([-W obsolete])
139 AT_CHECK_AUTOHEADER
140 AT_CHECK_CONFIGURE
141 AT_CHECK_ENV
142 AT_CHECK_DEFINES(
143 [/* #undef HAVE_AUTOCONF_FTNIRP */
144 #define HAVE_PRINTF 1
147 AT_CHECK([sed 's/  */ /g;s/^ //;s/ $//' config.libobjs], [],
148          [autoconf_ftnirp$U.o
151 AT_CLEANUP([config.libobjs])
154 # AC_CHECK_HEADERS
155 # ----------------
156 # Check that it performs the correct actions:
157 # Must define HAVE_STDIO_H, but not HAVE_AUTOCONF_IO_H.
158 AT_CHECK_MACRO([AC_CHECK_HEADERS],
159 [AC_CHECK_HEADERS(stdio.h autoconf_io.h)],
160 [AT_CHECK_DEFINES(
161 [/* #undef HAVE_AUTOCONF_IO_H */
162 #define HAVE_STDIO_H 1
163 ])])
166 # AC_CHECK_HEADERS_OLD
167 # --------------------
168 # Check that it performs the correct actions:
169 # Must not check prerequisites, hence define header2.h
170 AT_SETUP([AC_CHECK_HEADERS_OLD])
172 AT_DATA([header1.h],
173 [typedef int foo;
176 AT_DATA([header2.h],
177 [typedef foo bar;
180 AT_CONFIGURE_AC([AC_CHECK_HEADERS(header2.h, [], [], -)])
182 AT_CHECK_AUTOCONF([-W obsolete])
183 AT_CHECK_AUTOHEADER
184 AT_CHECK_CONFIGURE([CPPFLAGS=-I.])
185 AT_CHECK_ENV
186 AT_CHECK_DEFINES(
187 [#define HAVE_HEADER2_H 1
190 AT_CLEANUP([header1.h header2.h])
193 # AC_CHECK_HEADERS_NEW
194 # --------------------
195 # Check that it performs the correct actions:
196 # Must check prerequisites, hence define header2.h but not header3.h
197 AT_SETUP([AC_CHECK_HEADERS_NEW])
199 AT_DATA([header1.h],
200 [typedef int foo;
203 AT_DATA([header2.h],
204 [typedef foo bar;
207 AT_DATA([header3.h],
208 [typedef bar wow;
211 AT_CONFIGURE_AC(
212 [AC_CHECK_HEADERS(header2.h header3.h, [], [], [[@%:@include "header1.h"]])])
214 AT_CHECK_AUTOCONF([-W obsolete])
215 AT_CHECK_AUTOHEADER
216 AT_CHECK_CONFIGURE([CPPFLAGS=-I.])
217 AT_CHECK_ENV
218 AT_CHECK_DEFINES(
219 [#define HAVE_HEADER2_H 1
220 /* #undef HAVE_HEADER3_H */
223 AT_CLEANUP([header1.h header2.h header3.h])
226 # AC_CHECK_MEMBERS
227 # ----------------
228 # Check that it performs the correct actions.
229 # Must define HAVE_STRUCT_YES_S_YES, but not HAVE_STRUCT_YES_S_NO.
230 AT_CHECK_MACRO([AC_CHECK_MEMBERS],
231 [[AC_CHECK_MEMBERS([struct yes_s.yes, struct yes_s.no],,,
232                    [struct yes_s { int yes ;} ;])]],
233 [AT_CHECK_DEFINES(
234 [/* #undef HAVE_STRUCT_YES_S_NO */
235 #define HAVE_STRUCT_YES_S_YES 1
236 ])])
239 # AC_CHECK_ALIGNOF
240 # ----------------
241 # Not cross-compiling.
242 AT_CHECK_MACRO([AC_CHECK_ALIGNOF],
243 [[AC_CHECK_ALIGNOF(char)
244 AC_CHECK_ALIGNOF(charchar,
245 [[#include <stddef.h>
246 #include <stdio.h>
247 typedef char charchar[2];]])
248 AC_CHECK_ALIGNOF(charcharchar)
250 [AT_CHECK_DEFINES(
251 [#define ALIGNOF_CHAR 1
252 #define ALIGNOF_CHARCHAR 1
253 #define ALIGNOF_CHARCHARCHAR 0
254 ])])
257 # AC_CHECK_ALIGNOF
258 # ----------------
259 AT_CHECK_MACRO([AC_CHECK_ALIGNOF],
260 [[# Exercise the code used when cross-compiling
261 cross_compiling=yes
262 AC_CHECK_ALIGNOF(char)
263 AC_CHECK_ALIGNOF(charchar,
264 [[#include <stddef.h>
265 #include <stdio.h>
266 typedef char charchar[2];]])
267 AC_CHECK_ALIGNOF(charcharchar)
269 [AT_CHECK_DEFINES(
270 [#define ALIGNOF_CHAR 1
271 #define ALIGNOF_CHARCHAR 1
272 #define ALIGNOF_CHARCHARCHAR 0
273 ])])
276 # AC_CHECK_SIZEOF
277 # ---------------
278 # Not cross-compiling.
279 AT_CHECK_MACRO([AC_CHECK_SIZEOF],
280 [[AC_CHECK_SIZEOF(char)
281 AC_CHECK_SIZEOF(charchar,,
282 [[#include <stdio.h>
283 typedef char charchar[2];]])
284 AC_CHECK_SIZEOF(charcharchar)
286 [AT_CHECK_DEFINES(
287 [#define SIZEOF_CHAR 1
288 #define SIZEOF_CHARCHAR 2
289 #define SIZEOF_CHARCHARCHAR 0
290 ])])
293 # AC_CHECK_SIZEOF
294 # ---------------
295 AT_CHECK_MACRO([AC_CHECK_SIZEOF],
296 [[# Exercise the code used when cross-compiling
297 cross_compiling=yes
298 AC_CHECK_SIZEOF(char)
299 AC_CHECK_SIZEOF(charchar,,
300 [[#include <stdio.h>
301 typedef char charchar[2];]])
302 AC_CHECK_SIZEOF(charcharchar)
304 [AT_CHECK_DEFINES(
305 [#define SIZEOF_CHAR 1
306 #define SIZEOF_CHARCHAR 2
307 #define SIZEOF_CHARCHARCHAR 0
308 ])])
311 # AC_CHECK_TYPES
312 # --------------
313 # Check that it performs the correct actions.
314 # Must define HAVE_STRUCT_YES_S, HAVE_INT, but not HAVE_STRUCT_NO_S.
315 # `int' and `struct yes_s' are both checked to test both the compiler
316 # builtin types, and defined types.
317 AT_CHECK_MACRO([AC_CHECK_TYPES],
318 [[AC_CHECK_TYPES([int, struct yes_s, struct no_s],,,
319                  [struct yes_s { int yes ;} ;])]],
320 [AT_CHECK_DEFINES(
321 [#define HAVE_INT 1
322 /* #undef HAVE_STRUCT_NO_S */
323 #define HAVE_STRUCT_YES_S 1
324 ])])
327 # AC_CHECK_TYPES
328 # --------------
329 # Check that we properly dispatch properly to the old implementation
330 # or to the new one.
331 AT_SETUP([AC_CHECK_TYPES: backward compatibility])
333 AT_DATA([configure.ac],
334 [[AC_INIT
335 define([_AC_CHECK_TYPE_NEW], [NEW])
336 define([_AC_CHECK_TYPE_OLD], [OLD])
337 #(cut-from-here
338 AC_CHECK_TYPE(ptrdiff_t)
339 AC_CHECK_TYPE(ptrdiff_t, int)
340 AC_CHECK_TYPE(quad, long long int)
341 AC_CHECK_TYPE(table_42, [int[42]])
342 # Nice machine!
343 AC_CHECK_TYPE(uint8_t, uint65536_t)
344 AC_CHECK_TYPE(a,b,c,d)
345 #to-here)
346 AC_OUTPUT
349 AT_CHECK_AUTOCONF
350 AT_CHECK([[sed -e '/^#(cut-from-here/,/^#to-here)/!d' -e '/^#/d' configure]],
351          0,
352          [NEW
360 AT_CLEANUP
363 # AC_CHECK_FILES
364 # --------------
365 # FIXME: To really test HAVE_AC_EXISTS2 and HAVE_AC_MISSING2 we need to
366 # open AH_TEMPLATE to `configure.ac', which is not yet the case.
367 AT_CHECK_MACRO([AC_CHECK_FILES],
368 [touch at-exists1 at-exists2
369 ac_exists2=at-exists2
370 ac_missing2=at-missing2
371 AC_CHECK_FILES(at-exists1 at-missing1 $ac_exists2 $ac_missing2)
372 rm at-exists1 at-exists2],
373 [AT_CHECK_DEFINES(
374 [#define HAVE_AT_EXISTS1 1
375 /* #undef HAVE_AT_MISSING1 */
376 ])])
380 ## ------------------------------ ##
381 ## AC_CHECK_PROG & AC_PATH_PROG.  ##
382 ## ------------------------------ ##
385 # AT_CHECK_PROGS_PREPARE
386 # ----------------------
387 # Create a sub directory `path' with 6 subdirs which all 7 contain
388 # an executable `tool'. `6' contains a `better' tool.
389 m4_define([AT_CHECK_PROGS_PREPARE],
390 [mkdir path
392 cat >path/tool <<\EOF
393 #! /bin/sh
394 exit 0
396 chmod +x path/tool
398 for i in 1 2 3 4 5 6
400   mkdir path/$i
401   cp path/tool path/$i
402 done
403 cp path/tool path/6/better])
406 # -------------------------------- #
407 # AC_CHECK_PROG & AC_CHECK_PROGS.  #
408 # -------------------------------- #
410 AT_SETUP([AC_CHECK_PROG & AC_CHECK_PROGS])
412 AT_CHECK_PROGS_PREPARE
414 AT_DATA([configure.ac],
415 [[AC_INIT
416 pwd=`pwd`
417 p="1${PATH_SEPARATOR}2${PATH_SEPARATOR}3${PATH_SEPARATOR}4${PATH_SEPARATOR}5${PATH_SEPARATOR}6"
418 path=`echo $p | sed -e 's,\([[0-9]]\),'"$pwd"'/path/\1,g'`
419 fail=false
421 AC_CHECK_PROG(TOOL1, tool, found, not-found, $path)
422 test "$TOOL1" = found || fail=:
424 # Yes, the semantics of this macro is weird.
425 AC_CHECK_PROG(TOOL2, tool,, not-found, $path)
426 test "$TOOL2" = not-found || fail=:
428 AC_CHECK_PROG(TOOL3, tool, tool, not-found, $path, $pwd/path/1/tool)
429 test "$TOOL3" = $pwd/path/2/tool || fail=:
431 AC_CHECK_PROG(TOOL4, better, better, not-found, $path, $pwd/path/1/tool)
432 test "$TOOL4" = better || fail=:
434 # When a tool is not found, and no value is given for not-found,
435 # the variable is left empty.
436 AC_CHECK_PROGS(TOOL5, missing,, $path)
437 test -z "$TOOL5" || fail=:
439 AC_CHECK_PROGS(TOOL6, missing tool better,, $path)
440 test "$TOOL6" = tool || fail=:
442 # No AC-OUTPUT, we don't need config.status.
443 $fail &&
444   AC_MSG_ERROR([[CHECK_PROG failed]])
445 AS_EXIT(0)
448 AT_CHECK_AUTOCONF
449 AT_CHECK_CONFIGURE
451 AT_CLEANUP(path)
455 ## ---------------- ##
456 ## AC_C_BIGENDIAN.  ##
457 ## ---------------- ##
459 AT_SETUP([AC_C_BIGENDIAN])
460 AT_KEYWORDS([cross])
462 # Make sure that AC_C_BIGENDIAN behave the same whether we are
463 # cross-compiling or not.
465 _AT_CHECK_AC_MACRO(
466   [AC_C_BIGENDIAN([ac_endian=big],[ac_endian=little],[ac_endian=unknown])
467    echo $ac_endian > at-endian
470 rm -f config.hin  # So that next run of autoheader is quiet.
471 _AT_CHECK_AC_MACRO(
472   [cross_compiling=yes
473    AC_C_BIGENDIAN([ac_endian=big],[ac_endian=little],[ac_endian=unknown])
474    ac_prevendian=`cat at-endian`
475    # Check that we have found the same result as in the previous run
476    # or unknown (because the cross-compiling check is allowed to fail;
477    # although it might be interesting to suppress this comparison, just
478    # to know on which system it fails if it ever does).
479    if test $ac_endian != $ac_prevendian && test $ac_endian != unknown; then
480      AC_MSG_ERROR([unexpected endianness: first run found '$ac_prevendian' but second run found '$ac_endian'])
481    fi
484 # Make sure AC_C_BIGENDIAN with no argument will define WORDS_BIGENDIAN
485 AT_CONFIGURE_AC([AC_C_BIGENDIAN])
486 AT_CHECK_AUTOHEADER
487 AT_CHECK([grep WORDS_BIGENDIAN config.hin], [], [ignore])
489 AT_CLEANUP(at-endian)
492 # ------------------------------ #
493 # AC_PATH_PROG & AC_PATH_PROGS.  #
494 # ------------------------------ #
496 AT_SETUP([AC_PATH_PROG & AC_PATH_PROGS])
498 AT_CHECK_PROGS_PREPARE
500 AT_DATA([configure.ac],
501 [[AC_INIT
502 pwd=`pwd`
503 p="1${PATH_SEPARATOR}2${PATH_SEPARATOR}3${PATH_SEPARATOR}4${PATH_SEPARATOR}5${PATH_SEPARATOR}6"
504 path=`echo $p | sed -e 's,\([[0-9]]\),'"$pwd"'/path/\1,g'`
505 fail=false
507 AC_PATH_PROG(TOOL1, tool, not-found, $path)
508 test "$TOOL1" = $pwd/path/1/tool || fail=:
510 AC_PATH_PROG(TOOL2, better, not-found, $path)
511 test "$TOOL2" = $pwd/path/6/better || fail=:
513 # When a tool is not found, and no value is given for not-found,
514 # the variable is left empty.
515 AC_PATH_PROGS(TOOL3, missing,, $path)
516 test -z "$TOOL3" || fail=:
518 AC_PATH_PROGS(TOOL4, missing tool better,, $path)
519 test "$TOOL4" = $pwd/path/1/tool || fail=:
521 # No AC-OUTPUT, we don't need config.status.
522 $fail &&
523   AC_MSG_ERROR([[PATH_PROG failed]])
524 AS_EXIT(0)
527 AT_CHECK_AUTOCONF
528 AT_CHECK_CONFIGURE
530 AT_CLEANUP(path)
535 ## -------------- ##
536 ## AC_PATH_XTRA.  ##
537 ## -------------- ##
540 AT_SETUP([AC_PATH_XTRA])
542 _AT_CHECK_AC_MACRO([AC_PATH_XTRA])
544 # Check X_DISPLAY_MISSING.
545 AT_CHECK_CONFIGURE([--without-x])
546 AT_CHECK_DEFINES(
547 [#define X_DISPLAY_MISSING 1
550 AT_CLEANUP
553 ## ------------------------------- ##
554 ## Obsolete non-updatable macros.  ##
555 ## ------------------------------- ##
558 AT_CHECK_MACRO([AC_SYS_RESTARTABLE_SYSCALLS], , ,[-W no-obsolete])
559 AT_CHECK_MACRO([AC_FUNC_WAIT3], , ,[-W no-obsolete])