code:
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2017, 2018, 2019, 2020 Paul Garlick <pgarlick@tourbillion-technology.com>
;;;
;;; This file is part of GNU Guix.
;;;
;;; GNU Guix is free software; you can redistribute it and/or modify it
;;; under the terms of the GNU General Public License as published by
;;; the Free Software Foundation; either version 3 of the License, or (at
;;; your option) any later version.
;;;
;;; GNU Guix is distributed in the hope that it will be useful, but
;;; WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;;; GNU General Public License for more details.
;;;
;;; You should have received a copy of the GNU General Public License
;;; along with GNU Guix.  If not, see <http://www.gnu.org/licenses/>.

(define-module (gnu packages simulation)
  #:use-module (gnu packages)
  #:use-module (gnu packages algebra)
  #:use-module (gnu packages admin)
  #:use-module (gnu packages base)
  #:use-module (gnu packages bash)
  #:use-module (gnu packages bison)
  #:use-module (gnu packages boost)
  #:use-module (gnu packages check)
  #:use-module (gnu packages cmake)
  #:use-module (gnu packages compression)
  #:use-module (gnu packages flex)
  #:use-module (gnu packages gettext)
  #:use-module (gnu packages gcc)
  #:use-module (gnu packages gl)
  #:use-module (gnu packages graphics)
  #:use-module (gnu packages gtk)
  #:use-module (gnu packages linux)
  #:use-module (gnu packages m4)
  #:use-module (gnu packages maths)
  #:use-module (gnu packages mpi)
  #:use-module (gnu packages multiprecision)
  #:use-module (gnu packages ncurses)
  #:use-module (gnu packages pkg-config)
  #:use-module (gnu packages python)
  #:use-module (gnu packages python-xyz)
  #:use-module (gnu packages readline)
  #:use-module (gnu packages tls)
  #:use-module (gnu packages version-control)
  #:use-module (gnu packages xml)
  #:use-module (gnu packages xorg)
  #:use-module (guix download)
  #:use-module (guix svn-download)
  #:use-module (guix build-system cmake)
  #:use-module (guix build-system gnu)
  #:use-module (guix build-system python)
  #:use-module ((guix licenses) #:prefix license:)
  #:use-module (guix packages)
  #:use-module (guix utils)
  #:use-module (ice-9 ftw)
  #:use-module (ice-9 regex)
  #:use-module (srfi srfi-1))

(define-public openfoam
  (package
    (name "openfoam")
    (version "4.1")
    (source
     (origin
       (method url-fetch)
       (uri (string-append
             "http://dl.openfoam.org/source/"
             (string-map (lambda (x) (if (eq? x #\.) #\- x)) version)))
       (file-name (string-append name "-" version ".tar.gz"))
       (sha256
        (base32 "0cgxh4h2hf50qbvvdg5miwc2nympb0nrv3md96vb3gbs9vk8vq9d"))
       (patches (search-patches "openfoam-4.1-cleanup.patch"))
       (modules '((guix build utils)))
       (snippet
        '(begin
           ;; Include <sys/sysmacros.h>, which is where glibc >= 2.28 provides
           ;; 'major' and 'minor'.
           (substitute* "src/OSspecific/POSIX/fileStat.C"
             (("#include <unistd\\.h>")
              "#include <unistd.h>\n#include <sys/sysmacros.h>\n"))
           #t))))
    (build-system gnu-build-system)
    (inputs
     `(("boost" ,boost)
       ("cgal" ,cgal)
       ("flex" ,flex)
       ("git" ,git)
       ("gmp" ,gmp)
       ("libxt" ,libxt)
       ("metis" ,metis)
       ("mpfr" ,mpfr)
       ("ncurses" ,ncurses)
       ("readline" ,readline)
       ("scotch" ,pt-scotch32)
       ("zlib" ,zlib)))
    (native-inputs
     `(("bison" ,bison)))
    (propagated-inputs
     `(("gzip" ,gzip)
       ("gnuplot" ,gnuplot)
       ("openmpi" ,openmpi)))
    (outputs '("debug"                  ;~60MB
               "out"))
    (arguments
     `( ;; Executable files and shared libraries are located in the 'platforms'
       ;; subdirectory.
       #:strip-directories (list (string-append
                                  "lib/OpenFOAM-" ,version
                                  "/platforms/linux64GccDPInt32Opt/bin")
                                 (string-append
                                  "lib/OpenFOAM-" ,version
                                  "/platforms/linux64GccDPInt32Opt/lib"))
       #:tests? #f                                ; no tests to run

       #:modules ((ice-9 ftw)
                  (ice-9 regex)
                  (guix build gnu-build-system)
                  (guix build utils))

       #:phases (modify-phases %standard-phases
                  (add-after 'unpack 'rename-build-directory
                    (lambda _
                      (chdir "..")
                      ;; Use 'OpenFOAM-version' convention to match the file
                      ;; name expectations in the build phase.
                      (let ((unpack-dir (string-append
                                         (getcwd) "/"
                                         (list-ref (scandir (getcwd) (lambda (name)
                                                                       (string-match "^OpenFOAM" name))) 0)))
                            (build-dir (string-append
                                        (getcwd) "/OpenFOAM-" ,version)))
                        (rename-file unpack-dir build-dir) ; rename build directory
                        (chdir (basename build-dir))) ; move to build directory
                      #t))
                  (delete 'configure)             ; no configure phase
                  (replace 'build
                    (lambda _
                      (let ((libraries '("boost" "cgal" "gmp" "metis" "mpfr" "scotch")))
                        ;; set variables to define store paths
                        (for-each (lambda (library)
                                    (setenv (string-append
                                             (string-upcase library) "_ROOT")
                                            (assoc-ref %build-inputs library))) libraries))
                      ;; set variables to define package versions
                      (setenv "SCOTCHVERSION" ,(package-version scotch))
                      (setenv "METISVERSION" ,(package-version metis))
                      ;; set variable to pass extra 'rpath' arguments to linker
                      (setenv "LDFLAGS"
                              (string-append
                               "-Wl,"
                               "-rpath=" %output "/lib/OpenFOAM-" ,version
                               "/platforms/linux64GccDPInt32Opt/lib,"
                               "-rpath=" %output "/lib/OpenFOAM-" ,version
                               "/platforms/linux64GccDPInt32Opt/lib/dummy"))
                      ;; compile OpenFOAM libraries and applications
                      (zero? (system (format #f
                                             "source ./etc/bashrc && ./Allwmake -j~a"
                                             (parallel-job-count))))))
                  (add-after 'build 'update-configuration-files
                    (lambda _
                      ;; record store paths and package versions in
                      ;; configuration files
                      (substitute* "etc/config.sh/CGAL"
                        (("$BOOST_ROOT") (getenv "BOOST_ROOT")))
                      (substitute* "etc/config.sh/CGAL"
                        (("$CGAL_ROOT") (getenv "CGAL_ROOT")))
                      (substitute* "etc/config.sh/metis"
                        (("$METIS_ROOT") (getenv "METIS_ROOT")))
                      (substitute* "etc/config.sh/metis"
                        (("$METISVERSION") (getenv "METISVERSION")))
                      (substitute* "etc/config.sh/scotch"
                        (("$SCOTCH_ROOT") (getenv "SCOTCH_ROOT")))
                      (substitute* "etc/config.sh/scotch"
                        (("$SCOTCHVERSION") (getenv "SCOTCHVERSION")))
                      (substitute* "etc/config.sh/settings"
                        (("$GMP_ROOT") (getenv "GMP_ROOT")))
                      (substitute* "etc/config.sh/settings"
                        (("$MPFR_ROOT") (getenv "MPFR_ROOT")))
                      ;; reset lockDir variable to refer to write-enabled
                      ;; directory
                      (substitute* "wmake/wmake"
                        (("        lockDir=.*$")
                         "        lockDir=$HOME/.$WM_PROJECT/.wmake\n"))
                      (substitute* "wmake/wmakeScheduler"
                        (("lockDir=.*$")
                         "lockDir=$HOME/.$WM_PROJECT/.wmake\n"))
                      (substitute* "wmake/wmakeSchedulerUptime"
                        (("lockDir=.*$")
                         "lockDir=$HOME/.$WM_PROJECT/.wmake\n"))
                      #t))
                  (add-after 'build 'cleanup
                    ;; Avoid unncessary, voluminous object and dep files.
                    (lambda _
                      (delete-file-recursively
                       "platforms/linux64GccDPInt32Opt/src")
                      (delete-file-recursively
                       "platforms/linux64GccDPInt32OptSYSTEMOPENMPI")
                      (for-each delete-file (find-files "." "\\.o$"))
                      #t))
                  (replace 'install
                    (lambda _
                      ;; use 'OpenFOAM-version' convention
                      (let ((install-dir (string-append
                                          %output "/lib/OpenFOAM-" ,version)))
                        (mkdir-p install-dir)     ; create install directory
                        ;; move contents of build directory to install directory
                        (copy-recursively "." install-dir))))
                  (add-after 'install 'add-symbolic-link
                    (lambda _
                      ;; add symbolic link for standard 'bin' directory
                      (symlink
                       (string-append "./lib/OpenFOAM-" ,version
                                      "/platforms/linux64GccDPInt32Opt/bin")
                       (string-append %output "/bin"))
                      #t)))))
    ;; Note:
    ;;  Tutorial files are installed read-only in /gnu/store.
    ;;  To allow write permissions on files copied from the store a
    ;;  'chmod' step is needed before running the applications.  For
    ;;  example, from a user's login:
    ;;  $ source $GUIX_PROFILE/lib/OpenFOAM-4.1/etc/bashrc
    ;;  $ mkdir -p $FOAM_RUN
    ;;  $ cd $FOAM_RUN
    ;;  $ cp -r $FOAM_TUTORIALS/incompressible/simpleFoam/pitzDaily .
    ;;  $ cd pitzDaily
    ;;  $ chmod -R u+w .
    ;;  $ blockMesh
    (synopsis "Framework for numerical simulation of fluid flow")
    (description "OpenFOAM provides a set of solvers and methods for tackling
problems in the field of Computational Fluid Dynamics (CFD).  It is written in
C++.  Governing equations such as the Navier-Stokes equations can be solved in
integral form.  Physical processes such as phase change, droplet transport and
chemical reaction can be modelled.  Numerical methods are included to deal with
sharp gradients, such as those encountered in flows with shock waves and flows
with gas/liquid interfaces.  Large problems may be split into smaller, connected
problems for efficient solution on parallel systems.")
    (license license:gpl3+)
    (home-page "https://openfoam.org")))

(define-public python-fenics-dijitso
  (package
    (name "python-fenics-dijitso")
    (version "2019.1.0")
    (source
      (origin
        (method url-fetch)
        (uri (pypi-uri "fenics-dijitso" version))
        (sha256
          (base32
            "0lhqsq8ypdak0ahr2jnyvg07yrqp6wicjxi6k56zx24wp3qg60sc"))))
    (build-system python-build-system)
    (inputs
     `(("openmpi" ,openmpi)
       ("python-numpy" ,python-numpy)))
    (native-inputs
     `(("python-pytest-cov" ,python-pytest-cov)))
    (propagated-inputs
     `(("python-mpi4py" ,python-mpi4py)))
    (arguments
     `(#:phases
       (modify-phases %standard-phases
         (add-after 'build 'mpi-setup
           ,%openmpi-setup)
         (replace 'check
           (lambda _
             (setenv "HOME" "/tmp")
             (setenv "PYTHONPATH"
                     (string-append (getcwd) ":" (getenv "PYTHONPATH")))
             (with-directory-excursion "test"
               ;; Disable parallel tests to avoid race condition.  See
               ;; https://github.com/pytest-dev/pytest-cov/issues/237.
               (substitute* "runtests.sh"
                 (("for p in 1 4 8 16; do")
                  "for p in 1; do"))
               (invoke "./runtests.sh"))
             #t)))))
    (home-page "https://bitbucket.org/fenics-project/dijitso/")
    (synopsis "Distributed just-in-time building of shared libraries")
    (description
      "Dijitso provides a core component of the @code{FEniCS} framework,
namely the just-in-time compilation of C++ code that is generated from
Python modules.  It is called from within a C++ library, using ctypes
to import the dynamic shared library directly.

As long as the compiled code can provide a simple factory function to
a class implementing a predefined C++ interface, there is no limit to
the complexity of that interface.  Parallel support depends on the
@code{mpi4py} interface.")
    (license license:lgpl3+)))

(define-public python-fenics-ufl
  (package
    (name "python-fenics-ufl")
    (version "2019.1.0")
    (source
      (origin
        (method url-fetch)
        (uri (pypi-uri "fenics-ufl" version))
        (sha256
          (base32
            "10dz8x3lm68x2w3kkqcjask38h0zkhhak26jdbkppr8g9y8wny7p"))))
    (build-system python-build-system)
    (inputs
     `(("python-numpy" ,python-numpy)))
    (native-inputs
     `(("python-pytest" ,python-pytest)))
    (arguments
     '(#:phases
       (modify-phases %standard-phases
         (replace 'check
           (lambda _
             (setenv "PYTHONPATH"
                     (string-append (getcwd) ":" (getenv "PYTHONPATH")))
             (with-directory-excursion "test"
               (invoke "py.test"))
             #t)))))
    (home-page "https://bitbucket.org/fenics-project/ufl/")
    (synopsis "Unified language for form-compilers")
    (description "The Unified Form Language (UFL) is a domain specific
language for declaration of finite element discretizations of
variational forms.  More precisely, it defines a flexible interface
for choosing finite element spaces and defining expressions for weak
forms in a notation close to mathematical notation.

UFL is part of the FEniCS Project.")
    (license license:lgpl3+)))

(define-public python-fenics-fiat
  (package
    (name "python-fenics-fiat")
    (version "2019.1.0")
    (source
      (origin
        (method url-fetch)
        (uri (pypi-uri "fenics-fiat" version))
        (sha256
          (base32
            "13sc7lma3d2mh43an7i4kkdbbk4cmvxjk45wi43xnjd7qc38zg4b"))))
    (build-system python-build-system)
    (native-inputs
     `(("python-pytest" ,python-pytest)))
    (propagated-inputs
     `(("python-numpy" ,python-numpy)
       ("python-sympy" ,python-sympy)))
    (arguments
     '(#:phases
       (modify-phases %standard-phases
         (replace 'check
           (lambda _
             (setenv "PYTHONPATH"
                     (string-append (getcwd) ":" (getenv "PYTHONPATH")))
             (with-directory-excursion "test"
               ;; FIXME: three FIAT test modules are known to fail
               ;; with recent versions of pytest (>= 4).  These are
               ;; skipped for FIAT version 2019.1.0 pending an
               ;; upstream pull request. For details see request #59
               ;; at https://bitbucket.org/fenics-project/fiat/.
               (invoke "py.test" "unit/"
                       "--ignore=unit/test_fiat.py"
                       "--ignore=unit/test_quadrature.py"
                       "--ignore=unit/test_reference_element.py"))
             #t)))))
    (home-page "https://bitbucket.org/fenics-project/fiat/")
    (synopsis "Tabulation of finite element function spaces")
    (description
      "The FInite element Automatic Tabulator (FIAT) supports
generation of arbitrary order instances of the Lagrange elements on
lines, triangles, and tetrahedra.  It is also capable of generating
arbitrary order instances of Jacobi-type quadrature rules on the same
element shapes.  Further, H(div) and H(curl) conforming finite element
spaces such as the families of Raviart-Thomas, Brezzi-Douglas-Marini
and Nedelec are supported on triangles and tetrahedra.  Upcoming
versions will also support Hermite and nonconforming elements.

FIAT is part of the FEniCS Project.")
    (license license:lgpl3+)))

(define-public python-fenics-ffc
  (package
    (name "python-fenics-ffc")
    (version "2019.1.0.post0")
    (source
      (origin
        (method url-fetch)
        (uri (pypi-uri "fenics-ffc" version))
        (sha256
          (base32
            "1f2a44ha65fg3a1prrbrsz4dgvibsv0j5c3pi2m52zi93bhwwgg9"))))
    (build-system python-build-system)
    (native-inputs
     `(("python-pytest" ,python-pytest)))
    (propagated-inputs
     `(("python-fenics-dijitso" ,python-fenics-dijitso)
       ("python-fenics-fiat" ,python-fenics-fiat)
       ("python-fenics-ufl" ,python-fenics-ufl)))
    (arguments
     '(#:phases
       (modify-phases %standard-phases
         (replace 'check
           (lambda _
             (setenv "HOME" (getcwd))
             (setenv "PYTHONPATH"
                     (string-append (getcwd) ":" (getenv "PYTHONPATH")))
             (with-directory-excursion "test"
               ;; FIXME: the tests in subdirectory
               ;; 'unit/ufc/finite_element' require the ffc_factory
               ;; extension module.  This module, located in the 'libs'
               ;; subdirectory, needs to be built and made accessible
               ;; prior to running the tests.
               (invoke "py.test" "unit/" "--ignore=unit/ufc/")
               (with-directory-excursion "uflacs"
                 (invoke "py.test" "unit/")))
             #t)))))
    (home-page "https://bitbucket.org/fenics-project/ffc/")
    (synopsis "Compiler for finite element variational forms")
    (description "The FEniCS Form Compiler (FFC) is a compiler for
finite element variational forms.  From a high-level description of
the form, it generates efficient low-level C++ code that can be used
to assemble the corresponding discrete operator (tensor).  In
particular, a bilinear form may be assembled into a matrix and a
linear form may be assembled into a vector.  FFC may be used either
from the command line (by invoking the @code{ffc} command) or as a
Python module (@code{import ffc}).

FFC is part of the FEniCS Project.")
    ;; There are two files released with a public domain licence;
    ;; ufc.h and ufc_geometry.h, in subdirectory 'ffc/backends/ufc'.
    (license (list license:public-domain license:lgpl3+))))

(define-public fenics-dolfin
  (package
    (name "fenics-dolfin")
    (version "2019.1.0.post0")
    (source
      (origin
        (method url-fetch)
        (uri (string-append
              "https://bitbucket.org/fenics-project/dolfin/get/"
              version ".tar.gz"))
        (file-name (string-append name "-" version ".tar.gz"))
        (sha256
          (base32
           "1m91hwcq5gfj4qqswp8l8kj58nia48f0n4kq13w0xqj4biq7rla0"))
        (modules '((guix build utils)))
        (snippet
         '(begin
            ;; Make sure we don't use the bundled test framework.
            (delete-file-recursively "test/unit/cpp/catch")
            (substitute* "test/unit/cpp/main.cpp"
              ;; Use standard search paths for 'catch' header file.
              (("#include.*")
               "#include <catch.hpp>\n"))
            (substitute* "test/unit/cpp/CMakeLists.txt"
              ;; Specify directory to find the header file.
              (("(^set\\(CATCH_INCLUDE_DIR ).*(/catch\\))" _ front back)
               (string-append front
                              "$ENV{CATCH_DIR}/include" back "\n")))
            #t))))
    (build-system cmake-build-system)
    (inputs
     `(("blas" ,openblas)
       ("boost" ,boost)
       ("eigen" ,eigen)
       ("hdf5" ,hdf5-parallel-openmpi)
       ("lapack" ,lapack)
       ("libxml2" ,libxml2)
       ("openmpi" ,openmpi)
       ("python" ,python-3)
       ("scotch" ,pt-scotch32)
       ("suitesparse" ,suitesparse)
       ("sundials" ,sundials-openmpi)
       ("zlib" ,zlib)))
    (native-inputs
     `(("catch" ,catch-framework2-1)
       ("pkg-config" ,pkg-config)))
    (propagated-inputs
     `(("ffc" ,python-fenics-ffc)
       ("petsc" ,petsc-openmpi)
       ("slepc" ,slepc-openmpi)))
    (arguments
     `(#:configure-flags
       `("-DDOLFIN_ENABLE_DOCS:BOOL=OFF"
         "-DDOLFIN_ENABLE_HDF5:BOOL=ON"
         "-DDOLFIN_ENABLE_MPI:BOOL=ON"
         "-DDOLFIN_ENABLE_PARMETIS:BOOL=OFF"
         "-DDOLFIN_ENABLE_SCOTCH:BOOL=ON"
         "-DDOLFIN_ENABLE_SUNDIALS:BOOL=ON"
         "-DDOLFIN_ENABLE_TRILINOS:BOOL=OFF")
       #:phases
       (modify-phases %standard-phases
         (add-after 'patch-usr-bin-file 'mpi-setup
           ,%openmpi-setup)
         (add-after 'patch-source-shebangs 'set-paths
           (lambda _
             ;; Define paths to store locations.
             (setenv "BLAS_DIR" (assoc-ref %build-inputs "blas"))
             (setenv "CATCH_DIR" (assoc-ref %build-inputs "catch"))
             (setenv "LAPACK_DIR" (assoc-ref %build-inputs "lapack"))
             (setenv "PETSC_DIR" (assoc-ref %build-inputs "petsc"))
             (setenv "SLEPC_DIR" (assoc-ref %build-inputs "slepc"))
             (setenv "SCOTCH_DIR" (assoc-ref %build-inputs "scotch"))
             (setenv "SUNDIALS_DIR" (assoc-ref %build-inputs "sundials"))
             (setenv "UMFPACK_DIR" (assoc-ref %build-inputs "suitesparse"))
             #t))
         (add-before 'check 'pre-check
           (lambda _
             ;; The Dolfin repository uses git-lfs, whereby web links are
             ;; substituted for large files.  Guix does not currently support
             ;; git-lfs, so only the links are downloaded.  The tests that
             ;; require the absent meshes cannot run and are skipped.
             ;;
             ;; Two other serial tests fail and are skipped.
             ;; i) demo_stokes-iterative_serial,
             ;;   The MPI_Comm_rank() function was called before MPI_INIT was
             ;;   invoked
             ;; ii) demo_multimesh-stokes_serial:
             ;;   Warning: Found no facets matching domain for boundary
             ;;   condition.
             ;;
             ;; One mpi test fails and is skipped.
             ;; i) demo_stokes-iterative_mpi:
             ;;   The MPI_Comm_rank() function was called before MPI_INIT was
             ;;   invoked
             (call-with-output-file "CTestCustom.cmake"
               (lambda (port)
                 (display
                   (string-append
                    "set(CTEST_CUSTOM_TESTS_IGNORE "
                    "demo_bcs_serial "
                    "demo_bcs_mpi "
                    "demo_eigenvalue_serial "
                    "demo_eigenvalue_mpi "
                    "demo_navier-stokes_serial "
                    "demo_navier-stokes_mpi "
                    "demo_stokes-taylor-hood_serial "
                    "demo_stokes-taylor-hood_mpi "
                    "demo_subdomains_serial "
                    "demo_advection-diffusion_serial "
                    "demo_advection-diffusion_mpi "
                    "demo_auto-adaptive-navier-stokes_serial "
                    "demo_contact-vi-snes_serial "
                    "demo_contact-vi-snes_mpi "
                    "demo_contact-vi-tao_serial "
                    "demo_contact-vi-tao_mpi "
                    "demo_curl-curl_serial "
                    "demo_curl-curl_mpi "
                    "demo_dg-advection-diffusion_serial "
                    "demo_dg-advection-diffusion_mpi "
                    "demo_elasticity_serial "
                    "demo_elasticity_mpi "
                    "demo_elastodynamics_serial "
                    "demo_elastodynamics_mpi "
                    "demo_lift-drag_serial "
                    "demo_lift-drag_mpi "
                    "demo_mesh-quality_serial "
                    "demo_mesh-quality_mpi "
                    "demo_multimesh-stokes_serial "
                    "demo_stokes-iterative_serial "
                    "demo_stokes-iterative_mpi "
                    ")\n") port)))
             #t))
         (replace 'check
           (lambda _
             (and (invoke "make" "unittests")
                  (invoke "make" "demos")
                  (invoke "ctest" "-R" "unittests")
                  (invoke "ctest" "-R" "demo" "-R" "serial")
                  (invoke "ctest" "-R" "demo" "-R" "mpi")))))))
    (home-page "https://bitbucket.org/fenics-project/dolfin/")
    (synopsis "Problem solving environment for differential equations")
    (description
      "DOLFIN is a computational framework for finding numerical
solutions to problems described by differential equations.  Numerical
models in DOLFIN are constructed using general families of finite
elements.  Data structures are provided for discretizing the governing
system on a computational mesh.  A compact syntax, similar to
mathematical notation, is made available for defining function spaces
and expressing variational forms.  Interfaces to specialized matrix
solvers are provided for solving the resultant linear systems.

@code{fenics-dolfin} is part of the FEniCS project.  It is the C++
user interface to the FEniCS core components and external libraries.")
    ;; The source code for the DOLFIN C++ library is licensed under the
    ;; GNU Lesser General Public License, version 3 or later, with the
    ;; following exceptions:
    ;;
    ;; public-domain: dolfin/geometry/predicates.cpp
    ;;                dolfin/geometry/predicates.h
    ;;
    ;; zlib:          dolfin/io/base64.cpp
    ;;                dolfin/io/base64.h
    ;;
    ;; expat:         dolfin/io/pugiconfig.hpp
    ;;                dolfin/io/pugixml.cpp
    ;;                dolfin/io/pugixml.hpp
    (license (list license:public-domain
                   license:zlib
                   license:expat
                   license:lgpl3+))))

(define-public fenics
  (package (inherit fenics-dolfin)
    (name "fenics")
    (build-system python-build-system)
    (inputs
     `(("pybind11" ,pybind11)
       ("python-matplotlib" ,python-matplotlib)
       ,@(alist-delete "python" (package-inputs fenics-dolfin))))
    (native-inputs
     `(("cmake" ,cmake-minimal)
       ("ply" ,python-ply)
       ("pytest" ,python-pytest)
       ("python-decorator" ,python-decorator)
       ("python-pkgconfig" ,python-pkgconfig)
       ,@(package-native-inputs fenics-dolfin)))
    (propagated-inputs
     `(("dolfin" ,fenics-dolfin)
       ("petsc4py" ,python-petsc4py)
       ("slepc4py" ,python-slepc4py)))
    (arguments
     `(#:phases
       (modify-phases %standard-phases
         (add-after 'patch-source-shebangs 'set-paths
           (lambda _
             ;; Define paths to store locations.
             (setenv "PYBIND11_DIR" (assoc-ref %build-inputs "pybind11"))
             ;; Move to python sub-directory.
             (chdir "python")
             #t))
         (add-after 'build 'mpi-setup
           ,%openmpi-setup)
         (add-before 'check 'pre-check
           (lambda _
             ;; Exclude three tests that generate
             ;; 'NotImplementedError' in matplotlib version 3.1.2.
             ;; See
             ;; <https://github.com/matplotlib/matplotlib/issues/15382>.
             ;; Also exclude tests that require meshes supplied by
             ;; git-lfs.
             (substitute* "demo/test.py"
               (("(.*stem !.*)" line)
                (string-append
                 line "\n"
                 "excludeList = [\n"
                 "'built-in-meshes', \n"
                 "'hyperelasticity', \n"
                 "'elasticity', \n"
                 "'multimesh-quadrature', \n"
                 "'multimesh-marking', \n"
                 "'mixed-poisson-sphere', \n"
                 "'mesh-quality', \n"
                 "'lift-drag', \n"
                 "'elastodynamics', \n"
                 "'dg-advection-diffusion', \n"
                 "'curl-curl', \n"
                 "'contact-vi-tao', \n"
                 "'contact-vi-snes', \n"
                 "'collision-detection', \n"
                 "'buckling-tao', \n"
                 "'auto-adaptive-navier-stokes', \n"
                 "'advection-diffusion', \n"
                 "'subdomains', \n"
                 "'stokes-taylor-hood', \n"
                 "'stokes-mini', \n"
                 "'navier-stokes', \n"
                 "'eigenvalue']\n"
                 "demos = ["
                 "d for d in demos if d[0].stem not in "
                 "excludeList]\n")))
             (setenv "HOME" (getcwd))
             (setenv "PYTHONPATH"
                     (string-append
                      (getcwd) "/build/lib.linux-x86_64-"
                      ,(version-major+minor (package-version python)) ":"
                      (getenv "PYTHONPATH")))
             ;; Restrict OpenBLAS to MPI-only in preference to MPI+OpenMP.
             (setenv "OPENBLAS_NUM_THREADS" "1")
             #t))
         (replace 'check
           (lambda _
             (with-directory-excursion "test"
               ;; Note: The test test_snes_set_from_options() in the file
               ;; unit/nls/test_PETScSNES_solver.py fails and is ignored.
               (and (invoke "py.test" "unit" "--ignore"
                            "unit/nls/test_PETScSNES_solver.py")
                    (invoke "mpirun" "-np" "3" "python" "-B" "-m"
                            "pytest" "unit" "--ignore"
                            "unit/nls/test_PETScSNES_solver.py")))
             (with-directory-excursion "demo"
               ;; Check demos.
               (invoke "python" "generate-demo-files.py")
               (and (invoke "python" "-m" "pytest" "-v" "test.py")
                    (invoke "python" "-m" "pytest" "-v" "test.py"
                            "--mpiexec=mpiexec" "--num-proc=3")))
             #t))
         (add-after 'install 'install-demo-files
           (lambda* (#:key outputs #:allow-other-keys)
             (let* ((demos (string-append
                            (assoc-ref outputs "out")
                            "/share/python-dolfin/demo")))
               (mkdir-p demos)
               (with-directory-excursion "demo"
                 (for-each (lambda (file)
                             (let* ((dir (dirname file))
                                    (tgt-dir (string-append demos "/" dir)))
                               (unless (equal? "." dir)
                                 (mkdir-p tgt-dir)
                                 (install-file file tgt-dir))))
                           (find-files "." ".*\\.(py|gz|xdmf)$"))))
             #t)))))
    (home-page "https://fenicsproject.org/")
    (synopsis "High-level environment for solving differential equations")
    (description
      "@code{fenics} is a computing platform for solving general classes of
problems that involve differential equations.  @code{fenics} facilitates
access to efficient methods for dealing with ordinary differential
equations (ODEs) and partial differential equations (PDEs).  Systems of
equations such as these are commonly encountered in areas of engineering,
mathematics and the physical sciences.  It is particularly well-suited to
problems that can be solved using the Finite Element Method (FEM).

@code{fenics} is the top level of the set of packages that are developed
within the FEniCS project.  It provides the python user interface to the
FEniCS core components and external libraries.")
    (license license:lgpl3+)))

(define-public fullswof-2d
  (let ((revision 505)
        (release "1.09.01"))
    (package
      (name "fullswof-2d")
      (version release)
      (source (origin
               (method svn-fetch)
               (uri (svn-reference
                     (url (string-append "https://subversion.renater.fr/"
                                         "anonscm/svn/fullswof-2d/tags/"
                                         "release-" version))
                     (revision revision)))
               (file-name (string-append "fullswof-2d-" version "-checkout"))
               (sha256
                (base32
                 "16v08dx7h7n4wyddzbwimazwyj74ynis12mpjfkay4243npy44b8"))))
      (build-system gnu-build-system)
      (native-inputs
       `(("inetutils" ,inetutils))) ; for 'hostname', used in the check phase
      (arguments
       `(#:phases
         (modify-phases %standard-phases
           (delete 'configure)     ; no configure script
           (add-after 'build 'build-tools
             (lambda _
               (with-directory-excursion "Tools/ConvertFormat"
                 (invoke "make" "../../bin/asc2xyz")
                 (invoke "make" "../../bin/xyz2asc"))
               (with-directory-excursion "Tools/ExtractWindow"
                 (invoke "make" "../../bin/cropxyz"))
               #t))
           (replace 'check         ; no check target
             (lambda _
               (invoke "make" "benchref")))
           (replace 'install       ; no install target
             (lambda* (#:key outputs #:allow-other-keys)
               (let* ((out (assoc-ref outputs "out"))
                      (bin (string-append out "/bin"))
                      (doc (string-append
                            out "/share/doc/" ,name "-" ,version))
                      (examples (string-append doc "/Examples")))
                 (with-directory-excursion "bin"
                   (for-each (lambda (binary) (install-file binary bin))
                             (list "asc2xyz" "xyz2asc" "cropxyz"
                                   "FullSWOF_2D")))
                 (with-directory-excursion "doc"
                   (for-each (lambda (pdf) (install-file pdf doc))
                             (list "Documentation.pdf" "refman.pdf")))
                 (with-directory-excursion "Tools"
                   (for-each (lambda (dir)
                               (copy-file
                                (string-append dir "/README.txt")
                                (string-append doc "/README_" dir ".txt")))
                             (list "ConvertFormat" "ExtractWindow")))
                 (copy-recursively "Examples" examples)
                 #t))))))
      (home-page "https://www.idpoisson.fr/fullswof/")
      (synopsis "Two dimensional flow solver for flood modelling")
      (description "@code{FullSWOF_2d} is a numerical tool for solving
the shallow water equations on structured grids.  The name FullSWOF
refers to the Full form of the Shallow Water equations for Overland
Flow.  The discretized system of equations is solved using the finite
volume method.  A choice of shock-capturing methods is available to
locate the transition boundaries between the wet areas and the dry
areas in the model.  A semi-implicit method is used to advance the
solution in time.  The tool is typically applied to the modelling of
river flooding.")
      (license license:cecill))))


code:
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2015 Claes Wallin <claes.wallin@greatsinodevelopment.com>
;;; Copyright © 2016 Eric Le Bihan <eric.le.bihan.dev@free.fr>
;;; Copyright © 2017 Z. Ren <zren@dlut.edu.cn>
;;; Copyright © 2018, 2019, 2020 Tobias Geerinckx-Rice <me@tobias.gr>
;;; Copyright © 2020 Oleg Pykhalov <go.wigust@gmail.com>
;;;
;;; This file is part of GNU Guix.
;;;
;;; GNU Guix is free software; you can redistribute it and/or modify it
;;; under the terms of the GNU General Public License as published by
;;; the Free Software Foundation; either version 3 of the License, or (at
;;; your option) any later version.
;;;
;;; GNU Guix is distributed in the hope that it will be useful, but
;;; WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;;; GNU General Public License for more details.
;;;
;;; You should have received a copy of the GNU General Public License
;;; along with GNU Guix.  If not, see <http://www.gnu.org/licenses/>.

(define-module (gnu packages skarnet)
  #:use-module (gnu packages)
  #:use-module (guix licenses)
  #:use-module (guix packages)
  #:use-module (guix download)
  #:use-module (guix build-system gnu))

(define-public skalibs
  (package
    (name "skalibs")
    (version "2.9.2.1")
    (source
     (origin
      (method url-fetch)
      (uri (string-append "https://skarnet.org/software/skalibs/skalibs-"
                          version ".tar.gz"))
      (sha256
       (base32 "0ff551181vv9d1z5sv7yg6n4b88ajcdircs4p4nif4yl7nsrj2r5"))))
    (build-system gnu-build-system)
    (arguments
     '(#:tests? #f                      ; no tests exist
       #:phases (modify-phases %standard-phases
                  (add-after 'unpack 'reproducible
                    (lambda _
                      ;; Sort source files deterministically so that the *.a
                      ;; and *.so files are reproducible.
                      (substitute* "Makefile"
                        (("\\$\\(wildcard src/lib\\*/\\*.c\\)")
                         "$(sort $(wildcard src/lib*/*.c))"))
                      #t)))))
    (home-page "https://skarnet.org/software/skalibs/")
    (synopsis "Platform abstraction libraries for skarnet.org software")
    (description
     "This package provides lightweight C libraries isolating the developer
from portability issues, providing a unified systems API on all platforms,
including primitive data types, cryptography, and POSIX concepts like sockets
and file system operations.  It is used by all skarnet.org software.")
    (license isc)))

(define-public execline
  (package
    (name "execline")
    (version "2.6.0.2")
    (source
     (origin
      (method url-fetch)
      (uri (string-append "https://skarnet.org/software/execline/execline-"
                          version ".tar.gz"))
      (sha256
       (base32 "0wdg93hwpxxdqmsnd8j1nf3m2pf85n3rxaawzaih1y0ajyz6gwya"))))
    (build-system gnu-build-system)
    (inputs `(("skalibs" ,skalibs)))
    (arguments
     '(#:configure-flags (list
                          (string-append "--with-lib="
                                         (assoc-ref %build-inputs "skalibs")
                                         "/lib/skalibs")
                          (string-append "--with-sysdeps="
                                         (assoc-ref %build-inputs "skalibs")
                                         "/lib/skalibs/sysdeps"))
       #:phases (modify-phases %standard-phases
                  (add-after
                   'install 'post-install
                   (lambda* (#:key inputs outputs #:allow-other-keys)
                    (let* ((out (assoc-ref outputs "out"))
                           (bin (string-append out "/bin")))
                      (wrap-program (string-append bin "/execlineb")
                        `("PATH" ":" prefix (,bin)))))))
       #:tests? #f))                    ; no tests exist
    (home-page "https://skarnet.org/software/execline/")
    (license isc)
    (synopsis "Non-interactive shell-like language with minimal overhead")
    (description
     "Execline is a (non-interactive) scripting language, separated into a
parser (execlineb) and a set of commands meant to execute one another in a
chain-execution fashion, storing the whole script in the argument array.
It features conditional loops, getopt-style option handling, file name
globbing, redirection and other shell concepts, expressed as discrete commands
rather than in special syntax, minimizing runtime footprint and
complexity.")))

(define-public s6
  (package
   (name "s6")
   (version "2.9.1.0")
   (source
    (origin
     (method url-fetch)
     (uri (string-append "https://skarnet.org/software/s6/s6-"
                         version ".tar.gz"))
     (sha256
      (base32 "1xqzl2wnvcmcyhppk7mc10h1ac7fkik3i6gpyliwpf3d5i9mkqh5"))))
   (build-system gnu-build-system)
   (inputs `(("skalibs" ,skalibs)
             ("execline" ,execline)))
   (arguments
    `(#:configure-flags (list
                        (string-append "--with-lib="
                                       (assoc-ref %build-inputs "skalibs")
                                       "/lib/skalibs")
                        (string-append "--with-lib="
                                       (assoc-ref %build-inputs "execline")
                                       "/lib/execline")
                        (string-append "--with-sysdeps="
                                       (assoc-ref %build-inputs "skalibs")
                                       "/lib/skalibs/sysdeps"))
      #:tests? #f                       ; no tests exist
      #:phases
      (modify-phases %standard-phases
        (add-after 'install 'install-doc
          (lambda* (#:key outputs #:allow-other-keys)
            (let* ((out (assoc-ref outputs "out"))
                   (doc (string-append out "/share/doc/s6-" ,version)))
              (copy-recursively "doc" doc)
              #t))))))
   (home-page "https://skarnet.org/software/s6")
   (license isc)
   (synopsis "Small suite of programs for process supervision")
   (description
    "s6 is a small suite of programs for UNIX, designed to allow process
supervision (a.k.a. service supervision), in the line of daemontools and
runit, as well as various operations on processes and daemons.  It is meant to
be a toolbox for low-level process and service administration, providing
different sets of independent tools that can be used within or without the
framework, and that can be assembled together to achieve powerful
functionality with a very small amount of code.")))

(define-public s6-dns
  (package
   (name "s6-dns")
   (version "2.3.2.0")
   (source
    (origin
     (method url-fetch)
     (uri (string-append "https://skarnet.org/software/s6-dns/s6-dns-"
                         version ".tar.gz"))
     (sha256
      (base32 "09hyb1xv9glqq0yy7wy8hiwvlr78kwv552pags8ancgamag15di7"))))
    (build-system gnu-build-system)
    (inputs `(("skalibs" ,skalibs)))
    (arguments
     '(#:configure-flags (list
                          (string-append "--with-lib="
                                         (assoc-ref %build-inputs "skalibs")
                                         "/lib/skalibs")
                          (string-append "--with-sysdeps="
                                         (assoc-ref %build-inputs "skalibs")
                                         "/lib/skalibs/sysdeps"))
       #:tests? #f))                    ; no tests exist
    (home-page "https://skarnet.org/software/s6-dns")
    (license isc)
    (synopsis "Suite of DNS client programs")
    (description
     "s6-dns is a suite of DNS client programs and libraries for Unix systems,
as an alternative to the BIND, djbdns or other DNS clients.")))

(define-public s6-networking
  (package
   (name "s6-networking")
   (version "2.3.1.2")
   (source
    (origin
     (method url-fetch)
     (uri (string-append "https://skarnet.org/software/s6-networking/s6-networking-"
                         version ".tar.gz"))
     (sha256
      (base32 "1029bgwfmv903y5ji93j75m7p2jgchdxya1khxzb42q2z7yxnlyr"))))
    (build-system gnu-build-system)
    (inputs `(("skalibs" ,skalibs)
              ("execline" ,execline)
              ("s6" ,s6)
              ("s6-dns" ,s6-dns)))
    (arguments
     '(#:configure-flags (list
                          (string-append "--with-lib="
                                         (assoc-ref %build-inputs "skalibs")
                                         "/lib/skalibs")
                          (string-append "--with-lib="
                                         (assoc-ref %build-inputs "execline")
                                         "/lib/execline")
                          (string-append "--with-lib="
                                         (assoc-ref %build-inputs "s6")
                                         "/lib/s6")
                          (string-append "--with-lib="
                                         (assoc-ref %build-inputs "s6-dns")
                                         "/lib/s6-dns")
                          (string-append "--with-sysdeps="
                                         (assoc-ref %build-inputs "skalibs")
                                         "/lib/skalibs/sysdeps"))
       #:tests? #f))                    ; no tests exist
    (home-page "https://skarnet.org/software/s6-networking")
    (license isc)
    (synopsis "Suite of network utilities for Unix systems")
    (description
     "s6-networking is a suite of small networking utilities for Unix systems.
It includes command-line client and server management, TCP access control,
privilege escalation across UNIX domain sockets, IDENT protocol management and
clock synchronization.")))

(define-public s6-rc
  (package
   (name "s6-rc")
   (version "0.5.1.4")
   (source
    (origin
     (method url-fetch)
     (uri (string-append "https://skarnet.org/software/s6-rc/s6-rc-"
                         version ".tar.gz"))
     (sha256
      (base32 "07q0ixpwsmj1v08l6vd7qywdg33zzn8vhm21kvp179bapdzs8sdg"))))
    (build-system gnu-build-system)
    (inputs `(("skalibs" ,skalibs)
              ("execline" ,execline)
              ("s6" ,s6)))
    (arguments
     '(#:configure-flags (list
                          (string-append "--with-lib="
                                         (assoc-ref %build-inputs "skalibs")
                                         "/lib/skalibs")
                          (string-append "--with-lib="
                                         (assoc-ref %build-inputs "execline")
                                         "/lib/execline")
                          (string-append "--with-lib="
                                         (assoc-ref %build-inputs "s6")
                                         "/lib/s6")
                          (string-append "--with-sysdeps="
                                         (assoc-ref %build-inputs "skalibs")
                                         "/lib/skalibs/sysdeps"))
       #:tests? #f))                    ; no tests exist
    (home-page "https://skarnet.org/software/s6-rc")
    (license isc)
    (synopsis "Service manager for s6-based systems")
    (description
     "s6-rc is a service manager for s6-based systems, i.e. a suite of
programs that can start and stop services, both long-running daemons and
one-time initialization scripts, in the proper order according to a dependency
tree.  It ensures that long-running daemons are supervised by the s6
infrastructure, and that one-time scripts are also run in a controlled
environment.")))

(define-public s6-portable-utils
  (package
   (name "s6-portable-utils")
   (version "2.2.2.4")
   (source
    (origin
     (method url-fetch)
     (uri (string-append
           "https://skarnet.org/software/s6-portable-utils/s6-portable-utils-"
           version ".tar.gz"))
     (sha256
      (base32 "0494saavpqfa4v5kib69p186858yjy87hm5qm804a4xvq51wqbwm"))))
    (build-system gnu-build-system)
    (inputs `(("skalibs" ,skalibs)))
    (arguments
     '(#:configure-flags (list
                          (string-append "--with-lib="
                                         (assoc-ref %build-inputs "skalibs")
                                         "/lib/skalibs")
                          (string-append "--with-sysdeps="
                                         (assoc-ref %build-inputs "skalibs")
                                         "/lib/skalibs/sysdeps"))
       #:tests? #f))                    ; no tests exist
    (home-page "https://skarnet.org/software/s6-portable-utils")
    (license isc)
    (synopsis "Tiny command-line Unix utilities")
    (description
     "s6-portable-utils is a set of tiny general Unix utilities, often
performing well-known tasks such as @command{cut} and @command{grep}, but
optimized for simplicity and small size.  They were designed for embedded
systems and other constrained environments, but they work everywhere.")))

(define-public s6-linux-init
  (package
   (name "s6-linux-init")
   (version "1.0.4.2")
   (source
    (origin
     (method url-fetch)
     (uri (string-append
           "https://skarnet.org/software/s6-linux-init/s6-linux-init-"
           version ".tar.gz"))
     (sha256
      (base32 "0rp4k78555r38ir57a8w9qlxss4x487jqmhpn40ankpidwjs04gm"))))
    (build-system gnu-build-system)
    (inputs
     `(("execline" ,execline)
       ("s6", s6)
       ("skalibs" ,skalibs)))
    (arguments
     '(#:configure-flags
       (list
        (string-append "--with-lib="
                       (assoc-ref %build-inputs "skalibs")
                       "/lib/skalibs")
        (string-append "--with-lib="
                       (assoc-ref %build-inputs "execline")
                       "/lib/execline")
        (string-append "--with-lib="
                       (assoc-ref %build-inputs "s6")
                       "/lib/s6")
        (string-append "--with-sysdeps="
                       (assoc-ref %build-inputs "skalibs")
                       "/lib/skalibs/sysdeps"))
       #:tests? #f))                    ; no tests exist
    (home-page "https://skarnet.org/software/s6-linux-init")
    (license isc)
    (synopsis "Minimalistic tools to create an s6-based init system on Linux")
    (description
     "s6-linux-init is a set of minimalistic tools to create a s6-based init
system, including an @command{/sbin/init} binary, on a Linux kernel.

It is meant to automate creation of scripts revolving around the use of other
skarnet.org tools, especially s6, in order to provide a complete booting
environment with integrated supervision and logging without having to hand-craft
all the details.")))

(define-public s6-linux-utils
  (package
   (name "s6-linux-utils")
   (version "2.5.1.2")
   (source
    (origin
     (method url-fetch)
     (uri (string-append
           "https://skarnet.org/software/s6-linux-utils/s6-linux-utils-"
           version ".tar.gz"))
     (sha256
      (base32 "0w4jms9qyb5kx9zcyd3gzri60rrii2rbmh08s59ckg4awy27py86"))))
    (build-system gnu-build-system)
    (inputs `(("skalibs" ,skalibs)))
    (arguments
     '(#:configure-flags (list
                          (string-append "--with-lib="
                                         (assoc-ref %build-inputs "skalibs")
                                         "/lib/skalibs")
                          (string-append "--with-sysdeps="
                                         (assoc-ref %build-inputs "skalibs")
                                         "/lib/skalibs/sysdeps"))
       #:tests? #f))                    ; no tests exist
    (home-page "https://skarnet.org/software/s6-linux-utils")
    (license isc)
    (synopsis "Set of minimalistic Linux-specific system utilities")
    (description
     "s6-linux-utils is a set of minimalistic Linux-specific system utilities,
such as @command{mount}, @command{umount}, and @command{chroot} commands,
Linux uevent listeners, a @command{devd} device hotplug daemon, and more.")))

license: mit


code:
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2013, 2014, 2015, 2016, 2017, 2018, 2020 Ludovic Courtès <ludo@gnu.org>
;;;
;;; This file is part of GNU Guix.
;;;
;;; GNU Guix is free software; you can redistribute it and/or modify it
;;; under the terms of the GNU General Public License as published by
;;; the Free Software Foundation; either version 3 of the License, or (at
;;; your option) any later version.
;;;
;;; GNU Guix is distributed in the hope that it will be useful, but
;;; WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;;; GNU General Public License for more details.
;;;
;;; You should have received a copy of the GNU General Public License
;;; along with GNU Guix.  If not, see <http://www.gnu.org/licenses/>.

(define-module (gnu packages skribilo)
  #:use-module (guix packages)
  #:use-module (guix download)
  #:use-module (guix licenses)
  #:use-module (guix build-system gnu)
  #:use-module (gnu packages guile)
  #:use-module (gnu packages guile-xyz)
  #:use-module (gnu packages lout)
  #:use-module (gnu packages pkg-config)
  #:use-module (gnu packages plotutils)
  #:use-module (gnu packages imagemagick)
  #:use-module (gnu packages ghostscript))

(define-public skribilo
  (package
    (name "skribilo")
    (version "0.9.4")
    (source (origin
             (method url-fetch)
             (uri (string-append "mirror://savannah/skribilo/skribilo-"
                                 version ".tar.gz"))
             (sha256
              (base32
               "06ywnfjfa9sxrzdszb5sryzg266380g519cm64kq62sskzl7zmnf"))))
    (build-system gnu-build-system)
    (arguments
     ;; Make the modules available under the usual location.
     '(#:phases
       (modify-phases %standard-phases
         (add-before 'configure 'pre-configure
           (lambda* (#:key inputs #:allow-other-keys)
             ;; Make sure the 'skribilo' command gets to see
             ;; Guile-Reader, even if Guile-Reader is not in the search
             ;; path.
             (let ((reader (assoc-ref inputs "guile-reader")))
               (substitute* "src/skribilo.in"
                 (("^exec (.*) -c" _ things)
                  (string-append "exec " things
                                 " -L " reader "/share/guile/site/2.2"
                                 " -C " reader "/lib/guile/2.2/site-ccache"
                                 " -c"))))
             #t)))

       #:parallel-build? #f))

    (native-inputs `(("pkg-config" ,pkg-config)))

    (inputs `(("guile" ,guile-2.2)
              ("imagemagick" ,imagemagick)
              ("ghostscript" ,ghostscript)        ; for 'convert'
              ("ploticus" ,ploticus)
              ("lout" ,lout)))

    ;; The 'skribilo' command needs them, and for people using Skribilo as a
    ;; library, these inputs are needed as well.
    (propagated-inputs `(("guile-reader" ,guile2.2-reader)
                         ("guile-lib" ,guile2.2-lib)))

    (home-page "https://www.nongnu.org/skribilo/")
    (synopsis "Document production tool written in Guile Scheme")
    (description
     "Skribilo is a free document production tool that takes a structured
document representation as its input and renders that document in a variety of
output formats: HTML and Info for on-line browsing, and Lout and LaTeX for
high-quality hard copies.

The input document can use Skribilo's markup language to provide information
about the document's structure, which is similar to HTML or LaTeX and does not
require expertise.  Alternatively, it can use a simpler, “markup-less” format
that borrows from Emacs' outline mode and from other conventions used in
emails, Usenet and text.

Lastly, Skribilo provides Guile Scheme APIs.")
    (license gpl3+)))


code:
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2015 Ludovic Courtès <ludo@gnu.org>
;;; Copyright © 2015 Mark H Weaver <mhw@netris.org>
;;; Copyright © 2015 Eric Bavier <bavier@member.fsf.org>
;;; Copyright © 2018, 2019 Tobias Geerinckx-Rice <me@tobias.gr>
;;;
;;; This file is part of GNU Guix.
;;;
;;; GNU Guix is free software; you can redistribute it and/or modify it
;;; under the terms of the GNU General Public License as published by
;;; the Free Software Foundation; either version 3 of the License, or (at
;;; your option) any later version.
;;;
;;; GNU Guix is distributed in the hope that it will be useful, but
;;; WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;;; GNU General Public License for more details.
;;;
;;; You should have received a copy of the GNU General Public License
;;; along with GNU Guix.  If not, see <http://www.gnu.org/licenses/>.

(define-module (gnu packages slang)
  #:use-module (guix packages)
  #:use-module (guix download)
  #:use-module (guix utils)
  #:use-module (guix build-system gnu)
  #:use-module ((guix licenses) #:prefix license:)
  #:use-module (gnu packages readline)
  #:use-module (gnu packages ncurses)
  #:use-module (gnu packages popt)
  #:use-module (gnu packages fribidi)
  #:use-module (gnu packages compression)
  #:use-module (gnu packages image)
  #:use-module (gnu packages pcre)
  #:use-module (gnu packages python))

(define-public slang
  (package
    (name "slang")
    (version "2.3.2")
    (source (origin
              (method url-fetch)
              (uri (string-append "http://www.jedsoft.org/releases/slang/slang-"
                                  version ".tar.bz2"))
              (sha256
               (base32
                "06p379fqn6w38rdpqi98irxi2bf4llb0rja3dlgkqz7nqh7kp7pw"))
              (modules '((guix build utils)))
              (snippet
               '(begin
                  (substitute* "src/Makefile.in"
                    (("/bin/ln") "ln"))
                  #t))))
    (build-system gnu-build-system)
    (arguments
     '(#:parallel-tests? #f
       #:parallel-build? #f  ; there's at least one race
       #:phases
       (modify-phases %standard-phases
         (add-before 'configure 'substitute-before-config
           (lambda* (#:key inputs #:allow-other-keys)
             (let ((ncurses (assoc-ref inputs "ncurses")))
               (substitute* "configure"
                 (("MISC_TERMINFO_DIRS=\"\"")
                  (string-append "MISC_TERMINFO_DIRS="
                                 "\"" ncurses "/share/terminfo" "\"")))
               #t))))))
    (inputs
     `(("readline" ,readline)
       ("zlib" ,zlib)
       ("libpng" ,libpng)
       ("pcre" ,pcre)
       ("ncurses" ,ncurses)))
    (home-page "https://www.jedsoft.org/slang/")
    (synopsis "Library for interactive applications and extensibility")
    (description
     "S-Lang is a multi-platform programmer's library designed to allow a
developer to create robust multi-platform software.  It provides facilities
required by interactive applications such as display/screen management,
keyboard input, keymaps, and so on.  The most exciting feature of the library
is the slang interpreter that may be easily embedded into a program to make it
extensible.  While the emphasis has always been on the embedded nature of the
interpreter, it may also be used in a stand-alone fashion through the use of
slsh, which is part of the S-Lang distribution.")
    (license license:gpl2+)))

(define-public newt
  (package
    (name "newt")
    (version "0.52.21")
    (source (origin
              (method url-fetch)
              (uri (string-append "https://pagure.io/releases/newt/"
                                  "newt-" version ".tar.gz"))
              (sha256
               (base32
                "0cdvbancr7y4nrj8257y5n45hmhizr8isynagy4fpsnpammv8pi6"))))
    (build-system gnu-build-system)
    (outputs '("out" "python"))
    (inputs
     `(("slang" ,slang)
       ("popt" ,popt)
       ("python" ,python)
       ("fribidi" ,fribidi)))
    (arguments
     `(#:tests? #f    ; no test suite
       #:configure-flags
       ;; Set the correct RUNPATH in binaries.
       (list (string-append "LDFLAGS=-Wl,-rpath=" %output "/lib"))
       #:make-flags
       ;; configure uses a hard-coded search of /usr/include/python* to set
       ;; this variable, and does not allow us to override it from the
       ;; command line.  Fortunately, the Makefile does, so provide it here.
       (list (string-append "PYTHONVERS=python"
                            ,(version-major+minor (package-version python))))
       #:phases
       (modify-phases %standard-phases
         (add-after
          'unpack 'patch-/usr/bin/install
          (lambda _
            (substitute* "po/Makefile"
              (("/usr/bin/install") "install"))
            #t))
         (add-after
          'install 'move-python
          (lambda* (#:key outputs #:allow-other-keys)
            (let ((out  (assoc-ref outputs "out"))
                  (py   (assoc-ref outputs "python"))
                  (ver ,(version-major+minor (package-version python))))
              (mkdir-p (string-append py "/lib"))
              (rename-file (string-append out "/lib/python" ver)
                           (string-append py  "/lib/python" ver))
              #t))))))
    (home-page "https://pagure.io/newt")
    (synopsis "Not Erik's Windowing Toolkit - text mode windowing with slang")
    (description
     "Newt is a windowing toolkit for text mode built from the slang library.
It allows color text mode applications to easily use stackable windows, push
buttons, check boxes, radio buttons, lists, entry fields, labels, and
displayable text.  Scrollbars are supported, and forms may be nested to
provide extra functionality.")
    (license license:lgpl2.0)))


code:
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2013 Nikita Karetnikov <nikita@karetnikov.org>
;;; Copyright © 2016 Efraim Flashner <efraim@flashner.co.il>
;;; Copyright © 2016 Nicolas Goaziou <mail@nicolasgoaziou.fr>
;;; Copyright © 2016 Ludovic Courtès <ludo@gnu.org>
;;; Copyright © 2018 Tobias Geerinckx-Rice <me@tobias.gr>
;;;
;;; This file is part of GNU Guix.
;;;
;;; GNU Guix is free software; you can redistribute it and/or modify it
;;; under the terms of the GNU General Public License as published by
;;; the Free Software Foundation; either version 3 of the License, or (at
;;; your option) any later version.
;;;
;;; GNU Guix is distributed in the hope that it will be useful, but
;;; WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;;; GNU General Public License for more details.
;;;
;;; You should have received a copy of the GNU General Public License
;;; along with GNU Guix.  If not, see <http://www.gnu.org/licenses/>.

(define-module (gnu packages smalltalk)
  #:use-module ((guix licenses) #:prefix license:)
  #:use-module (guix packages)
  #:use-module (guix download)
  #:use-module (guix build-system cmake)
  #:use-module (guix build-system gnu)
  #:use-module (gnu packages audio)
  #:use-module (gnu packages autotools)
  #:use-module (gnu packages base)
  #:use-module (gnu packages compression)
  #:use-module (gnu packages fontutils)
  #:use-module (gnu packages gl)
  #:use-module (gnu packages glib)
  #:use-module (gnu packages libffi)
  #:use-module (gnu packages libsigsegv)
  #:use-module (gnu packages linux)
  #:use-module (gnu packages pkg-config)
  #:use-module (gnu packages pulseaudio)
  #:use-module (gnu packages xorg))

(define-public smalltalk
  (package
    (name "smalltalk")
    (version "3.2.5")
    (source
     (origin
      (method url-fetch)
      (uri (string-append "mirror://gnu/smalltalk/smalltalk-"
                          version ".tar.xz"))
      (sha256
       (base32
        "1k2ssrapfzhngc7bg1zrnd9n2vyxp9c9m70byvsma6wapbvib6l1"))))
    (build-system gnu-build-system)
    (native-inputs
     `(("libffi" ,libffi)
       ("libltdl" ,libltdl)
       ("libsigsegv" ,libsigsegv)
       ("pkg-config" ,pkg-config)))
    (inputs
     `(("zip" ,zip)))
    (arguments
     `(#:phases
       (modify-phases %standard-phases
         (add-before 'configure 'fix-libc
           (lambda _
             (let ((libc (assoc-ref %build-inputs "libc")))
               (substitute* "libc.la.in"
                 (("@LIBC_SO_NAME@") "libc.so")
                 (("@LIBC_SO_DIR@")  (string-append libc "/lib"))))
             #t)))))
    (home-page "http://smalltalk.gnu.org/")
    (synopsis "Smalltalk environment")
    (description
     "GNU Smalltalk is a free implementation of the Smalltalk language.  It
implements the ANSI standard for the language and also includes extra classes
such as ones for networking and GUI programming.")
    (license license:gpl2+)))

(define-public squeak-vm
  (package
    (name "squeak-vm")
    (version "4.10.2.2614")
    (source
     (origin
       (method url-fetch)
       (uri (string-append "http://squeakvm.org/unix/release/"
                           "Squeak-" version "-src.tar.gz"))
       (sha256
        (base32 "0bpwbnpy2sb4gylchfx50sha70z36bwgdxraym4vrr93l8pd3dix"))
       (modules '((guix build utils)))
       (snippet
        ;; Make builds bit-reproducible.
        '(begin
           (substitute* "unix/cmake/verstamp"
             (("vm_date=.*")
              "vm_date = \"1970-01-01\";\n")
             (("ux_version=.*")
              "ux_version = \"GNU\";\n"))
           (substitute* "unix/vm/config.cmake"
             (("\\(VM_BUILD_STRING.*")
              "(VM_BUILD_STRING \\\"Built with GNU Guix\\\")"))
           #t))))
    (inputs
     `(("alsa-lib" ,alsa-lib)
       ("dbus" ,dbus)
       ("freetype" ,freetype)
       ("libffi" ,libffi)
       ("libxrender" ,libxrender)
       ("mesa" ,mesa)
       ("pulseaudio" ,pulseaudio)))
    (native-inputs
     `(("pkg-config" ,pkg-config)))
    (build-system cmake-build-system)
    (arguments
     `(#:tests? #f                      ;no check target
       #:phases
       (modify-phases %standard-phases
         (add-after 'unpack 'remove-hardcoded-PATH
           (lambda _
             ;; Remove hard-coded FHS PATH entries.
             (substitute* '("unix/cmake/squeak.in"
                            "unix/cmake/squeak.sh.in")
               (("^PATH=.*") ""))
             #t))
         (add-before 'configure 'enter-build-directory
           (lambda _
             (mkdir "build")
             (chdir "build")
             #t))
         (replace 'configure
           (lambda* (#:key outputs #:allow-other-keys)
             (let ((out (assoc-ref outputs "out")))
               (invoke "../unix/cmake/configure"
                       (string-append "--prefix=" out)
                       "--without-quartz")
               #t))))))
    (synopsis "Smalltalk programming language and environment")
    (description "Squeak is a full-featured implementation of the Smalltalk
programming language and environment based on (and largely compatible with)
the original Smalltalk-80 system.  Squeak has very powerful 2- and 3-D
graphics, sound, video, MIDI, animation and other multimedia capabilities.  It
also includes a customisable framework for creating dynamic HTTP servers and
interactively extensible Web sites.")
    (home-page "http://squeakvm.org/")
    (license license:x11)))


code:
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2017 Andy Patterson <ajpatter@uwaterloo.ca>
;;; Copyright © 2017 Tobias Geerinckx-Rice <me@tobias.gr>
;;; Copyright © 2018 Ricardo Wurmus <rekado@elephly.net>
;;; Copyright © 2019, 2020 Brett Gilio <brettg@gnu.org>
;;;
;;; This file is part of GNU Guix.
;;;
;;; GNU Guix is free software; you can redistribute it and/or modify it
;;; under the terms of the GNU General Public License as published by
;;; the Free Software Foundation; either version 3 of the License, or (at
;;; your option) any later version.
;;;
;;; GNU Guix is distributed in the hope that it will be useful, but
;;; WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;;; GNU General Public License for more details.
;;;
;;; You should have received a copy of the GNU General Public License
;;; along with GNU Guix.  If not, see <http://www.gnu.org/licenses/>.

(define-module (gnu packages sml)
  #:use-module (gnu packages lesstif)
  #:use-module (gnu packages libffi)
  #:use-module (gnu packages multiprecision)
  #:use-module (gnu packages xorg)
  #:use-module (guix build-system gnu)
  #:use-module (guix download)
  #:use-module (guix git-download)
  #:use-module ((guix licenses) #:prefix license:)
  #:use-module (guix packages))

(define-public polyml
  (package
    (name "polyml")
    (version "5.8.1")
    (source (origin
              (method git-fetch)
              (uri (git-reference
                    (url "https://github.com/polyml/polyml")
                    (commit (string-append "v" version))))
              (file-name (git-file-name name version))
              (sha256
               (base32
                "1ag7n55ym1zxksi89dvs17j6iaa58v4mg47s92zpa1b49k4fql1k"))))
    (build-system gnu-build-system)
    (inputs
     `(("gmp" ,gmp)
       ("lesstif" ,lesstif)
       ("libffi" ,libffi)
       ("libx11" ,libx11)
       ("libxt" ,libxt)))
    (arguments
     '(#:configure-flags
       (list "--with-system-libffi=yes"
             "--with-x=yes"
             "--with-threads=yes"
             "--with-gmp=yes")
       #:phases
       (modify-phases %standard-phases
         (add-after 'build 'build-compiler
           (lambda* (#:key make-flags parallel-build? #:allow-other-keys)
             (define flags
               (if parallel-build?
                   (cons (format #f "-j~d" (parallel-job-count))
                         make-flags)
                   make-flags))
             (apply system* "make" (append flags (list "compiler"))))))))
    (home-page "https://www.polyml.org/")
    (synopsis "Standard ML implementation")
    (description "Poly/ML is a Standard ML implementation.  It is fully
compatible with the ML97 standard.  It includes a thread library, a foreign
function interface, and a symbolic debugger.")
    ;; Some source files specify 'or any later version'; some don't
    (license
     (list license:lgpl2.1
           license:lgpl2.1+))))


code:
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2016 David Thompson <davet@gnu.org>
;;; Copyright © 2016, 2019, 2020 Marius Bakke <mbakke@fastmail.com>
;;; Copyright © 2017 Leo Famulari <leo@famulari.name>
;;; Copyright © 2018, 2020 Tobias Geerinckx-Rice <me@tobias.gr>
;;; Copyright © 2016 Kei Kebreau <kkebreau@posteo.net>
;;; Copyright © 2019 Ricardo Wurmus <rekado@elephly.net>
;;; Copyright © 2020 Nicolas Goaziou <mail@nicolasgoaziou.fr>
;;; Copyright © 2020 Efraim Flashner <efraim@flashner.co.il>
;;;
;;; This file is part of GNU Guix.
;;;
;;; GNU Guix is free software; you can redistribute it and/or modify it
;;; under the terms of the GNU General Public License as published by
;;; the Free Software Foundation; either version 3 of the License, or (at
;;; your option) any later version.
;;;
;;; GNU Guix is distributed in the hope that it will be useful, but
;;; WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;;; GNU General Public License for more details.
;;;
;;; You should have received a copy of the GNU General Public License
;;; along with GNU Guix.  If not, see <http://www.gnu.org/licenses/>.

(define-module (gnu packages speech)
  #:use-module ((guix licenses) #:prefix license:)
  #:use-module (guix packages)
  #:use-module (guix download)
  #:use-module (guix git-download)
  #:use-module (guix utils)
  #:use-module (guix build-system gnu)
  #:use-module (gnu packages)
  #:use-module (gnu packages audio)
  #:use-module (gnu packages autotools)
  #:use-module (gnu packages base)            ;for 'which'
  #:use-module (gnu packages bison)
  #:use-module (gnu packages compression)
  #:use-module (gnu packages documentation)
  #:use-module (gnu packages emacs)
  #:use-module (gnu packages gcc)
  #:use-module (gnu packages glib)
  #:use-module (gnu packages gstreamer)
  #:use-module (gnu packages linux)
  #:use-module (gnu packages ncurses)
  #:use-module (gnu packages perl)
  #:use-module (gnu packages pkg-config)
  #:use-module (gnu packages pulseaudio)
  #:use-module (gnu packages python)
  #:use-module (gnu packages swig)
  #:use-module (gnu packages texinfo)
  #:use-module (gnu packages textutils))

(define-public flite
  (package
    (name "flite")
    (version "2.1")
    (source
     (origin
       (method url-fetch)
       (uri
        (string-append "http://www.festvox.org/" name "/packed/" name
                       "-" version "/" name "-" version "-release.tar.bz2"))
       (sha256
        (base32 "119b7l7pjb1l5raqq24p8rmhdqni49vjh2mgdryrfr575rm3yg67"))))
    (build-system gnu-build-system)
    (arguments
     ;; XXX:
     ;; There numerous issues with the testsuite.
     ;; Enable all of them once they are fixed in upstream.
     `(#:tests? #f
       #:configure-flags
       (list
        "--enable-shared"
        (string-append "LDFLAGS=-Wl,-rpath="
                       (assoc-ref %outputs "out")
                       "/lib"))
       #:phases
       (modify-phases %standard-phases
         (add-after 'unpack 'patch-rpath
           (lambda _
             (substitute* "main/Makefile"
              (("flite_LIBS_flags \\+= -Wl,-rpath [^ ]*")
               "flite_LIBS_flags +="))
             #t))
         (delete 'check)
         ;; Modifying testsuite/Makefile is not done in favor of
         ;; overriding 'check.
         ;; The path not taken would be:
         ;; test:\n\t$(foreach x,$(subst tris1,,$(subst dcoffset_wave,,$(subst flite_test,,$(subst by_word,,$(subst bin2ascii,,$(subst lpc_resynth,,$(subst rfc,,$(subst compare_wave,,$(subst record_in_noise,,$(subst combine_waves,,$(patsubst play_%,,$(subst record_wave,,$(subst lex_lookup,,$(patsubst lpc_test%,,$(patsubst asciiS2U%,,$(patsubst asciiU2S%,,$(ALL))))))))))))))))),echo TEST $x && ./$x data.one && ) true
         (add-after 'install 'check
           (lambda _
             (invoke "make" "-C" "testsuite")
             (with-directory-excursion "testsuite"
               (invoke "./token_test")
               (invoke "./hrg_test")
               (invoke "./regex_test")
               (invoke "./nums_test")
               (invoke "./lex_test")
               (invoke "./utt_test")
               (invoke "./multi_thread"))
             #t))
         (add-after 'install 'remove-static-libs
           (lambda* (#:key outputs #:allow-other-keys)
             (let* ((out (assoc-ref outputs "out")))
               (for-each delete-file
                         (find-files out "\\.a$"))
               #t))))))
    (native-inputs
     `(("perl" ,perl)))
    (inputs
     `(("alsa" ,alsa-lib)))
    (synopsis "Speech synthesis system")
    (description "Flite (festival-lite) is a small, fast run-time text to speech
synthesis engine developed at CMU and primarily designed for small embedded
machines and/or large servers.  It is designed as an alternative text to speech
synthesis engine to Festival for voices built using the FestVox suite of voice
building tools.")
    (home-page "http://www.festvox.org/flite/index.html")
    (license (license:non-copyleft "file:///COPYING"))))

(define-public espeak
  (package
    (name "espeak")
    (version "1.48.04")
    (source (origin
              (method url-fetch)
              (uri (string-append "mirror://sourceforge/espeak/espeak/"
                                  "espeak-" (version-major+minor version)
                                  "/espeak-" version "-source.zip"))
              (sha256
               (base32
                "0n86gwh9pw0jqqpdz7mxggllfr8k0r7pc67ayy7w5z6z79kig6mz"))
              (modules '((guix build utils)))
              (snippet
               ;; remove prebuilt binaries
               '(begin
                  (delete-file-recursively "linux_32bit")
                  #t))))
    (build-system gnu-build-system)
    (arguments
     `(#:make-flags (list (string-append "PREFIX=" (assoc-ref %outputs "out"))
                          (string-append "DATADIR="
                                         (assoc-ref %outputs "out")
                                         "/share/espeak-data")
                          (string-append "LDFLAGS=-Wl,-rpath="
                                         (assoc-ref %outputs "out")
                                         "/lib")
                          ;; The package fails to build with newer C++ standards.
                          "CXXFLAGS=-std=c++98"
                          "AUDIO=pulseaudio")
       #:tests? #f ; no check target
       #:phases
       (modify-phases %standard-phases
         (replace 'configure
           (lambda _
             (chdir "src")
             ;; We use version 19 of the PortAudio library, so we must copy the
             ;; corresponding file to be sure that espeak compiles correctly.
             (copy-file "portaudio19.h" "portaudio.h")
             (substitute* "Makefile"
               (("/bin/ln") "ln"))
             #t)))))
       (inputs
        `(("portaudio" ,portaudio)
          ("pulseaudio" ,pulseaudio)))
       (native-inputs `(("unzip" ,unzip)))
       (home-page "http://espeak.sourceforge.net/")
       (synopsis "Software speech synthesizer")
       (description "eSpeak is a software speech synthesizer for English and
other languages.  eSpeak uses a \"formant synthesis\" method.  This allows many
languages to be provided in a small size.  The speech is clear, and can be used
at high speeds, but is not as natural or smooth as larger synthesizers which are
based on human speech recordings.")
       (license license:gpl3+)))

(define-public espeak-ng
  (package
    (name "espeak-ng")
    (version "1.50")
    (home-page "https://github.com/espeak-ng/espeak-ng")
    ;; Note: eSpeak NG publishes release tarballs, but the 1.50 tarball is
    ;; broken: <https://github.com/espeak-ng/espeak-ng/issues/683>.
    ;; Download the raw repository to work around it; remove 'native-inputs'
    ;; below when switching back to the release tarball.
    (source (origin
              (method git-fetch)
              (uri (git-reference (url home-page) (commit version)))
              (file-name (git-file-name name version))
              (sha256
               (base32 "0jkqhf2h94vbqq7mg7mmm23bq372fa7mdk941my18c3vkldcir1b"))))
    (build-system gnu-build-system)
    (arguments
     `(#:configure-flags '("--disable-static")
       ;; Building in parallel triggers a race condition in 1.49.2.
       #:parallel-build? #f
       ;; XXX: Some tests require an audio device.
       #:tests? #f))
    (native-inputs
     `(("autoconf" ,autoconf)
       ("automake" ,automake)
       ("libtool" ,libtool)
       ("which" ,which)))
    (inputs
     `(("libcap" ,libcap)
       ("pcaudiolib" ,pcaudiolib)))
    (synopsis "Software speech synthesizer")
    (description
     "eSpeak NG is a software speech synthesizer for more than 100 languages.
It is based on the eSpeak engine and supports spectral and Klatt formant
synthesis, and the ability to use MBROLA voices.")
    (license license:gpl3+)))

(define-public mitlm
  (package
    (name "mitlm")
    (version "0.4.2")
    (source (origin
              (method url-fetch)
              (uri (string-append "https://github.com/mitlm/mitlm/releases/"
                                  "download/v" version "/"
                                  name "-" version ".tar.xz"))
              (sha256
               (base32
                "09fv4fcpmw9g1j0zml0k5kk1lgjw2spr8gn51llbkaaph6v8d62a"))))
    (build-system gnu-build-system)
    (native-inputs
     `(("gfortran" ,gfortran)))
    (synopsis "The MIT Language Modeling toolkit")
    (description "The MIT Language Modeling (MITLM) toolkit is a set of
tools designed for the efficient estimation of statistical n-gram language
models involving iterative parameter estimation.  It achieves much of its
efficiency through the use of a compact vector representation of n-grams.")
    (home-page "https://github.com/mitlm/mitlm")
    (license license:expat)))

(define-public speech-dispatcher
  (package
    (name "speech-dispatcher")
    (version "0.9.1")
    (source (origin
              (method url-fetch)
              (uri (string-append "https://github.com/brailcom/speechd/releases"
                                  "/download/" version "/speech-dispatcher-"
                                  version ".tar.gz"))
              (sha256
               (base32
                "16bg52hnkrsrs7kgbzanb34b9zb6fqxwj0a9bmsxmj1skkil1h1p"))))
    (build-system gnu-build-system)
    (arguments
     `(#:configure-flags '("--disable-static"

                           ;; Disable support for proprietary TTS engines.
                           "--with-ibmtts=no"
                           "--with-kali=no" "--with-baratinoo=no")))
    (native-inputs
     `(("intltool" ,intltool)
       ("pkg-config" ,pkg-config)))
    (inputs
     `(("dotconf" ,dotconf)
       ("espeak" ,espeak-ng)
       ("glib" ,glib)
       ("libltdl" ,libltdl)
       ("libsndfile" ,libsndfile)
       ("pulseaudio" ,pulseaudio)
       ("python" ,python)))
    (synopsis "Common interface to speech synthesizers")
    (description "The Speech Dispatcher project provides a high-level
device independent layer for access to speech synthesis through a simple,
stable and well documented interface.")
    (home-page "https://devel.freebsoft.org/speechd")
    ;; The software is distributed under GPL2+, but includes a number
    ;; of files covered by other licenses.  Note: in practice, this
    ;; is linked against dotconf, which is LGPL 2.1 only.
    (license (list license:gpl2+
                   license:fdl1.2+ ; Most files in doc/ are dual gpl2+/fdl1.2+.
                   license:lgpl2.1+
                   (license:non-copyleft
                    ;; festival_client.{c,h} carries an expat-style license.
                    "See src/modules/festival_client.c in the distribution.")
                   license:gpl3+)))) ; doc/texinfo.tex -- with TeX exception.

(define-public sonic
  (package
    (name "sonic")
    (version "0.2.0")
    (source (origin
             (method git-fetch)
             (uri (git-reference
                    (url "https://github.com/waywardgeek/sonic")
                    (commit (string-append "release-" version))))
             (file-name (git-file-name name version))
             (sha256
              (base32
               "08xwnpw9cnaix1n1i7gvpq5hrfrqc2z1snjhjapfam506hrc77g4"))))
    (build-system gnu-build-system)
    (arguments
     `(#:tests? #f                      ; no test suite
       #:make-flags
       (list (string-append "PREFIX=" (assoc-ref %outputs "out"))
             (string-append "LDFLAGS=-Wl,-rpath="
                            (assoc-ref %outputs "out") "/lib"))
       #:phases
       (modify-phases %standard-phases
         (add-after 'unpack 'respect-LDFLAGS
           (lambda _
             (substitute* "Makefile"
               ((" -o sonic " match)
                (string-append " $(LDFLAGS)" match)))
             #t))
         (delete 'configure))))        ; no ./configure script
    (synopsis "Speed up or slow down speech")
    (description "Sonic implements a simple algorithm for speeding up or slowing
down speech.  However, it's optimized for speed ups of over 2X, unlike previous
algorithms for changing speech rate.  Sonic is a C library designed to be easily
integrated into streaming voice applications such as text-to-speech (TTS) back
ends.

The primary motivation behind Sonic is to enable the blind and visually impaired
to improve their productivity with speech engines, like eSpeak.  Sonic can also
be used by the sighted.")
    (home-page "https://github.com/waywardgeek/sonic")
    (license license:asl2.0)))

(define-public festival
  (package
    (name "festival")
    (version "2.5.0")
    (source (origin
              (method url-fetch)
              (uri (string-append "http://festvox.org/packed/festival/"
                                  (version-major+minor version)
                                  "/festival-" version "-release.tar.gz"))
              (sha256
               (base32
                "1d5415nckiv19adxisxfm1l1xxfyw88g87ckkmcr0lhjdd10g42c"))))
    (build-system gnu-build-system)
    (arguments
     `(#:tests? #f ; there is no test target
       #:make-flags
       (list (string-append "RM="
                            (assoc-ref %build-inputs "coreutils")
                            "/bin/rm")
             (string-append "ECHO_N="
                            (assoc-ref %build-inputs "coreutils")
                            "/bin/printf \"%s\""))
       #:parallel-build? #f ; not supported
       #:modules ((guix build gnu-build-system)
                  (guix build utils)
                  (guix build emacs-utils))
       #:imported-modules (,@%gnu-build-system-modules
                           (guix build emacs-utils))
       #:phases
       (modify-phases %standard-phases
         (add-after 'unpack 'unpack-and-patch-speech-tools
           (lambda* (#:key inputs #:allow-other-keys)
             (invoke "tar" "-C" ".."
                     "-xf" (assoc-ref inputs "speech-tools"))
             (with-directory-excursion "../speech_tools"
               (substitute* '("config/rules/modules.mak"
                              "config/rules/test_make_rules.mak"
                              "config/make_system.mak")
                 (("/bin/sh") (which "sh"))))
             #t))
         (add-after 'unpack 'patch-/bin/sh
           (lambda _
             (substitute* '("config/test_make_rules"
                            "config/make_system.mak")
               (("/bin/sh") (which "sh")))
             #t))
         (add-before 'build 'build-speech-tools
           (lambda* (#:key configure-flags make-flags #:allow-other-keys)
             (with-directory-excursion "../speech_tools"
               (apply invoke "sh" "configure"
                      (string-append "CONFIG_SHELL=" (which "sh"))
                      (string-append "SHELL=" (which "sh"))
                      configure-flags)
               (apply invoke "make" make-flags))))
         (add-after 'build 'build-documentation
           (lambda _
             (with-directory-excursion "doc"
               (invoke "make" "festival.info"))))
         (add-after 'unpack 'set-installation-directories
           (lambda* (#:key outputs #:allow-other-keys)
             (let ((out (assoc-ref outputs "out")))
               (substitute* "config/project.mak"
                 (("^FTLIBDIR.*")
                  (string-append "FTLIBDIR=" out "/share/festival/lib")))
               (substitute* "config/systems/default.mak"
                 (("^INSTALL_PREFIX.*")
                  (string-append "INSTALL_PREFIX=" out)))
               #t)))
         (add-after 'install 'actually-install
           (lambda* (#:key inputs outputs #:allow-other-keys)
             (let ((out (assoc-ref outputs "out")))
               ;; Install Speech Tools first
               (with-directory-excursion "../speech_tools"
                 ;; Target directories
                 (for-each (lambda (dir)
                             (mkdir-p (string-append out dir)))
                           '("/bin"
                             "/lib"
                             "/include/speech_tools/"
                             "/include/speech_tools/instantiate"
                             "/include/speech_tools/ling_class"
                             "/include/speech_tools/rxp"
                             "/include/speech_tools/sigpr"
                             "/include/speech_tools/unix"))
                 ;; Install binaries
                 (for-each (lambda (file)
                             (install-file file (string-append out "/bin")))
                           (find-files "bin" ".*"))
                 (for-each (lambda (file)
                             (delete-file (string-append out "/bin/" file)))
                           '("est_gdb" "est_examples" "est_program"))
                 ;; Install libraries
                 (for-each (lambda (file)
                             (install-file file (string-append out "/lib")))
                           (find-files "lib" "lib.*\\.so.*"))

                 ;; Install headers
                 (for-each
                  (lambda (dir)
                    (for-each
                     (lambda (header)
                       (install-file header
                                     (string-append out "/include/speech_tools/" dir)))
                     (find-files (string-append "include/" dir)
                                 "\\.h$")))
                  '("." "instantiate" "ling_class" "rxp" "sigpr" "unix")))

               ;; Unpack files that will be installed together with the
               ;; Festival libraries.
               (invoke "tar" "--strip-components=1"
                       "-xvf" (assoc-ref inputs "festvox-cmu"))
               (invoke "tar" "--strip-components=1"
                       "-xvf" (assoc-ref inputs "festvox-poslex"))
               (invoke "tar" "--strip-components=1"
                       "-xvf" (assoc-ref inputs "default-voice"))

               ;; Install Festival
               (let ((bin (string-append out "/bin"))
                     (incdir (string-append out "/include/festival"))
                     (share (string-append out "/share/festival"))
                     (info (string-append out "/share/info")))
                 (for-each (lambda (executable)
                             (install-file executable bin))
                           '("src/main/festival"
                             "src/main/festival_client"
                             "examples/benchmark"))
                 (let ((scripts '("examples/dumpfeats"
                                  "examples/durmeanstd"
                                  "examples/latest"
                                  "examples/make_utts"
                                  "examples/powmeanstd"
                                  "examples/run-festival-script"
                                  "examples/saytime"
                                  "examples/scfg_parse_text"
                                  "examples/text2pos"
                                  "examples/text2wave")))
                   (substitute* scripts
                     (("exec /tmp/guix-build.*/bin/festival")
                      (string-append "exec " bin "/festival")))
                   (for-each (lambda (script)
                               (install-file script bin))
                             scripts))

                 ;; Documentation
                 (for-each (lambda (file)
                             (install-file file info))
                           (find-files "doc/info/" "festival.info.*"))

                 ;; Headers
                 (mkdir-p incdir)
                 (for-each (lambda (header)
                             (install-file header
                                           (string-append incdir "/"
                                                          (dirname header))))
                           (find-files "src/include" "\\.h$"))

                 ;; Data
                 (mkdir-p share)
                 (for-each (lambda (file)
                             (install-file file
                                           (string-append share "/"
                                                          (dirname file))))
                           (find-files "lib" ".*"))
                 (for-each delete-file
                           (append (find-files share "Makefile")
                                   (find-files bin "Makefile")))))
             #t))
         (add-after 'actually-install 'install-emacs-mode
           (lambda* (#:key outputs #:allow-other-keys)
             (let ((emacs-dir (string-append (assoc-ref outputs "out")
                                             "/share/emacs/site-lisp")))
               (install-file "lib/festival.el" emacs-dir)
               (emacs-generate-autoloads ,name emacs-dir)
               #t)))
         ;; Rebuild the very old configure script that is confused by extra
         ;; arguments.
         (add-before 'configure 'bootstrap
           (lambda _ (invoke "autoreconf" "-vif"))))))
    (inputs
     `(("ncurses" ,ncurses)))
    (native-inputs
     `(("autoconf" ,autoconf)
       ("automake" ,automake)
       ("texinfo" ,texinfo)
       ("emacs" ,emacs-minimal)
       ("festvox-cmu"
        ,(origin
           (method url-fetch)
           (uri (string-append "http://festvox.org/packed/festival/"
                               (version-major+minor version)
                               "/festlex_CMU.tar.gz"))
           (sha256
            (base32
             "01vwidqhhg2zifvk1gby91mckg1z2pv2mj6lihvdaifakf8k1561"))))
       ("festvox-poslex"
        ,(origin
           (method url-fetch)
           (uri (string-append "http://festvox.org/packed/festival/"
                               (version-major+minor version)
                               "/festlex_POSLEX.tar.gz"))
           (sha256
            (base32
             "18wywilxaqwy63lc47p5g5529mpxhslibh1bjij0snxx5mjf7ip7"))))
       ("default-voice"
        ,(origin
           (method url-fetch)
           (uri (string-append "http://festvox.org/packed/festival/"
                               (version-major+minor version)
                               "/voices/festvox_kallpc16k.tar.gz"))
           (sha256
            (base32
             "136hmsyiwnlg2qwa508dy0imf19mzrb5r3dmb2kg8kcyxnslm740"))))
       ("speech-tools"
        ,(origin
           (method url-fetch)
           (uri (string-append "http://festvox.org/packed/festival/"
                               (version-major+minor version)
                               "/speech_tools-" version "-release.tar.gz"))
           (sha256
            (base32
             "1k2xh13miyv48gh06rgsq2vj25xwj7z6vwq9ilsn8i7ig3nrgzg4"))))))
    (home-page "http://www.cstr.ed.ac.uk/projects/festival/")
    (synopsis "Speech synthesis system")
    (description "Festival offers a general framework for building speech
synthesis systems as well as including examples of various modules.  As a
whole it offers full text to speech through a number APIs: from shell level,
though a Scheme command interpreter, as a C++ library, from Java, and an Emacs
interface.  Festival is multi-lingual though English is the most advanced.
The system is written in C++ and uses the Edinburgh Speech Tools Library for
low level architecture and has a Scheme (SIOD) based command interpreter for
control.")
    (license (license:non-copyleft "file://COPYING"))))

(define-public sphinxbase
  (package
    (name "sphinxbase")
    (version "5prealpha")
    (source
     (origin
       (method url-fetch)
       (uri (string-append "mirror://sourceforge/cmusphinx/"
                           "sphinxbase/" version "/"
                           "sphinxbase-" version ".tar.gz"))
       (sha256
        (base32 "0vr4k8pv5a8nvq9yja7kl13b5lh0f9vha8fc8znqnm8bwmcxnazp"))
       (patches (search-patches "sphinxbase-fix-doxygen.patch"))))
    (build-system gnu-build-system)
    (arguments
     `(#:parallel-tests? #f))           ;tests fail otherwise
    (native-inputs
     `(("bison" ,bison)
       ("doxygen" ,doxygen)
       ("perl" ,perl)                   ;for tests
       ("python" ,python)
       ("swig" ,swig)))
    (inputs
     `(("pulseaudio" ,pulseaudio)))
    (home-page "https://cmusphinx.github.io/")
    (synopsis "Support library required by Pocketsphinx and Sphinxtrain")
    (description "This package contains the basic libraries shared by
the CMU Sphinx trainer and all the Sphinx decoders (Sphinx-II,
Sphinx-III, and PocketSphinx), as well as some common utilities for
manipulating acoustic feature and audio files.")
    (license license:bsd-4)))

(define-public pocketsphinx
  (package
    (name "pocketsphinx")
    (version "5prealpha")
    (source
     (origin
       (method url-fetch)
       (uri (string-append "mirror://sourceforge/cmusphinx/"
                           "pocketsphinx/" version "/"
                           "pocketsphinx-" version ".tar.gz"))
       (sha256
        (base32 "1n9yazzdgvpqgnfzsbl96ch9cirayh74jmpjf7svs4i7grabanzg"))))
    (build-system gnu-build-system)
    (native-inputs
     `(("pkg-config" ,pkg-config)
       ("perl" ,perl)                   ;for tests
       ("python" ,python)
       ("swig" ,swig)))
    (inputs
     `(("gstreamer" ,gstreamer)
       ("libcap" ,libcap)
       ("pulseaudio" ,pulseaudio)
       ("sphinxbase" ,sphinxbase)))
    (home-page "https://cmusphinx.github.io/")
    (synopsis "Recognizer library written in C")
    (description "PocketSphinx is one of Carnegie Mellon University's
large vocabulary, speaker-independent continuous speech recognition
engine.")
    (license license:bsd-2)))