guix.m4 16 KB

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