Subject: [bug#64114] [PATCH v2 1/2] gnu: fftw: Build entirely from source.

From: David Elsing <[email-masked]>
Date: Sun, 26 Jan 2025 16:54:32 +0000

* gnu/packages/algebra.scm (fftw)[source]: Use git checkout without
autogenerated files.
[arguments]<#:configure-flags>: Use Gexps and set --enable-maintainer-mode and
--disable-doc.
<#:phases>: Add 'fix-maintainer-build' phase.
[native-inputs]: Add autoconf, automake, libtool, ocaml, ocamlbuild, ocaml-num
and ocaml-findlib.
(fftwf,fftw-openmpi)[arguments]: Use Gexps.
---
 gnu/packages/algebra.scm | 111 ++++++++++++++++++++++++---------------
 1 file changed, 70 insertions(+), 41 deletions(-)

diff --git a/gnu/packages/algebra.scm b/gnu/packages/algebra.scm
index 7c22e811d5..96f9b36a0e 100644
--- a/gnu/packages/algebra.scm
+++ b/gnu/packages/algebra.scm
@@ -17,6 +17,7 @@
 ;;; Copyright © 2022 Maxim Cournoyer <[email-masked]>
 ;;; Copyright © 2023 Mehmet Tekman <[email-masked]>
 ;;; Copyright © 2025 Sharlatan Hellseher <[email-masked]>
+;;; Copyright © 2025 David Elsing <[email-masked]>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -40,6 +41,7 @@ (define-module (gnu packages algebra)
   #:use-module (gnu packages bison)
   #:use-module (gnu packages boost)
   #:use-module (gnu packages check)
+  #:use-module (gnu packages code)
   #:use-module (gnu packages compression)
   #:use-module (gnu packages cpp)
   #:use-module (gnu packages curl)
@@ -47,6 +49,7 @@ (define-module (gnu packages algebra)
   #:use-module (gnu packages flex)
   #:use-module (gnu packages fltk)
   #:use-module (gnu packages gcc)
+  #:use-module (gnu packages ghostscript)
   #:use-module (gnu packages gl)
   #:use-module (gnu packages graphviz)
   #:use-module (gnu packages image)
@@ -68,6 +71,7 @@ (define-module (gnu packages algebra)
   #:use-module (gnu packages tex)
   #:use-module (gnu packages texinfo)
   #:use-module (gnu packages text-editors)
+  #:use-module (gnu packages xfig)
   #:use-module (gnu packages xiph)
   #:use-module (gnu packages xml)
   #:use-module (gnu packages xorg)
@@ -730,37 +734,62 @@ (define-public fftw
     (name "fftw")
     (version "3.3.10")
     (source (origin
-             (method url-fetch)
-             (uri (string-append "ftp://ftp.fftw.org/pub/fftw/fftw-"
-                                 version".tar.gz"))
-             (sha256
-              (base32
-               "0rv4w90b65b2kvjpj8g9bdkl4xqc42q20f5bzpxdrkajk1a35jan"))))
+              ;; Release tarball contains many generated files
+              (method git-fetch)
+              (uri (git-reference
+                    (url "https://github.com/FFTW/fftw3")
+                    (commit (string-append "fftw-" version))))
+              (file-name (git-file-name name version))
+              (sha256
+               (base32
+                "11r4kd1478mi35vv6fgmg6qibqkqjhb77pqxaa8374rxdlqazgyy"))))
     (build-system gnu-build-system)
     (arguments
-     `(#:configure-flags
-       '("--enable-shared" "--enable-openmp" "--enable-threads"
-         ,@(let ((system (or (%current-target-system) (%current-system))))
-             ;; Enable SIMD extensions for codelets.  See details at:
-             ;; <http://fftw.org/fftw3_doc/Installation-on-Unix.html>.
-             (cond
-              ((string-prefix? "x86_64" system)
-               '("--enable-sse2" "--enable-avx" "--enable-avx2"
-                 "--enable-avx512" "--enable-avx-128-fma"))
-              ((string-prefix? "i686" system)
-               '("--enable-sse2"))
-              ((string-prefix? "aarch64" system)
-               ;; Note that fftw supports NEON on 32-bit ARM only when
-               ;; compiled for single-precision.
-               '("--enable-neon"))
-              (else
-               '())))
-         ;; By default '-mtune=native' is used.  However, that may cause the
-         ;; use of ISA extensions (e.g. AVX) that are not necessarily
-         ;; available on the user's machine when that package is built on a
-         ;; different machine.
-         "ax_cv_c_flags__mtune_native=no")))
-    (native-inputs (list perl))
+     (list
+      #:configure-flags
+      #~(list "--enable-shared"
+              "--enable-openmp"
+              "--enable-threads"
+              "--enable-maintainer-mode"
+              "--disable-doc"
+              #$@(let ((system (or (%current-target-system) (%current-system))))
+                   ;; Enable SIMD extensions for codelets.  See details at:
+                   ;; <https://fftw.org/fftw3_doc/Installation-on-Unix.html>.
+                   (cond
+                    ((string-prefix? "x86_64" system)
+                     '("--enable-sse2" "--enable-avx" "--enable-avx2"
+                       "--enable-avx512" "--enable-avx-128-fma"))
+                    ((string-prefix? "i686" system)
+                     '("--enable-sse2"))
+                    ((string-prefix? "aarch64" system)
+                     ;; Note that fftw supports NEON on 32-bit ARM only when
+                     ;; compiled for single-precision.
+                     '("--enable-neon"))
+                    (else '())))
+              ;; By default '-mtune=native' is used.  However, that may cause the
+              ;; use of ISA extensions (e.g. AVX) that are not necessarily
+              ;; available on the user's machine when that package is built on a
+              ;; different machine.
+              "ax_cv_c_flags__mtune_native=no")
+      #:phases
+      #~(modify-phases %standard-phases
+          (add-after 'unpack 'fix-maintainer-build
+            (lambda _
+              ;; This script calls configure
+              (delete-file "bootstrap.sh")
+              (invoke "touch" "ChangeLog")
+              ;; OCaml Num library
+              (substitute* "genfft/Makefile.am"
+                ((",nums")
+                 " -package num")))))))
+    (native-inputs (list autoconf
+                         automake
+                         libtool
+                         ocaml
+                         ocamlbuild
+                         ocaml-num
+                         ocaml-findlib
+                         perl))
     (home-page "https://fftw.org")
     (synopsis "Computing the discrete Fourier transform")
     (description
@@ -790,14 +819,14 @@ (define-public fftwf
     (arguments
      (substitute-keyword-arguments (package-arguments fftw)
        ((#:configure-flags fftw-configure-flags)
-        `(cons* "--enable-single"
-                ,@(if (string-prefix? "arm" (or (%current-target-system)
-                                                (%current-system)))
-                      ;; fftw supports NEON on 32-bit ARM only when compiled
-                      ;; for single-precision, so add it here.
-                      '("--enable-neon")
-                      '())
-                ,fftw-configure-flags))))
+        #~(cons* "--enable-single"
+                 #$@(if (string-prefix? "arm" (or (%current-target-system)
+                                                  (%current-system)))
+                        ;; fftw supports NEON on 32-bit ARM only when compiled
+                        ;; for single-precision, so add it here.
+                        '("--enable-neon")
+                        '())
+                 #$fftw-configure-flags))))
     (description
      (string-append (package-description fftw)
                     "  Single-precision version."))))
@@ -811,11 +840,11 @@ (define-public fftw-openmpi
     (arguments
      (substitute-keyword-arguments (package-arguments fftw)
        ((#:configure-flags cf)
-        `(cons "--enable-mpi" ,cf))
+        #~(cons "--enable-mpi" #$cf))
        ((#:phases phases '%standard-phases)
-        `(modify-phases ,phases
-           (add-before 'check 'mpi-setup
-             ,%openmpi-setup)))))
+        #~(modify-phases #$phases
+            (add-before 'check 'mpi-setup
+              #$%openmpi-setup)))))
     (description
      (string-append (package-description fftw)
                     "  With OpenMPI parallelism support."))))
-- 
2.46.0