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 # 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'`";;
83 AC_MSG_CHECKING([for the Guix system type])
84 AC_MSG_RESULT([$guix_system])
86 AC_SUBST([guix_system])
89 dnl GUIX_ASSERT_SUPPORTED_SYSTEM
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])
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"])
102 # Currently only Linux-based systems are supported, and only on some
104 case "$guix_system" in
105 x86_64-linux|i686-linux|armhf-linux|mips64el-linux)
108 if test "x$guix_courageous" = "xyes"; then
109 AC_MSG_WARN([building Guix on `$guix_system', which is not supported])
111 AC_MSG_ERROR([`$guix_system' is not a supported platform.
112 See "GNU Distribution" in the manual, or try `--with-courage'.])
118 dnl GUIX_ASSERT_GUILE_FEATURES FEATURES
120 dnl Assert that FEATURES are provided by $GUILE.
121 AC_DEFUN([GUIX_ASSERT_GUILE_FEATURES], [
122 for guix_guile_feature in $1
124 AC_MSG_CHECKING([whether $GUILE provides feature '$guix_guile_feature'])
125 if "$GUILE" -c "(exit (provided? '$guix_guile_feature))"
130 AC_MSG_ERROR([$GUILE does not support feature '$guix_guile_feature', which is required.])
135 dnl GUIX_CHECK_SRFI_37
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))) \
145 (define opts (list (option '(#\I) #f #t (lambda _ #t)))) \
146 (args-fold '(\"-I\") opts (lambda _ (error)) (lambda _ #f) '())"
148 ac_cv_guix_srfi_37_broken=no
150 ac_cv_guix_srfi_37_broken=yes
154 dnl GUIX_CHECK_UNBUFFERED_CBIP
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
165 ac_cv_guix_cbips_support_setvbuf=yes
167 ac_cv_guix_cbips_support_setvbuf=no
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"])
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)
182 dnl Hardcoded 'sun_path' length in <sys/un.h>.
183 m4_define([SOCKET_FILE_NAME_LIMIT], 108)
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`"])
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`"])
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`])
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`])
215 dnl GUIX_CHECK_FILE_NAME_LIMITS
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])
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])
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])
234 if test "$ac_cv_guix_hash_bang_length" -ge ]LINUX_HASH_BANG_LIMIT[; then
236 AC_MSG_ERROR([store directory '$storedir' would lead to overly long hash-bang lines])
238 if test "$ac_cv_guix_test_hash_bang_length" -ge ]LINUX_HASH_BANG_LIMIT[; then
240 AC_MSG_WARN([test directory '$ac_cv_guix_test_root' may lead to overly long hash-bang lines])
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"
255 #include <functional>
257 std::function<int(int)>
258 return_plus_lambda (int x)
260 auto result = [[&]](int y) {
267 [ac_cv_guix_cxx11_support=yes],
268 [ac_cv_guix_cxx11_support=no])
269 CXXFLAGS="$save_CXXFLAGS"
273 dnl GUIX_ASSERT_CXX11
275 dnl Error out if the C++ compiler cannot compile C++11 code.
276 AC_DEFUN([GUIX_ASSERT_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])
283 dnl GUIX_CHECK_LIBC_MOUNT
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"
292 guix_cv_libc_has_mount="no"
296 dnl GUIX_LIBGCRYPT_LIBDIR VAR
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"`
306 guix_cv_libgcrypt_libdir=""
308 $1="$guix_cv_libgcrypt_libdir"
311 dnl GUIX_LIBZ_LIBDIR VAR
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"
322 dnl GUIX_CURRENT_LOCALSTATEDIR
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)))' \
337 if test "x$guix_cv_current_localstatedir" = "x"; then
338 guix_cv_current_localstatedir=none
341 dnl GUIX_CHECK_LOCALSTATEDIR
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
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'.])
358 # User passed an explicit '--localstatedir'. Assume they know what
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!])