From fd982732f45c7f5e8adb025d11d106d2192d6723 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludovic=20Court=C3=A8s?= Date: Wed, 8 May 2013 01:50:21 +0200 Subject: [PATCH] gnu: python: Build the shared library. * gnu/packages/python.scm (python): Add `--enable-shared'. Add #:modules and #:phases. Add PatchELF as an input. --- gnu/packages/python.scm | 47 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 44 insertions(+), 3 deletions(-) diff --git a/gnu/packages/python.scm b/gnu/packages/python.scm index 4dff1b4475..23d18909a3 100644 --- a/gnu/packages/python.scm +++ b/gnu/packages/python.scm @@ -24,6 +24,7 @@ #:use-module (gnu packages gdbm) #:use-module (gnu packages readline) #:use-module (gnu packages openssl) + #:use-module (gnu packages patchelf) #:use-module (guix packages) #:use-module (guix download) #:use-module (guix build-system gnu)) @@ -49,7 +50,8 @@ (openssl (assoc-ref %build-inputs "openssl")) (readline (assoc-ref %build-inputs "readline")) (zlib (assoc-ref %build-inputs "zlib"))) - (list (string-append "CPPFLAGS=" + (list "--enable-shared" ; allow embedding + (string-append "CPPFLAGS=" "-I" bz2 "/include " "-I" gdbm "/include " "-I" openssl "/include " @@ -60,13 +62,52 @@ "-L" gdbm "/lib " "-L" openssl "/lib " "-L" readline "/lib " - "-L" zlib "/lib"))))) + "-L" zlib "/lib"))) + + #:modules ((guix build gnu-build-system) + (guix build utils) + (ice-9 popen) + (ice-9 rdelim) + (srfi srfi-26)) + + #:phases + (alist-cons-after + 'strip 'add-lib-to-runpath + (lambda* (#:key outputs #:allow-other-keys) + ;; XXX: copied from Samba; TODO: factorize in a module + + (define (file-rpath file) + ;; Return the RPATH of FILE. + (let* ((p (open-pipe* OPEN_READ "patchelf" + "--print-rpath" file)) + (l (read-line p))) + (and (zero? (close-pipe p)) l))) + + (define (augment-rpath file dir) + ;; Add DIR to the RPATH of FILE. + (let* ((rpath (file-rpath file)) + (rpath* (if rpath + (string-append dir ":" rpath) + dir))) + (format #t "~a: changing RPATH from `~a' to `~a'~%" + file (or rpath "") rpath*) + (zero? (system* "patchelf" "--set-rpath" + rpath* file)))) + + (let* ((out (assoc-ref outputs "out")) + (lib (string-append out "/lib"))) + ;; Add LIB to the RUNPATH of all the executables. + (with-directory-excursion out + (for-each (cut augment-rpath <> lib) + (find-files "bin" ".*"))))) + %standard-phases))) (inputs `(("bzip2" ,bzip2) ("gdbm" ,gdbm) ("openssl" ,openssl) ("readline" ,readline) - ("zlib" ,zlib))) + ("zlib" ,zlib) + ("patchelf" ,patchelf))) (native-search-paths (list (search-path-specification (variable "PYTHONPATH")