1 # M4 macros used in building Autoconf test suites. -*- Autotest -*-
3 # Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006 Free Software
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 AT_TESTED([autom4te autoconf autoheader autoupdate autoreconf ifnames])
28 ## ---------------- ##
30 ## ---------------- ##
32 # AT_CMP(FILE-1, FILE-2)
33 # ----------------------
34 # Check FILE-1 and FILE-2 for equality, like `cmp FILE-1 FILE-2'.
36 [m4_ifval([$2],, [m4_fatal([AT_CMP takes two arguments.])])[]dnl
37 AT_CHECK([$at_diff "$1" "$2"])
41 ## ---------------- ##
43 ## ---------------- ##
45 # AT_CHECK_SHELL_SYNTAX(PROGRAM)
46 # ------------------------------
47 # If the shell handles `-n' well, use it to check the syntax of PROGRAM;
48 # otherwise, do nothing.
49 m4_define([AT_CHECK_SHELL_SYNTAX],
50 [AS_IF([test "$ac_cv_sh_n_works" = yes],
51 [AT_CHECK([/bin/sh -n $1])])])
53 m4_define([AT_CHECK_PERL_SYNTAX],
54 [AT_CHECK([autom4te_perllibdir=$abs_top_srcdir/lib $PERL -c $abs_top_builddir/bin/$1],
57 ## ------------------ ##
58 ## Testing autom4te. ##
59 ## ------------------ ##
62 # AT_CHECK_M4(COMMAND, [EXIT-STATUS = 0], STDOUT, STDERR)
63 # -------------------------------------------------------
64 # If stderr is specified, normalize the observed stderr.
65 # This (using GNU M4 1.4.6 or later)
67 # /usr/local/bin/m4:script.4s:1: cannot open `foo': No such file or directory
68 # autom4te: /usr/local/bin/m4 failed with exit status: 1
70 # or this (GNU M4 1.4 installed as gm4)
72 # script.4s:1: /usr/local/bin/gm4: Cannot open foo: No such file or directory
73 # autom4te: /usr/local/bin/gm4 failed with exit status: 1
77 # m4:script.4s:1: cannot open `foo': No such file or directory
78 # autom4te: m4 failed with exit status: 1
80 # We use the following sed patterns:
82 # (m4): ?(file): ?(line):
83 # or (file): ?(line): ?(m4):
84 # to m4:(file):(line):
87 # m4:(file):(line): Cannot open foo:
88 # to m4:(file):(line): cannot open `foo':
92 # or autom4te: [^ ]m4.exe
95 # Moreover, DJGPP error messages include the error code in brackets;
96 # remove the error code during normalization.
98 m4_define([AT_CHECK_M4],
99 [AT_CHECK([$1], [$2], [$3], m4_ifval([$4], [stderr]))
101 [AT_CHECK([[sed 's/^[^:]*m4: *\([^:]*:\) *\([0-9][0-9]*: \)/m4:\1\2/
102 s/^\([^:]*:\) *\([0-9][0-9]*:\)[^:]*m4: /m4:\1\2 /
103 s/^\(m4:[^:]*:[0-9][0-9]*: \)C\(annot open \)\([^`:]*\):/\1c\2`\3'\'':/
104 s/^autom4te: [^ ]*m4 /autom4te: m4 /
105 s/^autom4te: [^ ]*m4\.exe /autom4te: m4 /
107 ' stderr]], [0],[$4])])
110 # AT_CHECK_AUTOM4TE(FLAGS, [EXIT-STATUS = 0], STDOUT, STDERR)
111 # -----------------------------------------------------------
112 m4_define([AT_CHECK_AUTOM4TE],
113 [AT_CHECK_M4([autom4te $1], [$2], [$3], [$4])])
117 ## ----------------- ##
118 ## Testing M4sugar. ##
119 ## ----------------- ##
122 # AT_DATA_M4SUGAR(FILE-NAME, CONTENTS)
123 # ------------------------------------
124 # Escape the invalid tokens with @&t@.
125 m4_define([AT_DATA_M4SUGAR],
129 [\(m4\)_], [\1@&t@_],
130 [dnl], [d@&t@nl])])])
133 # AT_CHECK_M4SUGAR(FLAGS, [EXIT-STATUS = 0], STDOUT, STDERR)
134 # ----------------------------------------------------------
135 m4_define([AT_CHECK_M4SUGAR],
136 [AT_KEYWORDS([m4sugar])
137 AT_CHECK_AUTOM4TE([--language=m4sugar script.4s -o script $1],
147 # AT_DATA_M4SH(FILE-NAME, CONTENTS)
148 # ---------------------------------
149 # Escape the invalid tokens with @&t@.
150 m4_define([AT_DATA_M4SH],
154 [\(m4\|AS\)_], [\1@&t@_],
155 [dnl], [d@&t@nl])])])
158 # AT_CHECK_M4SH(FLAGS, [EXIT-STATUS = 0], STDOUT, STDERR)
159 # -------------------------------------------------------
160 m4_define([AT_CHECK_M4SH],
161 [AT_CHECK_AUTOM4TE([--language=m4sh script.as -o script $1],
166 ## ------------------ ##
167 ## Testing Autoconf. ##
168 ## ------------------ ##
171 # AT_DATA_AUTOCONF(FILE-NAME, CONTENTS)
172 # -------------------------------------
173 # Escape the invalid tokens with @&t@.
174 m4_define([AT_DATA_AUTOCONF],
178 [\(m4\|AS\|AC\)_], [\1@&t@_],
179 [dnl], [d@&t@nl])])])
183 # AT_CONFIGURE_AC(BODY)
184 # ---------------------
185 # Create a full configure.ac running BODY, with a config header set up,
186 # AC_OUTPUT, and environment checking hooks.
187 m4_define([AT_CONFIGURE_AC],
188 [AT_DATA_AUTOCONF([aclocal.m4],
190 # AC_STATE_SAVE(FILE)
191 # -------------------
192 # Save the shell variables and directory listing. AT_CHECK_ENV uses these to
193 # confirm that no test modifies variables outside the Autoconf namespace or
194 # leaves temporary files. AT_CONFIG_CMP uses the variable dumps to confirm that
195 # tests have the same side effects regardless of caching.
196 m4_defun([AC_STATE_SAVE],
197 [(set) 2>&1 | sort >state-env.$][1
198 ls -1 | sed '/^at-/d;/^state-/d;/^config\./d' | sort >state-ls.$][1
202 AT_DATA([configure.ac],
204 AC_CONFIG_AUX_DIR($top_srcdir/build-aux)
205 AC_CONFIG_HEADER(config.h:config.hin)
206 AC_STATE_SAVE(before)]
214 # AT_CHECK_AUTOCONF(ARGS, [EXIT-STATUS = 0], STDOUT, STDERR)
215 # ----------------------------------------------------------
216 # We always use "--force", to prevent problems with timestamps if the testsuite
217 # were running too fast.
218 m4_define([AT_CHECK_AUTOCONF],
219 [AT_CHECK_M4([autoconf --force $1], [$2], [$3], [$4])
220 if test -s configure; then
221 AT_CHECK_SHELL_SYNTAX(configure)
226 # AT_CHECK_AUTOHEADER(ARGS, [EXIT-STATUS = 0], STDOUT, STDERR)
227 # ------------------------------------------------------------
228 m4_define([AT_CHECK_AUTOHEADER],
229 [AT_CHECK([autoheader $1], [$2], [$3], [$4])
233 # AT_CHECK_CONFIGURE(END-COMMAND,
235 # [STDOUT = IGNORE], STDERR)
236 # --------------------------------------------
237 # `abs_top_srcdir' is needed so that `./configure' finds install-sh.
238 # Using --srcdir is more expensive.
239 m4_define([AT_CHECK_CONFIGURE],
240 [AT_CAPTURE_FILE([config.log])[]dnl
241 AT_CHECK([top_srcdir=$abs_top_srcdir ./configure $1],
243 m4_default([$3], [ignore]), [$4])])
248 # Check that the full configure run remained in its variable name space,
249 # and cleaned up tmp files.
251 # Perhaps grep -E is not supported, or perhaps it chokes on such a big regex.
252 # In this case just don't pay attention to the env. It would be great
253 # to keep the error message but we can't: that would break AT_CHECK.
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 # - _|@|.[*#?$].|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 [# Compare directory listings.
285 test -f state-ls.before ||
286 AS_ERROR([state-ls.before not present])
287 test -f state-ls.after && { AT_CMP([state-ls.before], [state-ls.after]) }
288 # Compare variable space dumps.
289 if test -f state-env.before && test -f state-env.after; then
290 for act_file in state-env.before state-env.after
292 $EGREP -v '^(m4_join([|],
294 [(exec_)?prefix|DEFS|CONFIG_STATUS],
295 [CC|CFLAGS|CPP|GCC|CXX|CXXFLAGS|CXXCPP|GXX|F77|FFLAGS|FLIBS|G77],
296 [ERL|ERLC|ERLCFLAGS|ERLANG_PATH_ERL|ERLANG_ROOT_DIR|ERLANG_LIB_DIR],
297 [ERLANG_INSTALL_LIB_DIR|OBJC|OBJCPP|OBJCFLAGS],
299 [LIBS|LIB@&t@OBJS|LTLIBOBJS|LDFLAGS],
300 [INSTALL(_(DATA|PROGRAM|SCRIPT))?],
301 [CYGWIN|ISC|MINGW32|MINIX|EMXOS2|XENIX|EXEEXT|OBJEXT],
302 [X_(CFLAGS|(EXTRA_|PRE_)?LIBS)|x_(includes|libraries)|(have|no)_x],
303 [(host|build|target)(_(alias|cpu|vendor|os))?],
305 [interpval|PATH_SEPARATOR],
306 [F77_DUMMY_MAIN|f77_(case|underscore)],
307 [FC(_DUMMY_MAIN|FLAGS|LIBS|FLAGS_f)?],
308 [ALLOCA|GETLOADAVG_LIBS|KMEM_GROUP|NEED_SETGID|POW_LIB],
309 [AWK|LEX|LEXLIB|LEX_OUTPUT_ROOT|LN_S|M4|MKDIR_P|RANLIB|SET_MAKE|YACC],
311 [[_@]|.[*#?$].|LINENO|OLDPWD|PIPESTATUS|RANDOM|SECONDS]))=' \
312 $act_file 2>/dev/null |
313 # There may be variables spread on several lines; remove latter lines.
314 $GREP '^m4_defn([m4_re_word])=' >clean-$act_file
316 AT_CMP([clean-state-env.before], [clean-state-env.after])
321 # AT_CONFIG_CMP(VAR-FILE-A, VAR-FILE-B)
322 # -------------------------------------
323 # Check the outcomes of two configure runs for equality by comparing dumps of
324 # their shell variables. VAR-FILE-A and VAR-FILE-B are two `set'-style shell
325 # variable space dumps.
327 # We permit variance between runs in the following shell variables:
329 # M4sh's shell name space.
330 # - ^ac_, excluding ^ac_cv_
331 # Autoconf's private shell name space.
337 # Furthermore, it is okay for a non-cache variable initialized to empty in one
338 # run to be unset in another run. This happens when, for example, cache update
339 # code tries a number of values in LIBS and eventually restores LIBS to its
340 # original value. If LIBS was previously unset, it will have become set and
341 # empty. (OTOH, cache variables indicate the result of the test even if they
342 # are empty, so we have to be strict about them.)
344 # Lines that do not look like `foo=bar' are probably latter lines of
345 # multiline values; trim them.
347 m4_define([AT_CONFIG_CMP],
348 [for act_file in $1 $2
351 /^m4_defn([m4_re_word])=./ !d
352 /^[[^=]]*='\'''\''$/ d
358 ' $act_file >at_config_vars-$act_file
360 AT_CMP([at_config_vars-$1], [at_config_vars-$2])[]dnl
364 # AT_CHECK_DEFINES(CONTENT)
365 # -------------------------
366 # Verify that config.h, once stripped, is CONTENT.
367 # Stripping consists of keeping CPP lines (i.e. containing a hash),
368 # but those of automatically checked features (STDC_HEADERS etc.)
369 # and symbols (PACKAGE_...).
370 # AT_CHECK_HEADER is a better name, but too close from AC_CHECK_HEADER.
371 m4_define([AT_CHECK_DEFINES],
372 [AT_CHECK([[sed '/#/!d
382 /UNISTD/d' config.h]],,
386 # AT_CHECK_AUTOUPDATE
387 # -------------------
388 m4_define([AT_CHECK_AUTOUPDATE],
389 [AT_CHECK([autoupdate $1], [$2], [$3], [$4])
393 # _AT_CHECK_AC_MACRO(AC-BODY, PRE-TESTS)
394 # --------------------------------------
395 # Create a minimalist configure.ac running the macro named
396 # NAME-OF-THE-MACRO, check that autoconf runs on that script,
397 # and that the shell runs correctly the configure.
398 m4_define([_AT_CHECK_AC_MACRO],
399 [AT_CONFIGURE_AC([$1])
405 ])# _AT_CHECK_AC_MACRO
408 # AT_CHECK_MACRO(MACRO, [MACRO-USE], [ADDITIONAL-CMDS],
409 # [AUTOCONF-FLAGS = -W obsolete])
410 # -----------------------------------------------------
411 # Create a minimalist configure.ac running the macro named
412 # NAME-OF-THE-MACRO, check that autoconf runs on that script,
413 # and that the shell runs correctly the configure.
415 # We run `configure' twice, both times with a cache, and compare
416 # the environment after each run to detect inconsistencies.
418 # New macros are not expected to depend upon obsolete macros.
419 m4_define([AT_CHECK_MACRO],
422 AT_CONFIGURE_AC([m4_default([$2], [$1])])
424 AT_CHECK_AUTOCONF([m4_default([$4], [-W obsolete])])
429 AT_CHECK_CONFIGURE([-C])
430 cp -f state-env.after state-env.$at_run
431 cp -f config.h config-h.$at_run
435 AT_CMP([config-h.r1], [config-h.r2])
436 AT_CONFIG_CMP([state-env.r1], [state-env.r2])
444 # AT_CHECK_MACRO_CROSS(MACRO, [MACRO-USE], [ADDITIONAL-CMDS],
445 # [AUTOCONF-FLAGS = -W obsolete])
446 # -----------------------------------------------------------
447 # Like the previous one, but creates two checks: for native
448 # compile and for cross-compile.
449 m4_define([AT_CHECK_MACRO_CROSS],
451 AT_CHECK_MACRO([$1 (cross compile)],
452 [AT_KEYWORDS([cross])
453 # Exercise the code used when cross-compiling.
456 m4_default([$2], [$1])],
461 # AT_CHECK_AU_MACRO(MACRO)
462 # ------------------------
463 # Create a minimalist configure.ac running the macro named
464 # NAME-OF-THE-MACRO, autoupdate this script, check that autoconf runs
465 # on that script, and that the shell runs correctly the configure.
467 # Updated configure.ac shall not depend upon obsolete macros, which votes
468 # in favor of `-W obsolete', but since many of these macros leave a message
469 # to be removed by the user once her code is adjusted, let's not check.
471 # Remove config.hin to avoid `autoheader: config.hin is unchanged'.
472 m4_define([AT_CHECK_AU_MACRO],
474 AT_KEYWORDS([autoupdate])
476 AT_CONFIGURE_AC([$1])
484 AT_CHECK_AUTOUPDATE([], 0, [], ignore)
485 AT_CHECK([grep '^$1$' configure.ac], 1)
493 ])# AT_CHECK_AU_MACRO
497 ## ----------------------- ##
498 ## Launch the test suite. ##
499 ## ----------------------- ##
503 [Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006 Free Software
505 This is free software; see the source for copying conditions. There is NO
506 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.])