diff mbox series

[bug#56253] : gnu: vpnc: Fix cross-compilation.

Message ID FLlgKC6siW3VOq_B4lWQxjFA3AAfEeBHTzV6qw0FIAP_isJ8bLu0QF0hr3LNVzfW2lre7jAAb3AHD4UgIpGfGQDdGhtSSYwQ386OVu_U5tE=@jeandudey.tech
State Accepted
Headers show
Series [bug#56253] : gnu: vpnc: Fix cross-compilation. | expand

Checks

Context Check Description
cbaines/comparison success View comparision
cbaines/git branch success View Git branch
cbaines/applying patch fail View Laminar job
cbaines/issue success View issue

Commit Message

Jean Pierre De Jesus DIAZ June 27, 2022, 10:52 a.m. UTC
Fix cross-compilation for `vpnc'.

The error was because the `Makefile' tried to execute the resulting binary and
failed as a result. This is done to generate the manpage.

The solution I found was to compile twice the binary, one for the host and the
other for the target, this way the manpage is generated and installed first and
the binary for the target is built later. When not cross-compiling this is not
done.

The error can be seen by executing:

guix build vpnc \
           --target=aarch64-linux-gnu

I'm not entirely sure that I've made a correct git message, so feel free to
modify it if doesn't match the standards.


—
Jean-Pierre De Jesus DIAZ

Comments

M June 27, 2022, 11:27 a.m. UTC | #1
Jean Pierre De Jesus DIAZ via Guix-patches via schreef op ma 27-06-2022
om 10:52 [+0000]:
> +               (replace 'build
> +                 (lambda* (#:key inputs make-flags parallel-build?
> target
> +                           #:allow-other-keys)
> +                   ;; When cross-compiling, the bash script
> 'libgcrypt-config'
> +                   ;; must be accessible during the configure phase.
> +                   (when target
> +                     (setenv "PATH"
> +                             (string-append
> +                               (dirname
> +                                 (search-input-file inputs
> +                                                    "bin/libgcrypt-
> config"))

It would be simpler to replace 'libgcrypt-config --libs' by 'pkg-config
--libs' (with a substitute*, post-unpack) and likewise for
'libgcrypt-config --libs', to avoid executing a script compiled for
another architecture locally (it works because of a preceding $(shell
..., though doesn't seem great to me).

(Additionally, maybe upstream would be interested in pkg-config which
mostly just works when cross-compiling, in constrast to ...-config
scripts?)

> +           #~(let ((out (assoc-ref %outputs "out")))

If you're using G-exps, you might as well replace (assoc-ref %outputs
"out") by #$output.  Also, there's no configure phase, it has been
removed.


>+                   ;; manpage. This step is not necessary when the target is
>+                   ;; the host.
>+                   (when target
>+                     (apply invoke "make" "vpnc.8" "CC=gcc"
>+                            (if parallel-build?
>+                               (list "-j" (number->string (parallel-job-count)))
>+                               '()))
>+                     (install-file "vpnc.8"
>+                                   (string-append (assoc-ref outputs "out")
>+                                                  "/share/man/man8"))
>+                     (invoke "make" "clean"))))

You can simplify this by adding vpnc itself to the native-inputs (conditional
on %current-target-system to avoid a cycle) and when cross-compiling, copy the
man page from the native input to vpnc.8 (pre-build, instead of replacing build,
then you don't needd to fiddle with parallelism flags or the install phase).

>+                   ;; Remove installation of COPYING as 'install-
license-files
>+                   ;; phase does it with a proper version number.
>+                   (substitute* "Makefile"
>+                     (("install -m644 COPYING.*") "")))))))

Independent change, so for a separate commit.  Also, I don't think it's
worth it to remove the double installation -- we would be deviating
from upstream and at most some KB would be saved but we have automated
depulication.  Or maybe it's nice for consistency, dunno.

>+   (license (list license:gpl2+
>+                  ;; dh.c
>+                  ;; dh.h
>+                  ;; math_group.c
>+                  ;; math_group.h
>+                  license:bsd-2))

Again independent change -- I don't think it was necessary to mention
the file names (but I don't think they have to be removed either). More
precise license information looks nice.

Greetings,
Maxime.
M June 29, 2022, 11:09 a.m. UTC | #2
Maxime Devos schreef op ma 27-06-2022 om 13:27 [+0200]:
> (Additionally, maybe upstream would be interested in pkg-config which
> mostly just works when cross-compiling, in constrast to ...-config
> scripts?)

TBC: those scripts can work, but things go messy if you both have a
native libgcrypt and a cross-compiled libgcrypt.
diff mbox series

Patch

From d9379ceef2a7f6ed7bf49839ed066eca06d2b874 Mon Sep 17 00:00:00 2001
Message-Id: <d9379ceef2a7f6ed7bf49839ed066eca06d2b874.1656326922.git.me@jeandudey.tech>
From: Jean-Pierre De Jesus DIAZ <me@jeandudey.tech>
Date: Mon, 27 Jun 2022 12:41:35 +0200
Subject: [PATCH] gnu: vpnc: Fix cross-compilation.

* gnu/packages/vpn.scm (vpnc): Fix cross-compilation of package. Use
  G-Exps. Remove substitutions in favour of `#:make-flags`. Fix manpage
  generation error when cross-compiling, as the manpage generation
  depends on the executable being built for the host machine it is built
  twice for the host and the target machine, when not cross-compiling
  the package is built only one time. Add bsd-2 to license section and
  list the files as comments that are bsd-2. Remove duplicate
  installation of license files.
---
 gnu/packages/vpn.scm | 95 +++++++++++++++++++++++++++++++++++---------
 1 file changed, 76 insertions(+), 19 deletions(-)

diff --git a/gnu/packages/vpn.scm b/gnu/packages/vpn.scm
index e33821c97f..01f29996f2 100644
--- a/gnu/packages/vpn.scm
+++ b/gnu/packages/vpn.scm
@@ -21,6 +21,7 @@ 
 ;;; Copyright © 2022 Josselin Poiret <josselin.poiret@protonmail.ch>
 ;;; Copyright © 2022 Lu hui <luhux76@gmail.com>
 ;;; Copyright © 2022 Maxim Cournoyer <maxim.cournoyer@gmail.com>
+;;; Copyright © 2022 Jean-Pierre De Jesus DIAZ <me@jeandudey.tech>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -477,25 +478,76 @@  (define-public vpnc
             (sha256 (base32
                      "1128860lis89g1s21hqxvap2nq426c9j4bvgghncc1zj0ays7kj6"))))
    (build-system gnu-build-system)
-   (inputs (list libgcrypt perl vpnc-scripts))
+   ;; libgcrypt and vpnc-scripts are duplicated on both inputs because when
+   ;; cross-compiling we build vpnc for the host (to generate the manpage)
+   ;; and the target system.
+   (native-inputs (list libgcrypt perl vpnc-scripts))
+   (inputs (list libgcrypt vpnc-scripts))
    (arguments
-    `(#:tests? #f ; there is no check target
-      #:phases
-      (modify-phases %standard-phases
-        (add-after 'unpack 'use-store-paths
-          (lambda* (#:key inputs outputs #:allow-other-keys)
-            (let ((out          (assoc-ref outputs "out"))
-                  (vpnc-scripts (assoc-ref inputs  "vpnc-scripts")))
-              (substitute* "config.c"
-                (("/etc/vpnc/vpnc-script")
-                 (string-append vpnc-scripts "/etc/vpnc/vpnc-script")))
-              (substitute* "Makefile"
-                (("ETCDIR=.*")
-                 (string-append "ETCDIR=" out "/etc/vpnc\n"))
-                (("PREFIX=.*")
-                 (string-append "PREFIX=" out "\n")))
-              #t)))
-        (delete 'configure))))          ; no configure script
+     (list #:tests? #f ;; There is no check target
+           #:make-flags
+           #~(let ((out (assoc-ref %outputs "out")))
+               (list (string-append "CC=" #$(cc-for-target))
+                     (string-append "ETCDIR=" out "/etc/vpnc")
+                     (string-append "PREFIX=" out)))
+           #:phases
+           #~(modify-phases %standard-phases
+               (delete 'configure) ;; No configure script.
+               (add-after 'unpack 'use-store-paths
+                 (lambda* (#:key inputs outputs #:allow-other-keys)
+                   (let ((vpnc-scripts (assoc-ref inputs  "vpnc-scripts")))
+                     (substitute* "config.c"
+                       (("/etc/vpnc/vpnc-script")
+                        (string-append vpnc-scripts "/etc/vpnc/vpnc-script"))))))
+               (add-before 'build 'build-manpage
+                 (lambda* (#:key outputs parallel-build? target
+                           #:allow-other-keys)
+                   ;; The Makefile tries to generate the manpage by executing
+                   ;; the resulting binary, so, when cross-compiling the vpnc
+                   ;; package must be built first on the host to generate the
+                   ;; manpage. This step is not necessary when the target is
+                   ;; the host.
+                   (when target
+                     (apply invoke "make" "vpnc.8" "CC=gcc"
+                            (if parallel-build?
+                               (list "-j" (number->string (parallel-job-count)))
+                               '()))
+                     (install-file "vpnc.8"
+                                   (string-append (assoc-ref outputs "out")
+                                                  "/share/man/man8"))
+                     (invoke "make" "clean"))))
+               (replace 'build
+                 (lambda* (#:key inputs make-flags parallel-build? target
+                           #:allow-other-keys)
+                   ;; When cross-compiling, the bash script 'libgcrypt-config'
+                   ;; must be accessible during the configure phase.
+                   (when target
+                     (setenv "PATH"
+                             (string-append
+                               (dirname
+                                 (search-input-file inputs
+                                                    "bin/libgcrypt-config"))
+                               ":" (getenv "PATH"))))
+                   (apply invoke "make" "vpnc" "cisco-decrypt" "vpnc-script"
+                          (append make-flags
+                                  ;; Build manpage only if not cross-compiling.
+                                  (if (not target) (list "vpnc.8") '())
+                                  (if parallel-build?
+                                    (list "-j" (number->string (parallel-job-count)))
+                                    '())))))
+               (add-before 'install 'patch-install
+                 (lambda* (#:key target #:allow-other-keys)
+                   ;; When cross-compiling the manpage is already installed by
+                   ;; this point.
+                   (when target
+                     (substitute* "Makefile"
+                       (("all : \\$\\(BINS\\) vpnc\\.8 vpnc-script")
+                        "all : $(BINS) vpnc-script")
+                       (("install -m644 vpnc\\.8.*") "")))
+                   ;; Remove installation of COPYING as 'install-license-files
+                   ;; phase does it with a proper version number.
+                   (substitute* "Makefile"
+                     (("install -m644 COPYING.*") "")))))))
    (synopsis "Client for Cisco VPN concentrators")
    (description
     "vpnc is a VPN client compatible with Cisco's EasyVPN equipment.
@@ -503,7 +555,12 @@  (define-public vpnc
 shared-secret IPSec authentication with Xauth, AES (256, 192, 128), 3DES,
 1DES, MD5, SHA1, DH1/2/5 and IP tunneling.  It runs entirely in userspace.
 Only \"Universal TUN/TAP device driver support\" is needed in the kernel.")
-   (license license:gpl2+) ; some file are bsd-2, see COPYING
+   (license (list license:gpl2+
+                  ;; dh.c
+                  ;; dh.h
+                  ;; math_group.c
+                  ;; math_group.h
+                  license:bsd-2))
    (home-page "https://www.unix-ag.uni-kl.de/~massar/vpnc/")))
 
 (define-public vpnc-scripts
-- 
2.36.1