tests: better idiom to override make macro defs on the cmdline
[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 # single_quote STRING
125 # -------------------
126 # Single-quote STRING for the shell, also dealing with embedded single
127 # quotes. Place the result in the '$am_result', that is thus to be
128 # considered public.
129 single_quote ()
130 {
131   am_result=$1
132   case $am_result in
133     *\'*) am_result=$(printf '%s\n' "$*" | sed -e "s/'/'\\\\''/g");;
134   esac
135   am_result="'$am_result'"
136 }
137
138 # append_single_quoted VARIABLE STRING
139 # ------------------------------------
140 append_single_quoted ()
141 {
142   am__var=$1; shift
143   single_quote "$1" # Sets 'am_result'.
144   eval "${am__var}=\${$am__var:+\"\${$am__var} \"}\$am_result"
145   unset am__var am_result
146 }
147
148 # is_valid_varname STRING
149 # -----------------------
150 # Tell whether STRING is a valid name for a shell variable.  Return 0
151 # if yes, return 1 if not.
152 is_valid_varname ()
153 {
154   # FIXME: is the below truly portable even for LC_COLLATE != "C" ?
155   case $1 in
156     [0-9]*) return 1;;
157     *[!a-zA-Z0-9_]*) return 1;;
158   esac
159   return 0
160 }
161
162 # run_make [-e STATUS] [--] [VAR=VAL ...] [MAKE-ARGS...]
163 # ------------------------------------------------------
164 # Run $MAKE with the given command-line, and fail if it doesn't exit with
165 # STATUS (default: 0).  If STATUS is "FAIL", then any exit status > 0 is
166 # acceptable.  If STATUS is "IGNORE", any exit value is acceptable.
167 # This function also handle command-line override of variable definition
168 # in a smart way, using AM_MAKEFLAGS if a non-GNU make implementation
169 # is in use.
170 run_make ()
171 {
172   # Follow-up code might want to analyse these, so don't make them as
173   # private, nor unset them later.
174   am_make_rc_exp=0
175   am_make_rc_got=0
176   # Parse options for this function.
177   while test $# -gt 0; do
178     case $1 in
179       -e) am_make_rc_exp=$2; shift;;
180       --) shift; break;;
181        *) break;;
182     esac
183     shift
184   done
185   am__make_flags=
186   if using_gmake; then
187     # We can trust GNU make to correctly pass macro definitions given
188     # on the command line down to sub-make invocations, and this allow
189     # us to have a vary simple implementation: delegate all the work
190     # to GNU make.
191     :
192   else
193     # We have to explicitly parse arguments passed to make.  Not 100%
194     # safe w.r.t. options like '-I' that can have an argument, but
195     # should be good enough for our usages so far.
196     for am__x
197     do
198       case $am__x in
199         *=*)
200         am__maybe_var=${am__x%%=*}
201         am__maybe_val=${am__x#*=}
202         am__maybe_def="${am__maybe_var}=${am__maybe_val}"
203         # Some variables should be portably overridable from the command
204         # line, even when using non-GNU make.
205         case $am__maybe_var in
206           V|\
207           DESTDIR|\
208           SHELL|\
209           VERBOSE|\
210           DISABLE_HARD_ERRORS|\
211           DISTCHECK_CONFIGURE_FLAGS)
212             ;;
213           *)
214             if is_valid_varname "$am__maybe_var"; then
215               append_single_quoted am__make_flags "$am__maybe_def"
216             fi
217         esac
218         unset am__maybe_var am__maybe_val am__maybe_def
219         ;;
220       esac
221     done
222     unset am__x
223   fi
224   if test x"$am__make_flags" != x; then
225     $MAKE AM_MAKEFLAGS="$am__make_flags" ${1+"$@"} || am_make_rc_got=$?
226   else
227     $MAKE ${1+"$@"} || am_make_rc_got=$?
228   fi
229   unset am__make_flags
230   case $am_make_rc_exp in
231     IGNORE)
232       : Ignore exit status
233       ;;
234     FAIL)
235       test $am_make_rc_got -gt 0 || return 1
236       ;;
237     *)
238      test $am_make_rc_exp -ge 0 && test $am_make_rc_exp -le 255 \
239        || fatal_ "invalid expected exit status: '$am_make_rc_exp'"
240      test $am_make_rc_exp -eq $am_make_rc_got || return 1
241      ;;
242   esac
243 }
244
245 # AUTOMAKE_run [-e STATUS] [-d DESCRIPTION] [--] [AUTOMAKE-ARGS...]
246 # -----------------------------------------------------------------
247 # Run automake with AUTOMAKE-ARGS, and fail if it doesn't exit with
248 # STATUS.  Should be polymorphic for TAP and "plain" tests.  The
249 # DESCRIPTION, when provided, is used for console reporting, only if
250 # the TAP protocol is in use in the current test script.
251 AUTOMAKE_run ()
252 {
253   am__desc=
254   am__exp_rc=0
255   while test $# -gt 0; do
256     case $1 in
257       -d) am__desc=$2; shift;;
258       -e) am__exp_rc=$2; shift;;
259       --) shift; break;;
260        # Don't fail on unknown option: assume they (and the rest of the
261        # command line) are to be passed verbatim to automake (so stop our
262        # own option parsing).
263        *) break;;
264     esac
265     shift
266   done
267   am__got_rc=0
268   $AUTOMAKE ${1+"$@"} >stdout 2>stderr || am__got_rc=$?
269   cat stderr >&2
270   cat stdout
271   if test $am_test_protocol = none; then
272     test $am__got_rc -eq $am__exp_rc || exit 1
273     return
274   fi
275   if test -z "$am__desc"; then
276     if test $am__got_rc -eq $am__exp_rc; then
277       am__desc="automake exited $am__got_rc"
278     else
279       am__desc="automake exited $am__got_rc, expecting $am__exp_rc"
280     fi
281   fi
282   command_ok_ "$am__desc" test $am__got_rc -eq $am__exp_rc
283 }
284
285 # AUTOMAKE_fails [-d DESCRIPTION] [OPTIONS...]
286 # --------------------------------------------
287 # Run automake with OPTIONS, and fail if doesn't exit with status 1.
288 # Should be polymorphic for TAP and "plain" tests.  The DESCRIPTION,
289 # when provided, is used for console reporting, only if the TAP
290 # protocol is in use in the current test script.
291 AUTOMAKE_fails ()
292 {
293   AUTOMAKE_run -e 1 ${1+"$@"}
294 }
295
296 # extract_configure_help { --OPTION | VARIABLE-NAME } [FILES]
297 # -----------------------------------------------------------
298 # Use this to extract from the output of "./configure --help" (or similar)
299 # the description or help message associated to the given --OPTION or
300 # VARIABLE-NAME.
301 extract_configure_help ()
302 {
303   am__opt_re='' am__var_re=''
304   case $1 in
305     --*'=')   am__opt_re="^  $1";;
306     --*'[=]') am__opt_re='^  '$(printf '%s\n' "$1" | sed 's/...$//')'\[=';;
307     --*)      am__opt_re="^  $1( .*|$)";;
308       *)      am__var_re="^  $1( .*|$)";;
309   esac
310   shift
311   if test x"$am__opt_re" != x; then
312     LC_ALL=C awk '
313       /'"$am__opt_re"'/        { print; do_print = 1; next; }
314       /^$/                     { do_print = 0; next }
315       /^  --/                  { do_print = 0; next }
316       (do_print == 1)          { print }
317     ' ${1+"$@"}
318   else
319     LC_ALL=C awk '
320       /'"$am__var_re"'/        { print; do_print = 1; next; }
321       /^$/                     { do_print = 0; next }
322       /^  [A-Z][A-Z0-9_]* /    { do_print = 0; next }
323       /^  [A-Z][A-Z0-9_]*$/    { do_print = 0; next }
324       (do_print == 1)          { print }
325     ' ${1+"$@"}
326   fi
327 }
328
329 # grep_configure_help { --OPTION | VARIABLE-NAME } REGEXP
330 # -------------------------------------------------------
331 # Grep the section of "./configure --help" output associated with either
332 # --OPTION or VARIABLE-NAME for the given *extended* regular expression.
333 grep_configure_help ()
334 {
335   ./configure --help > am--all-help \
336     || { cat am--all-help; exit 1; }
337   cat am--all-help
338   extract_configure_help "$1" am--all-help > am--our-help \
339     || { cat am--our-help; exit 1; }
340   cat am--our-help
341   $EGREP "$2" am--our-help || exit 1
342 }
343
344 # using_gmake
345 # -----------
346 # Return success if $MAKE is GNU make, return failure otherwise.
347 # Caches the result for speed reasons.
348 using_gmake ()
349 {
350   case $am__using_gmake in
351     yes)
352       return 0;;
353     no)
354       return 1;;
355     '')
356       # Use --version AND -v, because SGI Make doesn't fail on --version.
357       # Also grep for GNU because newer versions of FreeBSD make do
358       # not complain about --version (they seem to silently ignore it).
359       if $MAKE --version -v | grep GNU; then
360         am__using_gmake=yes
361         return 0
362       else
363         am__using_gmake=no
364         return 1
365       fi;;
366     *)
367       fatal_ "invalid value for \$am__using_gmake: '$am__using_gmake'";;
368   esac
369 }
370 am__using_gmake="" # Avoid interferences from the environment.
371
372 # make_can_chain_suffix_rules
373 # ---------------------------
374 # Return 0 if $MAKE is a make implementation that can chain suffix rules
375 # automatically, return 1 otherwise.  Caches the result for speed reasons.
376 make_can_chain_suffix_rules ()
377 {
378   if test -z "$am__can_chain_suffix_rules"; then
379     if using_gmake; then
380       am__can_chain_suffix_rules=yes
381       return 0
382     else
383       mkdir am__chain.dir$$
384       cd am__chain.dir$$
385       unindent > Makefile << 'END'
386         .SUFFIXES: .u .v .w
387         .u.v: ; cp $< $@
388         .v.w: ; cp $< $@
389 END
390       echo make can chain suffix rules > foo.u
391       if $MAKE foo.w && diff foo.u foo.w; then
392         am__can_chain_suffix_rules=yes
393       else
394         am__can_chain_suffix_rules=no
395       fi
396       cd ..
397       rm -rf am__chain.dir$$
398     fi
399   fi
400   case $am__can_chain_suffix_rules in
401     yes) return 0;;
402      no) return 1;;
403       *) fatal_ "make_can_chain_suffix_rules: internal error";;
404   esac
405 }
406 am__can_chain_suffix_rules="" # Avoid interferences from the environment.
407
408 # useless_vpath_rebuild
409 # ---------------------
410 # Tell whether $MAKE suffers of the bug triggering automake bug#7884.
411 # For example, this happens with FreeBSD make, since in a VPATH build
412 # it tends to rebuilt files for which there is an explicit or even just
413 # a suffix rule, even if said files are already available in the VPATH
414 # directory.
415 useless_vpath_rebuild ()
416 {
417   if test -z "$am__useless_vpath_rebuild"; then
418     if using_gmake; then
419       am__useless_vpath_rebuild=no
420       return 1
421     fi
422     mkdir am__vpath.dir$$
423     cd am__vpath.dir$$
424     touch foo.a foo.b bar baz
425     mkdir build
426     cd build
427     unindent > Makefile << 'END'
428         .SUFFIXES: .a .b
429         VPATH = ..
430         all: foo.b baz
431         .PHONY: all
432         .a.b: ; cp $< $@
433         baz: bar ; cp ../baz bar
434 END
435     if run_make all && test ! -e foo.b && test ! -e bar; then
436       am__useless_vpath_rebuild=no
437     else
438       am__useless_vpath_rebuild=yes
439     fi
440     cd ../..
441     rm -rf am__vpath.dir$$
442   fi
443   case $am__useless_vpath_rebuild in
444     yes) return 0;;
445      no) return 1;;
446      "") ;;
447       *) fatal_ "useless_vpath_rebuild: internal error";;
448   esac
449 }
450 am__useless_vpath_rebuild=""
451
452 yl_distcheck () { useless_vpath_rebuild || run_make distcheck ${1+"$@"}; }
453
454 # count_test_results total=N pass=N fail=N xpass=N xfail=N skip=N error=N
455 # -----------------------------------------------------------------------
456 # Check that a testsuite run driven by the parallel-tests harness has
457 # had the specified numbers of test results (specified by kind).
458 # This function assumes that the output of "make check" or "make recheck"
459 # has been saved in the 'stdout' file in the current directory, and its
460 # log in the 'test-suite.log' file.
461 count_test_results ()
462 {
463   # Use a subshell so that we won't pollute the script namespace.
464   (
465     # TODO: Do proper checks on the arguments?
466     total=ERR pass=ERR fail=ERR xpass=ERR xfail=ERR skip=ERR error=ERR
467     eval "$@"
468     # For debugging.
469     $EGREP -i '(total|x?pass|x?fail|skip|error)' stdout || :
470     rc=0
471     # Avoid spurious failures with shells with "overly sensible"
472     # errexit shell flag, such as e.g., Solaris /bin/sh.
473     set +e
474     test $(grep -c '^PASS:'  stdout) -eq $pass  || rc=1
475     test $(grep -c '^XFAIL:' stdout) -eq $xfail || rc=1
476     test $(grep -c '^SKIP:'  stdout) -eq $skip  || rc=1
477     test $(grep -c '^FAIL:'  stdout) -eq $fail  || rc=1
478     test $(grep -c '^XPASS:' stdout) -eq $xpass || rc=1
479     test $(grep -c '^ERROR:' stdout) -eq $error || rc=1
480     grep "^# TOTAL:  *$total$" stdout || rc=1
481     grep "^# PASS:  *$pass$"   stdout || rc=1
482     grep "^# XFAIL:  *$xfail$" stdout || rc=1
483     grep "^# SKIP:  *$skip$"   stdout || rc=1
484     grep "^# FAIL:  *$fail$"   stdout || rc=1
485     grep "^# XPASS:  *$xpass$" stdout || rc=1
486     grep "^# ERROR:  *$error$" stdout || rc=1
487     test $rc -eq 0
488   )
489 }
490
491 # get_shell_script SCRIPT-NAME
492 # -----------------------------
493 # Fetch an Automake-provided shell script from the 'lib/' directory into
494 # the current directory, and, if the '$am_test_prefer_config_shell'
495 # variable is set to "yes", modify its shebang line to use $SHELL instead
496 # of /bin/sh.
497 get_shell_script ()
498 {
499   test ! -f "$1" || rm -f "$1" || return 99
500   if test x"$am_test_prefer_config_shell" = x"yes"; then
501     sed "1s|#!.*|#! $SHELL|" "$am_scriptdir/$1" > "$1" \
502      && chmod a+x "$1" \
503      || return 99
504   else
505     cp -f "$am_scriptdir/$1" . || return 99
506   fi
507   sed 10q "$1" # For debugging.
508 }
509
510 # require_xsi SHELL
511 # -----------------
512 # Skip the test if the given shell fails to support common XSI constructs.
513 require_xsi ()
514 {
515   test $# -eq 1 || fatal_ "require_xsi needs exactly one argument"
516   echo "$me: trying some XSI constructs with $1"
517   $1 -c "$xsi_shell_code" || skip_all_ "$1 lacks XSI features"
518 }
519 # Shell code supposed to work only with XSI shells.  Keep this in sync
520 # with libtool.m4:_LT_CHECK_SHELL_FEATURES.
521 xsi_shell_code='
522   _lt_dummy="a/b/c"
523   test "${_lt_dummy##*/},${_lt_dummy%/*},${_lt_dummy#??}"${_lt_dummy%"$_lt_dummy"}, \
524       = c,a/b,b/c, \
525     && eval '\''test $(( 1 + 1 )) -eq 2 \
526     && test "${#_lt_dummy}" -eq 5'\'
527
528 # fetch_tap_driver
529 # ----------------
530 # Fetch the Automake-provided TAP driver from the 'lib/' directory into
531 # the current directory, and edit its shebang line so that it will be
532 # run with the perl interpreter determined at configure time.
533 fetch_tap_driver ()
534 {
535   # TODO: we should devise a way to make the shell TAP driver tested also
536   # TODO: with /bin/sh, for better coverage.
537   case $am_tap_implementation in
538     # Extra quoting required to avoid maintainer-check spurious failures.
539    'perl')
540       $PERL -MTAP::Parser -e 1 \
541         || skip_all_ "cannot import TAP::Parser perl module"
542       sed "1s|#!.*|#! $PERL -w|" "$am_scriptdir"/tap-driver.pl >tap-driver
543       ;;
544     shell)
545       AM_TAP_AWK=$AWK; export AM_TAP_AWK
546       sed "1s|#!.*|#! $SHELL|" "$am_scriptdir"/tap-driver.sh >tap-driver
547       ;;
548     *)
549       fatal_ "invalid \$am_tap_implementation '$am_tap_implementation'" ;;
550   esac \
551     && chmod a+x tap-driver \
552     || framework_failure_ "couldn't fetch $am_tap_implementation TAP driver"
553   sed 10q tap-driver # For debugging.
554 }
555 am_tap_implementation=${am_tap_implementation-shell}
556
557 # $PYTHON and support for PEP-3147.  Needed to check our python-related
558 # install rules.
559 python_has_pep3147 ()
560 {
561   if test -z "$am_pep3147_tag"; then
562     am_pep3147_tag=$($PYTHON -c 'import imp; print(imp.get_tag())') \
563       || am_pep3147_tag=none
564   fi
565   test $am_pep3147_tag != none
566 }
567 am_pep3147_tag=
568
569 # pyc_location [-p] [FILE]
570 # ------------------------
571 # Determine what the actual location of the given '.pyc' or '.pyo'
572 # byte-compiled file should be, taking into account PEP-3147.  Save
573 # the location in the '$am_pyc_file' variable.  If the '-p' option
574 # is given, print the location on the standard output as well.
575 pyc_location ()
576 {
577   case $#,$1 in
578     2,-p) am_pyc_print=yes; shift;;
579      1,*) am_pyc_print=no;;
580        *) fatal_ "pyc_location: invalid usage";;
581   esac
582   if python_has_pep3147; then
583     case $1 in
584       */*) am_pyc_dir=${1%/*} am_pyc_base=${1##*/};;
585         *) am_pyc_dir=. am_pyc_base=$1;;
586     esac
587     am_pyc_ext=${am_pyc_base##*.}
588     am_pyc_base=${am_pyc_base%.py?}
589     am_pyc_file=$am_pyc_dir/__pycache__/$am_pyc_base.$am_pep3147_tag.$am_pyc_ext
590   else
591     am_pyc_file=$1
592   fi
593   test $am_pyc_print = no || printf '%s\n' "$am_pyc_file"
594 }
595
596 # py_installed [--not] FILE
597 # --------------------------
598 # Check that the given python FILE has been installed (resp. *not*
599 # installed, if the '--not' option is specified).  If FILE is a
600 # byte-compiled '.pyc' file, the new installation layout specified
601 # by PEP-3147 will be taken into account.
602 py_installed ()
603 {
604   case $#,$1 in
605         1,*) am_test_py_file='test -f';;
606     2,--not) am_test_py_file='test ! -e'; shift;;
607           *) fatal_ "pyc_installed: invalid usage";;
608   esac
609   case $1 in
610     *.py[co]) pyc_location "$1"; am_target_py_file=$am_pyc_file;;
611            *) am_target_py_file=$1;;
612   esac
613   $am_test_py_file "$am_target_py_file"
614 }
615
616 # Usage: require_compiler_ {cc|c++|fortran|fortran77}
617 require_compiler_ ()
618 {
619   case $# in
620     0) fatal_ "require_compiler_: missing argument";;
621     1) ;;
622     *) fatal_ "require_compiler_: too many arguments";;
623   esac
624   case $1 in
625     cc)
626       am__comp_lang="C"
627       am__comp_var=CC
628       am__comp_flag_vars='CFLAGS CPPFLAGS'
629       ;;
630     c++)
631       am__comp_lang="C++"
632       am__comp_var=CXX
633       am__comp_flag_vars='CXXFLAGS CPPFLAGS'
634       ;;
635     fortran)
636       am__comp_lang="Fortran"
637       am__comp_var=FC
638       am__comp_flag_vars='FCFLAGS'
639       ;;
640     fortran77)
641       am__comp_lang="Fortran 77"
642       am__comp_var=F77
643       am__comp_flag_vars='FFLAGS'
644       ;;
645   esac
646   shift
647   eval "am__comp_prog=\${$am__comp_var}" \
648     || fatal_ "expanding \${$am__comp_var} in require_compiler_"
649   case $am__comp_prog in
650     "")
651       fatal_ "botched configuration: \$$am__comp_var is empty";;
652     false)
653       skip_all_ "no $am__comp_lang compiler available";;
654     autodetect|autodetected)
655       # Let the ./configure commands in the test script try to determine
656       # these automatically.
657       unset $am__comp_var $am__comp_flag_vars;;
658     *)
659       # Pre-set these for the ./configure commands in the test script.
660       export $am__comp_var $am__comp_flag_vars;;
661   esac
662   # Delete private variables.
663   unset am__comp_lang am__comp_prog am__comp_var am__comp_flag_vars
664 }
665
666 ## ----------------------------------------------------------- ##
667 ##  Checks for required tools, and additional setups (if any)  ##
668 ##  required by them.                                          ##
669 ## ----------------------------------------------------------- ##
670
671 require_tool ()
672 {
673   am_tool=$1
674   case $1 in
675     cc|c++|fortran|fortran77)
676       require_compiler_ $1;;
677     xsi-lib-shell)
678       if test x"$am_test_prefer_config_shell" = x"yes"; then
679         require_xsi "$SHELL"
680       else
681         require_xsi "/bin/sh"
682       fi
683       ;;
684     bzip2)
685       # Do not use --version, older versions bzip2 still tries to compress
686       # stdin.
687       echo "$me: running bzip2 --help"
688       bzip2 --help \
689         || skip_all_ "required program 'bzip2' not available"
690       ;;
691     cl)
692       CC=cl
693       # Don't export CFLAGS, as that could have been initialized to only
694       # work with the C compiler detected at configure time.  If the user
695       # wants CFLAGS to also influence 'cl', he can still export CFLAGS
696       # in the environment "by hand" before calling the testsuite.
697       export CC CPPFLAGS
698       echo "$me: running $CC -?"
699       $CC -? || skip_all_ "Microsoft C compiler '$CC' not available"
700       ;;
701     etags)
702       # Exuberant Ctags will create a TAGS file even
703       # when asked for --help or --version.  (Emacs's etags
704       # does not have such problem.)  Use -o /dev/null
705       # to make sure we do not pollute the build directory.
706       echo "$me: running etags --version -o /dev/null"
707       etags --version -o /dev/null \
708         || skip_all_ "required program 'etags' not available"
709       ;;
710     GNUmake)
711       for am_make in "$MAKE" gmake gnumake :; do
712         MAKE=$am_make
713         am__using_gmake= # Invalidate cache used by 'using_gmake()'.
714         test "$MAKE" = : && break
715         echo "$me: determine whether $MAKE is GNU make"
716         using_gmake && break
717         : For shells with busted 'set -e'.
718       done
719       test "$MAKE" = : && skip_all_ "this test requires GNU make"
720       export MAKE
721       unset am_make
722       ;;
723     gcj)
724       GCJ=$GNU_GCJ GCJFLAGS=$GNU_GCJFLAGS; export GCJ GCJFLAGS
725       test "$GCJ" = false && skip_all_ "GNU Java compiler unavailable"
726       : For shells with busted 'set -e'.
727       ;;
728     gcc)
729       CC=$GNU_CC CFLAGS=$GNU_CFLAGS; export CC CFLAGS CPPFLAGS
730       test "$CC" = false && skip_all_ "GNU C compiler unavailable"
731       : For shells with busted 'set -e'.
732       ;;
733     g++)
734       CXX=$GNU_CXX CXXFLAGS=$GNU_CXXFLAGS; export CXX CXXFLAGS CPPFLAGS
735       test "$CXX" = false && skip_all_ "GNU C++ compiler unavailable"
736       : For shells with busted 'set -e'.
737       ;;
738     gfortran)
739       FC=$GNU_FC FCFLAGS=$GNU_FCFLAGS; export FC FCFLAGS
740       test "$FC" = false && skip_all_ "GNU Fortran compiler unavailable"
741       case " $required " in
742         *\ g77\ *) ;;
743         *) F77=$FC FFLAGS=$FCFLAGS; export F77 FFLAGS;;
744       esac
745       ;;
746     g77)
747       F77=$GNU_F77 FFLAGS=$GNU_FFLAGS; export F77 FFLAGS
748       test "$F77" = false && skip_all_ "GNU Fortran 77 compiler unavailable"
749       case " $required " in
750         *\ gfortran\ *) ;;
751         *) FC=$F77 FCFLAGS=$FFLAGS; export FC FCFLAGS;;
752       esac
753       ;;
754     grep-nonprint)
755       # Check that grep can parse nonprinting characters correctly.
756       # BSD 'grep' works from a pipe, but not a seekable file.
757       # GNU or BSD 'grep -a' works on files, but is not portable.
758       case $(echo "$esc" | grep .)$(echo "$esc" | grep "$esc") in
759         "$esc$esc") ;;
760         *) skip_ "grep can't handle nonprinting characters correctly";;
761       esac
762       ;;
763     javac)
764       # The Java compiler from JDK 1.5 (and presumably earlier versions)
765       # cannot handle the '-version' option by itself: it bails out
766       # telling that source files are missing.  Adding also the '-help'
767       # option seems to solve the problem.
768       echo "$me: running javac -version -help"
769       javac -version -help || skip_all_ "Sun Java compiler not available"
770       ;;
771     java)
772       # See the comments above about 'javac' for why we use also '-help'.
773       echo "$me: running java -version -help"
774       java -version -help || skip_all_ "Sun Java interpreter not found"
775       ;;
776     lib)
777       AR=lib; export AR
778       # Attempting to create an empty archive will actually not
779       # create the archive, but lib will output its version.
780       echo "$me: running $AR -out:defstest.lib"
781       $AR -out:defstest.lib \
782         || skip_all_ "Microsoft 'lib' utility not available"
783       ;;
784     makedepend)
785       echo "$me: running makedepend -f-"
786       makedepend -f- \
787         || skip_all_ "required program 'makedepend' not available"
788       ;;
789     mingw)
790       uname_s=$(uname -s || echo UNKNOWN)
791       echo "$me: system name: $uname_s"
792       case $uname_s in
793         MINGW*) ;;
794         *) skip_all_ "this test requires MSYS in MinGW mode" ;;
795       esac
796       unset uname_s
797       ;;
798     non-root)
799       # Skip this test case if the user is root.
800       # We try to append to a read-only file to detect this.
801       priv_check_temp=am--priv-check.$$
802       touch $priv_check_temp && chmod a-w $priv_check_temp \
803         || framework_failure_ "creating unwritable file $priv_check_temp"
804       # Not a useless use of subshell: lesser shells might bail
805       # out if a builtin fails.
806       overwrite_status=0
807       (echo foo >> $priv_check_temp) || overwrite_status=$?
808       rm -f $priv_check_temp
809       if test $overwrite_status -eq 0; then
810         skip_all_ "cannot drop file write permissions"
811       fi
812       unset priv_check_temp overwrite_status
813       ;;
814     # Extra quoting required to avoid maintainer-check spurious failures.
815     'perl-threads')
816       if test "$WANT_NO_THREADS" = "yes"; then
817         skip_all_ "Devel::Cover cannot cope with threads"
818       fi
819       ;;
820     native)
821       # Don't use "&&" here, to avoid a bug of 'set -e' present in
822       # some (even relatively recent) versions of the BSD shell.
823       # We add the dummy "else" branch for extra safety.
824       ! cross_compiling || skip_all_ "doesn't work in cross-compile mode"
825       ;;
826     python)
827       PYTHON=${PYTHON-python}
828       # Older python versions don't support --version, they have -V.
829       echo "$me: running $PYTHON -V"
830       $PYTHON -V || skip_all_ "python interpreter not available"
831       ;;
832     ro-dir)
833       # Skip this test case if read-only directories aren't supported
834       # (e.g., under DOS.)
835       ro_dir_temp=ro_dir.$$
836       mkdir $ro_dir_temp && chmod a-w $ro_dir_temp \
837         || framework_failure_ "creating unwritable directory $ro_dir_temp"
838       # Not a useless use of subshell: lesser shells might bail
839       # out if a builtin fails.
840       create_status=0
841       (: > $ro_dir_temp/probe) || create_status=$?
842       rm -rf $ro_dir_temp
843       if test $create_status -eq 0; then
844         skip_all_ "cannot drop directory write permissions"
845       fi
846       unset ro_dir_temp create_status
847       ;;
848     runtest)
849       # DejaGnu's runtest program. We rely on being able to specify
850       # the program on the runtest command-line. This requires
851       # DejaGnu 1.4.3 or later.
852       echo "$me: running runtest SOMEPROGRAM=someprogram --version"
853       runtest SOMEPROGRAM=someprogram --version \
854         || skip_all_ "DejaGnu is not available"
855       ;;
856     tex)
857       # No all versions of Tex support '--version', so we use
858       # a configure check.
859       if test -z "$TEX"; then
860         skip_all_ "TeX is required, but it wasn't found by configure"
861       fi
862       ;;
863     lex)
864       test x"$LEX" = x"false" && skip_all_ "lex not found or disabled"
865       export LEX
866       ;;
867     yacc)
868       test x"$YACC" = x"false" && skip_all_ "yacc not found or disabled"
869       export YACC
870       ;;
871     flex)
872       LEX=flex; export LEX
873       echo "$me: running flex --version"
874       flex --version || skip_all_ "required program 'flex' not available"
875       ;;
876     bison)
877       YACC='bison -y'; export YACC
878       echo "$me: running bison --version"
879       bison --version || skip_all_ "required program 'bison' not available"
880       ;;
881     valac)
882       echo "$me: running valac --version"
883       if ! valac --version; then
884         skip_all_ "required program 'valac' not available"
885       elif cross_compiling; then
886         skip_all_ "cross-compiling valac-generated C files is brittle"
887       fi
888       # TODO: We also know we need GNU make, the C compiler, and pkg-config
889       # here, but there is no easy way to express this with the current
890       # code organization.  We should improve the situation, sooner or
891       # later.  At which point the tests requiring 'valac' can drop the
892       # explicit requirements for those tools.
893       ;;
894     *)
895       # Generic case: the tool must support --version.
896       echo "$me: running $1 --version"
897       # It is not likely but possible that the required tool is a special
898       # builtin, in which case the shell is allowed to exit after an error.
899       # So we need the subshell here.  Also, some tools, like Sun cscope,
900       # can be interactive without redirection.
901       ($1 --version) </dev/null \
902         || skip_all_ "required program '$1' not available"
903       ;;
904   esac
905 }
906
907 process_requirements ()
908 {
909   # Look for (and maybe set up) required tools and/or system features;
910   # skip the current test if they are not found.
911   for am_tool in $*; do
912     require_tool $am_tool
913   done
914   # We might need extra m4 macros, e.g., for Libtool or Gettext.
915   for am_tool in gettext libtool pkg-config; do
916     case " $required " in
917       # The lack of whitespace after $am_tool is intended.
918       *" $am_tool"*) . ./t/$am_tool-macros.dir/get.sh;;
919     esac
920   done
921   unset am_tool
922 }
923
924 ## ---------------------------------------------------------------- ##
925 ##  Create and set up of the temporary directory used by the test.  ##
926 ## ---------------------------------------------------------------- ##
927
928 am_setup_testdir ()
929 {
930   # The subdirectory where the current test script will run and write its
931   # temporary/data files.  This will be created shortly, and will be removed
932   # by the cleanup trap below if the test passes.  If the test doesn't pass,
933   # this directory will be kept, to facilitate debugging.
934   am_test_subdir=${argv0#$am_rel_srcdir/}
935   case $am_test_subdir in
936     */*) am_test_subdir=${am_test_subdir%/*}/$me.dir;;
937       *) am_test_subdir=$me.dir;;
938   esac
939   test ! -e $am_test_subdir || rm_rf_ $am_test_subdir \
940     || framework_failure_ "removing old test subdirectory"
941   $MKDIR_P $am_test_subdir \
942     || framework_failure_ "creating test subdirectory"
943   cd $am_test_subdir \
944     || framework_failure_ "cannot chdir into test subdirectory"
945   if test x"$am_create_testdir" != x"empty"; then
946     cp "$am_scriptdir"/install-sh "$am_scriptdir"/missing \
947        "$am_scriptdir"/depcomp . \
948       || framework_failure_ "fetching common files from $am_scriptdir"
949     # Build appropriate environment in test directory.  E.g., create
950     # configure.ac, touch all necessary files, etc.  Don't use AC_OUTPUT,
951     # but AC_CONFIG_FILES so that appending still produces a valid
952     # configure.ac.  But then, tests running config.status really need
953     # to append AC_OUTPUT.
954     {
955       echo "AC_INIT([$me], [1.0])"
956       if test x"$am_serial_tests" = x"yes"; then
957         echo "AM_INIT_AUTOMAKE([serial-tests])"
958       else
959         echo "AM_INIT_AUTOMAKE"
960       fi
961       echo "AC_CONFIG_FILES([Makefile])"
962     } >configure.ac || framework_failure_ "creating configure.ac skeleton"
963   fi
964 }
965
966 am_extra_info ()
967 {
968   echo "Running from installcheck: $am_running_installcheck"
969   echo "Test Protocol: $am_test_protocol"
970   echo "PATH = $PATH"
971 }