ttaenc: init at 3.4.1 (#238757)
[NixPkgs.git] / pkgs / games / 0ad / game.nix
blob7f41d04321a8d400472ed5ea9f8f53a02f8e63fe
2   stdenv,
3   lib,
4   fetchpatch,
5   fetchpatch2,
6   perl,
7   fetchurl,
8   python3,
9   fmt,
10   libidn,
11   pkg-config,
12   spidermonkey_78,
13   boost,
14   icu,
15   libxml2,
16   libpng,
17   libsodium,
18   libjpeg,
19   zlib,
20   curl,
21   libogg,
22   libvorbis,
23   enet,
24   miniupnpc,
25   openal,
26   libGLU,
27   libGL,
28   xorgproto,
29   libX11,
30   libXcursor,
31   nspr,
32   SDL2,
33   gloox,
34   nvidia-texture-tools,
35   freetype,
36   withEditor ? true,
37   wxGTK,
40 # You can find more instructions on how to build 0ad here:
41 #    https://trac.wildfiregames.com/wiki/BuildInstructions
43 let
44   # the game requires a special version 78.6.0 of spidermonkey, otherwise
45   # we get compilation errors. We override the src attribute of spidermonkey_78
46   # in order to reuse that declartion, while giving it a different source input.
47   spidermonkey_78_6 = spidermonkey_78.overrideAttrs (old: rec {
48     version = "78.6.0";
49     src = fetchurl {
50       url = "mirror://mozilla/firefox/releases/${version}esr/source/firefox-${version}esr.source.tar.xz";
51       sha256 = "0lyg65v380j8i2lrylwz8a5ya80822l8vcnlx3dfqpd3s6zzjsay";
52     };
53     patches = (old.patches or [ ]) ++ [
54       ./spidermonkey-cargo-toml.patch
55     ];
56   });
58 stdenv.mkDerivation rec {
59   pname = "0ad";
60   version = "0.0.26";
62   src = fetchurl {
63     url = "http://releases.wildfiregames.com/0ad-${version}-alpha-unix-build.tar.xz";
64     sha256 = "Lhxt9+MxLnfF+CeIZkz/w6eNO/YGBsAAOSdeHRPA7ks=";
65   };
67   nativeBuildInputs = [
68     python3
69     perl
70     pkg-config
71   ];
73   buildInputs = [
74     spidermonkey_78_6
75     boost
76     icu
77     libxml2
78     libpng
79     libjpeg
80     zlib
81     curl
82     libogg
83     libvorbis
84     enet
85     miniupnpc
86     openal
87     libidn
88     libGLU
89     libGL
90     xorgproto
91     libX11
92     libXcursor
93     nspr
94     SDL2
95     gloox
96     nvidia-texture-tools
97     libsodium
98     fmt
99     freetype
100   ] ++ lib.optional withEditor wxGTK;
102   env.NIX_CFLAGS_COMPILE = toString [
103     "-I${xorgproto}/include"
104     "-I${libX11.dev}/include"
105     "-I${libXcursor.dev}/include"
106     "-I${SDL2}/include/SDL2"
107     "-I${fmt.dev}/include"
108     "-I${nvidia-texture-tools.dev}/include"
109   ];
111   NIX_CFLAGS_LINK = toString [
112     "-L${nvidia-texture-tools.lib}/lib/static"
113   ];
115   patches = [
116     ./rootdir_env.patch
118     # Fix build with libxml v2.12
119     # FIXME: Remove with next package update
120     (fetchpatch {
121       name = "libxml-2.12-fix.patch";
122       url = "https://github.com/0ad/0ad/commit/d242631245edb66816ef9960bdb2c61b68e56cec.patch";
123       hash = "sha256-Ik8ThkewB7wyTPTI7Y6k88SqpWUulXK698tevfSBr6I=";
124     })
125     # Fix build with GCC 13
126     # FIXME: Remove with next package update
127     (fetchpatch {
128       name = "gcc-13-fix.patch";
129       url = "https://github.com/0ad/0ad/commit/093e1eb23519ab4a4633a999a555a58e4fd5343e.patch";
130       hash = "sha256-NuWO64narU1JID/F3cj7lJKjo96XR7gSW0w8I3/hhuw=";
131     })
132     # Fix build with miniupnpc 2.2.8
133     # https://github.com/0ad/0ad/pull/45
134     (fetchpatch2 {
135       url = "https://github.com/0ad/0ad/commit/1575580bbc5278576693f3fbbb32de0b306aa27e.patch?full_index=1";
136       hash = "sha256-iXiUYTJCWwJpb2U3P58jTV4OpyW6quofu8Jq6xNEq48=";
137     })
138   ];
140   configurePhase = ''
141     # Delete shipped libraries which we don't need.
142     rm -rf libraries/source/{enet,miniupnpc,nvtt,spidermonkey}
144     # Update Makefiles
145     pushd build/workspaces
146     ./update-workspaces.sh \
147       --with-system-nvtt \
148       --with-system-mozjs \
149       ${lib.optionalString withEditor "--enable-atlas"} \
150       --bindir="$out"/bin \
151       --libdir="$out"/lib/0ad \
152       --without-tests \
153       -j $NIX_BUILD_CORES
154     popd
156     # Move to the build directory.
157     pushd build/workspaces/gcc
158   '';
160   enableParallelBuilding = true;
162   installPhase = ''
163     popd
165     # Copy executables.
166     install -Dm755 binaries/system/pyrogenesis "$out"/bin/0ad
167     ${lib.optionalString withEditor ''
168       install -Dm755 binaries/system/ActorEditor "$out"/bin/ActorEditor
169     ''}
171     # Copy l10n data.
172     install -Dm755 -t $out/share/0ad/data/l10n binaries/data/l10n/*
174     # Copy libraries.
175     install -Dm644 -t $out/lib/0ad        binaries/system/*.so
177     # Copy icon.
178     install -D build/resources/0ad.png     $out/share/icons/hicolor/128x128/apps/0ad.png
179     install -D build/resources/0ad.desktop $out/share/applications/0ad.desktop
180   '';
182   meta = with lib; {
183     description = "Free, open-source game of ancient warfare";
184     homepage = "https://play0ad.com/";
185     license = with licenses; [
186       gpl2Plus
187       lgpl21
188       mit
189       cc-by-sa-30
190       licenses.zlib # otherwise masked by pkgs.zlib
191     ];
192     maintainers = with maintainers; [ chvp ];
193     platforms = subtractLists platforms.i686 platforms.linux;
194     mainProgram = "0ad";
195   };