nixpkgs/pkgs/development/libraries/freeimage/default.nix
Artturin e0464e4788 treewide: replace stdenv.is with stdenv.hostPlatform.is
In preparation for the deprecation of `stdenv.isX`.

These shorthands are not conducive to cross-compilation because they
hide the platforms.

Darwin might get cross-compilation for which the continued usage of `stdenv.isDarwin` will get in the way

One example of why this is bad and especially affects compiler packages
https://www.github.com/NixOS/nixpkgs/pull/343059

There are too many files to go through manually but a treewide should
get users thinking when they see a `hostPlatform.isX` in a place where it
doesn't make sense.

```
fd --type f "\.nix" | xargs sd --fixed-strings "stdenv.is" "stdenv.hostPlatform.is"
fd --type f "\.nix" | xargs sd --fixed-strings "stdenv'.is" "stdenv'.hostPlatform.is"
fd --type f "\.nix" | xargs sd --fixed-strings "clangStdenv.is" "clangStdenv.hostPlatform.is"
fd --type f "\.nix" | xargs sd --fixed-strings "gccStdenv.is" "gccStdenv.hostPlatform.is"
fd --type f "\.nix" | xargs sd --fixed-strings "stdenvNoCC.is" "stdenvNoCC.hostPlatform.is"
fd --type f "\.nix" | xargs sd --fixed-strings "inherit (stdenv) is" "inherit (stdenv.hostPlatform) is"
fd --type f "\.nix" | xargs sd --fixed-strings "buildStdenv.is" "buildStdenv.hostPlatform.is"
fd --type f "\.nix" | xargs sd --fixed-strings "effectiveStdenv.is" "effectiveStdenv.hostPlatform.is"
fd --type f "\.nix" | xargs sd --fixed-strings "originalStdenv.is" "originalStdenv.hostPlatform.is"
```
2024-09-25 00:04:37 +03:00

93 lines
2.7 KiB
Nix

{ lib, stdenv, fetchsvn, cctools, libtiff
, libpng, zlib, libwebp, libraw, openexr, openjpeg
, libjpeg, jxrlib, pkg-config
, fixDarwinDylibNames, autoSignDarwinBinariesHook }:
stdenv.mkDerivation (finalAttrs: {
pname = "freeimage";
version = "unstable-2021-11-01";
src = fetchsvn {
url = "svn://svn.code.sf.net/p/freeimage/svn/";
rev = "1900";
sha256 = "rWoNlU/BWKZBPzRb1HqU6T0sT7aK6dpqKPe88+o/4sA=";
};
sourceRoot = "${finalAttrs.src.name}/FreeImage/trunk";
# Ensure that the bundled libraries are not used at all
prePatch = ''
rm -rf Source/Lib* Source/OpenEXR Source/ZLib
'';
patches = [
./unbundle.diff
./libtiff-4.4.0.diff
];
postPatch = ''
# To support cross compilation, use the correct `pkg-config`.
substituteInPlace Makefile.fip \
--replace "pkg-config" "$PKG_CONFIG"
substituteInPlace Makefile.gnu \
--replace "pkg-config" "$PKG_CONFIG"
'' + lib.optionalString (stdenv.hostPlatform.isDarwin && stdenv.hostPlatform.isAarch64) ''
# Upstream Makefile hardcodes i386 and x86_64 architectures only
substituteInPlace Makefile.osx --replace "x86_64" "arm64"
'';
nativeBuildInputs = [
pkg-config
] ++ lib.optionals stdenv.hostPlatform.isDarwin [
cctools
fixDarwinDylibNames
] ++ lib.optionals (stdenv.hostPlatform.isDarwin && stdenv.hostPlatform.isAarch64) [
autoSignDarwinBinariesHook
];
buildInputs = [ libtiff libtiff.dev_private libpng zlib libwebp libraw openexr openjpeg libjpeg libjpeg.dev_private jxrlib ];
postBuild = lib.optionalString (!stdenv.hostPlatform.isDarwin) ''
make -f Makefile.fip
'';
INCDIR = "${placeholder "out"}/include";
INSTALLDIR = "${placeholder "out"}/lib";
preInstall = ''
mkdir -p $INCDIR $INSTALLDIR
''
# Workaround for Makefiles.osx not using ?=
+ lib.optionalString stdenv.hostPlatform.isDarwin ''
makeFlagsArray+=( "INCDIR=$INCDIR" "INSTALLDIR=$INSTALLDIR" )
'';
postInstall = lib.optionalString (!stdenv.hostPlatform.isDarwin) ''
make -f Makefile.fip install
'' + lib.optionalString stdenv.hostPlatform.isDarwin ''
ln -s $out/lib/libfreeimage.3.dylib $out/lib/libfreeimage.dylib
'';
enableParallelBuilding = true;
meta = {
description = "Open Source library for accessing popular graphics image file formats";
homepage = "http://freeimage.sourceforge.net/";
license = "GPL";
knownVulnerabilities = [
"CVE-2021-33367"
"CVE-2021-40262"
"CVE-2021-40263"
"CVE-2021-40264"
"CVE-2021-40265"
"CVE-2021-40266"
"CVE-2023-47992"
"CVE-2023-47993"
"CVE-2023-47994"
"CVE-2023-47995"
"CVE-2023-47996"
];
maintainers = with lib.maintainers; [ l-as ];
platforms = with lib.platforms; unix;
};
})