gnu: libvterm: Update to 0.3.0.
[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>
08d15a24 4dnl Copyright © 2017, 2020, 2021 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
03b45230 92 x86_64-linux|i686-linux|armhf-linux|aarch64-linux|powerpc64le-linux|riscv64-linux|i586-gnu)
08d15a24
EF
93 ;;
94 mips64el-linux|powerpc-linux)
95 AC_MSG_WARN([building Guix on `$guix_system', which is not supported])
b97556d7
LC
96 ;;
97 *)
98 if test "x$guix_courageous" = "xyes"; then
99 AC_MSG_WARN([building Guix on `$guix_system', which is not supported])
100 else
101 AC_MSG_ERROR([`$guix_system' is not a supported platform.
102See "GNU Distribution" in the manual, or try `--with-courage'.])
103 fi
104 ;;
105 esac
106])
107
9c7dd33a
LC
108dnl GUIX_ASSERT_GUILE_FEATURES FEATURES
109dnl
110dnl Assert that FEATURES are provided by $GUILE.
111AC_DEFUN([GUIX_ASSERT_GUILE_FEATURES], [
112 for guix_guile_feature in $1
113 do
114 AC_MSG_CHECKING([whether $GUILE provides feature '$guix_guile_feature'])
115 if "$GUILE" -c "(exit (provided? '$guix_guile_feature))"
116 then
117 AC_MSG_RESULT([yes])
118 else
119 AC_MSG_RESULT([no])
120 AC_MSG_ERROR([$GUILE does not support feature '$guix_guile_feature', which is required.])
121 fi
122 done
123])
1959fb04 124
21531add
LC
125dnl GUIX_CHECK_GUILE_SSH
126dnl
127dnl Check whether a recent-enough Guile-SSH is available.
128AC_DEFUN([GUIX_CHECK_GUILE_SSH], [
e8088f0b
LDB
129 dnl Check whether '#:nodelay' paramater to 'make-session' (introduced in
130 dnl 0.13.0) is present.
21531add
LC
131 AC_CACHE_CHECK([whether Guile-SSH is available and recent enough],
132 [guix_cv_have_recent_guile_ssh],
133 [GUILE_CHECK([retval],
134 [(and (@ (ssh channel) channel-send-eof)
135 (@ (ssh popen) open-remote-pipe)
37891872 136 (@ (ssh dist node) node-eval)
e8088f0b
LDB
137 (@ (ssh auth) userauth-gssapi!)
138 ((@ (ssh session) make-session) #:nodelay #t))])
21531add
LC
139 if test "$retval" = 0; then
140 guix_cv_have_recent_guile_ssh="yes"
141 else
142 guix_cv_have_recent_guile_ssh="no"
143 fi])
144])
145
d59e75f3
LC
146dnl GUIX_CHECK_GUILE_SQLITE3
147dnl
148dnl Check whether a recent-enough Guile-Sqlite3 is available.
149AC_DEFUN([GUIX_CHECK_GUILE_SQLITE3], [
150 dnl Check whether 'sqlite-bind-arguments' is available. It was introduced
151 dnl in February 2018:
60e1c109 152 dnl <https://notabug.org/guile-sqlite3/guile-sqlite3/commit/1cd1dec96a9999db48c0ff45bab907efc637247f>.
d59e75f3
LC
153 AC_CACHE_CHECK([whether Guile-Sqlite3 is available and recent enough],
154 [guix_cv_have_recent_guile_sqlite3],
155 [GUILE_CHECK([retval],
156 [(@ (sqlite3) sqlite-bind-arguments)])
157 if test "$retval" = 0; then
158 guix_cv_have_recent_guile_sqlite3="yes"
159 else
160 guix_cv_have_recent_guile_sqlite3="no"
161 fi])
162])
163
81c3dc32
LC
164dnl GUIX_CHECK_GUILE_JSON
165dnl
166dnl Check whether a recent-enough Guile-JSON is available.
167AC_DEFUN([GUIX_CHECK_GUILE_JSON], [
b5eb901a
LC
168 dnl Check whether we're using Guile-JSON 4.3+, which provides
169 dnl 'define-json-mapping'.
81c3dc32
LC
170 AC_CACHE_CHECK([whether Guile-JSON is available and recent enough],
171 [guix_cv_have_recent_guile_json],
172 [GUILE_CHECK([retval],
b5eb901a
LC
173 [(use-modules (json))
174
175 (define-json-mapping <frob> make-frob
176 frob?
177 json->frob
178 (a frob-a)
179 (b frob-b \"bee\"))
180
181 (exit
182 (equal? (json->frob
183 (open-input-string \"{ \\\"a\\\": 1, \\\"bee\\\": 2 }\"))
184 (make-frob 1 2)))])
81c3dc32
LC
185 if test "$retval" = 0; then
186 guix_cv_have_recent_guile_json="yes"
187 else
188 guix_cv_have_recent_guile_json="no"
189 fi])
190])
191
c1dc50ab
LC
192dnl GUIX_CHECK_GUILE_GCRYPT
193dnl
194dnl Check whether a recent-enough Guile-Gcrypt is available.
195AC_DEFUN([GUIX_CHECK_GUILE_GCRYPT], [
196 dnl Check whether we're using Guile-Gcrypt 0.2.x or later. 0.2.0
197 dnl introduced the 'hash-algorithm' macro and related code.
198 AC_CACHE_CHECK([whether Guile-Gcrypt is available and recent enough],
199 [guix_cv_have_recent_guile_gcrypt],
200 [GUILE_CHECK([retval],
201 [(use-modules (gcrypt hash))
202 (equal? (hash-algorithm sha256)
203 (lookup-hash-algorithm 'sha256))])
204 if test "$retval" = 0; then
205 guix_cv_have_recent_guile_gcrypt="yes"
206 else
207 guix_cv_have_recent_guile_gcrypt="no"
208 fi])
209])
81c3dc32 210
59bb1ae3
LC
211dnl GUIX_CHECK_GUILE_GIT
212dnl
213dnl Check whether a recent-enough Guile-Git is available.
214AC_DEFUN([GUIX_CHECK_GUILE_GIT], [
215 dnl Check whether we're using Guile-Git 0.3.0 or later. 0.3.0
216 dnl introduced SSH authentication support and more.
217 AC_CACHE_CHECK([whether Guile-Git is available and recent enough],
218 [guix_cv_have_recent_guile_git],
219 [GUILE_CHECK([retval],
220 [(use-modules (git) (git auth) (git submodule))
221 (let ((auth (%make-auth-ssh-agent)))
222 repository-close!
223 object-lookup-prefix
224 (make-clone-options
225 #:fetch-options (make-fetch-options auth)))])
226 if test "$retval" = 0; then
227 guix_cv_have_recent_guile_git="yes"
228 else
229 guix_cv_have_recent_guile_git="no"
230 fi])
231])
232
62a09136
LC
233dnl GUIX_CHECK_GUILE_ZLIB
234dnl
235dnl Check whether a recent-enough Guile-zlib is available.
236AC_DEFUN([GUIX_CHECK_GUILE_ZLIB], [
237 dnl Check whether we're using Guile-zlib 0.1.0 or later.
238 dnl 0.1.0 introduced the 'make-zlib-input-port' and related code.
239 AC_CACHE_CHECK([whether Guile-zlib is available and recent enough],
240 [guix_cv_have_recent_guile_zlib],
241 [GUILE_CHECK([retval],
242 [(use-modules (zlib))
243 make-zlib-input-port])
244 if test "$retval" = 0; then
245 guix_cv_have_recent_guile_zlib="yes"
246 else
247 guix_cv_have_recent_guile_zlib="no"
248 fi])
249])
250
2178ed66
LC
251dnl GUIX_TEST_ROOT_DIRECTORY
252AC_DEFUN([GUIX_TEST_ROOT_DIRECTORY], [
253 AC_CACHE_CHECK([for unit test root directory],
254 [ac_cv_guix_test_root],
255 [ac_cv_guix_test_root="`pwd`/test-tmp"])
256])
257
93ce8a8e
LC
258dnl 'BINPRM_BUF_SIZE' constant in Linux (we leave room for the trailing zero.)
259dnl The Hurd has a limit of about a page (see exec/hashexec.c.)
260m4_define([LINUX_HASH_BANG_LIMIT], 127)
2178ed66
LC
261
262dnl Hardcoded 'sun_path' length in <sys/un.h>.
263m4_define([SOCKET_FILE_NAME_LIMIT], 108)
264
265dnl GUIX_SOCKET_FILE_NAME_LENGTH
266AC_DEFUN([GUIX_SOCKET_FILE_NAME_LENGTH], [
267 AC_CACHE_CHECK([the length of the installed socket file name],
268 [ac_cv_guix_socket_file_name_length],
269 [ac_cv_guix_socket_file_name_length="`echo -n "$guix_localstatedir/guix/daemon-socket/socket" | wc -c`"])
270])
271
272dnl GUIX_TEST_SOCKET_FILE_NAME_LENGTH
273AC_DEFUN([GUIX_TEST_SOCKET_FILE_NAME_LENGTH], [
274 AC_REQUIRE([GUIX_TEST_ROOT_DIRECTORY])
275 AC_CACHE_CHECK([the length of the socket file name used in tests],
276 [ac_cv_guix_test_socket_file_name_length],
277 [ac_cv_guix_test_socket_file_name_length="`echo -n "$ac_cv_guix_test_root/var/123456/daemon-socket/socket" | wc -c`"])
278])
279
280dnl GUIX_HASH_BANG_LENGTH
281AC_DEFUN([GUIX_HASH_BANG_LENGTH], [
282 AC_CACHE_CHECK([the length of a typical hash bang line],
283 [ac_cv_guix_hash_bang_length],
284 [ac_cv_guix_hash_bang_length=`echo -n "$storedir/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa-bootstrap-binaries-0/bin/bash" | wc -c`])
285])
286
27ab3cee
LC
287dnl GUIX_TEST_HASH_BANG_LENGTH
288AC_DEFUN([GUIX_TEST_HASH_BANG_LENGTH], [
289 AC_REQUIRE([GUIX_TEST_ROOT_DIRECTORY])
290 AC_CACHE_CHECK([the length of a hash bang line used in tests],
291 [ac_cv_guix_test_hash_bang_length],
292 [ac_cv_guix_test_hash_bang_length=`echo -n "$ac_cv_guix_test_root/store/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa-bootstrap-binaries-0/bin/bash" | wc -c`])
293])
294
2178ed66
LC
295dnl GUIX_CHECK_FILE_NAME_LIMITS
296dnl
297dnl GNU/Linux has a couple of silly limits that we can easily run into.
bb251307
LC
298dnl Make sure everything is fine with the current settings. Set $1 to
299dnl 'yes' if tests can run, 'no' otherwise.
2178ed66
LC
300AC_DEFUN([GUIX_CHECK_FILE_NAME_LIMITS], [
301 AC_REQUIRE([GUIX_SOCKET_FILE_NAME_LENGTH])
302 AC_REQUIRE([GUIX_TEST_SOCKET_FILE_NAME_LENGTH])
303 AC_REQUIRE([GUIX_HASH_BANG_LENGTH])
27ab3cee 304 AC_REQUIRE([GUIX_TEST_HASH_BANG_LENGTH])
2178ed66
LC
305
306 if test "$ac_cv_guix_socket_file_name_length" -ge ]SOCKET_FILE_NAME_LIMIT[; then
307 AC_MSG_ERROR([socket file name would exceed the maxium allowed length])
308 fi
309 if test "$ac_cv_guix_test_socket_file_name_length" -ge ]SOCKET_FILE_NAME_LIMIT[; then
310 AC_MSG_WARN([socket file name limit may be exceeded when running tests])
311 fi
bb251307
LC
312
313 $1=yes
2178ed66 314 if test "$ac_cv_guix_hash_bang_length" -ge ]LINUX_HASH_BANG_LIMIT[; then
bb251307 315 $1=no
2178ed66
LC
316 AC_MSG_ERROR([store directory '$storedir' would lead to overly long hash-bang lines])
317 fi
27ab3cee 318 if test "$ac_cv_guix_test_hash_bang_length" -ge ]LINUX_HASH_BANG_LIMIT[; then
bb251307 319 $1=no
27ab3cee
LC
320 AC_MSG_WARN([test directory '$ac_cv_guix_test_root' may lead to overly long hash-bang lines])
321 fi
2178ed66 322])
368d08f7
LC
323
324dnl GUIX_CHECK_CXX11
325dnl
326dnl Check whether the C++ compiler can compile a typical C++11 program.
327AC_DEFUN([GUIX_CHECK_CXX11], [
328 AC_REQUIRE([AC_PROG_CXX])
329 AC_CACHE_CHECK([whether $CXX supports C++11],
330 [ac_cv_guix_cxx11_support],
331 [save_CXXFLAGS="$CXXFLAGS"
332 CXXFLAGS="-std=c++11 $CXXFLAGS"
333 AC_COMPILE_IFELSE([
334 AC_LANG_SOURCE([
335 #include <functional>
336
337 std::function<int(int)>
338 return_plus_lambda (int x)
339 {
340 auto result = [[&]](int y) {
341 return x + y;
342 };
343
344 return result;
345 }
346 ])],
347 [ac_cv_guix_cxx11_support=yes],
348 [ac_cv_guix_cxx11_support=no])
349 CXXFLAGS="$save_CXXFLAGS"
350 ])
351])
352
353dnl GUIX_ASSERT_CXX11
354dnl
355dnl Error out if the C++ compiler cannot compile C++11 code.
356AC_DEFUN([GUIX_ASSERT_CXX11], [
357 GUIX_CHECK_CXX11
358 if test "x$ac_cv_guix_cxx11_support" != "xyes"; then
359 AC_MSG_ERROR([C++ compiler '$CXX' does not support the C++11 standard])
360 fi
361])
12e5b266 362
dd01fecd
LC
363dnl GUIX_LIBGCRYPT_LIBDIR VAR
364dnl
365dnl Attempt to determine libgcrypt's LIBDIR; store the result in VAR.
366AC_DEFUN([GUIX_LIBGCRYPT_LIBDIR], [
367 AC_PATH_PROG([LIBGCRYPT_CONFIG], [libgcrypt-config])
368 AC_CACHE_CHECK([libgcrypt's library directory],
369 [guix_cv_libgcrypt_libdir],
370 [if test "x$LIBGCRYPT_CONFIG" != "x"; then
ca34fc31 371 guix_cv_libgcrypt_libdir=`$LIBGCRYPT_CONFIG --libs | grep -e -L | sed -e "s/.*-L\([[^ ]]\+\)[[[:blank:]]]\+-lgcrypt.*/\1/g"`
dd01fecd
LC
372 else
373 guix_cv_libgcrypt_libdir=""
374 fi])
375 $1="$guix_cv_libgcrypt_libdir"
376])
ef5f5c86
LC
377
378dnl GUIX_CURRENT_LOCALSTATEDIR
379dnl
380dnl Determine the localstatedir of an existing Guix installation and set
381dnl 'guix_cv_current_localstatedir' accordingly. Set it to "none" if no
382dnl existing installation was found.
383AC_DEFUN([GUIX_CURRENT_LOCALSTATEDIR], [
384 AC_PATH_PROG([GUILE], [guile])
385 AC_CACHE_CHECK([the current installation's localstatedir],
386 [guix_cv_current_localstatedir],
387 [dnl Call 'dirname' because (guix config) appends "/guix" to LOCALSTATEDIR.
388 guix_cv_current_localstatedir="`"$GUILE" \
389 -c '(use-modules (guix config))
390 (when (string=? %store-directory "'$storedir'")
391 (display (dirname %state-directory)))' \
392 2>/dev/null`"
393 if test "x$guix_cv_current_localstatedir" = "x"; then
394 guix_cv_current_localstatedir=none
395 fi])])
396
397dnl GUIX_CHECK_LOCALSTATEDIR
398dnl
399dnl Check that the LOCALSTATEDIR value is consistent with that of the existing
400dnl Guix installation, if any. Error out or warn if they do not match.
401AC_DEFUN([GUIX_CHECK_LOCALSTATEDIR], [
402 AC_REQUIRE([GUIX_CURRENT_LOCALSTATEDIR])
403 if test "x$guix_cv_current_localstatedir" != "xnone"; then
404 if test "$guix_cv_current_localstatedir" != "$guix_localstatedir"; then
405 case "$localstatedir" in
406 NONE|\${prefix}*)
407 # User kept the default value---i.e., did not pass '--localstatedir'.
408 AC_MSG_ERROR([chosen localstatedir '$guix_localstatedir' does not match \
409that of the existing installation '$guix_cv_current_localstatedir'
410Installing may corrupt $storedir!
411Use './configure --localstatedir=$guix_cv_current_localstatedir'.])
412 ;;
413 *)
414 # User passed an explicit '--localstatedir'. Assume they know what
415 # they're doing.
416 AC_MSG_WARN([chosen localstatedir '$guix_localstatedir' does not match \
417that of the existing installation '$guix_cv_current_localstatedir'])
418 AC_MSG_WARN([installing may corrupt $storedir!])
419 ;;
420 esac
421 fi
422 fi])
55daad12
LC
423
424dnl GUIX_CHANNEL_METADATA
425dnl
426dnl Provide the channel metadata for this build. This allows 'guix describe'
427dnl to return meaningful data, as it would for a 'guix pull'-provided 'guix'.
428dnl The default URL and introduction are taken from (guix channels).
429AC_DEFUN([GUIX_CHANNEL_METADATA], [
430 AC_ARG_WITH([channel-url], [AS_HELP_STRING([--with-channel-url=URL],
431 [assert that this is built from the Git repository at URL])],
432 [guix_channel_url="\"$withval\""],
433 [guix_channel_url="\"https://git.savannah.gnu.org/git/guix.git\""])
434 AC_ARG_WITH([channel-commit], [AS_HELP_STRING([--with-channel-commit=COMMIT],
435 [assert that this is built from COMMIT])],
436 [guix_channel_commit="\"$withval\""],
437 [guix_channel_commit="#f"])
438 AC_ARG_WITH([channel-introduction], [AS_HELP_STRING([--with-channel-introduction=COMMIT:FINGERPRINT],
439 [specify COMMIT and FINGERPRINT as the introduction of this channel])],
440 [guix_channel_introduction="'(\"`echo $withval | cut -f1 -d:`\" \"`echo $withval | cut -f2 -d:`\")"],
441 [guix_channel_introduction="'(\"9edb3f66fd807b096b48283debdcddccfea34bad\" . \"BBB0 2DDF 2CEA F6A8 0D1D E643 A2A0 6DF2 A33A 54FA\")"])
442
443 GUIX_CHANNEL_URL="$guix_channel_url"
444 GUIX_CHANNEL_COMMIT="$guix_channel_commit"
445 GUIX_CHANNEL_INTRODUCTION="$guix_channel_introduction"
446
447 AC_SUBST([GUIX_CHANNEL_URL])
448 AC_SUBST([GUIX_CHANNEL_COMMIT])
449 AC_SUBST([GUIX_CHANNEL_INTRODUCTION])
450])