1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2012, 2013, 2014, 2020 Ludovic Courtès <ludo@gnu.org>
4 ;;; This file is part of GNU Guix.
6 ;;; GNU Guix is free software; you can redistribute it and/or modify it
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.
11 ;;; GNU Guix is distributed in the hope that it will be useful, but
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.
16 ;;; You should have received a copy of the GNU General Public License
17 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
19 (define-module (guix build-system)
20 #:use-module (guix records)
21 #:use-module (srfi srfi-1)
22 #:use-module (ice-9 match)
23 #:export (build-system
26 build-system-description
43 build-system-with-c-toolchain))
45 (define-record-type* <build-system> build-system make-build-system
47 (name build-system-name) ; symbol
48 (description build-system-description) ; short description
49 (lower build-system-lower)) ; args ... -> bags
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.
54 (define-record-type* <bag> bag %make-bag
56 (name bag-name) ;string
58 (system bag-system) ;string
59 (target bag-target ;string | #f
62 ;; Here we use build/host/target in the sense of the GNU tool chain (info
63 ;; "(autoconf) Specifying Target Triplets").
64 (build-inputs bag-build-inputs ;list of packages
66 (host-inputs bag-host-inputs ;list of packages
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
78 (outputs bag-outputs ;list of strings
80 (arguments bag-arguments ;list
82 (build bag-build)) ;bag -> derivation
84 (define* (make-bag build-system name
85 #:key source (inputs '()) (native-inputs '())
86 (outputs '()) (arguments '())
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.
92 This is the mechanism by which a package is \"lowered\" to a bag, which is the
93 intermediate representation just above derivations."
95 (($ <build-system> _ description lower)
100 #:native-inputs native-inputs
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."
111 (build-system-lower bs))
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"))
119 (define (lower* . args)
120 (let ((lowered (apply lower args)))
124 (append (fold alist-delete
125 (bag-build-inputs lowered)