gnu: gtk-engines: Don't propagate GTK+.
[jackhill/guix/guix.git] / gnu / packages / cross-base.scm
index 4856069..e6553dc 100644 (file)
@@ -2,6 +2,7 @@
 ;;; Copyright © 2013, 2014, 2015, 2016 Ludovic Courtès <ludo@gnu.org>
 ;;; Copyright © 2014, 2015 Mark H Weaver <mhw@netris.org>
 ;;; Copyright © 2016 Jan Nieuwenhuizen <janneke@gnu.org>
+;;; Copyright © 2016 Manolis Fragkiskos Ragkousis <manolis837@gmail.com>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -23,8 +24,8 @@
   #:use-module (gnu packages)
   #:use-module (gnu packages gcc)
   #:use-module (gnu packages base)
-  #:use-module (gnu packages commencement)
   #:use-module (gnu packages linux)
+  #:use-module (gnu packages hurd)
   #:use-module (guix packages)
   #:use-module (guix download)
   #:use-module (guix utils)
@@ -33,6 +34,7 @@
   #:use-module (srfi srfi-1)
   #:use-module (srfi srfi-26)
   #:use-module (ice-9 match)
+  #:use-module (ice-9 regex)
   #:export (cross-binutils
             cross-libc
             cross-gcc))
@@ -121,6 +123,14 @@ may be either a libc package or #f.)"
                                "--disable-libquadmath"
                                "--disable-decimal-float" ;would need libc
                                "--disable-libcilkrts"
