You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

367 lines
13 KiB

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