Subject: [bug#38687] [PATCH 1/2] gnu: Add lodepng.

From: Giacomo Leidi <[email-masked]>
Date: Thu, 6 Feb 2020 21:17:12 +0100

* gnu/packages/image.scm (lodepng): New variable.
---
 gnu/packages/image.scm | 58 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 58 insertions(+)

diff --git a/gnu/packages/image.scm b/gnu/packages/image.scm
index 45055858b4..18a51a8773 100644
--- a/gnu/packages/image.scm
+++ b/gnu/packages/image.scm
@@ -23,6 +23,7 @@
 ;;; Copyright © 2018 Pierre-Antoine Rouby <[email-masked]>
 ;;; Copyright © 2018 Alex Vong <[email-masked]>
 ;;; Copyright © 2018 Rutger Helling <[email-masked]>
+;;; Copyright © 2020 Giacomo Leidi <[email-masked]>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -1841,3 +1842,60 @@ using only text tools.
 SNG is implemented by a compiler/decompiler called sng that
 losslessly translates between SNG and PNG.")
     (license license:zlib)))
+
+(define-public lodepng
+  ;; The project doesn't seem to use any
+  ;; kind of meaningful versioning scheme.
+  (let ((commit "5a0dba103893e6b8084be13945a826663917d00a")
+        (revision "1")
+        (version "0.0.0"))
+    (package
+      (name "lodepng")
+      (version (git-version version revision commit))
+      (source (origin
+                (method git-fetch)
+                (uri (git-reference
+                      (url "https://github.com/lvandeve/lodepng")
+                      (commit commit)))
+                (sha256
+                 (base32
+                  "0nvlba82mf4n7xfc3rz2g9wwgnrxpjw64p5dsjmj2r06g5m4l38a"))
+                (file-name (git-file-name name version))))
+      (build-system gnu-build-system)
+      (arguments
+       '(#:phases
+         (modify-phases %standard-phases
+           (delete 'configure)
+           (replace 'build
+             (lambda _
+               (setenv "CXXFLAGS" "-fPIC")
+               (invoke "make" "lodepng.o")
+               (invoke "make" "lodepng_util.o")
+               (invoke "ar" "rv" "liblodepng.a" "lodepng.o" "lodepng_util.o")
+               (invoke "g++" "-fPIC" "-O3"
+                       "-o" "liblodepng.so"
+                       "-shared" "lodepng.o" "lodepng_util.o")
+               #t))
+           (replace 'check
+             (lambda _
+               (invoke "make" "unittest")
+               (invoke "./unittest")
+               #t))
+           (replace 'install
+             (lambda* (#:key outputs #:allow-other-keys)
+               (let* ((out (assoc-ref outputs "out"))
+                      (doc (string-append out "/share/doc"))
+                      (lib (string-append out "/lib"))
+                      (include (string-append out "/include")))
+                 (install-file "lodepng.h" include)
+                 (install-file "lodepng_util.h" include)
+                 (install-file "liblodepng.a" lib)
+                 (install-file "liblodepng.so" lib)
+                 (install-file "README.md" doc)
+                 #t))))))
+      (home-page "https://lodev.org/lodepng/")
+      (synopsis "PNG encoder and decoder in C and C++, without dependencies")
+      (description "LodePNG is a PNG image decoder and encoder, all in one,
+no dependency or linkage required.  It's made for C (ISO C90), and has a C++
+wrapper with a more convenient interface on top.")
+      (license license:zlib))))
-- 
2.25.0