Document FSEEKO fix.
[autoconf.git] / tests / local.at
bloba79682fb1bc284edfb3bada8ce77603a23b5745c
1 # M4 macros used in building Autoconf test suites.        -*- Autotest -*-
3 # Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006 Free Software
4 # Foundation, Inc.
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2, or (at your option)
9 # any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 # 02110-1301, USA.
21 m4_version_prereq([2.57])
23 # Used in many tests.
24 m4_pattern_allow([^AS_EXIT$])
25 m4_pattern_allow([^m4_(define|shift)$])
27 AT_TESTED([autom4te autoconf autoheader autoupdate autoreconf ifnames])
30 ## ---------------- ##
31 ## Utility macros.  ##
32 ## ---------------- ##
34 # AT_CMP(FILE-1, FILE-2)
35 # ----------------------
36 # Check FILE-1 and FILE-2 for equality, like `cmp FILE-1 FILE-2'.
37 m4_define([AT_CMP],
38 [m4_ifval([$2],, [m4_fatal([AT_CMP takes two arguments.])])[]dnl
39 AT_CHECK([$at_diff "$1" "$2"])
40 ])# AT_CMP
43 ## ---------------- ##
44 ## Testing syntax.  ##
45 ## ---------------- ##
47 # AT_CHECK_SHELL_SYNTAX(PROGRAM)
48 # ------------------------------
49 # If the shell handles `-n' well, use it to check the syntax of PROGRAM;
50 # otherwise, do nothing.
51 m4_define([AT_CHECK_SHELL_SYNTAX],
52 [AS_IF([test "$ac_cv_sh_n_works" = yes],
53   [AT_CHECK([/bin/sh -n $1])])])
55 m4_define([AT_CHECK_PERL_SYNTAX],
56 [AT_CHECK([autom4te_perllibdir=$abs_top_srcdir/lib $PERL -c $abs_top_builddir/bin/$1],
57           0, [], [ignore])])
59 ## ------------------ ##
60 ## Testing autom4te.  ##
61 ## ------------------ ##
64 # AT_CHECK_M4(COMMAND, [EXIT-STATUS = 0], STDOUT, STDERR)
65 # -------------------------------------------------------
66 # If stderr is specified, normalize the observed stderr.
67 # This (using GNU M4 1.4.6 or later)
69 #  /usr/local/bin/m4:script.4s:1: cannot open `foo': No such file or directory
70 #  autom4te: /usr/local/bin/m4 failed with exit status: 1
72 # or this (GNU M4 1.4 installed as gm4)
74 #  script.4s:1: /usr/local/bin/gm4: Cannot open foo: No such file or directory
75 #  autom4te: /usr/local/bin/gm4 failed with exit status: 1
77 # becomes
79 #  m4:script.4s:1: cannot open `foo': No such file or directory
80 #  autom4te: m4 failed with exit status: 1
82 # We use the following sed patterns:
84 #     (m4): ?(file): ?(line):
85 # or  (file): ?(line): ?(m4):
86 # to  m4:(file):(line):
88 # and
89 #     m4:(file):(line): Cannot open foo:
90 # to  m4:(file):(line): cannot open `foo':
92 # and
93 #     autom4te: [^ ]m4
94 # or  autom4te: [^ ]m4.exe
95 # to  autom4te: m4
97 # Moreover, DJGPP error messages include the error code in brackets;
98 # remove the error code during normalization.
100 m4_define([AT_CHECK_M4],
101 [AT_CHECK([$1], [$2], [$3], m4_ifval([$4], [stderr]))
102 m4_ifval([$4],
103 [AT_CHECK([[sed 's/^[^:]*m4: *\([^:]*:\) *\([0-9][0-9]*: \)/m4:\1\2/
104         s/^\([^:]*:\) *\([0-9][0-9]*:\)[^:]*m4: /m4:\1\2 /
105         s/^\(m4:[^:]*:[0-9][0-9]*: \)C\(annot open \)\([^`:]*\):/\1c\2`\3'\'':/
106         s/^autom4te: [^ ]*m4 /autom4te: m4 /
107         s/^autom4te: [^ ]*m4\.exe /autom4te: m4 /
108         s/ (E[A-Z]*)$//
109     ' stderr]], [0],[$4])])
112 # AT_CHECK_AUTOM4TE(FLAGS, [EXIT-STATUS = 0], STDOUT, STDERR)
113 # -----------------------------------------------------------
114 m4_define([AT_CHECK_AUTOM4TE],
115 [AT_CHECK_M4([autom4te $1], [$2], [$3], [$4])])
119 ## ----------------- ##
120 ## Testing M4sugar.  ##
121 ## ----------------- ##
124 # AT_DATA_M4SUGAR(FILE-NAME, CONTENTS)
125 # ------------------------------------
126 # Escape the invalid tokens with @&t@.
127 m4_define([AT_DATA_M4SUGAR],
128 [AT_DATA([$1],
129 [m4_bpatsubsts([$2],
130                [@&t@],    [@&@&t@t@],
131                [\(m4\)_], [\1@&t@_],
132                [dnl],     [d@&t@nl])])])
135 # AT_CHECK_M4SUGAR(FLAGS, [EXIT-STATUS = 0], STDOUT, STDERR)
136 # ----------------------------------------------------------
137 m4_define([AT_CHECK_M4SUGAR],
138 [AT_KEYWORDS([m4sugar])
139 AT_CHECK_AUTOM4TE([--language=m4sugar script.4s -o script $1],
140                    [$2], [$3], [$4])])
144 ## -------------- ##
145 ## Testing M4sh.  ##
146 ## -------------- ##
149 # AT_DATA_M4SH(FILE-NAME, CONTENTS)
150 # ---------------------------------
151 # Escape the invalid tokens with @&t@.
152 m4_define([AT_DATA_M4SH],
153 [AT_DATA([$1],
154 [m4_bpatsubsts([$2],
155                [@&t@],        [@&@&t@t@],
156                [\(m4\|AS\)_], [\1@&t@_],
157                [dnl],         [d@&t@nl])])])
160 # AT_CHECK_M4SH(FLAGS, [EXIT-STATUS = 0], STDOUT, STDERR)
161 # -------------------------------------------------------
162 m4_define([AT_CHECK_M4SH],
163 [AT_CHECK_AUTOM4TE([--language=m4sh script.as -o script $1],
164                    [$2], [$3], [$4])])
168 ## ------------------ ##
169 ## Testing Autoconf.  ##
170 ## ------------------ ##
173 # AT_DATA_AUTOCONF(FILE-NAME, CONTENTS)
174 # -------------------------------------
175 # Escape the invalid tokens with @&t@.
176 m4_define([AT_DATA_AUTOCONF],
177 [AT_DATA([$1],
178 [m4_bpatsubsts([$2],
179                [@&t@],            [@&@&t@t@],
180                [\(m4\|AS\|AC\)_], [\1@&t@_],
181                [dnl],             [d@&t@nl])])])
185 # AT_CONFIGURE_AC(BODY)
186 # ---------------------
187 # Create a full configure.ac running BODY, with a config header set up,
188 # AC_OUTPUT, and environment checking hooks.
189 m4_define([AT_CONFIGURE_AC],
190 [AT_DATA_AUTOCONF([aclocal.m4],
192 # AC_STATE_SAVE(FILE)
193 # -------------------
194 # Save the shell variables and directory listing.  AT_CHECK_ENV uses these to
195 # confirm that no test modifies variables outside the Autoconf namespace or
196 # leaves temporary files.  AT_CONFIG_CMP uses the variable dumps to confirm that
197 # tests have the same side effects regardless of caching.
198 m4_defun([AC_STATE_SAVE],
199 [(set) 2>&1 | sort >state-env.$][1
200 ls -1 | sed '/^at-/d;/^state-/d;/^config\./d' | sort >state-ls.$][1
201 ])# AC_STATE_SAVE
204 AT_DATA([configure.ac],
205 [[AC_INIT
206 AC_CONFIG_AUX_DIR($top_srcdir/build-aux)
207 AC_CONFIG_HEADER(config.h:config.hin)
208 AC_STATE_SAVE(before)]
210 [AC_OUTPUT
211 AC_STATE_SAVE(after)
213 ])# AT_CONFIGURE_AC
216 # AT_CHECK_AUTOCONF(ARGS, [EXIT-STATUS = 0], STDOUT, STDERR)
217 # ----------------------------------------------------------
218 # We always use "--force", to prevent problems with timestamps if the testsuite
219 # were running too fast.
220 m4_define([AT_CHECK_AUTOCONF],
221 [AT_CHECK_M4([autoconf --force $1], [$2], [$3], [$4])
222 if test -s configure; then
223   AT_CHECK_SHELL_SYNTAX(configure)
228 # AT_CHECK_AUTOHEADER(ARGS, [EXIT-STATUS = 0], STDOUT, STDERR)
229 # ------------------------------------------------------------
230 m4_define([AT_CHECK_AUTOHEADER],
231 [AT_CHECK([autoheader $1], [$2], [$3], [$4])
235 # AT_CHECK_CONFIGURE(END-COMMAND,
236 #                    [EXIT-STATUS = 0],
237 #                    [STDOUT = IGNORE], STDERR)
238 # --------------------------------------------
239 # `abs_top_srcdir' is needed so that `./configure' finds install-sh.
240 # Using --srcdir is more expensive.
241 m4_define([AT_CHECK_CONFIGURE],
242 [AT_CAPTURE_FILE([config.log])[]dnl
243  AT_CHECK([top_srcdir=$abs_top_srcdir ./configure $1],
244           [$2],
245           m4_default([$3], [ignore]), [$4])])
248 # AT_CHECK_ENV
249 # ------------
250 # Check that the full configure run remained in its variable name space,
251 # and cleaned up tmp files.
253 # Perhaps grep -E is not supported, or perhaps it chokes on such a big regex.
254 # In this case just don't pay attention to the env.  It would be great
255 # to keep the error message but we can't: that would break AT_CHECK.
257 # Some tests might exit prematurely when they find a problem, in
258 # which case `env-after' is probably missing.  Don't check it then.
260 # Here are the variables `configure' may modify during execution:
261 # - ^as_
262 #   M4sh's shell name space.
263 # - ^ac_
264 #   Autoconf's shell name space.
265 # - prefix and exec_prefix
266 #   are kept undefined (NONE) until AC_OUTPUT which then sets them to
267 #   `/usr/local' and `${prefix}' for make.
268 # - (host|build|target)(_(alias|cpu|vendor|os))?
269 #   Set by AC_CANONICAL_(HOST|BUILD|TARGET).
270 # - cross_compiling
271 #   Set by AC_INIT.
272 # - interpval
273 #   Set by AC_SYS_INTERPRETER.
274 # - CONFIG_STATUS and DEFS
275 #   Set by AC_OUTPUT.
276 # - AC_SUBST'ed variables
277 #   (FIXME: Generate a list of these automatically.)
278 # - _|@|.[*#?$].|LINENO|OLDPWD|PIPESTATUS|RANDOM|SECONDS
279 #   Some variables some shells use and change.
280 #   `.[*#?$].' catches `$#' etc. which are displayed like this:
281 #      | '!'=18186
282 #      | '#'=0
283 #      | '$'=6908
285 m4_define([AT_CHECK_ENV],
286 [# Compare directory listings.
287 test -f state-ls.before ||
288   AS_ERROR([state-ls.before not present])
289 test -f state-ls.after && { AT_CMP([state-ls.before], [state-ls.after]) }
290 # Compare variable space dumps.
291 if test -f state-env.before && test -f state-env.after; then
292   for act_file in state-env.before state-env.after
293   do
294     $EGREP -v '^(m4_join([|],
295       [a[cs]_.*],
296       [(exec_)?prefix|DEFS|CONFIG_STATUS],
297       [CC|CFLAGS|CPP|GCC|CXX|CXXFLAGS|CXXCPP|GXX|F77|FFLAGS|FLIBS|G77],
298       [ERL|ERLC|ERLCFLAGS|ERLANG_PATH_ERL|ERLANG_ROOT_DIR|ERLANG_LIB_DIR],
299       [ERLANG_INSTALL_LIB_DIR|OBJC|OBJCPP|OBJCFLAGS],
300       [LIBS|LIB@&t@OBJS|LTLIBOBJS|LDFLAGS],
301       [INSTALL(_(DATA|PROGRAM|SCRIPT))?],
302       [CYGWIN|ISC|MINGW32|MINIX|EMXOS2|XENIX|EXEEXT|OBJEXT],
303       [X_(CFLAGS|(EXTRA_|PRE_)?LIBS)|x_(includes|libraries)|(have|no)_x],
304       [(host|build|target)(_(alias|cpu|vendor|os))?],
305       [cross_compiling],
306       [interpval|PATH_SEPARATOR],
307       [F77_DUMMY_MAIN|f77_(case|underscore)],
308       [FC(_DUMMY_MAIN|FLAGS|LIBS|FLAGS_f)?],
309       [ALLOCA|GETLOADAVG_LIBS|KMEM_GROUP|NEED_SETGID|POW_LIB],
310       [AWK|LEX|LEXLIB|LEX_OUTPUT_ROOT|LN_S|M4|MKDIR_P|RANLIB|SET_MAKE|YACC],
311       [GREP|[EF]GREP|SED],
312       [[_@]|.[*#?$].|LINENO|OLDPWD|PIPESTATUS|RANDOM|SECONDS]))=' \
313      $act_file 2>/dev/null |
314       # There may be variables spread on several lines; remove latter lines.
315       $GREP '^m4_defn([m4_re_word])=' >clean-$act_file
316   done
317   AT_CMP([clean-state-env.before], [clean-state-env.after])
322 # AT_CONFIG_CMP(VAR-FILE-A, VAR-FILE-B)
323 # -------------------------------------
324 # Check the outcomes of two configure runs for equality by comparing dumps of
325 # their shell variables.  VAR-FILE-A and VAR-FILE-B are two `set'-style shell
326 # variable space dumps.
328 # We permit variance between runs in the following shell variables:
329 # - ^as_
330 #   M4sh's shell name space.
331 # - ^ac_, excluding ^ac_cv_
332 #   Autoconf's private shell name space.
333 # - PPID [bash, zsh]
334 # - RANDOM [zsh]
335 # - SECONDS [zsh]
336 # - '$' [zsh]
338 # Furthermore, it is okay for a non-cache variable initialized to empty in one
339 # run to be unset in another run.  This happens when, for example, cache update
340 # code tries a number of values in LIBS and eventually restores LIBS to its
341 # original value. If LIBS was previously unset, it will have become set and
342 # empty.  (OTOH, cache variables indicate the result of the test even if they
343 # are empty, so we have to be strict about them.)
345 # Lines that do not look like `foo=bar' are probably latter lines of
346 # multiline values; trim them.
348 m4_define([AT_CONFIG_CMP],
349 [for act_file in $1 $2
351   $SED '/^ac_cv_/ b
352         /^m4_defn([m4_re_word])=./ !d
353         /^[[^=]]*='\'''\''$/ d
354         /^a[[cs]]_/ d
355         /^PPID=/ d
356         /^RANDOM=/ d
357         /^SECONDS=/ d
358         /'\'\\\$\''=/ d
359         ' $act_file >at_config_vars-$act_file
360 done
361 AT_CMP([at_config_vars-$1], [at_config_vars-$2])[]dnl
362 ])# AT_CONFIG_CMP
365 # AT_CHECK_DEFINES(CONTENT)
366 # -------------------------
367 # Verify that config.h, once stripped, is CONTENT.
368 # Stripping consists of keeping CPP lines (i.e. containing a hash),
369 # but those of automatically checked features (STDC_HEADERS etc.)
370 # and symbols (PACKAGE_...).
371 # AT_CHECK_HEADER is a better name, but too close from AC_CHECK_HEADER.
372 m4_define([AT_CHECK_DEFINES],
373 [AT_CHECK([[sed '/#/!d
374 /INTTYPES/d
375 /MEMORY/d
376 /PACKAGE_/d
377 /STDC_HEADERS/d
378 /STDINT/d
379 /STDLIB/d
380 /STRING/d
381 /SYS_STAT/d
382 /SYS_TYPES/d
383 /UNISTD/d' config.h]],,
384           [$1])])
387 # AT_CHECK_AUTOUPDATE
388 # -------------------
389 m4_define([AT_CHECK_AUTOUPDATE],
390 [AT_CHECK([autoupdate $1], [$2], [$3], [$4])
394 # _AT_CHECK_AC_MACRO(AC-BODY, PRE-TESTS)
395 # --------------------------------------
396 # Create a minimalist configure.ac running the macro named
397 # NAME-OF-THE-MACRO, check that autoconf runs on that script,
398 # and that the shell runs correctly the configure.
399 m4_define([_AT_CHECK_AC_MACRO],
400 [AT_CONFIGURE_AC([$1])
402 AT_CHECK_AUTOCONF
403 AT_CHECK_AUTOHEADER
404 AT_CHECK_CONFIGURE
405 AT_CHECK_ENV
406 ])# _AT_CHECK_AC_MACRO
409 # AT_CHECK_MACRO(MACRO, [MACRO-USE], [ADDITIONAL-CMDS],
410 #                [AUTOCONF-FLAGS = -W obsolete])
411 # -----------------------------------------------------
412 # Create a minimalist configure.ac running the macro named
413 # NAME-OF-THE-MACRO, check that autoconf runs on that script,
414 # and that the shell runs correctly the configure.
416 # We run `configure' twice, both times with a cache, and compare
417 # the environment after each run to detect inconsistencies.
419 # New macros are not expected to depend upon obsolete macros.
420 m4_define([AT_CHECK_MACRO],
421 [AT_SETUP([$1])
423 AT_CONFIGURE_AC([m4_default([$2], [$1])])
425 AT_CHECK_AUTOCONF([m4_default([$4], [-W obsolete])])
426 AT_CHECK_AUTOHEADER
428 for at_run in r1 r2
430     AT_CHECK_CONFIGURE([-C])
431     cp -f state-env.after state-env.$at_run
432     cp -f config.h config-h.$at_run
433     AT_CHECK_ENV
434 done
436 AT_CMP([config-h.r1], [config-h.r2])
437 AT_CONFIG_CMP([state-env.r1], [state-env.r2])
441 AT_CLEANUP()dnl
442 ])# AT_CHECK_MACRO
445 # AT_CHECK_MACRO_CROSS(MACRO, [MACRO-USE], [ADDITIONAL-CMDS],
446 #                      [AUTOCONF-FLAGS = -W obsolete])
447 # -----------------------------------------------------------
448 # Like the previous one, but creates two checks: for native
449 # compile and for cross-compile.
450 m4_define([AT_CHECK_MACRO_CROSS],
451 [AT_CHECK_MACRO($@)
452 AT_CHECK_MACRO([$1 (cross compile)],
453   [AT_KEYWORDS([cross])
454   # Exercise the code used when cross-compiling.
455   cross_compiling=yes
456   ac_tool_warned=yes
457   m4_default([$2], [$1])],
458   [$3], [$4])
462 # AT_CHECK_AU_MACRO(MACRO)
463 # ------------------------
464 # Create a minimalist configure.ac running the macro named
465 # NAME-OF-THE-MACRO, autoupdate this script, check that autoconf runs
466 # on that script, and that the shell runs correctly the configure.
468 # Updated configure.ac shall not depend upon obsolete macros, which votes
469 # in favor of `-W obsolete', but since many of these macros leave a message
470 # to be removed by the user once her code is adjusted, let's not check.
472 # Remove config.hin to avoid `autoheader: config.hin is unchanged'.
473 m4_define([AT_CHECK_AU_MACRO],
474 [AT_SETUP([$1])
475 AT_KEYWORDS([autoupdate])
477 AT_CONFIGURE_AC([$1])
479 AT_CHECK_AUTOCONF
480 AT_CHECK_AUTOHEADER
481 AT_CHECK_CONFIGURE
482 AT_CHECK_ENV
484 rm config.hin
485 AT_CHECK_AUTOUPDATE([], 0, [], ignore)
486 AT_CHECK([grep '^$1$' configure.ac], 1)
488 AT_CHECK_AUTOCONF
489 AT_CHECK_AUTOHEADER
490 AT_CHECK_CONFIGURE
491 AT_CHECK_ENV
493 AT_CLEANUP()dnl
494 ])# AT_CHECK_AU_MACRO
498 ## ----------------------- ##
499 ## Launch the test suite.  ##
500 ## ----------------------- ##
502 AT_INIT
503 AT_COPYRIGHT(
504 [Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006 Free Software
505 Foundation, Inc.
506 This is free software; see the source for copying conditions.  There is NO
507 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.])