Unverified Commit dfabce26 authored by Masum Reza's avatar Masum Reza Committed by GitHub
Browse files

tome4: fix build, modernize (#454928)

parents 0e6c6277 0ba4d0e9
Loading
Loading
Loading
Loading
+24 −0
Original line number Diff line number Diff line
From e0c17a8665250b3e3e7f4938f7b256ff50b78fc8 Mon Sep 17 00:00:00 2001
From: Tom van Dijk <18gatenmaker6@gmail.com>
Date: Thu, 23 Oct 2025 15:01:01 +0200
Subject: [PATCH 1/3] web missing include

---
 src/web.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/src/web.c b/src/web.c
index f12eebb..940aaf9 100644
--- a/src/web.c
+++ b/src/web.c
@@ -32,6 +32,7 @@
 #include "te4web.h"
 #include "web-external.h"
 #include "lua_externs.h"
+#include <unistd.h>
 
 /*
  * Grab web browser methods -- availabe only here
-- 
2.51.0
+24 −0
Original line number Diff line number Diff line
From a14890a8a7080c73cac10ff31365833b179c0464 Mon Sep 17 00:00:00 2001
From: Tom van Dijk <18gatenmaker6@gmail.com>
Date: Thu, 23 Oct 2025 15:45:03 +0200
Subject: [PATCH 2/3] zlib missing include

---
 src/zlib/gzguts.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/src/zlib/gzguts.h b/src/zlib/gzguts.h
index 990a4d2..7c89751 100644
--- a/src/zlib/gzguts.h
+++ b/src/zlib/gzguts.h
@@ -21,6 +21,7 @@
 #include <stdio.h>
 #include "zlib.h"
 #ifdef STDC
+#  include <unistd.h>
 #  include <string.h>
 #  include <stdlib.h>
 #  include <limits.h>
-- 
2.51.0
+71 −0
Original line number Diff line number Diff line
From ed9f9819c3a0d6b8e92f66aafa6324eb4b310282 Mon Sep 17 00:00:00 2001
From: Tom van Dijk <18gatenmaker6@gmail.com>
Date: Thu, 23 Oct 2025 15:53:06 +0200
Subject: [PATCH 3/3] incompatible pointer types

---
 src/display_sdl.c                  | 2 +-
 src/physfs/archivers/bind_physfs.c | 2 +-
 src/physfs/physfs.c                | 3 ++-
 src/tgl.h                          | 2 +-
 4 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/src/display_sdl.c b/src/display_sdl.c
index 61b2f0e..c533c8b 100644
--- a/src/display_sdl.c
+++ b/src/display_sdl.c
@@ -78,5 +78,5 @@ GLuint gl_c_shader = 0;
 int nb_draws = 0;
 int gl_c_vertices_nb = 0, gl_c_texcoords_nb = 0, gl_c_colors_nb = 0;
 GLfloat *gl_c_vertices_ptr = NULL;
-GLfloat *gl_c_texcoords_ptr = NULL;
+void *gl_c_texcoords_ptr = NULL;
 GLfloat *gl_c_colors_ptr = NULL;
diff --git a/src/physfs/archivers/bind_physfs.c b/src/physfs/archivers/bind_physfs.c
index d02d323..c0d77c1 100644
--- a/src/physfs/archivers/bind_physfs.c
+++ b/src/physfs/archivers/bind_physfs.c
@@ -222,7 +222,7 @@ static fvoid *doOpen(dvoid *opaque, const char *name,
 
 static fvoid *BIND_PHYSFS_openRead(dvoid *opaque, const char *fnm, int *exist)
 {
-	return(doOpen(opaque, fnm, PHYSFS_openRead, exist));
+	return(doOpen(opaque, fnm, (void * (*)(const char *)) PHYSFS_openRead, exist));
 } /* BIND_PHYSFS_openRead */
 
 
diff --git a/src/physfs/physfs.c b/src/physfs/physfs.c
index 03eb86d..32e2c91 100644
--- a/src/physfs/physfs.c
+++ b/src/physfs/physfs.c
@@ -68,12 +68,13 @@ extern const PHYSFS_Archiver       __PHYSFS_Archiver_MVL;
 extern const PHYSFS_ArchiveInfo    __PHYSFS_ArchiveInfo_WAD;
 extern const PHYSFS_Archiver       __PHYSFS_Archiver_WAD;
 extern const PHYSFS_Archiver       __PHYSFS_Archiver_DIR;
+extern const PHYSFS_ArchiveInfo    __PHYSFS_ArchiveInfo_BIND_PHYSFS;
 extern const PHYSFS_Archiver       __PHYSFS_Archiver_BIND_PHYSFS;
 
 
 static const PHYSFS_ArchiveInfo *supported_types[] =
 {
-    &__PHYSFS_Archiver_BIND_PHYSFS,
+    &__PHYSFS_ArchiveInfo_BIND_PHYSFS,
 #if (defined PHYSFS_SUPPORTS_ZIP)
     &__PHYSFS_ArchiveInfo_SUBZIP,
     &__PHYSFS_ArchiveInfo_ZIP,
diff --git a/src/tgl.h b/src/tgl.h
index e2ec026..f905033 100644
--- a/src/tgl.h
+++ b/src/tgl.h
@@ -71,7 +71,7 @@ extern int nb_draws;
 
 extern int gl_c_vertices_nb, gl_c_texcoords_nb, gl_c_colors_nb;
 extern GLfloat *gl_c_vertices_ptr;
-extern GLfloat *gl_c_texcoords_ptr;
+extern void *gl_c_texcoords_ptr;
 extern GLfloat *gl_c_colors_ptr;
 #define glVertexPointer(nb, t, v, p) \
 { \
-- 
2.51.0
+80 −40
Original line number Diff line number Diff line
{
  lib,
  stdenv,
  fetchurl,
  fetchFromGitLab,
  fetchpatch2,
  copyDesktopItems,
  makeDesktopItem,
  makeWrapper,
  premake4,
  unzip,
  openal,
  libpng,
  libvorbis,
@@ -13,39 +14,53 @@
  SDL2,
  SDL2_image,
  SDL2_ttf,
  xorg,
  nix-update-script,
}:

stdenv.mkDerivation rec {
let
  sdlInputs = [
    SDL2
    SDL2_ttf
    SDL2_image
  ];
in

stdenv.mkDerivation (finalAttrs: {
  pname = "tome4";
  version = "1.7.6";

  src = fetchurl {
    url = "https://te4.org/dl/t-engine/t-engine4-src-${version}.tar.bz2";
    sha256 = "sha256-mJ3qAIA/jNyt4CT0ZH1IC7GsDUN8JUKSwHVJwnKkaAw=";
  };

  desktop = makeDesktopItem {
    desktopName = pname;
    name = pname;
    exec = "@out@/bin/${pname}";
    icon = pname;
    comment = "An open-source, single-player, role-playing roguelike game set in the world of Eyal.";
    type = "Application";
    categories = [
      "Game"
      "RolePlaying"
    ];
    genericName = pname;
  # Official source according to https://te4.org/wiki/How_to_compile
  src = fetchFromGitLab {
    domain = "git.net-core.org";
    owner = "tome";
    repo = "t-engine4";
    tag = "tome-${finalAttrs.version}";
    hash = "sha256-v0YPbmaOqKYgFkOe/X0FCirucrMo2UGAyhZ7MFj+nsU=";
  };

  prePatch = ''
    # http://forums.te4.org/viewtopic.php?f=42&t=49478&view=next#p234354
    sed -i 's|#include <GL/glext.h>||' src/tgl.h
    substituteInPlace src/tgl.h \
      --replace-fail "#include <GL/glext.h>" ""
  '';

  patches = [
    # https://forums.te4.org/viewtopic.php?f=69&t=39859&p=168681&hilit=luaopen_shaders#p168681
    (fetchpatch2 {
      url = "https://gist.githubusercontent.com/hasufell/cb3b10f834e891d90f83/raw/cb4adda13868f6b94585575db4f8df70877ae45a/tome4-1.1.3-fix-implicit-declaration.patch";
      hash = "sha256-g47N/bi2/DDKqaEkfTaGp9ItS57QVnObzMDWXqrCjWE=";
    })
    # unistd required for execv
    ./0001-web-missing-include.patch
    # unistd required for read and close
    ./0002-zlib-missing-include.patch
    ./0003-incompatible-pointer-types.patch
  ];

  nativeBuildInputs = [
    copyDesktopItems
    makeWrapper
    unzip
    premake4
  ];

@@ -56,52 +71,77 @@ stdenv.mkDerivation rec {
    openal
    libpng
    libvorbis
    SDL2
    SDL2_ttf
    SDL2_image
  ];
    xorg.libX11
    xorg.xorgproto
  ]
  ++ sdlInputs;

  # disable parallel building as it caused sporadic build failures
  enableParallelBuilding = false;

  env.NIX_CFLAGS_COMPILE = "-I${lib.getInclude SDL2}/include/SDL2 -I${SDL2_image}/include/SDL2 -I${SDL2_ttf}/include/SDL2";
  env = {
    NIX_CFLAGS_COMPILE =
      lib.concatMapStringsSep " " (i: "-I${lib.getInclude i}/include/SDL2") sdlInputs
      + " "
      + lib.concatMapStringsSep " " (i: "-I${lib.getInclude i}") finalAttrs.buildInputs;

    NIX_CFLAGS_LINK = lib.concatMapStringsSep " " (i: "-L${lib.getLib i}/lib") finalAttrs.buildInputs;
  };

  makeFlags = [ "config=release" ];

  desktopItems = [
    (makeDesktopItem {
      desktopName = "Tales of Maj'Eyal";
      name = "tome4";
      exec = "tome4";
      icon = "te4-icon";
      comment = "An open-source, single-player, role-playing roguelike game set in the world of Eyal.";
      type = "Application";
      categories = [
        "Game"
        "RolePlaying"
      ];
      genericName = "2D roguelike RPG";
    })
  ];

  # The wrapper needs to cd into the correct directory as tome4's detection of
  # the game asset root directory is faulty.

  installPhase = ''
    runHook preInstall

    dir=$out/share/${pname}
    dir=$out/share/tome4

    install -Dm755 t-engine $dir/t-engine
    cp -r bootstrap game $dir
    makeWrapper $dir/t-engine $out/bin/${pname} \
    makeWrapper $dir/t-engine $out/bin/tome4 \
      --chdir "$dir"

    install -Dm755 ${desktop}/share/applications/${pname}.desktop $out/share/applications/${pname}.desktop
    substituteInPlace $out/share/applications/${pname}.desktop \
      --subst-var out
    install -Dm644 game/engines/default/data/gfx/te4-icon.png -t $out/share/icons/hicolor/64x64

    unzip -oj -qq game/engines/te4-${version}.teae data/gfx/te4-icon.png
    install -Dm644 te4-icon.png $out/share/icons/hicolor/64x64/${pname}.png

    install -Dm644 -t $out/share/doc/${pname} CONTRIBUTING COPYING COPYING-MEDIA CREDITS
    install -Dm644 -t $out/share/doc/tome4 CONTRIBUTING COPYING COPYING-MEDIA CREDITS

    runHook postInstall
  '';

  meta = with lib; {
  passthru.updateScript = nix-update-script {
    extraArgs = [
      "--version-regex"
      "tome-(.*)"
    ];
  };

  meta = {
    description = "Tales of Maj'eyal (rogue-like game)";
    mainProgram = "tome4";
    homepage = "https://te4.org/";
    license = licenses.gpl3;
    maintainers = with maintainers; [ peterhoeg ];
    license = lib.licenses.gpl3;
    maintainers = with lib.maintainers; [ peterhoeg ];
    platforms = [
      "i686-linux"
      "x86_64-linux"
    ];
  };
}
})