guix.m4 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  1. dnl GNU Guix --- Functional package management for GNU
  2. dnl Copyright © 2012, 2013, 2014, 2015, 2016, 2018 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|mips64el-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_ASSERT_SYNTAX_OBJECT_EQUAL
  112. dnl
  113. dnl Guile 2.2.1 was a brown-paper-bag release where 'equal?' wouldn't work
  114. dnl for syntax objects, which broke gexps. Unfortunately Fedora 25 provides it.
  115. dnl Reject it.
  116. AC_DEFUN([GUIX_ASSERT_SYNTAX_OBJECT_EQUAL], [
  117. AC_CACHE_CHECK([whether 'equal?' works for syntax objects],
  118. [ac_cv_guix_syntax_object_equal],
  119. [if "$GUILE" -c '(exit (equal? (syntax x) (syntax x)))'
  120. then
  121. ac_cv_guix_syntax_object_equal=yes
  122. else
  123. ac_cv_guix_syntax_object_equal=no
  124. fi])
  125. if test "x$ac_cv_guix_syntax_object_equal" != xyes; then
  126. # This bug was present in Guile 2.2.1 only.
  127. AC_MSG_ERROR(['equal?' does not work for syntax object; upgrade to Guile 2.2.2 or later.])
  128. fi
  129. ])
  130. dnl GUIX_CHECK_GUILE_SSH
  131. dnl
  132. dnl Check whether a recent-enough Guile-SSH is available.
  133. AC_DEFUN([GUIX_CHECK_GUILE_SSH], [
  134. dnl Check whether 'channel-send-eof' (introduced in 0.10.2) is present.
  135. AC_CACHE_CHECK([whether Guile-SSH is available and recent enough],
  136. [guix_cv_have_recent_guile_ssh],
  137. [GUILE_CHECK([retval],
  138. [(and (@ (ssh channel) channel-send-eof)
  139. (@ (ssh popen) open-remote-pipe)
  140. (@ (ssh dist node) node-eval))])
  141. if test "$retval" = 0; then
  142. guix_cv_have_recent_guile_ssh="yes"
  143. else
  144. guix_cv_have_recent_guile_ssh="no"
  145. fi])
  146. ])
  147. dnl GUIX_CHECK_GUILE_SQLITE3
  148. dnl
  149. dnl Check whether a recent-enough Guile-Sqlite3 is available.
  150. AC_DEFUN([GUIX_CHECK_GUILE_SQLITE3], [
  151. dnl Check whether 'sqlite-bind-arguments' is available. It was introduced
  152. dnl in February 2018:
  153. dnl <https://notabug.org/guile-sqlite3/guile-sqlite3/commit/1cd1dec96a9999db48c0ff45bab907efc637247f>.
  154. AC_CACHE_CHECK([whether Guile-Sqlite3 is available and recent enough],
  155. [guix_cv_have_recent_guile_sqlite3],
  156. [GUILE_CHECK([retval],
  157. [(@ (sqlite3) sqlite-bind-arguments)])
  158. if test "$retval" = 0; then
  159. guix_cv_have_recent_guile_sqlite3="yes"
  160. else
  161. guix_cv_have_recent_guile_sqlite3="no"
  162. fi])
  163. ])
  164. dnl GUIX_TEST_ROOT_DIRECTORY
  165. AC_DEFUN([GUIX_TEST_ROOT_DIRECTORY], [
  166. AC_CACHE_CHECK([for unit test root directory],
  167. [ac_cv_guix_test_root],
  168. [ac_cv_guix_test_root="`pwd`/test-tmp"])
  169. ])
  170. dnl 'BINPRM_BUF_SIZE' constant in Linux (we leave room for the trailing zero.)
  171. dnl The Hurd has a limit of about a page (see exec/hashexec.c.)
  172. m4_define([LINUX_HASH_BANG_LIMIT], 127)
  173. dnl Hardcoded 'sun_path' length in <sys/un.h>.
  174. m4_define([SOCKET_FILE_NAME_LIMIT], 108)
  175. dnl GUIX_SOCKET_FILE_NAME_LENGTH
  176. AC_DEFUN([GUIX_SOCKET_FILE_NAME_LENGTH], [
  177. AC_CACHE_CHECK([the length of the installed socket file name],
  178. [ac_cv_guix_socket_file_name_length],
  179. [ac_cv_guix_socket_file_name_length="`echo -n "$guix_localstatedir/guix/daemon-socket/socket" | wc -c`"])
  180. ])
  181. dnl GUIX_TEST_SOCKET_FILE_NAME_LENGTH
  182. AC_DEFUN([GUIX_TEST_SOCKET_FILE_NAME_LENGTH], [
  183. AC_REQUIRE([GUIX_TEST_ROOT_DIRECTORY])
  184. AC_CACHE_CHECK([the length of the socket file name used in tests],
  185. [ac_cv_guix_test_socket_file_name_length],
  186. [ac_cv_guix_test_socket_file_name_length="`echo -n "$ac_cv_guix_test_root/var/123456/daemon-socket/socket" | wc -c`"])
  187. ])
  188. dnl GUIX_HASH_BANG_LENGTH
  189. AC_DEFUN([GUIX_HASH_BANG_LENGTH], [
  190. AC_CACHE_CHECK([the length of a typical hash bang line],
  191. [ac_cv_guix_hash_bang_length],
  192. [ac_cv_guix_hash_bang_length=`echo -n "$storedir/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa-bootstrap-binaries-0/bin/bash" | wc -c`])
  193. ])
  194. dnl GUIX_TEST_HASH_BANG_LENGTH
  195. AC_DEFUN([GUIX_TEST_HASH_BANG_LENGTH], [
  196. AC_REQUIRE([GUIX_TEST_ROOT_DIRECTORY])
  197. AC_CACHE_CHECK([the length of a hash bang line used in tests],
  198. [ac_cv_guix_test_hash_bang_length],
  199. [ac_cv_guix_test_hash_bang_length=`echo -n "$ac_cv_guix_test_root/store/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa-bootstrap-binaries-0/bin/bash" | wc -c`])
  200. ])
  201. dnl GUIX_CHECK_FILE_NAME_LIMITS
  202. dnl
  203. dnl GNU/Linux has a couple of silly limits that we can easily run into.
  204. dnl Make sure everything is fine with the current settings. Set $1 to
  205. dnl 'yes' if tests can run, 'no' otherwise.
  206. AC_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. AC_REQUIRE([GUIX_TEST_HASH_BANG_LENGTH])
  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. $1=yes
  218. if test "$ac_cv_guix_hash_bang_length" -ge ]LINUX_HASH_BANG_LIMIT[; then
  219. $1=no
  220. AC_MSG_ERROR([store directory '$storedir' would lead to overly long hash-bang lines])
  221. fi
  222. if test "$ac_cv_guix_test_hash_bang_length" -ge ]LINUX_HASH_BANG_LIMIT[; then
  223. $1=no
  224. AC_MSG_WARN([test directory '$ac_cv_guix_test_root' may lead to overly long hash-bang lines])
  225. fi
  226. ])
  227. dnl GUIX_CHECK_CXX11
  228. dnl
  229. dnl Check whether the C++ compiler can compile a typical C++11 program.
  230. AC_DEFUN([GUIX_CHECK_CXX11], [
  231. AC_REQUIRE([AC_PROG_CXX])
  232. AC_CACHE_CHECK([whether $CXX supports C++11],
  233. [ac_cv_guix_cxx11_support],
  234. [save_CXXFLAGS="$CXXFLAGS"
  235. CXXFLAGS="-std=c++11 $CXXFLAGS"
  236. AC_COMPILE_IFELSE([
  237. AC_LANG_SOURCE([
  238. #include <functional>
  239. std::function<int(int)>
  240. return_plus_lambda (int x)
  241. {
  242. auto result = [[&]](int y) {
  243. return x + y;
  244. };
  245. return result;
  246. }
  247. ])],
  248. [ac_cv_guix_cxx11_support=yes],
  249. [ac_cv_guix_cxx11_support=no])
  250. CXXFLAGS="$save_CXXFLAGS"
  251. ])
  252. ])
  253. dnl GUIX_ASSERT_CXX11
  254. dnl
  255. dnl Error out if the C++ compiler cannot compile C++11 code.
  256. AC_DEFUN([GUIX_ASSERT_CXX11], [
  257. GUIX_CHECK_CXX11
  258. if test "x$ac_cv_guix_cxx11_support" != "xyes"; then
  259. AC_MSG_ERROR([C++ compiler '$CXX' does not support the C++11 standard])
  260. fi
  261. ])
  262. dnl GUIX_LIBGCRYPT_LIBDIR VAR
  263. dnl
  264. dnl Attempt to determine libgcrypt's LIBDIR; store the result in VAR.
  265. AC_DEFUN([GUIX_LIBGCRYPT_LIBDIR], [
  266. AC_PATH_PROG([LIBGCRYPT_CONFIG], [libgcrypt-config])
  267. AC_CACHE_CHECK([libgcrypt's library directory],
  268. [guix_cv_libgcrypt_libdir],
  269. [if test "x$LIBGCRYPT_CONFIG" != "x"; then
  270. guix_cv_libgcrypt_libdir=`$LIBGCRYPT_CONFIG --libs | grep -e -L | sed -e "s/.*-L\([[^ ]]\+\)[[[:blank:]]]\+-lgcrypt.*/\1/g"`
  271. else
  272. guix_cv_libgcrypt_libdir=""
  273. fi])
  274. $1="$guix_cv_libgcrypt_libdir"
  275. ])
  276. dnl GUIX_LIBZ_LIBDIR VAR
  277. dnl
  278. dnl Attempt to determine libz's LIBDIR; store the result in VAR.
  279. AC_DEFUN([GUIX_LIBZ_LIBDIR], [
  280. AC_REQUIRE([PKG_PROG_PKG_CONFIG])
  281. AC_CACHE_CHECK([zlib's library directory],
  282. [guix_cv_libz_libdir],
  283. [guix_cv_libz_libdir="`$PKG_CONFIG zlib --variable=libdir 2> /dev/null`"])
  284. $1="$guix_cv_libz_libdir"
  285. ])
  286. dnl GUIX_CURRENT_LOCALSTATEDIR
  287. dnl
  288. dnl Determine the localstatedir of an existing Guix installation and set
  289. dnl 'guix_cv_current_localstatedir' accordingly. Set it to "none" if no
  290. dnl existing installation was found.
  291. AC_DEFUN([GUIX_CURRENT_LOCALSTATEDIR], [
  292. AC_PATH_PROG([GUILE], [guile])
  293. AC_CACHE_CHECK([the current installation's localstatedir],
  294. [guix_cv_current_localstatedir],
  295. [dnl Call 'dirname' because (guix config) appends "/guix" to LOCALSTATEDIR.
  296. guix_cv_current_localstatedir="`"$GUILE" \
  297. -c '(use-modules (guix config))
  298. (when (string=? %store-directory "'$storedir'")
  299. (display (dirname %state-directory)))' \
  300. 2>/dev/null`"
  301. if test "x$guix_cv_current_localstatedir" = "x"; then
  302. guix_cv_current_localstatedir=none
  303. fi])])
  304. dnl GUIX_CHECK_LOCALSTATEDIR
  305. dnl
  306. dnl Check that the LOCALSTATEDIR value is consistent with that of the existing
  307. dnl Guix installation, if any. Error out or warn if they do not match.
  308. AC_DEFUN([GUIX_CHECK_LOCALSTATEDIR], [
  309. AC_REQUIRE([GUIX_CURRENT_LOCALSTATEDIR])
  310. if test "x$guix_cv_current_localstatedir" != "xnone"; then
  311. if test "$guix_cv_current_localstatedir" != "$guix_localstatedir"; then
  312. case "$localstatedir" in
  313. NONE|\${prefix}*)
  314. # User kept the default value---i.e., did not pass '--localstatedir'.
  315. AC_MSG_ERROR([chosen localstatedir '$guix_localstatedir' does not match \
  316. that of the existing installation '$guix_cv_current_localstatedir'
  317. Installing may corrupt $storedir!
  318. Use './configure --localstatedir=$guix_cv_current_localstatedir'.])
  319. ;;
  320. *)
  321. # User passed an explicit '--localstatedir'. Assume they know what
  322. # they're doing.
  323. AC_MSG_WARN([chosen localstatedir '$guix_localstatedir' does not match \
  324. that of the existing installation '$guix_cv_current_localstatedir'])
  325. AC_MSG_WARN([installing may corrupt $storedir!])
  326. ;;
  327. esac
  328. fi
  329. fi])