gnu: yosys: Update to 0.7.
[jackhill/guix/guix.git] / m4 / guix.m4
CommitLineData
2357f850 1dnl GNU Guix --- Functional package management for GNU
27ab3cee 2dnl Copyright © 2012, 2013, 2014, 2015, 2016 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)
968ae903 53 machine_name="x86_64";;
dfdb15d9 54 arm|armv[[7-9]]*)
968ae903
LC
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 #
aa1e1947
MW
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";;
c2033df4
LC
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";;
4ed40a3e
MR
77 gnu*)
78 # Always use i586 for GNU/Hurd.
79 guix_system="i586-gnu";;
c2033df4
LC
80 *)
81 # Strip the version number from names such as `gnu0.3',
82 # `darwin10.2.0', etc.
eb25a30a 83 guix_system="$machine_name-`echo $host_os | "$SED" -e's/[0-9.]*$//g'`";;
c2033df4 84 esac])
5fedc65b
LC
85
86 AC_MSG_CHECKING([for the Guix system type])
87 AC_MSG_RESULT([$guix_system])
88
d8eea3d2 89 AC_SUBST([guix_system])
c2033df4 90])
9c7dd33a 91
b97556d7
LC
92dnl GUIX_ASSERT_SUPPORTED_SYSTEM
93dnl
94dnl Assert that this is a system to which the distro is ported.
95AC_DEFUN([GUIX_ASSERT_SUPPORTED_SYSTEM], [
96 AC_REQUIRE([GUIX_SYSTEM_TYPE])
97
98 AC_ARG_WITH([courage], [AC_HELP_STRING([--with-courage],
99 [Assert that even if this platform is unsupported, you will be
100courageous and port the GNU System distribution to it (see
101"GNU Distribution" in the manual.)])],
102 [guix_courageous="$withval"],
103 [guix_courageous="no"])
104
105 # Currently only Linux-based systems are supported, and only on some
106 # platforms.
107 case "$guix_system" in
aa1e1947 108 x86_64-linux|i686-linux|armhf-linux|mips64el-linux)
b97556d7
LC
109 ;;
110 *)
111 if test "x$guix_courageous" = "xyes"; then
112 AC_MSG_WARN([building Guix on `$guix_system', which is not supported])
113 else
114 AC_MSG_ERROR([`$guix_system' is not a supported platform.
115See "GNU Distribution" in the manual, or try `--with-courage'.])
116 fi
117 ;;
118 esac
119])
120
9c7dd33a
LC
121dnl GUIX_ASSERT_GUILE_FEATURES FEATURES
122dnl
123dnl Assert that FEATURES are provided by $GUILE.
124AC_DEFUN([GUIX_ASSERT_GUILE_FEATURES], [
125 for guix_guile_feature in $1
126 do
127 AC_MSG_CHECKING([whether $GUILE provides feature '$guix_guile_feature'])
128 if "$GUILE" -c "(exit (provided? '$guix_guile_feature))"
129 then
130 AC_MSG_RESULT([yes])
131 else
132 AC_MSG_RESULT([no])
133 AC_MSG_ERROR([$GUILE does not support feature '$guix_guile_feature', which is required.])
134 fi
135 done
136])
1959fb04
LC
137
138dnl GUIX_CHECK_SRFI_37
139dnl
140dnl Check whether SRFI-37 suffers from <http://bugs.gnu.org/13176>.
141dnl This bug was fixed in Guile 2.0.9.
142AC_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))) \
147 (alarm 1) \
148 (define opts (list (option '(#\I) #f #t (lambda _ #t)))) \
149 (args-fold '(\"-I\") opts (lambda _ (error)) (lambda _ #f) '())"
150 then
151 ac_cv_guix_srfi_37_broken=no
152 else
153 ac_cv_guix_srfi_37_broken=yes
154 fi])
155])
49e6291a
LC
156
157dnl GUIX_CHECK_UNBUFFERED_CBIP
158dnl
159dnl Check whether 'setbvuf' works on custom binary input ports (CBIPs), as is
160dnl the case starting with Guile 2.0.10.
161AC_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
167 then
168 ac_cv_guix_cbips_support_setvbuf=yes
169 else
170 ac_cv_guix_cbips_support_setvbuf=no
171 fi])
172])
2178ed66 173
21531add
LC
174dnl GUIX_CHECK_GUILE_SSH
175dnl
176dnl Check whether a recent-enough Guile-SSH is available.
177AC_DEFUN([GUIX_CHECK_GUILE_SSH], [
178 dnl Check whether 'channel-send-eof' (introduced in 0.10.2) is present.
179 AC_CACHE_CHECK([whether Guile-SSH is available and recent enough],
180 [guix_cv_have_recent_guile_ssh],
181 [GUILE_CHECK([retval],
182 [(and (@ (ssh channel) channel-send-eof)
183 (@ (ssh popen) open-remote-pipe)
184 (@ (ssh dist node) node-eval))])
185 if test "$retval" = 0; then
186 guix_cv_have_recent_guile_ssh="yes"
187 else
188 guix_cv_have_recent_guile_ssh="no"
189 fi])
190])
191
2178ed66
LC
192dnl GUIX_TEST_ROOT_DIRECTORY
193AC_DEFUN([GUIX_TEST_ROOT_DIRECTORY], [
194 AC_CACHE_CHECK([for unit test root directory],
195 [ac_cv_guix_test_root],
196 [ac_cv_guix_test_root="`pwd`/test-tmp"])
197])
198
93ce8a8e
LC
199dnl 'BINPRM_BUF_SIZE' constant in Linux (we leave room for the trailing zero.)
200dnl The Hurd has a limit of about a page (see exec/hashexec.c.)
201m4_define([LINUX_HASH_BANG_LIMIT], 127)
2178ed66
LC
202
203dnl Hardcoded 'sun_path' length in <sys/un.h>.
204m4_define([SOCKET_FILE_NAME_LIMIT], 108)
205
206dnl GUIX_SOCKET_FILE_NAME_LENGTH
207AC_DEFUN([GUIX_SOCKET_FILE_NAME_LENGTH], [
208 AC_CACHE_CHECK([the length of the installed socket file name],
209 [ac_cv_guix_socket_file_name_length],
210 [ac_cv_guix_socket_file_name_length="`echo -n "$guix_localstatedir/guix/daemon-socket/socket" | wc -c`"])
211])
212
213dnl GUIX_TEST_SOCKET_FILE_NAME_LENGTH
214AC_DEFUN([GUIX_TEST_SOCKET_FILE_NAME_LENGTH], [
215 AC_REQUIRE([GUIX_TEST_ROOT_DIRECTORY])
216 AC_CACHE_CHECK([the length of the socket file name used in tests],
217 [ac_cv_guix_test_socket_file_name_length],
218 [ac_cv_guix_test_socket_file_name_length="`echo -n "$ac_cv_guix_test_root/var/123456/daemon-socket/socket" | wc -c`"])
219])
220
221dnl GUIX_HASH_BANG_LENGTH
222AC_DEFUN([GUIX_HASH_BANG_LENGTH], [
223 AC_CACHE_CHECK([the length of a typical hash bang line],
224 [ac_cv_guix_hash_bang_length],
225 [ac_cv_guix_hash_bang_length=`echo -n "$storedir/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa-bootstrap-binaries-0/bin/bash" | wc -c`])
226])
227
27ab3cee
LC
228dnl GUIX_TEST_HASH_BANG_LENGTH
229AC_DEFUN([GUIX_TEST_HASH_BANG_LENGTH], [
230 AC_REQUIRE([GUIX_TEST_ROOT_DIRECTORY])
231 AC_CACHE_CHECK([the length of a hash bang line used in tests],
232 [ac_cv_guix_test_hash_bang_length],
233 [ac_cv_guix_test_hash_bang_length=`echo -n "$ac_cv_guix_test_root/store/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa-bootstrap-binaries-0/bin/bash" | wc -c`])
234])
235
2178ed66
LC
236dnl GUIX_CHECK_FILE_NAME_LIMITS
237dnl
238dnl GNU/Linux has a couple of silly limits that we can easily run into.
bb251307
LC
239dnl Make sure everything is fine with the current settings. Set $1 to
240dnl 'yes' if tests can run, 'no' otherwise.
2178ed66
LC
241AC_DEFUN([GUIX_CHECK_FILE_NAME_LIMITS], [
242 AC_REQUIRE([GUIX_SOCKET_FILE_NAME_LENGTH])
243 AC_REQUIRE([GUIX_TEST_SOCKET_FILE_NAME_LENGTH])
244 AC_REQUIRE([GUIX_HASH_BANG_LENGTH])
27ab3cee 245 AC_REQUIRE([GUIX_TEST_HASH_BANG_LENGTH])
2178ed66
LC
246
247 if test "$ac_cv_guix_socket_file_name_length" -ge ]SOCKET_FILE_NAME_LIMIT[; then
248 AC_MSG_ERROR([socket file name would exceed the maxium allowed length])
249 fi
250 if test "$ac_cv_guix_test_socket_file_name_length" -ge ]SOCKET_FILE_NAME_LIMIT[; then
251 AC_MSG_WARN([socket file name limit may be exceeded when running tests])
252 fi
bb251307
LC
253
254 $1=yes
2178ed66 255 if test "$ac_cv_guix_hash_bang_length" -ge ]LINUX_HASH_BANG_LIMIT[; then
bb251307 256 $1=no
2178ed66
LC
257 AC_MSG_ERROR([store directory '$storedir' would lead to overly long hash-bang lines])
258 fi
27ab3cee 259 if test "$ac_cv_guix_test_hash_bang_length" -ge ]LINUX_HASH_BANG_LIMIT[; then
bb251307 260 $1=no
27ab3cee
LC
261 AC_MSG_WARN([test directory '$ac_cv_guix_test_root' may lead to overly long hash-bang lines])
262 fi
2178ed66 263])
368d08f7
LC
264
265dnl GUIX_CHECK_CXX11
266dnl
267dnl Check whether the C++ compiler can compile a typical C++11 program.
268AC_DEFUN([GUIX_CHECK_CXX11], [
269 AC_REQUIRE([AC_PROG_CXX])
270 AC_CACHE_CHECK([whether $CXX supports C++11],
271 [ac_cv_guix_cxx11_support],
272 [save_CXXFLAGS="$CXXFLAGS"
273 CXXFLAGS="-std=c++11 $CXXFLAGS"
274 AC_COMPILE_IFELSE([
275 AC_LANG_SOURCE([
276 #include <functional>
277
278 std::function<int(int)>
279 return_plus_lambda (int x)
280 {
281 auto result = [[&]](int y) {
282 return x + y;
283 };
284
285 return result;
286 }
287 ])],
288 [ac_cv_guix_cxx11_support=yes],
289 [ac_cv_guix_cxx11_support=no])
290 CXXFLAGS="$save_CXXFLAGS"
291 ])
292])
293
294dnl GUIX_ASSERT_CXX11
295dnl
296dnl Error out if the C++ compiler cannot compile C++11 code.
297AC_DEFUN([GUIX_ASSERT_CXX11], [
298 GUIX_CHECK_CXX11
299 if test "x$ac_cv_guix_cxx11_support" != "xyes"; then
300 AC_MSG_ERROR([C++ compiler '$CXX' does not support the C++11 standard])
301 fi
302])
12e5b266 303
dd01fecd
LC
304dnl GUIX_LIBGCRYPT_LIBDIR VAR
305dnl
306dnl Attempt to determine libgcrypt's LIBDIR; store the result in VAR.
307AC_DEFUN([GUIX_LIBGCRYPT_LIBDIR], [
308 AC_PATH_PROG([LIBGCRYPT_CONFIG], [libgcrypt-config])
309 AC_CACHE_CHECK([libgcrypt's library directory],
310 [guix_cv_libgcrypt_libdir],
311 [if test "x$LIBGCRYPT_CONFIG" != "x"; then
ca34fc31 312 guix_cv_libgcrypt_libdir=`$LIBGCRYPT_CONFIG --libs | grep -e -L | sed -e "s/.*-L\([[^ ]]\+\)[[[:blank:]]]\+-lgcrypt.*/\1/g"`
dd01fecd
LC
313 else
314 guix_cv_libgcrypt_libdir=""
315 fi])
316 $1="$guix_cv_libgcrypt_libdir"
317])
ef5f5c86 318
72153902
LC
319dnl GUIX_LIBZ_LIBDIR VAR
320dnl
321dnl Attempt to determine libz's LIBDIR; store the result in VAR.
322AC_DEFUN([GUIX_LIBZ_LIBDIR], [
323 AC_REQUIRE([PKG_PROG_PKG_CONFIG])
324 AC_CACHE_CHECK([zlib's library directory],
325 [guix_cv_libz_libdir],
326 [guix_cv_libz_libdir="`$PKG_CONFIG zlib --variable=libdir 2> /dev/null`"])
327 $1="$guix_cv_libz_libdir"
328])
329
ef5f5c86
LC
330dnl GUIX_CURRENT_LOCALSTATEDIR
331dnl
332dnl Determine the localstatedir of an existing Guix installation and set
333dnl 'guix_cv_current_localstatedir' accordingly. Set it to "none" if no
334dnl existing installation was found.
335AC_DEFUN([GUIX_CURRENT_LOCALSTATEDIR], [
336 AC_PATH_PROG([GUILE], [guile])
337 AC_CACHE_CHECK([the current installation's localstatedir],
338 [guix_cv_current_localstatedir],
339 [dnl Call 'dirname' because (guix config) appends "/guix" to LOCALSTATEDIR.
340 guix_cv_current_localstatedir="`"$GUILE" \
341 -c '(use-modules (guix config))
342 (when (string=? %store-directory "'$storedir'")
343 (display (dirname %state-directory)))' \
344 2>/dev/null`"
345 if test "x$guix_cv_current_localstatedir" = "x"; then
346 guix_cv_current_localstatedir=none
347 fi])])
348
349dnl GUIX_CHECK_LOCALSTATEDIR
350dnl
351dnl Check that the LOCALSTATEDIR value is consistent with that of the existing
352dnl Guix installation, if any. Error out or warn if they do not match.
353AC_DEFUN([GUIX_CHECK_LOCALSTATEDIR], [
354 AC_REQUIRE([GUIX_CURRENT_LOCALSTATEDIR])
355 if test "x$guix_cv_current_localstatedir" != "xnone"; then
356 if test "$guix_cv_current_localstatedir" != "$guix_localstatedir"; then
357 case "$localstatedir" in
358 NONE|\${prefix}*)
359 # User kept the default value---i.e., did not pass '--localstatedir'.
360 AC_MSG_ERROR([chosen localstatedir '$guix_localstatedir' does not match \
361that of the existing installation '$guix_cv_current_localstatedir'
362Installing may corrupt $storedir!
363Use './configure --localstatedir=$guix_cv_current_localstatedir'.])
364 ;;
365 *)
366 # User passed an explicit '--localstatedir'. Assume they know what
367 # they're doing.
368 AC_MSG_WARN([chosen localstatedir '$guix_localstatedir' does not match \
369that of the existing installation '$guix_cv_current_localstatedir'])
370 AC_MSG_WARN([installing may corrupt $storedir!])
371 ;;
372 esac
373 fi
374 fi])