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