code:
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2014, 2015 David Thompson <dthompson2@worcester.edu>
;;; Copyright © 2014 Andreas Enge <andreas@enge.fr>
;;; Copyright © 2014 Cyrill Schenkel <cyrill.schenkel@gmail.com>
;;; Copyright © 2014 Ian Denhardt <ian@zenhack.net>
;;; Copyright © 2015 Paul van der Walt <paul@denknerd.org>
;;; Copyright © 2016, 2018, 2019, 2020 Leo Famulari <leo@famulari.name>
;;; Copyright © 2018–2021 Tobias Geerinckx-Rice <me@tobias.gr>
;;; Copyright © 2019 Evan Straw <evan.straw99@gmail.com>
;;; Copyright © 2020 Ricardo Wurmus <rekado@elephly.net>
;;; Copyright © 2020 Lars-Dominik Braun <lars@6xq.net>
;;; Copyright © 2020, 2021 Simon Streit <simon@netpanic.org>
;;; Copyright © 2021 Noah Evans <noah@nevans.me>
;;;
;;; 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 mpd)
  #:use-module (gnu packages)
  #: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 cmake)
  #:use-module (guix build-system gnu)
  #:use-module (guix build-system meson)
  #:use-module (guix build-system python)
  #:use-module (gnu packages audio)
  #:use-module (gnu packages autotools)
  #:use-module (gnu packages avahi)
  #:use-module (gnu packages base)
  #:use-module (gnu packages boost)
  #:use-module (gnu packages cdrom)
  #:use-module (gnu packages gettext)
  #:use-module (gnu packages gnome)
  #:use-module (gnu packages gnupg)
  #:use-module (gnu packages gtk)
  #:use-module (gnu packages icu4c)
  #:use-module (gnu packages libusb)
  #:use-module (gnu packages readline)
  #:use-module (gnu packages check)
  #:use-module (gnu packages compression)
  #:use-module (gnu packages curl)
  #:use-module (gnu packages documentation)
  #:use-module (gnu packages glib)
  #:use-module (gnu packages linux)
  #:use-module (gnu packages mp3)
  #:use-module (gnu packages ncurses)
  #:use-module (gnu packages pcre)
  #:use-module (gnu packages pkg-config)
  #:use-module (gnu packages python)
  #:use-module (gnu packages python-xyz)
  #:use-module (gnu packages pulseaudio)
  #:use-module (gnu packages qt)
  #:use-module (gnu packages sphinx)
  #:use-module (gnu packages sqlite)
  #:use-module (gnu packages video)
  #:use-module (gnu packages xiph))

