summary refs log tree commit diff
path: root/pkgs/games/zandronum/default.nix
blob: ce32e435608b83e6bddca0e667a35df2a9f29500 (plain) (blame)
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
{ stdenv, lib, fetchhg, cmake, pkgconfig, makeWrapper, callPackage
, soundfont-fluid, SDL, libGL, glew, bzip2, zlib, libjpeg, fluidsynth, openssl, gtk2, python3, libgme
, serverOnly ? false
}:

let
  suffix = lib.optionalString serverOnly "-server";
  fmod = callPackage ./fmod.nix { };
  sqlite = callPackage ./sqlite.nix { };
  clientLibPath = lib.makeLibraryPath [ fluidsynth ];

in stdenv.mkDerivation {
  name = "zandronum${suffix}-3.0";

  src = fetchhg {
    url = "https://bitbucket.org/Torr_Samaho/zandronum-stable";
    rev = "dd3c3b57023f";
    sha256 = "1f8pd8d2zjwdp6v9anp9yrkdbfhd2mp7svmnna0jiqgxjw6wkyls";
  };

  # zandronum tries to download sqlite now when running cmake, don't let it

  # it also needs the current mercurial revision info embedded in gitinfo.h
  # otherwise, the client will fail to connect to servers because the
  # protocol version doesn't match.

  patches = [ ./zan_configure_impurity.patch ./add_gitinfo.patch ./dont_update_gitinfo.patch ];

  # I have no idea why would SDL and libjpeg be needed for the server part!
  # But they are.
  buildInputs = [ openssl bzip2 zlib SDL libjpeg sqlite libgme ]
             ++ lib.optionals (!serverOnly) [ libGL glew fmod fluidsynth gtk2 ];

  nativeBuildInputs = [ cmake pkgconfig makeWrapper python3 ];

  preConfigure = ''
    ln -s ${sqlite}/* sqlite/
    sed -ie 's| restrict| _restrict|g' dumb/include/dumb.h \
                                       dumb/src/it/*.c
  '' + lib.optionalString (!serverOnly) ''
    sed -i \
      -e "s@/usr/share/sounds/sf2/@${soundfont-fluid}/share/soundfonts/@g" \
      -e "s@FluidR3_GM.sf2@FluidR3_GM2-2.sf2@g" \
      src/sound/music_fluidsynth_mididevice.cpp
  '';

  cmakeFlags =
    [ "-DFORCE_INTERNAL_GME=OFF" ]
    ++ (if serverOnly
    then [ "-DSERVERONLY=ON" ]
    else [ "-DFMOD_LIBRARY=${fmod}/lib/libfmodex.so" ]);

  enableParallelBuilding = true;

  hardeningDisable = [ "format" ];

  installPhase = ''
    mkdir -p $out/bin
    mkdir -p $out/lib/zandronum
    cp zandronum${suffix} \
       *.pk3 \
       ${lib.optionalString (!serverOnly) "liboutput_sdl.so"} \
       $out/lib/zandronum
    makeWrapper $out/lib/zandronum/zandronum${suffix} $out/bin/zandronum${suffix}
  '';

  postFixup = lib.optionalString (!serverOnly) ''
    patchelf --set-rpath $(patchelf --print-rpath $out/lib/zandronum/zandronum):$out/lib/zandronum:${clientLibPath} \
      $out/lib/zandronum/zandronum
  '';

  passthru = {
    inherit fmod sqlite;
  };

  meta = with stdenv.lib; {
    homepage = http://zandronum.com/;
    description = "Multiplayer oriented port, based off Skulltag, for Doom and Doom II by id Software";
    maintainers = with maintainers; [ lassulus MP2E ];
    license = licenses.unfreeRedistributable;
    platforms = platforms.linux;
  };
}