1 # M4 macros used in building Autoconf test suites. -*- Autotest -*-
3 # Copyright (C) 2000-2012 Free Software Foundation, Inc.
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18 m4_version_prereq([2.57])
21 m4_pattern_allow([^AS_EXIT$])
22 m4_pattern_allow([^m4_(define|shift)$])
24 # Programs this package provides
25 AT_TESTED([autom4te autoconf autoheader autoupdate autoreconf ifnames])
27 # Enable colored test output.
30 ## ---------------- ##
32 ## ---------------- ##
34 # AT_CMP(FILE-1, FILE-2)
35 # ----------------------
36 # Check FILE-1 and FILE-2 for equality, like `cmp FILE-1 FILE-2'.
38 [m4_ifval([$2],, [m4_fatal([AT_CMP takes two arguments.])])[]dnl
39 AT_CHECK([$at_diff "$1" "$2"])
43 ## ---------------- ##
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 [AT_SKIP_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],
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)
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.11)
74 # /usr/local/bin/m4:script.4s:1: include: cannot open `foo': No such file or directory
75 # autom4te: /usr/local/bin/m4 failed with exit status: 1
77 # or this (GNU M4 1.4 installed as gm4)
79 # script.4s:1: /usr/local/bin/gm4: Cannot open foo: No such file or directory
80 # autom4te: /usr/local/bin/gm4 failed with exit status: 1
82 # or this (GNU M4 1.4.13 installed as m4-1.4.13):
84 # /usr/bin/m4-1.4.13:script.4s:1: include: cannot open `foo': No such file or directory
85 # autom4te: /usr/bin/m4-1.4.13 failed with exit status: 1
89 # m4:script.4s:1: cannot open `foo': No such file or directory
90 # autom4te: m4 failed with exit status: 1
92 # We use the following sed patterns:
94 # (m4): ?(file): ?(line):
95 # or (file): ?(line): ?(m4):
96 # to m4:(file):(line):
99 # m4:(file):(line): Cannot open foo:
100 # or m4:(file):(line): include: cannot open `foo':
101 # to m4:(file):(line): cannot open `foo':
105 # or autom4te: [^ ]m4.exe
108 # Moreover, DJGPP error messages include the error code in brackets;
109 # remove the error code during normalization.
111 m4_define([AT_CHECK_M4],
112 [AT_CHECK([$1], [$2], [$3],
113 m4_case([$4], [], [], [ignore], [ignore], [stderr]))
114 m4_case([$4], [], [], [ignore], [],
115 [AT_CHECK([[sed 's/^[^:]*m4[-.ex0-9]*: *\([^:]*:\) *\([0-9][0-9]*: \)/m4:\1\2/
116 s/^\([^:]*:\) *\([0-9][0-9]*:\)[^:]*m4[-.ex0-9]*: /m4:\1\2 /
117 s/: C\(annot open \)\([^`:]*\):/: c\1`\2'\'':/
118 s/: include:\( cannot open\)/:\1/
119 s/^autom4te: [^ ]*m4[.ex]* /autom4te: m4 /
121 ' stderr >&2]], [0], [], [$4])])
124 # AT_CHECK_AUTOM4TE(FLAGS, [EXIT-STATUS = 0], STDOUT, STDERR)
125 # -----------------------------------------------------------
126 m4_define([AT_CHECK_AUTOM4TE],
127 [AT_CHECK_M4([autom4te $1], [$2], [$3], [$4])])
131 ## ----------------- ##
132 ## Testing M4sugar. ##
133 ## ----------------- ##
136 # AT_DATA_M4SUGAR(FILE-NAME, CONTENTS)
137 # ------------------------------------
138 # Escape the invalid tokens with @&t@.
139 m4_define([AT_DATA_M4SUGAR],
141 [m4_bpatsubst([$2], [\(@.\)\(.@\)\|\(m4\)\(_\)\|\(d\)\(nl\)],
142 [\1\3\5@&t@\2\4\6])])])
145 # AT_CHECK_M4SUGAR(FLAGS, [EXIT-STATUS = 0], STDOUT, STDERR)
146 # ----------------------------------------------------------
147 m4_define([AT_CHECK_M4SUGAR],
148 [AT_KEYWORDS([m4sugar])
149 AT_CHECK_AUTOM4TE([--language=m4sugar script.4s -o script $1],
159 # AT_DATA_M4SH(FILE-NAME, CONTENTS)
160 # ---------------------------------
161 # Escape the invalid tokens with @&t@.
162 m4_define([AT_DATA_M4SH],
164 [m4_bpatsubst([$2], [\(@.\)\(.@\)\|\(m4\|AS\)\(_\)\|\(d\)\(nl\)],
165 [\1\3\5@&t@\2\4\6])])])
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],
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],
186 [m4_bpatsubst([$2], [\(@.\)\(.@\)\|\(m4\|AS\|AC\)\(_\)\|\(d\)\(nl\)],
187 [\1\3\5@&t@\2\4\6])])])
191 # AT_CONFIGURE_AC(BODY)
192 # ---------------------
193 # Create a full configure.ac running BODY, with a config header set up,
194 # AC_OUTPUT, and environment checking hooks.
195 m4_define([AT_CONFIGURE_AC],
196 [AT_DATA([configure.ac],
198 AC_CONFIG_HEADERS(config.h:config.hin)
199 AC_STATE_SAVE(before)]
204 cp "$abs_top_srcdir/build-aux/install-sh" \
205 "$abs_top_srcdir/build-aux/config.guess" \
206 "$abs_top_srcdir/build-aux/config.sub" .
207 cp "$abs_top_srcdir/tests/statesave.m4" aclocal.m4
211 # AT_CHECK_AUTOCONF(ARGS, [EXIT-STATUS = 0], STDOUT, STDERR)
212 # ----------------------------------------------------------
213 # We always use "--force", to prevent problems with timestamps if the testsuite
214 # were running too fast.
215 m4_define([AT_CHECK_AUTOCONF],
216 [AT_CHECK_M4([autoconf --force $1], [$2], [$3], [$4])
217 if test -s configure && test "$ac_cv_sh_n_works" = yes; then
218 AT_CHECK_SHELL_SYNTAX([configure])
223 # AT_CHECK_AUTOHEADER(ARGS, [EXIT-STATUS = 0], STDOUT, STDERR)
224 # ------------------------------------------------------------
225 m4_define([AT_CHECK_AUTOHEADER],
226 [AT_CHECK([autoheader $1], [$2], [$3], [$4])
230 # AT_CHECK_CONFIGURE(END-COMMAND,
232 # [STDOUT = IGNORE], STDERR)
233 # ---------------------------------------------
234 # `abs_top_srcdir' is needed so that `./configure' finds install-sh.
235 # Using --srcdir is more expensive.
236 m4_define([AT_CHECK_CONFIGURE],
237 [AT_CAPTURE_FILE([config.log])[]dnl
238 AT_CHECK([./configure $configure_options $1],
240 m4_default([$3], [ignore]), [$4])])
245 # Check that the full configure run remained in its variable name space,
246 # and cleaned up tmp files.
248 # Perhaps grep -E is not supported, or perhaps it chokes on such a big regex.
249 # In this case just don't pay attention to the env. It would be great
250 # to keep the error message but we can't: that would break AT_CHECK.
252 # FreeBSD sh may intermingle the trace output from the egrep and grep
253 # commands in the pipe, so turn off tracing for these.
255 # Some tests might exit prematurely when they find a problem, in
256 # which case `env-after' is probably missing. Don't check it then.
258 # Here are the variables `configure' may modify during execution:
260 # M4sh's shell name space.
262 # Autoconf's shell name space.
263 # - prefix and exec_prefix
264 # are kept undefined (NONE) until AC_OUTPUT which then sets them to
265 # `/usr/local' and `${prefix}' for make.
266 # - (host|build|target)(_(alias|cpu|vendor|os))?
267 # Set by AC_CANONICAL_(HOST|BUILD|TARGET).
271 # Set by AC_SYS_INTERPRETER.
272 # - CONFIG_STATUS and DEFS
274 # - AC_SUBST'ed variables
275 # (FIXME: Generate a list of these automatically.)
276 # - _|@|.[*#?$].|argv|ARGC|LINENO|OLDPWD|PIPESTATUS|RANDOM|SECONDS
277 # Some variables some shells use and change.
278 # `.[*#?$].' catches `$#' etc. which are displayed like this:
283 m4_define([AT_CHECK_ENV],
284 [m4_divert_once([PREPARE_TESTS], [_AT_CHECK_ENV])dnl
285 AT_CHECK([at_check_env])])
286 m4_define([_AT_CHECK_ENV],
287 [AS_FUNCTION_DESCRIBE([at_check_env], [],
288 [Compare the directory and environment state both before and after a run,
289 and return non-zero status if they differ inappropriately.])
292 # Compare directory listings.
293 test -f state-ls.before ||
294 AS_ERROR([state-ls.before not present])
295 test -f state-ls.after \
296 && { $at_diff state-ls.before state-ls.after || return 1; }
297 # Compare variable space dumps.
298 if test -f state-env.before && test -f state-env.after; then
300 for act_file in state-env.before state-env.after
302 $EGREP -v '^(m4_join([|],
304 [(exec_)?prefix|DEFS|CONFIG_STATUS],
305 [CC|CFLAGS|CPP|GCC|CXX|CXXFLAGS|CXXCPP|GXX|F77|FFLAGS|FLIBS|G77],
306 [ERL|ERLC|ERLCFLAGS|ERLANG_PATH_ERL|ERLANG_ROOT_DIR|ERLANG_LIB_DIR],
307 [ERLANG_LIB_DIR_.*|ERLANG_LIB_VER_.*|ERLANG_INSTALL_LIB_DIR],
308 [ERLANG_INSTALL_LIB_DIR_.*|ERLANG_ERTS_VER|OBJC|OBJCPP|OBJCFLAGS],
309 [OBJCXX|OBJCXXCPP|OBJCXXFLAGS],
312 [LIBS|LIB@&t@OBJS|LTLIBOBJS|LDFLAGS],
313 [INSTALL(_(DATA|PROGRAM|SCRIPT))?],
314 [CYGWIN|ISC|MINGW32|MINIX|EMXOS2|XENIX|EXEEXT|OBJEXT],
315 [X_(CFLAGS|(EXTRA_|PRE_)?LIBS)|x_(includes|libraries)|(have|no)_x],
316 [(host|build|target)(_(alias|cpu|vendor|os))?],
318 [interpval|PATH_SEPARATOR],
319 [GFC|F77_DUMMY_MAIN|f77_(case|underscore)],
320 [FC(_DUMMY_MAIN|FLAGS|LIBS|FLAGS_[fF]|_MODEXT|_MODINC|_MODOUT|_DEFINE)?],
321 [ALLOCA|GETLOADAVG_LIBS|KMEM_GROUP|NEED_SETGID|POW_LIB],
322 [AWK|LEX|LEXLIB|LEX_OUTPUT_ROOT|LN_S|M4|MKDIR_P|RANLIB|SET_MAKE|YACC],
325 [argv|ARGC|LINENO|OLDPWD|PIPESTATUS|RANDOM|SECONDS]))=' \
326 $act_file 2>/dev/null |
327 # There may be variables spread on several lines; remove latter lines.
328 $GREP '^m4_defn([m4_re_word])=' >clean-$act_file
331 $at_diff clean-state-env.before clean-state-env.after
336 # AT_CONFIG_CMP(VAR-FILE-A, VAR-FILE-B)
337 # -------------------------------------
338 # Check the outcomes of two configure runs for equality by comparing dumps of
339 # their shell variables. VAR-FILE-A and VAR-FILE-B are two `set'-style shell
340 # variable space dumps.
342 # We permit variance between runs in the following shell variables:
344 # M4sh's shell name space.
345 # - ^ac_, excluding ^ac_cv_
346 # Autoconf's private shell name space.
354 # Furthermore, it is okay for a non-cache variable initialized to empty in one
355 # run to be unset in another run. This happens when, for example, cache update
356 # code tries a number of values in LIBS and eventually restores LIBS to its
357 # original value. If LIBS was previously unset, it will have become set and
358 # empty. (OTOH, cache variables indicate the result of the test even if they
359 # are empty, so we have to be strict about them.)
361 # Lines that do not look like `foo=bar' are probably latter lines of
362 # multiline values; trim them.
364 m4_define([AT_CONFIG_CMP],
365 [for act_file in $1 $2
368 /^m4_defn([m4_re_word])=./ !d
369 /^[[^=]]*='\'''\''$/ d
378 ' $act_file >at_config_vars-$act_file
380 AT_CMP([at_config_vars-$1], [at_config_vars-$2])[]dnl
384 # AT_CHECK_DEFINES(CONTENT)
385 # -------------------------
386 # Verify that config.h, once stripped, is CONTENT.
387 # Stripping consists of keeping CPP lines (i.e. containing a hash),
388 # but those of automatically checked features (STDC_HEADERS etc.)
389 # and symbols (PACKAGE_...).
390 # AT_CHECK_HEADER is a better name, but too close from AC_CHECK_HEADER.
391 m4_define([AT_CHECK_DEFINES],
392 [AT_CHECK([[sed '/#/!d
402 /UNISTD/d' config.h]],,
406 # AT_CHECK_AUTOUPDATE
407 # -------------------
408 m4_define([AT_CHECK_AUTOUPDATE],
409 [AT_CHECK([autoupdate $1], [$2], [$3], [$4])
413 # _AT_CHECK_AC_MACRO(AC-BODY, PRE-TESTS)
414 # --------------------------------------
415 # Create a minimalist configure.ac running the macro named
416 # NAME-OF-THE-MACRO, check that autoconf runs on that script,
417 # and that the shell runs correctly the configure.
418 m4_define([_AT_CHECK_AC_MACRO],
419 [AT_CONFIGURE_AC([$1])
425 ])# _AT_CHECK_AC_MACRO
428 # AT_CHECK_MACRO(MACRO, [MACRO-USE], [ADDITIONAL-CMDS],
429 # [AUTOCONF-FLAGS = -W obsolete])
430 # -----------------------------------------------------
431 # Create a minimalist configure.ac running the macro named
432 # NAME-OF-THE-MACRO, check that autoconf runs on that script,
433 # and that the shell runs correctly the configure.
435 # We run `configure' twice, both times with a cache, and compare
436 # the environment after each run to detect inconsistencies.
438 # New macros are not expected to depend upon obsolete macros.
439 m4_define([AT_CHECK_MACRO],
442 AT_CONFIGURE_AC([m4_default([$2], [$1])])
444 AT_CHECK_AUTOCONF([m4_default([$4], [-W obsolete])])
449 AT_CHECK_CONFIGURE([-C])
450 cp -f state-env.after state-env.$at_run
451 cp -f config.h config-h.$at_run
455 AT_CMP([config-h.r1], [config-h.r2])
456 AT_CONFIG_CMP([state-env.r1], [state-env.r2])
464 # AT_CHECK_MACRO_CROSS(MACRO, [MACRO-USE], [ADDITIONAL-CMDS],
465 # [AUTOCONF-FLAGS = -W obsolete])
466 # -----------------------------------------------------------
467 # Like the previous one, but creates two checks: for native
468 # compile and for cross-compile.
469 m4_define([AT_CHECK_MACRO_CROSS],
471 AT_CHECK_MACRO([$1 (cross compile)],
472 [AT_KEYWORDS([cross])
473 # Exercise the code used when cross-compiling.
476 m4_default([$2], [$1])],
481 # AT_CHECK_AU_MACRO(MACRO)
482 # ------------------------
483 # Create a minimalist configure.ac running the macro named
484 # NAME-OF-THE-MACRO, autoupdate this script, check that autoconf runs
485 # on that script, and that the shell runs correctly the configure.
487 # Updated configure.ac shall not depend upon obsolete macros, which votes
488 # in favor of `-W obsolete', but since many of these macros leave a message
489 # to be removed by the user once her code is adjusted, let's not check.
491 # Remove config.hin to avoid `autoheader: config.hin is unchanged'.
492 m4_define([AT_CHECK_AU_MACRO],
494 AT_KEYWORDS([autoupdate])
496 AT_CONFIGURE_AC([$1])
504 AT_CHECK_AUTOUPDATE([], 0, [], ignore)
505 AT_CHECK([grep '^$1$' configure.ac], 1)
513 ])# AT_CHECK_AU_MACRO
517 ## ----------------------- ##
518 ## Launch the test suite. ##
519 ## ----------------------- ##