Subject: [bug#75991] [PATCH 3/3] gnu: speed-dreams: Update to 2.4.0-rc1.

From: Maxim Cournoyer <[email-masked]>
Date: Sun, 2 Feb 2025 00:50:46 +0900

* gnu/packages/games.scm (speed-dreams-version
(speed-dreams-svn-revision): Delete variables.
(speed-dreams-source-tarball): Delete procedure.
(speed-dreams-base-tarball, speed-dreams-hq-cars-and-tracks-tarball)
(speed-dreams-more-hq-cars-and-tracks-tarball)
(speed-dreams-wip-cars-and-tracks-tarball)
(speed-dreams-unmaintained-tarball): Delete variables.
(speed-dreams-data): New variable.
(speed-dreams): Update to 2.4.0-rc1.
[source]: Fetch from git.  Apply patches.
[configure-flags]: Remove the SD_DATADIR, SD_LIBDIR, OPTION_3RDPARTY_SOLID,
CMAKE_MODULE_LINKER_FLAGS, and CMAKE_BUILD_RPATH_USE_ORIGIN flags.  Add the
VERSION_LONG flag.
[phases]: Delete phases.
[native-inputs]: Add speed-dreams-data.
[inputs]: Add cjson, glm, minizip, rhash and tinygltf.
* gnu/packages/patches/speed-dreams-freesolid-include-dir.patch: New file.
* gnu/packages/patches/speed-dreams-runpath.patch: Likewise.
* gnu/packages/patches/speed-dreams-desktop-file.patch: Likewise.
* gnu/packages/patches/speed-dreams-version.patch: Likewise.
* gnu/local.mk (dist_patch_DATA): Register them.

Change-Id: Ie782a65dadaafb5d6c3a7d4d6c28212eef2b36f7
---
 gnu/local.mk                                  |   4 +
 gnu/packages/games.scm                        | 145 +++++++-----------
 .../patches/speed-dreams-desktop-file.patch   |  37 +++++
 .../speed-dreams-freesolid-include-dir.patch  |  26 ++++
 .../patches/speed-dreams-runpath.patch        |  50 ++++++
 .../patches/speed-dreams-version.patch        |  13 ++
 6 files changed, 187 insertions(+), 88 deletions(-)
 create mode 100644 gnu/packages/patches/speed-dreams-desktop-file.patch
 create mode 100644 gnu/packages/patches/speed-dreams-freesolid-include-dir.patch
 create mode 100644 gnu/packages/patches/speed-dreams-runpath.patch
 create mode 100644 gnu/packages/patches/speed-dreams-version.patch

diff --git a/gnu/local.mk b/gnu/local.mk
index aa91977391..7aff24ea7b 100644
--- a/gnu/local.mk
+++ b/gnu/local.mk
@@ -2016,6 +2016,10 @@ dist_patch_DATA =						\
   %D%/packages/patches/sdl-pango-sans-serif.patch		\
   %D%/packages/patches/sioyek-fix-build.patch			\
   %D%/packages/patches/smalltalk-multiplication-overflow.patch	\
+  %D%/packages/patches/speed-dreams-desktop-file.patch		\
+  %D%/packages/patches/speed-dreams-freesolid-include-dir.patch	\
+  %D%/packages/patches/speed-dreams-runpath.patch		\
+  %D%/packages/patches/speed-dreams-version.patch		\
   %D%/packages/patches/sqlite-hurd.patch			\
   %D%/packages/patches/strace-readlink-tests.patch		\
   %D%/packages/patches/sunxi-tools-remove-sys-io.patch	\
diff --git a/gnu/packages/games.scm b/gnu/packages/games.scm
index c0319dcb20..7e0817666e 100644
--- a/gnu/packages/games.scm
+++ b/gnu/packages/games.scm
@@ -9332,116 +9332,85 @@ (define-public endless-sky
                    license:cc-by-sa4.0
                    license:public-domain))))
 
