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

Message ID GLlJUa75SYS6xoV29rej4ulOY7ojlZM7_CrnbERoAxpINvvOytcrLYkp6BWh8ABerbqWLR1pc41-yg5Ru5eNTFknSiHxLL2UL6fQD5p9Nww=@jeandudey.tech
State New
Headers
Series [bug#56253] : gnu: vpnc: Fix cross-compilation. |

Commit Message

Jean Pierre De Jesus DIAZ June 29, 2022, 11:04 a.m. UTC
  Thanks for the review!

Did not know that packages could have themselves as an input.
Added it and modified the phases accordingly and made the use
of `pkg-config' in the build.

Made a separate patch for the license change.

And, I will try to push of `pkg-config' usage on upstream by
sending a patch (and hopefully reduce substitutions on the
package).

—
Jean-Pierre De Jesus DIAZ
  

Comments

Maxime Devos June 29, 2022, 11:09 a.m. UTC | #1
Jean Pierre De Jesus DIAZ via Guix-patches via schreef op wo 29-06-2022
om 11:04 [+0000]:
> +                          (cflags (string-append pkg-config
> +                                                 " --cflags"
> +                                                 " liggcrypt"))

liggcrypt -> libgcrypt?
  
Maxime Devos June 29, 2022, 6:35 p.m. UTC | #2
Jean Pierre De Jesus DIAZ schreef op wo 29-06-2022 om 11:15 [+0000]:
> Sorry, fixed the typo and re-built again to verify and everything is
> in order.

Was just a typo, no need for apologies :).

It looks good to me (though TBC: didn't compile it myself) but you seem
to have forgotten to keep 56253@debbugs.gnu.org in CC, so people that
can actually commit it haven't seen it, so you'll have to resend it. 
(FWIW, reportedly the ‘reply all’ options of e-mail clients take care
of that)

Greeitngs,
Maxime.
  

Patch

From e4c1daacb42b56099ccee3f80ec022980f19efc1 Mon Sep 17 00:00:00 2001
Message-Id: <e4c1daacb42b56099ccee3f80ec022980f19efc1.1656500364.git.me@jeandudey.tech>
From: Jean-Pierre De Jesus DIAZ <me@jeandudey.tech>
Date: Wed, 29 Jun 2022 12:51:55 +0200
Subject: [PATCH 1/2] gnu: vpnc: Fix cross-compilation.

* gnu/packages/vpn.scm (vpnc): Fix cross-compilation.
  [native-inputs]: Add conditional input of `this-package' (vpnc)
  to reuse the man page and add `pkg-config'.
  [arguments]: Use G-Expressions.
  [arguments]: Make use of `make-flags' instead of using substitutions.
  [arguments]: Remove unneeded deletion of `configure'.
  [arguments]: Use `pkg-config' to search for libgcrypt.
---
 gnu/packages/vpn.scm | 80 ++++++++++++++++++++++++++++++++++----------
 1 file changed, 62 insertions(+), 18 deletions(-)

diff --git a/gnu/packages/vpn.scm b/gnu/packages/vpn.scm
index e33821c97f..c4399f232b 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,68 @@  (define-public vpnc
             (sha256 (base32
                      "1128860lis89g1s21hqxvap2nq426c9j4bvgghncc1zj0ays7kj6"))))
    (build-system gnu-build-system)
-   (inputs (list libgcrypt perl vpnc-scripts))
+   (native-inputs (append (list perl pkg-config vpnc-scripts)
+                          (if (%current-target-system)
+                            (list this-package)
+                            '())))
+   (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
+           #~(list (string-append "CC=" #$(cc-for-target))
+                   (string-append "ETCDIR=" #$output "/etc/vpnc")
+                   (string-append "PREFIX=" #$output))
+           #:phases
+           #~(modify-phases %standard-phases
+               (delete 'configure) ;; No configure script.
+               (add-after 'unpack 'use-store-paths
+                 (lambda* (#:key inputs #: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-after 'unpack 'patch-Makefile
+                 (lambda* (#:key target #:allow-other-keys)
+                   (let* ((pkg-config #$(pkg-config-for-target))
+                          (includedir (string-append pkg-config
+                                                     " --variable=includedir"
+                                                     " libgcrypt"))
+                          (cflags (string-append pkg-config
+                                                 " --cflags"
+                                                 " liggcrypt"))
+                          (libdir (string-append pkg-config
+                                                 " --variable=libdir"
+                                                 " libgcrypt"))
+                          (libs (string-append pkg-config
+                                               " --libs"
+                                               " libgcrypt")))
+                     (substitute* "Makefile"
+                       (("\\$\\(shell libgcrypt-config --cflags\\)")
+                        (string-append "-I$(shell " includedir ") "
+                                       "$(shell " cflags ")"))
+                       (("\\$\\(shell libgcrypt-config --libs\\)")
+                        (string-append
+                          "-L$(shell " libdir ") "
+                          "$(shell " libs ")")))
+                     ;; When cross-compiling the manpage can't be generated as the
+                     ;; Makefile needs to execute the resulting `vpnc' binary.
+                     (when target
+                       (substitute* "Makefile"
+                         (("all : \\$\\(BINS\\) vpnc\\.8 vpnc-script")
+                          "all : $(BINS) vpnc-script")
+                         (("install -m644 vpnc\\.8.*") ""))))))
+               (add-after 'unpack 'install-manpage
+                 (lambda* (#:key native-inputs inputs target
+                           #:allow-other-keys)
+                   ;; As the manpage is not generated. Instead install it from
+                   ;; the input vpnc package.
+                   (when target
+                     (let* ((vpnc (assoc-ref native-inputs "vpnc"))
+                            (man (string-append vpnc
+                                                "/share/man/man8/vpnc.8.gz"))
+                            (output (string-append #$output "/share/man/man8")))
+                       (install-file man output))))))))
    (synopsis "Client for Cisco VPN concentrators")
    (description
     "vpnc is a VPN client compatible with Cisco's EasyVPN equipment.
-- 
2.36.1