gnu: Add eyeD3.
[jackhill/guix/guix.git] / m4 / guix.m4
CommitLineData
2357f850 1dnl GNU Guix --- Functional package management for GNU
2178ed66 2dnl Copyright © 2012, 2013, 2014, 2015 Ludovic Courtès <ludo@gnu.org>
aa1e1947 3dnl Copyright © 2014 Mark H Weaver <mhw@netris.org>
d388c2c4 4dnl
2357f850 5dnl This file is part of GNU Guix.
d388c2c4 6dnl
2357f850 7dnl GNU Guix is free software; you can redistribute it and/or modify it
d388c2c4
LC
8dnl under the terms of the GNU General Public License as published by
9dnl the Free Software Foundation; either version 3 of the License, or (at
10dnl your option) any later version.
11dnl
2357f850 12dnl GNU Guix is distributed in the hope that it will be useful, but
d388c2c4
LC
13dnl WITHOUT ANY WARRANTY; without even the implied warranty of
14dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15dnl GNU General Public License for more details.
16dnl
17dnl You should have received a copy of the GNU General Public License
2357f850 18dnl along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
d388c2c4
LC
19
20dnl GUIX_ASSERT_LIBGCRYPT_USABLE
21dnl
22dnl Assert that GNU libgcrypt is usable from Guile.
23AC_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])
c2033df4
LC
37
38dnl GUIX_SYSTEM_TYPE
39dnl
40dnl Determine the Guix host system type, and store it in the
41dnl `guix_system' variable.
42AC_DEFUN([GUIX_SYSTEM_TYPE], [
43 AC_REQUIRE([AC_CANONICAL_HOST])
eb25a30a
LC
44 AC_PATH_PROG([SED], [sed])
45
c2033df4
LC
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";;
aa1e1947
MW
54 arm*)
55 # TODO: If not cross-compiling, add a sanity check to make
56 # sure this build machine has the needed features to
57 # support executables compiled using our armhf gcc,
58 # configured with:
59 # --with-arch=armv7-a
60 # --with-float=hard
61 # --with-mode=thumb
62 # --with-fpu=vfpv3-d16
63 machine_name="armhf";;
c2033df4
LC
64 *)
65 machine_name="$host_cpu";;
66 esac
67
68 case "$host_os" in
69 linux-gnu*)
70 # For backward compatibility, strip the `-gnu' part.
71 guix_system="$machine_name-linux";;
72 *)
73 # Strip the version number from names such as `gnu0.3',
74 # `darwin10.2.0', etc.
eb25a30a 75 guix_system="$machine_name-`echo $host_os | "$SED" -e's/[0-9.]*$//g'`";;
c2033df4 76 esac])
5fedc65b
LC
77
78 AC_MSG_CHECKING([for the Guix system type])
79 AC_MSG_RESULT([$guix_system])
80
d8eea3d2 81 AC_SUBST([guix_system])
c2033df4 82])
9c7dd33a 83
b97556d7
LC
84dnl GUIX_ASSERT_SUPPORTED_SYSTEM
85dnl
86dnl Assert that this is a system to which the distro is ported.
87AC_DEFUN([GUIX_ASSERT_SUPPORTED_SYSTEM], [
88 AC_REQUIRE([GUIX_SYSTEM_TYPE])
89
90 AC_ARG_WITH([courage], [AC_HELP_STRING([--with-courage],
91 [Assert that even if this platform is unsupported, you will be
92courageous and port the GNU System distribution to it (see
93"GNU Distribution" in the manual.)])],
94 [guix_courageous="$withval"],
95 [guix_courageous="no"])
96
97 # Currently only Linux-based systems are supported, and only on some
98 # platforms.
99 case "$guix_system" in
aa1e1947 100 x86_64-linux|i686-linux|armhf-linux|mips64el-linux)
b97556d7
LC
101 ;;
102 *)
103 if test "x$guix_courageous" = "xyes"; then
104 AC_MSG_WARN([building Guix on `$guix_system', which is not supported])
105 else
106 AC_MSG_ERROR([`$guix_system' is not a supported platform.
107See "GNU Distribution" in the manual, or try `--with-courage'.])
108 fi
109 ;;
110 esac
111])
112
9c7dd33a
LC
113dnl GUIX_ASSERT_GUILE_FEATURES FEATURES
114dnl
115dnl Assert that FEATURES are provided by $GUILE.
116AC_DEFUN([GUIX_ASSERT_GUILE_FEATURES], [
117 for guix_guile_feature in $1
118 do
119 AC_MSG_CHECKING([whether $GUILE provides feature '$guix_guile_feature'])
120 if "$GUILE" -c "(exit (provided? '$guix_guile_feature))"
121 then
122 AC_MSG_RESULT([yes])
123 else
124 AC_MSG_RESULT([no])
125 AC_MSG_ERROR([$GUILE does not support feature '$guix_guile_feature', which is required.])
126 fi
127 done
128])
1959fb04
LC
129
130dnl GUIX_CHECK_SRFI_37
131dnl
132dnl Check whether SRFI-37 suffers from <http://bugs.gnu.org/13176>.
133dnl This bug was fixed in Guile 2.0.9.
134AC_DEFUN([GUIX_CHECK_SRFI_37], [
135 AC_CACHE_CHECK([whether (srfi srfi-37) is affected by http://bugs.gnu.org/13176],
136 [ac_cv_guix_srfi_37_broken],
137 [if "$GUILE" -c "(use-modules (srfi srfi-37)) \
138 (sigaction SIGALRM (lambda _ (primitive-exit 1))) \
139 (alarm 1) \
140 (define opts (list (option '(#\I) #f #t (lambda _ #t)))) \
141 (args-fold '(\"-I\") opts (lambda _ (error)) (lambda _ #f) '())"
142 then
143 ac_cv_guix_srfi_37_broken=no
144 else
145 ac_cv_guix_srfi_37_broken=yes
146 fi])
147])
49e6291a
LC
148
149dnl GUIX_CHECK_UNBUFFERED_CBIP
150dnl
151dnl Check whether 'setbvuf' works on custom binary input ports (CBIPs), as is
152dnl the case starting with Guile 2.0.10.
153AC_DEFUN([GUIX_CHECK_UNBUFFERED_CBIP], [
154 AC_CACHE_CHECK([whether Guile's custom binary input ports support 'setvbuf'],
155 [ac_cv_guix_cbips_support_setvbuf],
156 [if "$GUILE" -c "(use-modules (rnrs io ports)) \
157 (let ((p (make-custom-binary-input-port \"cbip\" pk #f #f #f))) \
158 (setvbuf p _IONBF))" >&5 2>&1
159 then
160 ac_cv_guix_cbips_support_setvbuf=yes
161 else
162 ac_cv_guix_cbips_support_setvbuf=no
163 fi])
164])
2178ed66
LC
165
166dnl GUIX_TEST_ROOT_DIRECTORY
167AC_DEFUN([GUIX_TEST_ROOT_DIRECTORY], [
168 AC_CACHE_CHECK([for unit test root directory],
169 [ac_cv_guix_test_root],
170 [ac_cv_guix_test_root="`pwd`/test-tmp"])
171])
172
173dnl 'BINPRM_BUF_SIZE' constant in Linux. The Hurd has a limit
174dnl of about a page (see exec/hashexec.c.)
175m4_define([LINUX_HASH_BANG_LIMIT], 128)
176
177dnl Hardcoded 'sun_path' length in <sys/un.h>.
178m4_define([SOCKET_FILE_NAME_LIMIT], 108)
179
180dnl GUIX_SOCKET_FILE_NAME_LENGTH
181AC_DEFUN([GUIX_SOCKET_FILE_NAME_LENGTH], [
182 AC_CACHE_CHECK([the length of the installed socket file name],
183 [ac_cv_guix_socket_file_name_length],
184 [ac_cv_guix_socket_file_name_length="`echo -n "$guix_localstatedir/guix/daemon-socket/socket" | wc -c`"])
185])
186
187dnl GUIX_TEST_SOCKET_FILE_NAME_LENGTH
188AC_DEFUN([GUIX_TEST_SOCKET_FILE_NAME_LENGTH], [
189 AC_REQUIRE([GUIX_TEST_ROOT_DIRECTORY])
190 AC_CACHE_CHECK([the length of the socket file name used in tests],
191 [ac_cv_guix_test_socket_file_name_length],
192 [ac_cv_guix_test_socket_file_name_length="`echo -n "$ac_cv_guix_test_root/var/123456/daemon-socket/socket" | wc -c`"])
193])
194
195dnl GUIX_HASH_BANG_LENGTH
196AC_DEFUN([GUIX_HASH_BANG_LENGTH], [
197 AC_CACHE_CHECK([the length of a typical hash bang line],
198 [ac_cv_guix_hash_bang_length],
199 [ac_cv_guix_hash_bang_length=`echo -n "$storedir/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa-bootstrap-binaries-0/bin/bash" | wc -c`])
200])
201
202dnl GUIX_CHECK_FILE_NAME_LIMITS
203dnl
204dnl GNU/Linux has a couple of silly limits that we can easily run into.
205dnl Make sure everything is fine with the current settings.
206AC_DEFUN([GUIX_CHECK_FILE_NAME_LIMITS], [
207 AC_REQUIRE([GUIX_SOCKET_FILE_NAME_LENGTH])
208 AC_REQUIRE([GUIX_TEST_SOCKET_FILE_NAME_LENGTH])
209 AC_REQUIRE([GUIX_HASH_BANG_LENGTH])
210
211 if test "$ac_cv_guix_socket_file_name_length" -ge ]SOCKET_FILE_NAME_LIMIT[; then
212 AC_MSG_ERROR([socket file name would exceed the maxium allowed length])
213 fi
214 if test "$ac_cv_guix_test_socket_file_name_length" -ge ]SOCKET_FILE_NAME_LIMIT[; then
215 AC_MSG_WARN([socket file name limit may be exceeded when running tests])
216 fi
217 if test "$ac_cv_guix_hash_bang_length" -ge ]LINUX_HASH_BANG_LIMIT[; then
218 AC_MSG_ERROR([store directory '$storedir' would lead to overly long hash-bang lines])
219 fi
220])
368d08f7
LC
221
222dnl GUIX_CHECK_CXX11
223dnl
224dnl Check whether the C++ compiler can compile a typical C++11 program.
225AC_DEFUN([GUIX_CHECK_CXX11], [
226 AC_REQUIRE([AC_PROG_CXX])
227 AC_CACHE_CHECK([whether $CXX supports C++11],
228 [ac_cv_guix_cxx11_support],
229 [save_CXXFLAGS="$CXXFLAGS"
230 CXXFLAGS="-std=c++11 $CXXFLAGS"
231 AC_COMPILE_IFELSE([
232 AC_LANG_SOURCE([
233 #include <functional>
234
235 std::function<int(int)>
236 return_plus_lambda (int x)
237 {
238 auto result = [[&]](int y) {
239 return x + y;
240 };
241
242 return result;
243 }
244 ])],
245 [ac_cv_guix_cxx11_support=yes],
246 [ac_cv_guix_cxx11_support=no])
247 CXXFLAGS="$save_CXXFLAGS"
248 ])
249])
250
251dnl GUIX_ASSERT_CXX11
252dnl
253dnl Error out if the C++ compiler cannot compile C++11 code.
254AC_DEFUN([GUIX_ASSERT_CXX11], [
255 GUIX_CHECK_CXX11
256 if test "x$ac_cv_guix_cxx11_support" != "xyes"; then
257 AC_MSG_ERROR([C++ compiler '$CXX' does not support the C++11 standard])
258 fi
259])
12e5b266
LC
260
261dnl GUIX_CHECK_LIBC_MOUNT
262dnl
263dnl Check whether libc provides 'mount'. On GNU/Hurd it doesn't (yet).
264AC_DEFUN([GUIX_CHECK_LIBC_MOUNT], [
265 AC_CACHE_CHECK([whether libc provides 'mount'], [guix_cv_libc_has_mount],
266 [GUILE_CHECK([retval], [(dynamic-func \"mount\" (dynamic-link))])
267 if test "$retval" = 0; then
268 guix_cv_libc_has_mount="yes"
269 else
270 guix_cv_libc_has_mount="no"
271 fi])
272])
dd01fecd
LC
273
274dnl GUIX_LIBGCRYPT_LIBDIR VAR
275dnl
276dnl Attempt to determine libgcrypt's LIBDIR; store the result in VAR.
277AC_DEFUN([GUIX_LIBGCRYPT_LIBDIR], [
278 AC_PATH_PROG([LIBGCRYPT_CONFIG], [libgcrypt-config])
279 AC_CACHE_CHECK([libgcrypt's library directory],
280 [guix_cv_libgcrypt_libdir],
281 [if test "x$LIBGCRYPT_CONFIG" != "x"; then
ca34fc31 282 guix_cv_libgcrypt_libdir=`$LIBGCRYPT_CONFIG --libs | grep -e -L | sed -e "s/.*-L\([[^ ]]\+\)[[[:blank:]]]\+-lgcrypt.*/\1/g"`
dd01fecd
LC
283 else
284 guix_cv_libgcrypt_libdir=""
285 fi])
286 $1="$guix_cv_libgcrypt_libdir"
287])