1 # M4 macros used in building Autoconf test suites. -*- Autotest -*-
3 # Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007 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],
100 m4_case([$4], [], [], [ignore], [ignore], [stderr]))
101 m4_case([$4], [], [], [ignore], [],
102 [AT_CHECK([[sed 's/^[^:]*m4: *\([^:]*:\) *\([0-9][0-9]*: \)/m4:\1\2/
103 s/^\([^:]*:\) *\([0-9][0-9]*:\)[^:]*m4: /m4:\1\2 /
104 s/^\(m4:[^:]*:[0-9][0-9]*: \)C\(annot open \)\([^`:]*\):/\1c\2`\3'\'':/
105 s/^autom4te: [^ ]*m4 /autom4te: m4 /
106 s/^autom4te: [^ ]*m4\.exe /autom4te: m4 /
108 ' stderr >&2]], [0], [], [$4])])
111 # AT_CHECK_AUTOM4TE(FLAGS, [EXIT-STATUS = 0], STDOUT, STDERR)
112 # -----------------------------------------------------------
113 m4_define([AT_CHECK_AUTOM4TE],
114 [AT_CHECK_M4([autom4te $1], [$2], [$3], [$4])])
118 ## ----------------- ##
119 ## Testing M4sugar. ##
120 ## ----------------- ##
123 # AT_DATA_M4SUGAR(FILE-NAME, CONTENTS)
124 # ------------------------------------
125 # Escape the invalid tokens with @&t@.
126 m4_define([AT_DATA_M4SUGAR],
130 [\(m4\)_], [\1@&t@_],
131 [dnl], [d@&t@nl])])])
134 # AT_CHECK_M4SUGAR(FLAGS, [EXIT-STATUS = 0], STDOUT, STDERR)
135 # ----------------------------------------------------------
136 m4_define([AT_CHECK_M4SUGAR],
137 [AT_KEYWORDS([m4sugar])
138 AT_CHECK_AUTOM4TE([--language=m4sugar script.4s -o script $1],
148 # AT_DATA_M4SH(FILE-NAME, CONTENTS)
149 # ---------------------------------
150 # Escape the invalid tokens with @&t@.
151 m4_define([AT_DATA_M4SH],
155 [\(m4\|AS\)_], [\1@&t@_],
156 [dnl], [d@&t@nl])])])
159 # AT_CHECK_M4SH(FLAGS, [EXIT-STATUS = 0], STDOUT, STDERR)
160 # -------------------------------------------------------
161 m4_define([AT_CHECK_M4SH],
162 [AT_CHECK_AUTOM4TE([--language=m4sh script.as -o script $1],
167 ## ------------------ ##
168 ## Testing Autoconf. ##
169 ## ------------------ ##
172 # AT_DATA_AUTOCONF(FILE-NAME, CONTENTS)
173 # -------------------------------------
174 # Escape the invalid tokens with @&t@.
175 m4_define([AT_DATA_AUTOCONF],
179 [\(m4\|AS\|AC\)_], [\1@&t@_],
180 [dnl], [d@&t@nl])])])
184 # AT_CONFIGURE_AC(BODY)
185 # ---------------------
186 # Create a full configure.ac running BODY, with a config header set up,
187 # AC_OUTPUT, and environment checking hooks.
188 m4_define([AT_CONFIGURE_AC],
189 [AT_DATA_AUTOCONF([aclocal.m4],
191 # AC_STATE_SAVE(FILE)
192 # -------------------
193 # Save the shell variables and directory listing. AT_CHECK_ENV uses these to
194 # confirm that no test modifies variables outside the Autoconf namespace or
195 # leaves temporary files. AT_CONFIG_CMP uses the variable dumps to confirm that
196 # tests have the same side effects regardless of caching.
197 m4_defun([AC_STATE_SAVE],
198 [(set) 2>&1 | sort >state-env.$][1
199 ls -1 | sed '/^at-/d;/^state-/d;/^config\./d' | sort >state-ls.$][1
203 AT_DATA([configure.ac],
205 AC_CONFIG_AUX_DIR($top_srcdir/build-aux)
206 AC_CONFIG_HEADER(config.h:config.hin)
207 AC_STATE_SAVE(before)]
215 # AT_CHECK_AUTOCONF(ARGS, [EXIT-STATUS = 0], STDOUT, STDERR)
216 # ----------------------------------------------------------
217 # We always use "--force", to prevent problems with timestamps if the testsuite
218 # were running too fast.
219 m4_define([AT_CHECK_AUTOCONF],
220 [AT_CHECK_M4([autoconf --force $1], [$2], [$3], [$4])
221 if test -s configure; then
222 AT_CHECK_SHELL_SYNTAX(configure)
227 # AT_CHECK_AUTOHEADER(ARGS, [EXIT-STATUS = 0], STDOUT, STDERR)
228 # ------------------------------------------------------------
229 m4_define([AT_CHECK_AUTOHEADER],
230 [AT_CHECK([autoheader $1], [$2], [$3], [$4])
234 # AT_CHECK_CONFIGURE(END-COMMAND,
236 # [STDOUT = IGNORE], STDERR)
237 # --------------------------------------------
238 # `abs_top_srcdir' is needed so that `./configure' finds install-sh.
239 # Using --srcdir is more expensive.
240 m4_define([AT_CHECK_CONFIGURE],
241 [AT_CAPTURE_FILE([config.log])[]dnl
242 AT_CHECK([top_srcdir=$abs_top_srcdir ./configure $1],
244 m4_default([$3], [ignore]), [$4])])
249 # Check that the full configure run remained in its variable name space,
250 # and cleaned up tmp files.
252 # Perhaps grep -E is not supported, or perhaps it chokes on such a big regex.
253 # In this case just don't pay attention to the env. It would be great
254 # to keep the error message but we can't: that would break AT_CHECK.
256 # Some tests might exit prematurely when they find a problem, in
257 # which case `env-after' is probably missing. Don't check it then.
259 # Here are the variables `configure' may modify during execution:
261 # M4sh's shell name space.
263 # Autoconf's shell name space.
264 # - prefix and exec_prefix
265 # are kept undefined (NONE) until AC_OUTPUT which then sets them to
266 # `/usr/local' and `${prefix}' for make.
267 # - (host|build|target)(_(alias|cpu|vendor|os))?
268 # Set by AC_CANONICAL_(HOST|BUILD|TARGET).
272 # Set by AC_SYS_INTERPRETER.
273 # - CONFIG_STATUS and DEFS
275 # - AC_SUBST'ed variables
276 # (FIXME: Generate a list of these automatically.)
277 # - _|@|.[*#?$].|LINENO|OLDPWD|PIPESTATUS|RANDOM|SECONDS
278 # Some variables some shells use and change.
279 # `.[*#?$].' catches `$#' etc. which are displayed like this:
284 m4_define([AT_CHECK_ENV],
285 [# Compare directory listings.
286 test -f state-ls.before ||
287 AS_ERROR([state-ls.before not present])
288 test -f state-ls.after && { AT_CMP([state-ls.before], [state-ls.after]) }
289 # Compare variable space dumps.
290 if test -f state-env.before && test -f state-env.after; then
291 for act_file in state-env.before state-env.after
293 $EGREP -v '^(m4_join([|],
295 [(exec_)?prefix|DEFS|CONFIG_STATUS],
296 [CC|CFLAGS|CPP|GCC|CXX|CXXFLAGS|CXXCPP|GXX|F77|FFLAGS|FLIBS|G77],
297 [ERL|ERLC|ERLCFLAGS|ERLANG_PATH_ERL|ERLANG_ROOT_DIR|ERLANG_LIB_DIR],
298 [ERLANG_INSTALL_LIB_DIR|OBJC|OBJCPP|OBJCFLAGS],
300 [LIBS|LIB@&t@OBJS|LTLIBOBJS|LDFLAGS],
301 [INSTALL(_(DATA|PROGRAM|SCRIPT))?],
302 [CYGWIN|ISC|MINGW32|MINIX|EMXOS2|XENIX|EXEEXT|OBJEXT],
303 [X_(CFLAGS|(EXTRA_|PRE_)?LIBS)|x_(includes|libraries)|(have|no)_x],
304 [(host|build|target)(_(alias|cpu|vendor|os))?],
306 [interpval|PATH_SEPARATOR],
307 [F77_DUMMY_MAIN|f77_(case|underscore)],
308 [FC(_DUMMY_MAIN|FLAGS|LIBS|FLAGS_f)?],
309 [ALLOCA|GETLOADAVG_LIBS|KMEM_GROUP|NEED_SETGID|POW_LIB],
310 [AWK|LEX|LEXLIB|LEX_OUTPUT_ROOT|LN_S|M4|MKDIR_P|RANLIB|SET_MAKE|YACC],
312 [[_@]|.[*#?$].|LINENO|OLDPWD|PIPESTATUS|RANDOM|SECONDS]))=' \
313 $act_file 2>/dev/null |
314 # There may be variables spread on several lines; remove latter lines.
315 $GREP '^m4_defn([m4_re_word])=' >clean-$act_file
317 AT_CMP([clean-state-env.before], [clean-state-env.after])
322 # AT_CONFIG_CMP(VAR-FILE-A, VAR-FILE-B)
323 # -------------------------------------
324 # Check the outcomes of two configure runs for equality by comparing dumps of
325 # their shell variables. VAR-FILE-A and VAR-FILE-B are two `set'-style shell
326 # variable space dumps.
328 # We permit variance between runs in the following shell variables:
330 # M4sh's shell name space.
331 # - ^ac_, excluding ^ac_cv_
332 # Autoconf's private shell name space.
338 # Furthermore, it is okay for a non-cache variable initialized to empty in one
339 # run to be unset in another run. This happens when, for example, cache update
340 # code tries a number of values in LIBS and eventually restores LIBS to its
341 # original value. If LIBS was previously unset, it will have become set and
342 # empty. (OTOH, cache variables indicate the result of the test even if they
343 # are empty, so we have to be strict about them.)
345 # Lines that do not look like `foo=bar' are probably latter lines of
346 # multiline values; trim them.
348 m4_define([AT_CONFIG_CMP],
349 [for act_file in $1 $2
352 /^m4_defn([m4_re_word])=./ !d
353 /^[[^=]]*='\'''\''$/ d
359 ' $act_file >at_config_vars-$act_file
361 AT_CMP([at_config_vars-$1], [at_config_vars-$2])[]dnl
365 # AT_CHECK_DEFINES(CONTENT)
366 # -------------------------
367 # Verify that config.h, once stripped, is CONTENT.
368 # Stripping consists of keeping CPP lines (i.e. containing a hash),
369 # but those of automatically checked features (STDC_HEADERS etc.)
370 # and symbols (PACKAGE_...).
371 # AT_CHECK_HEADER is a better name, but too close from AC_CHECK_HEADER.
372 m4_define([AT_CHECK_DEFINES],
373 [AT_CHECK([[sed '/#/!d
383 /UNISTD/d' config.h]],,
387 # AT_CHECK_AUTOUPDATE
388 # -------------------
389 m4_define([AT_CHECK_AUTOUPDATE],
390 [AT_CHECK([autoupdate $1], [$2], [$3], [$4])
394 # _AT_CHECK_AC_MACRO(AC-BODY, PRE-TESTS)
395 # --------------------------------------
396 # Create a minimalist configure.ac running the macro named
397 # NAME-OF-THE-MACRO, check that autoconf runs on that script,
398 # and that the shell runs correctly the configure.
399 m4_define([_AT_CHECK_AC_MACRO],
400 [AT_CONFIGURE_AC([$1])
406 ])# _AT_CHECK_AC_MACRO
409 # AT_CHECK_MACRO(MACRO, [MACRO-USE], [ADDITIONAL-CMDS],
410 # [AUTOCONF-FLAGS = -W obsolete])
411 # -----------------------------------------------------
412 # Create a minimalist configure.ac running the macro named
413 # NAME-OF-THE-MACRO, check that autoconf runs on that script,
414 # and that the shell runs correctly the configure.
416 # We run `configure' twice, both times with a cache, and compare
417 # the environment after each run to detect inconsistencies.
419 # New macros are not expected to depend upon obsolete macros.
420 m4_define([AT_CHECK_MACRO],
423 AT_CONFIGURE_AC([m4_default([$2], [$1])])
425 AT_CHECK_AUTOCONF([m4_default([$4], [-W obsolete])])
430 AT_CHECK_CONFIGURE([-C])
431 cp -f state-env.after state-env.$at_run
432 cp -f config.h config-h.$at_run
436 AT_CMP([config-h.r1], [config-h.r2])
437 AT_CONFIG_CMP([state-env.r1], [state-env.r2])
445 # AT_CHECK_MACRO_CROSS(MACRO, [MACRO-USE], [ADDITIONAL-CMDS],
446 # [AUTOCONF-FLAGS = -W obsolete])
447 # -----------------------------------------------------------
448 # Like the previous one, but creates two checks: for native
449 # compile and for cross-compile.
450 m4_define([AT_CHECK_MACRO_CROSS],
452 AT_CHECK_MACRO([$1 (cross compile)],
453 [AT_KEYWORDS([cross])
454 # Exercise the code used when cross-compiling.
457 m4_default([$2], [$1])],
462 # AT_CHECK_AU_MACRO(MACRO)
463 # ------------------------
464 # Create a minimalist configure.ac running the macro named
465 # NAME-OF-THE-MACRO, autoupdate this script, check that autoconf runs
466 # on that script, and that the shell runs correctly the configure.
468 # Updated configure.ac shall not depend upon obsolete macros, which votes
469 # in favor of `-W obsolete', but since many of these macros leave a message
470 # to be removed by the user once her code is adjusted, let's not check.
472 # Remove config.hin to avoid `autoheader: config.hin is unchanged'.
473 m4_define([AT_CHECK_AU_MACRO],
475 AT_KEYWORDS([autoupdate])
477 AT_CONFIGURE_AC([$1])
485 AT_CHECK_AUTOUPDATE([], 0, [], ignore)
486 AT_CHECK([grep '^$1$' configure.ac], 1)
494 ])# AT_CHECK_AU_MACRO
498 ## ----------------------- ##
499 ## Launch the test suite. ##
500 ## ----------------------- ##
504 [Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006 Free Software
506 This is free software; see the source for copying conditions. There is NO
507 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.])