Beta release 1.11b (will become 1.12)
[automake.git] / defs
blobefa578d8ecb474033f848f71ed1ff49ece21867f
1 # -*- shell-script -*-
3 # Copyright (C) 1996-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 2, or (at your option)
8 # 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 ########################################################
19 ###  IMPORTANT NOTE: keep this file 'set -e' clean.  ###
20 ########################################################
22 # NOTE: This file should execute correctly with any system's /bin/sh
23 # shell, and not only with configure-time detected $CONFIG_SHELL,
24 # *until differently and explicitly specified*.
26 ## -------------------------------------------------------- ##
27 ##  Source static setup and definitions for the testsuite.  ##
28 ## -------------------------------------------------------- ##
30 # Ensure we are running from the right directory.
31 test -f ./defs-static || {
32    echo "$0: ./defs-static: not found in current directory" >&2
33    exit 99
36 # Source the shell sanitization and variables' definitions.
37 . ./defs-static || exit 99
39 # Enable the errexit shell flag early.
40 set -e
42 # The name of the current test (without the '.sh' or '.tap' suffix).
43 # Test scripts can override it if they need to (but this should
44 # be done carefully, and *before* including ./defs).
45 if test -z "$me"; then
46   # Guard against failure to spawn sed (seen on MSYS), or empty $argv0.
47   me=`echo "$argv0" | sed -e 's,.*[\\/],,;s/\.sh$//;s/\.tap$//'` \
48     && test -n "$me" \
49     || { echo "$argv0: failed to define \$me" >&2; exit 99; }
52 ## ---------------------- ##
53 ##  Early sanity checks.  ##
54 ## ---------------------- ##
56 # A single whitespace character.
57 sp=' '
58 # A tabulation character.
59 tab='   '
60 # A newline character.
61 nl='
64 # As autoconf-generated configure scripts do, ensure that IFS
65 # is defined initially, so that saving and restoring $IFS works.
66 IFS=$sp$tab$nl
68 # Ensure $am_top_srcdir is set correctly.
69 test -f "$am_top_srcdir/defs-static.in" || {
70    echo "$me: $am_top_srcdir/defs-static.in not found," \
71         "check \$am_top_srcdir" >&2
72    exit 99
75 # Ensure $am_top_builddir is set correctly.
76 test -f "$am_top_builddir/defs-static" || {
77    echo "$me: $am_top_builddir/defs-static not found," \
78         "check \$am_top_builddir" >&2
79    exit 99
83 ## ------------------------------------ ##
84 ##  Ensure we run with a proper shell.  ##
85 ## ------------------------------------ ##
87 # Make sure we run with the shell detected at configure time (unless
88 # the user forbids it).
89 case ${AM_TESTS_REEXEC-yes} in
90   n|no|false|0)
91     ;;
92   *)
93     # Ensure we can find ourselves.
94     if test ! -f "$0"; then
95       echo "$me: unable to find myself: $0" >&2
96       exit 99
97     fi
98     AM_TESTS_REEXEC=no; export AM_TESTS_REEXEC
99     # Cannot simply do "opts=$-", since the content of $- is not
100     # portable among different shells.  So try to propagate only
101     # the portable and interesting options.
102     case $- in
103       *x*v*|*v*x) opts=-vx;;
104       *v*) opts=-v;;
105       *x*) opts=-x;;
106       *) opts=;;
107     esac
108     echo $me: exec $SHELL $opts "$0" "$*"
109     exec $SHELL $opts "$0" ${1+"$@"} || {
110       echo "$me: failed to re-execute with $SHELL" >&2
111       exit 99
112     }
113     ;;
114 esac
116 # NOTE: From this point on, we can assume this file is being executed
117 # by the configure-time detected $CONFIG_SHELL.
120 ## ----------------------- ##
121 ##  Early debugging info.  ##
122 ## ----------------------- ##
124 echo "Running from installcheck: $am_running_installcheck"
125 echo "Using TAP: $am_using_tap"
126 echo "PATH = $PATH"
129 ## ---------------------- ##
130 ##  Environment cleanup.  ##
131 ## ---------------------- ##
133 # Temporarily disable this, since some shells (e.g., older version
134 # of Bash) can return a non-zero exit status upon the when a non-set
135 # variable is unset.
136 set +e
138 # Unset some make-related variables that may cause $MAKE to act like
139 # a recursively invoked sub-make.  Any $MAKE invocation in a test is
140 # conceptually an independent invocation, not part of the main
141 # 'automake' build.
142 unset MFLAGS MAKEFLAGS AM_MAKEFLAGS MAKELEVEL
143 unset __MKLVL__ MAKE_JOBS_FIFO                     # For BSD make.
144 unset DMAKE_CHILD DMAKE_DEF_PRINTED DMAKE_MAX_JOBS # For Solaris dmake.
145 # Unset verbosity flag.
146 unset V
147 # Also unset variables that will let "make -e install" divert
148 # files into unwanted directories.
149 unset DESTDIR
150 unset prefix exec_prefix bindir datarootdir datadir docdir dvidir
151 unset htmldir includedir infodir libdir libexecdir localedir mandir
152 unset oldincludedir pdfdir psdir sbindir sharedstatedir sysconfdir
153 # Unset variables that might change the "make distcheck" behaviour.
154 unset DISTCHECK_CONFIGURE_FLAGS AM_DISTCHECK_CONFIGURE_FLAGS
155 # The tests call "make -e" but we do not want $srcdir from the environment
156 # to override the definition from the Makefile.
157 unset srcdir
158 # Also unset variables that control our test driver.  While not
159 # conceptually independent, they cause some changed semantics we
160 # need to control (and test for) in some of the tests to ensure
161 # backward-compatible behavior.
162 unset TESTS_ENVIRONMENT AM_TESTS_ENVIRONMENT
163 unset DISABLE_HARD_ERRORS
164 unset AM_COLOR_TESTS
165 unset TESTS
166 unset XFAIL_TESTS
167 unset TEST_LOGS
168 unset TEST_SUITE_LOG
169 unset RECHECK_LOGS
170 unset VERBOSE
171 for pfx in TEST_ TAP_ ''; do
172   unset ${pfx}LOG_COMPILER
173   unset ${pfx}LOG_COMPILE # Not a typo!
174   unset ${pfx}LOG_FLAGS
175   unset AM_${pfx}LOG_FLAGS
176   unset ${pfx}LOG_DRIVER
177   unset ${pfx}LOG_DRIVER_FLAGS
178   unset AM_${pfx}LOG_DRIVER_FLAGS
179 done
180 unset pfx
182 # Re-enable, it had been temporarily disabled above.
183 set -e
185 ## ---------------------------- ##
186 ##  Auxiliary shell functions.  ##
187 ## ---------------------------- ##
189 # Tell whether we should keep the test directories around, even in
190 # case of success.  By default, we don't.
191 am_keeping_testdirs ()
193   case $keep_testdirs in
194      ""|n|no|NO) return 1;;
195               *) return 0;;
196   esac
199 # This is used in 'Exit' and in the exit trap.  See comments in the latter
200 # for more information,
201 am__test_skipped=no
203 # We use a trap below for cleanup.  This requires us to go through
204 # hoops to get the right exit status transported through the signal.
205 # So use "Exit STATUS" instead of "exit STATUS" inside of the tests.
206 # Turn off errexit here so that we don't trip the bug with OSF1/Tru64
207 # sh inside this function.
208 Exit ()
210   set +e
211   # See comments in the exit trap for the reason we do this.
212   test 77 = $1 && am__test_skipped=yes
213   (exit $1); exit $1
216 if test $am_using_tap = yes; then
217   am_funcs_file=tap-functions.sh
218 else
219   am_funcs_file=plain-functions.sh
222 if test -f "$am_testauxdir/$am_funcs_file"; then
223   . "$am_testauxdir/$am_funcs_file" || {
224     echo "$me: error sourcing $am_testauxdir/$am_funcs_file" >&2
225     Exit 99
226   }
227 else
228   echo "$me: $am_testauxdir/$am_funcs_file not found" >&2
229   Exit 99
231 unset am_funcs_file
233 # cross_compiling
234 # ---------------
235 # Tell whether we are cross-compiling.  This is especially useful to skip
236 # tests (or portions of them) that requires a native compiler.
237 cross_compiling ()
239   # Quoting from the autoconf manual:
240   #   ... [$host_alias and $build both] default to the result of running
241   #   config.guess, unless you specify either --build or --host.  In
242   #   this case, the default becomes the system type you specified.
243   #   If you specify both, *and they're different*, configure enters
244   #   cross compilation mode (so it doesn't run any tests that require
245   #   execution).
246   test x"$host_alias" != x && test x"$build_alias" != x"$host_alias"
249 # is_newest FILE FILES
250 # --------------------
251 # Return false if any file in FILES is newer than FILE.
252 # Resolve ties in favor of FILE.
253 is_newest ()
255   is_newest_files=`find "$@" -prune -newer "$1"`
256   test -z "$is_newest_files"
259 # is_blocked_signal SIGNAL-NUMBER
260 # --------------------------------
261 # Return success if the given signal number is blocked in the shell,
262 # return a non-zero exit status and print a proper diagnostic otherwise.
263 is_blocked_signal ()
265   # Use perl, since trying to do this portably in the shell can be
266   # very tricky, if not downright impossible.  For reference, see:
267   # <http://lists.gnu.org/archive/html/bug-autoconf/2011-09/msg00004.html>
268   if $PERL -w -e '
269     use strict;
270     use warnings FATAL => "all";
271     use POSIX;
272     my %oldsigaction = ();
273     sigaction('"$1"', 0, \%oldsigaction);
274     exit ($oldsigaction{"HANDLER"} eq "IGNORE" ? 0 : 77);
275   '; then
276     return 0
277   elif test $? -eq 77; then
278     return 1
279   else
280     fatal_ "couldn't determine whether signal $1 is blocked"
281   fi
284 # AUTOMAKE_run [-e STATUS] [-d DESCRIPTION] [--] [AUTOMAKE-ARGS...]
285 # -----------------------------------------------------------------
286 # Run automake with AUTOMAKE-ARGS, and fail if it doesn't exit with
287 # STATUS.  Should be polymorphic for TAP and "plain" tests.  The
288 # DESCRIPTION, when provided, is used for console reporting, only if
289 # the TAP protocol is in use in the current test script.
290 AUTOMAKE_run ()
292   am__desc=
293   am__exp_rc=0
294   while test $# -gt 0; do
295     case $1 in
296       -d) am__desc=$2; shift;;
297       -e) am__exp_rc=$2; shift;;
298       --) shift; break;;
299        # Don't fail on unknown option: assume they (and the rest of the
300        # command line) are to be passed verbatim to automake (so stop our
301        # own option parsing).
302        *) break;;
303     esac
304     shift
305   done
306   am__got_rc=0
307   $AUTOMAKE ${1+"$@"} >stdout 2>stderr || am__got_rc=$?
308   cat stderr >&2
309   cat stdout
310   if test $am_using_tap != yes; then
311     test $am__got_rc -eq $am__exp_rc || Exit 1
312     return
313   fi
314   if test -z "$am__desc"; then
315     if test $am__got_rc -eq $am__exp_rc; then
316       am__desc="automake exited $am__got_rc"
317     else
318       am__desc="automake exited $am__got_rc, expecting $am__exp_rc"
319     fi
320   fi
321   command_ok_ "$am__desc" test $am__got_rc -eq $am__exp_rc
324 # AUTOMAKE_fails [-d DESCRIPTION] [OPTIONS...]
325 # --------------------------------------------
326 # Run automake with OPTIONS, and fail if doesn't exit with status 1.
327 # Should be polymorphic for TAP and "plain" tests.  The DESCRIPTION,
328 # when provided, is used for console reporting, only if the TAP
329 # protocol is in use in the current test script.
330 AUTOMAKE_fails ()
332   AUTOMAKE_run -e 1 ${1+"$@"}
335 # extract_configure_help { --OPTION | VARIABLE-NAME } [FILES]
336 # -----------------------------------------------------------
337 # Use this to extract from the output of "./configure --help" (or similar)
338 # the description or help message associated to the given --OPTION or
339 # VARIABLE-NAME.
340 extract_configure_help ()
342   am__opt_re='' am__var_re=''
343   case $1 in
344     --*'=')   am__opt_re="^  $1";;
345     --*'[=]') am__opt_re='^  '`printf '%s\n' "$1" | sed 's/...$//'`'\[=';;
346     --*)      am__opt_re="^  $1( .*|$)";;
347       *)      am__var_re="^  $1( .*|$)";;
348   esac
349   shift
350   if test x"$am__opt_re" != x; then
351     LC_ALL=C awk '
352       /'"$am__opt_re"'/        { print; do_print = 1; next; }
353       /^$/                     { do_print = 0; next }
354       /^  --/                  { do_print = 0; next }
355       (do_print == 1)          { print }
356     ' ${1+"$@"}
357   else
358     LC_ALL=C awk '
359       /'"$am__var_re"'/        { print; do_print = 1; next; }
360       /^$/                     { do_print = 0; next }
361       /^  [A-Z][A-Z0-9_]* /    { do_print = 0; next }
362       /^  [A-Z][A-Z0-9_]*$/    { do_print = 0; next }
363       (do_print == 1)          { print }
364     ' ${1+"$@"}
365   fi
368 # grep_configure_help { --OPTION | VARIABLE-NAME } REGEXP
369 # -------------------------------------------------------
370 # Grep the section of "./configure --help" output associated with either
371 # --OPTION or VARIABLE-NAME for the given *extended* regular expression.
372 grep_configure_help ()
374   ./configure --help > am--all-help \
375     || { cat am--all-help; Exit 1; }
376   cat am--all-help
377   extract_configure_help "$1" am--all-help > am--our-help \
378     || { cat am--our-help; Exit 1; }
379   cat am--our-help
380   $EGREP "$2" am--our-help || Exit 1
383 # using_gmake
384 # -----------
385 # Return success if $MAKE is GNU make, return failure otherwise.
386 # Caches the result for speed reasons.
387 using_gmake ()
389   case $am__using_gmake in
390     yes)
391       return 0;;
392     no)
393       return 1;;
394     '')
395       # Use --version AND -v, because SGI Make doesn't fail on --version.
396       # Also grep for GNU because newer versions of FreeBSD make do
397       # not complain about --version (they seem to silently ignore it).
398       if $MAKE --version -v | grep GNU; then
399         am__using_gmake=yes
400         return 0
401       else
402         am__using_gmake=no
403         return 1
404       fi;;
405     *)
406       fatal_ "invalid value for \$am__using_gmake: '$am__using_gmake'";;
407   esac
409 am__using_gmake="" # Avoid interferences from the environment.
411 # make_can_chain_suffix_rules
412 # ---------------------------
413 # Return 0 if $MAKE is a make implementation that can chain suffix rules
414 # automatically, return 1 otherwise.  Caches the result for speed reasons.
415 make_can_chain_suffix_rules ()
417   if test -z "$am__can_chain_suffix_rules"; then
418     if using_gmake; then
419       am__can_chain_suffix_rules=yes
420       return 0
421     else
422       mkdir am__chain.dir$$
423       cd am__chain.dir$$
424       unindent > Makefile << 'END'
425         .SUFFIXES: .u .v .w
426         .u.v: ; cp $< $@
427         .v.w: ; cp $< $@
429       echo make can chain suffix rules > foo.u
430       if $MAKE foo.w && diff foo.u foo.w; then
431         am__can_chain_suffix_rules=yes
432       else
433         am__can_chain_suffix_rules=no
434       fi
435       cd ..
436       rm -rf am__chain.dir$$
437     fi
438   fi
439   case $am__can_chain_suffix_rules in
440     yes) return 0;;
441      no) return 1;;
442       *) fatal_ "make_can_chain_suffix_rules: internal error";;
443   esac
445 am__can_chain_suffix_rules="" # Avoid interferences from the environment.
447 # useless_vpath_rebuild
448 # ---------------------
449 # Tell whether $MAKE suffers of the bug triggering automake bug#7884.
450 # For example, this happens with FreeBSD make, since in a VPATH build
451 # it tends to rebuilt files for which there is an explicit or even just
452 # a suffix rule, even if said files are already available in the VPATH
453 # directory.
454 useless_vpath_rebuild ()
456   if test -z "$am__useless_vpath_rebuild"; then
457     if using_gmake; then
458       am__useless_vpath_rebuild=no
459       return 1
460     fi
461     mkdir am__vpath.dir$$
462     cd am__vpath.dir$$
463     touch foo.a foo.b bar baz
464     mkdir build
465     cd build
466     unindent > Makefile << 'END'
467         .SUFFIXES: .a .b
468         VPATH = ..
469         all: foo.b baz
470         .PHONY: all
471         .a.b: ; cp $< $@
472         baz: bar ; cp ../baz bar
474     if $MAKE all && test ! -f foo.b && test ! -f bar; then
475       am__useless_vpath_rebuild=no
476     else
477       am__useless_vpath_rebuild=yes
478     fi
479     cd ../..
480     rm -rf am__vpath.dir$$
481   fi
482   case $am__useless_vpath_rebuild in
483     yes) return 0;;
484      no) return 1;;
485      "") ;;
486       *) fatal_ "no_useless_builddir_remake: internal error";;
487   esac
489 am__useless_vpath_rebuild=""
491 yl_distcheck () { useless_vpath_rebuild || $MAKE distcheck ${1+"$@"}; }
493 # seq_ - print a sequence of numbers
494 # ----------------------------------
495 # This function simulates GNU seq(1) portably.  Valid usages:
496 #  - seq LAST
497 #  - seq FIRST LAST
498 #  - seq FIRST INCREMENT LAST
499 seq_ ()
501   case $# in
502     0) fatal_ "seq_: missing argument";;
503     1) seq_first=1  seq_incr=1  seq_last=$1;;
504     2) seq_first=$1 seq_incr=1  seq_last=$2;;
505     3) seq_first=$1 seq_incr=$2 seq_last=$3;;
506     *) fatal_ "seq_: too many arguments";;
507   esac
508   # Try to avoid forks if possible.
509   case "$BASH_VERSION" in
510     ""|[12].*)
511       : Not bash, or a too old bash version. ;;
512     *)
513       # Use eval to protect dumber shells from parsing errors.
514       eval 'for ((i = seq_first; i <= seq_last; i += seq_incr)); do
515               echo $i
516             done'
517       return 0;;
518   esac
519   # Else, use GNU seq if available.
520   seq "$@" && return 0
521   # Otherwise revert to a slower loop using expr(1).
522   i=$seq_first
523   while test $i -le $seq_last; do
524     echo $i
525     i=`expr $i + $seq_incr`
526   done
529 # rm_rf_ [FILES OR DIRECTORIES ...]
530 # ---------------------------------
531 # Recursively remove the given files or directory, also handling the case
532 # of non-writable subdirectories.
533 rm_rf_ ()
535   test $# -gt 0 || return 0
536   # Ignore failures in find, we are only interested in failures of the
537   # final rm.
538   find "$@" -type d ! -perm -700 -exec chmod u+rwx {} \; || :
539   rm -rf "$@"
542 # count_test_results total=N pass=N fail=N xpass=N xfail=N skip=N error=N
543 # -----------------------------------------------------------------------
544 # Check that a testsuite run driven by the parallel-tests harness has
545 # had the specified numbers of test results (specified by kind).
546 # This function assumes that the output of "make check" or "make recheck"
547 # has been saved in the 'stdout' file in the current directory, and its
548 # log in the 'test-suite.log' file.
549 count_test_results ()
551   # Use a subshell so that we won't pollute the script namespace.
552   (
553     # TODO: Do proper checks on the arguments?
554     total=ERR pass=ERR fail=ERR xpass=ERR xfail=ERR skip=ERR error=ERR
555     eval "$@"
556     # For debugging.
557     $EGREP -i '(total|x?pass|x?fail|skip|error)' stdout || :
558     rc=0
559     # Avoid spurious failures with shells with "overly sensible"
560     # errexit shell flag, such as e.g., Solaris /bin/sh.
561     set +e
562     test `grep -c '^PASS:'  stdout` -eq $pass  || rc=1
563     test `grep -c '^XFAIL:' stdout` -eq $xfail || rc=1
564     test `grep -c '^SKIP:'  stdout` -eq $skip  || rc=1
565     test `grep -c '^FAIL:'  stdout` -eq $fail  || rc=1
566     test `grep -c '^XPASS:' stdout` -eq $xpass || rc=1
567     test `grep -c '^ERROR:' stdout` -eq $error || rc=1
568     grep "^# TOTAL:  *$total$" stdout || rc=1
569     grep "^# PASS:  *$pass$"   stdout || rc=1
570     grep "^# XFAIL:  *$xfail$" stdout || rc=1
571     grep "^# SKIP:  *$skip$"   stdout || rc=1
572     grep "^# FAIL:  *$fail$"   stdout || rc=1
573     grep "^# XPASS:  *$xpass$" stdout || rc=1
574     grep "^# ERROR:  *$error$" stdout || rc=1
575     test $rc -eq 0
576   )
579 commented_sed_unindent_prog='
580   /^$/b                    # Nothing to do for empty lines.
581   x                        # Get x<indent> into pattern space.
582   /^$/{                    # No prior x<indent>, go prepare it.
583     g                      # Copy this 1st non-blank line into pattern space.
584     s/^\(['"$tab"' ]*\).*/x\1/   # Prepare x<indent> in pattern space.
585   }                        # Now: x<indent> in pattern and <line> in hold.
586   G                        # Build x<indent>\n<line> in pattern space, and
587   h                        # duplicate it into hold space.
588   s/\n.*$//                # Restore x<indent> in pattern space, and
589   x                        # exchange with the above duplicate in hold space.
590   s/^x\(.*\)\n\1//         # Remove leading <indent> from <line>.
591   s/^x.*\n//               # Restore <line> when there is no leading <indent>.
594 # unindent [input files...]
595 # -------------------------
596 # Remove the "proper" amount of leading whitespace from the given files,
597 # and output the result on stdout.  That amount is determined by looking
598 # at the leading whitespace of the first non-blank line in the input
599 # files.  If no input file is specified, standard input is implied.
600 unindent ()
602   if test x"$sed_unindent_prog" = x; then
603     sed_unindent_prog=`printf '%s\n' "$commented_sed_unindent_prog" | sed -e "s/  *# .*//"`
604   fi
605   sed "$sed_unindent_prog" ${1+"$@"}
607 sed_unindent_prog="" # Avoid interferences from the environment.
609 # get_shell_script SCRIPT-NAME
610 # -----------------------------
611 # Fetch an Automake-provided shell script from the 'lib/' directory into
612 # the current directory, and, if the '$am_test_prefer_config_shell'
613 # variable is set to "yes", modify its shebang line to use $SHELL instead
614 # of /bin/sh.
615 get_shell_script ()
617   test ! -f "$1" || rm -f "$1" || return 99
618   if test x"$am_test_prefer_config_shell" = x"yes"; then
619     sed "1s|#!.*|#! $SHELL|" "$am_scriptdir/$1" > "$1" \
620      && chmod a+x "$1" \
621      || return 99
622   else
623     cp -f "$am_scriptdir/$1" . || return 99
624   fi
625   sed 10q "$1" # For debugging.
628 # require_xsi SHELL
629 # -----------------
630 # Skip the test if the given shell fails to support common XSI constructs.
631 require_xsi ()
633   test $# -eq 1 || fatal_ "require_xsi needs exactly one argument"
634   echo "$me: trying some XSI constructs with $1"
635   $1 -c "$xsi_shell_code" || skip_all_ "$1 lacks XSI features"
637 # Shell code supposed to work only with XSI shells.  Keep this in sync
638 # with libtool.m4:_LT_CHECK_SHELL_FEATURES.
639 xsi_shell_code='
640   _lt_dummy="a/b/c"
641   test "${_lt_dummy##*/},${_lt_dummy%/*},${_lt_dummy#??}"${_lt_dummy%"$_lt_dummy"}, \
642       = c,a/b,b/c, \
643     && eval '\''test $(( 1 + 1 )) -eq 2 \
644     && test "${#_lt_dummy}" -eq 5'\'
646 # fetch_tap_driver
647 # ----------------
648 # Fetch the Automake-provided TAP driver from the 'lib/' directory into
649 # the current directory, and edit its shebang line so that it will be
650 # run with the perl interpreter determined at configure time.
651 fetch_tap_driver ()
653   # TODO: we should devise a way to make the shell TAP driver tested also
654   # TODO: with /bin/sh, for better coverage.
655   case $am_tap_implementation in
656     perl)
657       $PERL -MTAP::Parser -e 1 \
658         || skip_all_ "cannot import TAP::Parser perl module"
659       sed "1s|#!.*|#! $PERL -w|" "$am_scriptdir"/tap-driver.pl >tap-driver
660       ;;
661     shell)
662       AM_TAP_AWK=$AWK; export AM_TAP_AWK
663       sed "1s|#!.*|#! $SHELL|" "$am_scriptdir"/tap-driver.sh >tap-driver
664       ;;
665     *)
666       fatal_ "invalid \$am_tap_implementation '$am_tap_implementation'" ;;
667   esac \
668     && chmod a+x tap-driver \
669     || framework_failure_ "couldn't fetch $am_tap_implementation TAP driver"
670   sed 10q tap-driver # For debugging.
672 # The shell/awk implementation of the TAP driver is still mostly dummy, so
673 # use the perl implementation by default for the moment.
674 am_tap_implementation=${am_tap_implementation-shell}
676 # Usage: require_compiler_ {cc|c++|fortran|fortran77}
677 require_compiler_ ()
679   case $# in
680     0) fatal_ "require_compiler_: missing argument";;
681     1) ;;
682     *) fatal_ "require_compiler_: too many arguments";;
683   esac
684   case $1 in
685     cc)
686       am__comp_lang="C"
687       am__comp_var=CC
688       am__comp_flag_vars='CFLAGS CPPFLAGS'
689       ;;
690     c++)
691       am__comp_lang="C++"
692       am__comp_var=CXX
693       am__comp_flag_vars='CXXFLAGS CPPFLAGS'
694       ;;
695     fortran)
696       am__comp_lang="Fortran"
697       am__comp_var=FC
698       am__comp_flag_vars='FCFLAGS'
699       ;;
700     fortran77)
701       am__comp_lang="Fortran 77"
702       am__comp_var=F77
703       am__comp_flag_vars='FFLAGS'
704       ;;
705   esac
706   shift
707   eval "am__comp_prog=\${$am__comp_var}" \
708     || fatal_ "expanding \${$am__comp_var} in require_compiler_"
709   case $am__comp_prog in
710     "")
711       fatal_ "botched configuration: \$$am__comp_var is empty";;
712     false)
713       skip_all_ "no $am__comp_lang compiler available";;
714     autodetect|autodetected)
715       # Let the ./configure commands in the test script try to determine
716       # these automatically.
717       unset $am__comp_var $am__comp_flag_vars;;
718     *)
719       # Pre-set these for the ./configure commands in the test script.
720       export $am__comp_var $am__comp_flag_vars;;
721   esac
722   # Delete private variables.
723   unset am__comp_lang am__comp_prog am__comp_var am__comp_flag_vars
726 ## ----------------------------------------------------------- ##
727 ##  Checks for required tools, and additional setups (if any)  ##
728 ##  required by them.                                          ##
729 ## ----------------------------------------------------------- ##
731 # Look for (and maybe set up) required tools and/or system features; skip
732 # the current test if they are not found.
733 for tool in : $required
735   # Check that each required tool is present.
736   case $tool in
737     :) ;;
738     cc|c++|fortran|fortran77)
739       require_compiler_ $tool;;
740     xsi-lib-shell)
741       if test x"$am_test_prefer_config_shell" = x"yes"; then
742         require_xsi "$SHELL"
743       else
744         require_xsi "/bin/sh"
745       fi
746       ;;
747     bzip2)
748       # Do not use --version, older versions bzip2 still tries to compress
749       # stdin.
750       echo "$me: running bzip2 --help"
751       bzip2 --help \
752         || skip_all_ "required program 'bzip2' not available"
753       ;;
754     cl)
755       CC=cl
756       # Don't export CFLAGS, as that could have been initialized to only
757       # work with the C compiler detected at configure time.  If the user
758       # wants CFLAGS to also influence 'cl', he can still export CFLAGS
759       # in the environment "by hand" before calling the testsuite.
760       export CC CPPFLAGS
761       echo "$me: running $CC -?"
762       $CC -? || skip_all_ "Microsoft C compiler '$CC' not available"
763       ;;
764     etags)
765       # Exuberant Ctags will create a TAGS file even
766       # when asked for --help or --version.  (Emacs's etags
767       # does not have such problem.)  Use -o /dev/null
768       # to make sure we do not pollute the build directory.
769       echo "$me: running etags --version -o /dev/null"
770       etags --version -o /dev/null \
771         || skip_all_ "required program 'etags' not available"
772       ;;
773     GNUmake)
774       for make_ in "$MAKE" gmake gnumake :; do
775         MAKE=$make_ am__using_gmake=''
776         test "$MAKE" =  : && break
777         echo "$me: determine whether $MAKE is GNU make"
778         # Don't use "&&" here, or a bug of 'set -e' present in some
779         # versions of the BSD shell will be triggered.  We add the
780         # dummy "else" branch for extra safety.
781         if using_gmake; then break; else :; fi
782       done
783       test "$MAKE" = : && skip_all_ "this test requires GNU make"
784       export MAKE
785       unset make_
786       ;;
787     gcj)
788       GCJ=$GNU_GCJ GCJFLAGS=$GNU_GCJFLAGS; export GCJ GCJFLAGS
789       test "$GCJ" = false && skip_all_ "GNU Java compiler unavailable"
790       : For shells with busted 'set -e'.
791       ;;
792     gcc)
793       CC=$GNU_CC CFLAGS=$GNU_CFLAGS; export CC CFLAGS CPPFLAGS
794       test "$CC" = false && skip_all_ "GNU C compiler unavailable"
795       : For shells with busted 'set -e'.
796       ;;
797     g++)
798       CXX=$GNU_CXX CXXFLAGS=$GNU_CXXFLAGS; export CXX CXXFLAGS CPPFLAGS
799       test "$CXX" = false && skip_all_ "GNU C++ compiler unavailable"
800       : For shells with busted 'set -e'.
801       ;;
802     gfortran)
803       FC=$GNU_FC FCFLAGS=$GNU_FCFLAGS; export FC FCFLAGS
804       test "$FC" = false && skip_all_ "GNU Fortran compiler unavailable"
805       case " $required " in
806         *\ g77\ *) ;;
807         *) F77=$FC FFLAGS=$FCFLAGS; export F77 FFLAGS;;
808       esac
809       ;;
810     g77)
811       F77=$GNU_F77 FFLAGS=$GNU_FFLAGS; export F77 FFLAGS
812       test "$F77" = false && skip_all_ "GNU Fortran 77 compiler unavailable"
813       case " $required " in
814         *\ gfortran\ *) ;;
815         *) FC=$F77 FCFLAGS=$FFLAGS; export FC FCFLAGS;;
816       esac
817       ;;
818     javac)
819       # The Java compiler from JDK 1.5 (and presumably earlier versions)
820       # cannot handle the '-version' option by itself: it bails out
821       # telling that source files are missing.  Adding also the '-help'
822       # option seems to solve the problem.
823       echo "$me: running javac -version -help"
824       javac -version -help || skip_all_ "Sun Java compiler not available"
825       ;;
826     java)
827       # See the comments above about 'javac' for why we use also '-help'.
828       echo "$me: running java -version -help"
829       java -version -help || skip_all_ "Sun Java interpreter not found"
830       ;;
831     lib)
832       AR=lib
833       export AR
834       # Attempting to create an empty archive will actually not
835       # create the archive, but lib will output its version.
836       echo "$me: running $AR -out:defstest.lib"
837       $AR -out:defstest.lib \
838         || skip_all_ "Microsoft 'lib' utility not available"
839       ;;
840     makedepend)
841       echo "$me: running makedepend -f-"
842       makedepend -f- \
843         || skip_all_ "required program 'makedepend' not available"
844       ;;
845     makeinfo-html)
846       # Make sure we have makeinfo, and it understands '--html'.
847       echo "$me: running makeinfo --html --version"
848       makeinfo --html --version \
849         || skip_all_ "cannot find a makeinfo program that groks" \
850                      "the '--html' option"
851       ;;
852     mingw)
853       uname_s=`uname -s || echo UNKNOWN`
854       echo "$me: system name: $uname_s"
855       case $uname_s in
856         MINGW*) ;;
857         *) skip_all_ "this test requires MSYS in MinGW mode" ;;
858       esac
859       ;;
860     non-root)
861       # Skip this test case if the user is root.
862       # We try to append to a read-only file to detect this.
863       priv_check_temp=priv-check.$$
864       touch $priv_check_temp && chmod a-w $priv_check_temp \
865         || framework_failure_ "creating unwritable file $priv_check_temp"
866       # Not a useless use of subshell: lesser shells like Solaris /bin/sh
867       # can exit if a builtin fails.
868       overwrite_status=0
869       (echo foo >> $priv_check_temp) || overwrite_status=$?
870       rm -f $priv_check_temp
871       if test $overwrite_status -eq 0; then
872         skip_all_ "cannot drop file write permissions"
873       fi
874       unset priv_check_temp overwrite_status
875       ;;
876     perl-threads)
877       if test "$WANT_NO_THREADS" = "yes"; then
878         skip_all_ "Devel::Cover cannot cope with threads"
879       fi
880       ;;
881     native)
882       # Don't use "&&" here, to avoid a bug of 'set -e' present in
883       # some (even relatively recent) versions of the BSD shell.
884       # We add the dummy "else" branch for extra safety.
885       if cross_compiling; then
886         skip_all_ "doesn't work in cross-compile mode"
887       else :; fi
888       ;;
889     python)
890       # Python doesn't support --version, it has -V
891       echo "$me: running python -V"
892       python -V || skip_all_ "python interpreter not available"
893       ;;
894     ro-dir)
895       # Skip this test case if read-only directories aren't supported
896       # (e.g., under DOS.)
897       ro_dir_temp=ro_dir.$$
898       mkdir $ro_dir_temp && chmod a-w $ro_dir_temp \
899         || framework_failure_ "creating unwritable directory $ro_dir_temp"
900       # Not a useless use of subshell: lesser shells like Solaris /bin/sh
901       # can exit if a builtin fails.
902       create_status=0
903       (: > $ro_dir_temp/probe) || create_status=$?
904       rm -rf $ro_dir_temp
905       if test $create_status -eq 0; then
906         skip_all_ "cannot drop directory write permissions"
907       fi
908       unset ro_dir_temp create_status
909       ;;
910     runtest)
911       # DejaGnu's runtest program. We rely on being able to specify
912       # the program on the runtest command-line. This requires
913       # DejaGnu 1.4.3 or later.
914       echo "$me: running runtest SOMEPROGRAM=someprogram --version"
915       runtest SOMEPROGRAM=someprogram --version \
916         || skip_all_ "DejaGnu is not available"
917       ;;
918     tex)
919       # No all versions of Tex support '--version', so we use
920       # a configure check.
921       if test -z "$TEX"; then
922         skip_all_ "TeX is required, but it wasn't found by configure"
923       fi
924       ;;
925     texi2dvi-o)
926       # Texi2dvi supports '-o' since Texinfo 4.1.
927       echo "$me: running texi2dvi -o /dev/null --version"
928       texi2dvi -o /dev/null --version \
929         || skip_all_ "required program 'texi2dvi' not available"
930       ;;
931     lex)
932       test x"$LEX" = x"false" && skip_all_ "lex not found or disabled"
933       export LEX
934       ;;
935     yacc)
936       test x"$YACC" = x"false" && skip_all_ "yacc not found or disabled"
937       export YACC
938       ;;
939     flex)
940       LEX=flex; export LEX
941       echo "$me: running flex --version"
942       flex --version || skip_all_ "required program 'flex' not available"
943       ;;
944     bison)
945       YACC='bison -y'; export YACC
946       echo "$me: running bison --version"
947       bison --version || skip_all_ "required program 'bison' not available"
948       ;;
949     *)
950       # Generic case: the tool must support --version.
951       echo "$me: running $tool --version"
952       # It is not likely but possible that $tool is a special builtin,
953       # in which case the shell is allowed to exit after an error.  So
954       # we need the subshell here.  Also, some tools, like Sun cscope,
955       # can be interactive without redirection.
956       ($tool --version) </dev/null \
957         || skip_all_ "required program '$tool' not available"
958       ;;
959   esac
960 done
962 # Using just $am_top_builddir for the check here is ok, since the
963 # further temporary subdirectory where the test will be run is
964 # ensured not to contain any whitespace character.
965 case $am_top_builddir in
966   *\ *|*\       *)
967     case " $required " in
968       *' libtool '* | *' libtoolize '* )
969         skip_all_ "libtool has problems with spaces in builddir name";;
970     esac
971     ;;
972 esac
974 # This test is necessary, although Automake's configure script bails out
975 # when $srcdir contains spaces.  This is because $am_top_srcdir is in not
976 # configure-time $srcdir, but is instead configure-time $abs_srcdir, and
977 # that is allowed to contain spaces.
978 case $am_top_srcdir in
979   *\ * |*\      *)
980     case " $required " in
981       *' libtool '* | *' libtoolize '* | *' gettext '* )
982         skip_all_ "spaces in srcdir name: libtool/gettext tests won't work";;
983    esac
984    ;;
985 esac
987 # We might need extra macros, e.g., from Libtool or Gettext.
988 case " $required " in *\ libtool*) . ./t/libtool-macros.dir/get.sh;; esac
989 case " $required " in *\ gettext*) . ./t/gettext-macros.dir/get.sh;; esac
992 ## ---------------------------------------------------------------- ##
993 ##  Create and set up of the temporary directory used by the test.  ##
994 ##  Set up of the exit trap for cleanup of said directory.          ##
995 ## ---------------------------------------------------------------- ##
997 # This might be used in testcases checking distribution-related features.
998 # Test scripts are free to override this if they need to.
999 distdir=$me-1.0
1001 # Set up the exit trap.
1002 if test "$sh_errexit_works" = yes; then
1003   trap 'exit_status=$?
1004     set +e
1005     cd "$am_top_builddir"
1006     if test $am_using_tap = yes; then
1007       if test "$planned_" = later && test $exit_status -eq 0; then
1008         plan_ "now"
1009       fi
1010       test $exit_status -eq 0 && test $tap_pass_count_ -eq $tap_count_ \
1011         || keep_testdirs=yes
1012     else
1013       # This is to ensure that a test script does give a SKIP outcome just
1014       # because a command in it happens to exit with status 77.  This
1015       # behaviour, while from time to time useful to developers, is not
1016       # meant to be enabled by default, as it could cause spurious failures
1017       # in the wild.  Thus it will be enabled only when the variable
1018       # "am_explicit_skips" is set to a "true" value.
1019       case $am_explicit_skips in
1020         [yY]|[yY]es|1)
1021           if test $exit_status -eq 77 && test $am__test_skipped != yes; then
1022             echo "$me: implicit skip turned into failure"
1023             exit_status=78
1024           fi;;
1025       esac
1026       test $exit_status -eq 0 || keep_testdirs=yes
1027     fi
1028     am_keeping_testdirs || rm_rf_ $testSubDir
1029     set +x
1030     echo "$me: exit $exit_status"
1031     exit $exit_status
1032   ' 0
1033   trap "fatal_ 'caught signal SIGHUP'" 1
1034   trap "fatal_ 'caught signal SIGINT'" 2
1035   trap "fatal_ 'caught signal SIGTERM'" 15
1036   # Various shells seems to just ignore SIGQUIT under some circumstances,
1037   # even if the signal is not blocked; however, if the signal it trapped,
1038   # the trap gets correctly executed.  So we also trap SIGQUIT.
1039   # Here is a list of some shells that have been verified to exhibit the
1040   # problematic behavior with SIGQUIT:
1041   #  - zsh 4.3.12 on Debian GNU/Linux
1042   #  - /bin/ksh and /usr/xpg4/bin/sh on Solaris 10
1043   #  - Bash 3.2.51 on Solaris 10 and bash 4.1.5 on Debian GNU/Linux
1044   #  - AT&T ksh on Debian Gnu/Linux (deb package ksh, version 93u-1)
1045   # OTOH, at least these shells that do *not* exhibit that behaviour:
1046   #  - modern version of the Almquist Shell (at least 0.5.5.1), on
1047   #    both Solaris and GNU/Linux
1048   #  - Solaris 10 /bin/sh
1049   #  - public domain Korn Shell, version 5.2.14, on Debian GNU/Linux
1050   trap "fatal_ 'caught signal SIGQUIT'" 3
1051   # Ignore further SIGPIPE in the trap code.  This is required to avoid
1052   # a very weird issue with some shells, at least when the execution of
1053   # the automake testsuite is driven by the 'prove' utility: if prove
1054   # (or the make process that has spawned it) gets interrupted with
1055   # Ctrl-C, the shell might go in a loop, continually getting a SIGPIPE,
1056   # sometimes finally dumping core, other times hanging indefinitely.
1057   # See also Test::Harness bug [rt.cpan.org #70855], archived at
1058   # <https://rt.cpan.org/Ticket/Display.html?id=70855>
1059   trap "trap '' 13; fatal_ 'caught signal SIGPIPE'" 13
1062 # Create and populate the temporary directory, if and as required.
1063 if test x"$am_create_testdir" = x"no"; then
1064   testSubDir=
1065 else
1066   # The subdirectory where the current test script will run and write its
1067   # temporary/data files.  This will be created shortly, and will be removed
1068   # by the cleanup trap below if the test passes.  If the test doesn't pass,
1069   # this directory will be kept, to facilitate debugging.
1070   testSubDir=t/$me.dir
1071   test ! -d $testSubDir || rm_rf_ $testSubDir \
1072     || framework_failure_ "removing old test subdirectory"
1073   test -d t || mkdir t
1074   mkdir $testSubDir \
1075     || framework_failure_ "creating test subdirectory"
1076   # The trailing './'ris to avoid CDPATH issues.
1077   cd ./$testSubDir \
1078     || framework_failure_ "cannot chdir into test subdirectory"
1079   if test x"$am_create_testdir" != x"empty"; then
1080     cp "$am_scriptdir"/install-sh "$am_scriptdir"/missing \
1081        "$am_scriptdir"/depcomp . \
1082       || framework_failure_ "fetching common files from $am_scriptdir"
1083     # Build appropriate environment in test directory.  E.g., create
1084     # configure.ac, touch all necessary files, etc.  Don't use AC_OUTPUT,
1085     # but AC_CONFIG_FILES so that appending still produces a valid
1086     # configure.ac.  But then, tests running config.status really need
1087     # to append AC_OUTPUT.
1088     {
1089       echo "AC_INIT([$me], [1.0])"
1090       if test x"$am_parallel_tests" = x"yes"; then
1091         echo "AM_INIT_AUTOMAKE([parallel-tests])"
1092       else
1093         echo "AM_INIT_AUTOMAKE"
1094       fi
1095       echo "AC_CONFIG_FILES([Makefile])"
1096     } >configure.ac || framework_failure_ "creating configure.ac skeleton"
1097   fi
1101 ## ---------------- ##
1102 ##  Ready to go...  ##
1103 ## ---------------- ##
1105 set -x