perl.scm 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2013, 2014, 2015, 2021 Ludovic Courtès <ludo@gnu.org>
  3. ;;; Copyright © 2022 Maxime Devos <maximedevos@telenet.be>
  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 perl)
  20. #:use-module (guix store)
  21. #:use-module (guix utils)
  22. #:use-module (guix gexp)
  23. #:use-module (guix monads)
  24. #:use-module (guix search-paths)
  25. #:use-module (guix build-system)
  26. #:use-module (guix build-system gnu)
  27. #:use-module (guix packages)
  28. #:export (%perl-build-system-modules
  29. perl-build
  30. perl-cross-build
  31. perl-build-system))
  32. ;; Commentary:
  33. ;;
  34. ;; Standard build procedure for Perl packages using the "makefile
  35. ;; maker"---i.e., "perl Makefile.PL". This is implemented as an extension of
  36. ;; `gnu-build-system'. Cross-compilation is supported for some simple Perl
  37. ;; packages, but not for any Perl packages that do things like XS (Perl's FFI),
  38. ;; which makes C-style shared libraries, as it is currently not known how to
  39. ;; tell Perl to properly cross-compile.
  40. ;;
  41. ;; Code:
  42. (define %perl-build-system-modules
  43. ;; Build-side modules imported by default.
  44. `((guix build perl-build-system)
  45. ,@%gnu-build-system-modules))
  46. (define (default-perl)
  47. "Return the default Perl package."
  48. ;; Do not use `@' to avoid introducing circular dependencies.
  49. (let ((module (resolve-interface '(gnu packages perl))))
  50. (module-ref module 'perl)))
  51. (define* (lower name
  52. #:key source inputs native-inputs outputs
  53. system target
  54. (perl (default-perl))
  55. #:allow-other-keys
  56. #:rest arguments)
  57. "Return a bag for NAME."
  58. (define private-keywords
  59. `(#:perl #:inputs #:native-inputs
  60. ,@(if target '() '(#:target))))
  61. (bag
  62. (name name)
  63. (system system) (target target)
  64. (host-inputs `(,@(if source
  65. `(("source" ,source))
  66. '())
  67. ,@inputs
  68. ;; For interpreters in #! (shebang)
  69. ,@(if target
  70. `(("perl" ,perl))
  71. '())
  72. ;; Keep the standard inputs of 'gnu-build-system'.
  73. ;; TODO: make this unconditional, putting this into
  74. ;; 'build-inputs'.
  75. ,@(if target
  76. '()
  77. (standard-packages))))
  78. (build-inputs `(("perl" ,perl)
  79. ,@native-inputs
  80. ,@(if target
  81. (standard-cross-packages target 'host)
  82. '())
  83. ,@(if target
  84. (standard-packages)
  85. '())))
  86. ;; Keep the standard inputs of 'gnu-build-system'.
  87. (target-inputs (if target
  88. (standard-cross-packages target 'target)
  89. '()))
  90. (outputs outputs)
  91. (build (if target
  92. perl-cross-build
  93. perl-build))
  94. (arguments (strip-keyword-arguments private-keywords arguments))))
  95. (define* (perl-build name inputs
  96. #:key source
  97. (search-paths '())
  98. (tests? #t)
  99. (parallel-build? #t)
  100. (parallel-tests? #t)
  101. (make-maker? #f)
  102. (make-maker-flags ''())
  103. (module-build-flags ''())
  104. (phases '(@ (guix build perl-build-system)
  105. %standard-phases))
  106. (outputs '("out"))
  107. (system (%current-system))
  108. (guile #f)
  109. (imported-modules %perl-build-system-modules)
  110. (modules '((guix build perl-build-system)
  111. (guix build utils))))
  112. "Build SOURCE using PERL, and with INPUTS. This assumes that SOURCE
  113. provides a `Makefile.PL' file as its build system."
  114. (define build
  115. (with-imported-modules imported-modules
  116. #~(begin
  117. (use-modules #$@(sexp->gexp modules))
  118. #$(with-build-variables inputs outputs
  119. #~(perl-build #:name #$name
  120. #:source #+source
  121. #:search-paths '#$(sexp->gexp
  122. (map search-path-specification->sexp
  123. search-paths))
  124. #:make-maker? #$make-maker?
  125. #:make-maker-flags #$make-maker-flags
  126. #:module-build-flags #$(sexp->gexp module-build-flags)
  127. #:phases #$(if (pair? phases)
  128. (sexp->gexp phases)
  129. phases)
  130. #:system #$system
  131. #:test-target "test"
  132. #:tests? #$tests?
  133. #:parallel-build? #$parallel-build?
  134. #:parallel-tests? #$parallel-tests?
  135. #:outputs %outputs
  136. #:inputs %build-inputs)))))
  137. (mlet %store-monad ((guile (package->derivation (or guile (default-guile))
  138. system #:graft? #f)))
  139. (gexp->derivation name build
  140. #:system system
  141. #:target #f
  142. #:graft? #f
  143. #:guile-for-build guile)))
  144. (define* (perl-cross-build name #:key
  145. source
  146. target
  147. build-inputs host-inputs target-inputs
  148. (search-paths '())
  149. (native-search-paths '())
  150. (tests? #f) ; usually not possible when cross-compiling
  151. (parallel-build? #t)
  152. (parallel-tests? #t)
  153. (make-maker? #f)
  154. (make-maker-flags ''())
  155. (module-build-flags ''())
  156. (phases '(@ (guix build perl-build-system)
  157. %standard-phases))
  158. (outputs '("out"))
  159. (system (%current-system))
  160. (build (nix-system->gnu-triplet system))
  161. (guile #f)
  162. (imported-modules %perl-build-system-modules)
  163. (modules '((guix build perl-build-system)
  164. (guix build utils))))
  165. "Cross-build SOURCE to TARGET using PERL, and with INPUTS. This assumes
  166. that SOURCE provides a `Makefile.PL' file as its build system and does not use
  167. XS or similar."
  168. (define inputs
  169. #~(append #$(input-tuples->gexp host-inputs)
  170. #+(input-tuples->gexp target-inputs)))
  171. (define builder
  172. (with-imported-modules imported-modules
  173. #~(begin
  174. (use-modules #$@(sexp->gexp modules))
  175. (perl-build #:name #$name
  176. #:source #+source
  177. #:search-paths '#$(sexp->gexp
  178. (map search-path-specification->sexp
  179. search-paths))
  180. #:native-search-paths
  181. '#$(sexp->gexp
  182. (map search-path-specification->sexp
  183. native-search-paths))
  184. #:make-maker? #$make-maker?
  185. #:make-maker-flags #$make-maker-flags
  186. #:module-build-flags #$(sexp->gexp module-build-flags)
  187. #:phases #$phases
  188. #:build #$build
  189. #:system #$system
  190. #:target #$target
  191. #:test-target "test"
  192. #:tests? #$tests?
  193. #:parallel-build? #$parallel-build?
  194. #:parallel-tests? #$parallel-tests?
  195. #:outputs #$(outputs->gexp outputs)
  196. #:inputs #$inputs
  197. #:native-inputs #+(input-tuples->gexp build-inputs)))))
  198. (mlet %store-monad ((guile (package->derivation (or guile (default-guile))
  199. system #:graft? #f)))
  200. (gexp->derivation name builder
  201. #:system system
  202. #:target target
  203. #:graft? #false
  204. #:guile-for-build guile)))
  205. (define perl-build-system
  206. (build-system
  207. (name 'perl)
  208. (description "The standard Perl build system")
  209. (lower lower)))
  210. ;;; perl.scm ends here