code:
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2013 Ludovic Courtès <ludo@gnu.org>
;;; Copyright © 2016, 2020 Efraim Flashner <efraim@flashner.co.il>
;;; Copyright © 2019 Tobias Geerinckx-Rice <me@tobias.gr>
;;; Copyright © 2019 Alex Vong <alexvong1995@gmail.com>
;;; Copyright © 2021 Andy Tai <atai@atai.org>
;;; Copyright © 2021 Nicolas Goaziou <mail@nicolasgoaziou.fr>
;;;
;;; 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 ocr)
  #:use-module ((guix licenses) #:prefix license:)
  #:use-module (guix packages)
  #:use-module (guix download)
  #:use-module (guix git-download)
  #:use-module (guix build-system cmake)
  #:use-module (guix build-system gnu)
  #:use-module (guix build-system python)
  #:use-module (gnu packages)
  #:use-module (gnu packages autotools)
  #:use-module (gnu packages backup)
  #:use-module (gnu packages check)
  #:use-module (gnu packages compression)
  #:use-module (gnu packages curl)
  #:use-module (gnu packages djvu)
  #:use-module (gnu packages docbook)
  #:use-module (gnu packages documentation)
  #:use-module (gnu packages enchant)
  #:use-module (gnu packages gettext)
  #:use-module (gnu packages glib)
  #:use-module (gnu packages gtk)
  #:use-module (gnu packages icu4c)
  #:use-module (gnu packages pdf)
  #:use-module (gnu packages pkg-config)
  #:use-module (gnu packages python)
  #:use-module (gnu packages qt)
  #:use-module (gnu packages scanner)
  #:use-module (gnu packages xml)
  #:use-module (gnu packages image))

