git.iko.soy/typeable/nixpkgs
on master help sign in
zeroad: refactor, split data from binaries
commit5eddbc10c9abce952d1a87e01390c724039adb93 authorNikolay Amiantov <ab@fmap.me> dateThu 3 Nov 2016, 16:43 (10 years ago) parent6a76ee2
6 files changed+177−132
pkgs/games/0ad/data.nix+12−7 pkgs/games/0ad/default.nix+7−124 pkgs/games/0ad/game.nix+96 pkgs/games/0ad/rootdir_env.patch+38 pkgs/games/0ad/wrapper.nix+21 pkgs/top-level/all-packages.nix+3−1
pkgs/games/0ad/data.nix+12−7
@@ -1,19 +1,24 @@
1−{ stdenv, fetchurl, version, releaseType }:
1+{ stdenv, fetchurl }:
22
33stdenv.mkDerivation rec {
44 name = "0ad-data-${version}";
5+ version = "0.0.20";
56
67 src = fetchurl {
7− url = "http://releases.wildfiregames.com/0ad-${version}-${releaseType}-unix-data.tar.xz";
8+ url = "http://releases.wildfiregames.com/0ad-${version}-alpha-unix-data.tar.xz";
89 sha256 = "1lzl8chfqbgs1n9vpn0xaqd70kpwiibfk196iblyq6qkms3v6pnv";
910 };
1011
11− patchPhase = ''
12− rm binaries/data/tools/fontbuilder/fonts/*.txt
13− '';
14−
1512 installPhase = ''
13+ rm binaries/data/tools/fontbuilder/fonts/*.txt
1614 mkdir -p $out/share/0ad
17− cp -r binaries/data/* $out/share/0ad/
15+ cp -r binaries/data $out/share/0ad/
1816 '';
17+
18+ meta = with stdenv.lib; {
19+ description = "A free, open-source game of ancient warfare -- data files";
20+ homepage = "http://wildfiregames.com/0ad/";
21+ license = licenses.cc-by-sa-30;
22+ platforms = platforms.linux;
23+ };
1924}
pkgs/games/0ad/default.nix+7−124
@@ -1,131 +1,14 @@
1−{ stdenv, callPackage, fetchurl, python27
2−, pkgconfig, spidermonkey_31, boost, icu, libxml2, libpng
3−, libjpeg, zlib, curl, libogg, libvorbis, enet, miniupnpc
4−, openal, mesa, xproto, libX11, libXcursor, nspr, SDL, SDL2
5−, gloox, nvidia-texture-tools
6−, withEditor ? true, wxGTK ? null
7−}:
8−
9−assert withEditor -> wxGTK != null;
1+{ newScope }:
102
113let
12− version = "0.0.20";
13−
14− releaseType = "alpha";
15−
16− zeroadData = callPackage ./data.nix { inherit version releaseType; };
4+ callPackage = newScope self;
175
18− archForPremake =
19− if stdenv.lib.hasPrefix "x86_64-" stdenv.system then "x64" else
20− if stdenv.lib.hasPrefix "i686-" stdenv.system then "x32" else "ERROR";
6+ self = {
7+ zeroad-unwrapped = callPackage ./game.nix { };
218
22−in
23−stdenv.mkDerivation rec {
24− name = "0ad-${version}";
9+ zeroad-data = callPackage ./data.nix { };
2510
26− src = fetchurl {
27− url = "http://releases.wildfiregames.com/0ad-${version}-${releaseType}-unix-build.tar.xz";
28− sha256 = "13n61xhjsawda3kl7112la41bqkbqmq4yhr3slydsz856z5xb5m3";
11+ zeroad = callPackage ./wrapper.nix { };
2912 };
3013
31− buildInputs = [
32− zeroadData python27 pkgconfig spidermonkey_31 boost icu
33− libxml2 libpng libjpeg zlib curl libogg libvorbis enet
34− miniupnpc openal mesa xproto libX11 libXcursor nspr
35− SDL SDL2 gloox nvidia-texture-tools
36− ] ++ stdenv.lib.optional withEditor wxGTK;
37−
38− NIX_CFLAGS_COMPILE = [
39− "-I${xproto}/include/X11"
40− "-I${libX11.dev}/include/X11"
41− "-I${libXcursor.dev}/include/X11"
42− "-I${SDL.dev}/include/SDL"
43− "-I${SDL2}/include/SDL2"
44− ];
45−
46− patchPhase = ''
47− sed -i 's/MOZJS_MINOR_VERSION/false \&\& MOZJS_MINOR_VERSION/' source/scriptinterface/ScriptTypes.h
48− '';
49−
50− configurePhase = ''
51− # Delete shipped libraries which we don't need.
52− rm -rf libraries/source/{enet,miniupnpc,nvtt,spidermonkey}
53−
54− # Build shipped premake.
55− make -C build/premake/premake4/build/gmake.unix
56−
57− # Run premake.
58− pushd build/premake
59− ./premake4/bin/release/premake4 \
60− --file="premake4.lua" \
61− --outpath="../workspaces/gcc/" \
62− --platform=${archForPremake} \
63− --os=linux \
64− --with-system-nvtt \
65− --with-system-enet \
66− --with-system-miniupnpc \
67− --with-system-mozjs31 \
68− ${ if withEditor then "--atlas" else "" } \
69− --collada \
70− --bindir="$out"/bin \
71− --libdir="$out"/lib/0ad \
72− --datadir="$out"/share/0ad \
73− --without-tests \
74− gmake
75− popd
76− '';
77−
78− buildPhase = ''
79− # Build bundled fcollada.
80− make -C libraries/source/fcollada/src
81−
82− # Build 0ad.
83− make -C build/workspaces/gcc verbose=1
84− '';
85−
86− installPhase = ''
87− # Copy executables.
88− mkdir -p "$out"/bin
89− cp binaries/system/pyrogenesis "$out"/bin/0ad
90− ((${ toString withEditor })) && cp binaries/system/ActorEditor "$out"/bin/
91−
92− # Copy l10n data.
93− mkdir -p "$out"/share/0ad
94− cp -r binaries/data/l10n "$out"/share/0ad/
95−
96− # Copy libraries.
97− mkdir -p "$out"/lib/0ad
98− cp binaries/system/libCollada.so "$out"/lib/0ad/
99− ((${ toString withEditor })) && cp binaries/system/libAtlasUI.so "$out"/lib/0ad/
100−
101− # Create links to data files.
102− ln -s -t "$out"/share/0ad "${zeroadData}"/share/0ad/*
103−
104− # Copy icon.
105− mkdir -p "$out"/share/icons
106− cp build/resources/0ad.png "$out"/share/icons/
107−
108− # Copy/fix desktop item.
109− mkdir -p "$out"/share/applications
110− while read LINE; do
111− if [[ $LINE = "Exec=0ad" ]]; then
112− echo "Exec=$out/bin/zeroad"
113− elif [[ $LINE = "Icon=0ad" ]]; then
114− echo "Icon=$out/share/icons/0ad.png"
115− else
116− echo "$LINE"
117− fi
118− done <build/resources/0ad.desktop >"$out"/share/applications/0ad.desktop
119− '';
120−
121− meta = with stdenv.lib; {
122− description = "A free, open-source game of ancient warfare";
123− homepage = "http://wildfiregames.com/0ad/";
124− license = with licenses; [
125− gpl2 lgpl21 mit cc-by-sa-30
126− licenses.zlib # otherwise masked by pkgs.zlib
127− ];
128− platforms = [ "x86_64-linux" "i686-linux" ];
129− hydraPlatforms = []; # the data are too big (~1.5 GB)
130− };
131−}
14+in self
pkgs/games/0ad/game.nixnew file+96
@@ -0,0 +1,96 @@
1+{ stdenv, lib, callPackage, perl, fetchurl, python2
2+, pkgconfig, spidermonkey_31, boost, icu, libxml2, libpng
3+, libjpeg, zlib, curl, libogg, libvorbis, enet, miniupnpc
4+, openal, mesa, xproto, libX11, libXcursor, nspr, SDL, SDL2
5+, gloox, nvidia-texture-tools
6+, withEditor ? true, wxGTK ? null
7+}:
8+
9+assert withEditor -> wxGTK != null;
10+
11+stdenv.mkDerivation rec {
12+ name = "0ad-${version}";
13+ version = "0.0.20";
14+
15+ src = fetchurl {
16+ url = "http://releases.wildfiregames.com/0ad-${version}-alpha-unix-build.tar.xz";
17+ sha256 = "13n61xhjsawda3kl7112la41bqkbqmq4yhr3slydsz856z5xb5m3";
18+ };
19+
20+ nativeBuildInputs = [ python2 perl pkgconfig ];
21+
22+ buildInputs = [
23+ spidermonkey_31 boost icu libxml2 libpng libjpeg
24+ zlib curl libogg libvorbis enet miniupnpc openal
25+ mesa xproto libX11 libXcursor nspr SDL2 gloox
26+ nvidia-texture-tools
27+ ] ++ lib.optional withEditor wxGTK;
28+
29+ NIX_CFLAGS_COMPILE = [
30+ "-I${xproto}/include/X11"
31+ "-I${libX11.dev}/include/X11"
32+ "-I${libXcursor.dev}/include/X11"
33+ "-I${SDL.dev}/include/SDL"
34+ "-I${SDL2}/include/SDL2"
35+ ];
36+
37+ patches = [ ./rootdir_env.patch ];
38+
39+ postPatch = ''
40+ sed -i 's/MOZJS_MINOR_VERSION/false \&\& MOZJS_MINOR_VERSION/' source/scriptinterface/ScriptTypes.h
41+ '';
42+
43+ configurePhase = ''
44+ # Delete shipped libraries which we don't need.
45+ rm -rf libraries/source/{enet,miniupnpc,nvtt,spidermonkey}
46+
47+ # Update Makefiles
48+ pushd build/workspaces
49+ ./update-workspaces.sh \
50+ --with-system-nvtt \
51+ --with-system-mozjs31 \
52+ ${lib.optionalString withEditor "--enable-atlas"} \
53+ --bindir="$out"/bin \
54+ --libdir="$out"/lib/0ad \
55+ --without-tests \
56+ -j $NIX_BUILD_CORES
57+ popd
58+
59+ # Move to the build directory.
60+ pushd build/workspaces/gcc
61+ '';
62+
63+ enableParallelBuilding = true;
64+
65+ installPhase = ''
66+ popd
67+
68+ # Copy executables.
69+ install -Dm755 binaries/system/pyrogenesis "$out"/bin/0ad
70+ ${lib.optionalString withEditor ''
71+ install -Dm755 binaries/system/ActorEditor "$out"/bin/ActorEditor
72+ ''}
73+
74+ # Copy l10n data.
75+ mkdir -p "$out"/share/0ad/data
76+ cp -r binaries/data/l10n "$out"/share/0ad/data
77+
78+ # Copy libraries.
79+ mkdir -p "$out"/lib/0ad
80+ cp binaries/system/*.so "$out"/lib/0ad/
81+
82+ # Copy icon.
83+ install -D build/resources/0ad.png "$out"/share/icons/hicolor/128x128/0ad.png
84+ install -D build/resources/0ad.desktop "$out"/share/applications/0ad.desktop
85+ '';
86+
87+ meta = with stdenv.lib; {
88+ description = "A free, open-source game of ancient warfare";
89+ homepage = "http://wildfiregames.com/0ad/";
90+ license = with licenses; [
91+ gpl2 lgpl21 mit cc-by-sa-30
92+ licenses.zlib # otherwise masked by pkgs.zlib
93+ ];
94+ platforms = platforms.linux;
95+ };
96+}
pkgs/games/0ad/rootdir_env.patchnew file+38
@@ -0,0 +1,38 @@
1+diff -ru3 0ad-0.0.20-alpha/source/ps/GameSetup/Paths.cpp 0ad-0.0.20-alpha-new/source/ps/GameSetup/Paths.cpp
2+--- 0ad-0.0.20-alpha/source/ps/GameSetup/Paths.cpp 2015-02-14 04:45:13.000000000 +0300
3++++ 0ad-0.0.20-alpha-new/source/ps/GameSetup/Paths.cpp 2016-11-03 16:23:47.241514876 +0300
4+@@ -155,32 +155,8 @@
5+
6+ /*static*/ OsPath Paths::Root(const OsPath& argv0)
7+ {
8+-#if OS_ANDROID
9+- return OsPath("/sdcard/0ad"); // TODO: this is kind of bogus
10+-#else
11+-
12+- // get full path to executable
13+- OsPath pathname = sys_ExecutablePathname(); // safe, but requires OS-specific implementation
14+- if(pathname.empty()) // failed, use argv[0] instead
15+- {
16+- errno = 0;
17+- pathname = wrealpath(argv0);
18+- if(pathname.empty())
19+- WARN_IF_ERR(StatusFromErrno());
20+- }
21+-
22+- // make sure it's valid
23+- if(!FileExists(pathname))
24+- {
25+- LOGERROR("Cannot find executable (expected at '%s')", pathname.string8());
26+- WARN_IF_ERR(StatusFromErrno());
27+- }
28+-
29+- for(size_t i = 0; i < 2; i++) // remove "system/name.exe"
30+- pathname = pathname.Parent();
31+- return pathname;
32+-
33+-#endif
34++ UNUSED2(argv0);
35++ return getenv("ZEROAD_ROOTDIR");
36+ }
37+
38+ /*static*/ OsPath Paths::RootData(const OsPath& argv0)
pkgs/games/0ad/wrapper.nixnew file+21
@@ -0,0 +1,21 @@
1+{ buildEnv, makeWrapper, zeroad-unwrapped, zeroad-data }:
2+
3+assert zeroad-unwrapped.version == zeroad-data.version;
4+
5+buildEnv {
6+ name = "zeroad-${zeroad-unwrapped.version}";
7+ inherit (zeroad-unwrapped) meta;
8+
9+ buildInputs = [ makeWrapper ];
10+
11+ paths = [ zeroad-unwrapped zeroad-data ];
12+
13+ pathsToLink = [ "/" "/bin" ];
14+
15+ postBuild = ''
16+ for i in $out/bin/*; do
17+ wrapProgram "$i" \
18+ --set ZEROAD_ROOTDIR "$out/share/0ad"
19+ done
20+ '';
21+}
pkgs/top-level/all-packages.nix+3−1
@@ -16003,7 +16003,9 @@ in
1600316003
1600416004 keen4 = callPackage ../games/keen4 { };
1600516005
16006− zeroad = callPackage ../games/0ad { };
16006+ zeroadPackages = callPackage ../games/0ad { };
16007+
16008+ zeroad = zeroadPackages.zeroad;
1600716009
1600816010 ### DESKTOP ENVIRONMENTS
1600916011