Subject: [PATCH v2 2/2] gnu: Add vdrift.

From: Maxim Cournoyer <[email-masked]>
Date: Tue, 22 Oct 2024 15:53:32 +0900

* gnu/packages/patches/vdrift-icons.patch: New file.
* gnu/local.mk (dist_patch_DATA): Register it.
* gnu/packages/games.scm (vdrift): New variable.

Change-Id: I55b5884a9d7d4a9e874e76c6a7c8af4974dce701
---
Changes in v2: The icons are now properly installed.

 gnu/local.mk                            |  1 +
 gnu/packages/games.scm                  | 64 +++++++++++++++++++++++++
 gnu/packages/patches/vdrift-icons.patch | 42 ++++++++++++++++
 3 files changed, 107 insertions(+)
 create mode 100644 gnu/packages/patches/vdrift-icons.patch

diff --git a/gnu/local.mk b/gnu/local.mk
index a046a6122f..9c14308023 100644
--- a/gnu/local.mk
+++ b/gnu/local.mk
@@ -2289,6 +2289,7 @@ dist_patch_DATA =						\
   %D%/packages/patches/vcmi-disable-privacy-breach.patch	\
   %D%/packages/patches/vdrift-data-extra-resolutions.patch	\
   %D%/packages/patches/vdrift-data-icons.patch			\
+  %D%/packages/patches/vdrift-icons.patch			\
   %D%/packages/patches/vinagre-newer-freerdp.patch             \
   %D%/packages/patches/vinagre-newer-rdp-parameters.patch      \
   %D%/packages/patches/virtuoso-ose-remove-pre-built-jar-files.patch	\
diff --git a/gnu/packages/games.scm b/gnu/packages/games.scm
index 6525e1cb81..000e1fbab3 100644
--- a/gnu/packages/games.scm
+++ b/gnu/packages/games.scm
@@ -823,6 +823,70 @@ (define-public vdrift-data
 game.")
        (license license:gpl3+)))))      ;assumed same as Vdrift itself
 
