[bug#73754,5/5] gnu: jg-bsnes: Unbundle SameBoy.

Message ID cb93e8ce73ea21c6764d15e85744b0732bc11d87.1728684335.git.maxim.cournoyer@gmail.com
State New
Headers
Series Unbundle SameBoy from jg-bsnes. |

Commit Message

Maxim Cournoyer Oct. 12, 2024, 4:28 a.m. UTC
  * gnu/packages/emulators.scm (jg-bsnes) [source]: Delete deps/gb in snippet.
<patches>: Apply unbundling patch.
[make-flags]: Add USE_VENDORED_SAMEBOY=0 flag.
[inputs]: Add sameboy.
* gnu/packages/patches/jg-bsnes-unbundle-sameboy.patch: New file.
* gnu/local.mk (dist_patch_DATA): Register it.

Change-Id: I0ce850b366663d88d66becb9121b13c48d4091a3
---
 gnu/local.mk                                  |   1 +
 gnu/packages/emulators.scm                    |   9 +-
 .../patches/jg-bsnes-unbundle-sameboy.patch   | 101 ++++++++++++++++++
 3 files changed, 108 insertions(+), 3 deletions(-)
 create mode 100644 gnu/packages/patches/jg-bsnes-unbundle-sameboy.patch
  

Patch

diff --git a/gnu/local.mk b/gnu/local.mk
index 544cf36f04..1eb3c66f85 100644
--- a/gnu/local.mk
+++ b/gnu/local.mk
@@ -1592,6 +1592,7 @@  dist_patch_DATA =						\
   %D%/packages/patches/jfsutils-add-sysmacros.patch		\
   %D%/packages/patches/jfsutils-gcc-compat.patch		\
   %D%/packages/patches/jfsutils-include-systypes.patch		\
+  %D%/packages/patches/jg-bsnes-unbundle-sameboy.patch		\
   %D%/packages/patches/john-the-ripper-jumbo-with-gcc-11.patch	\
   %D%/packages/patches/json-c-0.13-CVE-2020-12762.patch		\
   %D%/packages/patches/json-c-0.12-CVE-2020-12762.patch		\
diff --git a/gnu/packages/emulators.scm b/gnu/packages/emulators.scm
index 3df1b94506..3d4b833c11 100644
--- a/gnu/packages/emulators.scm
+++ b/gnu/packages/emulators.scm
@@ -3291,10 +3291,12 @@  (define-public jg-bsnes
               ;; - snes_spc (also modified by this project)
               (snippet '(begin
                           (use-modules (guix build utils))
+                          (delete-file-recursively "deps/gb")
                           (delete-file-recursively "deps/libsamplerate")))
               (sha256
                (base32
-                "0z1ka4si8vcb0j6ih087cni18vpgfd3qnaw24awycxz23xc0jkdv"))))
+                "0z1ka4si8vcb0j6ih087cni18vpgfd3qnaw24awycxz23xc0jkdv"))
+              (patches (search-patches "jg-bsnes-unbundle-sameboy.patch"))))
     (build-system gnu-build-system)
     (arguments
      (list #:tests? #f                  ;no test suite
@@ -3302,11 +3304,12 @@  (define-public jg-bsnes
            #~(list (string-append "AR=" #$(ar-for-target))
                    (string-append "CC=" #$(cc-for-target))
                    (string-append "CXX=" #$(cxx-for-target))
-                   (string-append "PREFIX=" #$output))
+                   (string-append "PREFIX=" #$output)
+                   (string-append "USE_EXTERNAL_SAMEBOY=1"))
            #:phases #~(modify-phases %standard-phases
                         (delete 'configure)))) ;no configure script
     (native-inputs (list jg-api pkg-config))
-    (inputs (list libsamplerate))
+    (inputs (list libsamplerate sameboy))
     (home-page "https://gitlab.com/jgemu/bsnes")
     (synopsis "Jolly Good Fork of bsnes")
     (description "@code{bsnes-jg} is a cycle accurate emulator for the Super
diff --git a/gnu/packages/patches/jg-bsnes-unbundle-sameboy.patch b/gnu/packages/patches/jg-bsnes-unbundle-sameboy.patch
new file mode 100644
index 0000000000..1047dd4819
--- /dev/null
+++ b/gnu/packages/patches/jg-bsnes-unbundle-sameboy.patch
@@ -0,0 +1,101 @@ 
+Upstream-status: https://gitlab.com/jgemu/bsnes/-/merge_requests/429
+
+diff --git a/Makefile b/Makefile
+index 7371ff4..a4a8457 100644
+--- a/Makefile
++++ b/Makefile
+@@ -37,6 +37,9 @@ MKDIRS := deps/byuuML \
+ 	src/expansion \
+ 	src/processor
+ 
++# Set to 1 to use a system-provided SameBoy shared library.
++USE_EXTERNAL_SAMEBOY := 0
++
+ # Global symbols
+ # TODO: Darwin export files expect mangled symbols for C++
+ SYMBOLS :=
+@@ -61,6 +64,9 @@ CPPFLAGS_GB := -DGB_INTERNAL -DGB_DISABLE_CHEATS -DGB_DISABLE_DEBUGGER \
+ 	-D_GNU_SOURCE -DGB_VERSION=\"0.16.6\"
+ 
+ INCLUDES += $(CFLAGS_SAMPLERATE) -I$(DEPDIR)
++ifeq ($(USE_EXTERNAL_SAMEBOY), 0)
++INCLUDES += -I$(DEPDIR)/gb
++endif
+ LIBS += $(LIBS_SAMPLERATE)
+ 
+ EXT := cpp
+@@ -81,7 +87,13 @@ WARNINGS_CO := $(WARNINGS_MIN) -Wmissing-prototypes
+ WARNINGS_ICD := $(WARNINGS_CXX)
+ WARNINGS_GB := -Wall -Wno-missing-braces -Wno-multichar -Wno-unused-result
+ 
+-CSRCS := deps/gb/apu.c \
++CSRCS := \
++	deps/libco/libco.c \
++	deps/snes_spc/spc_dsp.c
++
++ifeq ($(USE_EXTERNAL_SAMEBOY), 0)
++CSRCS += \
++	deps/gb/apu.c \
+ 	deps/gb/camera.c \
+ 	deps/gb/display.c \
+ 	deps/gb/gb.c \
+@@ -96,9 +108,16 @@ CSRCS := deps/gb/apu.c \
+ 	deps/gb/sgb.c \
+ 	deps/gb/sm83_cpu.c \
+ 	deps/gb/timing.c \
+-	deps/gb/workboy.c \
+-	deps/libco/libco.c \
+-	deps/snes_spc/spc_dsp.c
++	deps/gb/workboy.c
++else
++CFLAGS_SAMEBOY = $(shell $(PKG_CONFIG) --cflags sameboy || echo fail)
++LIBS_SAMEBOY = $(shell $(PKG_CONFIG) --libs sameboy || echo fail)
++ifeq ($(CFLAGS_SAMEBOY)$(LIBS_SAMEBOY),failfail)
++$(error "pkg-config failure; CFLAGS_SAMEBOY and LIBS_SAMEBOY missing")
++endif
++INCLUDES += $(CFLAGS_SAMEBOY)
++LIBS += $(LIBS_SAMEBOY)
++endif
+ 
+ CXXSRCS := deps/byuuML/byuuML.cpp \
+ 	src/audio.cpp \
+@@ -243,8 +262,11 @@ install-data: all
+ 
+ install-docs::
+ 	cp $(DEPDIR)/byuuML/LICENSE $(DESTDIR)$(DOCDIR)/LICENSE-byuuML
+-	cp $(DEPDIR)/gb/LICENSE $(DESTDIR)$(DOCDIR)/LICENSE-gb
+ 	cp $(DEPDIR)/libco/LICENSE $(DESTDIR)$(DOCDIR)/LICENSE-libco
+ 	cp $(DEPDIR)/snes_spc/LICENSE $(DESTDIR)$(DOCDIR)/LICENSE-spc
++ifeq ($(USE_EXTERNAL_SAMEBOY), 0)
++install-docs::
++	cp $(DEPDIR)/gb/LICENSE $(DESTDIR)$(DOCDIR)/LICENSE-gb
++endif
+ 
+ include $(SOURCEDIR)/mk/rules.mk
+diff --git a/README b/README
+index 3db6823..910c8d5 100644
+--- a/README
++++ b/README
+@@ -30,7 +30,8 @@ Options:
+   ENABLE_HTML - Set to a non-zero value to generate the html documentation.
+   ENABLE_STATIC - Set to a non-zero value to build a static archive.
+   ENABLE_STATIC_JG - Set to a non-zero value to build a static JG archive.
+-  USE_VENDORED_SAMPLERATE - Set non-zero to use vendored libsamplerate
++  USE_VENDORED_SAMPLERATE - Set non-zero to use vendored libsamplerate.
++  USE_EXTERNAL_SAMEBOY - Set non-zero to use system-provided sameboy.
+ 
+ Linux:
+   make
+diff --git a/src/coprocessor/icd.cpp b/src/coprocessor/icd.cpp
+index 2b0fb96..066b63e 100644
+--- a/src/coprocessor/icd.cpp
++++ b/src/coprocessor/icd.cpp
+@@ -28,7 +28,7 @@
+ #include "icd.hpp"
+ 
+ extern "C" {
+-  #include <gb/gb.h>
++  #include <gb.h>
+ }
+ 
+ //warning: the size of this object will be too large due to C++ size rules differing from C rules.