copy.scm 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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. ;;; Copyright © 2021 Ludovic Courtès <ludo@gnu.org>
  5. ;;;
  6. ;;; This file is part of GNU Guix.
  7. ;;;
  8. ;;; GNU Guix is free software; you can redistribute it and/or modify it
  9. ;;; under the terms of the GNU General Public License as published by
  10. ;;; the Free Software Foundation; either version 3 of the License, or (at
  11. ;;; your option) any later version.
  12. ;;;
  13. ;;; GNU Guix is distributed in the hope that it will be useful, but
  14. ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
  15. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. ;;; GNU General Public License for more details.
  17. ;;;
  18. ;;; You should have received a copy of the GNU General Public License
  19. ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
  20. (define-module (guix build-system copy)
  21. #:use-module (guix store)
  22. #:use-module (guix utils)
  23. #:use-module (guix gexp)
  24. #:use-module (guix monads)
  25. #:use-module (guix search-paths)
  26. #:use-module (guix build-system)
  27. #:use-module (guix build-system gnu)
  28. #:use-module (guix packages)
  29. #:use-module (ice-9 match)
  30. #:use-module (srfi srfi-1)
  31. #:export (%copy-build-system-modules
  32. default-glibc
  33. lower
  34. copy-build
  35. copy-build-system))
  36. ;; Commentary:
  37. ;;
  38. ;; Standard build procedure for simple packages that don't require much
  39. ;; compilation, mostly just copying files around. This is implemented as an
  40. ;; extension of `gnu-build-system'.
  41. ;;
  42. ;; Code:
  43. (define %copy-build-system-modules
  44. ;; Build-side modules imported by default.
  45. `((guix build copy-build-system)
  46. ,@%gnu-build-system-modules))
  47. (define (default-glibc)
  48. "Return the default glibc package."
  49. ;; Do not use `@' to avoid introducing circular dependencies.
  50. (let ((module (resolve-interface '(gnu packages base))))
  51. (module-ref module 'glibc)))
  52. (define* (lower name
  53. #:key source inputs native-inputs outputs system target
  54. (glibc (default-glibc))
  55. #:allow-other-keys
  56. #:rest arguments)
  57. "Return a bag for NAME from the given arguments."
  58. (define private-keywords
  59. '(#:target #:inputs #:native-inputs))
  60. (bag
  61. (name name)
  62. (system system)
  63. (host-inputs `(,@(if source
  64. `(("source" ,source))
  65. '())
  66. ,@inputs
  67. ;; Keep the standard inputs of 'gnu-build-system'.
  68. ,@(standard-packages)))
  69. (build-inputs native-inputs)
  70. (outputs outputs)
  71. (build copy-build)
  72. (arguments (strip-keyword-arguments private-keywords arguments))))
  73. (define* (copy-build name inputs
  74. #:key
  75. guile source
  76. (outputs '("out"))
  77. (install-plan ''(("." "./")))
  78. (search-paths '())
  79. (out-of-source? #t)
  80. (validate-runpath? #t)
  81. (patch-shebangs? #t)
  82. (strip-binaries? #t)
  83. (strip-flags ''("--strip-debug"))
  84. (strip-directories ''("lib" "lib64" "libexec"
  85. "bin" "sbin"))
  86. (phases '(@ (guix build copy-build-system)
  87. %standard-phases))
  88. (system (%current-system))
  89. (target #f)
  90. (imported-modules %copy-build-system-modules)
  91. (modules '((guix build copy-build-system)
  92. (guix build utils))))
  93. "Build SOURCE using INSTALL-PLAN, and with INPUTS."
  94. (define builder
  95. (with-imported-modules imported-modules
  96. #~(begin
  97. (use-modules #$@modules)
  98. #$(with-build-variables inputs outputs
  99. #~(copy-build #:source #+source
  100. #:system #$system
  101. #:outputs %outputs
  102. #:inputs %build-inputs
  103. #:install-plan #$(if (pair? install-plan)
  104. (sexp->gexp install-plan)
  105. install-plan)
  106. #:search-paths '#$(sexp->gexp
  107. (map search-path-specification->sexp
  108. search-paths))
  109. #:phases #$(if (pair? phases)
  110. (sexp->gexp phases)
  111. phases)
  112. #:out-of-source? #$out-of-source?
  113. #:validate-runpath? #$validate-runpath?
  114. #:patch-shebangs? #$patch-shebangs?
  115. #:strip-binaries? #$strip-binaries?
  116. #:strip-flags #$(sexp->gexp strip-flags)
  117. #:strip-directories #$(sexp->gexp strip-directories))))))
  118. (mlet %store-monad ((guile (package->derivation (or guile (default-guile))
  119. system #:graft? #f)))
  120. (gexp->derivation name builder
  121. #:system system
  122. #:target #f
  123. #:guile-for-build guile)))
  124. (define copy-build-system
  125. (build-system
  126. (name 'copy)
  127. (description "The standard copy build system")
  128. (lower lower)))
  129. ;;; copy.scm ends here