guix.m4 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447
  1. dnl GNU Guix --- Functional package management for GNU
  2. dnl Copyright © 2012, 2013, 2014, 2015, 2016, 2018, 2019, 2020, 2021 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, AS_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], [AS_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_CHECK_GUILE_GIT
  192. dnl
  193. dnl Check whether a recent-enough Guile-Git is available.
  194. AC_DEFUN([GUIX_CHECK_GUILE_GIT], [
  195. dnl Check whether we're using Guile-Git 0.3.0 or later. 0.3.0
  196. dnl introduced SSH authentication support and more.
  197. AC_CACHE_CHECK([whether Guile-Git is available and recent enough],
  198. [guix_cv_have_recent_guile_git],
  199. [GUILE_CHECK([retval],
  200. [(use-modules (git) (git auth) (git submodule))
  201. (let ((auth (%make-auth-ssh-agent)))
  202. repository-close!
  203. object-lookup-prefix
  204. (make-clone-options
  205. #:fetch-options (make-fetch-options auth)))])
  206. if test "$retval" = 0; then
  207. guix_cv_have_recent_guile_git="yes"
  208. else
  209. guix_cv_have_recent_guile_git="no"
  210. fi])
  211. ])
  212. dnl GUIX_CHECK_GUILE_ZLIB
  213. dnl
  214. dnl Check whether a recent-enough Guile-zlib is available.
  215. AC_DEFUN([GUIX_CHECK_GUILE_ZLIB], [
  216. dnl Check whether we're using Guile-zlib 0.1.0 or later.
  217. dnl 0.1.0 introduced the 'make-zlib-input-port' and related code.
  218. AC_CACHE_CHECK([whether Guile-zlib is available and recent enough],
  219. [guix_cv_have_recent_guile_zlib],
  220. [GUILE_CHECK([retval],
  221. [(use-modules (zlib))
  222. make-zlib-input-port])
  223. if test "$retval" = 0; then
  224. guix_cv_have_recent_guile_zlib="yes"
  225. else
  226. guix_cv_have_recent_guile_zlib="no"
  227. fi])
  228. ])
  229. dnl GUIX_TEST_ROOT_DIRECTORY
  230. AC_DEFUN([GUIX_TEST_ROOT_DIRECTORY], [
  231. AC_CACHE_CHECK([for unit test root directory],
  232. [ac_cv_guix_test_root],
  233. [ac_cv_guix_test_root="`pwd`/test-tmp"])
  234. ])
  235. dnl 'BINPRM_BUF_SIZE' constant in Linux (we leave room for the trailing zero.)
  236. dnl The Hurd has a limit of about a page (see exec/hashexec.c.)
  237. m4_define([LINUX_HASH_BANG_LIMIT], 127)
  238. dnl Hardcoded 'sun_path' length in <sys/un.h>.
  239. m4_define([SOCKET_FILE_NAME_LIMIT], 108)
  240. dnl GUIX_SOCKET_FILE_NAME_LENGTH
  241. AC_DEFUN([GUIX_SOCKET_FILE_NAME_LENGTH], [
  242. AC_CACHE_CHECK([the length of the installed socket file name],
  243. [ac_cv_guix_socket_file_name_length],
  244. [ac_cv_guix_socket_file_name_length="`echo -n "$guix_localstatedir/guix/daemon-socket/socket" | wc -c`"])
  245. ])
  246. dnl GUIX_TEST_SOCKET_FILE_NAME_LENGTH
  247. AC_DEFUN([GUIX_TEST_SOCKET_FILE_NAME_LENGTH], [
  248. AC_REQUIRE([GUIX_TEST_ROOT_DIRECTORY])
  249. AC_CACHE_CHECK([the length of the socket file name used in tests],
  250. [ac_cv_guix_test_socket_file_name_length],
  251. [ac_cv_guix_test_socket_file_name_length="`echo -n "$ac_cv_guix_test_root/var/123456/daemon-socket/socket" | wc -c`"])
  252. ])
  253. dnl GUIX_HASH_BANG_LENGTH
  254. AC_DEFUN([GUIX_HASH_BANG_LENGTH], [
  255. AC_CACHE_CHECK([the length of a typical hash bang line],
  256. [ac_cv_guix_hash_bang_length],
  257. [ac_cv_guix_hash_bang_length=`echo -n "$storedir/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa-bootstrap-binaries-0/bin/bash" | wc -c`])
  258. ])
  259. dnl GUIX_TEST_HASH_BANG_LENGTH
  260. AC_DEFUN([GUIX_TEST_HASH_BANG_LENGTH], [
  261. AC_REQUIRE([GUIX_TEST_ROOT_DIRECTORY])
  262. AC_CACHE_CHECK([the length of a hash bang line used in tests],
  263. [ac_cv_guix_test_hash_bang_length],
  264. [ac_cv_guix_test_hash_bang_length=`echo -n "$ac_cv_guix_test_root/store/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa-bootstrap-binaries-0/bin/bash" | wc -c`])
  265. ])
  266. dnl GUIX_CHECK_FILE_NAME_LIMITS
  267. dnl
  268. dnl GNU/Linux has a couple of silly limits that we can easily run into.
  269. dnl Make sure everything is fine with the current settings. Set $1 to
  270. dnl 'yes' if tests can run, 'no' otherwise.
  271. AC_DEFUN([GUIX_CHECK_FILE_NAME_LIMITS], [
  272. AC_REQUIRE([GUIX_SOCKET_FILE_NAME_LENGTH])
  273. AC_REQUIRE([GUIX_TEST_SOCKET_FILE_NAME_LENGTH])
  274. AC_REQUIRE([GUIX_HASH_BANG_LENGTH])
  275. AC_REQUIRE([GUIX_TEST_HASH_BANG_LENGTH])
  276. if test "$ac_cv_guix_socket_file_name_length" -ge ]SOCKET_FILE_NAME_LIMIT[; then
  277. AC_MSG_ERROR([socket file name would exceed the maxium allowed length])
  278. fi
  279. if test "$ac_cv_guix_test_socket_file_name_length" -ge ]SOCKET_FILE_NAME_LIMIT[; then
  280. AC_MSG_WARN([socket file name limit may be exceeded when running tests])
  281. fi
  282. $1=yes
  283. if test "$ac_cv_guix_hash_bang_length" -ge ]LINUX_HASH_BANG_LIMIT[; then
  284. $1=no
  285. AC_MSG_ERROR([store directory '$storedir' would lead to overly long hash-bang lines])
  286. fi
  287. if test "$ac_cv_guix_test_hash_bang_length" -ge ]LINUX_HASH_BANG_LIMIT[; then
  288. $1=no
  289. AC_MSG_WARN([test directory '$ac_cv_guix_test_root' may lead to overly long hash-bang lines])
  290. fi
  291. ])
  292. dnl GUIX_CHECK_CXX11
  293. dnl
  294. dnl Check whether the C++ compiler can compile a typical C++11 program.
  295. AC_DEFUN([GUIX_CHECK_CXX11], [
  296. AC_REQUIRE([AC_PROG_CXX])
  297. AC_CACHE_CHECK([whether $CXX supports C++11],
  298. [ac_cv_guix_cxx11_support],
  299. [save_CXXFLAGS="$CXXFLAGS"
  300. CXXFLAGS="-std=c++11 $CXXFLAGS"
  301. AC_COMPILE_IFELSE([
  302. AC_LANG_SOURCE([
  303. #include <functional>
  304. std::function<int(int)>
  305. return_plus_lambda (int x)
  306. {
  307. auto result = [[&]](int y) {
  308. return x + y;
  309. };
  310. return result;
  311. }
  312. ])],
  313. [ac_cv_guix_cxx11_support=yes],
  314. [ac_cv_guix_cxx11_support=no])
  315. CXXFLAGS="$save_CXXFLAGS"
  316. ])
  317. ])
  318. dnl GUIX_ASSERT_CXX11
  319. dnl
  320. dnl Error out if the C++ compiler cannot compile C++11 code.
  321. AC_DEFUN([GUIX_ASSERT_CXX11], [
  322. GUIX_CHECK_CXX11
  323. if test "x$ac_cv_guix_cxx11_support" != "xyes"; then
  324. AC_MSG_ERROR([C++ compiler '$CXX' does not support the C++11 standard])
  325. fi
  326. ])
  327. dnl GUIX_LIBGCRYPT_LIBDIR VAR
  328. dnl
  329. dnl Attempt to determine libgcrypt's LIBDIR; store the result in VAR.
  330. AC_DEFUN([GUIX_LIBGCRYPT_LIBDIR], [
  331. AC_PATH_PROG([LIBGCRYPT_CONFIG], [libgcrypt-config])
  332. AC_CACHE_CHECK([libgcrypt's library directory],
  333. [guix_cv_libgcrypt_libdir],
  334. [if test "x$LIBGCRYPT_CONFIG" != "x"; then
  335. guix_cv_libgcrypt_libdir=`$LIBGCRYPT_CONFIG --libs | grep -e -L | sed -e "s/.*-L\([[^ ]]\+\)[[[:blank:]]]\+-lgcrypt.*/\1/g"`
  336. else
  337. guix_cv_libgcrypt_libdir=""
  338. fi])
  339. $1="$guix_cv_libgcrypt_libdir"
  340. ])
  341. dnl GUIX_CURRENT_LOCALSTATEDIR
  342. dnl
  343. dnl Determine the localstatedir of an existing Guix installation and set
  344. dnl 'guix_cv_current_localstatedir' accordingly. Set it to "none" if no
  345. dnl existing installation was found.
  346. AC_DEFUN([GUIX_CURRENT_LOCALSTATEDIR], [
  347. AC_PATH_PROG([GUILE], [guile])
  348. AC_CACHE_CHECK([the current installation's localstatedir],
  349. [guix_cv_current_localstatedir],
  350. [dnl Call 'dirname' because (guix config) appends "/guix" to LOCALSTATEDIR.
  351. guix_cv_current_localstatedir="`"$GUILE" \
  352. -c '(use-modules (guix config))
  353. (when (string=? %store-directory "'$storedir'")
  354. (display (dirname %state-directory)))' \
  355. 2>/dev/null`"
  356. if test "x$guix_cv_current_localstatedir" = "x"; then
  357. guix_cv_current_localstatedir=none
  358. fi])])
  359. dnl GUIX_CHECK_LOCALSTATEDIR
  360. dnl
  361. dnl Check that the LOCALSTATEDIR value is consistent with that of the existing
  362. dnl Guix installation, if any. Error out or warn if they do not match.
  363. AC_DEFUN([GUIX_CHECK_LOCALSTATEDIR], [
  364. AC_REQUIRE([GUIX_CURRENT_LOCALSTATEDIR])
  365. if test "x$guix_cv_current_localstatedir" != "xnone"; then
  366. if test "$guix_cv_current_localstatedir" != "$guix_localstatedir"; then
  367. case "$localstatedir" in
  368. NONE|\${prefix}*)
  369. # User kept the default value---i.e., did not pass '--localstatedir'.
  370. AC_MSG_ERROR([chosen localstatedir '$guix_localstatedir' does not match \
  371. that of the existing installation '$guix_cv_current_localstatedir'
  372. Installing may corrupt $storedir!
  373. Use './configure --localstatedir=$guix_cv_current_localstatedir'.])
  374. ;;
  375. *)
  376. # User passed an explicit '--localstatedir'. Assume they know what
  377. # they're doing.
  378. AC_MSG_WARN([chosen localstatedir '$guix_localstatedir' does not match \
  379. that of the existing installation '$guix_cv_current_localstatedir'])
  380. AC_MSG_WARN([installing may corrupt $storedir!])
  381. ;;
  382. esac
  383. fi
  384. fi])
  385. dnl GUIX_CHANNEL_METADATA
  386. dnl
  387. dnl Provide the channel metadata for this build. This allows 'guix describe'
  388. dnl to return meaningful data, as it would for a 'guix pull'-provided 'guix'.
  389. dnl The default URL and introduction are taken from (guix channels).
  390. AC_DEFUN([GUIX_CHANNEL_METADATA], [
  391. AC_ARG_WITH([channel-url], [AS_HELP_STRING([--with-channel-url=URL],
  392. [assert that this is built from the Git repository at URL])],
  393. [guix_channel_url="\"$withval\""],
  394. [guix_channel_url="\"https://git.savannah.gnu.org/git/guix.git\""])
  395. AC_ARG_WITH([channel-commit], [AS_HELP_STRING([--with-channel-commit=COMMIT],
  396. [assert that this is built from COMMIT])],
  397. [guix_channel_commit="\"$withval\""],
  398. [guix_channel_commit="#f"])
  399. AC_ARG_WITH([channel-introduction], [AS_HELP_STRING([--with-channel-introduction=COMMIT:FINGERPRINT],
  400. [specify COMMIT and FINGERPRINT as the introduction of this channel])],
  401. [guix_channel_introduction="'(\"`echo $withval | cut -f1 -d:`\" \"`echo $withval | cut -f2 -d:`\")"],
  402. [guix_channel_introduction="'(\"9edb3f66fd807b096b48283debdcddccfea34bad\" . \"BBB0 2DDF 2CEA F6A8 0D1D E643 A2A0 6DF2 A33A 54FA\")"])
  403. GUIX_CHANNEL_URL="$guix_channel_url"
  404. GUIX_CHANNEL_COMMIT="$guix_channel_commit"
  405. GUIX_CHANNEL_INTRODUCTION="$guix_channel_introduction"
  406. AC_SUBST([GUIX_CHANNEL_URL])
  407. AC_SUBST([GUIX_CHANNEL_COMMIT])
  408. AC_SUBST([GUIX_CHANNEL_INTRODUCTION])
  409. ])