-(define speed-dreams-version "2.3.0")
-(define speed-dreams-svn-revision "8786")
-(define (speed-dreams-source-tarball name sha256sum)
-  (origin
-    (method url-fetch)
-    (uri (string-append "mirror://sourceforge/speed-dreams/"
-                        speed-dreams-version "/"
-                        "speed-dreams-src-" name "-" speed-dreams-version "-r"
-                        speed-dreams-svn-revision ".tar.xz"))
-    (sha256 (base32 sha256sum))))
-
-;;; We use the release tarballs instead of the SVN repository for their
-;;; reduced weight (the tarballs do not provide the sources of the 3D models
-;;; used, which are heavy, for example).
-(define speed-dreams-base-tarball       ;about 240 MiB
-  (speed-dreams-source-tarball
-   "base" "190480qzkllykl07s6bxd5wdbjgavs7haw6mk0hgdm7bs6rqqk0d"))
-
-(define speed-dreams-hq-cars-and-tracks-tarball ;about 670 MiB
-  (speed-dreams-source-tarball
-   "hq-cars-and-tracks" "16zcgwax3n0gf79hw1dg42lzsyxbnxfw6hjxdi919q5hxgm9cgsr"))
-
-(define speed-dreams-more-hq-cars-and-tracks-tarball ;about 760 MiB
-  (speed-dreams-source-tarball
-   "more-hq-cars-and-tracks"
-   "1acwiacf77qk5azyg3bbxsydk3wsp5fvgwwnhxpk273mwszjkh56"))
-
-;;; Although these are marked as 'WIP', the game throws (non-fatal) errors
-;;; when it fails finding some "drivers" included within this pack.
-(define speed-dreams-wip-cars-and-tracks-tarball ;about 400 MiB
-  (speed-dreams-source-tarball
-   "wip-cars-and-tracks"
-   "0wqd9bpis9bg87rsqk0dyvljax4zrp9h57mz7z3zrn6fayl1nh1q"))
-
-;;; This is to allow selecting the legacy Simu V2 engine (configurable in the
-;;; game options).
-(define speed-dreams-unmaintained-tarball ;about 60 KiB
-  (speed-dreams-source-tarball
-   "unmaintained" "1cxcrjm2508najpz2b65i8gxgvgiq7fcp13xvicpiqp6xhq3hsyi"))
+(define-public speed-dreams-data
+  ;; Use the commit corresponding to the 'speed-dreams-data' submodule
+  ;; (https://forge.a-lec.org/speed-dreams/speed-dreams-data).
+  (let ((commit "3d26571ada10cd68944896fad39fd68b71c67abd")
+        (revision "0"))
+    (hidden-package
+     (package
+       (name "speed-dreams-data")
+       (version (git-version "2.3.0" revision commit))
+       (source
+        (origin
+          (method git-fetch)
+          (uri (git-reference
+                (url (string-append "https://forge.a-lec.org/speed-dreams/"
+                                    name))
+                (commit commit)))
+          (file-name (git-file-name name version))
+          (sha256
+           (base32
+            "12s02qkbqpgqy4jxj56jfxjahv1z0nbf758wlcgf9a3p3rnnm0rz"))))
+       (build-system cmake-build-system)
+       (arguments (list #:tests? #f))   ;no test suite
+       (home-page "https://www.speed-dreams.net/en")
+       (synopsis "Data for the Speed Dreams racing game")
+       (description "This package contains the non-functional data for the
+Speed Dreams racing game.")
+       (license license:gpl2+)))))
 
 (define-public speed-dreams
   (package
     (name "speed-dreams")
-    (version speed-dreams-version)
-    (source speed-dreams-base-tarball)
+    (version "2.4.0-rc1")
+    (source
+     (origin
+       (method git-fetch)
+       (uri (git-reference
+             (url (string-append "https://forge.a-lec.org/"
+                                 name "/" name "-code.git"))
+             (commit (string-append "v" version))))
+       (file-name (git-file-name name version))
+       (sha256
+        (base32
+         "1q4jr4gp9bq0khrjkmxsx1zh3bcij3spk2zrp1pakciqvk3hsj4g"))
+       (patches
+        (search-patches "speed-dreams-desktop-file.patch"
+                        "speed-dreams-freesolid-include-dir.patch"
+                        "speed-dreams-runpath.patch"
+                        "speed-dreams-version.patch"))))
     (build-system cmake-build-system)
     (arguments
      (list
       #:tests? #f                       ;no test suite
       #:build-type "Release"
       #:configure-flags
-      #~(list
-         "-DOPTION_OFFICIAL_ONLY=ON"                    ;build with content
-         (string-append "-DSD_BINDIR=" #$output "/bin") ;instead of 'games'
-         (string-append "-DSD_DATADIR=" #$output "/share/speed-dreams-2")
-         ;; Libdir defaults to a 'lib64/games' prefix.
-         (string-append "-DSD_LIBDIR=" #$output "/lib/speed-dreams-2")
-         ;; Use system-provided Expat and FreeSOLID
-         ;; libraries instead of the bundled ones.
-         "-DOPTION_3RDPARTY_EXPAT=ON"
-         "-DOPTION_3RDPARTY_SOLID=ON"
-         ;; Drivers and other shared objects are linked to private/internal
-         ;; shared libraries; have their location on the RUNPATH to satisfy
-         ;; the validate-runpath phase.
-         (string-append "-DCMAKE_MODULE_LINKER_FLAGS=-Wl,-rpath="
-                        #$output "/lib/speed-dreams-2/lib")
-         ;; The following flag is to avoid bogus RUNPATH warnings from the
-         ;; validate-runpath phase; without it, -rpath links referring to the
-         ;; build directory would be baked in driver modules.
-         "-DCMAKE_BUILD_RPATH_USE_ORIGIN=ON")
-      #:phases
-      #~(modify-phases %standard-phases
-          (add-after 'unpack 'extract-cars-and-tracks-data
-            (lambda _
-              ;; XXX: The current working directory is inside the cmake/
-              ;; sudbirectory following the unpack phase, for some reason.
-              (chdir "..")
-              (invoke "tar" "-xvf" #$speed-dreams-hq-cars-and-tracks-tarball)
-              (invoke "tar" "-xvf" #$speed-dreams-more-hq-cars-and-tracks-tarball)
-              (invoke "tar" "-xvf" #$speed-dreams-wip-cars-and-tracks-tarball)
-              (invoke "tar" "-xvf" #$speed-dreams-unmaintained-tarball)))
-          (add-after 'install 'install-desktop-entry
-            (lambda* (#:key outputs #:allow-other-keys)
-              (make-desktop-entry-file
-               (string-append #$output
-                              "/share/applications/speed-dreams.desktop")
-               #:name "Speed Dreams 2"
-               #:comment "3D racing cars simulator"
-               #:exec (search-input-file outputs "bin/speed-dreams-2")
-               #:icon (search-input-file
-                       outputs "share/speed-dreams-2/data/icons/icon.png")
-               #:categories '("Game" "Simulation")))))))
-    (native-inputs
-     (list pkg-config))
+      #~(list "-DOPTION_3RDPARTY_EXPAT=ON" ;use system expat library
+              "-DSD_BINDIR:PATH=bin"       ;install to /bin instead of /games
+              (string-append "-DVERSION_LONG=" #$version))))
+    (native-inputs (list pkg-config speed-dreams-data))
     (inputs
-     (list curl
+     (list cjson
+           curl
            enet
            expat
            freeglut
            freesolid
            freetype
+           glm
            libjpeg-turbo
            libogg
            libpng
            libvorbis
+           minizip
            openal
            openscenegraph
            plib
+           rhash
            sdl2
            sdl2-mixer
+           tinygltf
            zlib))
     (home-page "https://sourceforge.net/projects/speed-dreams/")
     (synopsis "Car racing simulator")
@@ -9450,9 +9419,9 @@ (define-public speed-dreams
 realism.  Initially forked from TORCS, it features improvements to the
 graphics and physics simulation, and supports modern input methods such as
 gamepads by use of the SDL library.  It features more than 20 tracks and more
-than 80 cars to race with.")
-    (license (list license:gpl2+        ;game code
-                   license:lal1.3))))   ;assets
+than 80 cars to race with.  Extra (freely licensed) assets can be downloaded
+via the in-game download manager.")
+    (license (list license:gpl2+))))
 
 (define-public stepmania
   (package
diff --git a/gnu/packages/patches/speed-dreams-desktop-file.patch b/gnu/packages/patches/speed-dreams-desktop-file.patch
new file mode 100644
index 0000000000..806790ffda
--- /dev/null
+++ b/gnu/packages/patches/speed-dreams-desktop-file.patch
@@ -0,0 +1,37 @@
+Upstream-status: https://forge.a-lec.org/speed-dreams/speed-dreams-code/pulls/53
+
+diff --git a/speed-dreams.desktop.in b/speed-dreams.desktop.in
+new file mode 100644
+index 00000000..45496917
+--- /dev/null
++++ b/speed-dreams.desktop.in
+@@ -0,0 +1,9 @@
++[Desktop Entry]
++Name=Speed Dreams
++Comment=3D racing cars simulator
++Exec=@CMAKE_INSTALL_PREFIX@/@SD_BINDIR@/@_TARGET_NAME@
++Icon=@SD_DATADIR_ABS@/data/icons/icon.png
++Terminal=false
++Type=Application
++Encoding=UTF-8
++Categories=Game;Simulation;
+diff --git a/src/main/CMakeLists.txt b/src/main/CMakeLists.txt
+index e6de4565..27f1d849 100644
+--- a/src/main/CMakeLists.txt
++++ b/src/main/CMakeLists.txt
+@@ -45,7 +45,14 @@ IF(MINGW)
+ ENDIF(MINGW)
+ 
+ IF(UNIX)
+-	SD_INSTALL_FILES(MAN man6 PREFIX ${CMAKE_SOURCE_DIR}/doc/man FILES ${_TARGET_NAME}.6)
++    SD_INSTALL_FILES(MAN man6 PREFIX ${CMAKE_SOURCE_DIR}/doc/man FILES ${_TARGET_NAME}.6)
++    # Install a launcher for desktop environments.
++    configure_file(
++        ${CMAKE_SOURCE_DIR}/speed-dreams.desktop.in
++        ${PROJECT_BINARY_DIR}/speed-dreams.desktop @ONLY)
++    install(
++        FILES ${PROJECT_BINARY_DIR}/speed-dreams.desktop
++        DESTINATION ${CMAKE_INSTALL_DATADIR}/applications)
+ ENDIF(UNIX)
+ 
+ SD_INSTALL_FILES(BIN TARGETS ${_TARGET_NAME})
diff --git a/gnu/packages/patches/speed-dreams-freesolid-include-dir.patch b/gnu/packages/patches/speed-dreams-freesolid-include-dir.patch
new file mode 100644
index 0000000000..a6ea131326
--- /dev/null
+++ b/gnu/packages/patches/speed-dreams-freesolid-include-dir.patch
@@ -0,0 +1,26 @@
+Upstream-status: https://forge.a-lec.org/speed-dreams/speed-dreams-code/pulls/46
+
+diff --git a/cmake/FindSOLID.cmake b/cmake/FindSOLID.cmake
+index 7adda425..89b07adf 100644
+--- a/cmake/FindSOLID.cmake
++++ b/cmake/FindSOLID.cmake
+@@ -20,9 +20,9 @@ ENDIF(SOLID_FOUND)
+ FIND_PACKAGE(PkgConfig)
+ IF(PKGCONFIG_FOUND)
+ 
+-  PKG_CHECK_MODULES(SOLID FreeSOLID)
++  PKG_CHECK_MODULES(SOLID FreeSOLID IMPORTED_TARGET)
+   IF(NOT SOLID_FOUND)
+-    PKG_CHECK_MODULES(SOLID SOLID)
++    PKG_CHECK_MODULES(SOLID SOLID IMPORTED_TARGET)
+   ENDIF (NOT SOLID_FOUND)
+ 
+   IF(SOLID_FOUND)
+@@ -33,6 +33,7 @@ IF(PKGCONFIG_FOUND)
+     SET(SOLID_MOTO_LIBRARY "NOT-FOUND" CACHE STRING "MOTO libraries")
+     SET(SOLID_LIBRARY ${SOLID_SOLID_LIBRARY})
+     MESSAGE(STATUS "Looking for SOLID --- found using pkg-config (${SOLID_SOLID_LIBRARY})")
++    add_library(solid ALIAS PkgConfig::SOLID)
+     RETURN()
+   ENDIF(SOLID_FOUND)
+ 
diff --git a/gnu/packages/patches/speed-dreams-runpath.patch b/gnu/packages/patches/speed-dreams-runpath.patch
new file mode 100644
index 0000000000..9c665343f8
--- /dev/null
+++ b/gnu/packages/patches/speed-dreams-runpath.patch
@@ -0,0 +1,50 @@
+From b6ac12ffd8bfbca0ae830ea5cf52844c55025115 Mon Sep 17 00:00:00 2001
+From: Xavier Del Campo Romero <[email-masked]>
+Date: Sat, 1 Feb 2025 08:02:36 +0100
+Subject: [PATCH] Do not assume Debian-specific CMAKE_INSTALL_RPATH
+
+6df4b6bf introduced a workaround to allow Ubuntu and Debian packages to
+work with default flags, since CPack does not adjust the rpath of the
+package executables according to its CPACK_PACKAGING_INSTALL_PREFIX. [1]
+
+However, this workaround caused a regression on those distributions not
+using /usr as their CPACK_PACKAGING_INSTALL_PREFIX, such as Guix.
+
+Until CPack is fixed, removing this line forces build-deb.yml to set a
+non-default CMAKE_INSTALL_PREFIX that matches
+CPACK_PACKAGING_INSTALL_PREFIX.
+
+[1]: https://cmake.org/cmake/help/latest/variable/CPACK_PACKAGING_INSTALL_PREFIX.html
+---
+ .forgejo/workflows/build-deb.yml | 2 +-
+ CMakeLists.txt                   | 1 -
+ 2 files changed, 1 insertion(+), 2 deletions(-)
+
+diff --git a/.forgejo/workflows/build-deb.yml b/.forgejo/workflows/build-deb.yml
+index 72eb1b622..ee5b5b292 100644
+--- a/.forgejo/workflows/build-deb.yml
++++ b/.forgejo/workflows/build-deb.yml
+@@ -25,7 +25,7 @@ jobs:
+         working-directory: /src
+       - name: Configure project
+         working-directory: /src
+-        run: cmake -B build -DSD_ASSUME_DATADIR=1
++        run: cmake -B build -DSD_ASSUME_DATADIR=1 -DCMAKE_INSTALL_PREFIX=/usr
+       - name: Build project
+         run: cmake --build build -j$(nproc --all)
+         working-directory: /src
+diff --git a/CMakeLists.txt b/CMakeLists.txt
+index 196de77e4..b80ca4baf 100644
+--- a/CMakeLists.txt
++++ b/CMakeLists.txt
+@@ -94,7 +94,6 @@ INCLUDE(cmake/checks.cmake)
+ set(CMAKE_INSTALL_RPATH
+    ${CMAKE_INSTALL_RPATH}
+    ${CMAKE_INSTALL_PREFIX}/${SD_LIBDIR}/lib
+-   /usr/${SD_LIBDIR}/lib
+ )
+ 
+ set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
+-- 
+2.39.5
+
diff --git a/gnu/packages/patches/speed-dreams-version.patch b/gnu/packages/patches/speed-dreams-version.patch
new file mode 100644
index 0000000000..d6269cd451
--- /dev/null
+++ b/gnu/packages/patches/speed-dreams-version.patch
@@ -0,0 +1,13 @@
+diff --git a/CMakeLists.txt b/CMakeLists.txt
+index 196de77e..eff5446b 100644
+--- a/CMakeLists.txt
++++ b/CMakeLists.txt
+@@ -114,7 +114,7 @@ if(NOT result EQUAL 0)
+    set(VERSION "undefined-version")
+ endif()
+ 
+-set(VERSION_LONG ${VERSION})
++set(VERSION_LONG ${VERSION} CACHE STRING "The version string displayed")
+ 
+ # CMAKE_PROJECT_VERSION_TWEAK is used by NSIS packagers
+ # its what comes after the '-' sign (if anything)
-- 
2.47.1