guix.m4 16 KB

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