Subject: [bug#37027] [PATCH] gnu: zlib: Add support for MinGW targets.

From: David Thompson <[email-masked]>
Date: Wed, 14 Aug 2019 08:58:53 -0400

---
 gnu/packages/compression.scm | 55 +++++++++++++++++++++++-------------
 1 file changed, 36 insertions(+), 19 deletions(-)

diff --git a/gnu/packages/compression.scm b/gnu/packages/compression.scm
index 9834fcbe63..092eb4a54a 100644
--- a/gnu/packages/compression.scm
+++ b/gnu/packages/compression.scm
@@ -87,26 +87,43 @@
     (arguments
      `(#:phases
        (modify-phases %standard-phases
-         (replace 'configure
-           (lambda* (#:key outputs #:allow-other-keys)
-             ;; Zlib's home-made `configure' fails when passed
-             ;; extra flags like `--enable-fast-install', so we need to
-             ;; invoke it with just what it understand.
-             (let ((out (assoc-ref outputs "out")))
-               ;; 'configure' doesn't understand '--host'.
-               ,@(if (%current-target-system)
-                     `((setenv "CHOST" ,(%current-target-system)))
-                     '())
-               (invoke "./configure"
-                       (string-append "--prefix=" out)))))
+         ,@(if (target-mingw?)
+               `((delete 'configure)
+                 (add-before 'install 'set-install-paths
+                             (lambda* (#:key outputs #:allow-other-keys)
+                               (let ((out (assoc-ref outputs "out")))
+                                 (setenv "INCLUDE_PATH" (string-append out "/include"))
+                                 (setenv "LIBRARY_PATH" (string-append out "/lib"))
+                                 (setenv "BINARY_PATH" (string-append out "/bin"))
+                                 #t))))
+               `((replace 'configure
+                          (lambda* (#:key outputs #:allow-other-keys)
+                            ;; Zlib's home-made `configure' fails when passed
+                            ;; extra flags like `--enable-fast-install', so we need to
+                            ;; invoke it with just what it understand.
+                            (let ((out (assoc-ref outputs "out")))
+                              ;; 'configure' doesn't understand '--host'.
+                              ,@(if (%current-target-system)
+                                    `((setenv "CHOST" ,(%current-target-system)))
+                                    '())
+                              (invoke "./configure"
+                                      (string-append "--prefix=" out)))))))
          (add-after 'install 'move-static-library
-           (lambda* (#:key outputs #:allow-other-keys)
-             (let ((out (assoc-ref outputs "out"))
-                   (static (assoc-ref outputs "static")))
-               (with-directory-excursion (string-append out "/lib")
-                 (install-file "libz.a" (string-append static "/lib"))
-                 (delete-file "libz.a")
-                 #t)))))))
+                    (lambda* (#:key outputs #:allow-other-keys)
+                      (let ((out (assoc-ref outputs "out"))
+                            (static (assoc-ref outputs "static")))
+                        (with-directory-excursion (string-append out "/lib")
+                                                  (install-file "libz.a" (string-append static "/lib"))
+                                                  (delete-file "libz.a")
+                                                  #t)))))
+       ,@(if (target-mingw?)
+             `(#:make-flags
+               '("-fwin32/Makefile.gcc"
+                 "SHARED_MODE=1"
+                 ,(string-append "CC=" (%current-target-system) "-gcc")
+                 ,(string-append "RC=" (%current-target-system) "-windres")
+                 ,(string-append "AR=" (%current-target-system) "-ar")))
+             '())))
     (home-page "https://zlib.net/")
     (synopsis "Compression library")
     (description
-- 
2.17.1