Update to GPLv3.
[autoconf.git] / tests / local.at
blob52af68a6fc97e2eb581cf639c4d66cfd1c40d376
1 # M4 macros used in building Autoconf test suites.        -*- Autotest -*-
3 # Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006 Free Software
4 # 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, 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 AT_TESTED([autom4te autoconf autoheader autoupdate autoreconf ifnames])
30 ## ---------------- ##
31 ## Utility macros.  ##
32 ## ---------------- ##
34 # AT_CMP(FILE-1, FILE-2)
35 # ----------------------
36 # Check FILE-1 and FILE-2 for equality, like `cmp FILE-1 FILE-2'.
37 m4_define([AT_CMP],
38 [m4_ifval([$2],, [m4_fatal([AT_CMP takes two arguments.])])[]dnl
39 AT_CHECK([$at_diff "$1" "$2"])
40 ])# AT_CMP
43 ## ---------------- ##
44 ## Testing syntax.  ##
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 [AS_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],
57           0, [], [ignore])])
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 or later)
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 installed as gm4)
74 #  script.4s:1: /usr/local/bin/gm4: Cannot open foo: No such file or directory
75 #  autom4te: /usr/local/bin/gm4 failed with exit status: 1
77 # becomes
79 #  m4:script.4s:1: cannot open `foo': No such file or directory
80 #  autom4te: m4 failed with exit status: 1
82 # We use the following sed patterns:
84 #     (m4): ?(file): ?(line):
85 # or  (file): ?(line): ?(m4):
86 # to  m4:(file):(line):
88 # and
89 #     m4:(file):(line): Cannot open foo:
90 # to  m4:(file):(line): cannot open `foo':
92 # and
93 #     autom4te: [^ ]m4
94 # or  autom4te: [^ ]m4.exe
95 # to  autom4te: m4
97 # Moreover, DJGPP error messages include the error code in brackets;
98 # remove the error code during normalization.
100 m4_define([AT_CHECK_M4],
101 [AT_CHECK([$1], [$2], [$3], m4_ifval([$4], [stderr]))
102 m4_ifval([$4],
103 [AT_CHECK([[sed 's/^[^:]*m4: *\([^:]*:\) *\([0-9][0-9]*: \)/m4:\1\2/
104         s/^\([^:]*:\) *\([0-9][0-9]*:\)[^:]*m4: /m4:\1\2 /
105         s/^\(m4:[^:]*:[0-9][0-9]*: \)C\(annot open \)\([^`:]*\):/\1c\2`\3'\'':/
106         s/^autom4te: [^ ]*m4 /autom4te: m4 /
107         s/^autom4te: [^ ]*m4\.exe /autom4te: m4 /
108         s/ (E[A-Z]*)$//
109     ' stderr]], [0],[$4])])
112 # AT_CHECK_AUTOM4TE(FLAGS, [EXIT-STATUS = 0], STDOUT, STDERR)
113 # -----------------------------------------------------------
114 m4_define([AT_CHECK_AUTOM4TE],
115 [AT_CHECK_M4([autom4te $1], [$2], [$3], [$4])])
119 ## ----------------- ##
120 ## Testing M4sugar.  ##
121 ## ----------------- ##
124 # AT_DATA_M4SUGAR(FILE-NAME, CONTENTS)
125 # ------------------------------------
126 # Escape the invalid tokens with @&t@.
127 m4_define([AT_DATA_M4SUGAR],
128 [AT_DATA([$1],
129 [m4_bpatsubsts([$2],
130                [@&t@],    [@&@&t@t@],
131                [\(m4\)_], [\1@&t@_],
132                [dnl],     [d@&t@nl])])])
135 # AT_CHECK_M4SUGAR(FLAGS, [EXIT-STATUS = 0], STDOUT, STDERR)
136 # ----------------------------------------------------------
137 m4_define([AT_CHECK_M4SUGAR],
138 [AT_KEYWORDS([m4sugar])
139 AT_CHECK_AUTOM4TE([--language=m4sugar script.4s -o script $1],
140                    [$2], [$3], [$4])])
144 ## -------------- ##
145 ## Testing M4sh.  ##
146 ## -------------- ##
149 # AT_DATA_M4SH(FILE-NAME, CONTENTS)
150 # ---------------------------------
151 # Escape the invalid tokens with @&t@.
152 m4_define([AT_DATA_M4SH],
153 [AT_DATA([$1],
154 [m4_bpatsubsts([$2],
155                [@&t@],        [@&@&t@t@],
156                [\(m4\|AS\)_], [\1@&t@_],
157                [dnl],         [d@&t@nl])])])
160 # AT_CHECK_M4SH(FLAGS, [EXIT-STATUS = 0], STDOUT, STDERR)
161 # -------------------------------------------------------
162 m4_define([AT_CHECK_M4SH],
163 [AT_CHECK_AUTOM4TE([--language=m4sh script.as -o script $1],
164                    [$2], [$3], [$4])])
168 ## ------------------ ##
169 ## Testing Autoconf.  ##
170 ## ------------------ ##
173 # AT_DATA_AUTOCONF(FILE-NAME, CONTENTS)
174 # -------------------------------------
175 # Escape the invalid tokens with @&t@.
176 m4_define([AT_DATA_AUTOCONF],
177 [AT_DATA([$1],
178 [m4_bpatsubsts([$2],
179                [@&t@],            [@&@&t@t@],
180                [\(m4\|AS\|AC\)_], [\1@&t@_],
181                [dnl],             [d@&t@nl])])])
185 # AT_CONFIGURE_AC(BODY)
186 # ---------------------
187 # Create a full configure.ac running BODY, with a config header set up,
188 # AC_OUTPUT, and environment checking hooks.
189 m4_define([AT_CONFIGURE_AC],
190 [AT_DATA_AUTOCONF([aclocal.m4],
192 # AC_STATE_SAVE(FILE)
193 # -------------------
194 # Save the shell variables and directory listing.  AT_CHECK_ENV uses these to
195 # confirm that no test modifies variables outside the Autoconf namespace or
196 # leaves temporary files.  AT_CONFIG_CMP uses the variable dumps to confirm that
197 # tests have the same side effects regardless of caching.
198 m4_defun([AC_STATE_SAVE],
199 [(set) 2>&1 | sort >state-env.$][1
200 ls -1 | sed '/^at-/d;/^state-/d;/^config\./d' | sort >state-ls.$][1
201 ])# AC_STATE_SAVE
204 AT_DATA([configure.ac],
205 [[AC_INIT
206 AC_CONFIG_AUX_DIR($top_srcdir/build-aux)
207 AC_CONFIG_HEADER(config.h:config.hin)
208 AC_STATE_SAVE(before)]
210 [AC_OUTPUT
211 AC_STATE_SAVE(after)
213 ])# AT_CONFIGURE_AC
216 # AT_CHECK_AUTOCONF(ARGS, [EXIT-STATUS = 0], STDOUT, STDERR)
217 # ----------------------------------------------------------
218 # We always use "--force", to prevent problems with timestamps if the testsuite
219 # were running too fast.
220 m4_define([AT_CHECK_AUTOCONF],
221 [AT_CHECK_M4([autoconf --force $1], [$2], [$3], [$4])
222 if test -s configure; then
223   AT_CHECK_SHELL_SYNTAX(configure)
228 # AT_CHECK_AUTOHEADER(ARGS, [EXIT-STATUS = 0], STDOUT, STDERR)
229 # ------------------------------------------------------------
230 m4_define([AT_CHECK_AUTOHEADER],
231 [AT_CHECK([autoheader $1], [$2], [$3], [$4])
235 # AT_CHECK_CONFIGURE(END-COMMAND,
236 #                    [EXIT-STATUS = 0],
237 #                    [STDOUT = IGNORE], STDERR)
238 # --------------------------------------------
239 # `abs_top_srcdir' is needed so that `./configure' finds install-sh.
240 # Using --srcdir is more expensive.
241 m4_define([AT_CHECK_CONFIGURE],
242 [AT_CAPTURE_FILE([config.log])[]dnl
243  AT_CHECK([top_srcdir=$abs_top_srcdir ./configure $1],
244           [$2],
245           m4_default([$3], [ignore]), [$4])])
248 # AT_CHECK_ENV
249 # ------------
250 # Check that the full configure run remained in its variable name space,
251 # and cleaned up tmp files.
253 # Perhaps grep -E is not supported, or perhaps it chokes on such a big regex.
254 # In this case just don't pay attention to the env.  It would be great
255 # to keep the error message but we can't: that would break AT_CHECK.
257 # Some tests might exit prematurely when they find a problem, in
258 # which case `env-after' is probably missing.  Don't check it then.
260 # Here are the variables `configure' may modify during execution:
261 # - ^as_
262 #   M4sh's shell name space.
263 # - ^ac_
264 #   Autoconf's shell name space.
265 # - prefix and exec_prefix
266 #   are kept undefined (NONE) until AC_OUTPUT which then sets them to
267 #   `/usr/local' and `${prefix}' for make.
268 # - (host|build|target)(_(alias|cpu|vendor|os))?
269 #   Set by AC_CANONICAL_(HOST|BUILD|TARGET).
270 # - cross_compiling
271 #   Set by AC_INIT.
272 # - interpval
273 #   Set by AC_SYS_INTERPRETER.
274 # - CONFIG_STATUS and DEFS
275 #   Set by AC_OUTPUT.
276 # - AC_SUBST'ed variables
277 #   (FIXME: Generate a list of these automatically.)
278 # - _|@|.[*#?$].|LINENO|OLDPWD|PIPESTATUS|RANDOM|SECONDS
279 #   Some variables some shells use and change.
280 #   `.[*#?$].' catches `$#' etc. which are displayed like this:
281 #      | '!'=18186
282 #      | '#'=0
283 #      | '$'=6908
285 m4_define([AT_CHECK_ENV],
286 [# Compare directory listings.
287 test -f state-ls.before ||
288   AS_ERROR([state-ls.before not present])
289 test -f state-ls.after && { AT_CMP([state-ls.before], [state-ls.after]) }
290 # Compare variable space dumps.
291 if test -f state-env.before && test -f state-env.after; then
292   for act_file in state-env.before state-env.after
293   do
294     $EGREP -v '^(m4_join([|],
295       [a[cs]_.*],
296       [(exec_)?prefix|DEFS|CONFIG_STATUS],
297       [CC|CFLAGS|CPP|GCC|CXX|CXXFLAGS|CXXCPP|GXX|F77|FFLAGS|FLIBS|G77],
298       [ERL|ERLC|ERLCFLAGS|ERLANG_PATH_ERL|ERLANG_ROOT_DIR|ERLANG_LIB_DIR],
299       [ERLANG_INSTALL_LIB_DIR|OBJC|OBJCPP|OBJCFLAGS],
300       [OPENMP_CFLAGS],
301       [LIBS|LIB@&t@OBJS|LTLIBOBJS|LDFLAGS],
302       [INSTALL(_(DATA|PROGRAM|SCRIPT))?],
303       [CYGWIN|ISC|MINGW32|MINIX|EMXOS2|XENIX|EXEEXT|OBJEXT],
304       [X_(CFLAGS|(EXTRA_|PRE_)?LIBS)|x_(includes|libraries)|(have|no)_x],
305       [(host|build|target)(_(alias|cpu|vendor|os))?],
306       [cross_compiling],
307       [interpval|PATH_SEPARATOR],
308       [F77_DUMMY_MAIN|f77_(case|underscore)],
309       [FC(_DUMMY_MAIN|FLAGS|LIBS|FLAGS_f)?],
310       [ALLOCA|GETLOADAVG_LIBS|KMEM_GROUP|NEED_SETGID|POW_LIB],
311       [AWK|LEX|LEXLIB|LEX_OUTPUT_ROOT|LN_S|M4|MKDIR_P|RANLIB|SET_MAKE|YACC],
312       [GREP|[EF]GREP|SED],
313       [[_@]|.[*#?$].|LINENO|OLDPWD|PIPESTATUS|RANDOM|SECONDS]))=' \
314      $act_file 2>/dev/null |
315       # There may be variables spread on several lines; remove latter lines.
316       $GREP '^m4_defn([m4_re_word])=' >clean-$act_file
317   done
318   AT_CMP([clean-state-env.before], [clean-state-env.after])
323 # AT_CONFIG_CMP(VAR-FILE-A, VAR-FILE-B)
324 # -------------------------------------
325 # Check the outcomes of two configure runs for equality by comparing dumps of
326 # their shell variables.  VAR-FILE-A and VAR-FILE-B are two `set'-style shell
327 # variable space dumps.
329 # We permit variance between runs in the following shell variables:
330 # - ^as_
331 #   M4sh's shell name space.
332 # - ^ac_, excluding ^ac_cv_
333 #   Autoconf's private shell name space.
334 # - PPID [bash, zsh]
335 # - RANDOM [zsh]
336 # - SECONDS [zsh]
337 # - '$' [zsh]
339 # Furthermore, it is okay for a non-cache variable initialized to empty in one
340 # run to be unset in another run.  This happens when, for example, cache update
341 # code tries a number of values in LIBS and eventually restores LIBS to its
342 # original value. If LIBS was previously unset, it will have become set and
343 # empty.  (OTOH, cache variables indicate the result of the test even if they
344 # are empty, so we have to be strict about them.)
346 # Lines that do not look like `foo=bar' are probably latter lines of
347 # multiline values; trim them.
349 m4_define([AT_CONFIG_CMP],
350 [for act_file in $1 $2
352   $SED '/^ac_cv_/ b
353         /^m4_defn([m4_re_word])=./ !d
354         /^[[^=]]*='\'''\''$/ d
355         /^a[[cs]]_/ d
356         /^PPID=/ d
357         /^RANDOM=/ d
358         /^SECONDS=/ d
359         /'\'\\\$\''=/ d
360         ' $act_file >at_config_vars-$act_file
361 done
362 AT_CMP([at_config_vars-$1], [at_config_vars-$2])[]dnl
363 ])# AT_CONFIG_CMP
366 # AT_CHECK_DEFINES(CONTENT)
367 # -------------------------
368 # Verify that config.h, once stripped, is CONTENT.
369 # Stripping consists of keeping CPP lines (i.e. containing a hash),
370 # but those of automatically checked features (STDC_HEADERS etc.)
371 # and symbols (PACKAGE_...).
372 # AT_CHECK_HEADER is a better name, but too close from AC_CHECK_HEADER.
373 m4_define([AT_CHECK_DEFINES],
374 [AT_CHECK([[sed '/#/!d
375 /INTTYPES/d
376 /MEMORY/d
377 /PACKAGE_/d
378 /STDC_HEADERS/d
379 /STDINT/d
380 /STDLIB/d
381 /STRING/d
382 /SYS_STAT/d
383 /SYS_TYPES/d
384 /UNISTD/d' config.h]],,
385           [$1])])
388 # AT_CHECK_AUTOUPDATE
389 # -------------------
390 m4_define([AT_CHECK_AUTOUPDATE],
391 [AT_CHECK([autoupdate $1], [$2], [$3], [$4])
395 # _AT_CHECK_AC_MACRO(AC-BODY, PRE-TESTS)
396 # --------------------------------------
397 # Create a minimalist configure.ac running the macro named
398 # NAME-OF-THE-MACRO, check that autoconf runs on that script,
399 # and that the shell runs correctly the configure.
400 m4_define([_AT_CHECK_AC_MACRO],
401 [AT_CONFIGURE_AC([$1])
403 AT_CHECK_AUTOCONF
404 AT_CHECK_AUTOHEADER
405 AT_CHECK_CONFIGURE
406 AT_CHECK_ENV
407 ])# _AT_CHECK_AC_MACRO
410 # AT_CHECK_MACRO(MACRO, [MACRO-USE], [ADDITIONAL-CMDS],
411 #                [AUTOCONF-FLAGS = -W obsolete])
412 # -----------------------------------------------------
413 # Create a minimalist configure.ac running the macro named
414 # NAME-OF-THE-MACRO, check that autoconf runs on that script,
415 # and that the shell runs correctly the configure.
417 # We run `configure' twice, both times with a cache, and compare
418 # the environment after each run to detect inconsistencies.
420 # New macros are not expected to depend upon obsolete macros.
421 m4_define([AT_CHECK_MACRO],
422 [AT_SETUP([$1])
424 AT_CONFIGURE_AC([m4_default([$2], [$1])])
426 AT_CHECK_AUTOCONF([m4_default([$4], [-W obsolete])])
427 AT_CHECK_AUTOHEADER
429 for at_run in r1 r2
431     AT_CHECK_CONFIGURE([-C])
432     cp -f state-env.after state-env.$at_run
433     cp -f config.h config-h.$at_run
434     AT_CHECK_ENV
435 done
437 AT_CMP([config-h.r1], [config-h.r2])
438 AT_CONFIG_CMP([state-env.r1], [state-env.r2])
442 AT_CLEANUP[]dnl
443 ])# AT_CHECK_MACRO
446 # AT_CHECK_MACRO_CROSS(MACRO, [MACRO-USE], [ADDITIONAL-CMDS],
447 #                      [AUTOCONF-FLAGS = -W obsolete])
448 # -----------------------------------------------------------
449 # Like the previous one, but creates two checks: for native
450 # compile and for cross-compile.
451 m4_define([AT_CHECK_MACRO_CROSS],
452 [AT_CHECK_MACRO($@)
453 AT_CHECK_MACRO([$1 (cross compile)],
454   [AT_KEYWORDS([cross])
455   # Exercise the code used when cross-compiling.
456   cross_compiling=yes
457   ac_tool_warned=yes
458   m4_default([$2], [$1])],
459   [$3], [$4])
463 # AT_CHECK_AU_MACRO(MACRO)
464 # ------------------------
465 # Create a minimalist configure.ac running the macro named
466 # NAME-OF-THE-MACRO, autoupdate this script, check that autoconf runs
467 # on that script, and that the shell runs correctly the configure.
469 # Updated configure.ac shall not depend upon obsolete macros, which votes
470 # in favor of `-W obsolete', but since many of these macros leave a message
471 # to be removed by the user once her code is adjusted, let's not check.
473 # Remove config.hin to avoid `autoheader: config.hin is unchanged'.
474 m4_define([AT_CHECK_AU_MACRO],
475 [AT_SETUP([$1])
476 AT_KEYWORDS([autoupdate])
478 AT_CONFIGURE_AC([$1])
480 AT_CHECK_AUTOCONF
481 AT_CHECK_AUTOHEADER
482 AT_CHECK_CONFIGURE
483 AT_CHECK_ENV
485 rm config.hin
486 AT_CHECK_AUTOUPDATE([], 0, [], ignore)
487 AT_CHECK([grep '^$1$' configure.ac], 1)
489 AT_CHECK_AUTOCONF
490 AT_CHECK_AUTOHEADER
491 AT_CHECK_CONFIGURE
492 AT_CHECK_ENV
494 AT_CLEANUP[]dnl
495 ])# AT_CHECK_AU_MACRO
499 ## ----------------------- ##
500 ## Launch the test suite.  ##
501 ## ----------------------- ##
503 AT_INIT
504 AT_COPYRIGHT(
505 [Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006 Free Software
506 Foundation, Inc.
507 This is free software; see the source for copying conditions.  There is NO
508 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.])