nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1{ lib, stdenv, fetchsvn, darwin, libtiff
2, libpng, zlib, libwebp, libraw, openexr, openjpeg
3, libjpeg, jxrlib, pkg-config
4, fixDarwinDylibNames }:
5
6stdenv.mkDerivation {
7 pname = "freeimage";
8 version = "unstable-2021-11-01";
9
10 src = fetchsvn {
11 url = "svn://svn.code.sf.net/p/freeimage/svn/";
12 rev = "1900";
13 sha256 = "rWoNlU/BWKZBPzRb1HqU6T0sT7aK6dpqKPe88+o/4sA=";
14 };
15 sourceRoot = "svn-r1900/FreeImage/trunk";
16
17 # Ensure that the bundled libraries are not used at all
18 prePatch = "rm -rf Source/Lib* Source/OpenEXR Source/ZLib";
19 patches = [ ./unbundle.diff ];
20
21 postPatch = ''
22 # To support cross compilation, use the correct `pkg-config`.
23 substituteInPlace Makefile.fip \
24 --replace "pkg-config" "$PKG_CONFIG"
25 substituteInPlace Makefile.gnu \
26 --replace "pkg-config" "$PKG_CONFIG"
27 '' + lib.optionalString (stdenv.isDarwin && stdenv.isAarch64) ''
28 # Upstream Makefile hardcodes i386 and x86_64 architectures only
29 substituteInPlace Makefile.osx --replace "x86_64" "arm64"
30 '';
31
32 nativeBuildInputs = [
33 pkg-config
34 ] ++ lib.optionals stdenv.isDarwin [
35 darwin.cctools
36 fixDarwinDylibNames
37 ];
38 buildInputs = [ libtiff libtiff.dev_private libpng zlib libwebp libraw openexr openjpeg libjpeg libjpeg.dev_private jxrlib ];
39
40 postBuild = lib.optionalString (!stdenv.isDarwin) ''
41 make -f Makefile.fip
42 '';
43
44 INCDIR = "${placeholder "out"}/include";
45 INSTALLDIR = "${placeholder "out"}/lib";
46
47 preInstall = ''
48 mkdir -p $INCDIR $INSTALLDIR
49 ''
50 # Workaround for Makefiles.osx not using ?=
51 + lib.optionalString stdenv.isDarwin ''
52 makeFlagsArray+=( "INCDIR=$INCDIR" "INSTALLDIR=$INSTALLDIR" )
53 '';
54
55 postInstall = lib.optionalString (!stdenv.isDarwin) ''
56 make -f Makefile.fip install
57 '' + lib.optionalString stdenv.isDarwin ''
58 ln -s $out/lib/libfreeimage.3.dylib $out/lib/libfreeimage.dylib
59 '';
60
61 enableParallelBuilding = true;
62
63 meta = {
64 description = "Open Source library for accessing popular graphics image file formats";
65 homepage = "http://freeimage.sourceforge.net/";
66 license = "GPL";
67 maintainers = with lib.maintainers; [viric l-as];
68 platforms = with lib.platforms; unix;
69 };
70}