gnu: docbook-xsl update to 1.78.1
[jackhill/guix/guix.git] / gnu / packages / cross-base.scm
CommitLineData
827d2891 1;;; GNU Guix --- Functional package management for GNU
a49c57a7 2;;; Copyright © 2013, 2014 Ludovic Courtès <ludo@gnu.org>
827d2891
LC
3;;;
4;;; This file is part of GNU Guix.
5;;;
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.
10;;;
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.
15;;;
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/>.
18
19(define-module (gnu packages cross-base)
20 #:use-module (guix licenses)
21 #:use-module (gnu packages)
f594028a 22 #:use-module (gnu packages gcc)
827d2891
LC
23 #:use-module (gnu packages base)
24 #:use-module (gnu packages linux)
25 #:use-module (guix packages)
26 #:use-module (guix download)
27 #:use-module (guix utils)
28 #:use-module (guix build-system gnu)
29 #:use-module (guix build-system trivial)
30 #:use-module (srfi srfi-1)
31 #:use-module (srfi srfi-26)
264218a4
LC
32 #:use-module (ice-9 match)
33 #:export (cross-binutils
34 cross-libc
35 cross-gcc))
827d2891
LC
36
37(define (cross p target)
38 (package (inherit p)
39 (location (source-properties->location (current-source-location)))
40 (name (string-append (package-name p) "-cross-" target))
41 (arguments
42 (substitute-keyword-arguments (package-arguments p)
43 ((#:configure-flags flags)
44 `(cons ,(string-append "--target=" target)
45 ,flags))))))
46
47e74d6e
LC
47(define (cross-binutils target)
48 "Return a cross-Binutils for TARGET."
49 (let ((binutils (package (inherit binutils)
50 (arguments
51 (substitute-keyword-arguments (package-arguments
52 binutils)
53 ((#:configure-flags flags)
54 ;; Build with `--with-sysroot' so that ld honors
55 ;; DT_RUNPATH entries when searching for a needed
56 ;; library. This works because as a side effect
57 ;; `genscripts.sh' sets `USE_LIBPATH=yes', which tells
58 ;; elf32.em to use DT_RUNPATH in its search list.
c8fa51f2
LC
59 ;; See <http://sourceware.org/ml/binutils/2013-05/msg00312.html>.
60 ;;
61 ;; In theory choosing / as the sysroot could lead ld
62 ;; to pick up native libs instead of target ones. In
63 ;; practice the RUNPATH of target libs only refers to
64 ;; target libs, not native libs, so this is safe.
65 `(cons "--with-sysroot=/" ,flags)))))))
47e74d6e 66 (cross binutils target)))
827d2891
LC
67
68(define* (cross-gcc target
69 #:optional (xbinutils (cross-binutils target)) libc)
70 "Return a cross-compiler for TARGET, where TARGET is a GNU triplet. Use
71XBINUTILS as the associated cross-Binutils. If LIBC is false, then build a
72GCC that does not target a libc; otherwise, target that libc."
9ae7cee3 73 (package (inherit gcc-4.8)
827d2891
LC
74 (name (string-append "gcc-cross-"
75 (if libc "" "sans-libc-")
76 target))
9ae7cee3 77 (source (origin (inherit (package-source gcc-4.8))
01eafd38 78 (patches
a49c57a7
LC
79 (list (search-patch
80 "gcc-cross-environment-variables.patch")))))
81
82 ;; For simplicity, use a single output. Otherwise libgcc_s & co. are not
83 ;; found by default, etc.
84 (outputs '("out"))
85
827d2891
LC
86 (arguments
87 `(#:implicit-inputs? #f
88 #:modules ((guix build gnu-build-system)
89 (guix build utils)
90 (ice-9 regex)
91 (srfi srfi-1)
92 (srfi srfi-26))
827d2891 93
9ae7cee3 94 ,@(substitute-keyword-arguments (package-arguments gcc-4.8)
827d2891
LC
95 ((#:configure-flags flags)
96 `(append (list ,(string-append "--target=" target)
beda99e8 97 ,@(gcc-configure-flags-for-triplet target)
827d2891
LC
98 ,@(if libc
99 '()
100 `( ;; Disable features not needed at this stage.
101 "--disable-shared" "--enable-static"
102
103 ;; Disable C++ because libstdc++'s
104 ;; configure script otherwise fails with
105 ;; "Link tests are not allowed after
106 ;; GCC_NO_EXECUTABLES."
107 "--enable-languages=c"
108
109 "--disable-threads" ; libgcc, would need libc
08928e57 110 "--disable-libatomic"
827d2891
LC
111 "--disable-libmudflap"
112 "--disable-libgomp"
113 "--disable-libssp"
114 "--disable-libquadmath"
115 "--disable-decimal-float" ; would need libc
116 )))
117
118 ,(if libc
119 flags
120 `(remove (cut string-match "--enable-languages.*" <>)
121 ,flags))))
122 ((#:make-flags flags)
123 (if libc
124 `(let ((libc (assoc-ref %build-inputs "libc")))
125 ;; FLAGS_FOR_TARGET are needed for the target libraries to
126 ;; receive the -Bxxx for the startfiles.
127 (cons (string-append "FLAGS_FOR_TARGET=-B" libc "/lib")
128 ,flags))
129 flags))
130 ((#:phases phases)
131 (let ((phases
132 `(alist-cons-after
133 'install 'make-cross-binutils-visible
134 (lambda* (#:key outputs inputs #:allow-other-keys)
135 (let* ((out (assoc-ref outputs "out"))
136 (libexec (string-append out "/libexec/gcc/"
137 ,target))
138 (binutils (string-append
139 (assoc-ref inputs "binutils-cross")
140 "/bin/" ,target "-")))
141 (for-each (lambda (file)
142 (symlink (string-append binutils file)
143 (string-append libexec "/"
144 file)))
145 '("as" "ld" "nm"))
146 #t))
147 ,phases)))
148 (if libc
149 `(alist-cons-before
150 'configure 'set-cross-path
151 (lambda* (#:key inputs #:allow-other-keys)
152 ;; Add the cross Linux headers to CROSS_CPATH, and remove
153 ;; them from CPATH.
154 (let ((libc (assoc-ref inputs "libc"))
155 (linux (assoc-ref inputs
156 "libc/cross-linux-headers")))
157 (define (cross? x)
158 ;; Return #t if X is a cross-libc or cross Linux.
159 (or (string-prefix? libc x)
160 (string-prefix? linux x)))
161
162 (setenv "CROSS_CPATH"
163 (string-append libc "/include:"
164 linux "/include"))
165 (setenv "CROSS_LIBRARY_PATH"
166 (string-append libc "/lib"))
167
168 (let ((cpath (search-path-as-string->list
169 (getenv "CPATH")))
170 (libpath (search-path-as-string->list
171 (getenv "LIBRARY_PATH"))))
172 (setenv "CPATH"
173 (list->search-path-as-string
174 (remove cross? cpath) ":"))
175 (setenv "LIBRARY_PATH"
176 (list->search-path-as-string
177 (remove cross? libpath) ":"))
178 #t)))
179 ,phases)
180 phases)))
181 ((#:strip-binaries? _)
182 ;; Disable stripping as this can break binaries, with object files
183 ;; of libgcc.a showing up as having an unknown architecture. See
184 ;; <http://lists.fedoraproject.org/pipermail/arm/2010-August/000663.html>
185 ;; for instance.
186 #f))))
0de71c23
LC
187
188 (native-inputs
01eafd38 189 `(("binutils-cross" ,xbinutils)
827d2891
LC
190
191 ;; Call it differently so that the builder can check whether the "libc"
192 ;; input is #f.
193 ("libc-native" ,@(assoc-ref %final-inputs "libc"))
194
195 ;; Remaining inputs.
9ae7cee3 196 ,@(let ((inputs (append (package-inputs gcc-4.8)
827d2891
LC
197 (alist-delete "libc" %final-inputs))))
198 (if libc
199 `(("libc" ,libc)
200 ,@inputs)
17bb886f
LC
201 inputs))))
202
0de71c23
LC
203 (inputs '())
204
17bb886f
LC
205 ;; Only search target inputs, not host inputs.
206 (search-paths
207 (list (search-path-specification
208 (variable "CROSS_CPATH")
209 (directories '("include")))
210 (search-path-specification
211 (variable "CROSS_LIBRARY_PATH")
212 (directories '("lib" "lib64")))))
213 (native-search-paths '())))
827d2891
LC
214
215(define* (cross-libc target
216 #:optional
217 (xgcc (cross-gcc target))
218 (xbinutils (cross-binutils target)))
219 "Return a libc cross-built for TARGET, a GNU triplet. Use XGCC and
220XBINUTILS and the cross tool chain."
221 (define xlinux-headers
222 (package (inherit linux-libre-headers)
223 (name (string-append (package-name linux-libre-headers)
224 "-cross-" target))
225 (arguments
226 (substitute-keyword-arguments (package-arguments linux-libre-headers)
227 ((#:phases phases)
228 `(alist-replace
229 'build
230 (lambda _
231 (setenv "ARCH" ,(system->linux-architecture target))
232 (format #t "`ARCH' set to `~a' (cross compiling)~%" (getenv "ARCH"))
233
234 (and (zero? (system* "make" "defconfig"))
235 (zero? (system* "make" "mrproper" "headers_check"))))
236 ,phases))))
0de71c23
LC
237 (native-inputs `(("cross-gcc" ,xgcc)
238 ("cross-binutils" ,xbinutils)
239 ,@(package-native-inputs linux-libre-headers)))))
827d2891
LC
240
241 (package (inherit glibc)
242 (name (string-append "glibc-cross-" target))
243 (arguments
244 (substitute-keyword-arguments
245 `(#:strip-binaries? #f ; disable stripping (see above)
246 ,@(package-arguments glibc))
247 ((#:configure-flags flags)
248 `(cons ,(string-append "--host=" target)
249 ,flags))
250 ((#:phases phases)
251 `(alist-cons-before
252 'configure 'set-cross-linux-headers-path
253 (lambda* (#:key inputs #:allow-other-keys)
254 (let ((linux (assoc-ref inputs "cross-linux-headers")))
255 (setenv "CROSS_CPATH"
256 (string-append linux "/include"))
257 #t))
258 ,phases))))
a4627d49 259
827d2891 260 (propagated-inputs `(("cross-linux-headers" ,xlinux-headers)))
0de71c23
LC
261 (native-inputs `(("cross-gcc" ,xgcc)
262 ("cross-binutils" ,xbinutils)
263 ,@(package-native-inputs glibc)))))
827d2891
LC
264
265\f
266;;;
267;;; Concrete cross toolchains.
268;;;
269
270(define-public xgcc-mips64el
beda99e8 271 (let ((triplet "mips64el-linux-gnuabi64")) ; N64 ABI
827d2891
LC
272 (cross-gcc triplet
273 (cross-binutils triplet)
274 (cross-libc triplet))))
275
276;; (define-public xgcc-armel
277;; (let ((triplet "armel-linux-gnueabi"))
278;; (cross-gcc triplet
279;; (cross-binutils triplet)
280;; (cross-libc triplet))))