sanity.m4 2.6 KB

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