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>
5 dnl This file is part of GNU Guix.
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.
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.
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/>.
20 dnl GUIX_ASSERT_LIBGCRYPT_USABLE
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"
31 guix_cv_libgcrypt_usable_p="no"
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'.])
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])
46 AC_ARG_WITH(system, AC_HELP_STRING([--with-system=SYSTEM],
47 [Platform identifier (e.g., `i686-linux').]),
48 [guix_system="$withval"],
53 machine_name="x86_64";;
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.
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,
67 # --with-fpu=vfpv3-d16
68 machine_name="armhf";;
70 machine_name="$host_cpu";;
75 # For backward compatibility, strip the `-gnu' part.
76 guix_system="$machine_name-linux";;
78 # Always use i586 for GNU/Hurd.
79 guix_system="i586-gnu";;
81 # Strip the version number from names such as `gnu0.3',
82 # `darwin10.2.0', etc.
83 guix_system="$machine_name-`echo $host_os | "$SED" -e's/[0-9.]*$//g'`";;
86 AC_MSG_CHECKING([for the Guix system type])
87 AC_MSG_RESULT([$guix_system])
89 AC_SUBST([guix_system])
92 dnl GUIX_ASSERT_SUPPORTED_SYSTEM
94 dnl Assert that this is a system to which the distro is ported.
95 AC_DEFUN([GUIX_ASSERT_SUPPORTED_SYSTEM], [
96 AC_REQUIRE([GUIX_SYSTEM_TYPE])
98 AC_ARG_WITH([courage], [AC_HELP_STRING([--with-courage],
99 [Assert that even if this platform is unsupported, you will be
100 courageous and port the GNU System distribution to it (see
101 "GNU Distribution" in the manual.)])],
102 [guix_courageous="$withval"],
103 [guix_courageous="no"])
105 # Currently only Linux-based systems are supported, and only on some
107 case "$guix_system" in
108 x86_64-linux|i686-linux|armhf-linux|mips64el-linux)
111 if test "x$guix_courageous" = "xyes"; then
112 AC_MSG_WARN([building Guix on `$guix_system', which is not supported])
114 AC_MSG_ERROR([`$guix_system' is not a supported platform.
115 See "GNU Distribution" in the manual, or try `--with-courage'.])
121 dnl GUIX_ASSERT_GUILE_FEATURES FEATURES
123 dnl Assert that FEATURES are provided by $GUILE.
124 AC_DEFUN([GUIX_ASSERT_GUILE_FEATURES], [
125 for guix_guile_feature in $1
127 AC_MSG_CHECKING([whether $GUILE provides feature '$guix_guile_feature'])
128 if "$GUILE" -c "(exit (provided? '$guix_guile_feature))"
133 AC_MSG_ERROR([$GUILE does not support feature '$guix_guile_feature', which is required.])
138 dnl GUIX_CHECK_SRFI_37
140 dnl Check whether SRFI-37 suffers from <http://bugs.gnu.org/13176>.
141 dnl This bug was fixed in Guile 2.0.9.
142 AC_DEFUN([GUIX_CHECK_SRFI_37], [
143 AC_CACHE_CHECK([whether (srfi srfi-37) is affected by http://bugs.gnu.org/13176],
144 [ac_cv_guix_srfi_37_broken],
145 [if "$GUILE" -c "(use-modules (srfi srfi-37)) \
146 (sigaction SIGALRM (lambda _ (primitive-exit 1))) \
148 (define opts (list (option '(#\I) #f #t (lambda _ #t)))) \
149 (args-fold '(\"-I\") opts (lambda _ (error)) (lambda _ #f) '())"
151 ac_cv_guix_srfi_37_broken=no
153 ac_cv_guix_srfi_37_broken=yes
157 dnl GUIX_CHECK_UNBUFFERED_CBIP
159 dnl Check whether 'setbvuf' works on custom binary input ports (CBIPs), as is
160 dnl the case starting with Guile 2.0.10.
161 AC_DEFUN([GUIX_CHECK_UNBUFFERED_CBIP], [
162 AC_CACHE_CHECK([whether Guile's custom binary input ports support 'setvbuf'],
163 [ac_cv_guix_cbips_support_setvbuf],
164 [if "$GUILE" -c "(use-modules (rnrs io ports)) \
165 (let ((p (make-custom-binary-input-port \"cbip\" pk #f #f #f))) \
166 (setvbuf p _IONBF))" >&5 2>&1
168 ac_cv_guix_cbips_support_setvbuf=yes
170 ac_cv_guix_cbips_support_setvbuf=no
174 dnl GUIX_TEST_ROOT_DIRECTORY
175 AC_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"])
181 dnl 'BINPRM_BUF_SIZE' constant in Linux (we leave room for the trailing zero.)
182 dnl The Hurd has a limit of about a page (see exec/hashexec.c.)
183 m4_define([LINUX_HASH_BANG_LIMIT], 127)
185 dnl Hardcoded 'sun_path' length in <sys/un.h>.
186 m4_define([SOCKET_FILE_NAME_LIMIT], 108)
188 dnl GUIX_SOCKET_FILE_NAME_LENGTH
189 AC_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`"])
195 dnl GUIX_TEST_SOCKET_FILE_NAME_LENGTH
196 AC_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`"])
203 dnl GUIX_HASH_BANG_LENGTH
204 AC_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`])
210 dnl GUIX_TEST_HASH_BANG_LENGTH
211 AC_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`])
218 dnl GUIX_CHECK_FILE_NAME_LIMITS
220 dnl GNU/Linux has a couple of silly limits that we can easily run into.
221 dnl Make sure everything is fine with the current settings. Set $1 to
222 dnl 'yes' if tests can run, 'no' otherwise.
223 AC_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])
227 AC_REQUIRE([GUIX_TEST_HASH_BANG_LENGTH])
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])
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])
237 if test "$ac_cv_guix_hash_bang_length" -ge ]LINUX_HASH_BANG_LIMIT[; then
239 AC_MSG_ERROR([store directory '$storedir' would lead to overly long hash-bang lines])
241 if test "$ac_cv_guix_test_hash_bang_length" -ge ]LINUX_HASH_BANG_LIMIT[; then
243 AC_MSG_WARN([test directory '$ac_cv_guix_test_root' may lead to overly long hash-bang lines])
249 dnl Check whether the C++ compiler can compile a typical C++11 program.
250 AC_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"
258 #include <functional>
260 std::function<int(int)>
261 return_plus_lambda (int x)
263 auto result = [[&]](int y) {
270 [ac_cv_guix_cxx11_support=yes],
271 [ac_cv_guix_cxx11_support=no])
272 CXXFLAGS="$save_CXXFLAGS"
276 dnl GUIX_ASSERT_CXX11
278 dnl Error out if the C++ compiler cannot compile C++11 code.
279 AC_DEFUN([GUIX_ASSERT_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])
286 dnl GUIX_LIBGCRYPT_LIBDIR VAR
288 dnl Attempt to determine libgcrypt's LIBDIR; store the result in VAR.
289 AC_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
294 guix_cv_libgcrypt_libdir=`$LIBGCRYPT_CONFIG --libs | grep -e -L | sed -e "s/.*-L\([[^ ]]\+\)[[[:blank:]]]\+-lgcrypt.*/\1/g"`
296 guix_cv_libgcrypt_libdir=""
298 $1="$guix_cv_libgcrypt_libdir"
301 dnl GUIX_LIBZ_LIBDIR VAR
303 dnl Attempt to determine libz's LIBDIR; store the result in VAR.
304 AC_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"
312 dnl GUIX_CURRENT_LOCALSTATEDIR
314 dnl Determine the localstatedir of an existing Guix installation and set
315 dnl 'guix_cv_current_localstatedir' accordingly. Set it to "none" if no
316 dnl existing installation was found.
317 AC_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)))' \
327 if test "x$guix_cv_current_localstatedir" = "x"; then
328 guix_cv_current_localstatedir=none
331 dnl GUIX_CHECK_LOCALSTATEDIR
333 dnl Check that the LOCALSTATEDIR value is consistent with that of the existing
334 dnl Guix installation, if any. Error out or warn if they do not match.
335 AC_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
341 # User kept the default value---i.e., did not pass '--localstatedir'.
342 AC_MSG_ERROR([chosen localstatedir '$guix_localstatedir' does not match \
343 that of the existing installation '$guix_cv_current_localstatedir'
344 Installing may corrupt $storedir!
345 Use './configure --localstatedir=$guix_cv_current_localstatedir'.])
348 # User passed an explicit '--localstatedir'. Assume they know what
350 AC_MSG_WARN([chosen localstatedir '$guix_localstatedir' does not match \
351 that of the existing installation '$guix_cv_current_localstatedir'])
352 AC_MSG_WARN([installing may corrupt $storedir!])