+(define-public vdrift
+  ;; The latest release is from 2014, and lacks build system and other
+  ;; unreleased improvements; use the latest commit.
+  (let ((commit "c85725b7b861db3f7e579456ec704f0134d46812")
+        (revision "0"))
+    (package
+      (name "vdrift")
+      (version (git-version "2014-10-20" revision commit))
+      (source (origin
+                (method git-fetch)
+                (uri (git-reference
+                      (url "https://github.com/VDrift/vdrift")
+                      (commit commit)))
+                (file-name (git-file-name name version))
+                (sha256
+                 (base32
+                  "1fndwrjdy1rxnhn8vpw2hv02vgdg3p5qnjmvx679dhwn57cd0773"))
+                (patches (search-patches "vdrift-icons.patch"))))
+      (build-system scons-build-system)
+      (arguments
+       (list
+        #:tests? #f                     ;no test suite
+        #:scons-flags #~(list (string-append "prefix=" #$output)
+                              "release=1"
+                              "verbose=1")
+        #:phases
+        #~(modify-phases %standard-phases
+            (add-after 'unpack 'setup-vdrift-data
+              (lambda _
+                ;; The locale data must be made writable, as gettext
+                ;; translation files are generated and written there as part
+                ;; of the installation script.
+                (copy-recursively (search-input-directory
+                                   %build-inputs
+                                   "share/games/vdrift/data")
+                                  "data")
+                (for-each make-file-writable (find-files "data/locale")))))))
+      (native-inputs (list gettext-minimal pkg-config vdrift-data))
+      (inputs (list bullet curl libvorbis mesa sdl2 zlib))
+      (home-page "https://vdrift.net/")
+      (synopsis "Racing simulator")
+      (description "VDrift aims to provide an accurate driving physics
+emulation, based on real world data of the actual vehicles, employing a full
+rigid body simulation and a complex tire model.  VDrift features:
+@itemize
+@item Over 45 tracks based on famous real-world tracks
+@item Over 45 cars based on real-world vehicles
+@item Very realistic, simulation-grade driving physics
+@item Mouse/joystick/gamepad/wheel/keyboard support
+@item Fully modeled tracks, scenery and terrain
+@item Several different camera modes
+@item Basic replay system with Skip Forward/Skip Backward
+@item Fully customizable controls
+@item Joystick, mouse and keyboard input filtering
+@item Brake and reverse lights
+@item Driver aids: automatic shifting, traction control, anti-lock braking
+@item Experimental force feedback
+@item Race against up to 3 AI with variable difficultly
+@item Engine and road sounds
+@end itemize
+The recommended input method is a steering wheel with pedals and force
+feedback support.")
+      (license license:gpl3+))))
+
 (define-public vitetris
   (package
     (name "vitetris")
diff --git a/gnu/packages/patches/vdrift-icons.patch b/gnu/packages/patches/vdrift-icons.patch
new file mode 100644
index 0000000000..d2e153e267
--- /dev/null
+++ b/gnu/packages/patches/vdrift-icons.patch
@@ -0,0 +1,42 @@
+Upstream-status: https://github.com/VDrift/vdrift/pull/202
+
+diff --git a/SConstruct b/SConstruct
+index 7ba3860f..4e8874d5 100644
+--- a/SConstruct
++++ b/SConstruct
+@@ -29,6 +29,7 @@ opts.Add(BoolVariable('verbose', 'Show verbose compiling output', 1))
+ cppdefines = []
+ default_settingsdir = ".vdrift"
+ default_prefix = "/usr/local"
++default_iconsdir = "share/icons/hicolor"
+ default_datadir = "share/games/vdrift/data"
+ default_localedir = "share/locale"
+ default_bindir = "bin"
+@@ -161,8 +162,9 @@ if ARGUMENTS.get('verbose') != "1":
+ #-------------------------------#
+ opts.Add('settings', 'Directory under user\'s home dir where settings will be stored', default_settingsdir )
+ opts.Add('prefix', 'Path prefix.', default_prefix)
+-# in most case datadir doesn't exsist => do not use PathOption (Fails on build)
+-opts.Add('datadir', 'Path suffix where where VDrift data will be installed', default_datadir) 
++# in most case datadir doesn't exist => do not use PathOption (Fails on build)
++opts.Add('datadir', 'Path suffix where VDrift data will be installed', default_datadir)
++opts.Add('iconsdir', 'Path suffix where VDrift icons will be installed', default_iconsdir)
+ opts.Add('localedir', 'Path where VDrift locale will be installed', default_localedir)
+ opts.Add('bindir', 'Path suffix where VDrift binary executable will be installed', default_bindir)
+ 
+@@ -335,6 +337,7 @@ Type: 'scons' to compile with the default options.
+       'scons destdir=$PWD/tmp' to install to $PWD/tmp staging area.
+       'scons datadir=' to install data files into an alternate directory.
+       'scons bindir=games/bin' to install executable into an alternate directory.
++      'scons iconsdir=share/icons/hicolor' to install the icons into an alternate directory.
+       'scons localedir=/usr/share/locale' to install language files into an alternate directory.
+       'scons release=1' to turn on compiler optimizations and disable debugging info.
+       'scons builddir_release=build' to set release build directory.
+@@ -375,6 +378,7 @@ env = conf.Finish()
+ # directories #
+ #-------------#
+ env['data_directory'] = env['destdir'] + env['prefix'] + '/' + env['datadir']
++env['icons_directory'] = env['destdir'] + env['prefix'] + '/' + env['iconsdir']
+ env['locale_directory'] = env['destdir'] + env['prefix'] + '/' + env['localedir']
+ cppdefines.append(("SETTINGS_DIR", '"%s"' % env['settings']))
+ if sys.platform in ['win32', 'msys', 'cygwin']:
-- 
2.46.0