Adjust to recent m4 1.6 change to support m4_debugmode(d).
[autoconf.git] / tests / local.at
bloba772a97a364985b2daac9d86143115225e219eea
1 # M4 macros used in building Autoconf test suites.        -*- Autotest -*-
3 # Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008
4 # Free Software 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 # Programs this package provides
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.
68 # This (using GNU M4 1.4.6)
70 #  /usr/local/bin/m4:script.4s:1: cannot open `foo': No such file or directory
71 #  autom4te: /usr/local/bin/m4 failed with exit status: 1
73 # or this (GNU M4 1.4.11)
75 #  /usr/local/bin/m4:script.4s:1: include: cannot open `foo': No such file or directory
76 #  autom4te: /usr/local/bin/m4 failed with exit status: 1
78 # or this (GNU M4 1.4 installed as gm4)
80 #  script.4s:1: /usr/local/bin/gm4: Cannot open foo: No such file or directory
81 #  autom4te: /usr/local/bin/gm4 failed with exit status: 1
83 # becomes
85 #  m4:script.4s:1: cannot open `foo': No such file or directory
86 #  autom4te: m4 failed with exit status: 1
88 # We use the following sed patterns:
90 #     (m4): ?(file): ?(line):
91 # or  (file): ?(line): ?(m4):
92 # to  m4:(file):(line):
94 # and
95 #     m4:(file):(line): Cannot open foo:
96 # or  m4:(file):(line): include: cannot open `foo':
97 # to  m4:(file):(line): cannot open `foo':
99 # and
100 #     autom4te: [^ ]m4
101 # or  autom4te: [^ ]m4.exe
102 # to  autom4te: m4
104 # Moreover, DJGPP error messages include the error code in brackets;
105 # remove the error code during normalization.
107 m4_define([AT_CHECK_M4],
108 [AT_CHECK([$1], [$2], [$3],
109           m4_case([$4], [], [], [ignore], [ignore], [stderr]))
110 m4_case([$4], [], [], [ignore], [],
111 [AT_CHECK([[sed 's/^[^:]*m4[.ex]*: *\([^:]*:\) *\([0-9][0-9]*: \)/m4:\1\2/
112         s/^\([^:]*:\) *\([0-9][0-9]*:\)[^:]*m4[.ex]*: /m4:\1\2 /
113         s/: C\(annot open \)\([^`:]*\):/: c\1`\2'\'':/
114         s/: include:\( cannot open\)/:\1/
115         s/^autom4te: [^ ]*m4[.ex]* /autom4te: m4 /
116         s/ (E[A-Z]*)$//
117     ' stderr >&2]], [0], [], [$4])])
120 # AT_CHECK_AUTOM4TE(FLAGS, [EXIT-STATUS = 0], STDOUT, STDERR)
121 # -----------------------------------------------------------
122 m4_define([AT_CHECK_AUTOM4TE],
123 [AT_CHECK_M4([autom4te $1], [$2], [$3], [$4])])
127 ## ----------------- ##
128 ## Testing M4sugar.  ##
129 ## ----------------- ##
132 # AT_DATA_M4SUGAR(FILE-NAME, CONTENTS)
133 # ------------------------------------
134 # Escape the invalid tokens with @&t@.
135 m4_define([AT_DATA_M4SUGAR],
136 [AT_DATA([$1],
137 [m4_bpatsubsts([$2],
138                [@&t@],    [@&@&t@t@],
139                [\(m4\)_], [\1@&t@_],
140                [dnl],     [d@&t@nl])])])
143 # AT_CHECK_M4SUGAR(FLAGS, [EXIT-STATUS = 0], STDOUT, STDERR)
144 # ----------------------------------------------------------
145 m4_define([AT_CHECK_M4SUGAR],
146 [AT_KEYWORDS([m4sugar])
147 AT_CHECK_AUTOM4TE([--language=m4sugar script.4s -o script $1],
148                    [$2], [$3], [$4])])
152 ## -------------- ##
153 ## Testing M4sh.  ##
154 ## -------------- ##
157 # AT_DATA_M4SH(FILE-NAME, CONTENTS)
158 # ---------------------------------
159 # Escape the invalid tokens with @&t@.
160 m4_define([AT_DATA_M4SH],
161 [AT_DATA([$1],
162 [m4_bpatsubsts([$2],
163                [@&t@],        [@&@&t@t@],
164                [\(m4\|AS\)_], [\1@&t@_],
165                [dnl],         [d@&t@nl])])])
168 # AT_CHECK_M4SH(FLAGS, [EXIT-STATUS = 0], STDOUT, STDERR)
169 # -------------------------------------------------------
170 m4_define([AT_CHECK_M4SH],
171 [AT_CHECK_AUTOM4TE([--language=m4sh script.as -o script $1],
172                    [$2], [$3], [$4])])
176 ## ------------------ ##
177 ## Testing Autoconf.  ##
178 ## ------------------ ##
181 # AT_DATA_AUTOCONF(FILE-NAME, CONTENTS)
182 # -------------------------------------
183 # Escape the invalid tokens with @&t@.
184 m4_define([AT_DATA_AUTOCONF],
185 [AT_DATA([$1],
186 [m4_bpatsubsts([$2],
187                [@&t@],            [@&@&t@t@],
188                [\(m4\|AS\|AC\)_], [\1@&t@_],
189                [dnl],             [d@&t@nl])])])
193 # AT_CONFIGURE_AC(BODY)
194 # ---------------------
195 # Create a full configure.ac running BODY, with a config header set up,
196 # AC_OUTPUT, and environment checking hooks.
197 m4_define([AT_CONFIGURE_AC],
198 [AT_DATA_AUTOCONF([aclocal.m4],
200 # AC_STATE_SAVE(FILE)
201 # -------------------
202 # Save the shell variables and directory listing.  AT_CHECK_ENV uses these to
203 # confirm that no test modifies variables outside the Autoconf namespace or
204 # leaves temporary files.  AT_CONFIG_CMP uses the variable dumps to confirm that
205 # tests have the same side effects regardless of caching.
206 m4_defun([AC_STATE_SAVE],
207 [(set) 2>&1 | sort >state-env.$][1
208 ls -1 | sed '/^at-/d;/^state-/d;/^config\./d' | sort >state-ls.$][1
209 ])# AC_STATE_SAVE
212 AT_DATA([configure.ac],
213 [[AC_INIT
214 AC_CONFIG_HEADERS(config.h:config.hin)
215 AC_STATE_SAVE(before)]
217 [AC_OUTPUT
218 AC_STATE_SAVE(after)
220 cp "$abs_top_srcdir/build-aux/install-sh" \
221    "$abs_top_srcdir/build-aux/config.guess" \
222    "$abs_top_srcdir/build-aux/config.sub" .
223 ])# AT_CONFIGURE_AC
226 # AT_CHECK_AUTOCONF(ARGS, [EXIT-STATUS = 0], STDOUT, STDERR)
227 # ----------------------------------------------------------
228 # We always use "--force", to prevent problems with timestamps if the testsuite
229 # were running too fast.
230 m4_define([AT_CHECK_AUTOCONF],
231 [AT_CHECK_M4([autoconf --force $1], [$2], [$3], [$4])
232 if test -s configure; then
233   AT_CHECK_SHELL_SYNTAX(configure)
238 # AT_CHECK_AUTOHEADER(ARGS, [EXIT-STATUS = 0], STDOUT, STDERR)
239 # ------------------------------------------------------------
240 m4_define([AT_CHECK_AUTOHEADER],
241 [AT_CHECK([autoheader $1], [$2], [$3], [$4])
245 # AT_CHECK_CONFIGURE(END-COMMAND,
246 #                    [EXIT-STATUS = 0],
247 #                    [STDOUT = IGNORE], STDERR)
248 # --------------------------------------------
249 # `abs_top_srcdir' is needed so that `./configure' finds install-sh.
250 # Using --srcdir is more expensive.
251 m4_define([AT_CHECK_CONFIGURE],
252 [AT_CAPTURE_FILE([config.log])[]dnl
253  AT_CHECK([./configure $1],
254           [$2],
255           m4_default([$3], [ignore]), [$4])])
258 # AT_CHECK_ENV
259 # ------------
260 # Check that the full configure run remained in its variable name space,
261 # and cleaned up tmp files.
263 # Perhaps grep -E is not supported, or perhaps it chokes on such a big regex.
264 # In this case just don't pay attention to the env.  It would be great
265 # to keep the error message but we can't: that would break AT_CHECK.
267 # Some tests might exit prematurely when they find a problem, in
268 # which case `env-after' is probably missing.  Don't check it then.
270 # Here are the variables `configure' may modify during execution:
271 # - ^as_
272 #   M4sh's shell name space.
273 # - ^ac_
274 #   Autoconf's shell name space.
275 # - prefix and exec_prefix
276 #   are kept undefined (NONE) until AC_OUTPUT which then sets them to
277 #   `/usr/local' and `${prefix}' for make.
278 # - (host|build|target)(_(alias|cpu|vendor|os))?
279 #   Set by AC_CANONICAL_(HOST|BUILD|TARGET).
280 # - cross_compiling
281 #   Set by AC_INIT.
282 # - interpval
283 #   Set by AC_SYS_INTERPRETER.
284 # - CONFIG_STATUS and DEFS
285 #   Set by AC_OUTPUT.
286 # - AC_SUBST'ed variables
287 #   (FIXME: Generate a list of these automatically.)
288 # - _|@|.[*#?$].|LINENO|OLDPWD|PIPESTATUS|RANDOM|SECONDS
289 #   Some variables some shells use and change.
290 #   `.[*#?$].' catches `$#' etc. which are displayed like this:
291 #      | '!'=18186
292 #      | '#'=0
293 #      | '$'=6908
295 m4_define([AT_CHECK_ENV],
296 [# Compare directory listings.
297 test -f state-ls.before ||
298   AS_ERROR([state-ls.before not present])
299 test -f state-ls.after && { AT_CMP([state-ls.before], [state-ls.after]) }
300 # Compare variable space dumps.
301 if test -f state-env.before && test -f state-env.after; then
302   for act_file in state-env.before state-env.after
303   do
304     $EGREP -v '^(m4_join([|],
305       [a[cs]_.*],
306       [(exec_)?prefix|DEFS|CONFIG_STATUS],
307       [CC|CFLAGS|CPP|GCC|CXX|CXXFLAGS|CXXCPP|GXX|F77|FFLAGS|FLIBS|G77],
308       [ERL|ERLC|ERLCFLAGS|ERLANG_PATH_ERL|ERLANG_ROOT_DIR|ERLANG_LIB_DIR],
309       [ERLANG_INSTALL_LIB_DIR|OBJC|OBJCPP|OBJCFLAGS],
310       [OPENMP_CFLAGS],
311       [LIBS|LIB@&t@OBJS|LTLIBOBJS|LDFLAGS],
312       [INSTALL(_(DATA|PROGRAM|SCRIPT))?],
313       [CYGWIN|ISC|MINGW32|MINIX|EMXOS2|XENIX|EXEEXT|OBJEXT],
314       [X_(CFLAGS|(EXTRA_|PRE_)?LIBS)|x_(includes|libraries)|(have|no)_x],
315       [(host|build|target)(_(alias|cpu|vendor|os))?],
316       [cross_compiling],
317       [interpval|PATH_SEPARATOR],
318       [F77_DUMMY_MAIN|f77_(case|underscore)],
319       [FC(_DUMMY_MAIN|FLAGS|LIBS|FLAGS_f)?],
320       [ALLOCA|GETLOADAVG_LIBS|KMEM_GROUP|NEED_SETGID|POW_LIB],
321       [AWK|LEX|LEXLIB|LEX_OUTPUT_ROOT|LN_S|M4|MKDIR_P|RANLIB|SET_MAKE|YACC],
322       [GREP|[EF]GREP|SED],
323       [[_@]|.[*#?$].|LINENO|OLDPWD|PIPESTATUS|RANDOM|SECONDS]))=' \
324      $act_file 2>/dev/null |
325       # There may be variables spread on several lines; remove latter lines.
326       $GREP '^m4_defn([m4_re_word])=' >clean-$act_file
327   done
328   AT_CMP([clean-state-env.before], [clean-state-env.after])
333 # AT_CONFIG_CMP(VAR-FILE-A, VAR-FILE-B)
334 # -------------------------------------
335 # Check the outcomes of two configure runs for equality by comparing dumps of
336 # their shell variables.  VAR-FILE-A and VAR-FILE-B are two `set'-style shell
337 # variable space dumps.
339 # We permit variance between runs in the following shell variables:
340 # - ^as_
341 #   M4sh's shell name space.
342 # - ^ac_, excluding ^ac_cv_
343 #   Autoconf's private shell name space.
344 # - PPID [bash, zsh]
345 # - RANDOM [zsh]
346 # - SECONDS [zsh]
347 # - '$' [zsh]
349 # Furthermore, it is okay for a non-cache variable initialized to empty in one
350 # run to be unset in another run.  This happens when, for example, cache update
351 # code tries a number of values in LIBS and eventually restores LIBS to its
352 # original value. If LIBS was previously unset, it will have become set and
353 # empty.  (OTOH, cache variables indicate the result of the test even if they
354 # are empty, so we have to be strict about them.)
356 # Lines that do not look like `foo=bar' are probably latter lines of
357 # multiline values; trim them.
359 m4_define([AT_CONFIG_CMP],
360 [for act_file in $1 $2
362   $SED '/^ac_cv_/ b
363         /^m4_defn([m4_re_word])=./ !d
364         /^[[^=]]*='\'''\''$/ d
365         /^a[[cs]]_/ d
366         /^PPID=/ d
367         /^RANDOM=/ d
368         /^SECONDS=/ d
369         /'\'\\\$\''=/ d
370         ' $act_file >at_config_vars-$act_file
371 done
372 AT_CMP([at_config_vars-$1], [at_config_vars-$2])[]dnl
373 ])# AT_CONFIG_CMP
376 # AT_CHECK_DEFINES(CONTENT)
377 # -------------------------
378 # Verify that config.h, once stripped, is CONTENT.
379 # Stripping consists of keeping CPP lines (i.e. containing a hash),
380 # but those of automatically checked features (STDC_HEADERS etc.)
381 # and symbols (PACKAGE_...).
382 # AT_CHECK_HEADER is a better name, but too close from AC_CHECK_HEADER.
383 m4_define([AT_CHECK_DEFINES],
384 [AT_CHECK([[sed '/#/!d
385 /INTTYPES/d
386 /MEMORY/d
387 /PACKAGE_/d
388 /STDC_HEADERS/d
389 /STDINT/d
390 /STDLIB/d
391 /STRING/d
392 /SYS_STAT/d
393 /SYS_TYPES/d
394 /UNISTD/d' config.h]],,
395           [$1])])
398 # AT_CHECK_AUTOUPDATE
399 # -------------------
400 m4_define([AT_CHECK_AUTOUPDATE],
401 [AT_CHECK([autoupdate $1], [$2], [$3], [$4])
405 # _AT_CHECK_AC_MACRO(AC-BODY, PRE-TESTS)
406 # --------------------------------------
407 # Create a minimalist configure.ac running the macro named
408 # NAME-OF-THE-MACRO, check that autoconf runs on that script,
409 # and that the shell runs correctly the configure.
410 m4_define([_AT_CHECK_AC_MACRO],
411 [AT_CONFIGURE_AC([$1])
413 AT_CHECK_AUTOCONF
414 AT_CHECK_AUTOHEADER
415 AT_CHECK_CONFIGURE
416 AT_CHECK_ENV
417 ])# _AT_CHECK_AC_MACRO
420 # AT_CHECK_MACRO(MACRO, [MACRO-USE], [ADDITIONAL-CMDS],
421 #                [AUTOCONF-FLAGS = -W obsolete])
422 # -----------------------------------------------------
423 # Create a minimalist configure.ac running the macro named
424 # NAME-OF-THE-MACRO, check that autoconf runs on that script,
425 # and that the shell runs correctly the configure.
427 # We run `configure' twice, both times with a cache, and compare
428 # the environment after each run to detect inconsistencies.
430 # New macros are not expected to depend upon obsolete macros.
431 m4_define([AT_CHECK_MACRO],
432 [AT_SETUP([$1])
434 AT_CONFIGURE_AC([m4_default([$2], [$1])])
436 AT_CHECK_AUTOCONF([m4_default([$4], [-W obsolete])])
437 AT_CHECK_AUTOHEADER
439 for at_run in r1 r2
441     AT_CHECK_CONFIGURE([-C])
442     cp -f state-env.after state-env.$at_run
443     cp -f config.h config-h.$at_run
444     AT_CHECK_ENV
445 done
447 AT_CMP([config-h.r1], [config-h.r2])
448 AT_CONFIG_CMP([state-env.r1], [state-env.r2])
452 AT_CLEANUP[]dnl
453 ])# AT_CHECK_MACRO
456 # AT_CHECK_MACRO_CROSS(MACRO, [MACRO-USE], [ADDITIONAL-CMDS],
457 #                      [AUTOCONF-FLAGS = -W obsolete])
458 # -----------------------------------------------------------
459 # Like the previous one, but creates two checks: for native
460 # compile and for cross-compile.
461 m4_define([AT_CHECK_MACRO_CROSS],
462 [AT_CHECK_MACRO($@)
463 AT_CHECK_MACRO([$1 (cross compile)],
464   [AT_KEYWORDS([cross])
465   # Exercise the code used when cross-compiling.
466   cross_compiling=yes
467   ac_tool_warned=yes
468   m4_default([$2], [$1])],
469   [$3], [$4])
473 # AT_CHECK_AU_MACRO(MACRO)
474 # ------------------------
475 # Create a minimalist configure.ac running the macro named
476 # NAME-OF-THE-MACRO, autoupdate this script, check that autoconf runs
477 # on that script, and that the shell runs correctly the configure.
479 # Updated configure.ac shall not depend upon obsolete macros, which votes
480 # in favor of `-W obsolete', but since many of these macros leave a message
481 # to be removed by the user once her code is adjusted, let's not check.
483 # Remove config.hin to avoid `autoheader: config.hin is unchanged'.
484 m4_define([AT_CHECK_AU_MACRO],
485 [AT_SETUP([$1])
486 AT_KEYWORDS([autoupdate])
488 AT_CONFIGURE_AC([$1])
490 AT_CHECK_AUTOCONF
491 AT_CHECK_AUTOHEADER
492 AT_CHECK_CONFIGURE
493 AT_CHECK_ENV
495 rm config.hin
496 AT_CHECK_AUTOUPDATE([], 0, [], ignore)
497 AT_CHECK([grep '^$1$' configure.ac], 1)
499 AT_CHECK_AUTOCONF
500 AT_CHECK_AUTOHEADER
501 AT_CHECK_CONFIGURE
502 AT_CHECK_ENV
504 AT_CLEANUP[]dnl
505 ])# AT_CHECK_AU_MACRO
509 ## ----------------------- ##
510 ## Launch the test suite.  ##
511 ## ----------------------- ##
513 AT_INIT
514 AT_COPYRIGHT(
515 [Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007 Free Software
516 Foundation, Inc.
517 This is free software; see the source for copying conditions.  There is NO
518 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.])