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