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.
 
 
 
 
 
 

396 lines
14 KiB

  1. dnl GNU Guix --- Functional package management for GNU
  2. dnl Copyright © 2012, 2013, 2014, 2015, 2016, 2018, 2019 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 'userauth-gssapi!' (introduced in 0.12.0) 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. (@ (ssh auth) userauth-gssapi!))])
  142. if test "$retval" = 0; then
  143. guix_cv_have_recent_guile_ssh="yes"
  144. else
  145. guix_cv_have_recent_guile_ssh="no"
  146. fi])
  147. ])
  148. dnl GUIX_CHECK_GUILE_SQLITE3
  149. dnl
  150. dnl Check whether a recent-enough Guile-Sqlite3 is available.
  151. AC_DEFUN([GUIX_CHECK_GUILE_SQLITE3], [
  152. dnl Check whether 'sqlite-bind-arguments' is available. It was introduced
  153. dnl in February 2018:
  154. dnl <https://notabug.org/guile-sqlite3/guile-sqlite3/commit/1cd1dec96a9999db48c0ff45bab907efc637247f>.
  155. AC_CACHE_CHECK([whether Guile-Sqlite3 is available and recent enough],
  156. [guix_cv_have_recent_guile_sqlite3],
  157. [GUILE_CHECK([retval],
  158. [(@ (sqlite3) sqlite-bind-arguments)])
  159. if test "$retval" = 0; then
  160. guix_cv_have_recent_guile_sqlite3="yes"
  161. else
  162. guix_cv_have_recent_guile_sqlite3="no"
  163. fi])
  164. ])
  165. dnl GUIX_CHECK_GUILE_JSON
  166. dnl
  167. dnl Check whether a recent-enough Guile-JSON is available.
  168. AC_DEFUN([GUIX_CHECK_GUILE_JSON], [
  169. dnl Check whether we're using Guile-JSON 3.x, which uses a JSON-to-Scheme
  170. dnl mapping different from that of earlier versions.
  171. AC_CACHE_CHECK([whether Guile-JSON is available and recent enough],
  172. [guix_cv_have_recent_guile_json],
  173. [GUILE_CHECK([retval],
  174. [(use-modules (json) (ice-9 match))
  175. (match (json-string->scm \"[[ { \\\"a\\\": 42 } ]]\")
  176. (#((("a" . 42))) #t))])
  177. if test "$retval" = 0; then
  178. guix_cv_have_recent_guile_json="yes"
  179. else
  180. guix_cv_have_recent_guile_json="no"
  181. fi])
  182. ])
  183. dnl GUIX_TEST_ROOT_DIRECTORY
  184. AC_DEFUN([GUIX_TEST_ROOT_DIRECTORY], [
  185. AC_CACHE_CHECK([for unit test root directory],
  186. [ac_cv_guix_test_root],
  187. [ac_cv_guix_test_root="`pwd`/test-tmp"])
  188. ])
  189. dnl 'BINPRM_BUF_SIZE' constant in Linux (we leave room for the trailing zero.)
  190. dnl The Hurd has a limit of about a page (see exec/hashexec.c.)
  191. m4_define([LINUX_HASH_BANG_LIMIT], 127)
  192. dnl Hardcoded 'sun_path' length in <sys/un.h>.
  193. m4_define([SOCKET_FILE_NAME_LIMIT], 108)
  194. dnl GUIX_SOCKET_FILE_NAME_LENGTH
  195. AC_DEFUN([GUIX_SOCKET_FILE_NAME_LENGTH], [
  196. AC_CACHE_CHECK([the length of the installed socket file name],
  197. [ac_cv_guix_socket_file_name_length],
  198. [ac_cv_guix_socket_file_name_length="`echo -n "$guix_localstatedir/guix/daemon-socket/socket" | wc -c`"])
  199. ])
  200. dnl GUIX_TEST_SOCKET_FILE_NAME_LENGTH
  201. AC_DEFUN([GUIX_TEST_SOCKET_FILE_NAME_LENGTH], [
  202. AC_REQUIRE([GUIX_TEST_ROOT_DIRECTORY])
  203. AC_CACHE_CHECK([the length of the socket file name used in tests],
  204. [ac_cv_guix_test_socket_file_name_length],
  205. [ac_cv_guix_test_socket_file_name_length="`echo -n "$ac_cv_guix_test_root/var/123456/daemon-socket/socket" | wc -c`"])
  206. ])
  207. dnl GUIX_HASH_BANG_LENGTH
  208. AC_DEFUN([GUIX_HASH_BANG_LENGTH], [
  209. AC_CACHE_CHECK([the length of a typical hash bang line],
  210. [ac_cv_guix_hash_bang_length],
  211. [ac_cv_guix_hash_bang_length=`echo -n "$storedir/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa-bootstrap-binaries-0/bin/bash" | wc -c`])
  212. ])
  213. dnl GUIX_TEST_HASH_BANG_LENGTH
  214. AC_DEFUN([GUIX_TEST_HASH_BANG_LENGTH], [
  215. AC_REQUIRE([GUIX_TEST_ROOT_DIRECTORY])
  216. AC_CACHE_CHECK([the length of a hash bang line used in tests],
  217. [ac_cv_guix_test_hash_bang_length],
  218. [ac_cv_guix_test_hash_bang_length=`echo -n "$ac_cv_guix_test_root/store/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa-bootstrap-binaries-0/bin/bash" | wc -c`])
  219. ])
  220. dnl GUIX_CHECK_FILE_NAME_LIMITS
  221. dnl
  222. dnl GNU/Linux has a couple of silly limits that we can easily run into.
  223. dnl Make sure everything is fine with the current settings. Set $1 to
  224. dnl 'yes' if tests can run, 'no' otherwise.
  225. AC_DEFUN([GUIX_CHECK_FILE_NAME_LIMITS], [
  226. AC_REQUIRE([GUIX_SOCKET_FILE_NAME_LENGTH])
  227. AC_REQUIRE([GUIX_TEST_SOCKET_FILE_NAME_LENGTH])
  228. AC_REQUIRE([GUIX_HASH_BANG_LENGTH])
  229. AC_REQUIRE([GUIX_TEST_HASH_BANG_LENGTH])
  230. if test "$ac_cv_guix_socket_file_name_length" -ge ]SOCKET_FILE_NAME_LIMIT[; then
  231. AC_MSG_ERROR([socket file name would exceed the maxium allowed length])
  232. fi
  233. if test "$ac_cv_guix_test_socket_file_name_length" -ge ]SOCKET_FILE_NAME_LIMIT[; then
  234. AC_MSG_WARN([socket file name limit may be exceeded when running tests])
  235. fi
  236. $1=yes
  237. if test "$ac_cv_guix_hash_bang_length" -ge ]LINUX_HASH_BANG_LIMIT[; then
  238. $1=no
  239. AC_MSG_ERROR([store directory '$storedir' would lead to overly long hash-bang lines])
  240. fi
  241. if test "$ac_cv_guix_test_hash_bang_length" -ge ]LINUX_HASH_BANG_LIMIT[; then
  242. $1=no
  243. AC_MSG_WARN([test directory '$ac_cv_guix_test_root' may lead to overly long hash-bang lines])
  244. fi
  245. ])
  246. dnl GUIX_CHECK_CXX11
  247. dnl
  248. dnl Check whether the C++ compiler can compile a typical C++11 program.
  249. AC_DEFUN([GUIX_CHECK_CXX11], [
  250. AC_REQUIRE([AC_PROG_CXX])
  251. AC_CACHE_CHECK([whether $CXX supports C++11],
  252. [ac_cv_guix_cxx11_support],
  253. [save_CXXFLAGS="$CXXFLAGS"
  254. CXXFLAGS="-std=c++11 $CXXFLAGS"
  255. AC_COMPILE_IFELSE([
  256. AC_LANG_SOURCE([
  257. #include <functional>
  258. std::function<int(int)>
  259. return_plus_lambda (int x)
  260. {
  261. auto result = [[&]](int y) {
  262. return x + y;
  263. };
  264. return result;
  265. }
  266. ])],
  267. [ac_cv_guix_cxx11_support=yes],
  268. [ac_cv_guix_cxx11_support=no])
  269. CXXFLAGS="$save_CXXFLAGS"
  270. ])
  271. ])
  272. dnl GUIX_ASSERT_CXX11
  273. dnl
  274. dnl Error out if the C++ compiler cannot compile C++11 code.
  275. AC_DEFUN([GUIX_ASSERT_CXX11], [
  276. GUIX_CHECK_CXX11
  277. if test "x$ac_cv_guix_cxx11_support" != "xyes"; then
  278. AC_MSG_ERROR([C++ compiler '$CXX' does not support the C++11 standard])
  279. fi
  280. ])
  281. dnl GUIX_LIBGCRYPT_LIBDIR VAR
  282. dnl
  283. dnl Attempt to determine libgcrypt's LIBDIR; store the result in VAR.
  284. AC_DEFUN([GUIX_LIBGCRYPT_LIBDIR], [
  285. AC_PATH_PROG([LIBGCRYPT_CONFIG], [libgcrypt-config])
  286. AC_CACHE_CHECK([libgcrypt's library directory],
  287. [guix_cv_libgcrypt_libdir],
  288. [if test "x$LIBGCRYPT_CONFIG" != "x"; then
  289. guix_cv_libgcrypt_libdir=`$LIBGCRYPT_CONFIG --libs | grep -e -L | sed -e "s/.*-L\([[^ ]]\+\)[[[:blank:]]]\+-lgcrypt.*/\1/g"`
  290. else
  291. guix_cv_libgcrypt_libdir=""
  292. fi])
  293. $1="$guix_cv_libgcrypt_libdir"
  294. ])
  295. dnl GUIX_LIBZ_LIBDIR VAR
  296. dnl
  297. dnl Attempt to determine libz's LIBDIR; store the result in VAR.
  298. AC_DEFUN([GUIX_LIBZ_LIBDIR], [
  299. AC_REQUIRE([PKG_PROG_PKG_CONFIG])
  300. AC_CACHE_CHECK([zlib's library directory],
  301. [guix_cv_libz_libdir],
  302. [guix_cv_libz_libdir="`$PKG_CONFIG zlib --variable=libdir 2> /dev/null`"])
  303. $1="$guix_cv_libz_libdir"
  304. ])
  305. dnl GUIX_LIBLZ_FILE_NAME VAR
  306. dnl
  307. dnl Attempt to determine liblz's absolute file name; store the result in VAR.
  308. AC_DEFUN([GUIX_LIBLZ_FILE_NAME], [
  309. AC_REQUIRE([PKG_PROG_PKG_CONFIG])
  310. AC_CACHE_CHECK([lzlib's file name],
  311. [guix_cv_liblz_libdir],
  312. [old_LIBS="$LIBS"
  313. LIBS="-llz"
  314. AC_LINK_IFELSE([AC_LANG_SOURCE([int main () { return LZ_decompress_open(); }])],
  315. [guix_cv_liblz_libdir="`ldd conftest$EXEEXT | grep liblz | sed '-es/.*=> \(.*\) .*$/\1/g'`"])
  316. LIBS="$old_LIBS"])
  317. $1="$guix_cv_liblz_libdir"
  318. ])
  319. dnl GUIX_CURRENT_LOCALSTATEDIR
  320. dnl
  321. dnl Determine the localstatedir of an existing Guix installation and set
  322. dnl 'guix_cv_current_localstatedir' accordingly. Set it to "none" if no
  323. dnl existing installation was found.
  324. AC_DEFUN([GUIX_CURRENT_LOCALSTATEDIR], [
  325. AC_PATH_PROG([GUILE], [guile])
  326. AC_CACHE_CHECK([the current installation's localstatedir],
  327. [guix_cv_current_localstatedir],
  328. [dnl Call 'dirname' because (guix config) appends "/guix" to LOCALSTATEDIR.
  329. guix_cv_current_localstatedir="`"$GUILE" \
  330. -c '(use-modules (guix config))
  331. (when (string=? %store-directory "'$storedir'")
  332. (display (dirname %state-directory)))' \
  333. 2>/dev/null`"
  334. if test "x$guix_cv_current_localstatedir" = "x"; then
  335. guix_cv_current_localstatedir=none
  336. fi])])
  337. dnl GUIX_CHECK_LOCALSTATEDIR
  338. dnl
  339. dnl Check that the LOCALSTATEDIR value is consistent with that of the existing
  340. dnl Guix installation, if any. Error out or warn if they do not match.
  341. AC_DEFUN([GUIX_CHECK_LOCALSTATEDIR], [
  342. AC_REQUIRE([GUIX_CURRENT_LOCALSTATEDIR])
  343. if test "x$guix_cv_current_localstatedir" != "xnone"; then
  344. if test "$guix_cv_current_localstatedir" != "$guix_localstatedir"; then
  345. case "$localstatedir" in
  346. NONE|\${prefix}*)
  347. # User kept the default value---i.e., did not pass '--localstatedir'.
  348. AC_MSG_ERROR([chosen localstatedir '$guix_localstatedir' does not match \
  349. that of the existing installation '$guix_cv_current_localstatedir'
  350. Installing may corrupt $storedir!
  351. Use './configure --localstatedir=$guix_cv_current_localstatedir'.])
  352. ;;
  353. *)
  354. # User passed an explicit '--localstatedir'. Assume they know what
  355. # they're doing.
  356. AC_MSG_WARN([chosen localstatedir '$guix_localstatedir' does not match \
  357. that of the existing installation '$guix_cv_current_localstatedir'])
  358. AC_MSG_WARN([installing may corrupt $storedir!])
  359. ;;
  360. esac
  361. fi
  362. fi])