* README: Recommend M4 1.4.5.
[autoconf/tsuna.git] / tests / local.at
blobe753ab187fb16d4d909965154c6cb2638bf0e686
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 # We need a very up to date version of Autotest.
22 m4_version_prereq([2.57])
24 # Used in many tests.
25 m4_pattern_allow([^AS_EXIT$])
26 m4_pattern_allow([^m4_(define|shift)$])
28 AT_TESTED([autom4te autoconf autoheader autoupdate autoreconf ifnames])
31 ## ---------------- ##
32 ## Utility macros.  ##
33 ## ---------------- ##
35 # AT_CMP(FILE-1, FILE-2)
36 # ----------------------
37 # Check FILE-1 and FILE-2 for equality, like `cmp FILE-1 FILE-2'.
38 m4_define([AT_CMP],
39 [m4_ifval([$2],, [m4_fatal([AT_CMP takes two arguments.])])[]dnl
40 AT_CHECK([$at_diff "$1" "$2"])
41 ])# AT_CMP
44 ## ---------------- ##
45 ## Testing syntax.  ##
46 ## ---------------- ##
48 # AT_CHECK_SHELL_SYNTAX(PROGRAM)
49 # ------------------------------
50 # If the shell handles `-n' well, use it to check the syntax of PROGRAM;
51 # otherwise, do nothing.
52 m4_define([AT_CHECK_SHELL_SYNTAX],
53 [AS_IF([test "$ac_cv_sh_n_works" = yes],
54   [AT_CHECK([/bin/sh -n $1])])])
56 m4_define([AT_CHECK_PERL_SYNTAX],
57 [AT_CHECK([autom4te_perllibdir=$abs_top_srcdir/lib $PERL -c $abs_top_builddir/bin/$1],
58           0, [], [ignore])])
60 ## ------------------ ##
61 ## Testing autom4te.  ##
62 ## ------------------ ##
65 # AT_CHECK_M4(COMMAND, [EXIT-STATUS = 0], STDOUT, STDERR)
66 # -------------------------------------------------------
67 # If stderr is specified, normalize the observed stderr.  E.g. (GNU M4 1.5):
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 (using gm4 as GNU M4 1.4):
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 #     (file): (line): (m4):
85 # or  (m4): (file): (line):
86 # to  m4: (file): (line):
88 # and
89 #     autom4te: [^ ]m4
90 # or  autom4te: [^ ]m4.exe
91 # to  autom4te: m4
92 m4_define([AT_CHECK_M4],
93 [AT_CHECK([$1], [$2], [$3], m4_ifval([$4], [stderr]))
94 m4_ifval([$4],
95 [AT_CHECK([[sed -e 's/^\([^:]*\): *\([0-9][0-9]*\): *[^:]*m4: /m4: \1: \2: /' \
96                 -e 's/^[^:]*m4: *\([^:]*\): *\([0-9][0-9]*\): /m4: \1: \2: /' \
97                 -e 's/^autom4te: [^ ]*m4 /autom4te: m4 /' \
98                 -e 's/^autom4te: [^ ]*m4\.exe /autom4te: m4 /' \
99                 -e 's/ (E[A-Z]*)$//' \
100            stderr]], [0],[$4])])
103 # AT_CHECK_AUTOM4TE(FLAGS, [EXIT-STATUS = 0], STDOUT, STDERR)
104 # -----------------------------------------------------------
105 m4_define([AT_CHECK_AUTOM4TE],
106 [AT_CHECK_M4([autom4te $1], [$2], [$3], [$4])])
110 ## ----------------- ##
111 ## Testing M4sugar.  ##
112 ## ----------------- ##
115 # AT_DATA_M4SUGAR(FILE-NAME, CONTENTS)
116 # ------------------------------------
117 # Escape the invalid tokens with @&t@.
118 m4_define([AT_DATA_M4SUGAR],
119 [AT_DATA([$1],
120 [m4_bpatsubsts([$2],
121                [@&t@],    [@&@&t@t@],
122                [\(m4\)_], [\1@&t@_],
123                [dnl],     [d@&t@nl])])])
126 # AT_CHECK_M4SUGAR(FLAGS, [EXIT-STATUS = 0], STDOUT, STDERR)
127 # ----------------------------------------------------------
128 m4_define([AT_CHECK_M4SUGAR],
129 [AT_KEYWORDS([m4sugar])
130 AT_CHECK_AUTOM4TE([--language=m4sugar script.4s -o script $1],
131                    [$2], [$3], [$4])])
135 ## -------------- ##
136 ## Testing M4sh.  ##
137 ## -------------- ##
140 # AT_DATA_M4SH(FILE-NAME, CONTENTS)
141 # ---------------------------------
142 # Escape the invalid tokens with @&t@.
143 m4_define([AT_DATA_M4SH],
144 [AT_DATA([$1],
145 [m4_bpatsubsts([$2],
146                [@&t@],        [@&@&t@t@],
147                [\(m4\|AS\)_], [\1@&t@_],
148                [dnl],         [d@&t@nl])])])
151 # AT_CHECK_M4SH(FLAGS, [EXIT-STATUS = 0], STDOUT, STDERR)
152 # -------------------------------------------------------
153 m4_define([AT_CHECK_M4SH],
154 [AT_CHECK_AUTOM4TE([--language=m4sh script.as -o script $1],
155                    [$2], [$3], [$4])])
159 ## ------------------ ##
160 ## Testing Autoconf.  ##
161 ## ------------------ ##
164 # AT_DATA_AUTOCONF(FILE-NAME, CONTENTS)
165 # -------------------------------------
166 # Escape the invalid tokens with @&t@.
167 m4_define([AT_DATA_AUTOCONF],
168 [AT_DATA([$1],
169 [m4_bpatsubsts([$2],
170                [@&t@],            [@&@&t@t@],
171                [\(m4\|AS\|AC\)_], [\1@&t@_],
172                [dnl],             [d@&t@nl])])])
176 # AT_CONFIGURE_AC(BODY)
177 # ---------------------
178 # Create a full configure.ac running BODY, with a config header set up,
179 # AC_OUTPUT, and environment checking hooks.
180 m4_define([AT_CONFIGURE_AC],
181 [AT_DATA_AUTOCONF([aclocal.m4],
183 # AC_STATE_SAVE(FILE)
184 # -------------------
185 # Save the shell variables and directory listing.  AT_CHECK_ENV uses these to
186 # confirm that no test modifies variables outside the Autoconf namespace or
187 # leaves temporary files.  AT_CONFIG_CMP uses the variable dumps to confirm that
188 # tests have the same side effects regardless of caching.
189 m4_defun([AC_STATE_SAVE],
190 [(set) 2>&1 | sort >state-env.$][1
191 ls -1 | sed '/^at-/d;/^state-/d;/^config\./d' | sort >state-ls.$][1
192 ])# AC_STATE_SAVE
195 AT_DATA([configure.ac],
196 [[AC_INIT
197 AC_CONFIG_AUX_DIR($top_srcdir/config)
198 AC_CONFIG_HEADER(config.h:config.hin)
199 AC_STATE_SAVE(before)]
201 [AC_OUTPUT
202 AC_STATE_SAVE(after)
204 ])# AT_CONFIGURE_AC
207 # AT_CHECK_AUTOCONF(ARGS, [EXIT-STATUS = 0], STDOUT, STDERR)
208 # ----------------------------------------------------------
209 # We always use "--force", to prevent problems with timestamps if the testsuite
210 # were running too fast.
211 m4_define([AT_CHECK_AUTOCONF],
212 [AT_CHECK_M4([autoconf --force $1], [$2], [$3], [$4])
213 if test -s configure; then
214   AT_CHECK_SHELL_SYNTAX(configure)
219 # AT_CHECK_AUTOHEADER(ARGS, [EXIT-STATUS = 0], STDOUT, STDERR)
220 # ------------------------------------------------------------
221 m4_define([AT_CHECK_AUTOHEADER],
222 [AT_CHECK([autoheader $1], [$2], [$3], [$4])
226 # AT_CHECK_CONFIGURE(END-COMMAND,
227 #                    [EXIT-STATUS = 0],
228 #                    [STDOUT = IGNORE], STDERR)
229 # --------------------------------------------
230 # `abs_top_srcdir' is needed so that `./configure' finds install-sh.
231 # Using --srcdir is more expensive.
232 m4_define([AT_CHECK_CONFIGURE],
233 [AT_CAPTURE_FILE([config.log])[]dnl
234  AT_CHECK([top_srcdir=$abs_top_srcdir ./configure $1],
235           [$2],
236           m4_default([$3], [ignore]), [$4])])
239 # AT_CHECK_ENV
240 # ------------
241 # Check that the full configure run remained in its variable name space,
242 # and cleaned up tmp files.
244 # Perhaps grep -E is not supported, or perhaps it chokes on such a big regex.
245 # In this case just don't pay attention to the env.  It would be great
246 # to keep the error message but we can't: that would break AT_CHECK.
248 # Some tests might exit prematurely when they find a problem, in
249 # which case `env-after' is probably missing.  Don't check it then.
251 # Here are the variables `configure' may modify during execution:
252 # - ^as_
253 #   M4sh's shell name space.
254 # - ^ac_
255 #   Autoconf's shell name space.
256 # - prefix and exec_prefix
257 #   are kept undefined (NONE) until AC_OUTPUT which then sets them to
258 #   `/usr/local' and `${prefix}' for make.
259 # - (host|build|target)(_(alias|cpu|vendor|os))?
260 #   Set by AC_CANONICAL_(HOST|BUILD|TARGET).
261 # - cross_compiling
262 #   Set by AC_INIT.
263 # - interpval
264 #   Set by AC_SYS_INTERPRETER.
265 # - CONFIG_STATUS and DEFS
266 #   Set by AC_OUTPUT.
267 # - AC_SUBST'ed variables
268 #   (FIXME: Generate a list of these automatically.)
269 # - _|@|.[*#?$].|LINENO|OLDPWD|PIPESTATUS|RANDOM|SECONDS
270 #   Some variables some shells use and change.
271 #   `.[*#?$].' catches `$#' etc. which are displayed like this:
272 #      | '!'=18186
273 #      | '#'=0
274 #      | '$'=6908
276 m4_define([AT_CHECK_ENV],
277 [# Compare directory listings.
278 test -f state-ls.before ||
279   AS_ERROR([state-ls.before not present])
280 test -f state-ls.after && { AT_CMP([state-ls.before], [state-ls.after]) }
281 # Compare variable space dumps.
282 if test -f state-env.before && test -f state-env.after; then
283   for act_file in state-env.before state-env.after
284   do
285     $EGREP -v '^(m4_join([|],
286       [a[cs]_.*],
287       [(exec_)?prefix|DEFS|CONFIG_STATUS],
288       [CC|CFLAGS|CPP|GCC|CXX|CXXFLAGS|CXXCPP|GXX|F77|FFLAGS|FLIBS|G77],
289       [ERL|ERLC|ERLCFLAGS|ERLANG_PATH_ERL|ERLANG_ROOT_DIR|ERLANG_LIB_DIR],
290       [ERLANG_INSTALL_LIB_DIR|OBJC|OBJCPP|OBJCFLAGS],
291       [LIBS|LIB@&t@OBJS|LTLIBOBJS|LDFLAGS],
292       [INSTALL(_(DATA|PROGRAM|SCRIPT))?],
293       [CYGWIN|ISC|MINGW32|MINIX|EMXOS2|XENIX|EXEEXT|OBJEXT],
294       [X_(CFLAGS|(EXTRA_|PRE_)?LIBS)|x_(includes|libraries)|(have|no)_x],
295       [(host|build|target)(_(alias|cpu|vendor|os))?],
296       [cross_compiling],
297       [interpval|PATH_SEPARATOR],
298       [F77_DUMMY_MAIN|f77_(case|underscore)],
299       [FC(_DUMMY_MAIN|FLAGS|LIBS|FLAGS_f)?],
300       [ALLOCA|GETLOADAVG_LIBS|KMEM_GROUP|NEED_SETGID|POW_LIB],
301       [AWK|LEX|LEXLIB|LEX_OUTPUT_ROOT|LN_S|M4|MKDIR_P|RANLIB|SET_MAKE|YACC],
302       [GREP|[EF]GREP|SED],
303       [[_@]|.[*#?$].|LINENO|OLDPWD|PIPESTATUS|RANDOM|SECONDS]))=' \
304      $act_file 2>/dev/null |
305       # There may be variables spread on several lines; remove latter lines.
306       $GREP '^m4_defn([m4_re_word])=' >clean-$act_file
307   done
308   AT_CMP([clean-state-env.before], [clean-state-env.after])
313 # AT_CONFIG_CMP(VAR-FILE-A, VAR-FILE-B)
314 # -------------------------------------
315 # Check the outcomes of two configure runs for equality by comparing dumps of
316 # their shell variables.  VAR-FILE-A and VAR-FILE-B are two `set'-style shell
317 # variable space dumps.
319 # We permit variance between runs in the following shell variables:
320 # - ^as_
321 #   M4sh's shell name space.
322 # - ^ac_, excluding ^ac_cv_
323 #   Autoconf's private shell name space.
324 # - PPID [bash, zsh]
325 # - RANDOM [zsh]
326 # - SECONDS [zsh]
327 # - '$' [zsh]
329 # Furthermore, it is okay for a non-cache variable initialized to empty in one
330 # run to be unset in another run.  This happens when, for example, cache update
331 # code tries a number of values in LIBS and eventually restores LIBS to its
332 # original value. If LIBS was previously unset, it will have become set and
333 # empty.  (OTOH, cache variables indicate the result of the test even if they
334 # are empty, so we have to be strict about them.)
336 # Lines that do not look like `foo=bar' are probably latter lines of
337 # multiline values; trim them.
339 m4_define([AT_CONFIG_CMP],
340 [for act_file in $1 $2
342   $SED '/^ac_cv_/ b
343         /^m4_defn([m4_re_word])=./ !d
344         /^[[^=]]*='\'''\''$/ d
345         /^a[[cs]]_/ d
346         /^PPID=/ d
347         /^RANDOM=/ d
348         /^SECONDS=/ d
349         /'\'\\\$\''=/ d
350         ' $act_file >at_config_vars-$act_file
351 done
352 AT_CMP([at_config_vars-$1], [at_config_vars-$2])[]dnl
353 ])# AT_CONFIG_CMP
356 # AT_CHECK_DEFINES(CONTENT)
357 # -------------------------
358 # Verify that config.h, once stripped, is CONTENT.
359 # Stripping consists of keeping CPP lines (i.e. containing a hash),
360 # but those of automatically checked features (STDC_HEADERS etc.)
361 # and symbols (PACKAGE_...).
362 # AT_CHECK_HEADER is a better name, but too close from AC_CHECK_HEADER.
363 m4_define([AT_CHECK_DEFINES],
364 [AT_CHECK([[sed '/#/!d
365 /INTTYPES/d
366 /MEMORY/d
367 /PACKAGE_/d
368 /STDC_HEADERS/d
369 /STDINT/d
370 /STDLIB/d
371 /STRING/d
372 /SYS_STAT/d
373 /SYS_TYPES/d
374 /UNISTD/d' config.h]],,
375           [$1])])
378 # AT_CHECK_AUTOUPDATE
379 # -------------------
380 m4_define([AT_CHECK_AUTOUPDATE],
381 [AT_CHECK([autoupdate $1], [$2], [$3], [$4])
385 # _AT_CHECK_AC_MACRO(AC-BODY, PRE-TESTS)
386 # --------------------------------------
387 # Create a minimalist configure.ac running the macro named
388 # NAME-OF-THE-MACRO, check that autoconf runs on that script,
389 # and that the shell runs correctly the configure.
390 m4_define([_AT_CHECK_AC_MACRO],
391 [AT_CONFIGURE_AC([$1])
393 AT_CHECK_AUTOCONF
394 AT_CHECK_AUTOHEADER
395 AT_CHECK_CONFIGURE
396 AT_CHECK_ENV
397 ])# _AT_CHECK_AC_MACRO
400 # AT_CHECK_MACRO(MACRO, [MACRO-USE], [ADDITIONAL-CMDS],
401 #                [AUTOCONF-FLAGS = -W obsolete])
402 # -----------------------------------------------------
403 # Create a minimalist configure.ac running the macro named
404 # NAME-OF-THE-MACRO, check that autoconf runs on that script,
405 # and that the shell runs correctly the configure.
407 # We run `configure' twice, both times with a cache, and compare
408 # the environment after each run to detect inconsistencies.
410 # New macros are not expected to depend upon obsolete macros.
411 m4_define([AT_CHECK_MACRO],
412 [AT_SETUP([$1])
414 AT_CONFIGURE_AC([m4_default([$2], [$1])])
416 AT_CHECK_AUTOCONF([m4_default([$4], [-W obsolete])])
417 AT_CHECK_AUTOHEADER
419 for at_run in r1 r2
421     AT_CHECK_CONFIGURE([-C])
422     cp -f state-env.after state-env.$at_run
423     cp -f config.h config-h.$at_run
424     AT_CHECK_ENV
425 done
427 AT_CMP([config-h.r1], [config-h.r2])
428 AT_CONFIG_CMP([state-env.r1], [state-env.r2])
432 AT_CLEANUP()dnl
433 ])# AT_CHECK_MACRO
436 # AT_CHECK_MACRO_CROSS(MACRO, [MACRO-USE], [ADDITIONAL-CMDS],
437 #                      [AUTOCONF-FLAGS = -W obsolete])
438 # -----------------------------------------------------------
439 # Like the previous one, but creates two checks: for native
440 # compile and for cross-compile.
441 m4_define([AT_CHECK_MACRO_CROSS],
442 [AT_CHECK_MACRO($@)
443 AT_CHECK_MACRO([$1 (cross compile)],
444   [AT_KEYWORDS([cross])
445   # Exercise the code used when cross-compiling.
446   cross_compiling=yes
447   ac_tool_warned=yes
448   m4_default([$2], [$1])],
449   [$3], [$4])
453 # AT_CHECK_AU_MACRO(MACRO)
454 # ------------------------
455 # Create a minimalist configure.ac running the macro named
456 # NAME-OF-THE-MACRO, autoupdate this script, check that autoconf runs
457 # on that script, and that the shell runs correctly the configure.
459 # Updated configure.ac shall not depend upon obsolete macros, which votes
460 # in favor of `-W obsolete', but since many of these macros leave a message
461 # to be removed by the user once her code is adjusted, let's not check.
463 # Remove config.hin to avoid `autoheader: config.hin is unchanged'.
464 m4_define([AT_CHECK_AU_MACRO],
465 [AT_SETUP([$1])
466 AT_KEYWORDS([autoupdate])
468 AT_CONFIGURE_AC([$1])
470 AT_CHECK_AUTOCONF
471 AT_CHECK_AUTOHEADER
472 AT_CHECK_CONFIGURE
473 AT_CHECK_ENV
475 rm config.hin
476 AT_CHECK_AUTOUPDATE([], 0, [], ignore)
477 AT_CHECK([grep '^$1$' configure.ac], 1)
479 AT_CHECK_AUTOCONF
480 AT_CHECK_AUTOHEADER
481 AT_CHECK_CONFIGURE
482 AT_CHECK_ENV
484 AT_CLEANUP()dnl
485 ])# AT_CHECK_AU_MACRO
489 ## ----------------------- ##
490 ## Launch the test suite.  ##
491 ## ----------------------- ##
493 AT_INIT
494 AT_COPYRIGHT(
495 [Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006 Free Software
496 Foundation, Inc.
497 This is free software; see the source for copying conditions.  There is NO
498 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.])