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