(define-public libmpdclient
  (package
    (name "libmpdclient")
    (version "2.19")
    (source (origin
              (method url-fetch)
              (uri
               (string-append "https://musicpd.org/download/libmpdclient/"
                              (car (string-split version #\.))
                              "/libmpdclient-" version ".tar.xz"))
              (sha256
               (base32
                "12d1fzlkcnjw4ayk2wp11vhglfcvr5k02arzdbkhiavq496av2hm"))))
    (build-system meson-build-system)
    (native-inputs
     `(("pkg-config" ,pkg-config)

       ;; For building HTML documentation.
       ("doxygen" ,doxygen)

       ;; For tests.
       ("check" ,check)))
    (arguments
     `(#:configure-flags
       (list "-Ddocumentation=true"
             "-Dtest=true")))
    (synopsis "Music Player Daemon client library")
    (description "A stable, documented, asynchronous API library for
interfacing MPD in the C, C++ & Objective C languages.")
    (home-page "https://www.musicpd.org/libs/libmpdclient/")
    (license license:bsd-3)))

(define-public mpd
  (package
    (name "mpd")
    (version "0.22.9")
    (source (origin
              (method url-fetch)
              (uri
               (string-append "https://musicpd.org/download/mpd/"
                              (version-major+minor version)
                              "/mpd-" version ".tar.xz"))
              (sha256
               (base32
                "0r5w282klk3d9pgsjjr8lnc77cbsxqvvkx39lpa0n962jwr40dzr"))))
    (build-system meson-build-system)
    (arguments
     `(#:configure-flags '("-Ddocumentation=enabled")))
    (inputs `(("ao" ,ao)
              ("alsa-lib" ,alsa-lib)
              ("avahi" ,avahi)
              ("boost" ,boost)
              ("curl" ,curl)
              ("ffmpeg" ,ffmpeg)
              ("flac" ,flac)
              ("glib" ,glib)
              ("icu4c" ,icu4c)
              ;; The LAME decoder comes from FFmpeg, but is added here so that
              ;; configure picks up the LAME encoder.
              ("lame" ,lame)
              ("libid3tag" ,libid3tag)
              ("libmpdclient" ,libmpdclient)
              ("libsamplerate" ,libsamplerate)
              ("libsndfile" ,libsndfile)
              ("libvorbis" ,libvorbis)
              ("opus" ,opus)
              ("pulseaudio" ,pulseaudio)
              ("sqlite" ,sqlite)
              ("zlib" ,zlib)))
    (native-inputs `(("pkg-config" ,pkg-config)
                     ("python-sphinx" ,python-sphinx)))
    ;; Missing optional inputs:
    ;;   libyajl
    ;;   libcdio_paranoia
    ;;   libmms
    ;;   libadplug
    ;;   libaudiofile
    ;;   faad2
    ;;   fluidsynth
    ;;   libgme
    ;;   libshout
    ;;   libmpg123
    ;;   libmodplug
    ;;   libmpcdec
    ;;   libsidplay2
    ;;   libwavpack
    ;;   libwildmidi
    ;;   libtwolame
    ;;   libroar
    ;;   libjack
    ;;   OpenAL
    (synopsis "Music Player Daemon")
    (description "Music Player Daemon (MPD) is a flexible, powerful,
server-side application for playing music.  Through plugins and libraries it
can play a variety of sound files while being controlled by its network
protocol.")
    (home-page "https://www.musicpd.org/")
    (license license:gpl2)))

(define-public mpd-mpc
  (package
    (name "mpd-mpc")
    (version "0.33")
    (source (origin
              (method url-fetch)
              (uri
               (string-append "https://www.musicpd.org/download/mpc/"
                              (car (string-split version #\.))
                              "/mpc-" version ".tar.xz"))
              (sha256
               (base32
                "15hjpzqs83v1zx49x8nkpwy9hpl1jxd55z1w50vm82gm32zcqh2g"))))
    (build-system meson-build-system)
    (inputs `(("libmpdclient" ,libmpdclient)))
    (native-inputs
     `(("pkg-config" ,pkg-config)
       ("python-sphinx" ,python-sphinx)))
    (synopsis "Music Player Daemon client")
    (description "MPC is a minimalist command line interface to MPD, the music
player daemon.")
    (home-page "https://www.musicpd.org/clients/mpc/")
    (license license:gpl2)))

(define-public ncmpc
  (package
    (name "ncmpc")
    (version "0.45")
    (source (origin
              (method url-fetch)
              (uri
               (string-append "http://musicpd.org/download/ncmpc/"
                              (version-major version)
                              "/ncmpc-" version ".tar.xz"))
              (sha256
               (base32
                "11gpy6kd7xr8x7f7gwdwfryxyc58cd135ds28gnz40p08xj49zqp"))))
    (build-system meson-build-system)
    (arguments
     `(#:configure-flags
       ;; Otherwise, they are installed incorrectly, in
       ;; '$out/share/man/man/man1'.
       (list (string-append "-Dmandir=" (assoc-ref %outputs "out")
                            "/share"))))
    (inputs `(("boost" ,boost)
              ("pcre" ,pcre)
              ("libmpdclient" ,libmpdclient)
              ("ncurses" ,ncurses)))
    (native-inputs `(("gettext" ,gettext-minimal) ; for xgettext
                     ("pkg-config" ,pkg-config)
                     ("python-sphinx" ,python-sphinx)))
    (synopsis "Curses Music Player Daemon client")
    (description "ncmpc is a fully featured MPD client, which runs in a
terminal using ncurses.")
    (home-page "https://www.musicpd.org/clients/ncmpc/")
    (license license:gpl2)))

(define-public ncmpcpp
  (package
    (name "ncmpcpp")
    (version "0.9.2")
    (source (origin
              (method url-fetch)
              (uri
               (string-append "https://ncmpcpp.rybczak.net/stable/ncmpcpp-"
                              version ".tar.bz2"))
              (sha256
               (base32
                "06rs734n120jp51hr0fkkhxrm7zscbhpdwls0m5b5cccghazdazs"))))
    (build-system gnu-build-system)
    (inputs `(("libmpdclient" ,libmpdclient)
              ("boost"  ,boost)
              ("readline" ,readline)
              ("ncurses" ,ncurses)
              ("taglib" ,taglib)
              ("icu4c" ,icu4c)
              ("curl" ,curl)))
    (native-inputs
     `(("pkg-config" ,pkg-config)))
    (arguments
     '(#:configure-flags
       '("BOOST_LIB_SUFFIX=" "--with-taglib" "--enable-clock")))
    (synopsis "Featureful ncurses based MPD client inspired by ncmpc")
    (description "Ncmpcpp is an mpd client with a UI very similar to ncmpc,
but it provides new useful features such as support for regular expressions
for library searches, extended song format, items filtering, the ability to
sort playlists, and a local file system browser.")
    (home-page "https://ncmpcpp.rybczak.net/")
    (license license:gpl2+)))

(define-public mpdscribble
  (package
    (name "mpdscribble")
    (version "0.23")
    (source (origin
              (method url-fetch)
              (uri (string-append "http://www.musicpd.org/download/mpdscribble/"
                                  version "/mpdscribble-" version ".tar.xz"))
              (sha256
               (base32
                "0s66zqscb44p88cl3kcv5jkjcqsskcnrv7xgrjhzrchf2kcpwf53"))))
    (build-system meson-build-system)
    (inputs `(("boost" ,boost)
              ("curl" ,curl)
              ("libgcrypt" ,libgcrypt)
              ("libmpdclient" ,libmpdclient)))
    (native-inputs `(("pkg-config" ,pkg-config)))
    (synopsis "MPD client for track scrobbling")
    (description "mpdscribble is a Music Player Daemon client which submits
information about tracks being played to a scrobbler, such as Libre.FM.")
    (home-page "https://www.musicpd.org/clients/mpdscribble/")
    (license license:gpl2+)))

(define-public python-mpd2
  (package
    (name "python-mpd2")
    (version "3.0.1")
    (source (origin
              (method url-fetch)
              (uri (pypi-uri "python-mpd2" version))
              (sha256
               (base32
                "0fxssbmnv44m03shjyvbqslc69b0160702j2s0flgvdxjggrnbjj"))))
    (build-system python-build-system)
    (arguments
     '(#:phases
       (modify-phases %standard-phases
         (replace 'check
           (lambda _ (invoke "python" "-m" "pytest" "mpd/tests.py"))))))
    (native-inputs
     `(("python-mock" ,python-mock)
       ("python-pytest" ,python-pytest)))
    (home-page "https://github.com/Mic92/python-mpd2")
    (synopsis "Python MPD client library")
    (description "Python-mpd2 is a Python library which provides a client
interface for the Music Player Daemon.")
    (license license:lgpl3+)))

(define-public sonata
  (package
    (name "sonata")
    (version "1.7.0")
    (source (origin
              (method git-fetch)
              (uri (git-reference
                     (url "https://github.com/multani/sonata")
                     (commit (string-append "v" version))))
              (file-name (git-file-name name version))
              (sha256
               (base32
                "0rl8w7s2asff626clzfvyz987l2k4ml5dg417mqp9v8a962q0v2x"))))
    (build-system python-build-system)
    (arguments
     `(#:modules ((guix build gnu-build-system)
                  (guix build python-build-system)
                  ((guix build glib-or-gtk-build-system) #:prefix glib-or-gtk:)
                  (guix build utils))
       #:imported-modules (,@%gnu-build-system-modules
                           (guix build python-build-system)
                           (guix build glib-or-gtk-build-system))
       #:phases
       (modify-phases %standard-phases
         (add-after 'install 'glib-or-gtk-wrap
           (assoc-ref glib-or-gtk:%standard-phases 'glib-or-gtk-wrap))
         (add-after 'install 'wrap-sonata
           (lambda* (#:key outputs #:allow-other-keys)
             (let ((out               (assoc-ref outputs "out"))
                   (gi-typelib-path   (getenv "GI_TYPELIB_PATH")))
               (wrap-program (string-append out "/bin/sonata")
                 `("GI_TYPELIB_PATH" ":" prefix (,gi-typelib-path))))
             #t)))))
    (native-inputs
     `(("gettext" ,gettext-minimal)))
    (inputs
     `(("python-mpd2" ,python-mpd2)
       ("gtk+" ,gtk+)
       ("gsettings-desktop-schemas" ,gsettings-desktop-schemas)
       ("gobject-introspection" ,gobject-introspection)
       ("adwaita-icon-theme" ,adwaita-icon-theme)
       ("python-pygobject" ,python-pygobject)))
    (synopsis "Elegant client for the Music Player Daemon")
    (description "Sonata is an elegant graphical client for the Music Player
Daemon (MPD).  It supports playlists, multiple profiles (connecting to different
MPD servers, search and multimedia key support.")
    (home-page "https://www.nongnu.org/sonata/")
    (license license:gpl3+)))

(define-public ashuffle
  (package
    (name "ashuffle")
    (version "2.0.2")
    (source (origin
              (method git-fetch)
              (uri (git-reference
                    (url "https://github.com/joshkunz/ashuffle")
                    (commit (string-append "v" version))))
              (file-name (git-file-name name version))
              (sha256
               (base32
                "11aa95cg0yca2m2d00sar6wr14g3lc7cfm9bin1h7lk7asdm8azp"))))
    (native-inputs `(("pkg-config" ,pkg-config)))
    (inputs `(("libmpdclient" ,libmpdclient)))
    (build-system meson-build-system)
    (home-page "https://github.com/joshkunz/ashuffle")
    (synopsis "Automatic library-wide shuffle for mpd")
    (description "ashuffle is an application for automatically shuffling your
MPD library in a similar way to many other music players' 'shuffle library'
feature. ashuffle works like any other MPD client, and can be used alongside
other MPD frontends.")
    (license license:expat)))

(define-public mpdris2
  (package
    (name "mpdris2")
    (version "0.9.1")
    (source (origin
              (method git-fetch)
              (uri (git-reference
                    (url "https://github.com/eonpatapon/mpDris2")
                    (commit version)))
              (file-name (git-file-name name version))
              (sha256
               (base32
                "17ys8ccr3h6vix0agvhz859slz0phhk7lwqn5bg4az8s7zgqm3nm"))))
    (build-system gnu-build-system)
    ;; Manually wrap the binary, because we’re not using python-build-system.
    (arguments
     '(#:phases
       (modify-phases %standard-phases
         (add-after 'install 'wrap-program
           (lambda* (#:key inputs outputs #:allow-other-keys)
             (let ((out         (assoc-ref outputs "out"))
                   (python-path (getenv "PYTHONPATH")))
               (wrap-program (string-append out "/bin/mpDris2")
                 `("PYTHONPATH" ":" prefix (,python-path)))
               #t))))))
    (inputs
     `(("python-mpd2" ,python-mpd2)
       ("python-dbus" ,python-dbus)
       ("python-pygobject" ,python-pygobject)
       ("python" ,python)))             ; Sets PYTHONPATH.
    ;; For bootstrapping.
    (native-inputs
     `(("autoconf" ,autoconf)
       ("automake" ,automake)
       ("gettext" ,gettext-minimal)
       ("which" ,which)
       ("intltool" ,intltool)))
    (synopsis "MPRIS V2.1 support for MPD")
    (description "Client for the Music Player Daemon providing MPRIS 2
support")
    (home-page "https://github.com/eonpatapon/mpDris2")
    (license license:gpl3+)))

(define-public cantata
  (package
    (name "cantata")
    (version "2.4.2")
    (source (origin
              (method url-fetch)
              (uri (string-append "https://github.com/CDrummond/"
                                  "cantata/releases/download/v" version "/"
                                  "cantata-" version ".tar.bz2"))
              (sha256
               (base32
                "10pcrpmb4n1mkgr21xd580nrbmh57q7s72cbs1zay847hc65vliy"))))
    (build-system cmake-build-system)
    (arguments
     `(#:tests? #f)) ; No test suite
    (native-inputs
     `(("pkg-config" ,pkg-config)))
    (inputs
     `(("eudev" ,eudev)
       ("ffmpeg" ,ffmpeg)
       ("libcdio-paranoia" ,libcdio-paranoia)
       ("libebur128" ,libebur128)
       ("libmtp" ,libmtp)
       ("mpg123" ,mpg123)
       ("qtbase" ,qtbase-5)
       ("qtmultimedia" ,qtmultimedia)
       ("qtsvg" ,qtsvg)
       ("taglib" ,taglib)
       ("zlib" ,zlib)))
    (synopsis "Graphical MPD Client")
    (description "Cantata is a graphical client for the Music Player Daemon
(MPD), using the Qt5 toolkit.  Its user interface is highly customizable,
supporting multiple collections, ratings, and dynamic playlists.  A local cache
of the music library will be created to provide a hierarchy of albums and
artists along with albumart.")
    (home-page "https://github.com/cdrummond/cantata")
    (license license:gpl3+)))

(define-public mcg
  (package
    (name "mcg")
    (version "2.1.2")
    (source
     (origin
       (method git-fetch)
       (uri
        (git-reference
         (url "https://gitlab.com/coderkun/mcg")
         (commit (string-append "v" version))))
       (file-name (git-file-name name version))
       (sha256
        (base32
         "01iqxydssxyi4s644dwl64vm7xhn0szd99hdpywbipvb7kwp5196"))))
    (build-system python-build-system)
    (native-inputs
     `(("glib:bin" ,glib "bin")
       ("gobject-introspection" ,gobject-introspection)
       ("pkg-config" ,pkg-config)))
    (inputs
     `(("avahi" ,avahi)
       ("dconf" ,dconf)
       ("gsettings-desktop-schemas" ,gsettings-desktop-schemas)
       ("gtk+" ,gtk+)
       ("python-pygobject" ,python-pygobject)))
    (arguments
     `(#:imported-modules ((guix build glib-or-gtk-build-system)
                           ,@%python-build-system-modules)
       #:modules ((guix build python-build-system)
                  ((guix build glib-or-gtk-build-system) #:prefix glib-or-gtk:)
                  (guix build utils))
       #:phases
       (modify-phases %standard-phases
         (add-after 'install 'wrap-program
           (lambda* (#:key outputs #:allow-other-keys)
             (let ((prog (string-append (assoc-ref outputs "out")
                                        "/bin/mcg")))
               (wrap-program prog
                 `("PYTHONPATH" = (,(getenv "PYTHONPATH")))
                 `("GI_TYPELIB_PATH" = (,(getenv "GI_TYPELIB_PATH"))))
               #t)))
         (add-after 'wrap-program 'glib-or-gtk-wrap
           (assoc-ref glib-or-gtk:%standard-phases 'glib-or-gtk-wrap)))))
    (synopsis "Covergrid for the MPD")
    (description
     "mcg (CoverGrid) is a client for the Music Player Daemon (MPD), focusing
on albums instead of single tracks.  It is not intended to be a replacement
for your favorite MPD client but an addition to get a better
album-experience.")
    (home-page "https://gitlab.com/coderkun/mcg")
    (license license:gpl3+)))


code:
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2014, 2015, 2018, 2019 Eric Bavier <bavier@member.fsf.org>
;;; Copyright © 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021 Ludovic Courtès <ludo@gnu.org>
;;; Copyright © 2014 Ian Denhardt <ian@zenhack.net>
;;; Copyright © 2016 Andreas Enge <andreas@enge.fr>
;;; Copyright © 2017 Dave Love <fx@gnu.org>
;;; Copyright © 2017 Efraim Flashner <efraim@flashner.co.il>
;;; Copyright © 2018–2021 Tobias Geerinckx-Rice <me@tobias.gr>
;;; Copyright © 2018 Paul Garlick <pgarlick@tourbillion-technology.com>
;;; Copyright © 2019 Ricardo Wurmus <rekado@elephly.net>
;;;
;;; 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 mpi)
  #:use-module (guix packages)
  #:use-module ((guix licenses) #:prefix license:)
  #:use-module (guix download)
  #:use-module (guix utils)
  #:use-module (guix deprecation)
  #:use-module (guix build-system gnu)
  #:use-module (guix build-system python)
  #:use-module (gnu packages)
  #:use-module (gnu packages base)
  #:use-module (gnu packages compression)
  #:use-module (gnu packages fabric-management)
  #:use-module (gnu packages gcc)
  #:use-module (gnu packages java)
  #:use-module (gnu packages libevent)
  #:use-module (gnu packages linux)
  #:use-module (gnu packages pciutils)
  #:use-module (gnu packages xorg)
  #:use-module (gnu packages gtk)
  #:use-module (gnu packages xml)
  #:use-module (gnu packages perl)
  #:use-module (gnu packages ncurses)
  #:use-module (gnu packages parallel)
  #:use-module (gnu packages pkg-config)
  #:use-module (gnu packages valgrind)
  #:use-module (srfi srfi-1)
  #:use-module (ice-9 match))

(define-public hwloc-1
  ;; Note: For now we keep 1.x as the default because many packages have yet
  ;; to migrate to 2.0.
  (package
    (name "hwloc")
    (version "1.11.12")
    (source (origin
              (method url-fetch)
              (uri (string-append "https://www.open-mpi.org/software/hwloc/v"
                                  (version-major+minor version)
                                  "/downloads/hwloc-" version ".tar.bz2"))
              (sha256
               (base32
                "0za1b9lvrm3rhn0lrxja5f64r0aq1qs4m0pxn1ji2mbi8ndppyyx"))))

    (properties
     ;; Tell the 'generic-html' updater to monitor this URL for updates.
     `((release-monitoring-url
        . "https://www-lb.open-mpi.org/software/hwloc/current")))

    (build-system gnu-build-system)
    (outputs '("out"           ;'lstopo' & co., depends on Cairo, libx11, etc.
               "lib"           ;small closure
               "doc"           ;400+ section 3 man pages
               "debug"))
    (inputs
     `(("libx11" ,libx11)
       ("cairo" ,cairo)
       ("ncurses" ,ncurses)
       ("expat" ,expat)
       ,@(if (not (string-prefix? "armhf"
                                  (or (%current-target-system)
                                      (%current-system))))
             `(("numactl" ,numactl))
             '())))
    (propagated-inputs
     ;; hwloc.pc lists it in 'Requires.private'.
     `(("libpciaccess" ,libpciaccess)))
    (native-inputs
     `(("pkg-config" ,pkg-config)))
    (arguments
     `(#:configure-flags '("--localstatedir=/var")
       #:phases
       (modify-phases %standard-phases
         (add-before 'check 'skip-linux-libnuma-test
           (lambda _
             ;; Arrange to skip 'tests/linux-libnuma', which fails on some
             ;; machines: <https://github.com/open-mpi/hwloc/issues/213>.
             (substitute* "tests/linux-libnuma.c"
               (("numa_available\\(\\)")
                "-1"))
             #t))
         (add-after 'install 'refine-libnuma
           ;; Give -L arguments for libraries to avoid propagation
           (lambda* (#:key inputs outputs #:allow-other-keys)
             (let ((out  (assoc-ref outputs "lib"))
                   (numa (assoc-ref inputs "numactl")))
               (substitute* (map (lambda (f) (string-append out "/" f))
                                 '("lib/pkgconfig/hwloc.pc" "lib/libhwloc.la"))
                 (("-lnuma" lib)
                  (string-append "-L" numa "/lib " lib))))))
         (add-after 'install 'avoid-circular-references
           (lambda* (#:key outputs #:allow-other-keys)
             (let ((lib (assoc-ref outputs "lib")))
               ;; Suppress the 'prefix=' and 'exec_prefix=' lines so that the
               ;; "lib" output doesn't refer to "out".
               (substitute* (string-append lib "/lib/pkgconfig/hwloc.pc")
                 (("^.*prefix=.*$")
                  ""))
               #t)))
         (add-after 'install 'move-man3-pages
           (lambda* (#:key outputs #:allow-other-keys)
             ;; Move section 3 man pages to the "doc" output.
             (let ((out (assoc-ref outputs "out"))
                   (doc (assoc-ref outputs "doc")))
               (copy-recursively (string-append out "/share/man/man3")
                                 (string-append doc "/share/man/man3"))
               (delete-file-recursively (string-append out "/share/man/man3"))
               #t))))))
    (home-page "https://www.open-mpi.org/projects/hwloc/")
    (synopsis "Abstraction of hardware architectures")
    (description
     "hwloc provides a portable abstraction (across OS,
versions, architectures, ...) of the hierarchical topology of modern
architectures, including NUMA memory nodes, sockets, shared caches, cores and
simultaneous multithreading.  It also gathers various attributes such as cache
and memory information.  It primarily aims at helping high-performance
computing applications with gathering information about the hardware so as to
exploit it accordingly and efficiently.

hwloc may display the topology in multiple convenient formats.  It also offers
a powerful programming interface to gather information about the hardware,
bind processes, and much more.")
    (license license:bsd-3)))

(define-public hwloc-2
  ;; Note: 2.x isn't the default yet, see above.
  (package
    (inherit hwloc-1)
    (version "2.5.0")
    (source (origin
              (method url-fetch)
              (uri (string-append "https://download.open-mpi.org/release/hwloc/v"
                                  (version-major+minor version)
                                  "/hwloc-" version ".tar.bz2"))
              (sha256
               (base32
                "1j2j9wn39a8v91r23xncm1rzls6rjkgkvdvqghbdsnq8ps491kx9"))))

    ;; libnuma is no longer needed.
    (inputs (alist-delete "numactl" (package-inputs hwloc-1)))
    (arguments
     (substitute-keyword-arguments (package-arguments hwloc-1)
       ((#:phases phases)
        `(modify-phases ,phases
           (replace 'skip-linux-libnuma-test
             (lambda _
               ;; Arrange to skip 'tests/hwloc/linux-libnuma', which fails on
               ;; some machines: <https://github.com/open-mpi/hwloc/issues/213>.
               (substitute* "tests/hwloc/linux-libnuma.c"
                 (("numa_available\\(\\)")
                  "-1"))
               #t))
           (add-before 'check 'skip-test-that-fails-on-qemu
             (lambda _
               ;; Skip test that fails on emulated hardware due to QEMU bug:
               ;; <https://bugs.gnu.org/40342>.
               (substitute* "tests/hwloc/hwloc_get_last_cpu_location.c"
                 (("hwloc_topology_init" all)
                  (string-append "exit (77);\n" all)))
               #t))))))))

(define-deprecated hwloc-2.0 hwloc-2)

(define-public hwloc
  ;; The latest stable series of hwloc.
  hwloc-2)

(define-public openmpi
  (package
    (name "openmpi")
    (version "4.1.1")
    (source
     (origin
      (method url-fetch)
      (uri (string-append "https://www.open-mpi.org/software/ompi/v"
                          (version-major+minor version)
                          "/downloads/openmpi-" version ".tar.bz2"))
      (sha256
       (base32 "1nkwq123vvmggcay48snm9qqmrh0bdzpln0l1jnp26niidvplkz2"))
      (patches (search-patches "openmpi-mtl-priorities.patch"))))

    (properties
     ;; Tell the 'generic-html' updater to monitor this URL for updates.
     `((release-monitoring-url
        . "https://www.open-mpi.org/software/ompi/current")))

    (build-system gnu-build-system)
    (inputs
     `(("hwloc" ,hwloc-2 "lib")
       ("gfortran" ,gfortran)
       ("libfabric" ,libfabric)
       ("libevent" ,libevent)
       ("opensm" ,opensm)
       ,@(if (and (not (%current-target-system))
                  (member (%current-system) (package-supported-systems psm)))
             `(("psm" ,psm))
             '())
       ,@(if (and (not (%current-target-system))
                  (member (%current-system) (package-supported-systems psm2)))
             `(("psm2" ,psm2))
             '())
       ,@(if (and (not (%current-target-system))
                  (member (%current-system) (package-supported-systems ucx)))
             `(("ucx" ,ucx))
             '())
       ("rdma-core" ,rdma-core)
       ("valgrind" ,valgrind)
       ("slurm" ,slurm)))              ;for PMI support (launching via "srun")
    (native-inputs
     `(("pkg-config" ,pkg-config)
       ("perl" ,perl)))
    (outputs '("out" "debug"))
    (arguments
     `(#:configure-flags `("--enable-mpi-ext=affinity" ;cr doesn't work
                           "--enable-memchecker"
                           "--with-sge"
                           "--with-valgrind"
                           "--with-hwloc=external"
                           "--with-libevent"

                           ;; Help 'orterun' and 'mpirun' find their tools
                           ;; under $prefix by default.
                           "--enable-mpirun-prefix-by-default"

                           ;; InfiniBand support
                           "--enable-openib-control-hdr-padding"
                           "--enable-openib-dynamic-sl"
                           "--enable-openib-udcm"
                           "--enable-openib-rdmacm"
                           "--enable-openib-rdmacm-ibaddr"

                           ;; Enable support for SLURM's Process Manager
                           ;; Interface (PMI).
                           ,(string-append "--with-pmi="
                                           (assoc-ref %build-inputs "slurm")))
       #:phases (modify-phases %standard-phases
                  ;; opensm is needed for InfiniBand support.
                  (add-after 'unpack 'find-opensm-headers
                    (lambda* (#:key inputs #:allow-other-keys)
                      (setenv "C_INCLUDE_PATH"
                              (string-append (assoc-ref inputs "opensm")
                                             "/include/infiniband"))
                      (setenv "CPLUS_INCLUDE_PATH"
                              (string-append (assoc-ref inputs "opensm")
                                             "/include/infiniband"))
                      #t))
                  (add-before 'build 'remove-absolute
                    (lambda _
                      ;; Remove compiler absolute file names (OPAL_FC_ABSOLUTE
                      ;; etc.) to reduce the closure size.  See
                      ;; <https://lists.gnu.org/archive/html/guix-devel/2017-07/msg00388.html>
                      ;; and
                      ;; <https://www.mail-archive.com/users@lists.open-mpi.org//msg31397.html>.
                      (substitute* '("orte/tools/orte-info/param.c"
                                     "oshmem/tools/oshmem_info/param.c"
                                     "ompi/tools/ompi_info/param.c")
                        (("_ABSOLUTE") ""))
                      ;; Avoid valgrind (which pulls in gdb etc.).
                      (substitute*
                          '("./ompi/mca/io/romio321/src/io_romio321_component.c")
                        (("MCA_io_romio321_COMPLETE_CONFIGURE_FLAGS")
                         "\"[elided to reduce closure]\""))
                      #t))
                  (add-before 'build 'scrub-timestamps ;reproducibility
                    (lambda _
                      (substitute* '("ompi/tools/ompi_info/param.c"
                                     "orte/tools/orte-info/param.c"
                                     "oshmem/tools/oshmem_info/param.c")
                        ((".*(Built|Configured) on.*") ""))
                      #t))
                  (add-after 'install 'remove-logs ;reproducibility
                    (lambda* (#:key outputs #:allow-other-keys)
                      (let ((out (assoc-ref outputs "out")))
                        (for-each delete-file (find-files out "config.log"))
                        #t))))))
    (home-page "https://www.open-mpi.org")
    (synopsis "MPI-3 implementation")
    (description
     "The Open MPI Project is an MPI-3 implementation that is developed and
maintained by a consortium of academic, research, and industry partners.  Open
MPI is therefore able to combine the expertise, technologies, and resources
from all across the High Performance Computing community in order to build the
best MPI library available.  Open MPI offers advantages for system and
software vendors, application developers and computer science researchers.")
    ;; See file://LICENSE
    (license license:bsd-2)))

;; TODO: javadoc files contain timestamps.
(define-public java-openmpi
  (package/inherit openmpi
    (name "java-openmpi")
    (inputs
     `(("openmpi" ,openmpi)
       ,@(package-inputs openmpi)))
    (native-inputs
     `(("jdk" ,openjdk11 "jdk")
       ("zip" ,(@ (gnu packages compression) zip))
       ,@(package-native-inputs openmpi)))
    (outputs '("out"))
    (arguments
     `(#:modules ((guix build gnu-build-system)
                  ((guix build ant-build-system) #:prefix ant:)
                  (guix build utils))
       #:imported-modules ((guix build ant-build-system)
                           (guix build syscalls)
                           ,@%gnu-build-system-modules)
       ,@(substitute-keyword-arguments (package-arguments openmpi)
           ((#:configure-flags flags)
            `(cons "--enable-mpi-java" ,flags))
           ((#:make-flags flags ''())
            `(append '("-C" "ompi/mpi/java")
                     ,flags))
           ((#:phases phases)
            `(modify-phases ,phases
               ;; We could provide the location of the JDK in the configure
               ;; flags, but since the configure flags are embedded in the
               ;; info binaries that would leave a reference to the JDK in
               ;; the "out" output.  To avoid this we set JAVA_HOME.
               (add-after 'unpack 'set-JAVA_HOME
                 (lambda* (#:key inputs #:allow-other-keys)
                   (setenv "JAVA_HOME" (assoc-ref inputs "jdk"))
                   #t))
               (add-after 'unpack 'link-with-existing-mpi-libraries
                 (lambda* (#:key inputs #:allow-other-keys)
                   (substitute* "ompi/mpi/java/c/Makefile.in"
                     (("\\$\\(top_builddir\\)/ompi/lib@OMPI_LIBMPI_NAME@.la")
                      (string-append (assoc-ref inputs "openmpi") "/lib/libmpi.la")))
                   #t))
               (add-after 'install 'strip-jar-timestamps
                 (assoc-ref ant:%standard-phases 'strip-jar-timestamps)))))))
    (synopsis "Java bindings for MPI")))

(define-public openmpi-thread-multiple
  (package/inherit openmpi
    (name "openmpi-thread-multiple")
    (arguments
     (substitute-keyword-arguments (package-arguments openmpi)
       ((#:configure-flags flags)
        `(cons "--enable-mpi-thread-multiple" ,flags))))
    (description " This version of Open@tie{}MPI has an implementation of
@code{MPI_Init_thread} that provides @code{MPI_THREAD_MULTIPLE}.  This won't
work correctly with all transports (such as @code{openib}), and the
performance is generally worse than the vanilla @code{openmpi} package, which
only provides @code{MPI_THREAD_FUNNELED}.")))

;;; Build phase to be used for packages that execute MPI code.
(define-public %openmpi-setup
  '(lambda _
     ;; By default, running the test suite would fail because 'ssh' could not
     ;; be found in $PATH.  Define this variable to placate Open MPI without
     ;; adding a dependency on OpenSSH (the agent isn't used anyway.)
     (setenv "OMPI_MCA_plm_rsh_agent" (which "false"))
     ;; Allow oversubscription in case there are less physical cores available
     ;; in the build environment than the package wants while testing.
     (setenv "OMPI_MCA_rmaps_base_mapping_policy" "core:OVERSUBSCRIBE")

     ;; UCX sometimes outputs uninteresting warnings such as:
     ;;
     ;;   mpool.c:38   UCX  WARN  object 0x7ffff44fffc0 was not returned to mpool ucp_am_bufs
     ;;
     ;; These in turn leads to failures of test suites that capture and
     ;; compare stdout, such as that of 'hdf5-parallel-openmpi'.  Thus, tell
     ;; UCX to not emit those warnings.
     (setenv "UCX_LOG_LEVEL" "error")
     #t))

(define-public python-mpi4py
  (package
    (name "python-mpi4py")
    (version "3.0.3")
    (source
     (origin
       (method url-fetch)
       (uri (pypi-uri "mpi4py" version))
       (sha256
        (base32 "07ssbhssv27rrjx1c5vd3vsr31vay5d8xcf4zh9yblcyidn72b81"))))
    (build-system python-build-system)
    (arguments
     `(#:phases
       (modify-phases %standard-phases
         (add-after 'build 'mpi-setup
           ,%openmpi-setup)
         (add-before 'check 'pre-check
           (lambda _
             ;; Skip BaseTestSpawn class (causes error 'ompi_dpm_dyn_init()
             ;; failed --> Returned "Unreachable"' in chroot environment).
             (substitute* "test/test_spawn.py"
               (("unittest.skipMPI\\('openmpi\\(<3.0.0\\)'\\)")
                "unittest.skipMPI('openmpi')"))
             #t)))))
    (inputs
     `(("openmpi" ,openmpi)))
    (home-page "https://bitbucket.org/mpi4py/mpi4py/")
    (synopsis "Python bindings for the Message Passing Interface standard")
    (description "MPI for Python (mpi4py) provides bindings of the Message
Passing Interface (MPI) standard for the Python programming language, allowing
any Python program to exploit multiple processors.

mpi4py is constructed on top of the MPI-1/MPI-2 specification and provides an
object oriented interface which closely follows MPI-2 C++ bindings.  It
supports point-to-point and collective communications of any picklable Python
object as well as optimized communications of Python objects (such as NumPy
arrays) that expose a buffer interface.")
    (license license:bsd-3)))

(define-public mpich
  (package
    (name "mpich")
    (version "3.3.2")
    (source (origin
              (method url-fetch)
              (uri (string-append "http://www.mpich.org/static/downloads/"
                                  version "/mpich-" version ".tar.gz"))
              (sha256
               (base32
                "1farz5zfx4cd0c3a0wb9pgfypzw0xxql1j1294z1sxslga1ziyjb"))))
    (build-system gnu-build-system)
    (inputs
     `(("zlib" ,zlib)
       ("hwloc" ,hwloc-2 "lib")
       ("slurm" ,slurm)
       ,@(if (and (not (%current-target-system))
                  (member (%current-system) (package-supported-systems ucx)))
             `(("ucx" ,ucx))
             '())))
    (native-inputs
     `(("perl" ,perl)
       ("which" ,which)
       ("gfortran" ,gfortran)))
    (outputs '("out" "debug"))
    (arguments
     `(#:configure-flags
       (list "--disable-silent-rules"             ;let's see what's happening
             "--enable-debuginfo"

             ;; Default to "ch4", as will be the case in 3.4.  It also works
             ;; around issues when running test suites of packages that use
             ;; MPICH: <https://issues.guix.gnu.org/39588#15>.
             "--with-device=ch4:ucx" ; --with-device=ch4:ofi segfaults in tests

             (string-append "--with-hwloc-prefix="
                            (assoc-ref %build-inputs "hwloc"))

             ,@(if (assoc "ucx" (package-inputs this-package))
                   `((string-append "--with-ucx="
                                    (assoc-ref %build-inputs "ucx")))
                   '()))

       #:phases (modify-phases %standard-phases
                  (add-after 'unpack 'patch-sources
                    (lambda _
                      (substitute* "./maint/gen_subcfg_m4"
                        (("/usr/bin/env") (which "env")))
                      (substitute* "src/glue/romio/all_romio_symbols"
                        (("/usr/bin/env") (which "env")))
                      (substitute* (find-files "." "buildiface")
                        (("/usr/bin/env") (which "env")))
                      (substitute* "maint/extracterrmsgs"
                        (("/usr/bin/env") (which "env")))
                      (substitute* (find-files "." "f77tof90")
                        (("/usr/bin/env") (which "env")))
                      (substitute* (find-files "." "\\.sh$")
                        (("/bin/sh") (which "sh")))
                      #t))
                  (add-before 'configure 'fix-makefile
                    (lambda _
                      ;; Remove "@hwloclib@" from 'pmpi_convenience_libs'.
                      ;; This fixes "No rule to make target '-lhwloc', needed
                      ;; by 'lib/libmpi.la'".
                      (substitute* "Makefile.in"
                        (("^pmpi_convenience_libs = (.*) @hwloclib@ (.*)$" _
                          before after)
                         (string-append "pmpi_convenience_libs = "
                                        before " " after)))
                      #t)))))
    (home-page "https://www.mpich.org/")
    (synopsis "Implementation of the Message Passing Interface (MPI)")
    (description
     "MPICH is a high-performance and portable implementation of the Message
Passing Interface (MPI) standard (MPI-1, MPI-2 and MPI-3).  MPICH provides an
MPI implementation that efficiently supports different computation and
communication platforms including commodity clusters, high-speed networks (10
Gigabit Ethernet, InfiniBand, Myrinet, Quadrics), and proprietary high-end
computing systems (Blue Gene, Cray).  It enables research in MPI through a
modular framework for other derived implementations.")
    (license license:bsd-2)))

repo_name: maximed/guix

license: mit


code:
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2013 John Darrington <jmd@gnu.org>
;;; Copyright © 2015, 2019 Ludovic Courtès <ludo@gnu.org>
;;; Copyright © 2018, 2020, 2021 Tobias Geerinckx-Rice <me@tobias.gr>
;;; Copyright © 2018 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 mtools)
  #:use-module (guix licenses)
  #:use-module (guix packages)
  #:use-module (guix download)
  #:use-module (guix build-system gnu)
  #:use-module (gnu packages))

(define-public mtools
  (package
    (name "mtools")
    (version "4.0.31")
    (source (origin
              (method url-fetch)
              (uri (string-append "mirror://gnu/mtools/mtools-"
                                  version ".tar.bz2"))
              (sha256
               (base32
                "11nm5mhsq700f3dzvzjpcik89cfcn38mb249yc0sjbwggwkrk2ak"))
              (patches
               (search-patches "mtools-mformat-uninitialized.patch"))))
    (build-system gnu-build-system)
    (home-page "https://www.gnu.org/software/mtools/")
    (synopsis "Access MS-DOS disks without mounting")
    (description
     "GNU Mtools is a set of utilities for accessing MS-DOS disks from a GNU
or Unix system.  It supports long file names and multiple disk formats.  It
also supports some FAT-specific features such as volume labels and
FAT-specific file attributes.")
    (license gpl3+)))


code:
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2012, 2013, 2015 Ludovic Courtès <ludo@gnu.org>
;;; Copyright © 2014 Mark H Weaver <mhw@netris.org>
;;; Copyright © 2015, 2018 Andreas Enge <andreas@enge.fr>
;;; Copyright © 2016, 2020 Nicolas Goaziou <mail@nicolasgoaziou.fr>
;;; Copyright © 2016, 2020 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
;;; Copyright © 2018, 2019 Tobias Geerinckx-Rice <me@tobias.gr>
;;; Copyright © 2018 Eric Bavier <bavier@member.fsf.org>
;;; Copyright © 2018, 2019, 2021 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 multiprecision)
  #:use-module (guix licenses)
  #:use-module (gnu packages)
  #:use-module (gnu packages autotools)
  #:use-module (gnu packages m4)
  #:use-module (gnu packages gcc)
  #:use-module (gnu packages texinfo)
  #:use-module (guix packages)
  #:use-module (guix download)
  #:use-module (guix utils)
  #:use-module (guix build-system gnu))

(define-public gmp
  (package
   (name "gmp")
   (version "6.2.0")
   (source (origin
            (method url-fetch)
            (uri
             (string-append "mirror://gnu/gmp/gmp-"
                            version ".tar.xz"))
            (sha256
             (base32
              "09hmg8k63mbfrx1x3yy6y1yzbbq85kw5avbibhcgrg9z3ganr3i5"))
            (patches (search-patches "gmp-faulty-test.patch"))))
   (build-system gnu-build-system)
   (native-inputs `(("m4" ,m4)))
   (outputs '("out" "debug"))
   (arguments
    `(#:parallel-tests? #f ; mpz/reuse fails otherwise
      #:configure-flags
      '(;; Build a "fat binary", with routines for several
        ;; sub-architectures.
        "--enable-fat"
        "--enable-cxx"
        ,@(cond ((target-mingw?)
                 ;; Static and shared cannot be built in one go:
                 ;; they produce different headers.  We need shared.
                 `("--disable-static"
                   "--enable-shared"))
                (else '())))
      ;; Remove after core-updates merge.
      ;; Workaround for gcc-7 transition breakage, -system and cross-build,
      ;; Note: See <http://bugs.gnu.org/22186> for why not 'CPATH'.
      ;; Note: See <http://bugs.gnu.org/30756> for why not 'C_INCLUDE_PATH' & co.
      ,@(if (target-mingw?)
            `(#:phases
              (modify-phases %standard-phases
                (add-before 'configure 'setenv
                  (lambda _
                    (let ((gcc (assoc-ref %build-inputs "cross-gcc"))
                          (libc (assoc-ref %build-inputs "cross-libc")))
                      (setenv "CROSS_CPLUS_INCLUDE_PATH"
                              (string-append gcc "/include/c++"
                                             ":" gcc "/include"
                                             ":" libc "/include"))
                      (format #t "environment variable `CROSS_CPLUS_INCLUDE_PATH' set to `~a'\n"
                              (getenv "CROSS_CPLUS_INCLUDE_PATH"))
                      #t)))))
            '())))
   (synopsis "Multiple-precision arithmetic library")
   (description
    "The @acronym{GMP, the GNU Multiple Precision Arithmetic} library performs
arbitrary-precision arithmetic on signed integers, rational numbers and floating
point numbers.  The precision is only limited by the available memory.
The library is highly optimized, with a design focus on execution speed.
It is aimed at use in, for example, cryptography and computational algebra.")
   (license lgpl3+)
   (home-page "https://gmplib.org/")))

(define-public gmp-6.0
  ;; We keep this one around to bootstrap GCC, to work around a compilation
  ;; issue on ARM.  See
  ;; <https://gmplib.org/list-archives/gmp-bugs/2015-December/003848.html>.
  (package
    (inherit gmp)
    (version "6.0.0a")
    (source (origin
              (method url-fetch)
              (uri (string-append "mirror://gnu/gmp/gmp-"
                                  version ".tar.xz"))
              (sha256
               (base32
                "0r5pp27cy7ch3dg5v0rsny8bib1zfvrza6027g2mp5f6v8pd6mli"))
              (patches (search-patches "gmp-arm-asm-nothumb.patch"
                                       "gmp-faulty-test.patch"))))))

(define-public mpfr
  (package
   (name "mpfr")
   (version "4.0.2")
   (source (origin
            (method url-fetch)
            (uri (string-append "mirror://gnu/mpfr/mpfr-" version
                                ".tar.xz"))
            (sha256 (base32
                     "12m3amcavhpqygc499s3fzqlb8f2j2rr7fkqsm10xbjfc04fffqx"))))
   (build-system gnu-build-system)
   (outputs '("out" "debug"))
   (propagated-inputs `(("gmp" ,gmp)))            ; <mpfr.h> refers to <gmp.h>
   (synopsis "C library for arbitrary-precision floating-point arithmetic")
   (description
    "GNU@tie{}@acronym{MPFR, Multiple Precision Floating-Point Reliably} is a C
library for performing multiple-precision, floating-point computations with
correct rounding.")
   (license lgpl3+)
   (home-page "https://www.mpfr.org/")))

(define-public mpc
  (package
   (name "mpc")
   (version "1.1.0")
   (source (origin
            (method url-fetch)
            (uri (string-append
                  "mirror://gnu/mpc/mpc-" version ".tar.gz"))
            (sha256
              (base32
                "0biwnhjm3rx3hc0rfpvyniky4lpzsvdcwhmcn7f0h4iw2hwcb1b9"))))
   (build-system gnu-build-system)
   (outputs '("out" "debug"))
   (propagated-inputs `(("gmp" ,gmp)              ; <mpc.h> refers to both
                        ("mpfr" ,mpfr)))
   (synopsis "C library for arbitrary-precision complex arithmetic")
   (description
    "GNU@tie{}@acronym{MPC, Multiple Precision Complex library} is a C library
for performing arithmetic on complex numbers.  It supports arbitrarily high
precision and correctly rounds the results.")
   (license lgpl3+)
   (home-page "http://www.multiprecision.org/mpc/")))

(define-public mpfi
  (package
    (name "mpfi")
    (version "1.5.4")
    (source
     (origin
       (method url-fetch)
       (uri (string-append "https://gforge.inria.fr/frs/download.php"
                           "/latestfile/181/mpfi-" version ".tgz"))
       (sha256
        (base32 "0mismr1ll3wp788dq2n22s5irm0dziy75byyfdwz22kjbmckhf9v"))))
    (build-system gnu-build-system)
    (arguments
     `(#:tests? #f                      ;tests are broken in this release
       #:configure-flags '("--enable-static=no")))
    (native-inputs
     `(("automake" ,automake)
       ("autoreconf" ,autoconf)
       ("libtool" ,libtool)
       ("texinfo" ,texinfo)))
    (propagated-inputs
     `(("gmp" ,gmp)                     ; <mpfi.h> refers to both
       ("mpfr" ,mpfr)))
    (home-page "https://gforge.inria.fr/projects/mpfi/")
    (synopsis "C library for arbitrary-precision interval arithmetic")
    (description
     "@acronym{MPFI, Multiple Precision Floating-point Interval} is a portable C
library for arbitrary-precision interval arithmetic, with intervals represented
using MPFR reliable floating-point numbers.  It's based on the @acronym{GMP, GNU
Multiple Precision Arithmetic} and GNU@tie{}@acronym{MPFR, Multiple Precision
Floating-Point Reliably} libraries.

The purpose of arbitrary-precision interval arithmetic is to get results that
are both guaranteed, thanks to interval computation, and accurate, thanks to
multiple-precision arithmetic.")
    (license lgpl2.1+)))

(define-public irram
  (package
    (name "irram")
    (version "2013_01")
    (source
     (origin
       (method url-fetch)
       (uri (string-append "http://irram.uni-trier.de/irram-files/iRRAM_"
                           version ".tar.bz2"))
       (sha256
        (base32 "1cdmvb4hsa161rfdjqyhd9sb3fcr43p3a6nsj7cb4kn9f94qmjpj"))))
    (build-system gnu-build-system)
    (propagated-inputs `(("gmp" ,gmp)   ; <mpfi.h> refers to both
                         ("mpfr" ,mpfr)))
    (arguments
     `(#:parallel-build? #f))
    (synopsis "C++ package for real arithmetic based on the Real-RAM concept")
    (description
     "@dfn{iRRAM} is a C++ package for error-free real arithmetic based on
the concept of a Real-RAM.  Its capabilities range from ordinary arithmetic
over trigonometric functions to linear algebra and differential
equations.  A program using iRRAM is coded in ordinary C++, but may use a
special class that behaves like real numbers without any
error.  Additionally, iRRAM uses the concept of multi-valued functions.")
    (license lgpl2.0+)
    (home-page "http://irram.uni-trier.de/")))

(define-public qd
  (package
    (name "qd")
    (version "2.3.22")
    (source
     (origin
       (method url-fetch)
       (uri (string-append "https://crd-legacy.lbl.gov/~dhbailey/mpdist/qd-"
                           version ".tar.gz"))
       (sha256
        (base32 "1lq609rsp6zpg7zda75lyxzzk1fabzp4jn88j7xfk84mdgjgzh9h"))))
    (build-system gnu-build-system)
    (native-inputs
     `(("gfortran" ,gfortran)))
    (arguments
     `(#:configure-flags `("--disable-enable_fma" ;weird :/
                           "--enable-shared"
                           ,,@(if (string-prefix? "aarch64"
                                                  (or (%current-target-system)
                                                      (%current-system)))
                                  ;; XXX: The qd_test test fails numerical
                                  ;; accuracy checks for 'dd_real::exp()' on
                                  ;; aarch64 with GCC 5.4 at -O2.  Disabling
                                  ;; expensive optimizations lets it pass.
                                  '("CXXFLAGS=-O3 -fno-expensive-optimizations")
                                  '("CXXFLAGS=-O3")))))
    (home-page "https://www.davidhbailey.com/dhbsoftware/")
    (synopsis "Double-double and quad-double library")
    (description "This package supports both a double-double
datatype (approx. 32 decimal digits) and a quad-double datatype (approx. 64
decimal digits).  The computational library is written in C++.  Both C++ and
Fortran-90 high-level language interfaces are provided to permit one to
convert an existing C++ or Fortran-90 program to use the library with only
minor changes to the source code.  In most cases only a few type statements
and (for Fortran-90 programs) read/write statements need to be changed.  PSLQ
and numerical quadrature programs are included.")
    (license bsd-3)))

(define-public tomsfastmath
  (package
    (name "tomsfastmath")
    (version "0.13.1")
    (synopsis "Large integer arithmetic library")
    (source (origin
              (method url-fetch)
              (uri (string-append "https://github.com/libtom/tomsfastmath/"
                                  "releases/download/v" version "/"
                                  "tfm-" version ".tar.xz"))
              (sha256
               (base32
                "0f0pmiaskh89sp0q933pafxb914shpaj5ad8sb5rzk1wv8d7mja7"))))
    (build-system gnu-build-system)
    (native-inputs
     `(("libtool" ,libtool)))
    (arguments
     `(#:make-flags (list "-f" "makefile.shared"
                          (string-append "LIBPATH=" %output "/lib")
                          (string-append "INCPATH=" %output "/include")
                          "GROUP=root" "USER=root"
                          "CC=gcc")
       #:phases
       (modify-phases %standard-phases
         (delete 'configure)            ; no configuration
         (replace 'check
           (lambda* (#:key make-flags #:allow-other-keys)
             (apply invoke "make"
                    "stest" "test_standalone"
                    make-flags)
             (invoke "./stest")
             (invoke "./test")))
         (add-before 'install 'install-nogroup
           (lambda _
             ;; Let permissions inherit from the current process.
             (substitute* "makefile.shared"
               (("-g \\$\\(GROUP\\) -o \\$\\(USER\\)") ""))
             #t))
         (add-after 'install 'install-doc
           (lambda* (#:key outputs #:allow-other-keys)
             (let ((docdir (string-append (assoc-ref outputs "out")
                                          "/share/doc/tomsfastmath")))
               (install-file "doc/tfm.pdf" docdir)
               #t)))
         (add-after 'install 'install-pc
           (lambda* (#:key outputs #:allow-other-keys)
             (let* ((out (assoc-ref outputs "out"))
                    (pc-dir (string-append out "/lib/pkgconfig")))
               (call-with-output-file "tomsfastmath.pc"
                 (lambda (port)
                   (format port "~
Name: TomsFastMath
Description: ~a
Version: ~a
Libs: -L~a/lib -ltfm~%"
                           ,synopsis ,version out)))
               (install-file "tomsfastmath.pc" pc-dir)
               #t))))))
    (home-page "https://www.libtom.net/TomsFastMath/")
    (description "TomsFastMath is a large integer library written in portable
ISO C.  It is a port of LibTomMath with optional support for inline assembler
multiplies.")
    (license public-domain)))

(define-public libtomcrypt
  (package
    (name "libtomcrypt")
    (version "1.18.2")
    (outputs '("out" "static"))
    (source
      (origin
        (method url-fetch)
        (uri (string-append "https://github.com/libtom/libtomcrypt"
                            "/releases/download/v" version
                            "/crypt-" version ".tar.xz"))
        (sha256
         (base32
          "113vfrgapyv72lalhd3nkw7jnks8az0gcb5wqn9hj19nhcxlrbcn"))
        (modules '((guix build utils)))
        (snippet
         '(begin
            ;; Patch CVE-2019-17362
            ;; https://github.com/libtom/libtomcrypt/commit/25c26a3b7a9ad8192ccc923e15cf62bf0108ef94
            (substitute* "src/pk/asn1/der/utf8/der_decode_utf8_string.c"
              (("z > 4") "z == 1 || z > 4"))
            #t))))
    (build-system gnu-build-system)
    (arguments
     `(#:phases
       (modify-phases %standard-phases
         (delete 'configure) ; no configure
         (add-after 'unpack 'prepare-build
           (lambda _
             ;; We want the shared library by default so force it to be the
             ;; default makefile target.
             (delete-file "makefile")
             (symlink "makefile.shared" "makefile")
             ;; We link to libtommath, so we need to add it to the pc file
             (substitute* "libtomcrypt.pc.in"
               (("-ltomcrypt") "-ltomcrypt -ltommath"))
             #t))
         (add-after 'build 'build-static
           (lambda* (#:key make-flags #:allow-other-keys)
             (apply invoke "make" "-f" "makefile.unix" make-flags)))
         (replace 'check
           (lambda* (#:key test-target make-flags #:allow-other-keys)
             (apply invoke "make" "-f" "makefile.unix" test-target make-flags)
             (invoke "./test")))
         (add-after 'install 'install-static-library
           (lambda* (#:key outputs #:allow-other-keys)
             (let ((out (assoc-ref outputs "out"))
                   (static (assoc-ref outputs "static")))
               (mkdir-p (string-append static "/lib"))
               (mkdir-p (string-append static "/include"))
               (rename-file (string-append out "/lib/libtomcrypt.a")
                            (string-append static "/lib/libtomcrypt.a"))
               (copy-recursively (string-append out "/include")
                                 (string-append static "/include"))
               #t))))
       #:test-target "test"
       #:make-flags
       (list (string-append "PREFIX=" (assoc-ref %outputs "out"))
             "CFLAGS += -DLTM_DESC -DUSE_LTM"
             (string-append "EXTRALIBS=" (assoc-ref %build-inputs "libtommath")
                            "/lib/libtommath.so")
             (string-append "CC=" ,(cc-for-target)))))
    (native-inputs
     `(("libtool" ,libtool)))
    (inputs
     `(("libtommath" ,libtommath)))
    (home-page "https://www.libtom.net/LibTomCrypt/")
    (synopsis "Cryptographic toolkit")
    (description "LibTomCrypt is a fairly comprehensive, modular and portable
cryptographic toolkit that provides developers with a vast array of well known
published block ciphers, one-way hash functions, chaining modes, pseudo-random
number generators, public key cryptography and a plethora of other routines.")
    (properties `((lint-hidden-cve . ("CVE-2019-17362"))))
    (license unlicense)))

(define-public libtommath
  (package
    (name "libtommath")
    (version "1.2.0")
    (outputs '("out" "static"))
    (source
      (origin
        (method url-fetch)
        (uri (string-append "https://github.com/libtom/libtommath/releases/"
                            "download/v" version "/ltm-" version ".tar.xz"))
        (sha256
         (base32
          "1c8q1qy88cjhdjlk3g24mra94h34c1ldvkjz0n2988c0yvn5xixp"))))
    (build-system gnu-build-system)
    (arguments
     '(#:phases
       (modify-phases %standard-phases
         (delete 'configure) ; no configure
         (add-after 'unpack 'prepare-build
           (lambda _
             ;; We want the shared library by default so force it to be the
             ;; default makefile target.
             (delete-file "makefile")
             (symlink "makefile.shared" "makefile")
             #t))
         (add-after 'install 'remove-static-library
           (lambda* (#:key outputs #:allow-other-keys)
             (delete-file (string-append (assoc-ref outputs "out")
                                         "/lib/libtommath.a"))
             #t))
         (replace 'check
           (lambda* (#:key test-target make-flags #:allow-other-keys)
             (apply invoke "make" test-target make-flags)
             (invoke "sh" "test")))
         (add-after 'install 'install-static-library
           (lambda* (#:key outputs #:allow-other-keys)
             (invoke "make" "-f" "makefile.unix" "install"
                     (string-append "PREFIX=" (assoc-ref outputs "static"))
                     (string-append "CC=" (which "gcc"))))))
       #:test-target "test"
       #:make-flags (list (string-append "PREFIX=" (assoc-ref %outputs "out"))
                          "CC=gcc")))
    (native-inputs
     `(("libtool" ,libtool)))
    (home-page "https://www.libtom.net/LibTomMath/")
    (synopsis "Portable number theoretic multiple-precision integer library")
    (description "LibTomMath is a portable number theoretic multiple-precision
integer library written entirely in C.  It's designed to provide an API that is
simple to work with that provides fairly efficient routines that build out of
the box without configuration.")
    (license unlicense)))

(define-public libtommath-1.1
  (package
    (inherit libtommath)
    (version "1.1.0")
    (source
      (origin
        (method url-fetch)
        (uri (string-append "https://github.com/libtom/libtommath/releases/"
                            "download/v" version "/ltm-" version ".tar.xz"))
        (sha256
         (base32
          "1bbyagqzfdbg37k1n08nsqzdf44z8zsnjjinqbsyj7rxg246qilh"))
        (patches (search-patches "libtommath-fix-linkage.patch"))))
    (arguments
      (substitute-keyword-arguments (package-arguments libtommath)
        ((#:phases phases)
         `(modify-phases ,phases
            (add-after 'unpack 'patch-coreutils-call
              (lambda _
                ;; Don't pull in coreutils.
                (substitute* "makefile_include.mk"
                  (("arch") "uname -m"))
                #t))))
        ((#:test-target _) "test_standalone")))))

(define-public libtommath-1.0
  (package
    (inherit libtommath-1.1)
    (version "1.0.1")
    (outputs '("out"))
    (source
      (origin
        (method url-fetch)
        (uri (string-append "https://github.com/libtom/libtommath/releases/"
                            "download/v" version "/ltm-" version ".tar.xz"))
        (sha256
         (base32
          "0sbccdwbkfc680id2fi0x067j23biqcjqilwkk7y9339knrjy0s7"))))
    (arguments
      (substitute-keyword-arguments (package-arguments libtommath-1.1)
        ((#:phases phases)
         `(modify-phases ,phases
            (delete 'install-static-library)))))))