guix.m4 13 KB

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