aboutsummaryrefslogtreecommitdiff
path: root/srcds-pkgs/vtflib-strata/default.nix
blob: 6772426141f406998f0353ec0914e1ad583a3fe8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
{ lib, stdenv, fetchFromGitHub, runCommand
, cmake, compressonator-sdk
}:
stdenv.mkDerivation rec {
  pname = "vtflib-strata";
  version = "2024-05-31";
  
  src = let
    cmplibs = "CMP_Compressonator" + lib.optionalString (!stdenv.isAarch64)
      " CMP_Core CMP_Core_SSE CMP_Core_AVX CMP_Core_AVX512";
    osrc = fetchFromGitHub {
      owner = "StrataSource";
      repo = "vtflib";
      rev = "418b1fc341f0912c86fb31867c91dbfd19beff66";
      hash = "sha256-/oSHgI2F/IJRHVoxq2emfzzTI4fM4Co3V49+GU6ZKbQ=";
    };
  in runCommand "vtflib-strata-source-revendored" {} ''
    cp -r ${osrc} $out
    chmod -R +w $out

    sed -E -i 's/_?stricmp/strcasecmp/g' \
      $out/VTFLib/VMT{Wrapper,GroupNode}.cpp
    sed -i 's/--no-undefined/-undefined,error/' \
      $out/CMakeLists.txt
    sed -i 's/CMP_Compressonator/${cmplibs}/' \
      $out/CMakeLists.txt
    cp ${compressonator-sdk}/lib/libCMP_*.a \
      $out/thirdparty/lib/x64/
    cp ${compressonator-sdk}/include/compressonator.h \
      $out/thirdparty/include/Compressonator.h
    
    chmod -R -w $out
  '';
  
  postPatch = ''
    cat ${./CMakeLists.txt.append} >> ./CMakeLists.txt
    cp ${./vtflib.pc.in} ./vtflib.pc.in
  '';
  
  nativeBuildInputs = [ cmake ];
  
  installPhase = ''
    runHook preInstall
    mkdir -p $out
    cmake --install .
    runHook postInstall
  '';

  meta = {
    homepage = src.url;
    description = "C and C++ API for reading and writing Valve VTF and VMT format image files";
    license = with lib.licenses; [ lgpl2 gpl2 ];
    platforms = lib.platforms.unix;
  };
}