gnu: coreutils: Mark pwd-long tests XFAIL on the Hurd.
[jackhill/guix/guix.git] / m4 / guix.m4
CommitLineData
2357f850 1dnl GNU Guix --- Functional package management for GNU
c1dc50ab 2dnl Copyright © 2012, 2013, 2014, 2015, 2016, 2018, 2019, 2020 Ludovic Courtès <ludo@gnu.org>
aa1e1947 3dnl Copyright © 2014 Mark H Weaver <mhw@netris.org>
3b88f376 4dnl Copyright © 2017 Efraim Flashner <efraim@flashner.co.il>
d388c2c4 5dnl
2357f850 6dnl This file is part of GNU Guix.
d388c2c4 7dnl
2357f850 8dnl GNU Guix is free software; you can redistribute it and/or modify it
d388c2c4
LC
9dnl under the terms of the GNU General Public License as published by
10dnl the Free Software Foundation; either version 3 of the License, or (at
11dnl your option) any later version.
12dnl
2357f850 13dnl GNU Guix is distributed in the hope that it will be useful, but
d388c2c4
LC
14dnl WITHOUT ANY WARRANTY; without even the implied warranty of
15dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16dnl GNU General Public License for more details.
17dnl
18dnl You should have received a copy of the GNU General Public License
2357f850 19dnl along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
d388c2c4 20
c2033df4
LC
21dnl GUIX_SYSTEM_TYPE
22dnl
23dnl Determine the Guix host system type, and store it in the
24dnl `guix_system' variable.
25AC_DEFUN([GUIX_SYSTEM_TYPE], [
26 AC_REQUIRE([AC_CANONICAL_HOST])
eb25a30a
LC
27 AC_PATH_PROG([SED], [sed])
28
c2033df4
LC
29 AC_ARG_WITH(system, AC_HELP_STRING([--with-system=SYSTEM],
30 [Platform identifier (e.g., `i686-linux').]),
31 [guix_system="$withval"],
32 [case "$host_cpu" in
33 i*86)
34 machine_name="i686";;
35 amd64)
968ae903 36 machine_name="x86_64";;
dfdb15d9 37 arm|armv[[7-9]]*)
968ae903
LC
38 # Here we want to exclude CPUs such as "armv6l". On ARMv7
39 # machines, we normally get "armv7l". However, in Guix, we
40 # configure with --build=arm-unknown-linux-gnueabihf, leading
41 # to just "arm", so we also have to allow it.
42 #
aa1e1947
MW
43 # TODO: If not cross-compiling, add a sanity check to make
44 # sure this build machine has the needed features to
45 # support executables compiled using our armhf gcc,
46 # configured with:
47 # --with-arch=armv7-a
48 # --with-float=hard
49 # --with-mode=thumb
50 # --with-fpu=vfpv3-d16
51 machine_name="armhf";;
c2033df4
LC
52 *)
53 machine_name="$host_cpu";;
54 esac
55
56 case "$host_os" in
57 linux-gnu*)
58 # For backward compatibility, strip the `-gnu' part.
59 guix_system="$machine_name-linux";;
4ed40a3e
MR
60 gnu*)
61 # Always use i586 for GNU/Hurd.
62 guix_system="i586-gnu";;
c2033df4
LC
63 *)
64 # Strip the version number from names such as `gnu0.3',
65 # `darwin10.2.0', etc.
eb25a30a 66 guix_system="$machine_name-`echo $host_os | "$SED" -e's/[0-9.]*$//g'`";;
c2033df4 67 esac])
5fedc65b
LC
68
69 AC_MSG_CHECKING([for the Guix system type])
70 AC_MSG_RESULT([$guix_system])
71
d8eea3d2 72 AC_SUBST([guix_system])
c2033df4 73])
9c7dd33a 74
b97556d7
LC
75dnl GUIX_ASSERT_SUPPORTED_SYSTEM
76dnl
77dnl Assert that this is a system to which the distro is ported.
78AC_DEFUN([GUIX_ASSERT_SUPPORTED_SYSTEM], [
79 AC_REQUIRE([GUIX_SYSTEM_TYPE])
80
81 AC_ARG_WITH([courage], [AC_HELP_STRING([--with-courage],
82 [Assert that even if this platform is unsupported, you will be
83courageous and port the GNU System distribution to it (see
84"GNU Distribution" in the manual.)])],
85 [guix_courageous="$withval"],
86 [guix_courageous="no"])
87
88 # Currently only Linux-based systems are supported, and only on some
89 # platforms.
90 case "$guix_system" in
03e64049 91 x86_64-linux|i686-linux|armhf-linux|aarch64-linux)
b97556d7
LC
92 ;;
93 *)
94 if test "x$guix_courageous" = "xyes"; then
95 AC_MSG_WARN([building Guix on `$guix_system', which is not supported])
96 else
97 AC_MSG_ERROR([`$guix_system' is not a supported platform.
98See "GNU Distribution" in the manual, or try `--with-courage'.])
99 fi
100 ;;
101 esac
102])
103
9c7dd33a
LC
104dnl GUIX_ASSERT_GUILE_FEATURES FEATURES
105dnl
106dnl Assert that FEATURES are provided by $GUILE.
107AC_DEFUN([GUIX_ASSERT_GUILE_FEATURES], [
108 for guix_guile_feature in $1
109 do
110 AC_MSG_CHECKING([whether $GUILE provides feature '$guix_guile_feature'])
111 if "$GUILE" -c "(exit (provided? '$guix_guile_feature))"
112 then
113 AC_MSG_RESULT([yes])
114 else
115 AC_MSG_RESULT([no])
116 AC_MSG_ERROR([$GUILE does not support feature '$guix_guile_feature', which is required.])
117 fi
118 done
119])
1959fb04 120
14218251
LC
121dnl GUIX_ASSERT_SYNTAX_OBJECT_EQUAL
122dnl
123dnl Guile 2.2.1 was a brown-paper-bag release where 'equal?' wouldn't work
124dnl for syntax objects, which broke gexps. Unfortunately Fedora 25 provides it.
125dnl Reject it.
126AC_DEFUN([GUIX_ASSERT_SYNTAX_OBJECT_EQUAL], [
127 AC_CACHE_CHECK([whether 'equal?' works for syntax objects],
128 [ac_cv_guix_syntax_object_equal],
129 [if "$GUILE" -c '(exit (equal? (syntax x) (syntax x)))'
130 then
131 ac_cv_guix_syntax_object_equal=yes
132 else
133 ac_cv_guix_syntax_object_equal=no
134 fi])
135 if test "x$ac_cv_guix_syntax_object_equal" != xyes; then
136 # This bug was present in Guile 2.2.1 only.
137 AC_MSG_ERROR(['equal?' does not work for syntax object; upgrade to Guile 2.2.2 or later.])
138 fi
139])
140
21531add
LC
141dnl GUIX_CHECK_GUILE_SSH
142dnl
143dnl Check whether a recent-enough Guile-SSH is available.
144AC_DEFUN([GUIX_CHECK_GUILE_SSH], [
37891872 145 dnl Check whether 'userauth-gssapi!' (introduced in 0.12.0) is present.
21531add
LC
146 AC_CACHE_CHECK([whether Guile-SSH is available and recent enough],
147 [guix_cv_have_recent_guile_ssh],
148 [GUILE_CHECK([retval],
149 [(and (@ (ssh channel) channel-send-eof)
150 (@ (ssh popen) open-remote-pipe)
37891872
LDB
151 (@ (ssh dist node) node-eval)
152 (@ (ssh auth) userauth-gssapi!))])
21531add
LC
153 if test "$retval" = 0; then
154 guix_cv_have_recent_guile_ssh="yes"
155 else
156 guix_cv_have_recent_guile_ssh="no"
157 fi])
158])
159
d59e75f3
LC
160dnl GUIX_CHECK_GUILE_SQLITE3
161dnl
162dnl Check whether a recent-enough Guile-Sqlite3 is available.
163AC_DEFUN([GUIX_CHECK_GUILE_SQLITE3], [
164 dnl Check whether 'sqlite-bind-arguments' is available. It was introduced
165 dnl in February 2018:
60e1c109 166 dnl <https://notabug.org/guile-sqlite3/guile-sqlite3/commit/1cd1dec96a9999db48c0ff45bab907efc637247f>.
d59e75f3
LC
167 AC_CACHE_CHECK([whether Guile-Sqlite3 is available and recent enough],
168 [guix_cv_have_recent_guile_sqlite3],
169 [GUILE_CHECK([retval],
170 [(@ (sqlite3) sqlite-bind-arguments)])
171 if test "$retval" = 0; then
172 guix_cv_have_recent_guile_sqlite3="yes"
173 else
174 guix_cv_have_recent_guile_sqlite3="no"
175 fi])
176])
177
81c3dc32
LC
178dnl GUIX_CHECK_GUILE_JSON
179dnl
180dnl Check whether a recent-enough Guile-JSON is available.
181AC_DEFUN([GUIX_CHECK_GUILE_JSON], [
182 dnl Check whether we're using Guile-JSON 3.x, which uses a JSON-to-Scheme
183 dnl mapping different from that of earlier versions.
184 AC_CACHE_CHECK([whether Guile-JSON is available and recent enough],
185 [guix_cv_have_recent_guile_json],
186 [GUILE_CHECK([retval],
187 [(use-modules (json) (ice-9 match))
611a64bd
LC
188 (match (json-string->scm \"[[ { \\\"a\\\": 42 } ]]\")
189 (#((("a" . 42))) #t))])
81c3dc32
LC
190 if test "$retval" = 0; then
191 guix_cv_have_recent_guile_json="yes"
192 else
193 guix_cv_have_recent_guile_json="no"
194 fi])
195])
196
c1dc50ab
LC
197dnl GUIX_CHECK_GUILE_GCRYPT
198dnl
199dnl Check whether a recent-enough Guile-Gcrypt is available.
200AC_DEFUN([GUIX_CHECK_GUILE_GCRYPT], [
201 dnl Check whether we're using Guile-Gcrypt 0.2.x or later. 0.2.0
202 dnl introduced the 'hash-algorithm' macro and related code.
203 AC_CACHE_CHECK([whether Guile-Gcrypt is available and recent enough],
204 [guix_cv_have_recent_guile_gcrypt],
205 [GUILE_CHECK([retval],
206 [(use-modules (gcrypt hash))
207 (equal? (hash-algorithm sha256)
208 (lookup-hash-algorithm 'sha256))])
209 if test "$retval" = 0; then
210 guix_cv_have_recent_guile_gcrypt="yes"
211 else
212 guix_cv_have_recent_guile_gcrypt="no"
213 fi])
214])
81c3dc32 215
2178ed66
LC
216dnl GUIX_TEST_ROOT_DIRECTORY
217AC_DEFUN([GUIX_TEST_ROOT_DIRECTORY], [
218 AC_CACHE_CHECK([for unit test root directory],
219 [ac_cv_guix_test_root],
220 [ac_cv_guix_test_root="`pwd`/test-tmp"])
221])
222
93ce8a8e
LC
223dnl 'BINPRM_BUF_SIZE' constant in Linux (we leave room for the trailing zero.)
224dnl The Hurd has a limit of about a page (see exec/hashexec.c.)
225m4_define([LINUX_HASH_BANG_LIMIT], 127)
2178ed66
LC
226
227dnl Hardcoded 'sun_path' length in <sys/un.h>.
228m4_define([SOCKET_FILE_NAME_LIMIT], 108)
229
230dnl GUIX_SOCKET_FILE_NAME_LENGTH
231AC_DEFUN([GUIX_SOCKET_FILE_NAME_LENGTH], [
232 AC_CACHE_CHECK([the length of the installed socket file name],
233 [ac_cv_guix_socket_file_name_length],
234 [ac_cv_guix_socket_file_name_length="`echo -n "$guix_localstatedir/guix/daemon-socket/socket" | wc -c`"])
235])
236
237dnl GUIX_TEST_SOCKET_FILE_NAME_LENGTH
238AC_DEFUN([GUIX_TEST_SOCKET_FILE_NAME_LENGTH], [
239 AC_REQUIRE([GUIX_TEST_ROOT_DIRECTORY])
240 AC_CACHE_CHECK([the length of the socket file name used in tests],
241 [ac_cv_guix_test_socket_file_name_length],
242 [ac_cv_guix_test_socket_file_name_length="`echo -n "$ac_cv_guix_test_root/var/123456/daemon-socket/socket" | wc -c`"])
243])
244
245dnl GUIX_HASH_BANG_LENGTH
246AC_DEFUN([GUIX_HASH_BANG_LENGTH], [
247 AC_CACHE_CHECK([the length of a typical hash bang line],
248 [ac_cv_guix_hash_bang_length],
249 [ac_cv_guix_hash_bang_length=`echo -n "$storedir/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa-bootstrap-binaries-0/bin/bash" | wc -c`])
250])
251
27ab3cee
LC
252dnl GUIX_TEST_HASH_BANG_LENGTH
253AC_DEFUN([GUIX_TEST_HASH_BANG_LENGTH], [
254 AC_REQUIRE([GUIX_TEST_ROOT_DIRECTORY])
255 AC_CACHE_CHECK([the length of a hash bang line used in tests],
256 [ac_cv_guix_test_hash_bang_length],
257 [ac_cv_guix_test_hash_bang_length=`echo -n "$ac_cv_guix_test_root/store/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa-bootstrap-binaries-0/bin/bash" | wc -c`])
258])
259
2178ed66
LC
260dnl GUIX_CHECK_FILE_NAME_LIMITS
261dnl
262dnl GNU/Linux has a couple of silly limits that we can easily run into.
bb251307
LC
263dnl Make sure everything is fine with the current settings. Set $1 to
264dnl 'yes' if tests can run, 'no' otherwise.
2178ed66
LC
265AC_DEFUN([GUIX_CHECK_FILE_NAME_LIMITS], [
266 AC_REQUIRE([GUIX_SOCKET_FILE_NAME_LENGTH])
267 AC_REQUIRE([GUIX_TEST_SOCKET_FILE_NAME_LENGTH])
268 AC_REQUIRE([GUIX_HASH_BANG_LENGTH])
27ab3cee 269 AC_REQUIRE([GUIX_TEST_HASH_BANG_LENGTH])
2178ed66
LC
270
271 if test "$ac_cv_guix_socket_file_name_length" -ge ]SOCKET_FILE_NAME_LIMIT[; then
272 AC_MSG_ERROR([socket file name would exceed the maxium allowed length])
273 fi
274 if test "$ac_cv_guix_test_socket_file_name_length" -ge ]SOCKET_FILE_NAME_LIMIT[; then
275 AC_MSG_WARN([socket file name limit may be exceeded when running tests])
276 fi
bb251307
LC
277
278 $1=yes
2178ed66 279 if test "$ac_cv_guix_hash_bang_length" -ge ]LINUX_HASH_BANG_LIMIT[; then
bb251307 280 $1=no
2178ed66
LC
281 AC_MSG_ERROR([store directory '$storedir' would lead to overly long hash-bang lines])
282 fi
27ab3cee 283 if test "$ac_cv_guix_test_hash_bang_length" -ge ]LINUX_HASH_BANG_LIMIT[; then
bb251307 284 $1=no
27ab3cee
LC
285 AC_MSG_WARN([test directory '$ac_cv_guix_test_root' may lead to overly long hash-bang lines])
286 fi
2178ed66 287])
368d08f7
LC
288
289dnl GUIX_CHECK_CXX11
290dnl
291dnl Check whether the C++ compiler can compile a typical C++11 program.
292AC_DEFUN([GUIX_CHECK_CXX11], [
293 AC_REQUIRE([AC_PROG_CXX])
294 AC_CACHE_CHECK([whether $CXX supports C++11],
295 [ac_cv_guix_cxx11_support],
296 [save_CXXFLAGS="$CXXFLAGS"
297 CXXFLAGS="-std=c++11 $CXXFLAGS"
298 AC_COMPILE_IFELSE([
299 AC_LANG_SOURCE([
300 #include <functional>
301
302 std::function<int(int)>
303 return_plus_lambda (int x)
304 {
305 auto result = [[&]](int y) {
306 return x + y;
307 };
308
309 return result;
310 }
311 ])],
312 [ac_cv_guix_cxx11_support=yes],
313 [ac_cv_guix_cxx11_support=no])
314 CXXFLAGS="$save_CXXFLAGS"
315 ])
316])
317
318dnl GUIX_ASSERT_CXX11
319dnl
320dnl Error out if the C++ compiler cannot compile C++11 code.
321AC_DEFUN([GUIX_ASSERT_CXX11], [
322 GUIX_CHECK_CXX11
323 if test "x$ac_cv_guix_cxx11_support" != "xyes"; then
324 AC_MSG_ERROR([C++ compiler '$CXX' does not support the C++11 standard])
325 fi
326])
12e5b266 327
dd01fecd
LC
328dnl GUIX_LIBGCRYPT_LIBDIR VAR
329dnl
330dnl Attempt to determine libgcrypt's LIBDIR; store the result in VAR.
331AC_DEFUN([GUIX_LIBGCRYPT_LIBDIR], [
332 AC_PATH_PROG([LIBGCRYPT_CONFIG], [libgcrypt-config])
333 AC_CACHE_CHECK([libgcrypt's library directory],
334 [guix_cv_libgcrypt_libdir],
335 [if test "x$LIBGCRYPT_CONFIG" != "x"; then
ca34fc31 336 guix_cv_libgcrypt_libdir=`$LIBGCRYPT_CONFIG --libs | grep -e -L | sed -e "s/.*-L\([[^ ]]\+\)[[[:blank:]]]\+-lgcrypt.*/\1/g"`
dd01fecd
LC
337 else
338 guix_cv_libgcrypt_libdir=""
339 fi])
340 $1="$guix_cv_libgcrypt_libdir"
341])
ef5f5c86 342
72153902
LC
343dnl GUIX_LIBZ_LIBDIR VAR
344dnl
345dnl Attempt to determine libz's LIBDIR; store the result in VAR.
346AC_DEFUN([GUIX_LIBZ_LIBDIR], [
347 AC_REQUIRE([PKG_PROG_PKG_CONFIG])
348 AC_CACHE_CHECK([zlib's library directory],
349 [guix_cv_libz_libdir],
350 [guix_cv_libz_libdir="`$PKG_CONFIG zlib --variable=libdir 2> /dev/null`"])
351 $1="$guix_cv_libz_libdir"
352])
353
fea338c6
PN
354dnl GUIX_LIBLZ_FILE_NAME VAR
355dnl
356dnl Attempt to determine liblz's absolute file name; store the result in VAR.
357AC_DEFUN([GUIX_LIBLZ_FILE_NAME], [
358 AC_REQUIRE([PKG_PROG_PKG_CONFIG])
359 AC_CACHE_CHECK([lzlib's file name],
360 [guix_cv_liblz_libdir],
361 [old_LIBS="$LIBS"
362 LIBS="-llz"
363 AC_LINK_IFELSE([AC_LANG_SOURCE([int main () { return LZ_decompress_open(); }])],
364 [guix_cv_liblz_libdir="`ldd conftest$EXEEXT | grep liblz | sed '-es/.*=> \(.*\) .*$/\1/g'`"])
365 LIBS="$old_LIBS"])
366 $1="$guix_cv_liblz_libdir"
367])
368
ef5f5c86
LC
369dnl GUIX_CURRENT_LOCALSTATEDIR
370dnl
371dnl Determine the localstatedir of an existing Guix installation and set
372dnl 'guix_cv_current_localstatedir' accordingly. Set it to "none" if no
373dnl existing installation was found.
374AC_DEFUN([GUIX_CURRENT_LOCALSTATEDIR], [
375 AC_PATH_PROG([GUILE], [guile])
376 AC_CACHE_CHECK([the current installation's localstatedir],
377 [guix_cv_current_localstatedir],
378 [dnl Call 'dirname' because (guix config) appends "/guix" to LOCALSTATEDIR.
379 guix_cv_current_localstatedir="`"$GUILE" \
380 -c '(use-modules (guix config))
381 (when (string=? %store-directory "'$storedir'")
382 (display (dirname %state-directory)))' \
383 2>/dev/null`"
384 if test "x$guix_cv_current_localstatedir" = "x"; then
385 guix_cv_current_localstatedir=none
386 fi])])
387
388dnl GUIX_CHECK_LOCALSTATEDIR
389dnl
390dnl Check that the LOCALSTATEDIR value is consistent with that of the existing
391dnl Guix installation, if any. Error out or warn if they do not match.
392AC_DEFUN([GUIX_CHECK_LOCALSTATEDIR], [
393 AC_REQUIRE([GUIX_CURRENT_LOCALSTATEDIR])
394 if test "x$guix_cv_current_localstatedir" != "xnone"; then
395 if test "$guix_cv_current_localstatedir" != "$guix_localstatedir"; then
396 case "$localstatedir" in
397 NONE|\${prefix}*)
398 # User kept the default value---i.e., did not pass '--localstatedir'.
399 AC_MSG_ERROR([chosen localstatedir '$guix_localstatedir' does not match \
400that of the existing installation '$guix_cv_current_localstatedir'
401Installing may corrupt $storedir!
402Use './configure --localstatedir=$guix_cv_current_localstatedir'.])
403 ;;
404 *)
405 # User passed an explicit '--localstatedir'. Assume they know what
406 # they're doing.
407 AC_MSG_WARN([chosen localstatedir '$guix_localstatedir' does not match \
408that of the existing installation '$guix_cv_current_localstatedir'])
409 AC_MSG_WARN([installing may corrupt $storedir!])
410 ;;
411 esac
412 fi
413 fi])