guix.m4 12 KB

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