[bug#36477,v4,01/23] gnu: openssl: Fix cross-compilation.
diff mbox series

Message ID 20191002095904.6325-2-m.othacehe@gmail.com
State New
Headers show
Series
  • System cross-compilation
Related show

Commit Message

Mathieu Othacehe Oct. 2, 2019, 9:58 a.m. UTC
* gnu/packages/tls.scm (openssl-next)[arguments]: Pass CROSS_COMPILE
environment variable and target system to configure script.
---
 gnu/packages/tls.scm | 62 ++++++++++++++++++++++++++++++++------------
 1 file changed, 45 insertions(+), 17 deletions(-)

Comments

Efraim Flashner Oct. 2, 2019, 10:17 a.m. UTC | #1
On Wed, Oct 02, 2019 at 11:58:42AM +0200, Mathieu Othacehe wrote:
> * gnu/packages/tls.scm (openssl-next)[arguments]: Pass CROSS_COMPILE
> environment variable and target system to configure script.
> ---
>  gnu/packages/tls.scm | 62 ++++++++++++++++++++++++++++++++------------
>  1 file changed, 45 insertions(+), 17 deletions(-)
> 
> diff --git a/gnu/packages/tls.scm b/gnu/packages/tls.scm
> index 6689375da6..8797429dcf 100644
> --- a/gnu/packages/tls.scm
> +++ b/gnu/packages/tls.scm
> @@ -13,6 +13,7 @@
>  ;;; Copyright © 2017, 2018, 2019 Tobias Geerinckx-Rice <me@tobias.gr>
>  ;;; Copyright © 2017 Rutger Helling <rhelling@mykolab.com>
>  ;;; Copyright © 2018 Clément Lassieur <clement@lassieur.org>
> +;;; Copyright © 2019 Mathieu Othacehe <m.othacehe@gmail.com>
>  ;;;
>  ;;; This file is part of GNU Guix.
>  ;;;
> @@ -301,6 +302,23 @@ required structures.")
>        #:disallowed-references ,(list (canonical-package perl))
>        #:phases
>        (modify-phases %standard-phases
> +	,@(if (%current-target-system)
> +	      '((add-before
> +		    'configure 'set-cross-compile
> +		  (lambda* (#:key target outputs #:allow-other-keys)
> +		    (setenv "CROSS_COMPILE" (string-append target "-"))
> +		    (setenv "CONFIGURE_TARGET_ARCH"
> +			    (cond
> +			     ((string-prefix? "i686" target)
> +			      "linux-x86")
> +			     ((string-prefix? "x86_64" target)
> +			      "linux-x86_64")
> +			     ((string-prefix? "arm" target)
> +			      "linux-armv4")
> +			     ((string-prefix? "aarch64" target)
> +			      "linux-aarch64")))

This needs a null case. I think I'd try
                (_
                 (string-append "linux-" (string-tokenize
                                         (%current-target-system)
                                         (char-set-compliment (char-set #\-)))))
This would create something somewhat usable for uncovered cases, and in
the case of x86_64-linux, it would (should) spit out "linux-x86_64"

This is basically the code used in (gnu services desktop) for the
enlightenment-setuid-programs.

> +		    #t)))
> +	      '())
>          (replace 'configure
>            (lambda* (#:key outputs #:allow-other-keys)
>              (let* ((out (assoc-ref outputs "out"))
> @@ -310,7 +328,9 @@ required structures.")
>                  (("/usr/bin/env")
>                   (string-append (assoc-ref %build-inputs "coreutils")
>                                  "/bin/env")))
> -              (invoke "./config"
> +              (invoke ,@(if (%current-target-system)
> +			    '("./Configure")
> +			    '("./config"))
>                        "shared"       ;build shared libraries
>                        "--libdir=lib"
>  
> @@ -321,7 +341,10 @@ required structures.")
>                                       "/share/openssl-" ,version)
>  
>                        (string-append "--prefix=" out)
> -                      (string-append "-Wl,-rpath," lib)))))
> +                      (string-append "-Wl,-rpath," lib)
> +		      ,@(if (%current-target-system)
> +			    '((getenv "CONFIGURE_TARGET_ARCH"))
> +			    '())))))

could this be changed to
             ,@(when (%current-target-system)
                 '((getenv "CONFIGURE_TARGET_ARCH")))

if it works then you don't need the 'if not' null case.

>          (add-after 'install 'move-static-libraries
>            (lambda* (#:key outputs #:allow-other-keys)
>              ;; Move static libraries to the "static" output.
> @@ -435,21 +458,26 @@ required structures.")
>                     (("^MANDIR[[:blank:]]*=.*$")
>                      (string-append "MANDIR = " out "/share/man\n")))
>                   #t)))
> -        (replace 'configure
> -          ;; Override this phase because OpenSSL 1.0 does not understand -rpath.
> -          (lambda* (#:key outputs #:allow-other-keys)
> -            (let ((out (assoc-ref outputs "out")))
> -              (invoke "./config"
> -                      "shared"                 ;build shared libraries
> -                      "--libdir=lib"
> -
> -                      ;; The default for this catch-all directory is
> -                      ;; PREFIX/ssl.  Change that to something more
> -                      ;; conventional.
> -                      (string-append "--openssldir=" out
> -                                     "/share/openssl-" ,version)
> -
> -                      (string-append "--prefix=" out)))))
> +	   (replace 'configure
> +	     ;; Override this phase because OpenSSL 1.0 does not understand -rpath.
> +	     (lambda* (#:key outputs #:allow-other-keys)
> +	       (let ((out (assoc-ref outputs "out")))
> +		 (invoke ,@(if (%current-target-system)
> +			       '("./Configure")
> +			       '("./config"))
> +			 "shared"                 ;build shared libraries
> +			 "--libdir=lib"
> +
> +			 ;; The default for this catch-all directory is
> +			 ;; PREFIX/ssl.  Change that to something more
> +			 ;; conventional.
> +			 (string-append "--openssldir=" out
> +					"/share/openssl-" ,version)
> +
> +			 (string-append "--prefix=" out)
> +			 ,@(if (%current-target-system)
> +			       '((getenv "CONFIGURE_TARGET_ARCH"))
> +			       '())))))
>          (delete 'move-extra-documentation)
>          (add-after 'install 'move-man3-pages
>            (lambda* (#:key outputs #:allow-other-keys)
> -- 
> 2.23.0
> 
> 
> 
>
Mathieu Othacehe Oct. 2, 2019, 1:12 p.m. UTC | #2
Hey Efraim,

Thanks for reviewing.

> This needs a null case. I think I'd try
>                 (_
>                  (string-append "linux-" (string-tokenize
>                                          (%current-target-system)
>                                          (char-set-compliment (char-set #\-)))))
> This would create something somewhat usable for uncovered cases, and in
> the case of x86_64-linux, it would (should) spit out "linux-x86_64"

Ok I'll add it (something like a "car" is missing to take only the first
part of %current-target-system which is referring to the architecture).

> could this be changed to
>              ,@(when (%current-target-system)
>                  '((getenv "CONFIGURE_TARGET_ARCH")))
>
> if it works then you don't need the 'if not' null case.

Nope, sadly it wouldn't work :(

,@(when #t '(1)) -> '(1)

but,

,@(when #f '(1)) -> "Unknown meta command: @"

Mathieu

Patch
diff mbox series

diff --git a/gnu/packages/tls.scm b/gnu/packages/tls.scm
index 6689375da6..8797429dcf 100644
--- a/gnu/packages/tls.scm
+++ b/gnu/packages/tls.scm
@@ -13,6 +13,7 @@ 
 ;;; Copyright © 2017, 2018, 2019 Tobias Geerinckx-Rice <me@tobias.gr>
 ;;; Copyright © 2017 Rutger Helling <rhelling@mykolab.com>
 ;;; Copyright © 2018 Clément Lassieur <clement@lassieur.org>
+;;; Copyright © 2019 Mathieu Othacehe <m.othacehe@gmail.com>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -301,6 +302,23 @@  required structures.")
       #:disallowed-references ,(list (canonical-package perl))
       #:phases
       (modify-phases %standard-phases
+	,@(if (%current-target-system)
+	      '((add-before
+		    'configure 'set-cross-compile
+		  (lambda* (#:key target outputs #:allow-other-keys)
+		    (setenv "CROSS_COMPILE" (string-append target "-"))
+		    (setenv "CONFIGURE_TARGET_ARCH"
+			    (cond
+			     ((string-prefix? "i686" target)
+			      "linux-x86")
+			     ((string-prefix? "x86_64" target)
+			      "linux-x86_64")
+			     ((string-prefix? "arm" target)
+			      "linux-armv4")
+			     ((string-prefix? "aarch64" target)
+			      "linux-aarch64")))
+		    #t)))
+	      '())
         (replace 'configure
           (lambda* (#:key outputs #:allow-other-keys)
             (let* ((out (assoc-ref outputs "out"))
@@ -310,7 +328,9 @@  required structures.")
                 (("/usr/bin/env")
                  (string-append (assoc-ref %build-inputs "coreutils")
                                 "/bin/env")))
-              (invoke "./config"
+              (invoke ,@(if (%current-target-system)
+			    '("./Configure")
+			    '("./config"))
                       "shared"       ;build shared libraries
                       "--libdir=lib"
 
@@ -321,7 +341,10 @@  required structures.")
                                      "/share/openssl-" ,version)
 
                       (string-append "--prefix=" out)
-                      (string-append "-Wl,-rpath," lib)))))
+                      (string-append "-Wl,-rpath," lib)
+		      ,@(if (%current-target-system)
+			    '((getenv "CONFIGURE_TARGET_ARCH"))
+			    '())))))
         (add-after 'install 'move-static-libraries
           (lambda* (#:key outputs #:allow-other-keys)
             ;; Move static libraries to the "static" output.
@@ -435,21 +458,26 @@  required structures.")
                    (("^MANDIR[[:blank:]]*=.*$")
                     (string-append "MANDIR = " out "/share/man\n")))
                  #t)))
-        (replace 'configure
-          ;; Override this phase because OpenSSL 1.0 does not understand -rpath.
-          (lambda* (#:key outputs #:allow-other-keys)
-            (let ((out (assoc-ref outputs "out")))
-              (invoke "./config"
-                      "shared"                 ;build shared libraries
-                      "--libdir=lib"
-
-                      ;; The default for this catch-all directory is
-                      ;; PREFIX/ssl.  Change that to something more
-                      ;; conventional.
-                      (string-append "--openssldir=" out
-                                     "/share/openssl-" ,version)
-
-                      (string-append "--prefix=" out)))))
+	   (replace 'configure
+	     ;; Override this phase because OpenSSL 1.0 does not understand -rpath.
+	     (lambda* (#:key outputs #:allow-other-keys)
+	       (let ((out (assoc-ref outputs "out")))
+		 (invoke ,@(if (%current-target-system)
+			       '("./Configure")
+			       '("./config"))
+			 "shared"                 ;build shared libraries
+			 "--libdir=lib"
+
+			 ;; The default for this catch-all directory is
+			 ;; PREFIX/ssl.  Change that to something more
+			 ;; conventional.
+			 (string-append "--openssldir=" out
+					"/share/openssl-" ,version)
+
+			 (string-append "--prefix=" out)
+			 ,@(if (%current-target-system)
+			       '((getenv "CONFIGURE_TARGET_ARCH"))
+			       '())))))
         (delete 'move-extra-documentation)
         (add-after 'install 'move-man3-pages
           (lambda* (#:key outputs #:allow-other-keys)