Merge branch 'maint'
[platform/upstream/automake.git] / m4 / sanity.m4
1 # Check to make sure that the build environment is sane.    -*- Autoconf -*-
2
3 # Copyright (C) 1996, 1997, 2000, 2001, 2003, 2005, 2008, 2009, 2010,
4 # 2011 Free Software Foundation, Inc.
5 #
6 # This file is free software; the Free Software Foundation
7 # gives unlimited permission to copy and/or distribute it,
8 # with or without modifications, as long as this notice is preserved.
9
10 # serial 9
11
12 # AM_SANITY_CHECK
13 # ---------------
14 AC_DEFUN([AM_SANITY_CHECK],
15 [AC_MSG_CHECKING([whether build environment is sane])
16 # Reject unsafe characters in $srcdir or the absolute working directory
17 # name.  Accept space and tab only in the latter.
18 am_lf='
19 '
20 case `pwd` in
21   *[[\\\"\#\$\&\'\`$am_lf]]*)
22     AC_MSG_ERROR([unsafe absolute working directory name]);;
23 esac
24 case $srcdir in
25   *[[\\\"\#\$\&\'\`$am_lf\ \    ]]*)
26     AC_MSG_ERROR([unsafe srcdir value: `$srcdir']);;
27 esac
28
29 # Do `set' in a subshell so we don't clobber the current shell's
30 # arguments.  Must try -L first in case configure is actually a
31 # symlink; some systems play weird games with the mod time of symlinks
32 # (eg FreeBSD returns the mod time of the symlink's containing
33 # directory).
34 if (
35    am_has_slept=no
36    for am_try in 1 2; do
37      echo "timestamp, slept: $am_has_slept" > conftest.file
38      set X `ls -Lt "$srcdir/configure" conftest.file 2> /dev/null`
39      if test "$[*]" = "X"; then
40         # -L didn't work.
41         set X `ls -t "$srcdir/configure" conftest.file`
42      fi
43      if test "$[*]" != "X $srcdir/configure conftest.file" \
44         && test "$[*]" != "X conftest.file $srcdir/configure"; then
45
46         # If neither matched, then we have a broken ls.  This can happen
47         # if, for instance, CONFIG_SHELL is bash and it inherits a
48         # broken ls alias from the environment.  This has actually
49         # happened.  Such a system could not be considered "sane".
50         AC_MSG_ERROR([ls -t appears to fail.  Make sure there is not a broken
51   alias in your environment])
52      fi
53      if test "$[2]" = conftest.file || test $am_try -eq 2; then
54        break
55      fi
56      # Just in case.
57      sleep 1
58      am_has_slept=yes
59    done
60    test "$[2]" = conftest.file
61    )
62 then
63    # Ok.
64    :
65 else
66    AC_MSG_ERROR([newly created file is older than distributed files!
67 Check your system clock])
68 fi
69 AC_MSG_RESULT([yes])
70 # If we didn't sleep, we still need to ensure time stamps of config.status and
71 # generated files are strictly newer.
72 am_sleep_pid=
73 if grep 'slept: no' conftest.file >/dev/null 2>&1; then
74   ( sleep 1 ) &
75   am_sleep_pid=$!
76 fi
77 AC_CONFIG_COMMANDS_PRE(
78   [AC_MSG_CHECKING([that generated files are newer than configure])
79    if test -n "$am_sleep_pid"; then
80      # Hide warnings about reused PIDs.
81      wait $am_sleep_pid 2>/dev/null
82    fi
83    AC_MSG_RESULT([done])])
84 rm -f conftest.file
85 ])