rpath.scm 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2013 Ludovic Courtès <ludo@gnu.org>
  3. ;;;
  4. ;;; This file is part of GNU Guix.
  5. ;;;
  6. ;;; GNU Guix is free software; you can redistribute it and/or modify it
  7. ;;; under the terms of the GNU General Public License as published by
  8. ;;; the Free Software Foundation; either version 3 of the License, or (at
  9. ;;; your option) any later version.
  10. ;;;
  11. ;;; GNU Guix is distributed in the hope that it will be useful, but
  12. ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
  13. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. ;;; GNU General Public License for more details.
  15. ;;;
  16. ;;; You should have received a copy of the GNU General Public License
  17. ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
  18. (define-module (guix build rpath)
  19. #:use-module (ice-9 popen)
  20. #:use-module (ice-9 rdelim)
  21. #:export (%patchelf
  22. file-rpath
  23. augment-rpath))
  24. ;;; Commentary:
  25. ;;;
  26. ;;; Tools to manipulate the RPATH and RUNPATH of ELF binaries. Currently they
  27. ;;; rely on PatchELF.
  28. ;;;
  29. ;;; Code:
  30. (define %patchelf
  31. ;; The `patchelf' command.
  32. (make-parameter "patchelf"))
  33. (define %not-colon
  34. (char-set-complement (char-set #\:)))
  35. (define (file-rpath file)
  36. "Return the RPATH (or RUNPATH) of FILE as a list of directory names, or #f
  37. on failure."
  38. (let* ((p (open-pipe* OPEN_READ (%patchelf) "--print-rpath" file))
  39. (l (read-line p)))
  40. (and (zero? (close-pipe p))
  41. (string-tokenize l %not-colon))))
  42. (define (augment-rpath file dir)
  43. "Add DIR to the front of the RPATH and RUNPATH of FILE. Return the new
  44. RPATH as a list, or #f on failure."
  45. (let* ((rpath (or (file-rpath file) '()))
  46. (rpath* (cons dir rpath)))
  47. (format #t "~a: changing RPATH from ~s to ~s~%"
  48. file rpath rpath*)
  49. (and (zero? (system* (%patchelf) "--set-rpath"
  50. (string-join rpath* ":") file))
  51. rpath*)))
  52. ;;; rpath.scm ends here