doc: update Vala documentation
[automake.git] / m4 / sanity.m4
blob59afa7b152ac1d37be24c080e2e1bab45922e2a1
1 # Check to make sure that the build environment is sane.    -*- Autoconf -*-
3 # Copyright (C) 1996-2024 Free Software Foundation, Inc.
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.
9 # _AM_SLEEP_FRACTIONAL_SECONDS
10 # ----------------------------
11 AC_DEFUN([_AM_SLEEP_FRACTIONAL_SECONDS], [dnl
12 AC_CACHE_CHECK([whether sleep supports fractional seconds],
13                am_cv_sleep_fractional_seconds, [dnl
14 AS_IF([sleep 0.001 2>/dev/null], [am_cv_sleep_fractional_seconds=true],
15                                  [am_cv_sleep_fractional_seconds=false])
16 ])])
18 # _AM_FILESYSTEM_TIMESTAMP_RESOLUTION
19 # -----------------------------------
20 # Determine the filesystem's resolution for file modification
21 # timestamps.  The coarsest we know of is FAT, with a resolution
22 # of only two seconds, even with the most recent "exFAT" extensions.
23 # The finest (e.g. ext4 with large inodes, XFS, ZFS) is one
24 # nanosecond, matching clock_gettime.  However, it is probably not
25 # possible to delay execution of a shell script for less than one
26 # millisecond, due to process creation overhead and scheduling
27 # granularity, so we don't check for anything finer than that.
28 AC_DEFUN([_AM_FILESYSTEM_TIMESTAMP_RESOLUTION], [dnl
29 AC_REQUIRE([_AM_SLEEP_FRACTIONAL_SECONDS])
30 AC_CACHE_CHECK([filesystem timestamp resolution], am_cv_filesystem_timestamp_resolution, [dnl
31 # Default to the worst case.
32 am_cv_filesystem_timestamp_resolution=2
34 # Only try to go finer than 1s if sleep can do it.
35 am_try_resolutions=1
36 if $am_cv_sleep_fractional_seconds; then
37   am_try_resolutions="0.01 0.1 $am_try_resolutions"
40 # In order to catch current-generation FAT out, we must *modify* files
41 # that already exist; the *creation* timestamp is finer.  Use names
42 # that make ls -t sort them differently when they have equal
43 # timestamps than when they have distinct timestamps, keeping
44 # in mind that ls -t prints the *newest* file first.
45 rm -f conftest.ts?
46 : > conftest.ts1
47 : > conftest.ts2
48 : > conftest.ts3
50 # Make sure ls -t actually works.  Do 'set' in a subshell so we don't
51 # clobber the current shell's arguments.
52 if (
53      set X `[ls -t conftest.ts[12]]` &&
54      {
55        test "$[*]" != "X conftest.ts1 conftest.ts2" ||
56        test "$[*]" != "X conftest.ts2 conftest.ts1";
57      }
58 ); then :; else
59   # If neither matched, then we have a broken ls.  This can happen
60   # if, for instance, CONFIG_SHELL is bash and it inherits a
61   # broken ls alias from the environment.  This has actually
62   # happened.  Such a system could not be considered "sane".
63   _AS_ECHO_UNQUOTED(
64     ["Bad output from ls -t: \"`[ls -t conftest.ts[12]]`\""],
65     [AS_MESSAGE_LOG_FD])
66   AC_MSG_FAILURE([ls -t produces unexpected output.
67 Make sure there is not a broken alias in your environment.])
70 for am_try_res in $am_try_resolutions; do
71   # Any one fine-grained sleep might happen to cross the boundary
72   # between two values of a coarser actual resolution, but if we do
73   # two fine-grained sleeps in a row, at least one of them will fall
74   # entirely within a coarse interval.
75   echo alpha > conftest.ts1
76   sleep $am_try_res
77   echo beta > conftest.ts2
78   sleep $am_try_res
79   echo gamma > conftest.ts3
81   # We assume that 'ls -t' will make use of high-resolution
82   # timestamps if the operating system supports them at all.
83   if (set X `ls -t conftest.ts?` &&
84       test "$[]2" = conftest.ts3 &&
85       test "$[]3" = conftest.ts2 &&
86       test "$[]4" = conftest.ts1); then
87     am_cv_filesystem_timestamp_resolution=$am_try_res
88     break
89   fi
90 done
91 rm -f conftest.ts?
92 ])])
94 # AM_SANITY_CHECK
95 # ---------------
96 AC_DEFUN([AM_SANITY_CHECK],
97 [AC_REQUIRE([_AM_FILESYSTEM_TIMESTAMP_RESOLUTION])
98 # This check should not be cached, as it may vary across builds of
99 # different projects.
100 AC_MSG_CHECKING([whether build environment is sane])
101 # Reject unsafe characters in $srcdir or the absolute working directory
102 # name.  Accept space and tab only in the latter.
103 am_lf='
105 case `pwd` in
106   *[[\\\"\#\$\&\'\`$am_lf]]*)
107     AC_MSG_ERROR([unsafe absolute working directory name]);;
108 esac
109 case $srcdir in
110   *[[\\\"\#\$\&\'\`$am_lf\ \    ]]*)
111     AC_MSG_ERROR([unsafe srcdir value: '$srcdir']);;
112 esac
114 # Do 'set' in a subshell so we don't clobber the current shell's
115 # arguments.  Must try -L first in case configure is actually a
116 # symlink; some systems play weird games with the mod time of symlinks
117 # (eg FreeBSD returns the mod time of the symlink's containing
118 # directory).
119 am_build_env_is_sane=no
120 am_has_slept=no
121 rm -f conftest.file
122 for am_try in 1 2; do
123   echo "timestamp, slept: $am_has_slept" > conftest.file
124   if (
125     set X `ls -Lt "$srcdir/configure" conftest.file 2> /dev/null`
126     if test "$[*]" = "X"; then
127       # -L didn't work.
128       set X `ls -t "$srcdir/configure" conftest.file`
129     fi
130     test "$[2]" = conftest.file
131   ); then
132     am_build_env_is_sane=yes
133     break
134   fi
135   # Just in case.
136   sleep $am_cv_filesystem_timestamp_resolution
137   am_has_slept=yes
138 done
140 AC_MSG_RESULT([$am_build_env_is_sane])
141 if test $am_build_env_is_sane = no; then
142   AC_MSG_ERROR([newly created file is older than distributed files!
143 Check your system clock])
146 # If we didn't sleep, we still need to ensure time stamps of config.status and
147 # generated files are strictly newer.
148 am_sleep_pid=
149 AS_IF([test -e conftest.file || grep 'slept: no' conftest.file >/dev/null 2>&1],, [dnl
150   ( sleep $am_cv_filesystem_timestamp_resolution ) &
151   am_sleep_pid=$!
153 AC_CONFIG_COMMANDS_PRE(
154   [AC_MSG_CHECKING([that generated files are newer than configure])
155    if test -n "$am_sleep_pid"; then
156      # Hide warnings about reused PIDs.
157      wait $am_sleep_pid 2>/dev/null
158    fi
159    AC_MSG_RESULT([done])])
160 rm -f conftest.file