copy.scm 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2019 Julien Lepiller <julien@lepiller.eu>
  3. ;;; Copyright © 2020 Pierre Neidhardt <mail@ambrevar.xyz>
  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-system copy)
  20. #:use-module (guix store)
  21. #:use-module (guix utils)
  22. #:use-module (guix derivations)
  23. #:use-module (guix search-paths)
  24. #:use-module (guix build-system)
  25. #:use-module (guix build-system gnu)
  26. #:use-module (guix packages)
  27. #:use-module (ice-9 match)
  28. #:use-module (srfi srfi-1)
  29. #:export (%copy-build-system-modules
  30. default-glibc
  31. lower
  32. copy-build
  33. copy-build-system))
  34. ;; Commentary:
  35. ;;
  36. ;; Standard build procedure for simple packages that don't require much
  37. ;; compilation, mostly just copying files around. This is implemented as an
  38. ;; extension of `gnu-build-system'.
  39. ;;
  40. ;; Code:
  41. (define %copy-build-system-modules
  42. ;; Build-side modules imported by default.
  43. `((guix build copy-build-system)
  44. ,@%gnu-build-system-modules))
  45. (define (default-glibc)
  46. "Return the default glibc package."
  47. ;; Do not use `@' to avoid introducing circular dependencies.
  48. (let ((module (resolve-interface '(gnu packages base))))
  49. (module-ref module 'glibc)))
  50. (define* (lower name
  51. #:key source inputs native-inputs outputs system target
  52. (glibc (default-glibc))
  53. #:allow-other-keys
  54. #:rest arguments)
  55. "Return a bag for NAME from the given arguments."
  56. (define private-keywords
  57. '(#:source #:target #:inputs #:native-inputs))
  58. (bag
  59. (name name)
  60. (system system)
  61. (host-inputs `(,@(if source
  62. `(("source" ,source))
  63. '())
  64. ,@inputs
  65. ;; Keep the standard inputs of 'gnu-build-system'.
  66. ,@(standard-packages)))
  67. (build-inputs native-inputs)
  68. (outputs outputs)
  69. (build copy-build)
  70. (arguments (strip-keyword-arguments private-keywords arguments))))
  71. (define* (copy-build store name inputs
  72. #:key (guile #f)
  73. (outputs '("out"))
  74. (install-plan ''(("." "./")))
  75. (search-paths '())
  76. (out-of-source? #t)
  77. (validate-runpath? #t)
  78. (patch-shebangs? #t)
  79. (strip-binaries? #t)
  80. (strip-flags ''("--strip-debug"))
  81. (strip-directories ''("lib" "lib64" "libexec"
  82. "bin" "sbin"))
  83. (phases '(@ (guix build copy-build-system)
  84. %standard-phases))
  85. (system (%current-system))
  86. (imported-modules %copy-build-system-modules)
  87. (modules '((guix build copy-build-system)
  88. (guix build utils))))
  89. "Build SOURCE using INSTALL-PLAN, and with INPUTS."
  90. (define builder
  91. `(begin
  92. (use-modules ,@modules)
  93. (copy-build #:source ,(match (assoc-ref inputs "source")
  94. (((? derivation? source))
  95. (derivation->output-path source))
  96. ((source)
  97. source)
  98. (source
  99. source))
  100. #:system ,system
  101. #:outputs %outputs
  102. #:inputs %build-inputs
  103. #:install-plan ,install-plan
  104. #:search-paths ',(map search-path-specification->sexp
  105. search-paths)
  106. #:phases ,phases
  107. #:out-of-source? ,out-of-source?
  108. #:validate-runpath? ,validate-runpath?
  109. #:patch-shebangs? ,patch-shebangs?
  110. #:strip-binaries? ,strip-binaries?
  111. #:strip-flags ,strip-flags
  112. #:strip-directories ,strip-directories)))
  113. (define guile-for-build
  114. (match guile
  115. ((? package?)
  116. (package-derivation store guile system #:graft? #f))
  117. (#f ; the default
  118. (let* ((distro (resolve-interface '(gnu packages commencement)))
  119. (guile (module-ref distro 'guile-final)))
  120. (package-derivation store guile system #:graft? #f)))))
  121. (build-expression->derivation store name builder
  122. #:system system
  123. #:inputs inputs
  124. #:modules imported-modules
  125. #:outputs outputs
  126. #:guile-for-build guile-for-build))
  127. (define copy-build-system
  128. (build-system
  129. (name 'copy)
  130. (description "The standard copy build system")
  131. (lower lower)))
  132. ;;; copy.scm ends here