about summary refs log tree commit diff
path: root/pkgs/games/dwarf-fortress/unfuck.nix
blob: a1baa2d83f757b37093de8b1c43311bb48e2e904 (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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
{ stdenv
, lib
, fetchFromGitHub
, fetchpatch
, cmake
, libGL
, libSM
, SDL
, SDL_image
, SDL_ttf
, glew
, openalSoft
, ncurses
, glib
, gtk2
, gtk3
, libsndfile
, zlib
, dfVersion
, pkg-config
}:

let
  inherit (lib)
    getAttr
    hasAttr
    licenses
    maintainers
    platforms
    versionOlder
    ;

  unfuck-releases = {
    "0.43.05" = {
      unfuckRelease = "0.43.05";
      hash = "sha256-4iLVrKmlVdvBICb8NLe/U7pHtL372CGDkxt/2lf2bZw=";
    };
    "0.44.05" = {
      unfuckRelease = "0.44.05";
      hash = "sha256-iwR9st4VsPJBn7cKH/cy8YS6Tcw8J+lMJK9/9Qgl0gM=";
    };
    "0.44.09" = {
      unfuckRelease = "0.44.09";
      hash = "sha256-9W9qON0QEjfXe2XzRvseixc+YznPzDQdcId08dEGF40=";
    };
    "0.44.10" = {
      unfuckRelease = "0.44.10";
      hash = "sha256-8ldEFcf5zPRdC/yXgMByeCC0pqZprreITIetKDpOYW0=";
    };
    "0.44.11" = {
      unfuckRelease = "0.44.11.1";
      hash = "sha256-f9vDe3Q3Vl2hFLCPSzYtqyv9rLKBKEnARZTu0MKaX88=";
    };
    "0.44.12" = {
      unfuckRelease = "0.44.12";
      hash = "sha256-f9vDe3Q3Vl2hFLCPSzYtqyv9rLKBKEnARZTu0MKaX88=";
    };
    "0.47.01" = {
      unfuckRelease = "0.47.01";
      hash = "sha256-k8yrcJVHlHNlmOL2kEPTftSfx4mXO35TcS0zAvFYu4c=";
    };
    "0.47.02" = {
      unfuckRelease = "0.47.01";
      hash = "sha256-k8yrcJVHlHNlmOL2kEPTftSfx4mXO35TcS0zAvFYu4c=";
    };
    "0.47.04" = {
      unfuckRelease = "0.47.04";
      hash = "sha256-KRr0A/2zANAOSDeP8V9tYe7tVO2jBLzU+TF6vTpISfE=";
    };
    "0.47.05" = {
      unfuckRelease = "0.47.05-final";
      hash = "sha256-kBdzU6KDpODOBP9XHM7lQRIEWUGOj838vXF1FbSr0Xw=";
    };
  };

  release =
    if hasAttr dfVersion unfuck-releases
    then getAttr dfVersion unfuck-releases
    else throw "[unfuck] Unknown Dwarf Fortress version: ${dfVersion}";
in

stdenv.mkDerivation {
  pname = "dwarf_fortress_unfuck";
  version = release.unfuckRelease;

  src = fetchFromGitHub {
    owner = "svenstaro";
    repo = "dwarf_fortress_unfuck";
    rev = release.unfuckRelease;
    inherit (release) hash;
  };

  patches = lib.optionals (versionOlder release.unfuckRelease "0.47.05") [(
    fetchpatch {
      name = "fix-noreturn-returning.patch";
      url = "https://github.com/svenstaro/dwarf_fortress_unfuck/commit/6dcfe5ae869fddd51940c6c37a95f7bc639f4389.patch";
      hash = "sha256-b9eI3iR7dmFqCrktPyn6QJ9U2A/7LvfYRS+vE3BOaqk=";
    }
  )];

  postPatch = ''
    # https://github.com/svenstaro/dwarf_fortress_unfuck/pull/27
    substituteInPlace CMakeLists.txt --replace \''${GLEW_LIBRARIES} GLEW::glew
  '';

  cmakeFlags = [
    "-DGTK2_GLIBCONFIG_INCLUDE_DIR=${glib.out}/lib/glib-2.0/include"
    "-DGTK2_GDKCONFIG_INCLUDE_DIR=${gtk2.out}/lib/gtk-2.0/include"
  ];

  nativeBuildInputs = [ cmake pkg-config ];
  buildInputs = [
    libSM
    SDL
    SDL_image
    SDL_ttf
    glew
    openalSoft
    ncurses
    libsndfile
    zlib
    libGL
  ]
  # switched to gtk3 in 0.47.05
  ++ (if versionOlder release.unfuckRelease "0.47.05" then [
    gtk2
  ] else [
    gtk3
  ]);

  # Don't strip unused symbols; dfhack hooks into some of them.
  dontStrip = true;

  installPhase = ''
    install -D -m755 ../build/libgraphics.so $out/lib/libgraphics.so
  '';

  # Breaks dfhack because of inlining.
  hardeningDisable = [ "fortify" ];

  passthru = { inherit dfVersion; };

  meta = {
    description = "Unfucked multimedia layer for Dwarf Fortress";
    homepage = "https://github.com/svenstaro/dwarf_fortress_unfuck";
    license = licenses.free;
    platforms = platforms.linux;
    maintainers = with maintainers; [ abbradar numinit ];
  };
}