-
Notifications
You must be signed in to change notification settings - Fork 62
/
perimeter.nix
137 lines (129 loc) · 4.18 KB
/
perimeter.nix
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
{
src,
pkgs,
system,
isStatic ? false,
flag_debug ? false,
flag_sokol,
flag_d3d9
}: let
lib = pkgs.lib;
platform = pkgs.stdenv.hostPlatform;
flag_static = isStatic || platform.isStatic;
flag_dxvk = !platform.isWindows && flag_d3d9;
link_libraries = []
++ lib.optionals flag_dxvk [ "vulkan" ]
++ lib.optionals (platform.isLinux && flag_sokol) [ "GL" ]
++ lib.optionals platform.isLinux [ "asound" ]
;
# Dependencies that CMake fetches with FetchContent
dxvk_git = builtins.fetchGit (if pkgs.stdenv.isDarwin then {
url = "https://github.com/IonAgorria/dxvk-native.git";
rev = "43aedc756cbd620b9ee8b1cf2c17b17cc49b3781";
ref = "master";
} else {
url = "https://github.com/doitsujin/dxvk.git";
rev = "80e075406b1b7d9d2508c9dc05e9745b3d3cf7e2";
ref = "master";
submodules = true;
});
sokol_git = builtins.fetchGit {
url = https://github.com/floooh/sokol;
rev = "7f7cd64c6d9d1d4ed08d88a3879b1d69841bf0a4";
ref = "master";
};
gamemath_git = builtins.fetchGit {
url = "https://github.com/TheAssemblyArmada/GameMath";
rev = "59f7ccd494f7e7c916a784ac26ef266f9f09d78d";
ref = "master";
};
simpleini_git = builtins.fetchGit {
url = "https://github.com/brofield/simpleini";
rev = "7350fcc9228f410309734c3fb6dae2bf513cdd98";
ref = "master";
};
pevents_git = builtins.fetchGit {
url = "https://github.com/neosmart/pevents";
rev = "d6afcbc629cf806f6465238849278e530e1d56fb";
ref = "master";
};
in pkgs.stdenv.mkDerivation {
pname = "perimeter";
version = "3.1.9";
meta = with lib; {
homepage = "https://github.com/KD-lab-Open-Source/Perimeter/";
description = "Perimeter - A open-source RTS game from 2004 by K-D LAB";
license = licenses.gpl3;
maintainers = with maintainers; [];
platforms = [ system ];
};
src = src;
# Build only dependencies
nativeBuildInputs = with pkgs.pkgsBuildHost; [
binutils #For strip
gitMinimal
ninja
pkg-config
cmake
]
++ lib.optionals flag_dxvk [ meson glslang ]
++ lib.optionals flag_sokol [ sokol ];
# Build / Runtime dependencies
buildInputs = with (if flag_static then pkgs.pkgsStatic else pkgs); [
zlib
libbacktrace
boost
ffmpeg
SDL2
SDL2_mixer
SDL2_image
SDL2_net
]
++ lib.optionals (flag_sokol && !platform.isWindows) [ libglvnd ]
++ lib.optionals (platform.isLinux) [ alsa-lib ]
++ lib.optionals (flag_dxvk) [ vulkan-loader ]
;
configurePhase = (lib.optionalString flag_dxvk ''
cp -a ${dxvk_git} dxvk_src
if [[ -f "dxvk_src/subprojects/libdisplay-info/tool/gen-search-table.py" ]]; then
substituteInPlace "dxvk_src/subprojects/libdisplay-info/tool/gen-search-table.py" \
--replace "/usr/bin/env python3" "${lib.getBin pkgs.pkgsBuildHost.python3}/bin/python3"
fi
'') + ''
mkdir build
cmake -S . -B build -G Ninja \
-DOPTION_STATIC_LIB_STD=ON \
-DOPTION_STATIC_BUILD=${if flag_static then "ON" else "OFF"} \
-DOPTION_D3D9=${if flag_d3d9 then "ON" else "OFF"} \
-DOPTION_SOKOL=${if flag_sokol then "ON" else "OFF"} \
-DOPTION_LINK_LIBS="${builtins.concatStringsSep ";" link_libraries}" \
-DFETCHCONTENT_FULLY_DISCONNECTED=True \
-DFETCHCONTENT_SOURCE_DIR_SIMPLEINI=${simpleini_git} \
-DFETCHCONTENT_SOURCE_DIR_GAMEMATH=${gamemath_git} \
-DFETCHCONTENT_SOURCE_DIR_PEVENTS=${pevents_git} \
'' + (lib.optionalString flag_sokol ''
-DFETCHCONTENT_SOURCE_DIR_SOKOL=${sokol_git} \
'') + (lib.optionalString flag_dxvk ''
-DOPTION_DXVK_SOURCE_DIR=$PWD/dxvk_src \
-DCMAKE_SKIP_BUILD_RPATH=ON \
'') + (lib.optionalString (platform.isWindows) ''
-DMINGW=${if platform.isMinGW then "ON" else "OFF"} \
-DCMAKE_BUILD_WITH_INSTALL_RPATH=ON \
'') + ''
-DCMAKE_BUILD_TYPE=${if flag_debug then "Debug" else "Release"}
'';
buildPhase = ''
cd build
ninja
'';
installPhase = (lib.optionalString flag_dxvk ''
mkdir -p $out/lib
cp dxvk-prefix/src/dxvk-build/src/d3d9/libdxvk_d3d9.so $out/lib;
'') + ''
strip -g -x Source/perimeter
mkdir -p $out/bin
install -m755 -D Source/perimeter $out/bin/perimeter
'';
# fixup phase
dontStrip = true;
}