Merge remote-tracking branch 'origin/master' into core-updates
[jackhill/guix/guix.git] / m4 / guix.m4
1 dnl GNU Guix --- Functional package management for GNU
2 dnl Copyright © 2012, 2013, 2014, 2015, 2016 Ludovic Courtès <ludo@gnu.org>
3 dnl Copyright © 2014 Mark H Weaver <mhw@netris.org>
4 dnl Copyright © 2017 Efraim Flashner <efraim@flashner.co.il>
5 dnl
6 dnl This file is part of GNU Guix.
7 dnl
8 dnl GNU Guix is free software; you can redistribute it and/or modify it
9 dnl under the terms of the GNU General Public License as published by
10 dnl the Free Software Foundation; either version 3 of the License, or (at
11 dnl your option) any later version.
12 dnl
13 dnl GNU Guix is distributed in the hope that it will be useful, but
14 dnl WITHOUT ANY WARRANTY; without even the implied warranty of
15 dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 dnl GNU General Public License for more details.
17 dnl
18 dnl You should have received a copy of the GNU General Public License
19 dnl along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
20
21 dnl GUIX_ASSERT_LIBGCRYPT_USABLE
22 dnl
23 dnl Assert that GNU libgcrypt is usable from Guile.
24 AC_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])
38
39 dnl GUIX_SYSTEM_TYPE
40 dnl
41 dnl Determine the Guix host system type, and store it in the
42 dnl `guix_system' variable.
43 AC_DEFUN([GUIX_SYSTEM_TYPE], [
44 AC_REQUIRE([AC_CANONICAL_HOST])
45 AC_PATH_PROG([SED], [sed])
46
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)
54 machine_name="x86_64";;
55 arm|armv[[7-9]]*)
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 #
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";;
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";;
78 gnu*)
79 # Always use i586 for GNU/Hurd.
80 guix_system="i586-gnu";;
81 *)
82 # Strip the version number from names such as `gnu0.3',
83 # `darwin10.2.0', etc.
84 guix_system="$machine_name-`echo $host_os | "$SED" -e's/[0-9.]*$//g'`";;
85 esac])
86
87 AC_MSG_CHECKING([for the Guix system type])
88 AC_MSG_RESULT([$guix_system])
89
90 AC_SUBST([guix_system])
91 ])
92
93 dnl GUIX_ASSERT_SUPPORTED_SYSTEM
94 dnl
95 dnl Assert that this is a system to which the distro is ported.
96 AC_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
101 courageous 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
109 x86_64-linux|i686-linux|armhf-linux|aarch64-linux|mips64el-linux)
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.
116 See "GNU Distribution" in the manual, or try `--with-courage'.])
117 fi
118 ;;
119 esac
120 ])
121
122 dnl GUIX_ASSERT_GUILE_FEATURES FEATURES
123 dnl
124 dnl Assert that FEATURES are provided by $GUILE.
125 AC_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 ])
138
139 dnl GUIX_CHECK_SRFI_37
140 dnl
141 dnl Check whether SRFI-37 suffers from <http://bugs.gnu.org/13176>.
142 dnl This bug was fixed in Guile 2.0.9.
143 AC_DEFUN([GUIX_CHECK_SRFI_37], [
144 AC_CACHE_CHECK([whether (srfi srfi-37) is affected by http://bugs.gnu.org/13176],
145 [ac_cv_guix_srfi_37_broken],
146 [if "$GUILE" -c "(use-modules (srfi srfi-37)) \
147 (sigaction SIGALRM (lambda _ (primitive-exit 1))) \
148 (alarm 1) \
149 (define opts (list (option '(#\I) #f #t (lambda _ #t)))) \
150 (args-fold '(\"-I\") opts (lambda _ (error)) (lambda _ #f) '())"
151 then
152 ac_cv_guix_srfi_37_broken=no
153 else
154 ac_cv_guix_srfi_37_broken=yes
155 fi])
156 ])
157
158 dnl GUIX_CHECK_UNBUFFERED_CBIP
159 dnl
160 dnl Check whether 'setbvuf' works on custom binary input ports (CBIPs), as is
161 dnl the case starting with Guile 2.0.10.
162 AC_DEFUN([GUIX_CHECK_UNBUFFERED_CBIP], [
163 AC_CACHE_CHECK([whether Guile's custom binary input ports support 'setvbuf'],
164 [ac_cv_guix_cbips_support_setvbuf],
165 [if "$GUILE" -c "(use-modules (rnrs io ports)) \
166 (let ((p (make-custom-binary-input-port \"cbip\" pk #f #f #f))) \
167 (setvbuf p _IONBF))" >&5 2>&1
168 then
169 ac_cv_guix_cbips_support_setvbuf=yes
170 else
171 ac_cv_guix_cbips_support_setvbuf=no
172 fi])
173 ])
174
175 dnl GUIX_CHECK_GUILE_SSH
176 dnl
177 dnl Check whether a recent-enough Guile-SSH is available.
178 AC_DEFUN([GUIX_CHECK_GUILE_SSH], [
179 dnl Check whether 'channel-send-eof' (introduced in 0.10.2) is present.
180 AC_CACHE_CHECK([whether Guile-SSH is available and recent enough],
181 [guix_cv_have_recent_guile_ssh],
182 [GUILE_CHECK([retval],
183 [(and (@ (ssh channel) channel-send-eof)
184 (@ (ssh popen) open-remote-pipe)
185 (@ (ssh dist node) node-eval))])
186 if test "$retval" = 0; then
187 guix_cv_have_recent_guile_ssh="yes"
188 else
189 guix_cv_have_recent_guile_ssh="no"
190 fi])
191 ])
192
193 dnl GUIX_TEST_ROOT_DIRECTORY
194 AC_DEFUN([GUIX_TEST_ROOT_DIRECTORY], [
195 AC_CACHE_CHECK([for unit test root directory],
196 [ac_cv_guix_test_root],
197 [ac_cv_guix_test_root="`pwd`/test-tmp"])
198 ])
199
200 dnl 'BINPRM_BUF_SIZE' constant in Linux (we leave room for the trailing zero.)
201 dnl The Hurd has a limit of about a page (see exec/hashexec.c.)
202 m4_define([LINUX_HASH_BANG_LIMIT], 127)
203
204 dnl Hardcoded 'sun_path' length in <sys/un.h>.
205 m4_define([SOCKET_FILE_NAME_LIMIT], 108)
206
207 dnl GUIX_SOCKET_FILE_NAME_LENGTH
208 AC_DEFUN([GUIX_SOCKET_FILE_NAME_LENGTH], [
209 AC_CACHE_CHECK([the length of the installed socket file name],
210 [ac_cv_guix_socket_file_name_length],
211 [ac_cv_guix_socket_file_name_length="`echo -n "$guix_localstatedir/guix/daemon-socket/socket" | wc -c`"])
212 ])
213
214 dnl GUIX_TEST_SOCKET_FILE_NAME_LENGTH
215 AC_DEFUN([GUIX_TEST_SOCKET_FILE_NAME_LENGTH], [
216 AC_REQUIRE([GUIX_TEST_ROOT_DIRECTORY])
217 AC_CACHE_CHECK([the length of the socket file name used in tests],
218 [ac_cv_guix_test_socket_file_name_length],
219 [ac_cv_guix_test_socket_file_name_length="`echo -n "$ac_cv_guix_test_root/var/123456/daemon-socket/socket" | wc -c`"])
220 ])
221
222 dnl GUIX_HASH_BANG_LENGTH
223 AC_DEFUN([GUIX_HASH_BANG_LENGTH], [
224 AC_CACHE_CHECK([the length of a typical hash bang line],
225 [ac_cv_guix_hash_bang_length],
226 [ac_cv_guix_hash_bang_length=`echo -n "$storedir/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa-bootstrap-binaries-0/bin/bash" | wc -c`])
227 ])
228
229 dnl GUIX_TEST_HASH_BANG_LENGTH
230 AC_DEFUN([GUIX_TEST_HASH_BANG_LENGTH], [
231 AC_REQUIRE([GUIX_TEST_ROOT_DIRECTORY])
232 AC_CACHE_CHECK([the length of a hash bang line used in tests],
233 [ac_cv_guix_test_hash_bang_length],
234 [ac_cv_guix_test_hash_bang_length=`echo -n "$ac_cv_guix_test_root/store/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa-bootstrap-binaries-0/bin/bash" | wc -c`])
235 ])
236
237 dnl GUIX_CHECK_FILE_NAME_LIMITS
238 dnl
239 dnl GNU/Linux has a couple of silly limits that we can easily run into.
240 dnl Make sure everything is fine with the current settings. Set $1 to
241 dnl 'yes' if tests can run, 'no' otherwise.
242 AC_DEFUN([GUIX_CHECK_FILE_NAME_LIMITS], [
243 AC_REQUIRE([GUIX_SOCKET_FILE_NAME_LENGTH])
244 AC_REQUIRE([GUIX_TEST_SOCKET_FILE_NAME_LENGTH])
245 AC_REQUIRE([GUIX_HASH_BANG_LENGTH])
246 AC_REQUIRE([GUIX_TEST_HASH_BANG_LENGTH])
247
248 if test "$ac_cv_guix_socket_file_name_length" -ge ]SOCKET_FILE_NAME_LIMIT[; then
249 AC_MSG_ERROR([socket file name would exceed the maxium allowed length])
250 fi
251 if test "$ac_cv_guix_test_socket_file_name_length" -ge ]SOCKET_FILE_NAME_LIMIT[; then
252 AC_MSG_WARN([socket file name limit may be exceeded when running tests])
253 fi
254
255 $1=yes
256 if test "$ac_cv_guix_hash_bang_length" -ge ]LINUX_HASH_BANG_LIMIT[; then
257 $1=no
258 AC_MSG_ERROR([store directory '$storedir' would lead to overly long hash-bang lines])
259 fi
260 if test "$ac_cv_guix_test_hash_bang_length" -ge ]LINUX_HASH_BANG_LIMIT[; then
261 $1=no
262 AC_MSG_WARN([test directory '$ac_cv_guix_test_root' may lead to overly long hash-bang lines])
263 fi
264 ])
265
266 dnl GUIX_CHECK_CXX11
267 dnl
268 dnl Check whether the C++ compiler can compile a typical C++11 program.
269 AC_DEFUN([GUIX_CHECK_CXX11], [
270 AC_REQUIRE([AC_PROG_CXX])
271 AC_CACHE_CHECK([whether $CXX supports C++11],
272 [ac_cv_guix_cxx11_support],
273 [save_CXXFLAGS="$CXXFLAGS"
274 CXXFLAGS="-std=c++11 $CXXFLAGS"
275 AC_COMPILE_IFELSE([
276 AC_LANG_SOURCE([
277 #include <functional>
278
279 std::function<int(int)>
280 return_plus_lambda (int x)
281 {
282 auto result = [[&]](int y) {
283 return x + y;
284 };
285
286 return result;
287 }
288 ])],
289 [ac_cv_guix_cxx11_support=yes],
290 [ac_cv_guix_cxx11_support=no])
291 CXXFLAGS="$save_CXXFLAGS"
292 ])
293 ])
294
295 dnl GUIX_ASSERT_CXX11
296 dnl
297 dnl Error out if the C++ compiler cannot compile C++11 code.
298 AC_DEFUN([GUIX_ASSERT_CXX11], [
299 GUIX_CHECK_CXX11
300 if test "x$ac_cv_guix_cxx11_support" != "xyes"; then
301 AC_MSG_ERROR([C++ compiler '$CXX' does not support the C++11 standard])
302 fi
303 ])
304
305 dnl GUIX_LIBGCRYPT_LIBDIR VAR
306 dnl
307 dnl Attempt to determine libgcrypt's LIBDIR; store the result in VAR.
308 AC_DEFUN([GUIX_LIBGCRYPT_LIBDIR], [
309 AC_PATH_PROG([LIBGCRYPT_CONFIG], [libgcrypt-config])
310 AC_CACHE_CHECK([libgcrypt's library directory],
311 [guix_cv_libgcrypt_libdir],
312 [if test "x$LIBGCRYPT_CONFIG" != "x"; then
313 guix_cv_libgcrypt_libdir=`$LIBGCRYPT_CONFIG --libs | grep -e -L | sed -e "s/.*-L\([[^ ]]\+\)[[[:blank:]]]\+-lgcrypt.*/\1/g"`
314 else
315 guix_cv_libgcrypt_libdir=""
316 fi])
317 $1="$guix_cv_libgcrypt_libdir"
318 ])
319
320 dnl GUIX_LIBZ_LIBDIR VAR
321 dnl
322 dnl Attempt to determine libz's LIBDIR; store the result in VAR.
323 AC_DEFUN([GUIX_LIBZ_LIBDIR], [
324 AC_REQUIRE([PKG_PROG_PKG_CONFIG])
325 AC_CACHE_CHECK([zlib's library directory],
326 [guix_cv_libz_libdir],
327 [guix_cv_libz_libdir="`$PKG_CONFIG zlib --variable=libdir 2> /dev/null`"])
328 $1="$guix_cv_libz_libdir"
329 ])
330
331 dnl GUIX_CURRENT_LOCALSTATEDIR
332 dnl
333 dnl Determine the localstatedir of an existing Guix installation and set
334 dnl 'guix_cv_current_localstatedir' accordingly. Set it to "none" if no
335 dnl existing installation was found.
336 AC_DEFUN([GUIX_CURRENT_LOCALSTATEDIR], [
337 AC_PATH_PROG([GUILE], [guile])
338 AC_CACHE_CHECK([the current installation's localstatedir],
339 [guix_cv_current_localstatedir],
340 [dnl Call 'dirname' because (guix config) appends "/guix" to LOCALSTATEDIR.
341 guix_cv_current_localstatedir="`"$GUILE" \
342 -c '(use-modules (guix config))
343 (when (string=? %store-directory "'$storedir'")
344 (display (dirname %state-directory)))' \
345 2>/dev/null`"
346 if test "x$guix_cv_current_localstatedir" = "x"; then
347 guix_cv_current_localstatedir=none
348 fi])])
349
350 dnl GUIX_CHECK_LOCALSTATEDIR
351 dnl
352 dnl Check that the LOCALSTATEDIR value is consistent with that of the existing
353 dnl Guix installation, if any. Error out or warn if they do not match.
354 AC_DEFUN([GUIX_CHECK_LOCALSTATEDIR], [
355 AC_REQUIRE([GUIX_CURRENT_LOCALSTATEDIR])
356 if test "x$guix_cv_current_localstatedir" != "xnone"; then
357 if test "$guix_cv_current_localstatedir" != "$guix_localstatedir"; then
358 case "$localstatedir" in
359 NONE|\${prefix}*)
360 # User kept the default value---i.e., did not pass '--localstatedir'.
361 AC_MSG_ERROR([chosen localstatedir '$guix_localstatedir' does not match \
362 that of the existing installation '$guix_cv_current_localstatedir'
363 Installing may corrupt $storedir!
364 Use './configure --localstatedir=$guix_cv_current_localstatedir'.])
365 ;;
366 *)
367 # User passed an explicit '--localstatedir'. Assume they know what
368 # they're doing.
369 AC_MSG_WARN([chosen localstatedir '$guix_localstatedir' does not match \
370 that of the existing installation '$guix_cv_current_localstatedir'])
371 AC_MSG_WARN([installing may corrupt $storedir!])
372 ;;
373 esac
374 fi
375 fi])