(define-public ocrad
  (package
    (name "ocrad")
    (version "0.27")
    (source (origin
             (method url-fetch)
             (uri (string-append "mirror://gnu/ocrad/ocrad-"
                                 version ".tar.lz"))
             (sha256
              (base32
               "0divffvcaim89g4pvqs8kslbcxi475bcl3b4ynphf284k9zfdgx9"))))
    (build-system gnu-build-system)
    (native-inputs `(("lzip" ,lzip)))
    (home-page "https://www.gnu.org/software/ocrad/")
    (synopsis "Optical character recognition based on feature extraction")
    (description
     "GNU Ocrad is an optical character recognition program based on a
feature extraction method.  It can read images in PBM, PGM or PPM formats and
it produces text in 8-bit or UTF-8 formats.")
    (license license:gpl3+)))

(define-public tesseract-ocr
  ;; There are useful commits beyond the last official stable release.
  (let ((commit "97079fa353557af6df86fd20b5d2e0dff5d8d5df")
        (revision "1"))
    (package
      (name "tesseract-ocr")
      (version (git-version "4.1.1" revision commit))
      (source
       (origin
         (method git-fetch)
         (uri (git-reference
               (url "https://github.com/tesseract-ocr/tesseract")
               (commit commit)))
         (file-name (git-file-name name version))
         (sha256
          (base32
           "11137a4aaay7qp64vdjd83hz1l089nzi5a0ql0qgk8gn79pyhi98"))))
      (build-system gnu-build-system)
      (inputs
       `(("cairo" ,cairo)
         ("icu" ,icu4c)
         ("leptonica" ,leptonica)
         ("pango" ,pango)
         ("python-wrapper" ,python-wrapper)))
      (native-inputs
       `(("asciidoc" ,asciidoc)
         ("autoconf" ,autoconf)
         ("automake" ,automake)
         ("docbook-xsl" ,docbook-xsl)
         ("libarchive" ,libarchive)
         ("libcurl" ,curl)
         ("libtool" ,libtool)
         ("libtiff" ,libtiff)
         ("pkg-config" ,pkg-config)
         ("xsltproc" ,libxslt)))
      (arguments
       `(#:configure-flags
         (let ((leptonica (assoc-ref %build-inputs "leptonica")))
           (list (string-append "LIBLEPT_HEADERSDIR=" leptonica "/include")))
         #:tests? #f ; Tests currently result in a segfault
         #:phases
         (modify-phases %standard-phases
           (add-after 'unpack 'fix-docbook
             (lambda* (#:key inputs #:allow-other-keys)
               ;; Don't attempt to download XSL schema.
               (substitute* "doc/Makefile.am"
                 (("http://docbook.sourceforge.net/release/xsl/current/manpages/docbook.xsl")
                  (string-append (assoc-ref inputs "docbook-xsl")
                                 "/xml/xsl/docbook-xsl-"
                                 ,(package-version docbook-xsl)
                                 "/manpages/docbook.xsl")))))
           (add-after 'install 'build-training
             (lambda _
               (invoke "make" "training")))
           (add-after 'build-training 'install-training
             (lambda _
               (invoke "make" "training-install"))))))
      (home-page "https://github.com/tesseract-ocr/tesseract")
      (synopsis "Optical character recognition engine")
      (description
       "Tesseract is an optical character recognition (OCR) engine with very
high accuracy.  It supports many languages, output text formatting, hOCR
positional information and page layout analysis.  Several image formats are
supported through the Leptonica library.  It can also detect whether text is
monospaced or proportional.")
      (license license:asl2.0))))

(define-public gimagereader
  (package
    (name "gimagereader")
    (version "3.3.1")
    (source
     (origin
       (method url-fetch)
       (uri (string-append
             "https://github.com/manisandro/gImageReader/releases"
             "/download/v" version "/"
             "gimagereader-" version ".tar.xz"))
       (sha256
        (base32 "1pghffb55k3wq33nbn9fi0lmjbldpmvqs2msnvss8bxz1k1ck23n"))))
    (build-system cmake-build-system)
    (arguments
     `(#:tests? #f                      ;no test
       #:configure-flags (list "-DENABLE_VERSIONCHECK=0")
       #:phases
       (modify-phases %standard-phases
         (add-after 'unpack 'fix-build
           ;; XXX: Prevent compilation error: "incomplete type ‘QUrl’ used in
           ;; nested name specifier".  Fixed upstream as
           ;; 6209e25dab20b233e399ff36fabe4252db0f9e44.  It can be removed in
           ;; release 3.3.2+.
           (lambda _
             (with-directory-excursion "qt/src/hocr"
               (substitute* '("HOCROdtExporter.cc" "HOCRTextExporter.cc")
                 (("#include <QMessageBox>\n" all)
                  (string-append all "#include <QUrl>\n"))))
             #t)))))
    (native-inputs
     `(("gettext" ,gettext-minimal)
       ("intltool" ,intltool)
       ("pkg-config" ,pkg-config)))
    (inputs
     `(("enchant" ,enchant)
       ("djvulibre" ,djvulibre)
       ("leptonica" ,leptonica)
       ("podofo" ,podofo)
       ("poppler-qt5" ,poppler-qt5)
       ("sane-backends" ,sane-backends)
       ("qtbase" ,qtbase-5)
       ("qtspell" ,qtspell)
       ("quazip" ,quazip)
       ("tesseract" ,tesseract-ocr)))
    (home-page "https://github.com/manisandro/gImageReader")
    (synopsis "Qt front-end to tesseract-ocr")
    (description
     "gImageReader is a Qt front-end to Tesseract optical character
recognition (OCR) software.

gImageReader supports automatic page layout detection but the user can
also manually define and adjust the recognition regions.  It is
possible to import images from disk, scanning devices, clipboard and
screenshots.  gImageReader also supports multipage PDF documents.
Recognized text is displayed directly next to the image and basic text
editing including search/replace and removing of line breaks is
possible.  Spellchecking for the output text is also supported if the
corresponding dictionaries are installed.")
    (license license:gpl3+)))

(define-public zinnia
  (let* ((commit "581faa8f6f15e4a7b21964be3a5ec36265c80e5b")
         (revision "1")
         ;; version copied from 'configure.in'
         (version (git-version "0.07" revision commit)))
    (package
      (name "zinnia")
      (version version)
      (source
       (origin
         (method git-fetch)
         (uri (git-reference
               (url "https://github.com/taku910/zinnia")
               (commit commit)))
         (sha256
          (base32
           "1izjy5qw6swg0rs2ym2i72zndb90mwrfbd1iv8xbpwckbm4899lg"))
         (file-name (git-file-name name version))
         (modules '((guix build utils)
                    (ice-9 ftw)
                    (srfi srfi-26)))
         (snippet ; remove unnecessary files with potentially different license
          '(begin
             (for-each delete-file-recursively
                       (scandir "."
                                (negate (cut member <> '("zinnia"
                                                         "." "..")))))
             #t))))
      (build-system gnu-build-system)
      (arguments
       `(#:phases
         (modify-phases %standard-phases
           (replace 'bootstrap
             (lambda _
               (chdir "zinnia")
               (for-each make-file-writable
                         '("config.log" "config.status"))
               #t)))))
      (home-page "https://taku910.github.io/zinnia/")
      (synopsis "Online hand recognition system with machine learning")
      (description
       "Zinnia is a simple, customizable and portable online hand recognition
system based on Support Vector Machines.  Zinnia simply receives user pen
strokes as a sequence of coordinate data and outputs n-best characters sorted
by SVM confidence.  To keep portability, Zinnia doesn't have any rendering
functionality.  In addition to recognition, Zinnia provides training module
that allows us to create any hand-written recognition systems with low-cost.")
      (license (list license:bsd-3 ; all files except...
                     (license:non-copyleft ; some autotools related files
                      "file://zinnia/aclocal.m4")
                     license:x11 ; 'install-sh'
                     license:public-domain))))) ; 'install-sh'

;;; python 2 bindings, license under the same terms as zinnia
(define-public python2-zinnia
  (package
    (inherit zinnia)
    (name "python2-zinnia")
    (build-system python-build-system)
    (arguments
     `(#:python ,python-2 ; CObject API is used, it was removed in Python 3.2
       #:tests? #f ; avoid circular dependency on tegaki-zinnia-japanese
       #:phases
       (modify-phases %standard-phases
         (add-after 'unpack 'chdir
           (lambda _
             (chdir "zinnia/python")
             #t)))))
    (inputs
     `(("zinnia" ,zinnia)))))

repo_name: maximed/guix

license: mit


code:
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2014, 2017, 2018 Ludovic Courtès <ludo@gnu.org>
;;; Copyright © 2016 John Darrington <jmd@gnu.org>
;;; Copyright © 2017, 2018 Leo Famulari <leo@famulari.name>
;;; Copyright © 2018, 2021 Tobias Geerinckx-Rice <me@tobias.gr>
;;; Copyright © 2019 Marius Bakke <mbakke@fastmail.com>
;;; Copyright © 2020 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 onc-rpc)
  #:use-module (guix licenses)
  #:use-module (guix packages)
  #:use-module (guix download)
  #:use-module (guix git-download)
  #:use-module (gnu packages)
  #:use-module (gnu packages autotools)
  #:use-module (gnu packages gettext)
  #:use-module (gnu packages kerberos)
  #:use-module (gnu packages pkg-config)
  #:use-module (guix build-system gnu)
  #:use-module (guix utils))

(define-public libtirpc
  (package
    (name "libtirpc")
    (version "1.2.5")
    (source (origin
              (method url-fetch)
              (uri (string-append "mirror://sourceforge/libtirpc/libtirpc/"
                                  version "/libtirpc-"
                                  version ".tar.bz2"))
              (sha256
               (base32
                "1jl6a5kkw2vrp4gb6pmvf72rqimywvwfb9f7iz2xjg4wgq63bdpk"))))
    (build-system gnu-build-system)
    (arguments
     `(#:configure-flags '("--disable-static")
       #:phases
       (modify-phases %standard-phases
         (add-after 'unpack 'remote-dangling-symlink
           (lambda _
             (substitute* '("man/netconfig.5"
                            "man/getnetconfig.3t"
                            "man/getnetpath.3t"
                            "man/rpc.3t"
                            "src/getnetconfig.c"
                            "tirpc/netconfig.h")
               (("/etc/netconfig") (string-append %output "/etc/netconfig")))

             ;; Remove the dangling symlinks since it breaks the
             ;; 'patch-source-shebangs' file tree traversal.
             (delete-file "INSTALL")
             #t)))))
    (inputs `(("mit-krb5" ,mit-krb5)))
    (home-page "https://sourceforge.net/projects/libtirpc/")
    (synopsis "Transport-independent Sun/ONC RPC implementation")
    (description
     "This package provides a library that implements the Sun/ONC RPC (remote
procedure calls) protocol in a transport-independent manner.  It supports both
IPv4 and IPv6.  ONC RPC is notably used by the network file system (NFS).")
    (license bsd-3)))

(define-public libtirpc/hurd
  (package/inherit libtirpc
    (name "libtirpc-hurd")
    (source (origin (inherit (package-source libtirpc))
                    (patches (append (origin-patches (package-source libtirpc))
                                     (search-patches "libtirpc-hurd.patch"
                                                     "libtirpc-hurd-client.patch")))))
    (arguments
     (substitute-keyword-arguments (package-arguments libtirpc)
       ((#:configure-flags flags ''())
        ;; When cross-building the target system's krb5-config should be used.
        `(list (string-append "ac_cv_prog_KRB5_CONFIG="
                              (assoc-ref %build-inputs "mit-krb5")
                              "/bin/krb5-config")))))))

(define-public rpcbind
  (package
    (name "rpcbind")
    (version "1.2.6")
    (source
     (origin
      (method url-fetch)
      (uri (string-append "mirror://sourceforge/" name "/" name "/"
                          version "/"
                          name "-" version ".tar.bz2"))
      (patches (search-patches "rpcbind-CVE-2017-8779.patch"))
      (sha256
       (base32 "1pp8xvprsfz8nlmmvxf829gilx0ibb08bfs3lhisxrfai5j784sn"))))
    (build-system gnu-build-system)
    (arguments
     `(#:configure-flags
       `("--with-systemdsystemunitdir=no" "--enable-warmstarts")))
    (inputs
     `(("libnsl" ,libnsl)
       ("libtirpc" ,libtirpc)))
    (native-inputs
     `(("pkg-config" ,pkg-config)))
    (home-page "http://rpcbind.sourceforge.net/")
    (synopsis "Server to convert RPC program numbers into universal addresses")
    (description
     "@command{Rpcbind} is a server that converts RPC program numbers into
universal addresses.")
    (license bsd-3)))

(define-public rpcsvc-proto
  (package
    (name "rpcsvc-proto")
    (version "1.4")
    (home-page "https://github.com/thkukuk/rpcsvc-proto")
    (source (origin
              (method url-fetch)
              (uri (string-append home-page "/releases/download/v" version
                                  "/rpcsvc-proto-" version ".tar.xz"))
              (sha256
               (base32
                "0i93wbpw5dk2gf5v4a5hq6frh814wzgjydh7saj28wlgbpqdaja1"))))
    (build-system gnu-build-system)
    (synopsis "RPCSVC protocol definitions")
    (description
     "This package provides @code{rpcsvc} @file{protocol.x} files and headers
that are not included with the @code{libtirpc} package.  Additionally it
contains @command{rpcgen}, which is used to produce header files and sources
from the protocol files.")
    (license bsd-3)))

(define-public libnsl
  (package
    (name "libnsl")
    (version "1.3.0")
    (source (origin
              (method git-fetch)
              (uri (git-reference
                    (url "https://github.com/thkukuk/libnsl")
                    (commit (string-append "v" version))))
              (file-name (git-file-name name version))
              (sha256
               (base32
                "1dayj5i4bh65gn7zkciacnwv2a0ghm6nn58d78rsi4zby4lyj5w5"))))
    (build-system gnu-build-system)
    (arguments
     `(#:configure-flags '("--disable-static")))
    (native-inputs
     `(("autoconf" ,autoconf)
       ("automake" ,automake)
       ("gettext" ,gettext-minimal)
       ("libtool" ,libtool)
       ("pkg-config" ,pkg-config)))
    (inputs
     `(("libtirpc" ,libtirpc)))
    (synopsis "Public client interface for NIS(YP) and NIS+")
    (description "Libnsl is the public client interface for the Network
Information Service / Yellow Pages (NIS/YP) and NIS+.  It includes IPv6 support.
This library was part of glibc < 2.26, but is now distributed separately.")
    (home-page "https://github.com/thkukuk/libnsl")
    ;; The package is distributed under the LGPL 2.1. Some files in
    ;; 'src/nisplus/' are LGPL 2.1+, and some files in 'src/rpcsvc/' are BSD-3.
    (license lgpl2.1)))


code:
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2014 Julien Lepiller <julien@lepiller.eu>
;;; Copyright © 2016 Efraim Flashner <efraim@flashner.co.il>
;;; Copyright © 2017 Nikita <nikita@n0.is>
;;;
;;; 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 openbox)
  #:use-module ((guix licenses) #:select (gpl2+))
  #:use-module (guix packages)
  #:use-module (guix download)
  #:use-module (guix build-system gnu)
  #:use-module (gnu packages freedesktop)
  #:use-module (gnu packages gettext)
  #:use-module (gnu packages gnome)
  #:use-module (gnu packages gtk)
  #:use-module (gnu packages image)
  #:use-module (gnu packages pkg-config)
  #:use-module (gnu packages python)
  #:use-module (gnu packages xdisorg)
  #:use-module (gnu packages xml)
  #:use-module (gnu packages xorg))

(define-public openbox
  (package
    (name "openbox")
    (version "3.6.1")
    (source (origin
              (method url-fetch)
              (uri (string-append
                    "http://openbox.org/dist/openbox/" name "-"
                    version ".tar.xz"))
              (sha256
               (base32
                "0vg2y1qddsdxkjv806mzpvmkgzliab8ll4s7zm7ma5jnriamirxb"))))
    (build-system gnu-build-system)
    (native-inputs `(("pkg-config" ,pkg-config)))
    (propagated-inputs `(("python2-pyxdg" ,python2-pyxdg)))
    (inputs `(("imlib2" ,imlib2)
              ("libxml2" ,libxml2)
              ("librsvg" ,librsvg)
              ("libsm" ,libsm)
              ("libxcursor" ,libxcursor)
              ("libxinerama" ,libxinerama)
              ("libxml2" ,libxml2)
              ("libxrandr" ,libxrandr)
              ("libxft" ,libxft)
              ("pango" ,pango)
              ("python-2" ,python-2)))
    (synopsis "Box style window manager")
    (description
     "Openbox is a highly configurable, next generation window manager with
extensive standards support.  The *box visual style is well known for its
minimalistic appearance.  Openbox uses the *box visual style, while providing
a greater number of options for theme developers than previous *box
implementations.")
    (home-page "http://openbox.org/wiki/Main_Page")
    (license gpl2+)))

(define-public obconf
  (package
    (name "obconf")
    (version "2.0.4")
    (source
     (origin
       (method url-fetch)
       (uri (string-append "http://openbox.org/dist/" name
                           "/" name "-" version ".tar.gz"))
       (sha256
        (base32
         "1fanjdmd8727kk74x5404vi8v7s4kpq48l583d12fsi4xvsfb8vi"))))
    (inputs
     `(("gtk+-2" ,gtk+-2)
       ("imlib2" ,imlib2)
       ("libglade" ,libglade)
       ("openbox" ,openbox)
       ("startup-notification" ,startup-notification)
       ("libsm" ,libsm)
       ("librsvg" ,librsvg)
       ("libxft" ,libxft)))
    (native-inputs
     `(("gettext" ,gettext-minimal)
       ("pkg-config" ,pkg-config)))
    (build-system gnu-build-system)
    (arguments
     `(#:configure-flags (list "--enable-nls")))
    (home-page "http://openbox.org/wiki/ObConf:About")
    (synopsis "Openbox configuration tool")
    (description
     "Obconf is a tool for configuring the Openbox window manager.
You can configure its appearance, themes, and much more.")
    (license gpl2+)))

;;; openbox.scm ends here


code:
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2018 Fis Trivial <ybbs.daans@hotmail.com>
;;; Copyright © 2018, 2020 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 opencl)
  #:use-module (guix build-system gnu)
  #:use-module (guix build-system cmake)
  #:use-module (guix build-system copy)
  #:use-module (guix build-system python)
  #:use-module (guix download)
  #:use-module (guix git-download)
  #:use-module ((guix licenses) #:prefix license:)
  #:use-module (guix packages)
  #:use-module (gnu packages)
  #:use-module (gnu packages autotools)
  #:use-module (gnu packages gl)
  #:use-module (gnu packages gnupg)
  #:use-module (gnu packages compression)
  #:use-module (gnu packages libedit)
  #:use-module (gnu packages llvm)
  #:use-module (gnu packages mpi)
  #: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 ruby)
  #:use-module (gnu packages video)
  #:use-module (gnu packages xdisorg)
  #:use-module (gnu packages xorg))

;; This file adds OpenCL implementation related packages. Due to the fact that
;; OpenCL devices like GPU are not available during build (store environment),
;; tests that require such devices are all disabled.
;; Check https://lists.gnu.org/archive/html/guix-devel/2018-04/msg00293.html

(define-public opencl-headers
  (package
    (name "opencl-headers")
    (version "2020.12.18")
    (source
      (origin
        (method git-fetch)
        (uri (git-reference
              (url "https://github.com/KhronosGroup/OpenCL-Headers")
              (commit (string-append "v" version))))
        (file-name (git-file-name name version))
        (sha256
         (base32 "1zslxfzvbb1mrzmsik4pjzj88ds8y3p94ry5nnrnkhv6qm4n4lw9"))))
    (build-system copy-build-system)
    (arguments
     '(#:install-plan
       '(("CL" "include/")))) ; TODO: add phase for tests
    (synopsis "The Khronos OpenCL headers")
    (description
     "This package provides the C headers by Khronos for OpenCL programming.")
    (home-page "https://www.khronos.org/registry/OpenCL/")
    (license license:asl2.0)))

(define (make-opencl-headers major-version subversion)
  ;; The upstream OpenCL-Headers repository is no longer separating headers by
  ;; version; instead, you are supposed to #define CL_TARGET_OPENCL_VERSION.
  (deprecated-package (string-append "opencl-headers-"
                                     major-version "."
                                     subversion) opencl-headers))

(define-public opencl-headers-2.2
  (make-opencl-headers "2" "2"))
(define-public opencl-headers-2.1
  (make-opencl-headers "2" "1"))
(define-public opencl-headers-2.0
  (make-opencl-headers "2" "0"))
(define-public opencl-headers-1.2
  (make-opencl-headers "1" "2"))
(define-public opencl-headers-1.1
  (make-opencl-headers "1" "1"))
(define-public opencl-headers-1.0
  (make-opencl-headers "1" "0"))

(define-public opencl-clhpp
  (package
    (name "opencl-clhpp")
    (version "2.0.10")
    (source
     (origin
       (method git-fetch)
       (uri (git-reference
             (url "https://github.com/KhronosGroup/OpenCL-CLHPP")
             (commit (string-append "v" version))))
       (sha256
        (base32 "0h5kpg5cl8wzfnqmv6i26aig2apv06ffm9p3rh35938n9r8rladm"))
       (file-name (git-file-name name version))))
    (native-inputs
     `(("python" ,python-wrapper)))
    (propagated-inputs
     `(("opencl-headers" ,opencl-headers)))
    (arguments
     `(#:configure-flags
       (let ((out (assoc-ref %outputs "out")))
         (list
          "-DBUILD_EXAMPLES=OFF"
          "-DBUILD_TESTS=OFF"
          (string-append "-DCMAKE_INSTALL_PREFIX="
                         (assoc-ref %outputs "out")
                         "/include")))
       ;; The regression tests require a lot more dependencies.
       #:tests? #f))
    (build-system cmake-build-system)
    (home-page "https://github.khronos.org/OpenCL-CLHPP/")
    (synopsis "Khronos OpenCL-CLHPP")
    (description
     "This package provides the @dfn{host API} C++ headers for OpenCL.")
    (license license:expat)))

(define-public ocl-icd
  (package
    (name "ocl-icd")
    (version "2.2.12")
    (source (origin
              (method url-fetch)
              (uri (string-append
                    "https://forge.imag.fr/frs/download.php/836/ocl-icd-"
                    version ".tar.gz"))
              (file-name (string-append name "-" version ".tar.gz"))
              (sha256
               (base32
                "1x2dr8p4dkfds56r38av360i3nv1y3326jmshxvjngaf6mlg6rbn"))
              (modules '((guix build utils)))
              (snippet
               '(delete-file-recursively "khronos-headers"))))
    (native-inputs
     `(("opencl-headers" ,opencl-headers)
       ("ruby" ,ruby)))
    (inputs
     `(("libgcrypt" ,libgcrypt)))
    (build-system gnu-build-system)
    (arguments
     '(#:configure-flags '("DEBUG_OCL_ICD=1")))
    (native-search-paths
     (list (search-path-specification
            (variable "OPENCL_VENDOR_PATH")
            (files '("etc/OpenCL/vendors")))))
    (search-paths native-search-paths)
    (home-page "https://forge.imag.fr/projects/ocl-icd/")
    (synopsis "OpenCL loader for Installable Client Drivers (ICDs)")
    (description
     "OpenCL implementations are provided as ICDs (Installable Client
Drivers).  An OpenCL program can use several ICDs thanks to the use of an ICD
Loader as provided by this package.")
    (license license:bsd-2)))

(define-public clinfo
  (package
    (name "clinfo")
    (version "2.2.18.04.06")
    (source
     (origin
       (method git-fetch)
       (uri (git-reference
             (url "https://github.com/Oblomov/clinfo")
             (commit version)))
       (file-name (git-file-name name version))
       (sha256
        (base32 "0y2q0lz5yzxy970b7w7340vp4fl25vndahsyvvrywcrn51ipgplx"))))
    (build-system gnu-build-system)
    (native-inputs
     `(("opencl-headers" ,opencl-headers)))
    (inputs
     `(("ocl-icd" ,ocl-icd)))
    (arguments
     `(#:phases
       (modify-phases %standard-phases
         (delete 'configure)
         (replace 'build
           (lambda _
             (let ((cores (number->string (parallel-job-count))))
               (setenv "CC" "gcc")
               (invoke "make" "-j" cores))))
         (replace 'install
           (lambda* (#:key outputs #:allow-other-keys)
             (invoke "make" "install" (string-append
                                       "PREFIX="
                                       (assoc-ref outputs "out"))))))
       #:tests? #f))
    (home-page "https://github.com/Oblomov/clinfo")
    (synopsis "Print information about OpenCL platforms and devices")
    ;; Only the implementation installed via Guix will be detected.
    (description
     "This package provides the @command{clinfo} command that enumerates all
possible (known) properties of the OpenCL platform and devices available on
the system.")
    (license license:cc0)))

(define-public beignet
  (package
    (name "beignet")
    (version "1.3.2")
    (source
     (origin
       (method git-fetch)
       (uri (git-reference
             (url "https://github.com/intel/beignet")
             (commit (string-append "Release_v" version))))
       (file-name (git-file-name name version))
       (sha256
        (base32 "0lpv3lvi2vrmzb8blflrpbd3jgin76zqmz6jcv17vn9mylqdrfnd"))
       (patches (search-patches "beignet-correct-file-names.patch"))
       (modules '((guix build utils)))
       (snippet
        ;; There's a suspicious .isa binary file under kernels/.
        ;; Remove it.
        '(for-each delete-file (find-files "." "\\.isa$")))))
    (native-inputs `(("pkg-config" ,pkg-config)
                     ("python" ,python)))
    (inputs `(("clang@3.7" ,clang-3.7)
              ("clang-runtime@3.7" ,clang-runtime-3.7)
              ("glu" ,glu)
              ("llvm@3.7" ,llvm-3.7)
              ("libdrm" ,libdrm)
              ("libedit" ,libedit)
              ("libpthread-stubs" ,libpthread-stubs)
              ("libsm" ,libsm)
              ("libva" ,libva)
              ("libxfixes" ,libxfixes)
              ("libxext" ,libxext)
              ("mesa-utils" ,mesa-utils)
              ("ncurses" ,ncurses)
              ("ocl-icd" ,ocl-icd)
              ("opencl-headers" ,opencl-headers)
              ("xextproto" ,xextproto)
              ("zlib" ,zlib)))
    (build-system cmake-build-system)
    (arguments
     `(#:configure-flags
       (list (string-append "-DCLANG_LIBRARY_DIR="
                            (assoc-ref %build-inputs "clang@3.7") "/lib")
             "-DENABLE_GL_SHARING=ON"
             "-DEXPERIMENTAL_DOUBLE=ON")

       #:phases
       (modify-phases %standard-phases
         (add-after 'install 'remove-headers
           (lambda* (#:key outputs #:allow-other-keys)
             (let ((out (assoc-ref outputs "out")))
               (delete-file-recursively
                (string-append out "/include"))
               #t)))
         (add-after 'remove-headers 'install-kernels
           (lambda* (#:key outputs #:allow-other-keys)
             (let* ((out (assoc-ref outputs "out"))
                    (builddir (getcwd))
                    (source-dir (string-append
                                 builddir
                                 "/../beignet-Release_v1.3.2/kernels")))
               (copy-recursively source-dir
                                 (string-append out "/lib/beignet/kernels"))
               #t))))
       ;; Beignet tries to find GPU when running tests, which is not available
       ;; during build.
       #:tests? #f))
    (home-page "https://wiki.freedesktop.org/www/Software/Beignet/")
    (synopsis "OpenCL framework for Intel GPUs")
    (description
     "Beignet is an implementation of the OpenCL specification.  This code
base contains the code to run OpenCL programs on Intel GPUs---IvyBridge,
Haswell, Skylake, Apollolake, etc.  It defines and implements the OpenCL host
functions required to initialize the device, create the command queues, the
kernels and the programs, and run them on the GPU.  The code also contains a
back-end for the LLVM compiler framework.")
    ;; Beignet only supports Intel processors.
    (supported-systems '("x86_64-linux" "i686-linux"))
    (license license:lgpl2.1+)))

(define-public pocl
  (package
    (name "pocl")
    (version "1.4")
    (source
     (origin
       (method git-fetch)
       (uri (git-reference
             (url "https://github.com/pocl/pocl")
             (commit (string-append "v" version))))
       (sha256
        (base32 "1c4y69zks6hkq5fqh9waxgb8g4ka7y6h3vacmsm720kba0h57g8a"))
       (file-name (git-file-name name version))))
    (build-system cmake-build-system)
    (native-inputs
     `(("libltdl" ,libltdl)
       ("pkg-config" ,pkg-config)))
    (inputs
     `(("clang" ,clang)
       ("hwloc" ,hwloc-2 "lib")
       ("llvm" ,llvm)
       ("ocl-icd" ,ocl-icd)))
    (arguments
     `(#:configure-flags
       (list "-DENABLE_ICD=ON"
             "-DENABLE_TESTSUITES=ON"
             ;; We are not developers, don't run conformance suite.
             "-DENABLE_CONFORMANCE=OFF"
             (string-append "-DEXTRA_HOST_LD_FLAGS=-L"
                            (assoc-ref %build-inputs "libc") "/lib"))
       #:phases
       (modify-phases %standard-phases
         (add-before 'check 'set-HOME
           (lambda _
             (setenv "HOME" "/tmp")
             #t)))))
    (home-page "http://portablecl.org/")
    (synopsis "Portable Computing Language (pocl), an OpenCL implementation")
    (description
     "Pocl is a portable implementation of the OpenCL standard (1.2 with some
2.0 features supported).  This project seeks to improve performance
portability of OpenCL programs with the kernel compiler and the task run-time,
reducing the need for target-dependent manual optimizations.

pocl uses Clang as an OpenCL C frontend and LLVM for kernel compiler
implementation, and as a portability layer.  Thus, if your desired target has
an LLVM backend, it should be able to get OpenCL support easily by using
pocl.")
    (license license:expat)))

(define-public python-pytools
  (package
    (name "python-pytools")
    (version "2020.4")
    (source
     (origin
       (method url-fetch)
       (uri (pypi-uri "pytools" version))
       (sha256
        (base32 "0q7439iy365a874ckpavx6h1mhnnngfy8nl7xj5grdd127zkknrp"))))
    (build-system python-build-system)
    (propagated-inputs
     `(("python-appdirs" ,python-appdirs)
       ("python-decorator" ,python-decorator)
       ("python-numpy" ,python-numpy)
       ("python-six" ,python-six)
       ("python-mpi4py" ,python-mpi4py)))
    (home-page "https://pypi.org/project/pytools/")
    (synopsis "Assorted tools for Python")
    (description
     "Pytools is a bag of things that are ``missing'' from the Python standard
library:

@itemize
@item
small helper functions such as @code{len_iterable}, @code{argmin},
tuple generation, permutation generation, ASCII table pretty printing,
GvR's @code{monkeypatch_xxx} hack, the elusive @code{flatten}, and much more.
@item
Michele Simionato's decorator module
@item
A time-series logging module, @code{pytools.log}.
@item
Batch job submission, @code{pytools.batchjob}.
@item
A lexer, @code{pytools.lex}.
@end itemize\n")
    (license license:expat)))

(define-public python-pyopencl
  (package
    (name "python-pyopencl")
    (version "2019.1.1")
    (source
     (origin
       ;; The tarball on PyPI lacks test programs such as
       ;; 'pygpu_language_opencl.cpp' so fetch it from Git.
       ;; XXX: The server at git.tiker.net is unreliable.
       (method git-fetch)
       (uri (git-reference
             (url "http://git.tiker.net/trees/pyopencl.git")
             (commit (string-append "v" version))
             (recursive? #t)))
       (file-name (git-file-name name version))
       (sha256
        (base32
         "12q0rs8yla571vcfpsh0mfrjbdiayv0hi8r1rq0f178m3i3qjz80"))))
    (build-system python-build-system)
    (arguments
     '(#:phases (modify-phases %standard-phases
                  (add-before 'build 'set-home
                    (lambda _
                      ;; Some of the Python build scripts expect 'HOME' to be
                      ;; set.
                      (setenv "HOME" (getcwd))
                      #t)))

       ;; Tests in 'compyte/ndarray/setup_opencl.py' appear to rely on
       ;; 'nvcc', which is not an option.
       #:tests? #f))
    (inputs
     `(("opencl-headers" ,opencl-headers-1.2)   ;POCL only supports OpenCL 1.2
       ("pybind11" ,pybind11)
       ("ocl-icd" ,ocl-icd)))                     ;libOpenCL
    (propagated-inputs
     `(("python-appdirs" ,python-appdirs)
       ("python-decorator" ,python-decorator)
       ("python-numpy" ,python-numpy)
       ("python-pytools" ,python-pytools)
       ("python-six" ,python-six)
       ("python-mako" ,python-mako)))
    (home-page "http://mathema.tician.de/software/pyopencl")
    (synopsis "Python wrapper for OpenCL")
    (description
     "PyOpenCL lets you access parallel computing devices such as GPUs from
Python @i{via} OpenCL.")
    (license license:expat)))


code:
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2020 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 opencog)
  #:use-module (gnu packages)
  #:use-module (gnu packages boost)
  #:use-module (gnu packages check)
  #:use-module (gnu packages databases)
  #:use-module (gnu packages guile)
  #:use-module (gnu packages language)
  #:use-module (gnu packages linux)
  #:use-module (gnu packages multiprecision)
  #:use-module (gnu packages pkg-config)
  #:use-module (gnu packages python)
  #:use-module ((guix licenses) #:prefix license:)
  #:use-module (guix packages)
  #:use-module (guix git-download)
  #:use-module (guix build-system cmake)
  #:use-module (guix utils))

(define-public cogutil
  ;; The last release was in 2016.  Other OpenCog packages require a later
  ;; version.
  (let ((commit "b07b41b2eaf01627c78b27f1f28bb09ef7086f8e")
        (revision "1"))
    (package
      (name "cogutil")
      (version (git-version "2.0.3" revision commit))
      (source (origin
                (method git-fetch)
                (uri (git-reference
                      (url "https://github.com/opencog/cogutil")
                      (commit commit)))
                (file-name (git-file-name name version))
                (sha256
                 (base32
                  "1ymmcrinp0prlxsmxmwdjjl4kgaj7wzq39d5b1q2apgg94yfdhqb"))))
      (build-system cmake-build-system)
      (arguments
       `(#:test-target "tests"))
      (inputs
       `(("boost" ,boost)))
      (native-inputs
       `(("cxxtest" ,cxxtest)
         ("python" ,python-minimal)
         ("pkg-config" ,pkg-config)))
      (home-page "https://github.com/opencog/cogutil/")
      (synopsis "Low-level C++ programming utilities used by OpenCog components")
      (description "The OpenCog utilities is a miscellaneous collection of C++
utilities use for typical programming tasks in multiple OpenCog projects.")
      ;; Either of these licenses.
      (license (list license:agpl3 license:asl2.0)))))

(define-public atomspace
  ;; The last release was in 2016 and doesn't build with our Boost package.
  (let ((commit "86c848dfc7135b3c47deb581f8da54a60f6711c9")
        (revision "1"))
    (package
      (name "atomspace")
      (version (git-version "5.0.3" revision commit))
      (source (origin
                (method git-fetch)
                (uri (git-reference
                      (url "https://github.com/opencog/atomspace")
                      (commit commit)))
                (file-name (git-file-name name version))
                (sha256
                 (base32
                  "0vxzhszb0z8081li38hid07a5axzxyflsmq1mcn4b1k4z1j8ggch"))))
      (build-system cmake-build-system)
      (arguments
       `(#:test-target "tests"
         #:configure-flags
         (list (string-append "-DGUILE_INCLUDE_DIR="
                              (assoc-ref %build-inputs "guile")
                              "/include/guile/2.2/")
               (string-append "-DGUILE_SITE_DIR="
                              (assoc-ref %outputs "out")
                              "/share/guile/site/2.2/"))))
      (inputs
       `(("boost" ,boost)
         ("cogutil" ,cogutil)
         ("gmp" ,gmp)
         ("guile" ,guile-2.2)
         ("postgresql" ,postgresql)))
      (native-inputs
       `(("cxxtest" ,cxxtest)
         ("python" ,python-minimal)
         ("pkg-config" ,pkg-config)))
      (home-page "https://github.com/opencog/atomspace/")
      (synopsis "OpenCog hypergraph database, query system and rule engine")
      (description "The OpenCog AtomSpace is an in-RAM @dfn{knowledge
representation} (KR) database, an associated query engine and graph-re-writing
system, and a rule-driven inferencing engine that can apply and manipulate
sequences of rules to perform reasoning.  It is a layer that sits on top of
ordinary distributed (graph) databases, providing a large variety of advanced
features not otherwise available.")
      (license license:agpl3))))

(define-public cogserver
  ;; There are no releases.
  (let ((commit "ec5f3b9590db0f6a085b5d0320f5d3710e0f1635")
        (revision "2"))
    (package
      (name "cogserver")
      (version (git-version "0" revision commit))
      (source (origin
                (method git-fetch)
                (uri (git-reference
                      (url "https://github.com/opencog/cogserver")
                      (commit commit)))
                (file-name (git-file-name name version))
                (sha256
                 (base32
                  "1h0vcxb6n5dc654xqinqcxc7dxwcs6bsywgir8rhrqiykk760mzl"))))
      (build-system cmake-build-system)
      (arguments
       `(#:test-target "tests"
         #:configure-flags
         (list (string-append "-DGUILE_INCLUDE_DIR="
                              (assoc-ref %build-inputs "guile")
                              "/include/guile/2.2/")
               (string-append "-DGUILE_SITE_DIR="
                              (assoc-ref %outputs "out")
                              "/share/guile/site/2.2/"))))
      (inputs
       `(("atomspace" ,atomspace)
         ("boost" ,boost)
         ("cogutil" ,cogutil)
         ("gmp" ,gmp)
         ("guile" ,guile-2.2)))
      (native-inputs
       `(("cxxtest" ,cxxtest)
         ("python" ,python-minimal)
         ("pkg-config" ,pkg-config)))
      (home-page "https://github.com/opencog/cogserver/")
      (synopsis "OpenCog network server")
      (description "The OpenCog Cogserver is a network and job server for the
OpenCog framework.")
      (license license:agpl3))))

(define-public attention
  ;; There are no releases.
  (let ((commit "87d43679280ce486cd6757765d2e1df6d502991d")
        (revision "1"))
    (package
      (name "attention")
      (version (git-version "0" revision commit))
      (source (origin
                (method git-fetch)
                (uri (git-reference
                      (url "https://github.com/opencog/attention")
                      (commit commit)))
                (file-name (git-file-name name version))
                (sha256
                 (base32
                  "0sndslphicv6w9qpag168rqkxq5sf71l5qbfx6zhsd5bzlf5fhwv"))))
      (build-system cmake-build-system)
      (arguments
       `(#:test-target "tests"
         #:configure-flags
         (list
          (string-append "-DGUILE_INCLUDE_DIR="
                         (assoc-ref %build-inputs "guile")
                         "/include/guile/2.2/")
          (string-append "-DGUILE_SITE_DIR="
                         (assoc-ref %outputs "out")
                         "/share/guile/site/2.2/"))))
      (inputs
       `(("atomspace" ,atomspace)
         ("boost" ,boost)
         ("cogserver" ,cogserver)
         ("cogutil" ,cogutil)
         ("gmp" ,gmp)
         ("guile" ,guile-2.2)))
      (native-inputs
       `(("cxxtest" ,cxxtest)
         ("python" ,python-minimal)
         ("pkg-config" ,pkg-config)))
      (home-page "https://github.com/opencog/attention/")
      (synopsis "OpenCog attention allocation subsystem")
      (description "Attention Allocation is an OpenCog subsystem meant to
control the application of processing and memory resources to specific
tasks.")
      (license license:agpl3))))

(define-public opencog
  ;; There are no recent releases.
  (let ((commit "ceac90507610cb2d0ee98f97a2086865292b1204")
        (revision "1"))
    (package
      (name "opencog")
      (version (git-version "0.1.4" revision commit))
      (source (origin
                (method git-fetch)
                (uri (git-reference
                      (url "https://github.com/opencog/opencog")
                      (commit commit)))
                (file-name (git-file-name name version))
                (sha256
                 (base32
                  "1j8wv910fvrmph370wv5pv2f4bc2s9vl6i7bw3pkmwbdhxkhjbhm"))))
      (build-system cmake-build-system)
      (arguments
       `(#:test-target "tests"
         #:configure-flags
         (list
          (string-append "-DGUILE_INCLUDE_DIR="
                         (assoc-ref %build-inputs "guile")
                         "/include/guile/2.2/")
          (string-append "-DGUILE_SITE_DIR="
                         (assoc-ref %outputs "out")
                         "/share/guile/site/2.2/"))))
      (inputs
       `(("attention" ,attention)
         ("atomspace" ,atomspace)
         ("boost" ,boost)
         ("cogserver" ,cogserver)
         ("cogutil" ,cogutil)
         ("gmp" ,gmp)
         ("guile" ,guile-2.2)
         ("libuuid" ,util-linux "lib")
         ("link-grammar" ,link-grammar)))
      (native-inputs
       `(("cxxtest" ,cxxtest)
         ("python" ,python-minimal)
         ("pkg-config" ,pkg-config)))
      (home-page "https://github.com/opencog/attention/")
      (synopsis "Framework for integrated artificial intelligence")
      (description "OpenCog is a framework for developing AI systems,
especially appropriate for integrative multi-algorithm systems, and artificial
general intelligence systems.  It currently contains a functional core
framework, and a number of cognitive agents at varying levels of completion,
some already displaying interesting and useful functionalities alone and in
combination.")
      (license license:agpl3))))

(define-public agi-bio
  ;; There are no releases.
  (let ((commit "b5c6f3d99e8cca3798bf0cdf2c32f4bdb8098efb")
        (revision "1"))
    (package
      (name "agi-bio")
      (version (git-version "0" revision commit))
      (source (origin
                (method git-fetch)
                (uri (git-reference
                      (url "https://github.com/opencog/agi-bio")
                      (commit commit)))
                (file-name (git-file-name name version))
                (sha256
                 (base32
                  "0c3q0nhmd03nvqm1ih10y28n596cjvfhkcfvzw2fmz1sn3ywdah4"))))
      (build-system cmake-build-system)
      (arguments
       `(#:tests? #f ; there are none
         #:configure-flags
         (list
          (string-append "-DGUILE_INCLUDE_DIR="
                         (assoc-ref %build-inputs "guile")
                         "/include/guile/2.2/")
          (string-append "-DGUILE_SITE_DIR="
                         (assoc-ref %outputs "out")
                         "/share/guile/site/2.2/"))
         #:phases
         (modify-phases %standard-phases
           (add-after 'unpack 'fix-unqualified-load
             (lambda* (#:key outputs #:allow-other-keys)
               (substitute* "bioscience/bioscience.scm"
                 (("\\(load \"bioscience/types/bioscience_types.scm\"\\)")
                  (format #f "(load \"~a/bioscience/types/bioscience_types.scm\")"
                          (string-append (assoc-ref outputs "out")
                                         "/share/guile/site/2.2/opencog"))))
               #t)))))
      (inputs
       `(("atomspace" ,atomspace)
         ("cogutil" ,cogutil)
         ("gmp" ,gmp)
         ("guile" ,guile-2.2)))
      (native-inputs
       `(("cxxtest" ,cxxtest)
         ("python" ,python-minimal)
         ("pkg-config" ,pkg-config)))
      (home-page "https://github.com/opencog/agi-bio")
      (synopsis "Genomic and proteomic data exploration and pattern mining")
      (description "This is a package for genomic and proteomic research using
the OpenCog toolset with Guile.  This includes experiments in applying pattern
mining and other OpenCog components.")
      (license license:agpl3))))


code:
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2020 Ekaitz Zarraga <ekaitz@elenq.tech>
;;; Copyright © 2021 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 openkinect)
  #:use-module (guix packages)
  #:use-module (guix git-download)
  #:use-module (guix build-system cmake)
  #:use-module ((guix licenses) #:prefix license:)
  #:use-module (gnu packages pkg-config)
  #:use-module (gnu packages libusb)
  #:use-module (gnu packages python)
  #:use-module (gnu packages python-xyz)
  #:use-module (gnu packages gl)
  #:use-module (gnu packages pkg-config)
  #:use-module (gnu packages image-processing))

(define-public libfreenect
  (let ((version "0.6.2"))
    (package
      (name "libfreenect")
      (version version)
      (source (origin
                (method git-fetch)
                (uri (git-reference
                      (url "https://github.com/OpenKinect/libfreenect")
                      (commit (string-append "v" version))))
                (file-name (git-file-name name version))
                (sha256
                 (base32
                  "02pb8mcl62kzdcgbnv3rw4nl0f08iw8pjiqqhfy3ycpkvyppw97w"))))
      (build-system cmake-build-system)
      (arguments
       '(#:tests? #f                    ; package has no tests
         #:configure-flags
         '("-DBUILD_FAKENECT=ON"
           "-DBUILD_CPP=ON"
           "-DBUILD_EXAMPLES=OFF"       ; available in libfreenect-examples
           "-DBUILD_CV=OFF"             ; available in libfreenect-cv
           "-DBUILD_PYTHON=OFF"         ; available in python-libfreenect
           "-DBUILD_C_SYNC=ON")
         #:phases
         (modify-phases %standard-phases
           (add-after 'install 'install-udev-rules
             (lambda* (#:key outputs #:allow-other-keys)
               (let* ((out (assoc-ref outputs "out"))
                      (rules-out (string-append out "/lib/udev/rules.d")))
                 (install-file "../source/platform/linux/udev/51-kinect.rules"
                               (string-append rules-out "51-kinect.rules"))
                 #t))))))
      (native-inputs
       `(("pkg-config" ,pkg-config)))
      (inputs
       `(("libusb" ,libusb)))
      (synopsis "Drivers and libraries for the Xbox Kinect device")
      (description "libfreenect is a userspace driver for the Microsoft Kinect.
It supports: RGB and Depth Images, Motors, Accelerometer, LED and Audio.")
      (home-page "https://openkinect.org/")
      (license license:gpl2+))))

;; Library are already compiled in libfreenect, avoid build it again.
(define libfreenect-derived-phases
  '(modify-phases %standard-phases
     (add-after 'unpack 'patch-CMakeLists.txt
       (lambda* (#:key outputs #:allow-other-keys)
         (substitute* "CMakeLists.txt"
           ((".*libusb.*") "")
           (("add_subdirectory \\(src\\)") "")
           ((".*libfreenectConfig.cmake.*") ""))
         #t))))

(define-public libfreenect-examples
  (package
    (inherit libfreenect)
    (name "libfreenect-examples")
    (inputs
     `(("libfreenect" ,libfreenect)
       ("glut" ,freeglut)))
    (arguments
     `(#:tests? #f                      ; package has no tests
       #:configure-flags '("-DBUILD_EXAMPLES=ON"
                           "-DBUILD_FAKENECT=OFF"
                           "-DBUILD_CPP=OFF"
                           "-DBUILD_C_SYNC=OFF"
                           "-DBUILD_CV=OFF")
       #:phases ,libfreenect-derived-phases))
    (synopsis "Examples for libfreenect, the Xbox Kinect device library")))

(define-public libfreenect-opencv
  (package
    (inherit libfreenect)
    (name "libfreenect-opencv")
    (inputs
     `(("libfreenect" ,libfreenect)
       ("opencv" ,opencv)))
    (arguments
     `(#:tests? #f                      ; package has no tests
       #:configure-flags '("-DBUILD_EXAMPLES=OFF"
                           "-DBUILD_FAKENECT=OFF"
                           "-DBUILD_CPP=OFF"
                           "-DBUILD_C_SYNC=OFF"
                           "-DBUILD_CV=ON")
       #:phases ,libfreenect-derived-phases))
    (synopsis "OpenCV wrapper for libfreenect, the Xbox Kinect device
library")))

(define-public python-libfreenect
  (package
    (inherit libfreenect)
    (name "python-libfreenect")
    (native-inputs
     `(("python-cython" ,python-cython)))
    (inputs
     `(("libfreenect" ,libfreenect)))
    (propagated-inputs
     `(("python" ,python)
       ("python-numpy" ,python-numpy)))
    (arguments
     `(#:tests? #f                      ; package has no tests
       #:configure-flags '("-DBUILD_EXAMPLES=OFF"
                           "-DBUILD_FAKENECT=OFF"
                           "-DBUILD_CPP=OFF"
                           "-DBUILD_C_SYNC=OFF"
                           "-DBUILD_CV=OFF"
                           "-DBUILD_PYTHON3=ON")
       #:phases ,libfreenect-derived-phases))
    (synopsis "Python wrapper for libfreenect, the Xbox Kinect device
library")))


code:
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2013, 2014, 2015, 2019, 2020 Ludovic Courtès <ludo@gnu.org>
;;; Copyright © 2013 Andreas Enge <andreas@enge.fr>
;;; Copyright © 2016, 2021 Leo Famulari <leo@famulari.name>
;;; Copyright © 2017, 2018, 2019 Ricardo Wurmus <rekado@elephly.net>
;;; Copyright © 2018 Tobias Geerinckx-Rice <me@tobias.gr>
;;; Copyright © 2019 Mathieu Othacehe <m.othacehe@gmail.com>
;;; Copyright © 2020 Lars-Dominik Braun <ldb@leibniz-psychology.org>
;;; 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 openldap)
  #:use-module (gnu packages autotools)
  #:use-module (gnu packages check)
  #:use-module (gnu packages compression)
  #:use-module (gnu packages cyrus-sasl)
  #:use-module (gnu packages dbm)
  #:use-module (gnu packages documentation)
  #:use-module (gnu packages gettext)
  #:use-module (gnu packages gnupg)
  #:use-module (gnu packages groff)
  #:use-module (gnu packages icu4c)
  #:use-module (gnu packages kerberos)
  #:use-module (gnu packages libevent)
  #:use-module (gnu packages linux)
  #:use-module (gnu packages networking)
  #:use-module (gnu packages nss)
  #:use-module (gnu packages password-utils)
  #:use-module (gnu packages pcre)
  #:use-module (gnu packages perl)
  #:use-module (gnu packages pkg-config)
  #:use-module (gnu packages python)
  #:use-module (gnu packages python-xyz)
  #:use-module (gnu packages rsync)
  #:use-module (gnu packages selinux)
  #:use-module (gnu packages time)
  #:use-module (gnu packages tls)
  #:use-module (gnu packages web)
  #:use-module (gnu packages)
  #:use-module ((guix licenses) #:select (openldap2.8 lgpl2.1+ gpl3+ psfl expat))
  #:use-module (guix packages)
  #:use-module (guix utils)
  #:use-module (guix download)
  #:use-module (guix build-system gnu)
  #:use-module (guix build-system python))

(define-public openldap
  (package
   (name "openldap")
   (replacement openldap-2.4.57)
   (version "2.4.50")
   (source (origin
             (method url-fetch)
             ;; See <http://www.openldap.org/software/download/> for a list of
             ;; mirrors.
             (uri (list (string-append
                         "ftp://mirror.switch.ch/mirror/OpenLDAP/"
                         "openldap-release/openldap-" version ".tgz")
                        (string-append
                         "https://www.openldap.org/software/download/OpenLDAP/"
                         "openldap-release/openldap-" version ".tgz")
                        (string-append
                         "ftp://ftp.dti.ad.jp/pub/net/OpenLDAP/"
                         "openldap-release/openldap-" version ".tgz")))
             (sha256
              (base32
               "1f46nlfwmys110j36sifm7ah8m8f3s10c3vaiikmmigmifapvdaw"))))
   (build-system gnu-build-system)
   (inputs `(("bdb" ,bdb-5.3)
             ("cyrus-sasl" ,cyrus-sasl)
             ("gnutls" ,gnutls)
             ("libgcrypt" ,libgcrypt)
             ("zlib" ,zlib)))
   (native-inputs `(("libtool" ,libtool)
                    ("groff" ,groff)
                    ("bdb" ,bdb-5.3)))
   (arguments
    `(#:tests? #f
      #:configure-flags
      '("--disable-static"
        ,@(if (%current-target-system)
              '("--with-yielding_select=yes"
                "ac_cv_func_memcmp_working=yes")
              '()))
      ;; Disable install stripping as it breaks cross-compiling.
      #:make-flags '("STRIP=")
      #:phases
      (modify-phases %standard-phases
        ,@(if (%current-target-system)
              '((add-before 'configure 'fix-cross-gcc
                  (lambda* (#:key target #:allow-other-keys)
                    (setenv "CC" (string-append target "-gcc"))
                    #t)))
              '())
        (add-after 'install 'patch-sasl-path
          ;; Give -L arguments for cyrus-sasl to avoid propagation.
          (lambda* (#:key inputs outputs #:allow-other-keys)
            (let ((out (assoc-ref outputs "out"))
                  (krb5 (assoc-ref inputs "mit-krb5"))) ;propagated from cyrus-sasl

              ;; The ancient Libtool bundled with OpenLDAP copies the linker flags
              ;; from Cyrus-SASL and embeds them into its own .la files.  Add an
              ;; absolute reference to Kerberos so it does not have to be propagated.
              (substitute* (map (lambda (f) (string-append out "/" f))
                                '("lib/libldap.la" "lib/libldap_r.la"))
                (("-lkrb5" lib)
                 (string-append "-L" krb5 "/lib " lib)))
              #t))))))
   (synopsis "Implementation of the Lightweight Directory Access Protocol")
   (description
    "OpenLDAP is a free implementation of the Lightweight Directory Access Protocol.")
   (license openldap2.8)
   (home-page "https://www.openldap.org/")))

(define-public openldap-2.4.57
  (package
    (inherit openldap)
    (version "2.4.57")
    (source (origin
              (method url-fetch)
              ;; See <http://www.openldap.org/software/download/> for a list of
              ;; mirrors.
              (uri (list (string-append
                          "ftp://mirror.switch.ch/mirror/OpenLDAP/"
                          "openldap-release/openldap-" version ".tgz")
                         (string-append
                          "https://www.openldap.org/software/download/OpenLDAP/"
                          "openldap-release/openldap-" version ".tgz")
                         (string-append
                          "ftp://ftp.dti.ad.jp/pub/net/OpenLDAP/"
                          "openldap-release/openldap-" version ".tgz")))
              (sha256
               (base32
                "0nmlyqhc52v24b4awh914sczmvxbazgq2cnlycvb9dgcwvhlgfn7"))))))

(define-public nss-pam-ldapd
  (package
    (name "nss-pam-ldapd")
    (version "0.9.11")
    (source (origin
              (method url-fetch)
              (uri (string-append "https://arthurdejong.org/nss-pam-ldapd/"
                                  "nss-pam-ldapd-" version ".tar.gz"))
              (sha256
               (base32
                "1dna3r0q6sjhhlkhcp8x2zkslrd4y7701kk6fl5r940sdph1pmyh"))))
    (build-system gnu-build-system)
    (arguments
     `(#:configure-flags
       (list (string-append "--with-pam-seclib-dir="
                            (assoc-ref %outputs "out") "/lib/security/")
             ;; nslcd cannot be convinced to look at run-time for its
             ;; configuration file at a location that differs from the
             ;; configured location.
             "--with-ldap-conf-file=/etc/nslcd.conf")
       #:phases
       (modify-phases %standard-phases
         ;; This is necessary because we tell nslcd with configure flags that
         ;; it should look for its configuration file at /etc/nslcd.conf.  The
         ;; build system tries to install a default configuration to that very
         ;; location.
         (add-after 'unpack 'override-nslcd.conf-install-path
           (lambda* (#:key outputs #:allow-other-keys)
             (substitute* "Makefile.in"
               (("\\$\\(DESTDIR\\)\\$\\(NSLCD_CONF_PATH\\)")
                (string-append (assoc-ref outputs "out")
                               "/etc/nslcd.conf.example")))
             #t)))))
    (inputs
     `(("linux-pam" ,linux-pam)
       ("openldap" ,openldap)
       ("mit-krb5" ,mit-krb5)
       ("python" ,python)))
    (home-page "https://arthurdejong.org/nss-pam-ldapd")
    (synopsis "NSS and PAM modules for LDAP")
    (description "nss-pam-ldapd provides a @dfn{Name Service Switch} (NSS)
module that allows your LDAP server to provide user account, group, host name,
alias, netgroup, and basically any other information that you would normally
get from @file{/etc} flat files or NIS.  It also provides a @dfn{Pluggable
Authentication Module} (PAM) to do identity and authentication management with
an LDAP server.")
    (license lgpl2.1+)))

(define-public python-ldap
  (package
    (name "python-ldap")
    (version "3.3.1")
    (source
     (origin
       (method url-fetch)
       (uri (pypi-uri "python-ldap" version))
       (sha256
        (base32
         "198as30xy6p760niqps2zdvq2xcmr765h06pmda8fa9y077wl4a7"))))
    (build-system python-build-system)
    (arguments
     `(#:phases
       (modify-phases %standard-phases
         (add-after 'unpack 'configure-openldap-locations
           (lambda* (#:key inputs #:allow-other-keys)
             (let ((openldap (assoc-ref inputs "openldap")))
               (setenv "SLAPD"
                       (string-append openldap
                                      "/libexec/slapd"))
               (setenv "SCHEMA"
                       (string-append openldap
                                      "/etc/openldap/schema/")))
             #t)))))
    (inputs
     `(("openldap" ,openldap)
       ("cyrus-sasl" ,cyrus-sasl)
       ("mit-krb5" ,mit-krb5)))
    (propagated-inputs
     `(("python-pyasn1" ,python-pyasn1)
       ("python-pyasn1-modules" ,python-pyasn1-modules)))
    (home-page "https://www.python-ldap.org/")
    (synopsis "Python modules for implementing LDAP clients")
    (description
     "This package provides an object-oriented API to access LDAP directory
servers from Python programs.")
    (license psfl)))

(define-public 389-ds-base
  (package
    (name "389-ds-base")
    (version "1.4.0.31")
    (source (origin
              (method url-fetch)
              (uri (string-append "https://releases.pagure.org/389-ds-base/"
                                  "389-ds-base-" version ".tar.bz2"))
              (sha256
               (base32
                "1rs218iqxyclccsdqb529favdsmz88zw785lsxd9ln43ja3x3l65"))))
    (build-system gnu-build-system)
    (arguments
     `(#:modules ((srfi srfi-1)
                  (guix build gnu-build-system)
                  ((guix build python-build-system)
                   #:select (python-version))
                  (guix build utils))
       #:imported-modules ((guix build python-build-system)
                           ,@%gnu-build-system-modules)
       #:configure-flags
       (list (string-append "--with-db="
                            (assoc-ref %build-inputs "bdb"))
             (string-append "--with-sasl="
                            (assoc-ref %build-inputs "cyrus-sasl"))
             (string-append "--with-netsnmp="
                            (assoc-ref %build-inputs "net-snmp"))
             (string-append "--with-pcre="
                            (assoc-ref %build-inputs "pcre"))
             (string-append "--with-selinux="
                            (assoc-ref %build-inputs "libselinux"))
             "--localstatedir=/var"
             "--with-instconfigdir=/etc/dirsrv"
             ;; The Perl scripts are being removed in the 1.4.0 release.
             ;; Building them would require packaging of the outdated Mozilla
             ;; LDAP SDK (instead of OpenLDAP) and PerLDAP.
             "--disable-perl")
       #:phases
       (modify-phases %standard-phases
         (add-after 'unpack 'fix-references
           (lambda _
             (substitute* "include/ldaputil/certmap.h"
               (("nss3/cert.h") "nss/cert.h"))
             (substitute* "src/lib389/lib389/nss_ssl.py"
               (("'/usr/bin/certutil'")
                (string-append "'" (which "certutil") "'"))
               (("'/usr/bin/c_rehash'")
                (string-append "'" (which "perl") "', '" (which "c_rehash") "'")))
             #t))
         (add-after 'unpack 'overwrite-default-locations
           (lambda* (#:key outputs #:allow-other-keys)
             (let ((out (assoc-ref outputs "out")))
               (substitute* "src/lib389/lib389/paths.py"
                 (("/usr/share/dirsrv/inf/defaults.inf")
                  (string-append out "/share/dirsrv/inf/defaults.inf")))
               ;; This directory can only be specified relative to sysconfdir.  This
               ;; is used to determine where to look for installed directory
               ;; servers, so in the absence of a search path it needs to be global.
               (substitute* "ldap/admin/src/defaults.inf.in"
                 (("^initconfig_dir =.*")
                  "initconfig_dir = /etc/dirsrv/registry\n"))
               ;; This is used to determine where to write certificate files
               ;; when installing new directory server instances.
               (substitute* '("src/lib389/lib389/instance/setup.py"
                              "src/lib389/lib389/instance/remove.py")
                 (("etc_dirsrv_path = .*")
                  "etc_dirsrv_path = '/etc/dirsrv/'\n"))
               #t)))
         (add-after 'unpack 'fix-install-location-of-python-tools
           (lambda* (#:key inputs outputs #:allow-other-keys)
             (let* ((out (assoc-ref outputs "out"))
                    (pythondir (string-append
                                out "/lib/python"
                                (python-version (assoc-ref inputs "python"))
                                "/site-packages/")))
               ;; Install directory must be on PYTHONPATH.
               (setenv "PYTHONPATH"
                       (string-append (getenv "PYTHONPATH")
                                      ":" pythondir))
               ;; Install directory must exist.
               (mkdir-p pythondir)
               (substitute* "src/lib389/setup.py"
                 (("/usr") out))
               (substitute* "Makefile.am"
                 (("setup.py install --skip-build" m)
                  (string-append m " --prefix=" out
                                 " --root=/ --single-version-externally-managed"))))
             #t))
         (add-after 'build 'build-python-tools
           (lambda* (#:key make-flags #:allow-other-keys)
             ;; Set DETERMINISTIC_BUILD to override the embedded mtime in pyc
             ;; files.
             (setenv "DETERMINISTIC_BUILD" "1")
             ;; Use deterministic hashes for strings, bytes, and datetime
             ;; objects.
             (setenv "PYTHONHASHSEED" "0")
             (apply invoke "make" "lib389" make-flags)
             #t))
         (add-after 'install 'install-python-tools
           (lambda* (#:key make-flags #:allow-other-keys)
             (apply invoke "make" "lib389-install" make-flags)
             #t))
         (add-after 'install-python-tools 'wrap-python-tools
           (lambda* (#:key outputs #:allow-other-keys)
             (let* ((out  (assoc-ref outputs "out"))
                    (path (getenv "PYTHONPATH")))
               (for-each (lambda (file)
                           (wrap-program (string-append out file)
                             `("PYTHONPATH" ":" prefix (,path))))
                         '("/sbin/dsconf"
                           "/sbin/dscreate"
                           "/sbin/dsctl"
                           "/sbin/dsidm"
                           "/bin/ds-logpipe.py"
                           "/bin/ds-replcheck"
                           "/bin/readnsstate")))
             #t)))))
    (inputs
     `(("bdb" ,bdb)
       ("cracklib" ,cracklib)
       ("cyrus-sasl" ,cyrus-sasl)
       ("gnutls" ,gnutls)
       ("httpd" ,httpd)
       ("icu4c" ,icu4c)
       ("libevent" ,libevent)
       ("libselinux" ,libselinux)
       ("linux-pam" ,linux-pam)
       ("mit-krb5" ,mit-krb5)
       ("net-snmp" ,net-snmp)
       ("nspr" ,nspr)
       ("nss" ,nss)
       ("nss:bin" ,nss "bin") ; for certutil
       ("openldap" ,openldap)
       ("openssl" ,openssl)             ; #included by net-snmp
       ("pcre" ,pcre)
       ("perl" ,perl)
       ("python" ,python)
       ("python-pyasn1" ,python-pyasn1)
       ("python-pyasn1-modules" ,python-pyasn1-modules)
       ("python-pytest" ,python-pytest)
       ("python-dateutil" ,python-dateutil)
       ("python-six" ,python-six)
       ("python-argcomplete" ,python-argcomplete)
       ("python-argparse-manpage" ,python-argparse-manpage)
       ("python-ldap" ,python-ldap)))
    (native-inputs
     `(("autoconf" ,autoconf)
       ("automake" ,automake)
       ("doxygen" ,doxygen)
       ("gettext" ,gettext-minimal)
       ("libtool" ,libtool)
       ("rsync" ,rsync)
       ("pkg-config" ,pkg-config)))
    (home-page "https://directory.fedoraproject.org")
    (synopsis "Enterprise-class LDAP server")
    (description "389ds is an enterprise-class LDAP server.  It is hardened by
real-world use, is full-featured, and supports multi-master replication.

Other features include:

@enumerate
@item Online, zero downtime, LDAP-based update of schema, configuration, and
  management including @dfn{Access Control Information} (ACIs);
@item Asynchronous Multi-Master Replication, to provide fault tolerance and
  high write performance;
@item Extensive documentation;
@item Secure authentication and transport (TLS, and SASL);
@item LDAPv3 compliant server.
@end enumerate\n")
    ;; GPLv3+ with OpenSSL linking exception.
    (license gpl3+)))

(define-public python-bonsai
  (package
    (name "python-bonsai")
    (version "1.2.0")
    (source
     (origin
       (method url-fetch)
       (uri (pypi-uri "bonsai" version))
       (sha256
        (base32
         "013bl6h1m3f7vg1lk89d4vi28wbf31zdcs4f9g8css7ngx63v6px"))))
    (build-system python-build-system)
    (inputs
     `(("mit-krb5" ,mit-krb5)
       ("cyrus-sasl" ,cyrus-sasl)
       ("openldap" ,openldap)))
    ;; disabling tests, since they require docker and extensive setup
    (arguments `(#:tests? #f))
    (home-page "https://github.com/noirello/bonsai")
    (synopsis "Access LDAP directory servers from Python")
    (description
     "This is a module for handling LDAP operations in Python.  LDAP entries
are mapped to a special Python case-insensitive dictionary, tracking the
changes of the dictionary to modify the entry on the server easily.")
    (license expat)))


code:
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2020 Justus Winter <justus@sequoia-pgp.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 openpgp)
  #:use-module (guix packages)
  #:use-module (guix download)
  #:use-module (guix git-download)
  #:use-module (guix build-system cmake)
  #:use-module (guix build-system gnu)
  #:use-module ((guix licenses) #:prefix license:)
  #:use-module (gnu packages)
  #:use-module (gnu packages check)
  #:use-module (gnu packages compression)
  #:use-module (gnu packages crypto)
  #:use-module (gnu packages gnupg)
  #:use-module (gnu packages multiprecision)
  #:use-module (gnu packages pkg-config)
  #:use-module (gnu packages python)
  #:use-module (gnu packages web))

(define-public libtmcg
  (package
    (name "libtmcg")
    (version "1.3.18")
    (source (origin
              (method url-fetch)
              (uri (string-append "mirror://savannah/libtmcg/libTMCG-" version
                                  ".tar.gz"))
              (sha256
               (base32
                "179b5jx3mqs9hgsj8cfwk6x8qib60kw9szk9fkz6s1gl3v83mnyx"))))
    (build-system gnu-build-system)
    (arguments '(#:configure-flags '("--enable-silent-rules")))
    (inputs `(("gmp" ,gmp)
              ("libgcrypt" ,libgcrypt)))
    (synopsis
     "C++ library for creating secure and fair online card games")
    (description
     "The library provides a sort of useful classes, algorithms, and
high-level protocols to support an application programmer in writing such
software.  The most remarkable feature is the absence of a trusted third
party (TTP), i.e. neither a central game server nor trusted hardware
components are necessary.

The corresponding cryptographic problem, actually called Mental Poker, has
been studied since 1979 (Shamir, Rivest, and Adleman) by many authors.
LibTMCG provides the first practical implementation of such protocols.")
    (home-page "https://www.nongnu.org/libtmcg/")
    (license license:gpl2+)))

(define-public dkgpg
  (package
    (name "dkgpg")
    (version "1.1.3")
    (source (origin
              (method url-fetch)
              (uri (string-append "mirror://savannah/dkgpg/dkgpg-" version
                                  ".tar.gz"))
              (sha256
               (base32
                "1hpfg7akd5icj49i03z74hp9zj0xwl90bndn0hnw0hpb8lk7qcxg"))))
    (build-system gnu-build-system)
    (arguments '(#:configure-flags
                 '("--enable-silent-rules")
                 ;; https://savannah.nongnu.org/bugs/?58772
                 #:parallel-tests? #f))
    (inputs `(("bzip2" ,bzip2)
              ("gmp" ,gmp)
              ("libgcrypt" ,libgcrypt)
              ("libtmcg" ,libtmcg)
              ("zlib" ,zlib)))
    (synopsis
     "Distributed Key Generation and Threshold Cryptography for OpenPGP")
    (description
     "The Distributed Privacy Guard (DKGPG) implements Distributed Key
Generation (DKG) and Threshold Cryptography for OpenPGP.  The generated public
keys are compatible with the standard and thus can be used by any
RFC4880-compliant application (e.g. GnuPG).  The main purposes of this
software are distributing power among multiple parties, eliminating single
points of failure, and increasing the difficulty of side-channel attacks on
private key material.

DKGPG consists of a bunch of simple command-line programs.  The current
implementation is in experimental state and should NOT be used in production
environments.")
    (home-page "https://www.nongnu.org/dkgpg/")
    (license license:gpl2+)))

(define-public rnp
  ;; Packaging the currently released version requires a large number of
  ;; patches.  For now, we package a snapshot instead.
  (let ((commit "203224f0b1505dba17837c03da603e5b98ab125a")
        (revision "0")
        (last-version "0.13.1")
        (day-of-release "2020-07-21"))
    (package
      (name "rnp")
      (version (git-version last-version revision commit))
      (source (origin
                (method git-fetch)
                (uri (git-reference
                      (url "https://github.com/rnpgp/rnp")
                      (commit commit)))
                (file-name
                 (string-append name "-" (string-take commit 7) "-checkout"))
                (sha256
                 (base32
                  "1rnwhc9ys4v4mv584hmmrl0ycnqmsaigpffzm31qq337hz24zqya"))
                (patches
                 (search-patches "rnp-unbundle-googletest.patch"
                                 "rnp-disable-ruby-rnp-tests.patch"
                                 "rnp-add-version.cmake.patch"))))
      (build-system cmake-build-system)
      (arguments `(#:configure-flags
                   '("-DBUILD_SHARED_LIBS=on"
                     "-DBUILD_TESTING=on")
                   #:phases
                   (modify-phases %standard-phases
                     (add-after 'unpack 'fixes
                       (lambda* (#:key inputs #:allow-other-keys)
                         (copy-recursively (assoc-ref inputs "googletest-source")
                                           "src/tests/googletest-src")
                         (substitute* "src/tests/support.cpp"
                           (("\"cp\"") (string-append "\"" (which "cp") "\"")))
                         ;; Produce a version stamp in the format the upstream
                         ;; project uses for unreleased revisions.
                         (with-output-to-file "version.txt"
                           (lambda _
                             (display
                              (string-append ,last-version
                                             "-" ,revision
                                             "-g" ,(string-take commit 7)))))
                         #t))
                     (replace 'check
                       (lambda _
                         ;; Some OpenPGP certificates used by the tests expire.
                         ;; To work around that, set the time to roughly the
                         ;; release date.
                         (invoke "faketime" ,day-of-release "make" "test"))))))
      (native-inputs
       `(("gnupg" ,gnupg) ; for tests
         ("googletest-source" ,(package-source googletest)) ; for tests
         ("libfaketime" ,libfaketime) ; for tests
         ("pkg-config" ,pkg-config)
         ("python" ,python)
         ("python2" ,python-2.7)))
      (inputs `(("botan" ,botan)
                ("bzip2" ,bzip2)
                ("json-c" ,json-c)
                ("zlib" ,zlib)))
      (synopsis
       "RFC4880-compliant OpenPGP library written in C++")
      (description
       "Set of OpenPGP (RFC4880) tools that works on Linux, *BSD and macOS as a
replacement of GnuPG.  It is maintained by Ribose after being forked from
NetPGP, itself originally written for NetBSD.

librnp is the library used by rnp for all OpenPGP functions, useful for
developers to build against.  It is a “real” library, not a wrapper like GPGME
of GnuPG.")
      (home-page "https://www.rnpgp.com/")
      (license
       ;; RNP contains code written by Ribose and code derived from netpgp.
       (list
        ;; Ribose's BSD 2-Clause License and NetBSD's BSD 2-Clause License
        ;; (netpgp).
        license:bsd-2
        ;; Nominet UK's Apache 2.0 Licence (netpgp).
        license:asl2.0
        ;; Nominet UK's BSD 3-Clause License (netpgp).
        license:bsd-3)))))