gnu: emacs-org: Update to 9.4.
[jackhill/guix/guix.git] / guix / build-system / copy.scm
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
20 (define-module (guix build-system copy)
21 #:use-module (guix store)
22 #:use-module (guix utils)
23 #:use-module (guix derivations)
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 #:use-module (ice-9 match)
29 #:use-module (srfi srfi-1)
30 #:export (%copy-build-system-modules
31 default-glibc
32 lower
33 copy-build
34 copy-build-system))
35
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
44 (define %copy-build-system-modules
45 ;; Build-side modules imported by default.
46 `((guix build copy-build-system)
47 ,@%gnu-build-system-modules))
48
49 (define (default-glibc)
50 "Return the default glibc package."
51 ;; Do not use `@' to avoid introducing circular dependencies.
52 (let ((module (resolve-interface '(gnu packages base))))
53 (module-ref module 'glibc)))
54
55 (define* (lower name
56 #:key source inputs native-inputs outputs system target
57 (glibc (default-glibc))
58 #:allow-other-keys
59 #:rest arguments)
60 "Return a bag for NAME from the given arguments."
61 (define private-keywords
62 '(#:source #:target #:inputs #:native-inputs))
63
64 (bag
65 (name name)
66 (system system)
67 (host-inputs `(,@(if source
68 `(("source" ,source))
69 '())
70 ,@inputs
71 ;; Keep the standard inputs of 'gnu-build-system'.
72 ,@(standard-packages)))
73 (build-inputs native-inputs)
74 (outputs outputs)
75 (build copy-build)
76 (arguments (strip-keyword-arguments private-keywords arguments))))
77
78 (define* (copy-build store name inputs
79 #:key (guile #f)
80 (outputs '("out"))
81 (install-plan ''(("." "./")))
82 (search-paths '())
83 (out-of-source? #t)
84 (validate-runpath? #t)
85 (patch-shebangs? #t)
86 (strip-binaries? #t)
87 (strip-flags ''("--strip-debug"))
88 (strip-directories ''("lib" "lib64" "libexec"
89 "bin" "sbin"))
90 (phases '(@ (guix build copy-build-system)
91 %standard-phases))
92 (system (%current-system))
93 (imported-modules %copy-build-system-modules)
94 (modules '((guix build copy-build-system)
95 (guix build utils))))
96 "Build SOURCE using INSTALL-PLAN, and with INPUTS."
97 (define builder
98 `(begin
99 (use-modules ,@modules)
100 (copy-build #:source ,(match (assoc-ref inputs "source")
101 (((? derivation? source))
102 (derivation->output-path source))
103 ((source)
104 source)
105 (source
106 source))
107 #:system ,system
108 #:outputs %outputs
109 #:inputs %build-inputs
110 #:install-plan ,install-plan
111 #:search-paths ',(map search-path-specification->sexp
112 search-paths)
113 #:phases ,phases
114 #:out-of-source? ,out-of-source?
115 #:validate-runpath? ,validate-runpath?
116 #:patch-shebangs? ,patch-shebangs?
117 #:strip-binaries? ,strip-binaries?
118 #:strip-flags ,strip-flags
119 #:strip-directories ,strip-directories)))
120
121 (define guile-for-build
122 (match guile
123 ((? package?)
124 (package-derivation store guile system #:graft? #f))
125 (#f ; the default
126 (let* ((distro (resolve-interface '(gnu packages commencement)))
127 (guile (module-ref distro 'guile-final)))
128 (package-derivation store guile system #:graft? #f)))))
129
130 (build-expression->derivation store name builder
131 #:system system
132 #:inputs inputs
133 #:modules imported-modules
134 #:outputs outputs
135 #:guile-for-build guile-for-build))
136
137 (define copy-build-system
138 (build-system
139 (name 'copy)
140 (description "The standard copy build system")
141 (lower lower)))
142
143 ;;; copy.scm ends here