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