build: Require GNU libgcrypt.

* guix/utils.scm (sha256): Remove Coreutils- and libchop-based
  implementations.
* README: Update accordingly.

* m4/guix.m4: New file.
* configure.ac: Use `GUIX_ASSERT_LIBGCRYPT_USABLE'.  Set and substitute
  `LIBGCRYPT_PREFIX'.
* Makefile.am (AM_DISTCHECK_CONFIGURE_FLAGS): Pass
  `--with-libgcrypt-prefix=$(LIBGCRYPT_PREFIX)'.
This commit is contained in:
Ludovic Courtès 2012-11-03 21:43:30 +01:00
parent 1275baeba7
commit d388c2c435
5 changed files with 52 additions and 51 deletions

View File

@ -172,4 +172,5 @@ EXTRA_DIST += doc/fdl-1.3.texi
ACLOCAL_AMFLAGS = -I m4
AM_DISTCHECK_CONFIGURE_FLAGS = \
--with-libgcrypt-prefix="$(LIBGCRYPT_PREFIX)" \
--with-nix-prefix="$(NIX_PREFIX)"

2
README
View File

@ -17,7 +17,7 @@ Guix currently depends on the following packages:
- [[http://gnu.org/software/guile/][GNU Guile 2.0.x]]
- [[http://nixos.org/nix/][Nix]]
- [[http://gnupg.org/][GNU libgcrypt]], or [[http://nongnu.org/libchop/][libchop]]
- [[http://gnupg.org/][GNU libgcrypt]]
Optionally, packages from Nixpkgs may be transparently reused from Guix.
For this to work, you need to have a checkout of the Nixpkgs repository;

View File

@ -65,9 +65,11 @@ AC_ARG_WITH([libgcrypt-prefix],
[case "$withval" in
yes|no)
LIBGCRYPT="libgcrypt"
LIBGCRYPT_PREFIX="no"
;;
*)
LIBGCRYPT="$withval/lib/libgcrypt"
LIBGCRYPT_PREFIX="$withval"
;;
esac],
[LIBGCRYPT="libgcrypt"])
@ -76,6 +78,10 @@ dnl Library name suitable for `dynamic-link'.
AC_MSG_CHECKING([for libgcrypt shared library name])
AC_MSG_RESULT([$LIBGCRYPT])
AC_SUBST([LIBGCRYPT])
AC_SUBST([LIBGCRYPT_PREFIX])
GUIX_ASSERT_LIBGCRYPT_USABLE
AC_CONFIG_FILES([Makefile
po/Makefile.in

View File

@ -394,58 +394,17 @@ starting from the right of S."
;;;
(define sha256
(cond
((compile-time-value
(false-if-exception (dynamic-link %libgcrypt)))
;; Using libgcrypt.
(let ((hash (pointer->procedure void
(dynamic-func "gcry_md_hash_buffer"
(dynamic-link %libgcrypt))
`(,int * * ,size_t)))
(sha256 8)) ; GCRY_MD_SHA256, as of 1.5.0
(lambda (bv)
"Return the SHA256 of BV as a bytevector."
(let ((digest (make-bytevector (/ 256 8))))
(hash sha256 (bytevector->pointer digest)
(bytevector->pointer bv) (bytevector-length bv))
digest))))
((compile-time-value
(false-if-exception (resolve-interface '(chop hash))))
;; Using libchop.
(let ((bytevector-hash (@ (chop hash) bytevector-hash))
(hash-method/sha256 (@ (chop hash) hash-method/sha256)))
(lambda (bv)
"Return the SHA256 of BV as a bytevector."
(bytevector-hash hash-method/sha256 bv))))
(else
;; Slow, poor programmer's implementation that uses Coreutils.
(let ((hash (pointer->procedure void
(dynamic-func "gcry_md_hash_buffer"
(dynamic-link %libgcrypt))
`(,int * * ,size_t)))
(sha256 8)) ; GCRY_MD_SHA256, as of 1.5.0
(lambda (bv)
"Return the SHA256 of BV as a bytevector."
(let ((in (pipe))
(out (pipe))
(pid (primitive-fork)))
(if (= 0 pid)
(begin ; child
(close (cdr in))
(close (car out))
(close 0)
(close 1)
(dup2 (fileno (car in)) 0)
(dup2 (fileno (cdr out)) 1)
(execlp "sha256sum" "sha256sum"))
(begin ; parent
(close (car in))
(close (cdr out))
(put-bytevector (cdr in) bv)
(close (cdr in)) ; EOF
(let ((line (car (string-tokenize (read-line (car out))))))
(close (car out))
(and (and=> (status:exit-val (cdr (waitpid pid)))
zero?)
(base16-string->bytevector line))))))))))
(let ((digest (make-bytevector (/ 256 8))))
(hash sha256 (bytevector->pointer digest)
(bytevector->pointer bv) (bytevector-length bv))
digest))))
;;;

35
m4/guix.m4 Normal file
View File

@ -0,0 +1,35 @@
dnl Guix --- Nix package management from Guile. -*- coding: utf-8 -*-
dnl Copyright (C) 2012 Ludovic Courtès <ludo@gnu.org>
dnl
dnl This file is part of Guix.
dnl
dnl Guix is free software; you can redistribute it and/or modify it
dnl under the terms of the GNU General Public License as published by
dnl the Free Software Foundation; either version 3 of the License, or (at
dnl your option) any later version.
dnl
dnl Guix is distributed in the hope that it will be useful, but
dnl WITHOUT ANY WARRANTY; without even the implied warranty of
dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
dnl GNU General Public License for more details.
dnl
dnl You should have received a copy of the GNU General Public License
dnl along with Guix. If not, see <http://www.gnu.org/licenses/>.
dnl GUIX_ASSERT_LIBGCRYPT_USABLE
dnl
dnl Assert that GNU libgcrypt is usable from Guile.
AC_DEFUN([GUIX_ASSERT_LIBGCRYPT_USABLE],
[AC_CACHE_CHECK([whether $LIBGCRYPT can be dynamically loaded],
[guix_cv_libgcrypt_usable_p],
[GUILE_CHECK([retval],
[(dynamic-func \"gcry_md_hash_buffer\" (dynamic-link \"$LIBGCRYPT\"))])
if test "$retval" = 0; then
guix_cv_libgcrypt_usable_p="yes"
else
guix_cv_libgcrypt_usable_p="no"
fi])
if test "x$guix_cv_libgcrypt_usable_p" != "xyes"; then
AC_MSG_ERROR([GNU libgcrypt does not appear to be usable; see `--with-libgcrypt-prefix' and `README'.])
fi])