gnu: Add emacs-company-quickhelp.
[jackhill/guix/guix.git] / m4 / guix.m4
CommitLineData
2357f850 1dnl GNU Guix --- Functional package management for GNU
27ab3cee 2dnl Copyright © 2012, 2013, 2014, 2015, 2016 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
LC
20
21dnl GUIX_ASSERT_LIBGCRYPT_USABLE
22dnl
23dnl Assert that GNU libgcrypt is usable from Guile.
24AC_DEFUN([GUIX_ASSERT_LIBGCRYPT_USABLE],
25 [AC_CACHE_CHECK([whether $LIBGCRYPT can be dynamically loaded],
26 [guix_cv_libgcrypt_usable_p],
27 [GUILE_CHECK([retval],
28 [(dynamic-func \"gcry_md_hash_buffer\" (dynamic-link \"$LIBGCRYPT\"))])
29 if test "$retval" = 0; then
30 guix_cv_libgcrypt_usable_p="yes"
31 else
32 guix_cv_libgcrypt_usable_p="no"
33 fi])
34
35 if test "x$guix_cv_libgcrypt_usable_p" != "xyes"; then
36 AC_MSG_ERROR([GNU libgcrypt does not appear to be usable; see `--with-libgcrypt-prefix' and `README'.])
37 fi])
c2033df4
LC
38
39dnl GUIX_SYSTEM_TYPE
40dnl
41dnl Determine the Guix host system type, and store it in the
42dnl `guix_system' variable.
43AC_DEFUN([GUIX_SYSTEM_TYPE], [
44 AC_REQUIRE([AC_CANONICAL_HOST])
eb25a30a
LC
45 AC_PATH_PROG([SED], [sed])
46
c2033df4
LC
47 AC_ARG_WITH(system, AC_HELP_STRING([--with-system=SYSTEM],
48 [Platform identifier (e.g., `i686-linux').]),
49 [guix_system="$withval"],
50 [case "$host_cpu" in
51 i*86)
52 machine_name="i686";;
53 amd64)
968ae903 54 machine_name="x86_64";;
dfdb15d9 55 arm|armv[[7-9]]*)
968ae903
LC
56 # Here we want to exclude CPUs such as "armv6l". On ARMv7
57 # machines, we normally get "armv7l". However, in Guix, we
58 # configure with --build=arm-unknown-linux-gnueabihf, leading
59 # to just "arm", so we also have to allow it.
60 #
aa1e1947
MW
61 # TODO: If not cross-compiling, add a sanity check to make
62 # sure this build machine has the needed features to
63 # support executables compiled using our armhf gcc,
64 # configured with:
65 # --with-arch=armv7-a
66 # --with-float=hard
67 # --with-mode=thumb
68 # --with-fpu=vfpv3-d16
69 machine_name="armhf";;
c2033df4
LC
70 *)
71 machine_name="$host_cpu";;
72 esac
73
74 case "$host_os" in
75 linux-gnu*)
76 # For backward compatibility, strip the `-gnu' part.
77 guix_system="$machine_name-linux";;
4ed40a3e
MR
78 gnu*)
79 # Always use i586 for GNU/Hurd.
80 guix_system="i586-gnu";;
c2033df4
LC
81 *)
82 # Strip the version number from names such as `gnu0.3',
83 # `darwin10.2.0', etc.
eb25a30a 84 guix_system="$machine_name-`echo $host_os | "$SED" -e's/[0-9.]*$//g'`";;
c2033df4 85 esac])
5fedc65b
LC
86
87 AC_MSG_CHECKING([for the Guix system type])
88 AC_MSG_RESULT([$guix_system])
89
d8eea3d2 90 AC_SUBST([guix_system])
c2033df4 91])
9c7dd33a 92
b97556d7
LC
93dnl GUIX_ASSERT_SUPPORTED_SYSTEM
94dnl
95dnl Assert that this is a system to which the distro is ported.
96AC_DEFUN([GUIX_ASSERT_SUPPORTED_SYSTEM], [
97 AC_REQUIRE([GUIX_SYSTEM_TYPE])
98
99 AC_ARG_WITH([courage], [AC_HELP_STRING([--with-courage],
100 [Assert that even if this platform is unsupported, you will be
101courageous and port the GNU System distribution to it (see
102"GNU Distribution" in the manual.)])],
103 [guix_courageous="$withval"],
104 [guix_courageous="no"])
105
106 # Currently only Linux-based systems are supported, and only on some
107 # platforms.
108 case "$guix_system" in
3b88f376 109 x86_64-linux|i686-linux|armhf-linux|aarch64-linux|mips64el-linux)
b97556d7
LC
110 ;;
111 *)
112 if test "x$guix_courageous" = "xyes"; then
113 AC_MSG_WARN([building Guix on `$guix_system', which is not supported])
114 else
115 AC_MSG_ERROR([`$guix_system' is not a supported platform.
116See "GNU Distribution" in the manual, or try `--with-courage'.])
117 fi
118 ;;
119 esac
120])
121
9c7dd33a
LC
122dnl GUIX_ASSERT_GUILE_FEATURES FEATURES
123dnl
124dnl Assert that FEATURES are provided by $GUILE.
125AC_DEFUN([GUIX_ASSERT_GUILE_FEATURES], [
126 for guix_guile_feature in $1
127 do
128 AC_MSG_CHECKING([whether $GUILE provides feature '$guix_guile_feature'])
129 if "$GUILE" -c "(exit (provided? '$guix_guile_feature))"
130 then
131 AC_MSG_RESULT([yes])
132 else
133 AC_MSG_RESULT([no])
134 AC_MSG_ERROR([$GUILE does not support feature '$guix_guile_feature', which is required.])
135 fi
136 done
137])
1959fb04 138
49e6291a
LC
139dnl GUIX_CHECK_UNBUFFERED_CBIP
140dnl
141dnl Check whether 'setbvuf' works on custom binary input ports (CBIPs), as is
142dnl the case starting with Guile 2.0.10.
143AC_DEFUN([GUIX_CHECK_UNBUFFERED_CBIP], [
144 AC_CACHE_CHECK([whether Guile's custom binary input ports support 'setvbuf'],
145 [ac_cv_guix_cbips_support_setvbuf],
146 [if "$GUILE" -c "(use-modules (rnrs io ports)) \
147 (let ((p (make-custom-binary-input-port \"cbip\" pk #f #f #f))) \
148 (setvbuf p _IONBF))" >&5 2>&1
149 then
150 ac_cv_guix_cbips_support_setvbuf=yes
151 else
152 ac_cv_guix_cbips_support_setvbuf=no
153 fi])
154])
2178ed66 155
21531add
LC
156dnl GUIX_CHECK_GUILE_SSH
157dnl
158dnl Check whether a recent-enough Guile-SSH is available.
159AC_DEFUN([GUIX_CHECK_GUILE_SSH], [
160 dnl Check whether 'channel-send-eof' (introduced in 0.10.2) is present.
161 AC_CACHE_CHECK([whether Guile-SSH is available and recent enough],
162 [guix_cv_have_recent_guile_ssh],
163 [GUILE_CHECK([retval],
164 [(and (@ (ssh channel) channel-send-eof)
165 (@ (ssh popen) open-remote-pipe)
166 (@ (ssh dist node) node-eval))])
167 if test "$retval" = 0; then
168 guix_cv_have_recent_guile_ssh="yes"
169 else
170 guix_cv_have_recent_guile_ssh="no"
171 fi])
172])
173
2178ed66
LC
174dnl GUIX_TEST_ROOT_DIRECTORY
175AC_DEFUN([GUIX_TEST_ROOT_DIRECTORY], [
176 AC_CACHE_CHECK([for unit test root directory],
177 [ac_cv_guix_test_root],
178 [ac_cv_guix_test_root="`pwd`/test-tmp"])
179])
180
93ce8a8e
LC
181dnl 'BINPRM_BUF_SIZE' constant in Linux (we leave room for the trailing zero.)
182dnl The Hurd has a limit of about a page (see exec/hashexec.c.)
183m4_define([LINUX_HASH_BANG_LIMIT], 127)
2178ed66
LC
184
185dnl Hardcoded 'sun_path' length in <sys/un.h>.
186m4_define([SOCKET_FILE_NAME_LIMIT], 108)
187
188dnl GUIX_SOCKET_FILE_NAME_LENGTH
189AC_DEFUN([GUIX_SOCKET_FILE_NAME_LENGTH], [
190 AC_CACHE_CHECK([the length of the installed socket file name],
191 [ac_cv_guix_socket_file_name_length],
192 [ac_cv_guix_socket_file_name_length="`echo -n "$guix_localstatedir/guix/daemon-socket/socket" | wc -c`"])
193])
194
195dnl GUIX_TEST_SOCKET_FILE_NAME_LENGTH
196AC_DEFUN([GUIX_TEST_SOCKET_FILE_NAME_LENGTH], [
197 AC_REQUIRE([GUIX_TEST_ROOT_DIRECTORY])
198 AC_CACHE_CHECK([the length of the socket file name used in tests],
199 [ac_cv_guix_test_socket_file_name_length],
200 [ac_cv_guix_test_socket_file_name_length="`echo -n "$ac_cv_guix_test_root/var/123456/daemon-socket/socket" | wc -c`"])
201])
202
203dnl GUIX_HASH_BANG_LENGTH
204AC_DEFUN([GUIX_HASH_BANG_LENGTH], [
205 AC_CACHE_CHECK([the length of a typical hash bang line],
206 [ac_cv_guix_hash_bang_length],
207 [ac_cv_guix_hash_bang_length=`echo -n "$storedir/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa-bootstrap-binaries-0/bin/bash" | wc -c`])
208])
209
27ab3cee
LC
210dnl GUIX_TEST_HASH_BANG_LENGTH
211AC_DEFUN([GUIX_TEST_HASH_BANG_LENGTH], [
212 AC_REQUIRE([GUIX_TEST_ROOT_DIRECTORY])
213 AC_CACHE_CHECK([the length of a hash bang line used in tests],
214 [ac_cv_guix_test_hash_bang_length],
215 [ac_cv_guix_test_hash_bang_length=`echo -n "$ac_cv_guix_test_root/store/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa-bootstrap-binaries-0/bin/bash" | wc -c`])
216])
217
2178ed66
LC
218dnl GUIX_CHECK_FILE_NAME_LIMITS
219dnl
220dnl GNU/Linux has a couple of silly limits that we can easily run into.
bb251307
LC
221dnl Make sure everything is fine with the current settings. Set $1 to
222dnl 'yes' if tests can run, 'no' otherwise.
2178ed66
LC
223AC_DEFUN([GUIX_CHECK_FILE_NAME_LIMITS], [
224 AC_REQUIRE([GUIX_SOCKET_FILE_NAME_LENGTH])
225 AC_REQUIRE([GUIX_TEST_SOCKET_FILE_NAME_LENGTH])
226 AC_REQUIRE([GUIX_HASH_BANG_LENGTH])
27ab3cee 227 AC_REQUIRE([GUIX_TEST_HASH_BANG_LENGTH])
2178ed66
LC
228
229 if test "$ac_cv_guix_socket_file_name_length" -ge ]SOCKET_FILE_NAME_LIMIT[; then
230 AC_MSG_ERROR([socket file name would exceed the maxium allowed length])
231 fi
232 if test "$ac_cv_guix_test_socket_file_name_length" -ge ]SOCKET_FILE_NAME_LIMIT[; then
233 AC_MSG_WARN([socket file name limit may be exceeded when running tests])
234 fi
bb251307
LC
235
236 $1=yes
2178ed66 237 if test "$ac_cv_guix_hash_bang_length" -ge ]LINUX_HASH_BANG_LIMIT[; then
bb251307 238 $1=no
2178ed66
LC
239 AC_MSG_ERROR([store directory '$storedir' would lead to overly long hash-bang lines])
240 fi
27ab3cee 241 if test "$ac_cv_guix_test_hash_bang_length" -ge ]LINUX_HASH_BANG_LIMIT[; then
bb251307 242 $1=no
27ab3cee
LC
243 AC_MSG_WARN([test directory '$ac_cv_guix_test_root' may lead to overly long hash-bang lines])
244 fi
2178ed66 245])
368d08f7
LC
246
247dnl GUIX_CHECK_CXX11
248dnl
249dnl Check whether the C++ compiler can compile a typical C++11 program.
250AC_DEFUN([GUIX_CHECK_CXX11], [
251 AC_REQUIRE([AC_PROG_CXX])
252 AC_CACHE_CHECK([whether $CXX supports C++11],
253 [ac_cv_guix_cxx11_support],
254 [save_CXXFLAGS="$CXXFLAGS"
255 CXXFLAGS="-std=c++11 $CXXFLAGS"
256 AC_COMPILE_IFELSE([
257 AC_LANG_SOURCE([
258 #include <functional>
259
260 std::function<int(int)>
261 return_plus_lambda (int x)
262 {
263 auto result = [[&]](int y) {
264 return x + y;
265 };
266
267 return result;
268 }
269 ])],
270 [ac_cv_guix_cxx11_support=yes],
271 [ac_cv_guix_cxx11_support=no])
272 CXXFLAGS="$save_CXXFLAGS"
273 ])
274])
275
276dnl GUIX_ASSERT_CXX11
277dnl
278dnl Error out if the C++ compiler cannot compile C++11 code.
279AC_DEFUN([GUIX_ASSERT_CXX11], [
280 GUIX_CHECK_CXX11
281 if test "x$ac_cv_guix_cxx11_support" != "xyes"; then
282 AC_MSG_ERROR([C++ compiler '$CXX' does not support the C++11 standard])
283 fi
284])
12e5b266 285
dd01fecd
LC
286dnl GUIX_LIBGCRYPT_LIBDIR VAR
287dnl
288dnl Attempt to determine libgcrypt's LIBDIR; store the result in VAR.
289AC_DEFUN([GUIX_LIBGCRYPT_LIBDIR], [
290 AC_PATH_PROG([LIBGCRYPT_CONFIG], [libgcrypt-config])
291 AC_CACHE_CHECK([libgcrypt's library directory],
292 [guix_cv_libgcrypt_libdir],
293 [if test "x$LIBGCRYPT_CONFIG" != "x"; then
ca34fc31 294 guix_cv_libgcrypt_libdir=`$LIBGCRYPT_CONFIG --libs | grep -e -L | sed -e "s/.*-L\([[^ ]]\+\)[[[:blank:]]]\+-lgcrypt.*/\1/g"`
dd01fecd
LC
295 else
296 guix_cv_libgcrypt_libdir=""
297 fi])
298 $1="$guix_cv_libgcrypt_libdir"
299])
ef5f5c86 300
72153902
LC
301dnl GUIX_LIBZ_LIBDIR VAR
302dnl
303dnl Attempt to determine libz's LIBDIR; store the result in VAR.
304AC_DEFUN([GUIX_LIBZ_LIBDIR], [
305 AC_REQUIRE([PKG_PROG_PKG_CONFIG])
306 AC_CACHE_CHECK([zlib's library directory],
307 [guix_cv_libz_libdir],
308 [guix_cv_libz_libdir="`$PKG_CONFIG zlib --variable=libdir 2> /dev/null`"])
309 $1="$guix_cv_libz_libdir"
310])
311
ef5f5c86
LC
312dnl GUIX_CURRENT_LOCALSTATEDIR
313dnl
314dnl Determine the localstatedir of an existing Guix installation and set
315dnl 'guix_cv_current_localstatedir' accordingly. Set it to "none" if no
316dnl existing installation was found.
317AC_DEFUN([GUIX_CURRENT_LOCALSTATEDIR], [
318 AC_PATH_PROG([GUILE], [guile])
319 AC_CACHE_CHECK([the current installation's localstatedir],
320 [guix_cv_current_localstatedir],
321 [dnl Call 'dirname' because (guix config) appends "/guix" to LOCALSTATEDIR.
322 guix_cv_current_localstatedir="`"$GUILE" \
323 -c '(use-modules (guix config))
324 (when (string=? %store-directory "'$storedir'")
325 (display (dirname %state-directory)))' \
326 2>/dev/null`"
327 if test "x$guix_cv_current_localstatedir" = "x"; then
328 guix_cv_current_localstatedir=none
329 fi])])
330
331dnl GUIX_CHECK_LOCALSTATEDIR
332dnl
333dnl Check that the LOCALSTATEDIR value is consistent with that of the existing
334dnl Guix installation, if any. Error out or warn if they do not match.
335AC_DEFUN([GUIX_CHECK_LOCALSTATEDIR], [
336 AC_REQUIRE([GUIX_CURRENT_LOCALSTATEDIR])
337 if test "x$guix_cv_current_localstatedir" != "xnone"; then
338 if test "$guix_cv_current_localstatedir" != "$guix_localstatedir"; then
339 case "$localstatedir" in
340 NONE|\${prefix}*)
341 # User kept the default value---i.e., did not pass '--localstatedir'.
342 AC_MSG_ERROR([chosen localstatedir '$guix_localstatedir' does not match \
343that of the existing installation '$guix_cv_current_localstatedir'
344Installing may corrupt $storedir!
345Use './configure --localstatedir=$guix_cv_current_localstatedir'.])
346 ;;
347 *)
348 # User passed an explicit '--localstatedir'. Assume they know what
349 # they're doing.
350 AC_MSG_WARN([chosen localstatedir '$guix_localstatedir' does not match \
351that of the existing installation '$guix_cv_current_localstatedir'])
352 AC_MSG_WARN([installing may corrupt $storedir!])
353 ;;
354 esac
355 fi
356 fi])