lol
1{ lib, stdenv, fetchFromGitHub, fetchpatch, pkgconfig, libtool
2, bzip2, zlib, libX11, libXext, libXt, fontconfig, freetype, ghostscript, libjpeg
3, lcms2, openexr, libpng, librsvg, libtiff, libxml2, openjpeg, libwebp
4, ApplicationServices
5, buildPlatform, hostPlatform
6}:
7
8let
9 arch =
10 if stdenv.system == "i686-linux" then "i686"
11 else if stdenv.system == "x86_64-linux" || stdenv.system == "x86_64-darwin" then "x86-64"
12 else if stdenv.system == "armv7l-linux" then "armv7l"
13 else if stdenv.system == "aarch64-linux" then "aarch64"
14 else throw "ImageMagick is not supported on this platform.";
15
16 cfg = {
17 version = "6.9.9-34";
18 sha256 = "0sqrgyfi7i7x1akna95c1qhk9sxxswzm3pkssfi4w6v7bn24g25g";
19 patches = [];
20 }
21 # Freeze version on mingw so we don't need to port the patch too often.
22 # FIXME: This version has multiple security vulnerabilities
23 // lib.optionalAttrs (hostPlatform.isMinGW) {
24 version = "6.9.2-0";
25 sha256 = "17ir8bw1j7g7srqmsz3rx780sgnc21zfn0kwyj78iazrywldx8h7";
26 patches = [(fetchpatch {
27 name = "mingw-build.patch";
28 url = "https://raw.githubusercontent.com/Alexpux/MINGW-packages/"
29 + "01ca03b2a4ef/mingw-w64-imagemagick/002-build-fixes.patch";
30 sha256 = "1pypszlcx2sf7wfi4p37w1y58ck2r8cd5b2wrrwr9rh87p7fy1c0";
31 })];
32 };
33in
34
35stdenv.mkDerivation rec {
36 name = "imagemagick-${version}";
37 inherit (cfg) version;
38
39 src = fetchFromGitHub {
40 owner = "ImageMagick";
41 repo = "ImageMagick";
42 rev = cfg.version;
43 inherit (cfg) sha256;
44 };
45
46 patches = [ ./imagetragick.patch ] ++ cfg.patches;
47
48 outputs = [ "out" "dev" "doc" ]; # bin/ isn't really big
49 outputMan = "out"; # it's tiny
50
51 enableParallelBuilding = true;
52
53 configureFlags =
54 [ "--with-frozenpaths" ]
55 ++ [ "--with-gcc-arch=${arch}" ]
56 ++ lib.optional (librsvg != null) "--with-rsvg"
57 ++ lib.optionals (ghostscript != null)
58 [ "--with-gs-font-dir=${ghostscript}/share/ghostscript/fonts"
59 "--with-gslib"
60 ]
61 ++ lib.optionals (hostPlatform.isMinGW)
62 [ "--enable-static" "--disable-shared" ] # due to libxml2 being without DLLs ATM
63 ;
64
65 nativeBuildInputs = [ pkgconfig libtool ];
66
67 buildInputs =
68 [ zlib fontconfig freetype ghostscript
69 libpng libtiff libxml2
70 ]
71 ++ lib.optionals (!hostPlatform.isMinGW)
72 [ openexr librsvg openjpeg ]
73 ++ lib.optional stdenv.isDarwin ApplicationServices;
74
75 propagatedBuildInputs =
76 [ bzip2 freetype libjpeg lcms2 ]
77 ++ lib.optionals (!hostPlatform.isMinGW)
78 [ libX11 libXext libXt libwebp ]
79 ;
80
81 postInstall = ''
82 (cd "$dev/include" && ln -s ImageMagick* ImageMagick)
83 moveToOutput "bin/*-config" "$dev"
84 moveToOutput "lib/ImageMagick-*/config-Q16" "$dev" # includes configure params
85 for file in "$dev"/bin/*-config; do
86 substituteInPlace "$file" --replace "${pkgconfig}/bin/pkg-config -config" \
87 ${pkgconfig}/bin/pkg-config
88 substituteInPlace "$file" --replace ${pkgconfig}/bin/pkg-config \
89 "PKG_CONFIG_PATH='$dev/lib/pkgconfig' '${pkgconfig}/bin/pkg-config'"
90 done
91 '' + lib.optionalString (ghostscript != null) ''
92 for la in $out/lib/*.la; do
93 sed 's|-lgs|-L${lib.getLib ghostscript}/lib -lgs|' -i $la
94 done
95 '';
96
97 meta = with stdenv.lib; {
98 homepage = http://www.imagemagick.org/;
99 description = "A software suite to create, edit, compose, or convert bitmap images";
100 platforms = platforms.linux ++ platforms.darwin;
101 maintainers = with maintainers; [ the-kenny wkennington ];
102 };
103}