Merge branch 'maint' into 'yacc-work'
[platform/upstream/automake.git] / tests / defs.in
1 # -*- shell-script -*-
2 # @configure_input@
3 #
4 # Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
5 # 2005, 2006, 2007, 2008, 2009, 2011 Free Software Foundation, Inc.
6 #
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2, or (at your option)
10 # any later version.
11 #
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 # GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
19
20 # Defines for Automake testing environment.
21 # Tom Tromey <tromey@cygnus.com>
22
23 # Be more Bourne compatible.
24 # (Snippet copied from configure's initialization in Autoconf 2.64)
25 DUALCASE=1; export DUALCASE # for MKS sh
26 if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then
27   emulate sh
28   NULLCMD=:
29   # Pre-4.2 versions of Zsh do word splitting on ${1+"$@"}, which
30   # is contrary to our usage.  Disable this feature.
31   alias -g '${1+"$@"}'='"$@"'
32   setopt NO_GLOB_SUBST
33 else
34   case `(set -o) 2>/dev/null` in *posix*) set -o posix;; esac
35 fi
36
37 # A single whitespace character.
38 sp=' '
39 # A tabulation character.
40 tab='   '
41 # A newline character.
42 nl='
43 '
44
45 # As autoconf-generated configure scripts do, ensure that IFS
46 # is defined initially, so that saving and restoring $IFS works.
47 IFS=$sp$tab$nl
48
49 # Ensure we are running from the right directory.
50 test -f ./defs || {
51    echo "defs: not found in current directory" 1>&2
52    exit 1
53 }
54
55 if test -z "$srcdir"; then
56    # compute $srcdir.
57    srcdir=`echo "$0" | sed -e 's,/[^\\/]*$,,'`
58    test "$srcdir" = $0 && srcdir=.
59 else :; fi
60
61 # Ensure $srcdir is set correctly.
62 test -f "$srcdir/defs.in" || {
63    echo "$srcdir/defs.in not found, check \$srcdir" 1>&2
64    exit 1
65 }
66
67 # The name of the current test (without the `.test' suffix).
68 # Test scripts can override it if they need to (but this should
69 # be done carefully, and *before* including ./defs).
70 if test -z "$me"; then
71   me=`echo "$0" | sed -e 's,.*[\\/],,;s/\.test$//'`
72 elif env | grep '^me=' >/dev/null; then
73   echo "$0: variable \`me' is set in the environment: this is unsafe" >&2
74   exit 99
75 fi
76
77 # Check that the environment is properly sanitized.
78 for var in required parallel_tests; do
79   if env | grep "^$var=" >/dev/null; then
80     echo "$me: variable \`$var' is set in the environment:" \
81          "this is unsafe" >&2
82     exit 99
83   fi
84 done
85 unset var
86
87 # This might be used in testcases checking distribution-related features.
88 # Test scripts are free to override this if they need to.
89 distdir=$me-1.0
90
91 APIVERSION='@APIVERSION@'
92 PATH_SEPARATOR='@PATH_SEPARATOR@'
93
94 # Make sure we override the user shell.
95 SHELL='@SHELL@'
96 export SHELL
97 # User can override various tools used.
98 test -z "$PERL" && PERL='@PERL@'
99 test -z "$YACC" && YACC='@YACC@'
100 test -z "$LEX" && LEX='@LEX@'
101 test -z "$MAKE" && MAKE=make
102 test -z "$AUTOCONF" && AUTOCONF="@am_AUTOCONF@"
103 test -z "$AUTOM4TE" && AUTOM4TE="@am_AUTOM4TE@"
104 test -z "$AUTORECONF" && AUTORECONF="@am_AUTORECONF@"
105 test -z "$AUTOHEADER" && AUTOHEADER="@am_AUTOHEADER@"
106 test -z "$AUTOUPDATE" && AUTOUPDATE="@am_AUTOUPDATE@"
107 test -z "$MISSING" && MISSING=`pwd`/../lib/missing
108 # Use -Werror because this also turns some Perl warnings into error.
109 # (Tests for which this is inappropriate should use -Wno-error.)
110 test -z "$ACLOCAL" && ACLOCAL="aclocal-$APIVERSION -Werror"
111
112 # See how Automake should be run.  We put --foreign as the default
113 # strictness to avoid having to create lots and lots of files.  A test
114 # can override this by specifying a different strictness.  Use -Wall
115 # -Werror by default.  Tests for which this is inappropriate
116 # (e.g. when testing that a warning is enabled by a specific switch)
117 # should use -Wnone or/and -Wno-error
118 test -z "$AUTOMAKE" && AUTOMAKE="automake-$APIVERSION --foreign -Werror -Wall"
119
120 PATH="`pwd`$PATH_SEPARATOR$PATH"
121 echo "$PATH"
122 # Some shells forget to export modified environment variables.
123 # (See note about `export' in the Autoconf manual.)
124 export PATH
125
126 # We use a trap below for cleanup.  This requires us to go through
127 # hoops to get the right exit status transported through the signal.
128 # So use `Exit STATUS' instead of `exit STATUS' inside of the tests.
129 # Turn off errexit here so that we don't trip the bug with OSF1/Tru64
130 # sh inside this function.
131 Exit ()
132 {
133   set +e
134   (exit $1)
135   exit $1
136 }
137
138 # Print warnings (e.g., about skipped and failed tests) to this file
139 # number.  Override by putting, say:
140 #   stderr_fileno_=9; export stderr_fileno_; exec 9>&2;
141 # in the definition of AM_TESTS_ENVIRONMENT.
142 # This is useful when using automake's parallel tests mode, to print the
143 # reason for skip/failure to console, rather than to the *.log files.
144 : ${stderr_fileno_=2}
145
146 # Copied from Gnulib's `tests/init.sh'.
147 warn_ () { echo "$@" 1>&$stderr_fileno_; }
148 fail_ () { warn_ "$me: failed test: $@"; Exit 1; }
149 skip_ () { warn_ "$me: skipped test: $@"; Exit 77; }
150 fatal_ () { warn_ "$me: hard error: $@"; Exit 99; }
151 framework_failure_ () { warn_ "$me: set-up failure: $@"; Exit 99; }
152
153 # cross_compiling
154 # ---------------
155 # Tell whether we are cross-compiling.  This is especially useful to skip
156 # tests (or portions of them) that requires a native compiler.
157 cross_compiling ()
158 {
159   test x"$host_alias" != x
160 }
161
162 # So that we can force the use of correct gcc, g++ etc., consistently
163 # with cross-compilation settings.
164 if cross_compiling; then
165   am__tool_prefix="$host_alias-"
166 else
167   am__tool_prefix=
168 fi
169
170 for tool in : $required
171 do
172   # Check that each required tool is present.
173   case $tool in
174     :) ;;
175     cc|c++|fortran|fortran77)
176       echo "$me: dummy requirement '$tool', no check done"
177       ;;
178     bzip2)
179       # Do not use --version, bzip2 still tries to compress stdin.
180       echo "$me: running bzip2 --help"
181       ( bzip2 --help ) || exit 77
182       ;;
183     etags)
184       # Exuberant Ctags will create a TAGS file even
185       # when asked for --help or --version.  (Emacs's etags
186       # does not have such problem.)  Use -o /dev/null
187       # to make sure we do not pollute the tests/ directory.
188       echo "$me: running etags --version -o /dev/null"
189       ( etags --version -o /dev/null ) || exit 77
190       ;;
191     GNUmake)
192       # Use --version AND -v, because SGI Make doesn't fail on --version.
193       # Also grep for GNU because newer versions of FreeBSD make do
194       # not complain about `--version' (they seem to silently ignore it).
195       echo "$me: running $MAKE --version -v | grep GNU"
196       ( $MAKE --version -v | grep GNU ) || exit 77
197       ;;
198     gcc)
199       # When gcc is required, export `CC=gcc' so that ./configure
200       # always use it.  This is important only when the user
201       # has defined CC in his environment, otherwise ./configure will
202       # prefer gcc to other compilers.
203       CC=${am__tool_prefix}gcc
204       export CC
205       echo "$me: running $CC --version"
206       ( $CC --version ) || exit 77
207       ;;
208     gcj)
209       GCJ=${am__tool_prefix}gcj
210       export GCJ
211       echo "$me: running $GCJ --version"
212       ( $GCJ --version ) || exit 77
213       ( $GCJ -v ) || exit 77
214       ;;
215     g++)
216       CXX=${am__tool_prefix}g++
217       export CXX
218       echo "$me: running $CXX --version"
219       ( $CXX --version ) || exit 77
220       ;;
221     gfortran)
222       FC=${am__tool_prefix}gfortran
223       export FC
224       echo "$me: running $FC --version"
225       $FC --version || skip_ "GNU Fortran compiler not available"
226       echo "$me: running $FC -v"
227       $FC -v || skip_ "botched installation for GNU Fortran compiler"
228       case " $required " in
229         *\ g77\ *) ;;
230         *) F77=$FC; export F77;;
231       esac
232       ;;
233     g77)
234       F77=${am__tool_prefix}g77
235       export F77
236       echo "$me: running $F77 --version"
237       $F77 --version || skip_ "GNU Fortran 77 compiler not available"
238       echo "$me: running $F77 -v"
239       $F77 -v || skip_ "botched installation for GNU Fortran 77 compiler"
240       case " $required " in
241         *\ gfortran\ *) ;;
242         *) FC=$F77; export FC;;
243       esac
244       ;;
245     icc)
246       CC=icc
247       export CC
248       # There is no way to ask *only* the compiler's version.
249       # This tool always wants to do something (by default
250       # it will try link *nothing* and complain it cannot find
251       # main(); funny).  Use -help so it does not try linking anything.
252       echo "$me: running $CC -V -help"
253       ( $CC -V -help ) || exit 77
254       ;;
255     javac)
256       # The Java compiler from JDK 1.5 (and presumably earlier versions)
257       # cannot handle the `-version' option by itself: it bails out
258       # telling that source files are missing.  Adding also the `-help'
259       # option seems to solve the problem.
260       echo "$me: running javac -version -help"
261       javac -version -help || exit 77
262       ;;
263     makedepend)
264       echo "$me: running makedepend -f-"
265       ( makedepend -f- ) || exit 77
266       ;;
267     makeinfo-html)
268       # Make sure makeinfo understands --html.
269       echo "$me: running makeinfo --html --version"
270       ( makeinfo --html --version ) || exit 77
271       ;;
272     non-root)
273       # Skip this test case if the user is root.
274       # We try to append to a read-only file to detect this.
275       priv_check_temp=priv-check.$$
276       touch $priv_check_temp || exit 1
277       chmod a-w $priv_check_temp || exit 1
278       (echo foo >> $priv_check_temp) >/dev/null 2>&1
279       overwrite_status=$?
280       rm -f $priv_check_temp
281       test $overwrite_status = 0 && exit 77
282       ;;
283     native)
284       cross_compiling && skip_ "doesn't work in cross-compile mode"
285       ;;
286     python)
287       # Python doesn't support --version, it has -V
288       echo "$me: running python -V"
289       ( python -V ) || exit 77
290       ;;
291     ro-dir)
292       # Skip this test case if read-only directories aren't supported
293       # (e.g., under DOS.)
294       ro_dir_temp=ro_dir.$$
295       mkdir $ro_dir_temp || exit 1
296       chmod a-w $ro_dir_temp || exit 1
297       (: > $ro_dir_temp/probe) >/dev/null 2>/dev/null
298       create_status=$?
299       rm -rf $ro_dir_temp
300       test $create_status = 0 && exit 77
301       ;;
302     rst2html)
303       # Try the variants that are tried in check.am.
304       while :; do
305         for r2h in $RST2HTML rst2html rst2html.py; do
306           echo "$me: running $r2h --version"
307           $r2h --version && break 2
308         done
309         exit 77
310       done
311       ;;
312     runtest)
313       # DejaGnu's runtest program. We rely on being able to specify
314       # the program on the runtest command-line. This requires
315       # DejaGnu 1.4.3 or later.
316       echo "$me: running runtest --version"
317       (runtest SOMEPROGRAM=someprogram --version) || exit 77
318       ;;
319     tex)
320       # No all versions of Tex support `--version', so we use
321       # a configure check.
322       test -n "@TEX@" || exit 77
323       ;;
324     texi2dvi-o)
325       # Texi2dvi supports `-o' since Texinfo 4.1.
326       echo "$me: running texi2dvi -o /dev/null --version"
327       ( texi2dvi -o /dev/null --version ) || exit 77
328       ;;
329     lex)
330       export LEX
331       test x"$LEX" = x"false" && skip_ "lex not found or disabled"
332       ;;
333     yacc)
334       export YACC
335       test x"$YACC" = x"false" && skip_ "yacc not found or disabled"
336       ;;
337     # Generic case: the tool must support --version.
338     *)
339       echo "$me: running $tool --version"
340       ( $tool --version ) || exit 77
341       ;;
342   esac
343 done
344
345
346 # Always use an absolute srcdir.  Otherwise symlinks made in subdirs
347 # of the test dir just won't work.
348 case "$srcdir" in
349  [\\/]* | ?:[\\/]*)
350     ;;
351
352  *)
353     srcdir=`CDPATH=: && cd "$srcdir" && pwd`
354     ;;
355 esac
356
357 curdir=`pwd`
358 testSubDir=$me.dir
359 test ! -d $testSubDir || {
360   find $testSubDir -type d ! -perm -700 -exec chmod u+rwx {} ";"
361   rm -rf $testSubDir
362 }
363 mkdir $testSubDir
364
365 sh_errexit_works=@sh_errexit_works@
366 if test "$sh_errexit_works" = yes; then
367   trap 'exit_status=$?
368     set +e
369     cd "$curdir"
370     case $exit_status,$keep_testdirs in
371     0,)
372       find $testSubDir -type d ! -perm -700 -exec chmod u+rwx {} ";"
373       rm -rf $testSubDir
374       ;;
375     esac
376     test "$signal" != 0 &&
377       echo "$me: caught signal $signal"
378     echo "$me: exit $exit_status"
379     exit $exit_status
380   ' 0
381   for signal in 1 2 13 15; do
382     trap 'signal='$signal'; { Exit 1; }' $signal
383   done
384 fi
385 signal=0
386
387 # Copy in some files we need.
388 for file in install-sh missing depcomp; do
389    cp "$srcdir/../lib/$file" "$testSubDir/$file" || Exit 1
390 done
391
392 cd ./$testSubDir
393
394 # Build appropriate environment in test directory.  Eg create
395 # configure.in, touch all necessary files, etc.
396 # Don't use AC_OUTPUT, but AC_CONFIG_FILES so that appending
397 # still produces a valid configure.ac.  But then, tests running
398 # config.status really need to append AC_OUTPUT.
399 {
400   echo "AC_INIT([$me], [1.0])"
401   if test x"$parallel_tests" = x"yes"; then
402     echo "AM_INIT_AUTOMAKE([parallel-tests])"
403   else
404     echo "AM_INIT_AUTOMAKE"
405   fi
406   echo "AC_CONFIG_FILES([Makefile])"
407 } >configure.in
408
409 # Unset some make-related variables that may cause $MAKE to act like
410 # a recursively invoked sub-make.  Any $MAKE invocation in a test is
411 # conceptually an independent invocation, not part of the main
412 # 'automake' build.
413 unset MFLAGS MAKEFLAGS AM_MAKEFLAGS MAKELEVEL
414 unset __MKLVL__ MAKE_JOBS_FIFO                     # For BSD make.
415 unset DMAKE_CHILD DMAKE_DEF_PRINTED DMAKE_MAX_JOBS # For Solaris dmake.
416 # Unset verbosity flag.
417 unset V
418 # Also unset variables that will let `make -e install' divert
419 # files into unwanted directories.
420 unset DESTDIR
421 unset prefix exec_prefix bindir datarootdir datadir docdir dvidir
422 unset htmldir includedir infodir libdir libexecdir localedir mandir
423 unset oldincludedir pdfdir psdir sbindir sharedstatedir sysconfdir
424 # Unset variables that might change the "make distcheck" behaviour.
425 unset DISTCHECK_CONFIGURE_FLAGS AM_DISTCHECK_CONFIGURE_FLAGS
426 # Also unset variables that control our test driver.  While not
427 # conceptually independent, they cause some changed semantics we
428 # need to control (and test for) in some of the tests to ensure
429 # backward-compatible behavior.
430 unset TESTS_ENVIRONMENT AM_TESTS_ENVIRONMENT
431 unset DISABLE_HARD_ERRORS
432 unset AM_COLOR_TESTS
433 unset TESTS
434 unset TEST_LOG_COMPILER
435 unset TEST_LOGS
436 unset RECHECK_LOGS
437 unset VERBOSE
438
439 echo "=== Running test $0"
440
441 # We might need extra macros, e.g., from Libtool or Gettext.
442 # Find them on the system.
443 # Use `-I $srcdir/../m4' in addition to `--acdir=$srcdir/../m4', because the
444 # other `-I' directories added for libtool and gettext might contain
445 # files from an old version of Automake that we don't want to use.
446 # Use `-Wno-syntax' because we do not want our test suite to fail because
447 # some third-party .m4 file is underquoted.
448 case $required in
449   *libtool* | *gettext* )
450     aclocaldir='@prefix@/share/aclocal'
451     extra_includes=""
452     if test -f $aclocaldir/dirlist; then
453        extra_includes=`
454        <$aclocaldir/dirlist \
455        sed  's/#.*//;s/[         ][      ]*$//g' \
456        | while read dir; do test ! -d "$dir" || echo "-I $dir"; done`
457     else :; fi
458
459     libtool_found=no
460     gettext_found=no
461     for d in $extra_includes $aclocaldir ; do
462        test "x$d" != x-I || continue
463        if test -f "$d/libtool.m4"; then
464           libtool_found=yes
465        fi
466        if test -f "$d/gettext.m4"; then
467           gettext_found=yes
468        fi
469     done
470     case $required in
471       *libtool* ) test $libtool_found = yes || Exit 77 ;;
472       *gettext* ) test $gettext_found = yes || Exit 77 ;;
473     esac
474     # Libtool cannot cope with spaces in the build tree.  Our testsuite setup
475     # cannot cope with spaces in the source tree name for Libtool and gettext
476     # tests.
477     case $srcdir,`pwd` in
478       *\ * | *\ *) Exit 77 ;;
479     esac
480     ACLOCAL="$ACLOCAL -Wno-syntax -I $srcdir/../m4 $extra_includes -I $aclocaldir"
481     ;;
482 esac
483
484 testaclocaldir='@abs_top_srcdir@/m4'
485
486 # POSIX no longer requires 'egrep' and 'fgrep',
487 # but some hosts lack 'grep -E' and 'grep -F'.
488 EGREP='@EGREP@'
489 FGREP='@FGREP@'
490
491 # The amount we should wait after modifying files depends on the platform.
492 # For instance, Windows '95, '98 and ME have 2-second granularity
493 # and can be up to 3 seconds in the future w.r.t. the system clock.
494 sleep='sleep @MODIFICATION_DELAY@'
495
496 # The tests call `make -e' but we do not want $srcdir from the environment
497 # to override the definition from the Makefile.
498 testsrcdir=$srcdir
499 unset srcdir
500
501 # An old timestamp that can be given to a file, in "touch -t" format.
502 # The time stamp should be portable to all file systems of interest.
503 # Just for fun, choose the exact time of the announcement of the GNU project
504 # in UTC; see <http://www.gnu.org/gnu/initial-announcement.html>.
505 old_timestamp=198309271735.59
506
507 # is_newest FILE FILES
508 # --------------------
509 # Return false if any file in FILES is newer than FILE.
510 # Resolve ties in favor of FILE.
511 is_newest ()
512 {
513   is_newest_files=`find "$@" -newer "$1"`
514   test -z "$is_newest_files"
515 }
516
517 # using_gmake
518 # -----------
519 # Return success if $MAKE is GNU make, return failure otherwise.
520 using_gmake ()
521 {
522   # Use --version AND -v, because SGI Make doesn't fail on --version.
523   # Also grep for GNU because newer versions of FreeBSD make do
524   # not complain about `--version' (they seem to silently ignore it).
525   $MAKE --version -v | grep GNU
526 }
527
528 # AUTOMAKE_run status [options...]
529 # --------------------------------
530 # Run Automake with OPTIONS, and fail if automake
531 # does not exit with STATUS.
532 AUTOMAKE_run ()
533 {
534   expected_exitcode=$1
535   shift
536   exitcode=0
537   $AUTOMAKE ${1+"$@"} >stdout 2>stderr || exitcode=$?
538   cat stderr >&2
539   cat stdout
540   test $exitcode = $expected_exitcode || Exit 1
541 }
542
543 # AUTOMAKE_fails [options...]
544 # ---------------------------
545 # Run Automake with OPTIONS, and fail if automake
546 # does not exit with STATUS.
547 AUTOMAKE_fails ()
548 {
549   AUTOMAKE_run 1 ${1+"$@"}
550 }
551
552 commented_sed_unindent_prog='
553   /^$/b                    # Nothing to do for empty lines.
554   x                        # Get x<indent> into pattern space.
555   /^$/{                    # No prior x<indent>, go prepare it.
556     g                      # Copy this 1st non-blank line into pattern space.
557     s/^\(['"$tab"' ]*\).*/x\1/   # Prepare x<indent> in pattern space.
558   }                        # Now: x<indent> in pattern and <line> in hold.
559   G                        # Build x<indent>\n<line> in pattern space, and
560   h                        # duplicate it into hold space.
561   s/\n.*$//                # Restore x<indent> in pattern space, and
562   x                        # exchange with the above duplicate in hold space.
563   s/^x\(.*\)\n\1//         # Remove leading <indent> from <line>.
564   s/^x.*\n//               # Restore <line> when there is no leading <indent>.
565 '
566
567 # unindent [input files...]
568 # -------------------------
569 # Remove the "proper" amount of leading whitespace from the given files,
570 # and output the result on stdout.  That amount is determined by looking
571 # at the leading whitespace of the first non-blank line in the input
572 # files.  If no input file is specified, standard input is implied.
573 unindent ()
574 {
575   if test x"$sed_unindent_prog" = x; then
576     sed_unindent_prog=`printf '%s\n' "$commented_sed_unindent_prog" | sed -e "s/  *# .*//"`
577   fi
578   sed "$sed_unindent_prog" ${1+"$@"}
579 }
580 sed_unindent_prog="" # Avoid interferences from the environment.
581
582 # Turn on shell traces.
583 set -x
584
585 pwd