Subject: [bug#78102] [PATCH v2 3/3] gnu: Add redumper.

From: Maxim Cournoyer <[email-masked]>
Date: Wed, 30 Apr 2025 00:31:40 +0900

* gnu/packages/audio.scm (redumper): New variable.

Change-Id: I3740c6941d1ab11ac38993775a8004618636513c
---

I was not able to fix cross-compilation when using clang, as it fails
to detect the glibc library objects needed.  Here's an attempt:

       ;; The build system uses CMake modules features that are only available
       ;; when using Ninja.
-      #:configure-flags #~(list "-GNinja"
-                                "-DREDUMPER_CLANG_USE_LIBCPP=ON"
-                                (string-append "-DREDUMPER_VERSION_BUILD="
-                                               #$version)
-                                "-DCMAKE_BUILD_TYPE=Release")
+      #:configure-flags
+      #~(list "-GNinja"
+              "-DCMAKE_CXX_COMPILER=clang++"
+              #$@(if (%current-target-system)
+                     (list (string-append "-DCMAKE_CXX_COMPILER_TARGET="
+                                          (%current-target-system)))
+                     '())
+              "-DREDUMPER_CLANG_USE_LIBCPP=ON"
+              (string-append "-DREDUMPER_VERSION_BUILD="
+                             #$version)
+              "-DCMAKE_BUILD_TYPE=Release")
       #:phases
       #~(modify-phases %standard-phases
           (add-after 'unpack 'patch-build-system

Which errors like:

Run Build Command(s): /gnu/store/w02489mcgfg5mj9z4c6nmnh3185v5xlv-ninja-1.11.1/bin/ninja -v cmTC_aa843
    [1/2] /gnu/store/dfi5zbk288grsj5xnxpcihyy235sb2zv-clang-toolchain-19.1.7/bin/clang++ --target=i686-linux-gnu    -MD -MT CMakeFiles/cmTC_aa843.dir/testCXXCompiler.cxx.o -MF CMakeFiles/cmTC_aa843.dir/testCXXCompiler.cxx.o.d -o CMakeFiles/cmTC_aa843.dir/testCXXCompiler.cxx.o -c /tmp/guix-build-redumper-561.drv-0/build/CMakeFiles/CMakeScratch/TryCompile-he4ad3/testCXXCompiler.cxx
    [2/2] : && /gnu/store/dfi5zbk288grsj5xnxpcihyy235sb2zv-clang-toolchain-19.1.7/bin/clang++ --target=i686-linux-gnu   CMakeFiles/cmTC_aa843.dir/testCXXCompiler.cxx.o -o cmTC_aa843   && :
    FAILED: cmTC_aa843 
    : && /gnu/store/dfi5zbk288grsj5xnxpcihyy235sb2zv-clang-toolchain-19.1.7/bin/clang++ --target=i686-linux-gnu   CMakeFiles/cmTC_aa843.dir/testCXXCompiler.cxx.o -o cmTC_aa843   && :
    /gnu/store/m8nars4f5d5x0sfhdlz69nc5blfyym1q-binutils-cross-i686-linux-gnu-2.41/bin/i686-linux-gnu-ld: cannot find crtbeginS.o: No such file or directory
    /gnu/store/m8nars4f5d5x0sfhdlz69nc5blfyym1q-binutils-cross-i686-linux-gnu-2.41/bin/i686-linux-gnu-ld: cannot find -lstdc++: No such file or directory

 gnu/packages/audio.scm | 76 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 76 insertions(+)

diff --git a/gnu/packages/audio.scm b/gnu/packages/audio.scm
index 03867b2da36..3850b916ca5 100644
--- a/gnu/packages/audio.scm
+++ b/gnu/packages/audio.scm
@@ -126,6 +126,7 @@ (define-module (gnu packages audio)
   #:use-module (gnu packages music)
   #:use-module (gnu packages ncurses)
   #:use-module (gnu packages networking)
+  #:use-module (gnu packages ninja)
   #:use-module (gnu packages onc-rpc)
   #:use-module (gnu packages perl)
   #:use-module (gnu packages pkg-config)
@@ -4082,6 +4083,81 @@ (define-public libshout-idjc
     ;; GNU Library (not Lesser) General Public License.
     (license license:lgpl2.0+)))
 
+(define-public redumper
+  (package
+    (name "redumper")
+    (version "561")
+    (source (origin
+              (method git-fetch)
+              (uri (git-reference
+                    (url "https://github.com/superg/redumper")
+                    (commit (string-append "build_" version))))
+              (file-name (git-file-name name version))
+              (sha256
+               (base32
+                "1r0wfi0fn3rq7s28p89rkgpgf567akd8z25l8r9sj7p4p3xp9m91"))))
+    (build-system cmake-build-system)
+    (arguments
+     (list
+      #:cmake cmake-next
+      #:build-type "Release"
+      ;; The build system uses CMake modules features that are only available
+      ;; when using Ninja.
+      #:configure-flags #~(list "-GNinja"
+                                "-DREDUMPER_CLANG_USE_LIBCPP=ON"
+                                (string-append "-DREDUMPER_VERSION_BUILD="
+                                               #$version)
+                                "-DCMAKE_BUILD_TYPE=Release")
+      #:phases
+      #~(modify-phases %standard-phases
+          (add-after 'unpack 'patch-build-system
+            (lambda _
+              ;; The CMAKE_SYSTEM_VERSION is undefined when cross-compiling.
+              (substitute* "CMakeLists.txt"
+                (("\\$\\{CMAKE_SYSTEM_VERSION}")
+                 "\"${CMAKE_SYSTEM_VERSION}\""))))
+          (add-after 'unpack 'adjust-CPLUS_INCLUDE_PATH
+            ;; The libcxx include/c++/v1 directory is not exposed via
+            ;; CPLUS_INCLUDE_PATH by default, causing errors like
+            ;; "fatal error: 'format' file not found".
+            (lambda* (#:key native-inputs inputs #:allow-other-keys)
+              (setenv "CPLUS_INCLUDE_PATH"
+                      (string-append
+                       (search-input-directory inputs
+                                               "/include/c++/v1")
+                       ":" (getenv "CPLUS_INCLUDE_PATH")))))
+          (replace 'build
+            (lambda* (#:key parallel-build? #:allow-other-keys)
+              (invoke "cmake" "--build" "."
+                      "-j" (number->string
+                            (if parallel-build?
+                                (parallel-job-count)
+                                1)))))
+          (replace 'check
+            (lambda* (#:key build-type parallel-tests? tests?
+                      #:allow-other-keys)
+              (when tests?
+                (invoke "ctest" "-C" build-type
+                        "-j" (number->string
+                              (if parallel-tests?
+                                  (parallel-job-count)
+                                  1))))))
+          (replace 'install
+            (lambda _
+              ;; There is no CMake install target; manually install the
+              ;; binary.
+              (install-file "redumper"
+                            (string-append #$output "/bin")))))))
+    (native-inputs (list ninja clang-toolchain-19))
+    (inputs (list libcxx))
+    (home-page "https://github.com/superg/redumper")
+    (synopsis "Low-level CD/DVD dumper")
+    (description "@command{redumper} is a low-level byte perfect CD disc
+dumper.  It supports incremental dumps, advanced SCSI/C2 repair, intelligent
+audio CD offset detection, among other features.  @command{redumper} is also a
+general purpose DVD/HD-DVD/Blu-ray disc dumper.")
+    (license license:gpl3+)))
+
 (define-public resample
   (package
     (name "resample")
-- 
2.49.0