guix.m4 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453
  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, 2020, 2021 Efraim Flashner <efraim@flashner.co.il>
  5. dnl Copyright © 2021 Chris Marusich <cmmarusich@gmail.com>
  6. dnl
  7. dnl This file is part of GNU Guix.
  8. dnl
  9. dnl GNU Guix is free software; you can redistribute it and/or modify it
  10. dnl under the terms of the GNU General Public License as published by
  11. dnl the Free Software Foundation; either version 3 of the License, or (at
  12. dnl your option) any later version.
  13. dnl
  14. dnl GNU Guix is distributed in the hope that it will be useful, but
  15. dnl WITHOUT ANY WARRANTY; without even the implied warranty of
  16. dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. dnl GNU General Public License for more details.
  18. dnl
  19. dnl You should have received a copy of the GNU General Public License
  20. dnl along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
  21. dnl GUIX_SYSTEM_TYPE
  22. dnl
  23. dnl Determine the Guix host system type, and store it in the
  24. dnl `guix_system' variable.
  25. AC_DEFUN([GUIX_SYSTEM_TYPE], [
  26. AC_REQUIRE([AC_CANONICAL_HOST])
  27. AC_PATH_PROG([SED], [sed])
  28. AC_ARG_WITH(system, AS_HELP_STRING([--with-system=SYSTEM],
  29. [Platform identifier (e.g., `i686-linux').]),
  30. [guix_system="$withval"],
  31. [case "$host_cpu" in
  32. i*86)
  33. machine_name="i686";;
  34. amd64)
  35. machine_name="x86_64";;
  36. arm|armv[[7-9]]*)
  37. # Here we want to exclude CPUs such as "armv6l". On ARMv7
  38. # machines, we normally get "armv7l". However, in Guix, we
  39. # configure with --build=arm-unknown-linux-gnueabihf, leading
  40. # to just "arm", so we also have to allow it.
  41. #
  42. # TODO: If not cross-compiling, add a sanity check to make
  43. # sure this build machine has the needed features to
  44. # support executables compiled using our armhf gcc,
  45. # configured with:
  46. # --with-arch=armv7-a
  47. # --with-float=hard
  48. # --with-mode=thumb
  49. # --with-fpu=vfpv3-d16
  50. machine_name="armhf";;
  51. *)
  52. machine_name="$host_cpu";;
  53. esac
  54. case "$host_os" in
  55. linux-gnu*)
  56. # For backward compatibility, strip the `-gnu' part.
  57. guix_system="$machine_name-linux";;
  58. linux-musl*)
  59. guix_system="$machine_name-linux";;
  60. gnu*)
  61. # Always use i586 for GNU/Hurd.
  62. guix_system="i586-gnu";;
  63. *)
  64. # Strip the version number from names such as `gnu0.3',
  65. # `darwin10.2.0', etc.
  66. guix_system="$machine_name-`echo $host_os | "$SED" -e's/[0-9.]*$//g'`";;
  67. esac])
  68. AC_MSG_CHECKING([for the Guix system type])
  69. AC_MSG_RESULT([$guix_system])
  70. AC_SUBST([guix_system])
  71. ])
  72. dnl GUIX_ASSERT_SUPPORTED_SYSTEM
  73. dnl
  74. dnl Assert that this is a system to which the distro is ported.
  75. AC_DEFUN([GUIX_ASSERT_SUPPORTED_SYSTEM], [
  76. AC_REQUIRE([GUIX_SYSTEM_TYPE])
  77. AC_ARG_WITH([courage], [AS_HELP_STRING([--with-courage],
  78. [Assert that even if this platform is unsupported, you will be
  79. courageous and port the GNU System distribution to it (see
  80. "GNU Distribution" in the manual.)])],
  81. [guix_courageous="$withval"],
  82. [guix_courageous="no"])
  83. # Currently only Linux-based systems are supported, and only on some
  84. # platforms.
  85. case "$guix_system" in
  86. x86_64-linux|i686-linux|armhf-linux|aarch64-linux|powerpc64le-linux|riscv64-linux|i586-gnu)
  87. ;;
  88. mips64el-linux|powerpc-linux)
  89. AC_MSG_WARN([building Guix on `$guix_system', which is not supported])
  90. ;;
  91. *)
  92. if test "x$guix_courageous" = "xyes"; then
  93. AC_MSG_WARN([building Guix on `$guix_system', which is not supported])
  94. else
  95. AC_MSG_ERROR([`$guix_system' is not a supported platform.
  96. See "GNU Distribution" in the manual, or try `--with-courage'.])
  97. fi
  98. ;;
  99. esac
  100. ])
  101. dnl GUIX_ASSERT_GUILE_FEATURES FEATURES
  102. dnl
  103. dnl Assert that FEATURES are provided by $GUILE.
  104. AC_DEFUN([GUIX_ASSERT_GUILE_FEATURES], [
  105. for guix_guile_feature in $1
  106. do
  107. AC_MSG_CHECKING([whether $GUILE provides feature '$guix_guile_feature'])
  108. if "$GUILE" -c "(exit (provided? '$guix_guile_feature))"
  109. then
  110. AC_MSG_RESULT([yes])
  111. else
  112. AC_MSG_RESULT([no])
  113. AC_MSG_ERROR([$GUILE does not support feature '$guix_guile_feature', which is required.])
  114. fi
  115. done
  116. ])
  117. dnl GUIX_CHECK_GUILE_SSH
  118. dnl
  119. dnl Check whether a recent-enough Guile-SSH is available.
  120. AC_DEFUN([GUIX_CHECK_GUILE_SSH], [
  121. dnl Check whether '#:nodelay' paramater to 'make-session' (introduced in
  122. dnl 0.13.0) is present.
  123. AC_CACHE_CHECK([whether Guile-SSH is available and recent enough],
  124. [guix_cv_have_recent_guile_ssh],
  125. [GUILE_CHECK([retval],
  126. [(and (@ (ssh channel) channel-send-eof)
  127. (@ (ssh popen) open-remote-pipe)
  128. (@ (ssh dist node) node-eval)
  129. (@ (ssh auth) userauth-gssapi!)
  130. ((@ (ssh session) make-session) #:nodelay #t))])
  131. if test "$retval" = 0; then
  132. guix_cv_have_recent_guile_ssh="yes"
  133. else
  134. guix_cv_have_recent_guile_ssh="no"
  135. fi])
  136. ])
  137. dnl GUIX_CHECK_GUILE_SQLITE3
  138. dnl
  139. dnl Check whether a recent-enough Guile-Sqlite3 is available.
  140. AC_DEFUN([GUIX_CHECK_GUILE_SQLITE3], [
  141. dnl Check whether 'sqlite-bind-arguments' is available. It was introduced
  142. dnl in February 2018:
  143. dnl <https://notabug.org/guile-sqlite3/guile-sqlite3/commit/1cd1dec96a9999db48c0ff45bab907efc637247f>.
  144. AC_CACHE_CHECK([whether Guile-Sqlite3 is available and recent enough],
  145. [guix_cv_have_recent_guile_sqlite3],
  146. [GUILE_CHECK([retval],
  147. [(@ (sqlite3) sqlite-bind-arguments)])
  148. if test "$retval" = 0; then
  149. guix_cv_have_recent_guile_sqlite3="yes"
  150. else
  151. guix_cv_have_recent_guile_sqlite3="no"
  152. fi])
  153. ])
  154. dnl GUIX_CHECK_GUILE_JSON
  155. dnl
  156. dnl Check whether a recent-enough Guile-JSON is available.
  157. AC_DEFUN([GUIX_CHECK_GUILE_JSON], [
  158. dnl Check whether we're using Guile-JSON 4.3+, which provides
  159. dnl 'define-json-mapping'.
  160. AC_CACHE_CHECK([whether Guile-JSON is available and recent enough],
  161. [guix_cv_have_recent_guile_json],
  162. [GUILE_CHECK([retval],
  163. [(use-modules (json))
  164. (define-json-mapping <frob> make-frob
  165. frob?
  166. json->frob
  167. (a frob-a)
  168. (b frob-b \"bee\"))
  169. (exit
  170. (equal? (json->frob
  171. (open-input-string \"{ \\\"a\\\": 1, \\\"bee\\\": 2 }\"))
  172. (make-frob 1 2)))])
  173. if test "$retval" = 0; then
  174. guix_cv_have_recent_guile_json="yes"
  175. else
  176. guix_cv_have_recent_guile_json="no"
  177. fi])
  178. ])
  179. dnl GUIX_CHECK_GUILE_GCRYPT
  180. dnl
  181. dnl Check whether a recent-enough Guile-Gcrypt is available.
  182. AC_DEFUN([GUIX_CHECK_GUILE_GCRYPT], [
  183. dnl Check whether we're using Guile-Gcrypt 0.2.x or later. 0.2.0
  184. dnl introduced the 'hash-algorithm' macro and related code.
  185. AC_CACHE_CHECK([whether Guile-Gcrypt is available and recent enough],
  186. [guix_cv_have_recent_guile_gcrypt],
  187. [GUILE_CHECK([retval],
  188. [(use-modules (gcrypt hash))
  189. (equal? (hash-algorithm sha256)
  190. (lookup-hash-algorithm 'sha256))])
  191. if test "$retval" = 0; then
  192. guix_cv_have_recent_guile_gcrypt="yes"
  193. else
  194. guix_cv_have_recent_guile_gcrypt="no"
  195. fi])
  196. ])
  197. dnl GUIX_CHECK_GUILE_GIT
  198. dnl
  199. dnl Check whether a recent-enough Guile-Git is available.
  200. AC_DEFUN([GUIX_CHECK_GUILE_GIT], [
  201. dnl Check whether we're using Guile-Git 0.3.0 or later. 0.3.0
  202. dnl introduced SSH authentication support and more.
  203. AC_CACHE_CHECK([whether Guile-Git is available and recent enough],
  204. [guix_cv_have_recent_guile_git],
  205. [GUILE_CHECK([retval],
  206. [(use-modules (git) (git auth) (git submodule))
  207. (let ((auth (%make-auth-ssh-agent)))
  208. repository-close!
  209. object-lookup-prefix
  210. (make-clone-options
  211. #:fetch-options (make-fetch-options auth)))])
  212. if test "$retval" = 0; then
  213. guix_cv_have_recent_guile_git="yes"
  214. else
  215. guix_cv_have_recent_guile_git="no"
  216. fi])
  217. ])
  218. dnl GUIX_CHECK_GUILE_ZLIB
  219. dnl
  220. dnl Check whether a recent-enough Guile-zlib is available.
  221. AC_DEFUN([GUIX_CHECK_GUILE_ZLIB], [
  222. dnl Check whether we're using Guile-zlib 0.1.0 or later.
  223. dnl 0.1.0 introduced the 'make-zlib-input-port' and related code.
  224. AC_CACHE_CHECK([whether Guile-zlib is available and recent enough],
  225. [guix_cv_have_recent_guile_zlib],
  226. [GUILE_CHECK([retval],
  227. [(use-modules (zlib))
  228. make-zlib-input-port])
  229. if test "$retval" = 0; then
  230. guix_cv_have_recent_guile_zlib="yes"
  231. else
  232. guix_cv_have_recent_guile_zlib="no"
  233. fi])
  234. ])
  235. dnl GUIX_TEST_ROOT_DIRECTORY
  236. AC_DEFUN([GUIX_TEST_ROOT_DIRECTORY], [
  237. AC_CACHE_CHECK([for unit test root directory],
  238. [ac_cv_guix_test_root],
  239. [ac_cv_guix_test_root="`pwd`/test-tmp"])
  240. ])
  241. dnl 'BINPRM_BUF_SIZE' constant in Linux (we leave room for the trailing zero.)
  242. dnl The Hurd has a limit of about a page (see exec/hashexec.c.)
  243. m4_define([LINUX_HASH_BANG_LIMIT], 127)
  244. dnl Hardcoded 'sun_path' length in <sys/un.h>.
  245. m4_define([SOCKET_FILE_NAME_LIMIT], 108)
  246. dnl GUIX_SOCKET_FILE_NAME_LENGTH
  247. AC_DEFUN([GUIX_SOCKET_FILE_NAME_LENGTH], [
  248. AC_CACHE_CHECK([the length of the installed socket file name],
  249. [ac_cv_guix_socket_file_name_length],
  250. [ac_cv_guix_socket_file_name_length="`echo -n "$guix_localstatedir/guix/daemon-socket/socket" | wc -c`"])
  251. ])
  252. dnl GUIX_TEST_SOCKET_FILE_NAME_LENGTH
  253. AC_DEFUN([GUIX_TEST_SOCKET_FILE_NAME_LENGTH], [
  254. AC_REQUIRE([GUIX_TEST_ROOT_DIRECTORY])
  255. AC_CACHE_CHECK([the length of the socket file name used in tests],
  256. [ac_cv_guix_test_socket_file_name_length],
  257. [ac_cv_guix_test_socket_file_name_length="`echo -n "$ac_cv_guix_test_root/var/123456/daemon-socket/socket" | wc -c`"])
  258. ])
  259. dnl GUIX_HASH_BANG_LENGTH
  260. AC_DEFUN([GUIX_HASH_BANG_LENGTH], [
  261. AC_CACHE_CHECK([the length of a typical hash bang line],
  262. [ac_cv_guix_hash_bang_length],
  263. [ac_cv_guix_hash_bang_length=`echo -n "$storedir/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa-bootstrap-binaries-0/bin/bash" | wc -c`])
  264. ])
  265. dnl GUIX_TEST_HASH_BANG_LENGTH
  266. AC_DEFUN([GUIX_TEST_HASH_BANG_LENGTH], [
  267. AC_REQUIRE([GUIX_TEST_ROOT_DIRECTORY])
  268. AC_CACHE_CHECK([the length of a hash bang line used in tests],
  269. [ac_cv_guix_test_hash_bang_length],
  270. [ac_cv_guix_test_hash_bang_length=`echo -n "$ac_cv_guix_test_root/store/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa-bootstrap-binaries-0/bin/bash" | wc -c`])
  271. ])
  272. dnl GUIX_CHECK_FILE_NAME_LIMITS
  273. dnl
  274. dnl GNU/Linux has a couple of silly limits that we can easily run into.
  275. dnl Make sure everything is fine with the current settings. Set $1 to
  276. dnl 'yes' if tests can run, 'no' otherwise.
  277. AC_DEFUN([GUIX_CHECK_FILE_NAME_LIMITS], [
  278. AC_REQUIRE([GUIX_SOCKET_FILE_NAME_LENGTH])
  279. AC_REQUIRE([GUIX_TEST_SOCKET_FILE_NAME_LENGTH])
  280. AC_REQUIRE([GUIX_HASH_BANG_LENGTH])
  281. AC_REQUIRE([GUIX_TEST_HASH_BANG_LENGTH])
  282. if test "$ac_cv_guix_socket_file_name_length" -ge ]SOCKET_FILE_NAME_LIMIT[; then
  283. AC_MSG_ERROR([socket file name would exceed the maxium allowed length])
  284. fi
  285. if test "$ac_cv_guix_test_socket_file_name_length" -ge ]SOCKET_FILE_NAME_LIMIT[; then
  286. AC_MSG_WARN([socket file name limit may be exceeded when running tests])
  287. fi
  288. $1=yes
  289. if test "$ac_cv_guix_hash_bang_length" -ge ]LINUX_HASH_BANG_LIMIT[; then
  290. $1=no
  291. AC_MSG_ERROR([store directory '$storedir' would lead to overly long hash-bang lines])
  292. fi
  293. if test "$ac_cv_guix_test_hash_bang_length" -ge ]LINUX_HASH_BANG_LIMIT[; then
  294. $1=no
  295. AC_MSG_WARN([test directory '$ac_cv_guix_test_root' may lead to overly long hash-bang lines])
  296. fi
  297. ])
  298. dnl GUIX_CHECK_CXX11
  299. dnl
  300. dnl Check whether the C++ compiler can compile a typical C++11 program.
  301. AC_DEFUN([GUIX_CHECK_CXX11], [
  302. AC_REQUIRE([AC_PROG_CXX])
  303. AC_CACHE_CHECK([whether $CXX supports C++11],
  304. [ac_cv_guix_cxx11_support],
  305. [save_CXXFLAGS="$CXXFLAGS"
  306. CXXFLAGS="-std=c++11 $CXXFLAGS"
  307. AC_COMPILE_IFELSE([
  308. AC_LANG_SOURCE([
  309. #include <functional>
  310. std::function<int(int)>
  311. return_plus_lambda (int x)
  312. {
  313. auto result = [[&]](int y) {
  314. return x + y;
  315. };
  316. return result;
  317. }
  318. ])],
  319. [ac_cv_guix_cxx11_support=yes],
  320. [ac_cv_guix_cxx11_support=no])
  321. CXXFLAGS="$save_CXXFLAGS"
  322. ])
  323. ])
  324. dnl GUIX_ASSERT_CXX11
  325. dnl
  326. dnl Error out if the C++ compiler cannot compile C++11 code.
  327. AC_DEFUN([GUIX_ASSERT_CXX11], [
  328. GUIX_CHECK_CXX11
  329. if test "x$ac_cv_guix_cxx11_support" != "xyes"; then
  330. AC_MSG_ERROR([C++ compiler '$CXX' does not support the C++11 standard])
  331. fi
  332. ])
  333. dnl GUIX_LIBGCRYPT_LIBDIR VAR
  334. dnl
  335. dnl Attempt to determine libgcrypt's LIBDIR; store the result in VAR.
  336. AC_DEFUN([GUIX_LIBGCRYPT_LIBDIR], [
  337. AC_PATH_PROG([LIBGCRYPT_CONFIG], [libgcrypt-config])
  338. AC_CACHE_CHECK([libgcrypt's library directory],
  339. [guix_cv_libgcrypt_libdir],
  340. [if test "x$LIBGCRYPT_CONFIG" != "x"; then
  341. guix_cv_libgcrypt_libdir=`$LIBGCRYPT_CONFIG --libs | grep -e -L | sed -e "s/.*-L\([[^ ]]\+\)[[[:blank:]]]\+-lgcrypt.*/\1/g"`
  342. else
  343. guix_cv_libgcrypt_libdir=""
  344. fi])
  345. $1="$guix_cv_libgcrypt_libdir"
  346. ])
  347. dnl GUIX_CURRENT_LOCALSTATEDIR
  348. dnl
  349. dnl Determine the localstatedir of an existing Guix installation and set
  350. dnl 'guix_cv_current_localstatedir' accordingly. Set it to "none" if no
  351. dnl existing installation was found.
  352. AC_DEFUN([GUIX_CURRENT_LOCALSTATEDIR], [
  353. AC_PATH_PROG([GUILE], [guile])
  354. AC_CACHE_CHECK([the current installation's localstatedir],
  355. [guix_cv_current_localstatedir],
  356. [dnl Call 'dirname' because (guix config) appends "/guix" to LOCALSTATEDIR.
  357. guix_cv_current_localstatedir="`"$GUILE" \
  358. -c '(use-modules (guix config))
  359. (when (string=? %store-directory "'$storedir'")
  360. (display (dirname %state-directory)))' \
  361. 2>/dev/null`"
  362. if test "x$guix_cv_current_localstatedir" = "x"; then
  363. guix_cv_current_localstatedir=none
  364. fi])])
  365. dnl GUIX_CHECK_LOCALSTATEDIR
  366. dnl
  367. dnl Check that the LOCALSTATEDIR value is consistent with that of the existing
  368. dnl Guix installation, if any. Error out or warn if they do not match.
  369. AC_DEFUN([GUIX_CHECK_LOCALSTATEDIR], [
  370. AC_REQUIRE([GUIX_CURRENT_LOCALSTATEDIR])
  371. if test "x$guix_cv_current_localstatedir" != "xnone"; then
  372. if test "$guix_cv_current_localstatedir" != "$guix_localstatedir"; then
  373. case "$localstatedir" in
  374. NONE|\${prefix}*)
  375. # User kept the default value---i.e., did not pass '--localstatedir'.
  376. AC_MSG_ERROR([chosen localstatedir '$guix_localstatedir' does not match \
  377. that of the existing installation '$guix_cv_current_localstatedir'
  378. Installing may corrupt $storedir!
  379. Use './configure --localstatedir=$guix_cv_current_localstatedir'.])
  380. ;;
  381. *)
  382. # User passed an explicit '--localstatedir'. Assume they know what
  383. # they're doing.
  384. AC_MSG_WARN([chosen localstatedir '$guix_localstatedir' does not match \
  385. that of the existing installation '$guix_cv_current_localstatedir'])
  386. AC_MSG_WARN([installing may corrupt $storedir!])
  387. ;;
  388. esac
  389. fi
  390. fi])
  391. dnl GUIX_CHANNEL_METADATA
  392. dnl
  393. dnl Provide the channel metadata for this build. This allows 'guix describe'
  394. dnl to return meaningful data, as it would for a 'guix pull'-provided 'guix'.
  395. dnl The default URL and introduction are taken from (guix channels).
  396. AC_DEFUN([GUIX_CHANNEL_METADATA], [
  397. AC_ARG_WITH([channel-url], [AS_HELP_STRING([--with-channel-url=URL],
  398. [assert that this is built from the Git repository at URL])],
  399. [guix_channel_url="\"$withval\""],
  400. [guix_channel_url="\"https://git.savannah.gnu.org/git/guix.git\""])
  401. AC_ARG_WITH([channel-commit], [AS_HELP_STRING([--with-channel-commit=COMMIT],
  402. [assert that this is built from COMMIT])],
  403. [guix_channel_commit="\"$withval\""],
  404. [guix_channel_commit="#f"])
  405. AC_ARG_WITH([channel-introduction], [AS_HELP_STRING([--with-channel-introduction=COMMIT:FINGERPRINT],
  406. [specify COMMIT and FINGERPRINT as the introduction of this channel])],
  407. [guix_channel_introduction="'(\"`echo $withval | cut -f1 -d:`\" \"`echo $withval | cut -f2 -d:`\")"],
  408. [guix_channel_introduction="'(\"9edb3f66fd807b096b48283debdcddccfea34bad\" . \"BBB0 2DDF 2CEA F6A8 0D1D E643 A2A0 6DF2 A33A 54FA\")"])
  409. GUIX_CHANNEL_URL="$guix_channel_url"
  410. GUIX_CHANNEL_COMMIT="$guix_channel_commit"
  411. GUIX_CHANNEL_INTRODUCTION="$guix_channel_introduction"
  412. AC_SUBST([GUIX_CHANNEL_URL])
  413. AC_SUBST([GUIX_CHANNEL_COMMIT])
  414. AC_SUBST([GUIX_CHANNEL_INTRODUCTION])
  415. ])