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