1 # M4 macros used in building Autoconf test suites. -*- Autotest -*-
3 # Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008,
4 # 2009, 2010 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 3 of the License, or
9 # (at your option) 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, see <http://www.gnu.org/licenses/>.
19 m4_version_prereq([2.57])
22 m4_pattern_allow([^AS_EXIT$])
23 m4_pattern_allow([^m4_(define|shift)$])
25 # Programs this package provides
26 AT_TESTED([autom4te autoconf autoheader autoupdate autoreconf ifnames])
28 # Enable colored test output.
31 ## ---------------- ##
33 ## ---------------- ##
35 # AT_CMP(FILE-1, FILE-2)
36 # ----------------------
37 # Check FILE-1 and FILE-2 for equality, like `cmp FILE-1 FILE-2'.
39 [m4_ifval([$2],, [m4_fatal([AT_CMP takes two arguments.])])[]dnl
40 AT_CHECK([$at_diff "$1" "$2"])
44 ## ---------------- ##
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 [AT_SKIP_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],
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
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):
95 # m4:(file):(line): Cannot open foo:
96 # or m4:(file):(line): include: cannot open `foo':
97 # to m4:(file):(line): cannot open `foo':
101 # or autom4te: [^ ]m4.exe
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 /
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],
137 [m4_bpatsubst([$2], [\(@.\)\(.@\)\|\(m4\)\(_\)\|\(d\)\(nl\)],
138 [\1\3\5@&t@\2\4\6])])])
141 # AT_CHECK_M4SUGAR(FLAGS, [EXIT-STATUS = 0], STDOUT, STDERR)
142 # ----------------------------------------------------------
143 m4_define([AT_CHECK_M4SUGAR],
144 [AT_KEYWORDS([m4sugar])
145 AT_CHECK_AUTOM4TE([--language=m4sugar script.4s -o script $1],
155 # AT_DATA_M4SH(FILE-NAME, CONTENTS)
156 # ---------------------------------
157 # Escape the invalid tokens with @&t@.
158 m4_define([AT_DATA_M4SH],
160 [m4_bpatsubst([$2], [\(@.\)\(.@\)\|\(m4\|AS\)\(_\)\|\(d\)\(nl\)],
161 [\1\3\5@&t@\2\4\6])])])
164 # AT_CHECK_M4SH(FLAGS, [EXIT-STATUS = 0], STDOUT, STDERR)
165 # -------------------------------------------------------
166 m4_define([AT_CHECK_M4SH],
167 [AT_CHECK_AUTOM4TE([--language=m4sh script.as -o script $1],
172 ## ------------------ ##
173 ## Testing Autoconf. ##
174 ## ------------------ ##
177 # AT_DATA_AUTOCONF(FILE-NAME, CONTENTS)
178 # -------------------------------------
179 # Escape the invalid tokens with @&t@.
180 m4_define([AT_DATA_AUTOCONF],
182 [m4_bpatsubst([$2], [\(@.\)\(.@\)\|\(m4\|AS\|AC\)\(_\)\|\(d\)\(nl\)],
183 [\1\3\5@&t@\2\4\6])])])
187 # AT_CONFIGURE_AC(BODY)
188 # ---------------------
189 # Create a full configure.ac running BODY, with a config header set up,
190 # AC_OUTPUT, and environment checking hooks.
191 m4_define([AT_CONFIGURE_AC],
192 [AT_DATA([configure.ac],
194 AC_CONFIG_HEADERS(config.h:config.hin)
195 AC_STATE_SAVE(before)]
200 cp "$abs_top_srcdir/build-aux/install-sh" \
201 "$abs_top_srcdir/build-aux/config.guess" \
202 "$abs_top_srcdir/build-aux/config.sub" .
203 cp "$abs_top_srcdir/tests/statesave.m4" aclocal.m4
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 && test "$ac_cv_sh_n_works" = yes; 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,
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([./configure $configure_options $1],
236 m4_default([$3], [ignore]), [$4])])
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 # FreeBSD sh may intermingle the trace output from the egrep and grep
249 # commands in the pipe, so turn off tracing for these.
251 # Some tests might exit prematurely when they find a problem, in
252 # which case `env-after' is probably missing. Don't check it then.
254 # Here are the variables `configure' may modify during execution:
256 # M4sh's shell name space.
258 # Autoconf's shell name space.
259 # - prefix and exec_prefix
260 # are kept undefined (NONE) until AC_OUTPUT which then sets them to
261 # `/usr/local' and `${prefix}' for make.
262 # - (host|build|target)(_(alias|cpu|vendor|os))?
263 # Set by AC_CANONICAL_(HOST|BUILD|TARGET).
267 # Set by AC_SYS_INTERPRETER.
268 # - CONFIG_STATUS and DEFS
270 # - AC_SUBST'ed variables
271 # (FIXME: Generate a list of these automatically.)
272 # - _|@|.[*#?$].|argv|ARGC|LINENO|OLDPWD|PIPESTATUS|RANDOM|SECONDS
273 # Some variables some shells use and change.
274 # `.[*#?$].' catches `$#' etc. which are displayed like this:
279 m4_define([AT_CHECK_ENV],
280 [m4_divert_once([PREPARE_TESTS], [_AT_CHECK_ENV])dnl
281 AT_CHECK([at_check_env])])
282 m4_define([_AT_CHECK_ENV],
283 [AS_FUNCTION_DESCRIBE([at_check_env], [],
284 [Compare the directory and environment state both before and after a run,
285 and return non-zero status if they differ inappropriately.])
288 # Compare directory listings.
289 test -f state-ls.before ||
290 AS_ERROR([state-ls.before not present])
291 test -f state-ls.after \
292 && { $at_diff state-ls.before state-ls.after || return 1; }
293 # Compare variable space dumps.
294 if test -f state-env.before && test -f state-env.after; then
296 for act_file in state-env.before state-env.after
298 $EGREP -v '^(m4_join([|],
300 [(exec_)?prefix|DEFS|CONFIG_STATUS],
301 [CC|CFLAGS|CPP|GCC|CXX|CXXFLAGS|CXXCPP|GXX|F77|FFLAGS|FLIBS|G77],
302 [ERL|ERLC|ERLCFLAGS|ERLANG_PATH_ERL|ERLANG_ROOT_DIR|ERLANG_LIB_DIR],
303 [ERLANG_LIB_DIR_.*|ERLANG_LIB_VER_.*|ERLANG_INSTALL_LIB_DIR],
304 [ERLANG_INSTALL_LIB_DIR_.*|ERLANG_ERTS_VER|OBJC|OBJCPP|OBJCFLAGS],
305 [OBJCXX|OBJCXXCPP|OBJCXXFLAGS],
307 [LIBS|LIB@&t@OBJS|LTLIBOBJS|LDFLAGS],
308 [INSTALL(_(DATA|PROGRAM|SCRIPT))?],
309 [CYGWIN|ISC|MINGW32|MINIX|EMXOS2|XENIX|EXEEXT|OBJEXT],
310 [X_(CFLAGS|(EXTRA_|PRE_)?LIBS)|x_(includes|libraries)|(have|no)_x],
311 [(host|build|target)(_(alias|cpu|vendor|os))?],
313 [interpval|PATH_SEPARATOR],
314 [F77_DUMMY_MAIN|f77_(case|underscore)],
315 [FC(_DUMMY_MAIN|FLAGS|LIBS|FLAGS_f)?],
316 [ALLOCA|GETLOADAVG_LIBS|KMEM_GROUP|NEED_SETGID|POW_LIB],
317 [AWK|LEX|LEXLIB|LEX_OUTPUT_ROOT|LN_S|M4|MKDIR_P|RANLIB|SET_MAKE|YACC],
320 [argv|ARGC|LINENO|OLDPWD|PIPESTATUS|RANDOM|SECONDS]))=' \
321 $act_file 2>/dev/null |
322 # There may be variables spread on several lines; remove latter lines.
323 $GREP '^m4_defn([m4_re_word])=' >clean-$act_file
326 $at_diff clean-state-env.before clean-state-env.after
331 # AT_CONFIG_CMP(VAR-FILE-A, VAR-FILE-B)
332 # -------------------------------------
333 # Check the outcomes of two configure runs for equality by comparing dumps of
334 # their shell variables. VAR-FILE-A and VAR-FILE-B are two `set'-style shell
335 # variable space dumps.
337 # We permit variance between runs in the following shell variables:
339 # M4sh's shell name space.
340 # - ^ac_, excluding ^ac_cv_
341 # Autoconf's private shell name space.
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
363 /^m4_defn([m4_re_word])=./ !d
364 /^[[^=]]*='\'''\''$/ d
372 ' $act_file >at_config_vars-$act_file
374 AT_CMP([at_config_vars-$1], [at_config_vars-$2])[]dnl
378 # AT_CHECK_DEFINES(CONTENT)
379 # -------------------------
380 # Verify that config.h, once stripped, is CONTENT.
381 # Stripping consists of keeping CPP lines (i.e. containing a hash),
382 # but those of automatically checked features (STDC_HEADERS etc.)
383 # and symbols (PACKAGE_...).
384 # AT_CHECK_HEADER is a better name, but too close from AC_CHECK_HEADER.
385 m4_define([AT_CHECK_DEFINES],
386 [AT_CHECK([[sed '/#/!d
396 /UNISTD/d' config.h]],,
400 # AT_CHECK_AUTOUPDATE
401 # -------------------
402 m4_define([AT_CHECK_AUTOUPDATE],
403 [AT_CHECK([autoupdate $1], [$2], [$3], [$4])
407 # _AT_CHECK_AC_MACRO(AC-BODY, PRE-TESTS)
408 # --------------------------------------
409 # Create a minimalist configure.ac running the macro named
410 # NAME-OF-THE-MACRO, check that autoconf runs on that script,
411 # and that the shell runs correctly the configure.
412 m4_define([_AT_CHECK_AC_MACRO],
413 [AT_CONFIGURE_AC([$1])
419 ])# _AT_CHECK_AC_MACRO
422 # AT_CHECK_MACRO(MACRO, [MACRO-USE], [ADDITIONAL-CMDS],
423 # [AUTOCONF-FLAGS = -W obsolete])
424 # -----------------------------------------------------
425 # Create a minimalist configure.ac running the macro named
426 # NAME-OF-THE-MACRO, check that autoconf runs on that script,
427 # and that the shell runs correctly the configure.
429 # We run `configure' twice, both times with a cache, and compare
430 # the environment after each run to detect inconsistencies.
432 # New macros are not expected to depend upon obsolete macros.
433 m4_define([AT_CHECK_MACRO],
436 AT_CONFIGURE_AC([m4_default([$2], [$1])])
438 AT_CHECK_AUTOCONF([m4_default([$4], [-W obsolete])])
443 AT_CHECK_CONFIGURE([-C])
444 cp -f state-env.after state-env.$at_run
445 cp -f config.h config-h.$at_run
449 AT_CMP([config-h.r1], [config-h.r2])
450 AT_CONFIG_CMP([state-env.r1], [state-env.r2])
458 # AT_CHECK_MACRO_CROSS(MACRO, [MACRO-USE], [ADDITIONAL-CMDS],
459 # [AUTOCONF-FLAGS = -W obsolete])
460 # -----------------------------------------------------------
461 # Like the previous one, but creates two checks: for native
462 # compile and for cross-compile.
463 m4_define([AT_CHECK_MACRO_CROSS],
465 AT_CHECK_MACRO([$1 (cross compile)],
466 [AT_KEYWORDS([cross])
467 # Exercise the code used when cross-compiling.
470 m4_default([$2], [$1])],
475 # AT_CHECK_AU_MACRO(MACRO)
476 # ------------------------
477 # Create a minimalist configure.ac running the macro named
478 # NAME-OF-THE-MACRO, autoupdate this script, check that autoconf runs
479 # on that script, and that the shell runs correctly the configure.
481 # Updated configure.ac shall not depend upon obsolete macros, which votes
482 # in favor of `-W obsolete', but since many of these macros leave a message
483 # to be removed by the user once her code is adjusted, let's not check.
485 # Remove config.hin to avoid `autoheader: config.hin is unchanged'.
486 m4_define([AT_CHECK_AU_MACRO],
488 AT_KEYWORDS([autoupdate])
490 AT_CONFIGURE_AC([$1])
498 AT_CHECK_AUTOUPDATE([], 0, [], ignore)
499 AT_CHECK([grep '^$1$' configure.ac], 1)
507 ])# AT_CHECK_AU_MACRO
511 ## ----------------------- ##
512 ## Launch the test suite. ##
513 ## ----------------------- ##