Merge branch 'staging' into core-updates
[jackhill/guix/guix.git] / gnu / packages / netpbm.scm
1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2013, 2015 Andreas Enge <andreas@enge.fr>
3 ;;; Copyright © 2015, 2016 Ludovic Courtès <ludo@gnu.org>
4 ;;; Copyright © 2019 Tobias Geerinckx-Rice <me@tobias.gr>
5 ;;;
6 ;;; This file is part of GNU Guix.
7 ;;;
8 ;;; GNU Guix is free software; you can redistribute it and/or modify it
9 ;;; under the terms of the GNU General Public License as published by
10 ;;; the Free Software Foundation; either version 3 of the License, or (at
11 ;;; your option) any later version.
12 ;;;
13 ;;; GNU Guix is distributed in the hope that it will be useful, but
14 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ;;; GNU General Public License for more details.
17 ;;;
18 ;;; You should have received a copy of the GNU General Public License
19 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
20
21 (define-module (gnu packages netpbm)
22 #:use-module (gnu packages)
23 #:use-module (gnu packages compression)
24 #:use-module (gnu packages flex)
25 #:use-module (gnu packages ghostscript)
26 #:use-module (gnu packages image)
27 #:use-module (gnu packages perl)
28 #:use-module (gnu packages pkg-config)
29 #:use-module (gnu packages python)
30 #:use-module (gnu packages xml)
31 #:use-module (gnu packages xorg)
32 #:use-module (guix build-system gnu)
33 #:use-module ((guix licenses) #:select (gpl2))
34 #:use-module (guix packages)
35 #:use-module (guix svn-download))
36
37 (define-public netpbm
38 (package
39 (name "netpbm")
40 (version "10.78.3")
41 (source (origin
42 (method svn-fetch)
43 ;; At the time of first packaging, the "super-stable" and
44 ;; "stable" versions did not compile with newer libpng;
45 ;; we needed the "advanced" version.
46 ;; The currently highest stable version is 10.47.53,
47 ;; the currently highest advanced version is 10.69.4,
48 ;; svn release 2397.
49 ;; To determine the correct release: "svn log version.mk".
50 (uri (svn-reference
51 (url "http://svn.code.sf.net/p/netpbm/code/advanced")
52 (revision 2965)))
53 (sha256
54 (base32
55 "1k7as9qi1942wyjxpvbf02wg0h4braw44m3m3vvi8sm9y5z1m967"))
56 (patches (search-patches "netpbm-CVE-2017-2586.patch"
57 "netpbm-CVE-2017-2587.patch"))
58 (file-name (string-append name "-" version "-checkout"))
59 (modules '((guix build utils)))
60 (snippet
61 '(begin
62 ;; Remove non-FSDG-compliant code.
63
64 (define-syntax drop
65 (syntax-rules (in)
66 ;; Remove PROGRAM from DIRECTORY/Makefile, and remove
67 ;; DIRECTORY/PROGRAM and DIRECTORY/PROGRAM.c.
68 ((_ program ... in directory)
69 (begin
70 (substitute* (string-append directory "/Makefile")
71 ((program) "") ...)
72
73 (let* ((subdir (string-append directory "/" program))
74 (dot-c (string-append subdir ".c")))
75 (when (file-exists? subdir)
76 (delete-file-recursively subdir))
77 (when (file-exists? dot-c)
78 (delete-file dot-c)))
79
80 ...))))
81
82 ;; Drop advertisement for non-free program.
83 (drop "hpcdtoppm" in "converter/ppm")
84
85 ;; Drop programs without a license, see
86 ;; <http://packages.debian.org/changelogs/pool/main/n/netpbm-free/netpbm-free_10.0-12.2/libnetpbm10.copyright>.
87 (drop "pbmto4425" "pbmtoln03" "pbmtolps" "pbmtopk" "pktopbm"
88 in "converter/pbm")
89 (drop "spottopgm" in "converter/pgm")
90 (drop "ppmtopjxl" in "converter/ppm")
91
92 ;; Remove timestamps from the generated code.
93 (substitute* "buildtools/makepointerman"
94 (("gmctime[(][)]")
95 "\"Thu Jan 1 00:00:00 1970\""))
96 (substitute* "buildtools/stamp-date"
97 (("^DATE=.*")
98 "DATE=\"Thu Jan 01 00:00:00+0000 1970\"\n")
99 (("^USER=.*")
100 "USER=Guix\n"))
101 #t))))
102
103 (build-system gnu-build-system)
104 (inputs `(("ghostscript" ,ghostscript)
105 ("libjpeg" ,libjpeg)
106 ("libpng" ,libpng)
107 ("libtiff" ,libtiff)
108 ("libxml2" ,libxml2)
109 ("xorg-rgb" ,xorg-rgb)
110 ("zlib" ,zlib)))
111 (native-inputs
112 `(("flex" ,flex)
113 ("perl" ,perl)
114 ("pkg-config" ,pkg-config)
115 ("python" ,python-wrapper)))
116 (arguments
117 `(#:phases
118 (modify-phases %standard-phases
119 (replace 'configure
120 (lambda* (#:key inputs outputs #:allow-other-keys)
121 (copy-file "config.mk.in" "config.mk")
122 (chmod "config.mk" #o664)
123 (let ((f (open-file "config.mk" "a")))
124 (display "CC=gcc\n" f)
125 (display "CFLAGS_SHLIB += -fPIC\n" f)
126 (display "TIFFLIB = libtiff.so\n" f)
127 (display "JPEGLIB = libjpeg.so\n" f)
128 (display "ZLIB = libz.so\n" f)
129 (display (string-append "LDFLAGS += -Wl,-rpath=" %output "/lib") f)
130 (close-port f))
131
132 (let ((rgb (string-append (assoc-ref inputs "xorg-rgb")
133 "/share/X11/rgb.txt")))
134 (substitute* "config.mk"
135 (("/usr/share/netpbm/rgb.txt") rgb))
136
137 ;; Our Ghostscript no longer provides the 'gs' command, only
138 ;; 'gsc', so look for that instead.
139 (substitute* "converter/other/pstopnm.c"
140 (("\"%s/gs\"")
141 "\"%s/gsc\"")
142 (("/usr/bin/gs")
143 (string-append (assoc-ref inputs "ghostscript") "/bin/gsc"))))
144 #t))
145 (add-before 'check 'setup-check
146 (lambda _
147 ;; install temporarily into /tmp/netpbm
148 (system* "make" "package")
149 ;; remove test requiring X
150 (substitute* "test/all-in-place.test" (("pamx") ""))
151 ;; do not worry about non-existing file
152 (substitute* "test/all-in-place.test" (("^rm ") "rm -f "))
153 ;; remove four tests that fail for unknown reasons
154 (substitute* "test/Test-Order"
155 (("all-in-place.test") "")
156 (("pnmpsnr.test") "")
157 (("pnmremap1.test") "")
158 (("gif-roundtrip.test") "")
159
160 ;; These two tests started failing in netpbm-10.78.3.
161 (("jpeg-roundtrip.test") "")
162 (("pbmtext.test") "")
163
164 ;; Skip tests that use nonfree programs that we don't build.
165 (("ps-alt-roundtrip.test") "" )
166 (("pbm-misc-converters.test") ""))
167 #t))
168 (replace 'install
169 (lambda* (#:key outputs make-flags #:allow-other-keys)
170 (let ((out (assoc-ref outputs "out")))
171 (apply system* "make" "package"
172 (string-append "pkgdir=" out) make-flags)
173 ;; copy static library
174 (copy-file (string-append out "/link/libnetpbm.a")
175 (string-append out "/lib/libnetpbm.a"))
176 ;; remove superfluous folders and files
177 (system* "rm" "-r" (string-append out "/link"))
178 (system* "rm" "-r" (string-append out "/misc"))
179 (with-directory-excursion out
180 (for-each delete-file
181 '("config_template" "pkginfo" "README"
182 "VERSION")))
183 #t))))))
184 (synopsis "Toolkit for manipulation of images")
185 (description
186 "Netpbm is a toolkit for the manipulation of graphic images, including
187 the conversion of images between a variety of different formats.
188 There are over 300 separate tools in the package including converters for
189 about 100 graphics formats.")
190 (license gpl2)
191 (home-page "http://netpbm.sourceforge.net/")))