From aa4f7078b95df91d204a30f0ccd3fc8dc4b09118 Mon Sep 17 00:00:00 2001 From: rian <19516527+360ied@users.noreply.github.com> Date: Fri, 9 Sep 2022 09:45:59 +0000 Subject: [PATCH] classicube: init at 1.3.2 (#189491) Co-authored-by: Sandro --- pkgs/games/classicube/default.nix | 87 +++++++++++++++++++++++ pkgs/games/classicube/fix-linking.patch | 13 ++++ pkgs/games/classicube/font-location.patch | 16 +++++ pkgs/games/classicube/use-sdl.patch | 13 ++++ pkgs/top-level/all-packages.nix | 2 + 5 files changed, 131 insertions(+) create mode 100644 pkgs/games/classicube/default.nix create mode 100644 pkgs/games/classicube/fix-linking.patch create mode 100644 pkgs/games/classicube/font-location.patch create mode 100644 pkgs/games/classicube/use-sdl.patch diff --git a/pkgs/games/classicube/default.nix b/pkgs/games/classicube/default.nix new file mode 100644 index 000000000000..b2b2ee68ff09 --- /dev/null +++ b/pkgs/games/classicube/default.nix @@ -0,0 +1,87 @@ +{ lib +, stdenv +, fetchFromGitHub +, dos2unix +, makeWrapper +, SDL2 +, libGL +, curl +, openal +, liberation_ttf +}: + +stdenv.mkDerivation rec { + pname = "ClassiCube"; + version = "1.3.2"; + + src = fetchFromGitHub { + owner = "UnknownShadow200"; + repo = "ClassiCube"; + rev = version; + sha256 = "6a0f7b03ef3a7f74cf42ffa5b88ab1a7b7beb4d864871a1b700465343ae74bb6"; + }; + + nativeBuildInputs = [ dos2unix makeWrapper ]; + + prePatch = '' + # The ClassiCube sources have DOS-style newlines + # which causes problems with diff/patch. + dos2unix 'src/Platform_Posix.c' 'src/Core.h' + ''; + + patches = [ + # Fix hardcoded font paths + ./font-location.patch + # ClassiCube doesn't compile with its X11 backend + # because of issues with libXi. + ./use-sdl.patch + # For some reason, the Makefile doesn't link + # with libcurl and openal when ClassiCube requires them. + # Also links with SDL2 instead of libX11 and libXi. + ./fix-linking.patch + ]; + + font_path = "${liberation_ttf}/share/fonts/truetype"; + + enableParallelBuilding = true; + + postPatch = '' + # ClassiCube hardcodes locations of fonts. + # This changes the hardcoded location + # to the path of liberation_ttf instead + substituteInPlace src/Platform_Posix.c \ + --replace '%NIXPKGS_FONT_PATH%' "${font_path}" + # ClassiCube's Makefile hardcodes JOBS=1 for some reason, + # even though it works perfectly well multi-threaded. + substituteInPlace src/Makefile \ + --replace 'JOBS=1' "JOBS=$NIX_BUILD_CORES" + ''; + + buildInputs = [ SDL2 libGL curl openal liberation_ttf ]; + + preBuild = "cd src"; + + postBuild = "cd -"; + + installPhase = '' + mkdir -p "$out/bin" + cp 'src/ClassiCube' "$out/bin" + # ClassiCube puts downloaded resources + # next to the location of the executable by default. + # This doesn't work with Nix + # as the location of the executable is read-only. + # We wrap the program to make it put its resources + # in ~/.local/share instead. + wrapProgram "$out/bin/ClassiCube" \ + --run 'mkdir -p "$HOME/.local/share/ClassiCube"' \ + --add-flags '-d"$HOME/.local/share/ClassiCube"' + ''; + + meta = with lib; { + homepage = "https://www.classicube.net/"; + description = "A lightweight, custom Minecraft Classic/ClassiCube client with optional additions written from scratch in C"; + license = licenses.bsd3; + platforms = platforms.linux; + maintainers = with maintainers; [ _360ied ]; + }; +} diff --git a/pkgs/games/classicube/fix-linking.patch b/pkgs/games/classicube/fix-linking.patch new file mode 100644 index 000000000000..987c882367ee --- /dev/null +++ b/pkgs/games/classicube/fix-linking.patch @@ -0,0 +1,13 @@ +diff --git a/src/Makefile b/src/Makefile +index 83188ce..3439cdb 100644 +--- a/src/Makefile ++++ b/src/Makefile +@@ -40,7 +40,7 @@ LIBS=-mwindows -lws2_32 -lwininet -lwinmm -limagehlp -lcrypt32 -ld3d9 + endif + + ifeq ($(PLAT),linux) +-LIBS=-lX11 -lXi -lpthread -lGL -lm -ldl ++LIBS=-lSDL2 -lpthread -lGL -lm -ldl -lcurl -lopenal + endif + + ifeq ($(PLAT),sunos) diff --git a/pkgs/games/classicube/font-location.patch b/pkgs/games/classicube/font-location.patch new file mode 100644 index 000000000000..48428a8bb94f --- /dev/null +++ b/pkgs/games/classicube/font-location.patch @@ -0,0 +1,16 @@ +diff --git a/src/Platform_Posix.c b/src/Platform_Posix.c +index bca992d..3540afa 100644 +--- a/src/Platform_Posix.c ++++ b/src/Platform_Posix.c +@@ -440,9 +440,8 @@ void Platform_LoadSysFonts(void) { + String_FromConst("/Library/Fonts") + }; + #else +- static const cc_string dirs[2] = { +- String_FromConst("/usr/share/fonts"), +- String_FromConst("/usr/local/share/fonts") ++ static const cc_string dirs[1] = { ++ String_FromConst("%NIXPKGS_FONT_PATH%") + }; + #endif + for (i = 0; i < Array_Elems(dirs); i++) { diff --git a/pkgs/games/classicube/use-sdl.patch b/pkgs/games/classicube/use-sdl.patch new file mode 100644 index 000000000000..3456ef8b6469 --- /dev/null +++ b/pkgs/games/classicube/use-sdl.patch @@ -0,0 +1,13 @@ +diff --git a/src/Core.h b/src/Core.h +index e94a39e..96527d0 100644 +--- a/src/Core.h ++++ b/src/Core.h +@@ -170,7 +170,7 @@ Thus it is **NOT SAFE** to allocate a string on the stack. */ + #define CC_BUILD_LINUX + #define CC_BUILD_POSIX + #define CC_BUILD_GL +-#define CC_BUILD_X11 ++#define CC_BUILD_SDL + #define CC_BUILD_CURL + #define CC_BUILD_OPENAL + #if defined CC_BUILD_RPI diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 12279ff757e6..efa0185f55ac 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -368,6 +368,8 @@ with pkgs; chrysalis = callPackage ../applications/misc/chrysalis { }; + classicube = callPackage ../games/classicube { }; + clj-kondo = callPackage ../development/tools/clj-kondo { }; cloak = callPackage ../applications/misc/cloak {