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