1{ stdenv, fetchurl, unzip, darwin }:
2
3stdenv.mkDerivation {
4 name = "freeimage-3.17.0";
5
6 src = fetchurl {
7 url = mirror://sourceforge/freeimage/FreeImage3170.zip;
8 sha256 = "12bz57asdcfsz3zr9i9nska0fb6h3z2aizy412qjqkixkginbz7v";
9 };
10
11 patches = let
12 patchURL = https://anonscm.debian.org/cgit/debian-science/packages/freeimage.git/plain/debian/patches;
13 in [
14 (fetchurl {
15 url = patchURL + "/Fix-CVE-2015-0852.patch";
16 sha256 = "1vxdck4i5qi5j6i3cjja0gfy79mmbf0lq2qdrnqdsl4kclbvw2c8";
17 })
18 (fetchurl {
19 url = patchURL + "/Fix-CVE-2016-5684.patch";
20 sha256 = "14ffgqbnwg28r6sjvm3z89zbnnm9ghbc81hdhrzxlyk3vwvd6cw3";
21 })
22 ];
23
24 buildInputs = [ unzip ] ++ stdenv.lib.optional stdenv.isDarwin darwin.cctools;
25
26 prePatch = if stdenv.isDarwin
27 then ''
28 sed -e 's/gcc-4.0/clang/g' \
29 -e 's/g++-4.0/clang++/g' \
30 -e 's/COMPILERFLAGS = -Os -fexceptions -fvisibility=hidden -DNO_LCMS/COMPILERFLAGS = -Os -fexceptions -fvisibility=hidden -DNO_LCMS -D__ANSI__/' \
31 -e "s|PREFIX = /usr/local|PREFIX = $out|" \
32 -e 's|-Wl,-syslibroot /Developer/SDKs/MacOSX10.5.sdk||g' \
33 -e 's|-Wl,-syslibroot /Developer/SDKs/MacOSX10.6.sdk||g' \
34 -e 's|-isysroot /Developer/SDKs/MacOSX10.6.sdk||g' \
35 -e 's|-isysroot /Developer/SDKs/MacOSX10.5.sdk||g' \
36 -e 's| $(STATICLIB)-ppc $(STATICLIB)-i386||g' \
37 -e 's| $(SHAREDLIB)-ppc $(SHAREDLIB)-i386||g' \
38 -e 's| install -d -m 755 -o root -g wheel $(INCDIR) $(INSTALLDIR)||' \
39 -e 's| -m 644 -o root -g wheel||g' \
40 -i ./Makefile.osx
41 # Fix LibJXR performance timers
42 sed 's|^SRCS = \(.*\)$|SRCS = \1 Source/LibJXR/image/sys/perfTimerANSI.c|' -i ./Makefile.srcs
43 ''
44 else ''
45 sed -e s@/usr/@$out/@ \
46 -e 's@-o root -g root@@' \
47 -e 's@ldconfig@echo not running ldconfig@' \
48 -i Makefile.gnu Makefile.fip
49 # Fix gcc 5.1 macro problems
50 # https://chromium.googlesource.com/webm/libwebp/+/eebaf97f5a1cb713d81d311308d8a48c124e5aef%5E!/
51 sed -i -e 's/"\(#[^"]*\)"/" \1 "/g' Source/LibWebP/src/dsp/*
52 '';
53
54 postBuild = stdenv.lib.optionalString (!stdenv.isDarwin) "make -f Makefile.fip";
55 preInstall = "mkdir -p $out/include $out/lib";
56 postInstall = stdenv.lib.optionalString (!stdenv.isDarwin) "make -f Makefile.fip install";
57
58 NIX_CFLAGS_COMPILE = "-Wno-narrowing";
59
60 meta = {
61 description = "Open Source library for accessing popular graphics image file formats";
62 homepage = http://freeimage.sourceforge.net/;
63 license = "GPL";
64 maintainers = with stdenv.lib.maintainers; [viric];
65 platforms = with stdenv.lib.platforms; unix;
66 };
67}