gnu-dist.scm 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2013, 2015 Ludovic Courtès <ludo@gnu.org>
  3. ;;; Copyright © 2018 Mark H Weaver <mhw@netris.org>
  4. ;;;
  5. ;;; This file is part of GNU Guix.
  6. ;;;
  7. ;;; GNU Guix is free software; you can redistribute it and/or modify it
  8. ;;; under the terms of the GNU General Public License as published by
  9. ;;; the Free Software Foundation; either version 3 of the License, or (at
  10. ;;; your option) any later version.
  11. ;;;
  12. ;;; GNU Guix is distributed in the hope that it will be useful, but
  13. ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
  14. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. ;;; GNU General Public License for more details.
  16. ;;;
  17. ;;; You should have received a copy of the GNU General Public License
  18. ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
  19. (define-module (guix build gnu-dist)
  20. #:use-module (guix build utils)
  21. #:use-module (guix build gnu-build-system)
  22. #:use-module (srfi srfi-1)
  23. #:export (%dist-phases))
  24. ;;; Commentary:
  25. ;;;
  26. ;;; Build phases to build a source tarball with the GNU build system, as with
  27. ;;; "make distcheck".
  28. ;;;
  29. ;;; Code:
  30. (define* (copy-source #:key source #:allow-other-keys)
  31. (copy-recursively source "."))
  32. (define* (autoreconf #:rest args)
  33. (letrec-syntax ((try-files (syntax-rules (else)
  34. ((_ (else fallback ...))
  35. (begin fallback ...))
  36. ((_ file files ... (else fallback ...))
  37. (if (file-exists? file)
  38. (begin
  39. (format #t "bootstrapping with `~a'...~%"
  40. file)
  41. (invoke (string-append "./" file)))
  42. (try-files files ...
  43. (else fallback ...)))))))
  44. (try-files "bootstrap" "bootstrap.sh" "autogen" "autogen.sh"
  45. (else
  46. (format #t "bootstrapping with `autoreconf'...~%")
  47. (invoke "autoreconf" "-vfi")))))
  48. (define* (build #:key build-before-dist? make-flags (dist-target "distcheck")
  49. #:allow-other-keys
  50. #:rest args)
  51. (when build-before-dist?
  52. (let ((build (assq-ref %standard-phases 'build)))
  53. (apply build args)))
  54. (format #t "building target `~a'~%" dist-target)
  55. (apply invoke "make" dist-target make-flags))
  56. (define* (install-dist #:key outputs #:allow-other-keys)
  57. (let* ((out (assoc-ref outputs "out"))
  58. (meta (string-append out "/nix-support")) ; Hydra meta-data
  59. (tarballs (find-files "." "\\.tar\\.")))
  60. (mkdir out)
  61. (for-each (lambda (tarball)
  62. (copy-file tarball (string-append out "/" tarball)))
  63. out)
  64. (mkdir meta)
  65. (call-with-output-file (string-append out "/hydra-build-products")
  66. (lambda (port)
  67. (for-each (lambda (tarball)
  68. ;; This tells Hydra's what kind of build products we have,
  69. ;; so it can represent them nicely. See `product-list.tt'
  70. ;; in Hydra for details.
  71. (format port "file source-dist ~a/~a~%" out tarball))
  72. tarballs)))
  73. #t))
  74. (define %dist-phases
  75. ;; Phases for building a source tarball.
  76. (modify-phases %standard-phases
  77. (delete 'strip)
  78. (replace 'install install-dist)
  79. (replace 'build build)
  80. (add-before 'configure 'autoreconf autoreconf)
  81. (replace 'unpack copy-source)))
  82. ;;; gnu-dist.scm ends here