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