Commit | Line | Data |
---|---|---|
233e7676 | 1 | ;;; GNU Guix --- Functional package management for GNU |
46135ce4 | 2 | ;;; Copyright © 2012, 2013, 2014, 2020 Ludovic Courtès <ludo@gnu.org> |
208f7cd1 | 3 | ;;; |
233e7676 | 4 | ;;; This file is part of GNU Guix. |
208f7cd1 | 5 | ;;; |
233e7676 | 6 | ;;; GNU Guix is free software; you can redistribute it and/or modify it |
208f7cd1 LC |
7 | ;;; under the terms of the GNU General Public License as published by |
8 | ;;; the Free Software Foundation; either version 3 of the License, or (at | |
9 | ;;; your option) any later version. | |
10 | ;;; | |
233e7676 | 11 | ;;; GNU Guix is distributed in the hope that it will be useful, but |
208f7cd1 LC |
12 | ;;; WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | ;;; GNU General Public License for more details. | |
15 | ;;; | |
16 | ;;; You should have received a copy of the GNU General Public License | |
233e7676 | 17 | ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>. |
208f7cd1 LC |
18 | |
19 | (define-module (guix build-system) | |
c0cd1b3e | 20 | #:use-module (guix records) |
46135ce4 | 21 | #:use-module (srfi srfi-1) |
0d5a559f | 22 | #:use-module (ice-9 match) |
208f7cd1 LC |
23 | #:export (build-system |
24 | build-system? | |
25 | build-system-name | |
26 | build-system-description | |
0d5a559f LC |
27 | build-system-lower |
28 | ||
29 | bag | |
30 | bag? | |
31 | bag-name | |
d3d337d2 LC |
32 | bag-system |
33 | bag-target | |
0d5a559f LC |
34 | bag-build-inputs |
35 | bag-host-inputs | |
36 | bag-target-inputs | |
37 | bag-outputs | |
38 | bag-arguments | |
39 | bag-build | |
40 | ||
46135ce4 LC |
41 | make-bag |
42 | ||
43 | build-system-with-c-toolchain)) | |
208f7cd1 LC |
44 | |
45 | (define-record-type* <build-system> build-system make-build-system | |
46 | build-system? | |
47 | (name build-system-name) ; symbol | |
48 | (description build-system-description) ; short description | |
0d5a559f LC |
49 | (lower build-system-lower)) ; args ... -> bags |
50 | ||
d3d337d2 LC |
51 | ;; "Bags" are low-level representations of "packages". The system and target |
52 | ;; of a bag is fixed when it's created. This is because build systems may | |
53 | ;; choose inputs as a function of the system and target. | |
0d5a559f LC |
54 | (define-record-type* <bag> bag %make-bag |
55 | bag? | |
56 | (name bag-name) ;string | |
d3d337d2 LC |
57 | |
58 | (system bag-system) ;string | |
59 | (target bag-target ;string | #f | |
60 | (default #f)) | |
61 | ||
62 | ;; Here we use build/host/target in the sense of the GNU tool chain (info | |
63 | ;; "(autoconf) Specifying Target Triplets"). | |
0d5a559f LC |
64 | (build-inputs bag-build-inputs ;list of packages |
65 | (default '())) | |
66 | (host-inputs bag-host-inputs ;list of packages | |
67 | (default '())) | |
68 | ||
69 | ;; "Target inputs" are packages that are built natively, but that are used | |
70 | ;; by target programs in a cross-compilation environment. Thus, they act | |
71 | ;; like 'inputs' as far as search paths are concerned. The only example of | |
72 | ;; that is the cross-libc: it is an input of 'cross-gcc', thus built | |
73 | ;; natively; yet, we want it to be considered as a target input for the | |
74 | ;; purposes of $CPATH, $LIBRARY_PATH, etc. | |
75 | (target-inputs bag-target-inputs | |
76 | (default '())) | |
77 | ||
78 | (outputs bag-outputs ;list of strings | |
79 | (default '("out"))) | |
80 | (arguments bag-arguments ;list | |
81 | (default '())) | |
82 | (build bag-build)) ;bag -> derivation | |
83 | ||
84 | (define* (make-bag build-system name | |
85 | #:key source (inputs '()) (native-inputs '()) | |
86 | (outputs '()) (arguments '()) | |
d3d337d2 | 87 | system target) |
0d5a559f LC |
88 | "Ask BUILD-SYSTEM to return a 'bag' for NAME, with the given SOURCE, |
89 | INPUTS, NATIVE-INPUTS, OUTPUTS, and additional ARGUMENTS. If TARGET is not | |
90 | #f, it must be a string with the GNU triplet of a cross-compilation target. | |
91 | ||
92 | This is the mechanism by which a package is \"lowered\" to a bag, which is the | |
93 | intermediate representation just above derivations." | |
94 | (match build-system | |
95 | (($ <build-system> _ description lower) | |
96 | (apply lower name | |
d3d337d2 | 97 | #:system system |
0d5a559f LC |
98 | #:source source |
99 | #:inputs inputs | |
100 | #:native-inputs native-inputs | |
101 | #:outputs outputs | |
102 | #:target target | |
103 | arguments)))) | |
46135ce4 LC |
104 | |
105 | (define (build-system-with-c-toolchain bs toolchain) | |
106 | "Return a variant of BS, a build system, that uses TOOLCHAIN instead of the | |
107 | default GNU C/C++ toolchain. TOOLCHAIN must be a list of | |
108 | inputs (label/package tuples) providing equivalent functionality, such as the | |
109 | 'gcc-toolchain' package." | |
110 | (define lower | |
111 | (build-system-lower bs)) | |
112 | ||
113 | (define toolchain-packages | |
114 | ;; These are the GNU toolchain packages pulled in by GNU-BUILD-SYSTEM and | |
115 | ;; all the build systems that inherit from it. Keep the list in sync with | |
116 | ;; 'standard-packages' in (guix build-system gnu). | |
117 | '("gcc" "binutils" "libc" "libc:static" "ld-wrapper")) | |
118 | ||
119 | (define (lower* . args) | |
120 | (let ((lowered (apply lower args))) | |
121 | (bag | |
122 | (inherit lowered) | |
123 | (build-inputs | |
124 | (append (fold alist-delete | |
125 | (bag-build-inputs lowered) | |
126 | toolchain-packages) | |
127 | toolchain))))) | |
128 | ||
129 | (build-system | |
130 | (inherit bs) | |
131 | (lower lower*))) |