From d388c2c435395aee61dc074023b1f218e6037545 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludovic=20Court=C3=A8s?= Date: Sat, 3 Nov 2012 21:43:30 +0100 Subject: [PATCH] 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)'. --- Makefile.am | 1 + README | 2 +- configure.ac | 6 +++++ guix/utils.scm | 59 ++++++++------------------------------------------ m4/guix.m4 | 35 ++++++++++++++++++++++++++++++ 5 files changed, 52 insertions(+), 51 deletions(-) create mode 100644 m4/guix.m4 diff --git a/Makefile.am b/Makefile.am index b06f575e6c..24fc22e2d3 100644 --- a/Makefile.am +++ b/Makefile.am @@ -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)" diff --git a/README b/README index 5be253bd49..02c1f34e2e 100644 --- a/README +++ b/README @@ -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; diff --git a/configure.ac b/configure.ac index 6d3d1482b4..cd07a54a3d 100644 --- a/configure.ac +++ b/configure.ac @@ -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 diff --git a/guix/utils.scm b/guix/utils.scm index 10b0c15fad..345ed374cd 100644 --- a/guix/utils.scm +++ b/guix/utils.scm @@ -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)))) ;;; diff --git a/m4/guix.m4 b/m4/guix.m4 new file mode 100644 index 0000000000..29f928f653 --- /dev/null +++ b/m4/guix.m4 @@ -0,0 +1,35 @@ +dnl Guix --- Nix package management from Guile. -*- coding: utf-8 -*- +dnl Copyright (C) 2012 Ludovic Courtès +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 . + +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])