+
+                               ;; When target is any OS other than 'none' these
+                               ;; libraries will fail if there is no libc
+                               ;; present. See
+                               ;; <https://lists.gnu.org/archive/html/guix-devel/2016-02/msg01311.html>
+                               "--disable-libitm"
+                               "--disable-libvtv"
+                               "--disable-libsanitizer"
                                )))
 
                  ,(if libc
@@ -167,24 +177,25 @@ may be either a libc package or #f.)"
               `(alist-cons-before
                 'configure 'set-cross-path
                 (lambda* (#:key inputs #:allow-other-keys)
-                  ;; Add the cross Linux headers to CROSS_C_*_INCLUDE_PATH,
-                  ;; and remove them from C_*INCLUDE_PATH.
+                  ;; Add the cross kernel headers to CROSS_CPATH, and remove them
+                  ;; from CPATH.
                   (let ((libc  (assoc-ref inputs "libc"))
-                        (linux (assoc-ref inputs "xlinux-headers")))
+                        (kernel (assoc-ref inputs "xkernel-headers")))
                     (define (cross? x)
                       ;; Return #t if X is a cross-libc or cross Linux.
                       (or (string-prefix? libc x)
-                          (string-prefix? linux x)))
+                          (string-prefix? kernel x)))
                     (let ((cpath (string-append
                                   libc "/include"
-                                  ":" linux "/include")))
+                                  ":" kernel "/include")))
                       (for-each (cut setenv <> cpath)
                                 '("CROSS_C_INCLUDE_PATH"
                                   "CROSS_CPLUS_INCLUDE_PATH"
                                   "CROSS_OBJC_INCLUDE_PATH"
                                   "CROSS_OBJCPLUS_INCLUDE_PATH")))
                     (setenv "CROSS_LIBRARY_PATH"
-                            (string-append libc "/lib"))
+                            (string-append libc "/lib:"
+                                           kernel "/lib")) ;for Hurd's libihash
                     (for-each
                      (lambda (var)
                        (and=> (getenv var)
@@ -242,22 +253,22 @@ GCC that does not target a libc; otherwise, target that libc."
     (native-inputs
      `(("ld-wrapper-cross" ,(make-ld-wrapper
                              (string-append "ld-wrapper-" target)
-                             #:target target
+                             #:target (const target)
                              #:binutils xbinutils))
        ("binutils-cross" ,xbinutils)
 
        ;; Call it differently so that the builder can check whether the "libc"
        ;; input is #f.
-       ("libc-native" ,@(assoc-ref %final-inputs "libc"))
+       ("libc-native" ,@(assoc-ref (%final-inputs) "libc"))
 
        ;; Remaining inputs.
        ,@(let ((inputs (append (package-inputs %xgcc)
-                               (alist-delete "libc" %final-inputs))))
+                               (alist-delete "libc" (%final-inputs)))))
            (if libc
                `(("libc" ,libc)
-                 ("xlinux-headers"                ;the target headers
+                 ("xkernel-headers"                ;the target headers
                   ,@(assoc-ref (package-propagated-inputs libc)
-                               "linux-headers"))
+                               "kernel-headers"))
                  ,@inputs)
                inputs))))
 
@@ -283,12 +294,12 @@ GCC that does not target a libc; otherwise, target that libc."
             (files '("lib" "lib64")))))
     (native-search-paths '())))
 
-(define* (cross-libc target
-                     #:optional
-                     (xgcc (cross-gcc target))
-                     (xbinutils (cross-binutils target)))
-  "Return a libc cross-built for TARGET, a GNU triplet.  Use XGCC and
-XBINUTILS and the cross tool chain."
+(define* (cross-kernel-headers target
+                               #:optional
+                               (xgcc (cross-gcc target))
+                               (xbinutils (cross-binutils target)))
+  "Return headers depending on TARGET."
+
   (define xlinux-headers
     (package (inherit linux-libre-headers)
       (name (string-append (package-name linux-libre-headers)
@@ -311,91 +322,213 @@ XBINUTILS and the cross tool chain."
                        ("cross-binutils" ,xbinutils)
                        ,@(package-native-inputs linux-libre-headers)))))
 
-  (package (inherit glibc)
-    (name (string-append "glibc-cross-" target))
-    (arguments
-     (substitute-keyword-arguments
-         `(;; Disable stripping (see above.)
-           #:strip-binaries? #f
+  (define xgnumach-headers
+    (package (inherit gnumach-headers)
+      (name (string-append (package-name gnumach-headers)
+                           "-cross-" target))
 
-           ;; This package is used as a target input, but it should not have
-           ;; the usual cross-compilation inputs since that would include
-           ;; itself.
-           #:implicit-cross-inputs? #f
+      (native-inputs `(("cross-gcc" ,xgcc)
+                       ("cross-binutils" ,xbinutils)
+                       ,@(package-native-inputs gnumach-headers)))))
+
+  (define xmig
+    (package (inherit mig)
+      (name (string-append "mig-cross"))
+      (arguments
+       `(#:modules ((guix build gnu-build-system)
+                    (guix build utils)
+                    (srfi srfi-26))
+         #:phases (alist-cons-before
+                   'configure 'set-cross-headers-path
+                   (lambda* (#:key inputs #:allow-other-keys)
+                     (let* ((mach (assoc-ref inputs "cross-gnumach-headers"))
+                            (cpath (string-append mach "/include")))
+                       (for-each (cut setenv <> cpath)
+                                 '("CROSS_C_INCLUDE_PATH"
+                                   "CROSS_CPLUS_INCLUDE_PATH"
+                                   "CROSS_OBJC_INCLUDE_PATH"
+                                   "CROSS_OBJCPLUS_INCLUDE_PATH"))))
+                   %standard-phases)
+         #:configure-flags (list ,(string-append "--target=" target))
+         ,@(package-arguments mig)))
+
+      (propagated-inputs `(("cross-gnumach-headers" ,xgnumach-headers)))
+      (native-inputs `(("cross-gcc" ,xgcc)
+                       ("cross-binutils" ,xbinutils)
+                       ,@(package-native-inputs mig)))))
+
+  (define xhurd-headers
+    (package (inherit hurd-headers)
+      (name (string-append (package-name hurd-headers)
+                           "-cross-" target))
 
-           ;; We need SRFI 26.
-           #:modules ((guix build gnu-build-system)
+      (propagated-inputs `(("cross-mig" ,xmig)))
+      (native-inputs `(("cross-gcc" ,xgcc)
+                       ("cross-binutils" ,xbinutils)
+                       ("cross-mig" ,xmig)
+                       ,@(alist-delete "mig"(package-native-inputs hurd-headers))))))
+
+   (define xglibc/hurd-headers
+    (package (inherit glibc/hurd-headers)
+      (name (string-append (package-name glibc/hurd-headers)
+                           "-cross-" target))
+
+      (arguments
+       (substitute-keyword-arguments
+           `(#:modules ((guix build gnu-build-system)
+                        (guix build utils)
+                        (srfi srfi-26))
+             ,@(package-arguments glibc/hurd-headers))
+         ((#:phases phases)
+          `(alist-cons-before
+            'pre-configure 'set-cross-headers-path
+            (lambda* (#:key inputs #:allow-other-keys)
+              (let* ((mach (assoc-ref inputs "gnumach-headers"))
+                     (hurd (assoc-ref inputs "hurd-headers"))
+                     (cpath (string-append mach "/include:"
+                                           hurd "/include")))
+                (for-each (cut setenv <> cpath)
+                          '("CROSS_C_INCLUDE_PATH"
+                            "CROSS_CPLUS_INCLUDE_PATH"
+                            "CROSS_OBJC_INCLUDE_PATH"
+                            "CROSS_OBJCPLUS_INCLUDE_PATH"))))
+            ,phases))))
+
+      (propagated-inputs `(("gnumach-headers" ,xgnumach-headers)
+                           ("hurd-headers" ,xhurd-headers)))
+
+      (native-inputs `(("cross-gcc" ,xgcc)
+                       ("cross-binutils" ,xbinutils)
+                       ("cross-mig" ,xmig)
+                       ,@(alist-delete "mig"(package-native-inputs glibc/hurd-headers))))))
+
+  (define xhurd-minimal
+    (package (inherit hurd-minimal)
+      (name (string-append (package-name hurd-minimal)
+                           "-cross-" target))
+      (arguments
+       (substitute-keyword-arguments
+         `(#:modules ((guix build gnu-build-system)
                       (guix build utils)
                       (srfi srfi-26))
+           ,@(package-arguments hurd-minimal))
+         ((#:phases phases)
+          `(alist-cons-before
+            'configure 'set-cross-headers-path
+            (lambda* (#:key inputs #:allow-other-keys)
+              (let* ((glibc-headers (assoc-ref inputs "cross-glibc-hurd-headers"))
+                    (cpath (string-append glibc-headers "/include")))
+                (for-each (cut setenv <> cpath)
+                          '("CROSS_C_INCLUDE_PATH"
+                            "CROSS_CPLUS_INCLUDE_PATH"
+                            "CROSS_OBJC_INCLUDE_PATH"
+                            "CROSS_OBJCPLUS_INCLUDE_PATH"))))
+            ,phases))))
 
-           ,@(package-arguments glibc))
-       ((#:configure-flags flags)
-        `(cons ,(string-append "--host=" target)
+      (inputs `(("cross-glibc-hurd-headers" ,xglibc/hurd-headers)))
+
+      (native-inputs `(("cross-gcc" ,xgcc)
+                       ("cross-binutils" ,xbinutils)
+                       ("cross-mig" ,xmig)
+                       ,@(alist-delete "mig"(package-native-inputs hurd-minimal))))))
+
+  (define xhurd-core-headers
+    (package (inherit hurd-core-headers)
+      (name (string-append (package-name hurd-core-headers)
+                           "-cross-" target))
+
+      (inputs `(("gnumach-headers" ,xgnumach-headers)
+                ("hurd-headers" ,xhurd-headers)
+                ("hurd-minimal" ,xhurd-minimal)))
+
+      (native-inputs `(("cross-gcc" ,xgcc)
+                       ("cross-binutils" ,xbinutils)
+                       ("cross-mig" ,xmig)
+                       ,@(package-native-inputs hurd-core-headers)))))
+
+  (match target
+    ((or "i586-pc-gnu" "i586-gnu") xhurd-core-headers)
+    (_ xlinux-headers)))
+
+(define* (cross-libc target
+                     #:optional
+                     (xgcc (cross-gcc target))
+                     (xbinutils (cross-binutils target))
+                     (xheaders (cross-kernel-headers target)))
+  "Return a libc cross-built for TARGET, a GNU triplet.  Use XGCC and
+XBINUTILS and the cross tool chain."
+  (define (cross-libc-for-target target)
+    "Return libc depending on TARGET."
+    (match target
+      ((or "i586-pc-gnu" "i586-gnu") glibc/hurd)
+      (_ glibc/linux)))
+
+  ;; Use (cross-libc-for-target ...) to determine the correct libc to use.
+  (let ((libc (cross-libc-for-target target)))
+    (package (inherit libc)
+      (name (string-append "glibc-cross-" target))
+      (arguments
+       (substitute-keyword-arguments
+           `(;; Disable stripping (see above.)
+             #:strip-binaries? #f
+
+             ;; This package is used as a target input, but it should not have
+             ;; the usual cross-compilation inputs since that would include
+             ;; itself.
+             #:implicit-cross-inputs? #f
+
+             ;; We need SRFI 26.
+             #:modules ((guix build gnu-build-system)
+                        (guix build utils)
+                        (srfi srfi-26))
+
+             ,@(package-arguments libc))
+         ((#:configure-flags flags)
+          `(cons ,(string-append "--host=" target)
                ,flags))
-       ((#:phases phases)
-        `(alist-cons-before
-          'configure 'set-cross-linux-headers-path
-          (lambda* (#:key inputs #:allow-other-keys)
-            (let* ((linux (assoc-ref inputs "linux-headers"))
-                   (cpath (string-append linux "/include")))
-              (for-each (cut setenv <> cpath)
-                        '("CROSS_C_INCLUDE_PATH"
-                          "CROSS_CPLUS_INCLUDE_PATH"
-                          "CROSS_OBJC_INCLUDE_PATH"
-                          "CROSS_OBJCPLUS_INCLUDE_PATH"))
-              #t))
-          ,phases))))
-
-    ;; Shadow the native "linux-headers" because glibc's recipe expects the
-    ;; "linux-headers" input to point to the right thing.
-    (propagated-inputs `(("linux-headers" ,xlinux-headers)))
-
-    ;; FIXME: 'static-bash' should really be an input, not a native input, but
-    ;; to do that will require building an intermediate cross libc.
-    (inputs '())
+         ((#:phases phases)
+          `(alist-cons-before
+            'configure 'set-cross-kernel-headers-path
+            (lambda* (#:key inputs #:allow-other-keys)
+              (let* ((kernel (assoc-ref inputs "kernel-headers"))
+                     (cpath (string-append kernel "/include")))
+                (for-each (cut setenv <> cpath)
+                          '("CROSS_C_INCLUDE_PATH"
+                            "CROSS_CPLUS_INCLUDE_PATH"
+                            "CROSS_OBJC_INCLUDE_PATH"
+                            "CROSS_OBJCPLUS_INCLUDE_PATH"))
+                (setenv "CROSS_LIBRARY_PATH"
+                        (string-append kernel "/lib")) ;for Hurd's libihash
+                #t))
+            ,phases))))
 
-    (native-inputs `(("cross-gcc" ,xgcc)
-                     ("cross-binutils" ,xbinutils)
-                     ,@(package-inputs glibc)     ;FIXME: static-bash
-                     ,@(package-native-inputs glibc)))))
+      ;; Shadow the native "kernel-headers" because glibc's recipe expects the
+      ;; "kernel-headers" input to point to the right thing.
+      (propagated-inputs `(("kernel-headers" ,xheaders)))
 
-\f
-;;;
-;;; Concrete cross toolchains.
-;;;
+      ;; FIXME: 'static-bash' should really be an input, not a native input, but
+      ;; to do that will require building an intermediate cross libc.
+      (inputs '())
 
-(define-public xgcc-mips64el
-  (let* ((triplet "mips64el-linux-gnuabi64")      ;N64 ABI
-         (xgcc    (cross-gcc triplet
-                             (cross-binutils triplet)
-                             (cross-libc triplet))))
-    ;; Don't attempt to build this cross-compiler on i686;
-    ;; see <http://bugs.gnu.org/19598>.
-    (package (inherit xgcc)
-      (supported-systems (fold delete
-                               (package-supported-systems xgcc)
-                               '("mips64el-linux" "i686-linux"))))))
-
-(define-public xgcc-avr
-  ;; AVR cross-compiler, used to build AVR-Libc.
-  (let ((triplet "avr"))
-    (cross-gcc triplet
-               (cross-binutils triplet))))
-
-(define-public xgcc-xtensa
-  ;; Bare-bones Xtensa cross-compiler, used to build the Atheros firmware.
-  (cross-gcc "xtensa-elf"))
-
-(define-public xgcc-armhf
-  (let* ((triplet "arm-linux-gnueabihf")
-         (xgcc    (cross-gcc triplet
-                             (cross-binutils triplet)
-                             (cross-libc triplet))))
-    (package (inherit xgcc)
-      (supported-systems (delete "armhf-linux" %supported-systems)))))
-
-;; (define-public xgcc-armel
-;;   (let ((triplet "armel-linux-gnueabi"))
+      (native-inputs `(("cross-gcc" ,xgcc)
+                       ("cross-binutils" ,xbinutils)
+                       ,@(if (string-match (or "i586-pc-gnu" "i586-gnu") target)
+                             `(("cross-mig"
+                                ,@(assoc-ref (package-native-inputs xheaders)
+                                             "cross-mig")))
+                             '())
+                       ,@(package-inputs libc)     ;FIXME: static-bash
+                       ,@(package-native-inputs libc))))))
+
+\f
+;;; Concrete cross tool chains are instantiated like this:
+;;
+;; (define-public xgcc-armhf
+;;   (let ((triplet "arm-linux-gnueabihf"))
 ;;     (cross-gcc triplet
 ;;                (cross-binutils triplet)
 ;;                (cross-libc triplet))))
+;;
+;;; We don't do that here because we'd be referring to bindings from (gnu
+;;; packages gcc) from the top level, which doesn't play well with circular
+;;; dependencies among modules.