Merge branch 'micro' into maint
[platform/upstream/automake.git] / t / ax / am-test-lib.sh
1 # -*- shell-script -*-
2 #
3 # Copyright (C) 1996-2013 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 # Do not source several times.
23 test ${am_test_lib_sourced-no} = yes && return 0
24 am_test_lib_sourced=yes
25
26 # A literal escape character.  Used by test checking colored output.
27 esc='\e'
28
29 # This might be used in testcases checking distribution-related features.
30 # Test scripts are free to override this if they need to.
31 distdir=$me-1.0
32
33 ## ---------------------- ##
34 ##  Environment cleanup.  ##
35 ## ---------------------- ##
36
37 # Unset some make-related variables that may cause $MAKE to act like
38 # a recursively invoked sub-make.  Any $MAKE invocation in a test is
39 # conceptually an independent invocation, not part of the main
40 # 'automake' build.
41 unset MFLAGS MAKEFLAGS AM_MAKEFLAGS MAKELEVEL
42 unset __MKLVL__ MAKE_JOBS_FIFO                     # For BSD make.
43 unset DMAKE_CHILD DMAKE_DEF_PRINTED DMAKE_MAX_JOBS # For Solaris dmake.
44 # Unset verbosity flag.
45 unset V
46 # Also unset variables that will let "make -e install" divert
47 # files into unwanted directories.
48 unset DESTDIR
49 unset prefix exec_prefix bindir datarootdir datadir docdir dvidir
50 unset htmldir includedir infodir libdir libexecdir localedir mandir
51 unset oldincludedir pdfdir psdir sbindir sharedstatedir sysconfdir
52 # Unset variables that might change the "make distcheck" behaviour.
53 unset DISTCHECK_CONFIGURE_FLAGS AM_DISTCHECK_CONFIGURE_FLAGS
54 # Used by install rules for info files.
55 unset AM_UPDATE_INFO_DIR
56 # The tests call "make -e" but we do not want $srcdir from the environment
57 # to override the definition from the Makefile.
58 unset srcdir
59 # Also unset variables that control our test driver.  While not
60 # conceptually independent, they cause some changed semantics we
61 # need to control (and test for) in some of the tests to ensure
62 # backward-compatible behavior.
63 unset TESTS_ENVIRONMENT AM_TESTS_ENVIRONMENT
64 unset DISABLE_HARD_ERRORS
65 unset AM_COLOR_TESTS
66 unset TESTS
67 unset XFAIL_TESTS
68 unset TEST_LOGS
69 unset TEST_SUITE_LOG
70 unset RECHECK_LOGS
71 unset VERBOSE
72 for pfx in TEST_ SH_ TAP_ ''; do
73   unset ${pfx}LOG_COMPILER
74   unset ${pfx}LOG_COMPILE # Not a typo!
75   unset ${pfx}LOG_FLAGS
76   unset AM_${pfx}LOG_FLAGS
77   unset ${pfx}LOG_DRIVER
78   unset ${pfx}LOG_DRIVER_FLAGS
79   unset AM_${pfx}LOG_DRIVER_FLAGS
80 done
81 unset pfx
82
83 # cross_compiling
84 # ---------------
85 # Tell whether we are cross-compiling.  This is especially useful to skip
86 # tests (or portions of them) that requires a native compiler.
87 cross_compiling ()
88 {
89   # Quoting from the autoconf manual:
90   #   ... [$host_alias and $build both] default to the result of running
91   #   config.guess, unless you specify either --build or --host.  In
92   #   this case, the default becomes the system type you specified.
93   #   If you specify both, *and they're different*, configure enters
94   #   cross compilation mode (so it doesn't run any tests that require
95   #   execution).
96   test x"$host_alias" != x && test x"$build_alias" != x"$host_alias"
97 }
98
99 # is_blocked_signal SIGNAL-NUMBER
100 # --------------------------------
101 # Return success if the given signal number is blocked in the shell,
102 # return a non-zero exit status and print a proper diagnostic otherwise.
103 is_blocked_signal ()
104 {
105   # Use perl, since trying to do this portably in the shell can be
106   # very tricky, if not downright impossible.  For reference, see:
107   # <http://lists.gnu.org/archive/html/bug-autoconf/2011-09/msg00004.html>
108   if $PERL -w -e '
109     use strict;
110     use warnings FATAL => "all";
111     use POSIX;
112     my %oldsigaction = ();
113     sigaction('"$1"', 0, \%oldsigaction);
114     exit ($oldsigaction{"HANDLER"} eq "IGNORE" ? 0 : 77);
115   '; then
116     return 0
117   elif test $? -eq 77; then
118     return 1
119   else
120     fatal_ "couldn't determine whether signal $1 is blocked"
121   fi
122 }
123
124 # AUTOMAKE_run [-e STATUS] [-d DESCRIPTION] [--] [AUTOMAKE-ARGS...]
125 # -----------------------------------------------------------------
126 # Run automake with AUTOMAKE-ARGS, and fail if it doesn't exit with
127 # STATUS.  Should be polymorphic for TAP and "plain" tests.  The
128 # DESCRIPTION, when provided, is used for console reporting, only if
129 # the TAP protocol is in use in the current test script.
130 AUTOMAKE_run ()
131 {
132   am__desc=
133   am__exp_rc=0
134   while test $# -gt 0; do
135     case $1 in
136       -d) am__desc=$2; shift;;
137       -e) am__exp_rc=$2; shift;;
138       --) shift; break;;
139        # Don't fail on unknown option: assume they (and the rest of the
140        # command line) are to be passed verbatim to automake (so stop our
141        # own option parsing).
142        *) break;;
143     esac
144     shift
145   done
146   am__got_rc=0
147   $AUTOMAKE ${1+"$@"} >stdout 2>stderr || am__got_rc=$?
148   cat stderr >&2
149   cat stdout
150   if test $am_test_protocol = none; then
151     test $am__got_rc -eq $am__exp_rc || exit 1
152     return
153   fi
154   if test -z "$am__desc"; then
155     if test $am__got_rc -eq $am__exp_rc; then
156       am__desc="automake exited $am__got_rc"
157     else
158       am__desc="automake exited $am__got_rc, expecting $am__exp_rc"
159     fi
160   fi
161   command_ok_ "$am__desc" test $am__got_rc -eq $am__exp_rc
162 }
163
164 # AUTOMAKE_fails [-d DESCRIPTION] [OPTIONS...]
165 # --------------------------------------------
166 # Run automake with OPTIONS, and fail if doesn't exit with status 1.
167 # Should be polymorphic for TAP and "plain" tests.  The DESCRIPTION,
168 # when provided, is used for console reporting, only if the TAP
169 # protocol is in use in the current test script.
170 AUTOMAKE_fails ()
171 {
172   AUTOMAKE_run -e 1 ${1+"$@"}
173 }
174
175 # extract_configure_help { --OPTION | VARIABLE-NAME } [FILES]
176 # -----------------------------------------------------------
177 # Use this to extract from the output of "./configure --help" (or similar)
178 # the description or help message associated to the given --OPTION or
179 # VARIABLE-NAME.
180 extract_configure_help ()
181 {
182   am__opt_re='' am__var_re=''
183   case $1 in
184     --*'=')   am__opt_re="^  $1";;
185     --*'[=]') am__opt_re='^  '$(printf '%s\n' "$1" | sed 's/...$//')'\[=';;
186     --*)      am__opt_re="^  $1( .*|$)";;
187       *)      am__var_re="^  $1( .*|$)";;
188   esac
189   shift
190   if test x"$am__opt_re" != x; then
191     LC_ALL=C awk '
192       /'"$am__opt_re"'/        { print; do_print = 1; next; }
193       /^$/                     { do_print = 0; next }
194       /^  --/                  { do_print = 0; next }
195       (do_print == 1)          { print }
196     ' ${1+"$@"}
197   else
198     LC_ALL=C awk '
199       /'"$am__var_re"'/        { print; do_print = 1; next; }
200       /^$/                     { do_print = 0; next }
201       /^  [A-Z][A-Z0-9_]* /    { do_print = 0; next }
202       /^  [A-Z][A-Z0-9_]*$/    { do_print = 0; next }
203       (do_print == 1)          { print }
204     ' ${1+"$@"}
205   fi
206 }
207
208 # grep_configure_help { --OPTION | VARIABLE-NAME } REGEXP
209 # -------------------------------------------------------
210 # Grep the section of "./configure --help" output associated with either
211 # --OPTION or VARIABLE-NAME for the given *extended* regular expression.
212 grep_configure_help ()
213 {
214   ./configure --help > am--all-help \
215     || { cat am--all-help; exit 1; }
216   cat am--all-help
217   extract_configure_help "$1" am--all-help > am--our-help \
218     || { cat am--our-help; exit 1; }
219   cat am--our-help
220   $EGREP "$2" am--our-help || exit 1
221 }
222
223 # using_gmake
224 # -----------
225 # Return success if $MAKE is GNU make, return failure otherwise.
226 # Caches the result for speed reasons.
227 using_gmake ()
228 {
229   case $am__using_gmake in
230     yes)
231       return 0;;
232     no)
233       return 1;;
234     '')
235       # Use --version AND -v, because SGI Make doesn't fail on --version.
236       # Also grep for GNU because newer versions of FreeBSD make do
237       # not complain about --version (they seem to silently ignore it).
238       if $MAKE --version -v | grep GNU; then
239         am__using_gmake=yes
240         return 0
241       else
242         am__using_gmake=no
243         return 1
244       fi;;
245     *)
246       fatal_ "invalid value for \$am__using_gmake: '$am__using_gmake'";;
247   esac
248 }
249 am__using_gmake="" # Avoid interferences from the environment.
250
251 # make_can_chain_suffix_rules
252 # ---------------------------
253 # Return 0 if $MAKE is a make implementation that can chain suffix rules
254 # automatically, return 1 otherwise.  Caches the result for speed reasons.
255 make_can_chain_suffix_rules ()
256 {
257   if test -z "$am__can_chain_suffix_rules"; then
258     if using_gmake; then
259       am__can_chain_suffix_rules=yes
260       return 0
261     else
262       mkdir am__chain.dir$$
263       cd am__chain.dir$$
264       unindent > Makefile << 'END'
265         .SUFFIXES: .u .v .w
266         .u.v: ; cp $< $@
267         .v.w: ; cp $< $@
268 END
269       echo make can chain suffix rules > foo.u
270       if $MAKE foo.w && diff foo.u foo.w; then
271         am__can_chain_suffix_rules=yes
272       else
273         am__can_chain_suffix_rules=no
274       fi
275       cd ..
276       rm -rf am__chain.dir$$
277     fi
278   fi
279   case $am__can_chain_suffix_rules in
280     yes) return 0;;
281      no) return 1;;
282       *) fatal_ "make_can_chain_suffix_rules: internal error";;
283   esac
284 }
285 am__can_chain_suffix_rules="" # Avoid interferences from the environment.
286
287 # useless_vpath_rebuild
288 # ---------------------
289 # Tell whether $MAKE suffers of the bug triggering automake bug#7884.
290 # For example, this happens with FreeBSD make, since in a VPATH build
291 # it tends to rebuilt files for which there is an explicit or even just
292 # a suffix rule, even if said files are already available in the VPATH
293 # directory.
294 useless_vpath_rebuild ()
295 {
296   if test -z "$am__useless_vpath_rebuild"; then
297     if using_gmake; then
298       am__useless_vpath_rebuild=no
299       return 1
300     fi
301     mkdir am__vpath.dir$$
302     cd am__vpath.dir$$
303     touch foo.a foo.b bar baz
304     mkdir build
305     cd build
306     unindent > Makefile << 'END'
307         .SUFFIXES: .a .b
308         VPATH = ..
309         all: foo.b baz
310         .PHONY: all
311         .a.b: ; cp $< $@
312         baz: bar ; cp ../baz bar
313 END
314     if $MAKE all && test ! -e foo.b && test ! -e bar; then
315       am__useless_vpath_rebuild=no
316     else
317       am__useless_vpath_rebuild=yes
318     fi
319     cd ../..
320     rm -rf am__vpath.dir$$
321   fi
322   case $am__useless_vpath_rebuild in
323     yes) return 0;;
324      no) return 1;;
325      "") ;;
326       *) fatal_ "no_useless_builddir_remake: internal error";;
327   esac
328 }
329 am__useless_vpath_rebuild=""
330
331 yl_distcheck () { useless_vpath_rebuild || $MAKE distcheck ${1+"$@"}; }
332
333 # count_test_results total=N pass=N fail=N xpass=N xfail=N skip=N error=N
334 # -----------------------------------------------------------------------
335 # Check that a testsuite run driven by the parallel-tests harness has
336 # had the specified numbers of test results (specified by kind).
337 # This function assumes that the output of "make check" or "make recheck"
338 # has been saved in the 'stdout' file in the current directory, and its
339 # log in the 'test-suite.log' file.
340 count_test_results ()
341 {
342   # Use a subshell so that we won't pollute the script namespace.
343   (
344     # TODO: Do proper checks on the arguments?
345     total=ERR pass=ERR fail=ERR xpass=ERR xfail=ERR skip=ERR error=ERR
346     eval "$@"
347     # For debugging.
348     $EGREP -i '(total|x?pass|x?fail|skip|error)' stdout || :
349     rc=0
350     # Avoid spurious failures with shells with "overly sensible"
351     # errexit shell flag, such as e.g., Solaris /bin/sh.
352     set +e
353     test $(grep -c '^PASS:'  stdout) -eq $pass  || rc=1
354     test $(grep -c '^XFAIL:' stdout) -eq $xfail || rc=1
355     test $(grep -c '^SKIP:'  stdout) -eq $skip  || rc=1
356     test $(grep -c '^FAIL:'  stdout) -eq $fail  || rc=1
357     test $(grep -c '^XPASS:' stdout) -eq $xpass || rc=1
358     test $(grep -c '^ERROR:' stdout) -eq $error || rc=1
359     grep "^# TOTAL:  *$total$" stdout || rc=1
360     grep "^# PASS:  *$pass$"   stdout || rc=1
361     grep "^# XFAIL:  *$xfail$" stdout || rc=1
362     grep "^# SKIP:  *$skip$"   stdout || rc=1
363     grep "^# FAIL:  *$fail$"   stdout || rc=1
364     grep "^# XPASS:  *$xpass$" stdout || rc=1
365     grep "^# ERROR:  *$error$" stdout || rc=1
366     test $rc -eq 0
367   )
368 }
369
370 # get_shell_script SCRIPT-NAME
371 # -----------------------------
372 # Fetch an Automake-provided shell script from the 'lib/' directory into
373 # the current directory, and, if the '$am_test_prefer_config_shell'
374 # variable is set to "yes", modify its shebang line to use $SHELL instead
375 # of /bin/sh.
376 get_shell_script ()
377 {
378   test ! -f "$1" || rm -f "$1" || return 99
379   if test x"$am_test_prefer_config_shell" = x"yes"; then
380     sed "1s|#!.*|#! $SHELL|" "$am_scriptdir/$1" > "$1" \
381      && chmod a+x "$1" \
382      || return 99
383   else
384     cp -f "$am_scriptdir/$1" . || return 99
385   fi
386   sed 10q "$1" # For debugging.
387 }
388
389 # require_xsi SHELL
390 # -----------------
391 # Skip the test if the given shell fails to support common XSI constructs.
392 require_xsi ()
393 {
394   test $# -eq 1 || fatal_ "require_xsi needs exactly one argument"
395   echo "$me: trying some XSI constructs with $1"
396   $1 -c "$xsi_shell_code" || skip_all_ "$1 lacks XSI features"
397 }
398 # Shell code supposed to work only with XSI shells.  Keep this in sync
399 # with libtool.m4:_LT_CHECK_SHELL_FEATURES.
400 xsi_shell_code='
401   _lt_dummy="a/b/c"
402   test "${_lt_dummy##*/},${_lt_dummy%/*},${_lt_dummy#??}"${_lt_dummy%"$_lt_dummy"}, \
403       = c,a/b,b/c, \
404     && eval '\''test $(( 1 + 1 )) -eq 2 \
405     && test "${#_lt_dummy}" -eq 5'\'
406
407 # fetch_tap_driver
408 # ----------------
409 # Fetch the Automake-provided TAP driver from the 'lib/' directory into
410 # the current directory, and edit its shebang line so that it will be
411 # run with the perl interpreter determined at configure time.
412 fetch_tap_driver ()
413 {
414   # TODO: we should devise a way to make the shell TAP driver tested also
415   # TODO: with /bin/sh, for better coverage.
416   case $am_tap_implementation in
417     # Extra quoting required to avoid maintainer-check spurious failures.
418    'perl')
419       $PERL -MTAP::Parser -e 1 \
420         || skip_all_ "cannot import TAP::Parser perl module"
421       sed "1s|#!.*|#! $PERL -w|" "$am_scriptdir"/tap-driver.pl >tap-driver
422       ;;
423     shell)
424       AM_TAP_AWK=$AWK; export AM_TAP_AWK
425       sed "1s|#!.*|#! $SHELL|" "$am_scriptdir"/tap-driver.sh >tap-driver
426       ;;
427     *)
428       fatal_ "invalid \$am_tap_implementation '$am_tap_implementation'" ;;
429   esac \
430     && chmod a+x tap-driver \
431     || framework_failure_ "couldn't fetch $am_tap_implementation TAP driver"
432   sed 10q tap-driver # For debugging.
433 }
434 am_tap_implementation=${am_tap_implementation-shell}
435
436 # $PYTHON and support for PEP-3147.  Needed to check our python-related
437 # install rules.
438 python_has_pep3147 ()
439 {
440   if test -z "$am_pep3147_tag"; then
441     am_pep3147_tag=$($PYTHON -c 'import imp; print(imp.get_tag())') \
442       || am_pep3147_tag=none
443   fi
444   test $am_pep3147_tag != none
445 }
446 am_pep3147_tag=
447
448 # pyc_location [-p] [FILE]
449 # ------------------------
450 # Determine what the actual location of the given '.pyc' or '.pyo'
451 # byte-compiled file should be, taking into account PEP-3147.  Save
452 # the location in the '$am_pyc_file' variable.  If the '-p' option
453 # is given, print the location on the standard output as well.
454 pyc_location ()
455 {
456   case $#,$1 in
457     2,-p) am_pyc_print=yes; shift;;
458      1,*) am_pyc_print=no;;
459        *) fatal_ "pyc_location: invalid usage";;
460   esac
461   if python_has_pep3147; then
462     case $1 in
463       */*) am_pyc_dir=${1%/*} am_pyc_base=${1##*/};;
464         *) am_pyc_dir=. am_pyc_base=$1;;
465     esac
466     am_pyc_ext=${am_pyc_base##*.}
467     am_pyc_base=${am_pyc_base%.py?}
468     am_pyc_file=$am_pyc_dir/__pycache__/$am_pyc_base.$am_pep3147_tag.$am_pyc_ext
469   else
470     am_pyc_file=$1
471   fi
472   test $am_pyc_print = no || printf '%s\n' "$am_pyc_file"
473 }
474
475 # py_installed [--not] FILE
476 # --------------------------
477 # Check that the given python FILE has been installed (resp. *not*
478 # installed, if the '--not' option is specified).  If FILE is a
479 # byte-compiled '.pyc' file, the new installation layout specified
480 # by PEP-3147 will be taken into account.
481 py_installed ()
482 {
483   case $#,$1 in
484         1,*) am_test_py_file='test -f';;
485     2,--not) am_test_py_file='test ! -e'; shift;;
486           *) fatal_ "pyc_installed: invalid usage";;
487   esac
488   case $1 in
489     *.py[co]) pyc_location "$1"; am_target_py_file=$am_pyc_file;;
490            *) am_target_py_file=$1;;
491   esac
492   $am_test_py_file "$am_target_py_file"
493 }
494
495 # Usage: require_compiler_ {cc|c++|fortran|fortran77}
496 require_compiler_ ()
497 {
498   case $# in
499     0) fatal_ "require_compiler_: missing argument";;
500     1) ;;
501     *) fatal_ "require_compiler_: too many arguments";;
502   esac
503   case $1 in
504     cc)
505       am__comp_lang="C"
506       am__comp_var=CC
507       am__comp_flag_vars='CFLAGS CPPFLAGS'
508       ;;
509     c++)
510       am__comp_lang="C++"
511       am__comp_var=CXX
512       am__comp_flag_vars='CXXFLAGS CPPFLAGS'
513       ;;
514     fortran)
515       am__comp_lang="Fortran"
516       am__comp_var=FC
517       am__comp_flag_vars='FCFLAGS'
518       ;;
519     fortran77)
520       am__comp_lang="Fortran 77"
521       am__comp_var=F77
522       am__comp_flag_vars='FFLAGS'
523       ;;
524   esac
525   shift
526   eval "am__comp_prog=\${$am__comp_var}" \
527     || fatal_ "expanding \${$am__comp_var} in require_compiler_"
528   case $am__comp_prog in
529     "")
530       fatal_ "botched configuration: \$$am__comp_var is empty";;
531     false)
532       skip_all_ "no $am__comp_lang compiler available";;
533     autodetect|autodetected)
534       # Let the ./configure commands in the test script try to determine
535       # these automatically.
536       unset $am__comp_var $am__comp_flag_vars;;
537     *)
538       # Pre-set these for the ./configure commands in the test script.
539       export $am__comp_var $am__comp_flag_vars;;
540   esac
541   # Delete private variables.
542   unset am__comp_lang am__comp_prog am__comp_var am__comp_flag_vars
543 }
544
545 ## ----------------------------------------------------------- ##
546 ##  Checks for required tools, and additional setups (if any)  ##
547 ##  required by them.                                          ##
548 ## ----------------------------------------------------------- ##
549
550 require_tool ()
551 {
552   am_tool=$1
553   case $1 in
554     cc|c++|fortran|fortran77)
555       require_compiler_ $1;;
556     xsi-lib-shell)
557       if test x"$am_test_prefer_config_shell" = x"yes"; then
558         require_xsi "$SHELL"
559       else
560         require_xsi "/bin/sh"
561       fi
562       ;;
563     bzip2)
564       # Do not use --version, older versions bzip2 still tries to compress
565       # stdin.
566       echo "$me: running bzip2 --help"
567       bzip2 --help \
568         || skip_all_ "required program 'bzip2' not available"
569       ;;
570     cl)
571       CC=cl
572       # Don't export CFLAGS, as that could have been initialized to only
573       # work with the C compiler detected at configure time.  If the user
574       # wants CFLAGS to also influence 'cl', he can still export CFLAGS
575       # in the environment "by hand" before calling the testsuite.
576       export CC CPPFLAGS
577       echo "$me: running $CC -?"
578       $CC -? || skip_all_ "Microsoft C compiler '$CC' not available"
579       ;;
580     etags)
581       # Exuberant Ctags will create a TAGS file even
582       # when asked for --help or --version.  (Emacs's etags
583       # does not have such problem.)  Use -o /dev/null
584       # to make sure we do not pollute the build directory.
585       echo "$me: running etags --version -o /dev/null"
586       etags --version -o /dev/null \
587         || skip_all_ "required program 'etags' not available"
588       ;;
589     GNUmake)
590       for make_ in "$MAKE" gmake gnumake :; do
591         MAKE=$make_ am__using_gmake=''
592         test "$MAKE" =  : && break
593         echo "$me: determine whether $MAKE is GNU make"
594         using_gmake && break
595         : For shells with busted 'set -e'.
596       done
597       test "$MAKE" = : && skip_all_ "this test requires GNU make"
598       export MAKE
599       unset make_
600       ;;
601     gcj)
602       GCJ=$GNU_GCJ GCJFLAGS=$GNU_GCJFLAGS; export GCJ GCJFLAGS
603       test "$GCJ" = false && skip_all_ "GNU Java compiler unavailable"
604       : For shells with busted 'set -e'.
605       ;;
606     gcc)
607       CC=$GNU_CC CFLAGS=$GNU_CFLAGS; export CC CFLAGS CPPFLAGS
608       test "$CC" = false && skip_all_ "GNU C compiler unavailable"
609       : For shells with busted 'set -e'.
610       ;;
611     g++)
612       CXX=$GNU_CXX CXXFLAGS=$GNU_CXXFLAGS; export CXX CXXFLAGS CPPFLAGS
613       test "$CXX" = false && skip_all_ "GNU C++ compiler unavailable"
614       : For shells with busted 'set -e'.
615       ;;
616     gfortran)
617       FC=$GNU_FC FCFLAGS=$GNU_FCFLAGS; export FC FCFLAGS
618       test "$FC" = false && skip_all_ "GNU Fortran compiler unavailable"
619       case " $required " in
620         *\ g77\ *) ;;
621         *) F77=$FC FFLAGS=$FCFLAGS; export F77 FFLAGS;;
622       esac
623       ;;
624     g77)
625       F77=$GNU_F77 FFLAGS=$GNU_FFLAGS; export F77 FFLAGS
626       test "$F77" = false && skip_all_ "GNU Fortran 77 compiler unavailable"
627       case " $required " in
628         *\ gfortran\ *) ;;
629         *) FC=$F77 FCFLAGS=$FFLAGS; export FC FCFLAGS;;
630       esac
631       ;;
632     grep-nonprint)
633       # Check that grep can parse nonprinting characters correctly.
634       # BSD 'grep' works from a pipe, but not a seekable file.
635       # GNU or BSD 'grep -a' works on files, but is not portable.
636       case $(echo "$esc" | grep .)$(echo "$esc" | grep "$esc") in
637         "$esc$esc") ;;
638         *) skip_ "grep can't handle nonprinting characters correctly";;
639       esac
640       ;;
641     javac)
642       # The Java compiler from JDK 1.5 (and presumably earlier versions)
643       # cannot handle the '-version' option by itself: it bails out
644       # telling that source files are missing.  Adding also the '-help'
645       # option seems to solve the problem.
646       echo "$me: running javac -version -help"
647       javac -version -help || skip_all_ "Sun Java compiler not available"
648       ;;
649     java)
650       # See the comments above about 'javac' for why we use also '-help'.
651       echo "$me: running java -version -help"
652       java -version -help || skip_all_ "Sun Java interpreter not found"
653       ;;
654     lib)
655       AR=lib
656       export AR
657       # Attempting to create an empty archive will actually not
658       # create the archive, but lib will output its version.
659       echo "$me: running $AR -out:defstest.lib"
660       $AR -out:defstest.lib \
661         || skip_all_ "Microsoft 'lib' utility not available"
662       ;;
663     makedepend)
664       echo "$me: running makedepend -f-"
665       makedepend -f- \
666         || skip_all_ "required program 'makedepend' not available"
667       ;;
668     mingw)
669       uname_s=$(uname -s || echo UNKNOWN)
670       echo "$me: system name: $uname_s"
671       case $uname_s in
672         MINGW*) ;;
673         *) skip_all_ "this test requires MSYS in MinGW mode" ;;
674       esac
675       unset uname_s
676       ;;
677     non-root)
678       # Skip this test case if the user is root.
679       # We try to append to a read-only file to detect this.
680       priv_check_temp=priv-check.$$
681       touch $priv_check_temp && chmod a-w $priv_check_temp \
682         || framework_failure_ "creating unwritable file $priv_check_temp"
683       # Not a useless use of subshell: lesser shells might bail
684       # out if a builtin fails.
685       overwrite_status=0
686       (echo foo >> $priv_check_temp) || overwrite_status=$?
687       rm -f $priv_check_temp
688       if test $overwrite_status -eq 0; then
689         skip_all_ "cannot drop file write permissions"
690       fi
691       unset priv_check_temp overwrite_status
692       ;;
693     # Extra quoting required to avoid maintainer-check spurious failures.
694     'perl-threads')
695       if test "$WANT_NO_THREADS" = "yes"; then
696         skip_all_ "Devel::Cover cannot cope with threads"
697       fi
698       ;;
699     native)
700       # Don't use "&&" here, to avoid a bug of 'set -e' present in
701       # some (even relatively recent) versions of the BSD shell.
702       # We add the dummy "else" branch for extra safety.
703       ! cross_compiling || skip_all_ "doesn't work in cross-compile mode"
704       ;;
705     python)
706       PYTHON=${PYTHON-python}
707       # Older python versions don't support --version, they have -V.
708       echo "$me: running $PYTHON -V"
709       $PYTHON -V || skip_all_ "python interpreter not available"
710       ;;
711     ro-dir)
712       # Skip this test case if read-only directories aren't supported
713       # (e.g., under DOS.)
714       ro_dir_temp=ro_dir.$$
715       mkdir $ro_dir_temp && chmod a-w $ro_dir_temp \
716         || framework_failure_ "creating unwritable directory $ro_dir_temp"
717       # Not a useless use of subshell: lesser shells might bail
718       # out if a builtin fails.
719       create_status=0
720       (: > $ro_dir_temp/probe) || create_status=$?
721       rm -rf $ro_dir_temp
722       if test $create_status -eq 0; then
723         skip_all_ "cannot drop directory write permissions"
724       fi
725       unset ro_dir_temp create_status
726       ;;
727     runtest)
728       # DejaGnu's runtest program. We rely on being able to specify
729       # the program on the runtest command-line. This requires
730       # DejaGnu 1.4.3 or later.
731       echo "$me: running runtest SOMEPROGRAM=someprogram --version"
732       runtest SOMEPROGRAM=someprogram --version \
733         || skip_all_ "DejaGnu is not available"
734       ;;
735     tex)
736       # No all versions of Tex support '--version', so we use
737       # a configure check.
738       if test -z "$TEX"; then
739         skip_all_ "TeX is required, but it wasn't found by configure"
740       fi
741       ;;
742     lex)
743       test x"$LEX" = x"false" && skip_all_ "lex not found or disabled"
744       export LEX
745       ;;
746     yacc)
747       test x"$YACC" = x"false" && skip_all_ "yacc not found or disabled"
748       export YACC
749       ;;
750     flex)
751       LEX=flex; export LEX
752       echo "$me: running flex --version"
753       flex --version || skip_all_ "required program 'flex' not available"
754       ;;
755     bison)
756       YACC='bison -y'; export YACC
757       echo "$me: running bison --version"
758       bison --version || skip_all_ "required program 'bison' not available"
759       ;;
760     valac)
761       echo "$me: running valac --version"
762       if ! valac --version; then
763         skip_all_ "required program 'valac' not available"
764       elif cross_compiling; then
765         skip_all_ "cross-compiling valac-generated C files is brittle"
766       fi
767       # TODO: We also know we need GNU make, the C compiler, and pkg-config
768       # here, but there is no easy way to express this with the current
769       # code organization.  We should improve the situation, sooner or
770       # later.  At which point the tests requiring 'valac' can drop the
771       # explicit requirements for those tools.
772       ;;
773     *)
774       # Generic case: the tool must support --version.
775       echo "$me: running $1 --version"
776       # It is not likely but possible that the required tool is a special
777       # builtin, in which case the shell is allowed to exit after an error.
778       # So we need the subshell here.  Also, some tools, like Sun cscope,
779       # can be interactive without redirection.
780       ($1 --version) </dev/null \
781         || skip_all_ "required program '$1' not available"
782       ;;
783   esac
784 }
785
786 process_requirements ()
787 {
788   # Look for (and maybe set up) required tools and/or system features;
789   # skip the current test if they are not found.
790   for am_tool in $*; do
791     require_tool $am_tool
792   done
793   # We might need extra m4 macros, e.g., for Libtool or Gettext.
794   for am_tool in gettext libtool pkg-config; do
795     case " $required " in
796       # The lack of whitespace after $am_tool is intended.
797       *" $am_tool"*) . ./t/$am_tool-macros.dir/get.sh;;
798     esac
799   done
800   unset am_tool
801 }
802
803 ## ---------------------------------------------------------------- ##
804 ##  Create and set up of the temporary directory used by the test.  ##
805 ## ---------------------------------------------------------------- ##
806
807 am_setup_testdir ()
808 {
809   # The subdirectory where the current test script will run and write its
810   # temporary/data files.  This will be created shortly, and will be removed
811   # by the cleanup trap below if the test passes.  If the test doesn't pass,
812   # this directory will be kept, to facilitate debugging.
813   am_test_subdir=${argv0#$am_rel_srcdir/}
814   case $am_test_subdir in
815     */*) am_test_subdir=${am_test_subdir%/*}/$me.dir;;
816       *) am_test_subdir=$me.dir;;
817   esac
818   test ! -e $am_test_subdir || rm_rf_ $am_test_subdir \
819     || framework_failure_ "removing old test subdirectory"
820   $MKDIR_P $am_test_subdir \
821     || framework_failure_ "creating test subdirectory"
822   cd $am_test_subdir \
823     || framework_failure_ "cannot chdir into test subdirectory"
824   if test x"$am_create_testdir" != x"empty"; then
825     cp "$am_scriptdir"/install-sh "$am_scriptdir"/missing \
826        "$am_scriptdir"/compile "$am_scriptdir"/depcomp . \
827       || framework_failure_ "fetching common files from $am_scriptdir"
828     # Build appropriate environment in test directory.  E.g., create
829     # configure.ac, touch all necessary files, etc.  Don't use AC_OUTPUT,
830     # but AC_CONFIG_FILES so that appending still produces a valid
831     # configure.ac.  But then, tests running config.status really need
832     # to append AC_OUTPUT.
833     {
834       echo "AC_INIT([$me], [1.0])"
835       if test x"$am_serial_tests" = x"yes"; then
836         echo "AM_INIT_AUTOMAKE([serial-tests])"
837       else
838         echo "AM_INIT_AUTOMAKE"
839       fi
840       echo "AC_CONFIG_FILES([Makefile])"
841     } >configure.ac || framework_failure_ "creating configure.ac skeleton"
842   fi
843 }
844
845 am_extra_info ()
846 {
847   echo "Running from installcheck: $am_running_installcheck"
848   echo "Test Protocol: $am_test_protocol"
849   echo "PATH = $PATH"
850 }