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