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