code:
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2012, 2013, 2014, 2015, 2016 Ludovic Courtès <ludo@gnu.org>
;;; Copyright © 2014, 2015 Mark H Weaver <mhw@netris.org>
;;; 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 gawk)
  #:use-module (guix licenses)
  #:use-module (gnu packages)
  #:use-module (gnu packages bash)
  #:use-module (gnu packages libsigsegv)
  #:use-module (guix packages)
  #:use-module (guix download)
  #:use-module (guix build-system gnu))

(define-public gawk
  (package
   (name "gawk")
   (version "5.1.0")
   (source (origin
            (method url-fetch)
            (uri (string-append "mirror://gnu/gawk/gawk-" version
                                ".tar.xz"))
            (sha256
             (base32 "1gc2cccqy1x1bf6rhwlmd8q7dz7gnam6nwgl38bxapv6qm5flpyg"))))
   (build-system gnu-build-system)
   (arguments
    `(#:phases (modify-phases %standard-phases
                 (add-before 'configure 'set-shell-file-name
                   (lambda* (#:key inputs #:allow-other-keys)
                     ;; Refer to the right shell.
                     (let ((bash (assoc-ref inputs "bash")))
                       (substitute* "io.c"
                         (("/bin/sh")
                          (string-append bash "/bin/sh")))

                       ;; When cross-compiling, remove dependencies on the
                       ;; `check-for-shared-lib-support' target, which tries
                       ;; to run the cross-built `gawk'.
                       ,@(if (%current-target-system)
                             '((substitute* "extension/Makefile.in"
                                 (("^.*: check-for-shared-lib-support" match)
                                  (string-append "### " match))))
                             '())

                       #t)))

                 (add-before 'check 'adjust-test-infrastructure
                   (lambda _
                     ;; Remove dependency on 'more' (from util-linux), which
                     ;; would needlessly complicate bootstrapping.
                     (substitute* "test/Makefile"
                       (("\\| more") ""))

                     ;; Adjust the shebang in that file since it is then diff'd
                     ;; against the actual test output.
                     (substitute* "test/watchpoint1.ok"
                       (("#! /usr/bin/gawk")
                        (string-append "#!" (which "gawk"))))
                     #t)))))

   (inputs `(("libsigsegv" ,libsigsegv)

             ,@(if (%current-target-system)
                   `(("bash" ,bash))
                   '())))

   (home-page "https://www.gnu.org/software/gawk/")
   (synopsis "Text scanning and processing language")
   (description
    "Gawk is the GNU implementation of Awk, a specialized programming
language for the easy manipulation of formatted text, such as tables of data.
Gawk features many extensions beyond the traditional implementation,
including network access, sorting, and large libraries.")
   (license gpl3+)))


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

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

(define-public gcal
  (package
    (name "gcal")
    (version "4.1")
    (source (origin
             (method url-fetch)
             (uri (string-append "mirror://gnu/gcal/gcal-"
                                 version ".tar.xz"))
             (sha256
              (base32
               "1av11zkfirbixn05hyq4xvilin0ncddfjqzc4zd9pviyp506rdci"))
             (modules '((guix build utils)))
             (snippet
              '(begin
                 ;; Adjust the bundled gnulib to work with glibc 2.28.  See e.g.
                 ;; "m4-gnulib-libio.patch".  This is a phase rather than patch
                 ;; or snippet to work around <https://bugs.gnu.org/32347>.
                 (substitute* (find-files "lib" "\\.c$")
                   (("#if defined _IO_ftrylockfile")
                    "#if defined _IO_EOF_SEEN"))
                 (substitute* "lib/stdio-impl.h"
                   (("^/\\* BSD stdio derived implementations")
                    (string-append "#if !defined _IO_IN_BACKUP && defined _IO_EOF_SEEN\n"
                                   "# define _IO_IN_BACKUP 0x100\n"
                                   "#endif\n\n"
                                   "/* BSD stdio derived implementations")))
                 #t))))
    (build-system gnu-build-system)
    (home-page "https://www.gnu.org/software/gcal/")
    (synopsis "Calculating and printing a wide variety of calendars")
    (description
     "Gcal is a program to calculate and print calendars on the
command-line.  Calendars can be printed in 1-month, 3-month or whole-year
views.  In addition, eternal holiday lists can be generated for many
countries, which can be complemented by user-made lists of fixed dates to
make an agenda.  Gcal can also calculate astronomical data, such as the
phases of the moon, and supports alternative calendar formats: Julian,
Gregorian, Islamic, Chinese and more.")
    (license gpl3+)))

license: mit


code:
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020 Ludovic Courtès <ludo@gnu.org>
;;; Copyright © 2014, 2015, 2018 Mark H Weaver <mhw@netris.org>
;;; Copyright © 2014, 2015, 2016, 2017, 2019 Ricardo Wurmus <rekado@elephly.net>
;;; Copyright © 2015 Andreas Enge <andreas@enge.fr>
;;; Copyright © 2015, 2016, 2017, 2018, 2020 Efraim Flashner <efraim@flashner.co.il>
;;; Copyright © 2016 Carlos Sánchez de La Lama <csanchezdll@gmail.com>
;;; Copyright © 2018 Tobias Geerinckx-Rice <me@tobias.gr>
;;; Copyright © 2018, 2020 Marius Bakke <mbakke@fastmail.com>
;;; Copyright © 2020 Joseph LaFreniere <joseph@lafreniere.xyz>
;;; Copyright © 2020 Guy Fleury Iteriteka <gfleury@disroot.org>
;;; Copyright © 2020 Simon Tournier <zimon.toutoune@gmail.com>
;;;
;;; This file is part of GNU Guix.
;;;
;;; GNU Guix is free software; you can redistribute it and/or modify it
;;; under the terms of the GNU General Public License as published by
;;; the Free Software Foundation; either version 3 of the License, or (at
;;; your option) any later version.
;;;
;;; GNU Guix is distributed in the hope that it will be useful, but
;;; WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;;; GNU General Public License for more details.
;;;
;;; You should have received a copy of the GNU General Public License
;;; along with GNU Guix.  If not, see <http://www.gnu.org/licenses/>.

(define-module (gnu packages gcc)
  #:use-module ((guix licenses)
                #:select (gpl3+ gpl2+ lgpl2.1+ lgpl2.0+ fdl1.3+))
  #:use-module (gnu packages)
  #:use-module (gnu packages bootstrap)
  #:use-module (gnu packages compression)
  #:use-module (gnu packages multiprecision)
  #:use-module (gnu packages texinfo)
  #:use-module (gnu packages dejagnu)
  #:use-module (gnu packages documentation)
  #:use-module (gnu packages xml)
  #:use-module (gnu packages docbook)
  #:use-module (gnu packages graphviz)
  #:use-module (gnu packages elf)
  #:use-module (gnu packages perl)
  #:use-module (guix packages)
  #:use-module (guix download)
  #:use-module (guix build-system gnu)
  #:use-module (guix build-system trivial)
  #:use-module (guix utils)
  #:use-module (srfi srfi-1)
  #:use-module (ice-9 regex))

(define %gcc-infrastructure
  ;; Base URL for GCC's infrastructure.
  "mirror://gcc/infrastructure/")

(define (gcc-configure-flags-for-triplet target)
  "Return a list of additional GCC `configure' flags for TARGET, a GNU triplet.

The purpose of this procedure is to translate extended GNU triplets---e.g.,
where the OS part is overloaded to denote a specific ABI---into GCC
`configure' options.  We take extended GNU triplets that glibc recognizes."
  (cond ((string-match "^mips64el.*gnuabin?64$" target)
         ;; Triplets recognized by glibc as denoting the N64 ABI; see
         ;; ports/sysdeps/mips/preconfigure.
         '("--with-abi=64"))

        ((string-match "^arm.*-gnueabihf$" target)
         '("--with-arch=armv7-a"
           "--with-float=hard"
           "--with-mode=thumb"
           "--with-fpu=neon"))

        ((and (string-suffix? "-gnu" target)
              (not (string-contains target "-linux")))
         ;; Cross-compilation of libcilkrts in GCC 5.5.0 to GNU/Hurd fails
         ;; with:
         ;;   libcilkrts/runtime/os-unix.c:388:2: error: #error "Unknown architecture"
         ;; Cilk has been removed from GCC 8 anyway.
         '("--disable-libcilkrts"))

        (else
         ;; TODO: Add `arm.*-gnueabi', etc.
         '())))

(define-public gcc-4.7
  (let* ((stripped? #t)      ;whether to strip the compiler, not the libraries
         (maybe-target-tools
          (lambda ()
            ;; Return the `_FOR_TARGET' variables that are needed when
            ;; cross-compiling GCC.
            (let ((target (%current-target-system)))
              (if target
                  (map (lambda (var tool)
                         (string-append (string-append var "_FOR_TARGET")
                                        "=" target "-" tool))
                       '("CC"  "CXX" "LD" "AR" "NM" "OBJDUMP" "RANLIB" "STRIP")
                       '("gcc" "g++" "ld" "ar" "nm" "objdump" "ranlib" "strip"))
                  '()))))
         (libdir
          (let ((base '(or (assoc-ref outputs "lib")
                           (assoc-ref outputs "out"))))
            (lambda ()
              ;; Return the directory that contains lib/libgcc_s.so et al.
              (if (%current-target-system)
                  `(string-append ,base "/" ,(%current-target-system))
                  base))))
         (configure-flags
          (lambda ()
            ;; This is terrible.  Since we have two levels of quasiquotation,
            ;; we have to do this convoluted thing just so we can insert the
            ;; contents of (maybe-target-tools).
            (list 'quasiquote
                  (append
                   '("--enable-plugin"
                     "--enable-languages=c,c++"
                     "--disable-multilib"
                     "--with-system-zlib"

                     ;; No pre-compiled libstdc++ headers, to save space.
                     "--disable-libstdcxx-pch"

                     "--with-local-prefix=/no-gcc-local-prefix"

                     ;; With a separate "lib" output, the build system
                     ;; incorrectly guesses GPLUSPLUS_INCLUDE_DIR, so force
                     ;; it.  (Don't use a versioned sub-directory, that's
                     ;; unnecessary.)
                     ,(string-append "--with-gxx-include-dir="
                                     (assoc-ref %outputs "out")
                                     "/include/c++")

                     ,(let ((libc (assoc-ref %build-inputs "libc")))
                        (if libc
                            (string-append "--with-native-system-header-dir=" libc
                                           "/include")
                            "--without-headers")))

                   ;; Pass the right options for the target triplet.
                   (let ((triplet
                          (or (%current-target-system)
                              (nix-system->gnu-triplet (%current-system)))))
                     (gcc-configure-flags-for-triplet triplet))

                   (maybe-target-tools))))))
    (hidden-package
     (package
       (name "gcc")
       (version "4.7.4")
       (source (origin
                 (method url-fetch)
                 (uri (string-append "mirror://gnu/gcc/gcc-"
                                     version "/gcc-" version ".tar.bz2"))
                 (sha256
                  (base32
                   "10k2k71kxgay283ylbbhhs51cl55zn2q38vj5pk4k950qdnirrlj"))
                 (patches (search-patches "gcc-4-compile-with-gcc-5.patch"
                                          "gcc-fix-texi2pod.patch"))))
       (build-system gnu-build-system)

       ;; Separate out the run-time support libraries because all the
       ;; dynamic-linked objects depend on it.
       (outputs '("out"                    ;commands, etc. (60+ MiB)
                  "lib"                    ;libgcc_s, libgomp, etc. (15+ MiB)
                  "debug"))                ;debug symbols of run-time libraries

       (inputs `(("gmp" ,gmp)
                 ("mpfr" ,mpfr)
                 ("mpc" ,mpc)
                 ("libelf" ,libelf)
                 ("zlib" ,zlib)))

       ;; GCC < 5 is one of the few packages that doesn't ship .info files.
       ;; Newer texinfos fail to build the manual, so we use an older one.
       (native-inputs `(("perl" ,perl)   ;for manpages
                        ("texinfo" ,texinfo-5)))

       (arguments
        `(#:out-of-source? #t
          #:configure-flags ,(configure-flags)
          #:make-flags
          ;; None of the flags below are needed when doing a Canadian cross.
          ;; TODO: Simplify this.
          ,(if (%current-target-system)
               (if stripped?
                   ''("CFLAGS=-g0 -O2")
                   ''())
               `(let* ((libc        (assoc-ref %build-inputs "libc"))
                       (libc-native (or (assoc-ref %build-inputs "libc-native")
                                        libc)))
                  `(,@(if libc
                          (list (string-append "LDFLAGS_FOR_TARGET="
                                               "-B" libc "/lib "
                                               "-Wl,-dynamic-linker "
                                               "-Wl," libc
                                               ,(glibc-dynamic-linker)))
                          '())

                    ;; Native programs like 'genhooks' also need that right.
                    ,(string-append "LDFLAGS="
                                    "-Wl,-rpath=" libc-native "/lib "
                                    "-Wl,-dynamic-linker "
                                    "-Wl," libc-native ,(glibc-dynamic-linker))
                    ,(string-append "BOOT_CFLAGS=-O2 "
                                    ,(if stripped? "-g0" "-g")))))

          #:tests? #f

          #:phases
          (modify-phases %standard-phases
            (add-before 'configure 'pre-configure
              (lambda* (#:key inputs outputs #:allow-other-keys)
                (let ((libdir ,(libdir))
                      (libc   (assoc-ref inputs "libc")))
                  (when libc
                    ;; The following is not performed for `--without-headers'
                    ;; cross-compiler builds.

                    ;; Join multi-line definitions of GLIBC_DYNAMIC_LINKER* into a
                    ;; single line, to allow the next step to work properly.
                    (for-each
                     (lambda (x)
                       (substitute* (find-files "gcc/config"
                                                "^(linux|gnu|sysv4)(64|-elf|-eabi)?\\.h$")
                         (("(#define (GLIBC|GNU_USER)_DYNAMIC_LINKER.*)\\\\\n$" _ line)
                          line)))
                     '(1 2 3))

                    ;; Fix the dynamic linker's file name.
                    (substitute* (find-files "gcc/config"
                                             "^(linux|gnu|sysv4)(64|-elf|-eabi)?\\.h$")
                      (("#define (GLIBC|GNU_USER)_DYNAMIC_LINKER([^ \t]*).*$"
                        _ gnu-user suffix)
                       (format #f "#define ~a_DYNAMIC_LINKER~a \"~a\"~%"
                               gnu-user suffix
                               (string-append libc ,(glibc-dynamic-linker)))))

                    ;; Tell where to find libstdc++, libc, and `?crt*.o', except
                    ;; `crt{begin,end}.o', which come with GCC.
                    (substitute* (find-files "gcc/config"
                                             "^gnu-user.*\\.h$")
                      (("#define GNU_USER_TARGET_LIB_SPEC (.*)$" _ suffix)
                       ;; Help libgcc_s.so be found (see also below.)  Always use
                       ;; '-lgcc_s' so that libgcc_s.so is always found by those
                       ;; programs that use 'pthread_cancel' (glibc dlopens
                       ;; libgcc_s.so when pthread_cancel support is needed, but
                       ;; having it in the application's RUNPATH isn't enough; see
                       ;; <http://sourceware.org/ml/libc-help/2013-11/msg00023.html>.)
                       ;;
                       ;; NOTE: The '-lgcc_s' added below needs to be removed in a
                       ;; later phase of %gcc-static.  If you change the string
                       ;; below, make sure to update the relevant code in
                       ;; %gcc-static package as needed.
                       (format #f "#define GNU_USER_TARGET_LIB_SPEC \
\"-L~a/lib %{!static:-rpath=~a/lib %{!static-libgcc:-rpath=~a/lib -lgcc_s}} \" ~a"
                               libc libc libdir suffix))
                      (("#define GNU_USER_TARGET_STARTFILE_SPEC.*$" line)
                       (format #f "#define STANDARD_STARTFILE_PREFIX_1 \"~a/lib\"
#define STANDARD_STARTFILE_PREFIX_2 \"\"
~a"
                               libc line)))

                    ;; The rs6000 (a.k.a. powerpc) config in GCC does not use
                    ;; GNU_USER_* defines.  Do the above for this case.
                    (substitute*
                        "gcc/config/rs6000/sysv4.h"
                      (("#define LIB_LINUX_SPEC (.*)$" _ suffix)
                       (format #f "#define LIB_LINUX_SPEC \
\"-L~a/lib %{!static:-rpath=~a/lib %{!static-libgcc:-rpath=~a/lib -lgcc_s}} \" ~a"
                               libc libc libdir suffix))
                      (("#define	STARTFILE_LINUX_SPEC.*$" line)
                       (format #f "#define STANDARD_STARTFILE_PREFIX_1 \"~a/lib\"
#define STANDARD_STARTFILE_PREFIX_2 \"\"
~a"
                               libc line))))

                  ;; Don't retain a dependency on the build-time sed.
                  (substitute* "fixincludes/fixincl.x"
                    (("static char const sed_cmd_z\\[\\] =.*;")
                     "static char const sed_cmd_z[] = \"sed\";"))

                  ;; Aarch64 support didn't land in GCC until the 4.8 series.
                  (when (file-exists? "gcc/config/aarch64")
                    ;; Force Aarch64 libdir to be /lib and not /lib64
                    (substitute* "gcc/config/aarch64/t-aarch64-linux"
                      (("lib64") "lib")))

                  (when (file-exists? "libbacktrace")
                    ;; GCC 4.8+ comes with libbacktrace.  By default it builds
                    ;; with -Werror, which fails with a -Wcast-qual error in glibc
                    ;; 2.21's stdlib-bsearch.h.  Remove -Werror.
                    (substitute* "libbacktrace/configure"
                      (("WARN_FLAGS=(.*)-Werror" _ flags)
                       (string-append "WARN_FLAGS=" flags)))

                    (when (file-exists? "libsanitizer/libbacktrace")
                      ;; Same in libsanitizer's bundled copy (!) found in 4.9+.
                      (substitute* "libsanitizer/libbacktrace/Makefile.in"
                        (("-Werror")
                         ""))))

                  ;; Add a RUNPATH to libstdc++.so so that it finds libgcc_s.
                  ;; See <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=32354>
                  ;; and <http://bugs.gnu.org/20358>.
                  (substitute* "libstdc++-v3/src/Makefile.in"
                    (("^OPT_LDFLAGS = ")
                     "OPT_LDFLAGS = -Wl,-rpath=$(libdir) "))

                  ;; Move libstdc++*-gdb.py to the "lib" output to avoid a
                  ;; circularity between "out" and "lib".  (Note:
                  ;; --with-python-dir is useless because it imposes $(prefix) as
                  ;; the parent directory.)
                  (substitute* "libstdc++-v3/python/Makefile.in"
                    (("pythondir = .*$")
                     (string-append "pythondir = " libdir "/share"
                                    "/gcc-$(gcc_version)/python\n")))

                  ;; Avoid another circularity between the outputs: this #define
                  ;; ends up in auto-host.h in the "lib" output, referring to
                  ;; "out".  (This variable is used to augment cpp's search path,
                  ;; but there's nothing useful to look for here.)
                  (substitute* "gcc/config.in"
                    (("PREFIX_INCLUDE_DIR")
                     "PREFIX_INCLUDE_DIR_isnt_necessary_here"))
                  #t)))

            (add-after 'configure 'post-configure
              (lambda _
                ;; Don't store configure flags, to avoid retaining references to
                ;; build-time dependencies---e.g., `--with-ppl=/gnu/store/xxx'.
                (substitute* "Makefile"
                  (("^TOPLEVEL_CONFIGURE_ARGUMENTS=(.*)$" _ rest)
                   "TOPLEVEL_CONFIGURE_ARGUMENTS=\n"))
                #t)))))

       (native-search-paths
        ;; Use the language-specific variables rather than 'CPATH' because they
        ;; are equivalent to '-isystem' whereas 'CPATH' is equivalent to '-I'.
        ;; The intent is to allow headers that are in the search path to be
        ;; treated as "system headers" (headers exempt from warnings) just like
        ;; the typical /usr/include headers on an FHS system.
        (list (search-path-specification
               (variable "C_INCLUDE_PATH")
               (files '("include")))
              (search-path-specification
               (variable "CPLUS_INCLUDE_PATH")
               ;; Add 'include/c++' here so that <cstdlib>'s "#include_next
               ;; <stdlib.h>" finds GCC's <stdlib.h>, not libc's.
               (files '("include/c++" "include")))
              (search-path-specification
               (variable "LIBRARY_PATH")
               (files '("lib" "lib64")))))

       (properties `((gcc-libc . ,(assoc-ref inputs "libc"))))
       (synopsis "GNU Compiler Collection")
       (description
        "GCC is the GNU Compiler Collection.  It provides compiler front-ends
for several languages, including C, C++, Objective-C, Fortran, Java, Ada, and
Go.  It also includes runtime support libraries for these languages.")
       (license gpl3+)
       (supported-systems (delete "aarch64-linux" %supported-systems))
       (home-page "https://gcc.gnu.org/")))))

(define-public gcc-4.8
  (package (inherit gcc-4.7)
    (version "4.8.5")
    (source (origin
              (method url-fetch)
              (uri (string-append "mirror://gnu/gcc/gcc-"
                                  version "/gcc-" version ".tar.bz2"))
              (sha256
               (base32
                "08yggr18v373a1ihj0rg2vd6psnic42b518xcgp3r9k81xz1xyr2"))
              (patches (search-patches "gcc-arm-link-spec-fix.patch"
                                       "gcc-4.8-libsanitizer-fix.patch"
                                       "gcc-asan-missing-include.patch"
                                       "gcc-fix-texi2pod.patch"))
              (modules '((guix build utils)))
              ;; This is required for building with glibc-2.26.
              ;; https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81712
              (snippet
               '(begin
                  (for-each
                   (lambda (dir)
                     (substitute* (string-append "libgcc/config/"
                                                 dir "/linux-unwind.h")
                       (("struct ucontext") "ucontext_t")))
                   '("aarch64" "alpha" "bfin" "i386" "m68k"
                     "pa" "sh" "tilepro" "xtensa"))
                  #t))))
    (supported-systems %supported-systems)
    (inputs
     `(("isl" ,isl-0.11)
       ("cloog" ,cloog)
       ,@(package-inputs gcc-4.7)))))

(define-public gcc-4.9
  (package (inherit gcc-4.8)
    (version "4.9.4")
    (source (origin
              (method url-fetch)
              (uri (string-append "mirror://gnu/gcc/gcc-"
                                  version "/gcc-" version ".tar.bz2"))
              (sha256
               (base32
                "14l06m7nvcvb0igkbip58x59w3nq6315k6jcz3wr9ch1rn9d44bc"))
              (patches (search-patches "gcc-4.9-libsanitizer-fix.patch"
                                       "gcc-4.9-libsanitizer-ustat.patch"
                                       "gcc-4.9-libsanitizer-mode-size.patch"
                                       "gcc-arm-bug-71399.patch"
                                       "gcc-asan-missing-include.patch"
                                       "gcc-libvtv-runpath.patch"
                                       "gcc-fix-texi2pod.patch"))
              (modules '((guix build utils)))
              ;; This is required for building with glibc-2.26.
              ;; https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81712
              (snippet
               '(begin
                  (for-each
                   (lambda (dir)
                     (substitute* (string-append "libgcc/config/"
                                                 dir "/linux-unwind.h")
                       (("struct ucontext") "ucontext_t")))
                   '("aarch64" "alpha" "bfin" "i386" "m68k" "nios2"
                     "pa" "sh" "tilepro" "xtensa"))
                  #t))))
    ;; Override inherited texinfo-5 with latest version.
    (native-inputs `(("perl" ,perl)   ;for manpages
                     ("texinfo" ,texinfo)))
    (arguments
     (if (%current-target-system)
         (package-arguments gcc-4.8)
         ;; For native builds of GCC 4.9 and GCC 5, the C++ include path needs
         ;; to be adjusted so it does not interfere with GCC's own build processes.
         (substitute-keyword-arguments (package-arguments gcc-4.8)
           ((#:modules modules %gnu-build-system-modules)
            `((srfi srfi-1)
              ,@modules))
           ((#:phases phases)
            `(modify-phases ,phases
               (add-after 'set-paths 'adjust-CPLUS_INCLUDE_PATH
                 (lambda* (#:key inputs #:allow-other-keys)
                   (let ((libc (assoc-ref inputs "libc"))
                         (gcc (assoc-ref inputs  "gcc")))
                     (setenv "CPLUS_INCLUDE_PATH"
                             (string-join (fold delete
                                                (string-split (getenv "CPLUS_INCLUDE_PATH")
                                                              #\:)
                                                (list (string-append libc "/include")
                                                      (string-append gcc "/include/c++")))
                                          ":"))
                     (format #t
                             "environment variable `CPLUS_INCLUDE_PATH' changed to ~a~%"
                             (getenv "CPLUS_INCLUDE_PATH"))
                     #t))))))))))

(define-public gcc-5
  ;; Note: GCC >= 5 ships with .info files but 'make install' fails to install
  ;; them in a VPATH build.
  (package (inherit gcc-4.9)
    (version "5.5.0")
    (source (origin
              (method url-fetch)
              (uri (string-append "mirror://gnu/gcc/gcc-"
                                  version "/gcc-" version ".tar.xz"))
              (sha256
               (base32
                "11zd1hgzkli3b2v70qsm2hyqppngd4616qc96lmm9zl2kl9yl32k"))
              (patches (search-patches "gcc-arm-bug-71399.patch"
                                       "gcc-libsanitizer-ustat.patch"
                                       "gcc-strmov-store-file-names.patch"
                                       "gcc-5.0-libvtv-runpath.patch"
                                       "gcc-5-source-date-epoch-1.patch"
                                       "gcc-5-source-date-epoch-2.patch"
                                       "gcc-6-libsanitizer-mode-size.patch"
                                       "gcc-fix-texi2pod.patch"
                                       "gcc-5-hurd.patch"))
              (modules '((guix build utils)))
              (snippet
               ;; Fix 'libcc1/configure' error when cross-compiling GCC.
               ;; Without that, 'libcc1/configure' wrongfully determines that
               ;; '-rdynamic' support is missing because $gcc_cv_objdump is
               ;; empty:
               ;;
               ;;   https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67590
               ;;   http://cgit.openembedded.org/openembedded-core/commit/?id=f6e47aa9b12f9ab61530c40e0343f451699d9077
               '(begin
                  (substitute* "libcc1/configure"
                    (("\\$gcc_cv_objdump -T")
                     "$OBJDUMP_FOR_TARGET -T"))
                  #t))))
    (inputs
     `(;; GCC5 needs <isl/band.h> which is removed in later versions.
       ("isl" ,isl-0.18)
       ,@(package-inputs gcc-4.7)))))

(define-public gcc-6
  (package
    (inherit gcc-5)
    (version "6.5.0")
    (source (origin
              (method url-fetch)
              (uri (string-append "mirror://gnu/gcc/gcc-"
                                  version "/gcc-" version ".tar.xz"))
              (sha256
               (base32
                "0i89fksfp6wr1xg9l8296aslcymv2idn60ip31wr9s4pwin7kwby"))
              (patches (search-patches "gcc-strmov-store-file-names.patch"
                                       "gcc-6-libsanitizer-mode-size.patch"
                                       "gcc-6-source-date-epoch-1.patch"
                                       "gcc-6-source-date-epoch-2.patch"
                                       "gcc-5.0-libvtv-runpath.patch"))))

    ;; GCC 4.9 and 5 has a workaround that is not needed for GCC 6 and later.
    (arguments (package-arguments gcc-4.8))

    (inputs
     `(("isl" ,isl)

       ;; XXX: This gross hack allows us to have libstdc++'s <bits/c++config.h>
       ;; in the search path, thereby avoiding misconfiguration of libstdc++:
       ;; <https://bugs.gnu.org/42392>.
       ("libstdc++" ,libstdc++-headers)

       ,@(package-inputs gcc-4.7)))))

(define-public gcc-7
  (package
    (inherit gcc-6)
    (version "7.5.0")
    (source (origin
              (method url-fetch)
              (uri (string-append "mirror://gnu/gcc/gcc-"
                                  version "/gcc-" version ".tar.xz"))
              (sha256
               (base32
                "0qg6kqc5l72hpnj4vr6l0p69qav0rh4anlkk3y55540zy3klc6dq"))
              (patches (search-patches "gcc-strmov-store-file-names.patch"
                                       "gcc-7-libsanitizer-mode-size.patch"
                                       "gcc-5.0-libvtv-runpath.patch"))))
    (description
     "GCC is the GNU Compiler Collection.  It provides compiler front-ends
for several languages, including C, C++, Objective-C, Fortran, Ada, and Go.
It also includes runtime support libraries for these languages.")))

(define-public gcc-8
  (package
    (inherit gcc-7)
    (version "8.4.0")
    (source (origin
              (method url-fetch)
              (uri (string-append "mirror://gnu/gcc/gcc-"
                                  version "/gcc-" version ".tar.xz"))
              (sha256
               (base32
                "1m1d3gfix56w4aq8myazzfffkl8bqcrx4jhhapnjf7qfs596w2p3"))
              (patches (search-patches "gcc-8-strmov-store-file-names.patch"
                                       "gcc-5.0-libvtv-runpath.patch"))))))

(define-public gcc-9
  (package
   (inherit gcc-8)
   (version "9.3.0")
   (source (origin
            (method url-fetch)
            (uri (string-append "mirror://gnu/gcc/gcc-"
                                version "/gcc-" version ".tar.xz"))
            (sha256
             (base32
              "1la2yy27ziasyf0jvzk58y1i5b5bq2h176qil550bxhifs39gqbi"))
            (patches (search-patches "gcc-9-strmov-store-file-names.patch"
                                     "gcc-9-asan-fix-limits-include.patch"
                                     "gcc-5.0-libvtv-runpath.patch"))))))

(define-public gcc-10
  (package
   (inherit gcc-8)
   (version "10.2.0")
   (source (origin
            (method url-fetch)
            (uri (string-append "mirror://gnu/gcc/gcc-"
                                version "/gcc-" version ".tar.xz"))
            (sha256
             (base32
              "130xdkhmz1bc2kzx061s3sfwk36xah1fw5w332c0nzwwpdl47pdq"))
            (patches (search-patches "gcc-9-strmov-store-file-names.patch"
                                     "gcc-5.0-libvtv-runpath.patch"))))))

;; Note: When changing the default gcc version, update
;;       the gcc-toolchain-* definitions and the gfortran definition
;;       accordingly.
(define-public gcc gcc-7)

(define-public (make-libstdc++ gcc)
  "Return a libstdc++ package based on GCC.  The primary use case is when
using compilers other than GCC."
  (package
    (inherit gcc)
    (name "libstdc++")
    (arguments
     `(#:out-of-source? #t
       #:phases (alist-cons-before
                 'configure 'chdir
                 (lambda _
                   (chdir "libstdc++-v3")
                   #t)
                 %standard-phases)
       #:configure-flags `("--disable-libstdcxx-pch"
                           ,(string-append "--with-gxx-include-dir="
                                           (assoc-ref %outputs "out")
                                           "/include"))))
    (outputs '("out" "debug"))
    (inputs '())
    (native-inputs '())
    (propagated-inputs '())
    (synopsis "GNU C++ standard library")))

(define libstdc++
  ;; Libstdc++ matching the default GCC.
  (make-libstdc++ gcc))

(define libstdc++-headers
  ;; XXX: This package is for internal use to work around
  ;; <https://bugs.gnu.org/42392> (see above).  The main difference compared
  ;; to the libstdc++ headers that come with 'gcc' is that <bits/c++config.h>
  ;; is right under include/c++ and not under
  ;; include/c++/x86_64-unknown-linux-gnu (aka. GPLUSPLUS_TOOL_INCLUDE_DIR).
  (package
    (inherit libstdc++)
    (name "libstdc++-headers")
    (outputs '("out"))
    (build-system trivial-build-system)
    (arguments
     '(#:builder (let* ((out       (assoc-ref %outputs "out"))
                        (libstdc++ (assoc-ref %build-inputs "libstdc++")))
                   (mkdir out)
                   (mkdir (string-append out "/include"))
                   (symlink (string-append libstdc++ "/include")
                            (string-append out "/include/c++")))))
    (inputs `(("libstdc++" ,libstdc++)))
    (synopsis "Headers of GNU libstdc++")))

(define-public libstdc++-4.9
  (make-libstdc++ gcc-4.9))

(define (make-libiberty gcc)
  "Return a libiberty package based on GCC."
  (package
    (inherit gcc)
    (name "libiberty")
    (arguments
     `(#:out-of-source? #t
       #:phases
       (modify-phases %standard-phases
         (add-before 'configure 'chdir
           (lambda _
             (chdir "libiberty")
             #t))
         (replace 'install
           (lambda* (#:key outputs #:allow-other-keys)
             (let* ((out     (assoc-ref outputs "out"))
                    (lib     (string-append out "/lib/"))
                    (include (string-append out "/include/")))
               (install-file "libiberty.a" lib)
               (install-file "../include/libiberty.h" include))
             #t)))))
    (inputs '())
    (outputs '("out"))
    (native-inputs '())
    (propagated-inputs '())
    (properties '())
    (synopsis "Collection of subroutines used by various GNU programs")))

(define-public libiberty
  (make-libiberty gcc))

(define* (custom-gcc gcc name languages
                     #:optional
                     (search-paths (package-native-search-paths gcc))
                     #:key (separate-lib-output? #t))
  "Return a custom version of GCC that supports LANGUAGES.  Use SEARCH-PATHS
as the 'native-search-paths' field."
  (package (inherit gcc)
    (name name)
    (outputs (if separate-lib-output?
                 (package-outputs gcc)
                 (delete "lib" (package-outputs gcc))))
    (native-search-paths search-paths)
    (properties (alist-delete 'hidden? (package-properties gcc)))
    (arguments
     (substitute-keyword-arguments (package-arguments gcc)
       ((#:modules modules %gnu-build-system-modules)
        `(,@modules
          (srfi srfi-1)
          (srfi srfi-26)
          (ice-9 regex)))
       ((#:configure-flags flags)
        `(cons (string-append "--enable-languages="
                              ,(string-join languages ","))
               (remove (cut string-match "--enable-languages.*" <>)
                       ,flags)))
       ((#:phases phases)
        `(modify-phases ,phases
           (add-after 'install 'remove-broken-or-conflicting-files
             (lambda* (#:key outputs #:allow-other-keys)
               (for-each delete-file
                         (find-files (string-append (assoc-ref outputs "out") "/bin")
                                     ".*(c\\+\\+|cpp|g\\+\\+|gcov|gcc|gcc-.*)"))
               #t))))))))

(define %generic-search-paths
  ;; This is the language-neutral search path for GCC.  Entries in $CPATH are
  ;; not considered "system headers", which means GCC can raise warnings for
  ;; issues in those headers.  'CPATH' is the only one that works for
  ;; front-ends not in the C family.
  (list (search-path-specification
         (variable "CPATH")
         (files '("include")))
        (search-path-specification
         (variable "LIBRARY_PATH")
         (files '("lib" "lib64")))))

(define-public gfortran
  (hidden-package
   (custom-gcc (package
                 (inherit gcc)
                 ;; XXX: Remove LIBSTDC++-HEADERS from the inputs just to
                 ;; avoid a rebuild of all the GFORTRAN dependents.
                 ;; TODO: Remove this hack on the next rebuild cycle.
                 (inputs (alist-delete "libstdc++" (package-inputs gcc))))
               "gfortran" '("fortran")
               %generic-search-paths)))

(define-public gdc-10
  (hidden-package
   (custom-gcc gcc-10 "gdc" '("d")
               %generic-search-paths)))

(define-public libgccjit
  (package
    (inherit gcc-9)
    (name "libgccjit")
    (outputs (delete "lib" (package-outputs gcc)))
    (properties (alist-delete 'hidden? (package-properties gcc)))
    (arguments
     (substitute-keyword-arguments `(#:modules ((guix build gnu-build-system)
                                                (guix build utils)
                                                (ice-9 regex)
                                                (srfi srfi-1)
                                                (srfi srfi-26))
                                     ,@(package-arguments gcc))
       ((#:configure-flags flags)
        `(append `("--enable-host-shared"
                   ,(string-append "--enable-languages=jit"))
                 (remove (cut string-match "--enable-languages.*" <>)
                         ,flags)))
       ((#:phases phases)
        `(modify-phases ,phases
           (add-after 'install 'remove-broken-or-conflicting-files
             (lambda* (#:key outputs #:allow-other-keys)
               (for-each delete-file
                         (find-files (string-append (assoc-ref outputs "out") "/bin")
                                     ".*(c\\+\\+|cpp|g\\+\\+|gcov|gcc|gcc-.*)"))
               #t))))))
    (synopsis "GCC library generating machine code on-the-fly at runtime")
    (description
     "This package is part of the GNU Compiler Collection and provides an
embeddable library for generating machine code on-the-fly at runtime.  This
shared library can then be dynamically-linked into bytecode interpreters and
other such programs that want to generate machine code on-the-fly at run-time.
It can also be used for ahead-of-time code generation for building standalone
compilers.  The just-in-time (jit) part of the name is now something of a
misnomer.")))

(define-public gccgo-4.9
  (custom-gcc (package
                (inherit gcc-4.9)
                (synopsis "Go frontend to GCC")
                (description
                 "This package is part of the GNU Compiler Collection and
provides the GNU compiler for the Go programming language."))
              "gccgo" '("go")
              %generic-search-paths
              ;; Suppress the separate "lib" output, because otherwise the
              ;; "lib" and "out" outputs would refer to each other, creating
              ;; a cyclic dependency.  <http://debbugs.gnu.org/18101>
              #:separate-lib-output? #f))

(define %objc-search-paths
  (list (search-path-specification
         (variable "OBJC_INCLUDE_PATH")
         (files '("include")))
        (search-path-specification
         (variable "LIBRARY_PATH")
         (files '("lib" "lib64")))))

(define-public gcc-objc-4.8
  (custom-gcc gcc-4.8 "gcc-objc" '("objc")
              %objc-search-paths))

(define-public gcc-objc-4.9
  (custom-gcc gcc-4.9 "gcc-objc" '("objc")
              %objc-search-paths))

(define-public gcc-objc-5
  (custom-gcc gcc-5 "gcc-objc" '("objc")
              %objc-search-paths))

(define-public gcc-objc-6
  (custom-gcc gcc-6 "gcc-objc" '("objc")
              %objc-search-paths))

(define-public gcc-objc-7
  (custom-gcc gcc-7 "gcc-objc" '("objc")
              %objc-search-paths))

(define-public gcc-objc-8
  (custom-gcc gcc-8 "gcc-objc" '("objc")
              %objc-search-paths))

(define-public gcc-objc-9
  (custom-gcc gcc-9 "gcc-objc" '("objc")
              %objc-search-paths))

(define-public gcc-objc-10
  (custom-gcc gcc-10 "gcc-objc" '("objc")
              %objc-search-paths))

(define-public gcc-objc gcc-objc-7)

(define %objc++-search-paths
  (list (search-path-specification
         (variable "OBJCPLUS_INCLUDE_PATH")
         (files '("include")))
        (search-path-specification
         (variable "LIBRARY_PATH")
         (files '("lib" "lib64")))))

(define-public gcc-objc++-4.8
  (custom-gcc gcc-4.8 "gcc-objc++" '("obj-c++")
              %objc++-search-paths))

(define-public gcc-objc++-4.9
  (custom-gcc gcc-4.9 "gcc-objc++" '("obj-c++")
              %objc++-search-paths))

(define-public gcc-objc++-5
  (custom-gcc gcc-5 "gcc-objc++" '("obj-c++")
              %objc++-search-paths))

(define-public gcc-objc++-6
  (custom-gcc gcc-6 "gcc-objc++" '("obj-c++")
              %objc++-search-paths))

(define-public gcc-objc++-7
  (custom-gcc gcc-7 "gcc-objc++" '("obj-c++")
              %objc++-search-paths))

(define-public gcc-objc++-8
  (custom-gcc gcc-8 "gcc-objc++" '("obj-c++")
              %objc++-search-paths))

(define-public gcc-objc++-9
  (custom-gcc gcc-9 "gcc-objc++" '("obj-c++")
              %objc++-search-paths))

(define-public gcc-objc++-10
  (custom-gcc gcc-10 "gcc-objc++" '("obj-c++")
              %objc++-search-paths))

(define-public gcc-objc++ gcc-objc++-7)

(define (make-libstdc++-doc gcc)
  "Return a package with the libstdc++ documentation for GCC."
  (package
    (inherit gcc)
    (name "libstdc++-doc")
    (version (package-version gcc))
    (synopsis "GNU libstdc++ documentation")
    (outputs '("out"))
    (native-inputs `(("doxygen" ,doxygen)
                     ("texinfo" ,texinfo)
                     ("libxml2" ,libxml2)
                     ("libxslt" ,libxslt)
                     ("docbook-xml" ,docbook-xml)
                     ("docbook-xsl" ,docbook-xsl)
                     ("graphviz" ,graphviz))) ;for 'dot', invoked by 'doxygen'
    (inputs '())
    (propagated-inputs '())
    (arguments
     '(#:out-of-source? #t
       #:tests? #f                                ;it's just documentation
       #:phases (modify-phases %standard-phases
                  (add-before 'configure 'chdir
                              (lambda _
                                (chdir "libstdc++-v3")
                                #t))
                  (add-before 'configure 'set-xsl-directory
                              (lambda* (#:key inputs #:allow-other-keys)
                                (let ((docbook (assoc-ref inputs "docbook-xsl")))
                                  (substitute* (find-files "doc"
                                                           "^Makefile\\.in$")
                                    (("@XSL_STYLE_DIR@")
                                     (string-append
                                      docbook "/xml/xsl/"
                                      (strip-store-file-name docbook))))
                                  #t)))
                  (replace 'build
                           (lambda _
                             ;; XXX: There's also a 'doc-info' target, but it
                             ;; relies on docbook2X, which itself relies on
                             ;; DocBook 4.1.2, which is not really usable
                             ;; (lacks a catalog.xml.)
                             (invoke "make"
                                     "doc-html"
                                     "doc-man")))
                  (replace 'install
                           (lambda* (#:key outputs #:allow-other-keys)
                             (let ((out (assoc-ref outputs "out")))
                               (invoke "make"
                                       "doc-install-html"
                                       "doc-install-man")))))))
    (properties (alist-delete 'hidden? (package-properties gcc)))))

(define-public libstdc++-doc-5
  (make-libstdc++-doc gcc-5))

(define-public libstdc++-doc-9
  (make-libstdc++-doc gcc-9))

(define-public isl
  (package
    (name "isl")
    (version "0.22.1")
    (source (origin
             (method url-fetch)
             (uri (list (string-append
                         "http://isl.gforge.inria.fr/isl-"
                         version
                         ".tar.bz2")
                        (string-append %gcc-infrastructure
                                       name "-" version ".tar.bz2")))
             (sha256
              (base32
               "1kf54jib0nind1pvakblnfhimmwzm0y1llz8470ag0di5vwqwrhs"))))
    (build-system gnu-build-system)
    (outputs '("out" "static"))
    (arguments
     '(#:phases (modify-phases %standard-phases
                  (add-after 'install 'move-static-library
                    (lambda* (#:key outputs #:allow-other-keys)
                      (let* ((out (assoc-ref outputs "out"))
                             (static (assoc-ref outputs "static"))
                             (source (string-append out "/lib/libisl.a"))
                             (target (string-append static "/lib/libisl.a")))
                        (mkdir-p (dirname target))
                        (link source target)
                        (delete-file source)

                        ;; Remove reference to libisl.a from the .la file so
                        ;; libtool looks for it in the usual locations.
                        (substitute* (string-append out "/lib/libisl.la")
                          (("^old_library=.*")
                           "old_library=''\n"))
                        #t))))))
    (inputs `(("gmp" ,gmp)))
    (home-page "http://isl.gforge.inria.fr/")
    (synopsis
     "Manipulating sets and relations of integer points \
bounded by linear constraints")
    (description
     "isl is a library for manipulating sets and relations of integer points
bounded by linear constraints.  Supported operations on sets include
intersection, union, set difference, emptiness check, convex hull, (integer)
affine hull, integer projection, computing the lexicographic minimum using
parametric integer programming, coalescing and parametric vertex
enumeration.  It also includes an ILP solver based on generalized basis
reduction, transitive closures on maps (which may encode infinite graphs),
dependence analysis and bounds on piecewise step-polynomials.")
    (license lgpl2.1+)))

(define-public isl-0.18
  (package
    (inherit isl)
    (version "0.18")
    (source (origin
              (method url-fetch)
              (uri (list (string-append "http://isl.gforge.inria.fr/isl-"
                                        version ".tar.bz2")
                         (string-append %gcc-infrastructure
                                        "isl-" version ".tar.bz2")))
              (sha256
               (base32
                "06ybml6llhi4i56q90jnimbcgk1lpcdwhy9nxdxra2hxz3bhz2vb"))))))

(define-public isl-0.11
  (package
    (inherit isl)
    (name "isl")
    (version "0.11.1")
    (source (origin
             (method url-fetch)
             (uri (list (string-append
                         "http://isl.gforge.inria.fr/isl-"
                         version
                         ".tar.bz2")
                        (string-append %gcc-infrastructure
                                       name "-" version ".tar.bz2")))
             (sha256
              (base32
               "13d9cqa5rzhbjq0xf0b2dyxag7pqa72xj9dhsa03m8ccr1a4npq9"))
             (patches (search-patches "isl-0.11.1-aarch64-support.patch"))))))

(define-public cloog
  (package
    (name "cloog")
    (version "0.18.0")
    (source
     (origin
      (method url-fetch)
      (uri (list (string-append
                  "http://www.bastoul.net/cloog/pages/download/count.php3?url=cloog-"
                  version
                  ".tar.gz")
                 (string-append %gcc-infrastructure
                                name "-" version ".tar.gz")))
      (sha256
       (base32
        "0a12rwfwp22zd0nlld0xyql11cj390rrq1prw35yjsw8wzfshjhw"))
      (file-name (string-append name "-" version ".tar.gz"))))
    (build-system gnu-build-system)
    (inputs `(("gmp" ,gmp)
              ("isl" ,isl-0.11)))
    (arguments '(#:configure-flags '("--with-isl=system")))
    (home-page "http://www.cloog.org/")
    (synopsis "Library to generate code for scanning Z-polyhedra")
    (description
     "CLooG is a free software library to generate code for scanning
Z-polyhedra.  That is, it finds a code (e.g., in C, FORTRAN...) that
reaches each integral point of one or more parameterized polyhedra.
CLooG has been originally written to solve the code generation problem
for optimizing compilers based on the polytope model.  Nevertheless it
is used now in various area e.g., to build control automata for
high-level synthesis or to find the best polynomial approximation of a
function.  CLooG may help in any situation where scanning polyhedra
matters.  While the user has full control on generated code quality,
CLooG is designed to avoid control overhead and to produce a very
effective code.")
    (license gpl2+)))

(define-public gnu-c-manual
  (package
    (name "gnu-c-manual")
    (version "0.2.5")
    (source (origin
              (method url-fetch)
              (uri (string-append "mirror://gnu/gnu-c-manual/gnu-c-manual-"
                                  version ".tar.gz"))
              (sha256
               (base32
                "1sfsj9256w18qzylgag2h5h377aq8in8929svblfnj9svfriqcys"))))
    (build-system gnu-build-system)
    (native-inputs `(("texinfo" ,texinfo)))
    (arguments
     '(#:phases (modify-phases %standard-phases
                  (delete 'configure)
                  (delete 'check)
                  (replace 'build
                           (lambda _
                             (invoke "make"
                                     "gnu-c-manual.info"
                                     "gnu-c-manual.html")))
                  (replace 'install
                           (lambda* (#:key outputs #:allow-other-keys)
                             (let* ((out (assoc-ref outputs "out"))
                                    (info (string-append out "/share/info"))
                                    (html (string-append
                                           out "/share/doc/gnu-c-manual")))
                               (mkdir-p info)
                               (mkdir-p html)

                               (for-each (lambda (file)
                                           (copy-file file
                                                      (string-append info "/"
                                                                     file)))
                                         (find-files "." "\\.info(-[0-9])?$"))
                               (for-each (lambda (file)
                                           (copy-file file
                                                      (string-append html "/"
                                                                     file)))
                                         (find-files "." "\\.html$"))
                               #t))))))
    (synopsis "Reference manual for the C programming language")
    (description
     "This is a reference manual for the C programming language, as
implemented by the GNU C Compiler (gcc).  As a reference, it is not intended
to be a tutorial of the language.  Rather, it outlines all of the constructs
of the language.  Library functions are not included.")
    (home-page "https://www.gnu.org/software/gnu-c-manual/")
    (license fdl1.3+)))


code:
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2013, 2016 Ludovic Courtès <ludo@gnu.org>
;;; Copyright © 2015, 2016 Mark H Weaver <mhw@netris.org>
;;; Copyright © 2015 Eric Bavier <bavier@member.fsf.org>
;;; Copyright © 2016, 2017 Leo Famulari <leo@famulari.name>
;;; Copyright © 2017 Efraim Flashner <efraim@flashner.co.il>
;;; Copyright © 2017 Marius Bakke <mbakke@fastmail.com>
;;; Copyright © 2018, 2019, 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 gd)
  #:use-module (guix packages)
  #:use-module (guix build-system gnu)
  #:use-module (guix build-system perl)
  #:use-module (guix download)
  #:use-module (gnu packages)
  #:use-module (gnu packages perl)
  #:use-module (gnu packages image)
  #:use-module (gnu packages imagemagick)
  #:use-module (gnu packages fontutils)
  #:use-module (gnu packages compression)
  #:use-module (gnu packages pkg-config)
  #:use-module ((guix licenses) #:select (non-copyleft perl-license)))

(define-public gd
  (package
    (name "gd")
    ;; Note: With libgd.org now pointing to github.com, genuine old
    ;; tarballs are no longer available.  Notably, versions 2.0.x are
    ;; missing.
    (version "2.3.0")
    (source (origin
             (method url-fetch)
             (uri (string-append
                   "https://github.com/libgd/libgd/releases/download/gd-"
                   version "/libgd-" version ".tar.xz"))
             (sha256
              (base32
               "0n5czhxzinvjvmhkf5l9fwjdx5ip69k5k7pj6zwb6zs1k9dibngc"))
             (patches (search-patches "gd-fix-tests-on-i686.patch"
                                      "gd-brect-bounds.patch"))))
    (build-system gnu-build-system)
    (arguments
      ;; As recommended by github.com/libgd/libgd/issues/278 to fix rounding
      ;; issues on aarch64 and other architectures.
     `(#:make-flags '("CFLAGS=-ffp-contract=off")
       #:configure-flags '("--disable-static")
       #:phases
       (modify-phases %standard-phases
         ;; This test is known to fail on i686-linux:
         ;; https://github.com/libgd/libgd/issues/359
         ;; TODO Replace this substitution with an upstream bug fix.
         (add-after 'unpack 'disable-failing-test
           (lambda _
             (substitute* "tests/gdimagegrayscale/basic.c"
               (("return gdNumFailures\\(\\)")
                 "return 0"))
             #t)))))
    (native-inputs
     `(("pkg-config" ,pkg-config)))
    (inputs
     `(("fontconfig" ,fontconfig)
       ("freetype" ,freetype)
       ("libjpeg" ,libjpeg-turbo)
       ("libpng" ,libpng)
       ("zlib" ,zlib)))
    (home-page "https://www.libgd.org/")
    (synopsis "Library for the dynamic creation of images by programmers")
    (description
     "GD is a library for the dynamic creation of images by programmers.  GD
is written in C, and \"wrappers\" are available for Perl, PHP and other
languages.  GD creates PNG, JPEG, GIF, WebP, XPM, BMP images, among other
formats.  GD is commonly used to generate charts, graphics, thumbnails, and
most anything else, on the fly.  While not restricted to use on the web, the
most common applications of GD involve website development.")
    (license (non-copyleft "file://COPYING"
                           "See COPYING file in the distribution."))
    (properties '((cpe-name . "libgd")))))

(define-public perl-gd
  (package
    (name "perl-gd")
    (version "2.72")
    (source
     (origin
       (method url-fetch)
       (uri (string-append "mirror://cpan/authors/id/R/RU/RURBAN/"
                           "GD-" version ".tar.gz"))
       (sha256
        (base32 "014ik1rng6cnjfgdarkyy5m6wl4pdzc2b445m27krfn3zh9hgl31"))))
    (build-system perl-build-system)
    (inputs
     `(("fontconfig" ,fontconfig)
       ("freetype" ,freetype)
       ("gd" ,gd)
       ("libpng" ,libpng)
       ("libjpeg" ,libjpeg-turbo)
       ("zlib" ,zlib)))
    (native-inputs
     `(("perl-extutils-pkgconfig" ,perl-extutils-pkgconfig)))
    (arguments
     `(#:make-maker-flags
       (list (string-append "--lib_jpeg_path="
                            (assoc-ref %build-inputs "libjpeg")))))
    (home-page "https://metacpan.org/release/GD")
    (synopsis "Perl interface to the GD graphics library")
    (description "GD.pm is an autoloadable interface module for libgd, a
popular library for creating and manipulating PNG files.  With this library
you can create PNG images on the fly or modify existing files.")
    (license perl-license)))

(define-public perl-gd-securityimage
  (package
    (name "perl-gd-securityimage")
    (version "1.75")
    (source
     (origin
       (method url-fetch)
       (uri (string-append "mirror://cpan/authors/id/B/BU/BURAK/"
                           "GD-SecurityImage-" version ".tar.gz"))
       (sha256
        (base32 "19lf1kzdavrkkx3f900jnpynr55d5kjd2sdmwpfir5dsmkcj9pix"))))
    (build-system perl-build-system)
    (arguments
     '(#:phases
       (modify-phases %standard-phases
         (add-after 'unpack 'set-env
           (lambda _ (setenv "PERL_USE_UNSAFE_INC" "1") #t)))))
    (native-inputs
     `(("perl-module-build" ,perl-module-build)))
    (propagated-inputs
     `(("perl-gd" ,perl-gd)
       ("perl-image-magick" ,perl-image-magick)))
    (home-page "https://metacpan.org/release/GD-SecurityImage")
    (synopsis "Security image generator")
    (description "This module provides a basic interface to create
security (captcha) images.  The final output is the actual graphic data, the
mime type of the graphic, and the created random string.  The module also has
some \"styles\" that are used to create the background (or foreground) of the
image.")
    (license perl-license)))


code:
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2013, 2014, 2015, 2019, 2020 Ludovic Courtès <ludo@gnu.org>
;;; Copyright © 2015 Mark H Weaver <mhw@netris.org>
;;; Copyright © 2015, 2016, 2019 Efraim Flashner <efraim@flashner.co.il>
;;; Copyright © 2020 Marius Bakke <mbakke@fastmail.com>
;;; Copyright © 2020 Vincent Legoll <vincent.legoll@gmail.com>
;;; Copyright © 2020 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
;;; Copyright © 2020 Maxim Cournoyer <maxim.cournoyer@gmail.com>
;;;
;;; This file is part of GNU Guix.
;;;
;;; GNU Guix is free software; you can redistribute it and/or modify it
;;; under the terms of the GNU General Public License as published by
;;; the Free Software Foundation; either version 3 of the License, or (at
;;; your option) any later version.
;;;
;;; GNU Guix is distributed in the hope that it will be useful, but
;;; WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;;; GNU General Public License for more details.
;;;
;;; You should have received a copy of the GNU General Public License
;;; along with GNU Guix.  If not, see <http://www.gnu.org/licenses/>.

(define-module (gnu packages gdb)
  #:use-module (gnu packages)
  #:use-module (gnu packages hurd)
  #:use-module (gnu packages ncurses)
  #:use-module (gnu packages readline)
  #:use-module (gnu packages dejagnu)
  #:use-module (gnu packages texinfo)
  #:use-module (gnu packages multiprecision)
  #:use-module (gnu packages xml)
  #:use-module (gnu packages guile)
  #:use-module (gnu packages pretty-print)
  #:use-module (gnu packages python)
  #:use-module (gnu packages pkg-config)
  #:use-module ((guix licenses) #:select (gpl3+))
  #:use-module (guix packages)
  #:use-module (guix download)
  #:use-module (guix build-system gnu)
  #:use-module (srfi srfi-1))

(define-public gdb-9.1
  (package
    (name "gdb")
    (version "9.1")
    (source (origin
             (method url-fetch)
             (uri (string-append "mirror://gnu/gdb/gdb-"
                                 version ".tar.xz"))
             (sha256
              (base32
               "0dqp1p7w836iwijg1zb4a784n0j4pyjiw5v6h8fg5lpx6b40x7k9"))))

    (build-system gnu-build-system)
    (arguments
     `(#:tests? #f ; FIXME "make check" fails on single-processor systems.

       #:out-of-source? #t

       #:modules ((srfi srfi-1)
                  ,@%gnu-build-system-modules)

       #:phases (modify-phases %standard-phases
                  (add-after
                   'configure 'post-configure
                   (lambda _
                     (for-each patch-makefile-SHELL
                               (find-files "." "Makefile\\.in"))
                     #t))
                  (add-after
                   'install 'remove-libs-already-in-binutils
                   (lambda* (#:key inputs outputs
                             ;; TODO: Inline the native-inputs addition and
                             ;; below usage in the next rebuild cycle.
                             ,@(if (%current-target-system)
                                   '(native-inputs)
                                   '())
                             #:allow-other-keys)
                     ;; Like Binutils, GDB installs libbfd, libopcodes, etc.
                     ;; However, this leads to collisions when both are
                     ;; installed, and really is none of its business,
                     ;; conceptually.  So remove them.
                     (let* ((binutils ,@(if (%current-target-system)
                                            '((assoc-ref native-inputs "binutils"))
                                            '((assoc-ref inputs "binutils"))))
                            (out      (assoc-ref outputs "out"))
                            (files1   (with-directory-excursion binutils
                                        (append (find-files "lib")
                                                (find-files "include"))))
                            (files2   (with-directory-excursion out
                                        (append (find-files "lib")
                                                (find-files "include"))))
                            (common   (lset-intersection string=?
                                                         files1 files2)))
                       (with-directory-excursion out
                         (for-each delete-file common)
                         #t)))))))
    (inputs
     `(("expat" ,expat)
       ("mpfr" ,mpfr)
       ("gmp" ,gmp)
       ("readline" ,readline)
       ("ncurses" ,ncurses)
       ("guile" ,guile-2.0)
       ("python-wrapper" ,python-wrapper)
       ("source-highlight" ,source-highlight)

       ;; Allow use of XML-formatted syscall information.  This enables 'catch
       ;; syscall' and similar commands.
       ("libxml2" ,libxml2)

       ;; The Hurd needs -lshouldbeinlibc.
       ,@(if (hurd-target?) `(("hurd" ,hurd)) '())))
    (native-inputs
      `(("texinfo" ,texinfo)
        ("dejagnu" ,dejagnu)
        ("pkg-config" ,pkg-config)
        ,@(if (hurd-target?) `(("mig" ,mig)) '())))
    ;; TODO: Add support for the GDB_DEBUG_FILE_DIRECTORY environment variable
    ;; in GDB itself instead of relying on some glue code in the Guix-provided
    ;; .gdbinit file.
    (native-search-paths (list (search-path-specification
                                (variable "GDB_DEBUG_FILE_DIRECTORY")
                                (files '("lib/debug")))))
    (home-page "https://www.gnu.org/software/gdb/")
    (synopsis "The GNU debugger")
    (description
     "GDB is the GNU debugger.  With it, you can monitor what a program is
doing while it runs or what it was doing just before a crash.  It allows you
to specify the runtime conditions, to define breakpoints, and to change how
the program is running to try to fix bugs.  It can be used to debug programs
written in C, C++, Ada, Objective-C, Pascal and more.")
    (license gpl3+)))

;; This version of GDB is required by some of the Rust compilers, see
;; <https://bugs.gnu.org/37810>.
(define-public gdb-8.2
  (package
    (inherit gdb-9.1)
    (version "8.2.1")
    (source (origin
              (method url-fetch)
              (uri (string-append "mirror://gnu/gdb/gdb-"
                                  version ".tar.xz"))
              (sha256
               (base32
                "00i27xqawjv282a07i73lp1l02n0a3ywzhykma75qg500wll6sha"))))))

(define-public gdb
  ;; This is the fixed version that packages depend on.  Update it rarely
  ;; enough to avoid massive rebuilds.
  gdb-9.1)

(define-public gdb-9.2
  (package
    (inherit gdb)
    (version "9.2")
    (source (origin
              (method url-fetch)
              (uri (string-append "mirror://gnu/gdb/gdb-"
                                  version ".tar.xz"))
              (patches (search-patches "gdb-hurd.patch"))
              (sha256
               (base32
                "0mf5fn8v937qwnal4ykn3ji1y2sxk0fa1yfqi679hxmpg6pdf31n"))))))

(define-public gdb-minimal
  (package/inherit
   gdb-9.2
   (name "gdb-minimal")
   (inputs (fold alist-delete (package-inputs gdb)
                 '("libxml2" "ncurses" "python-wrapper" "source-highlight")))))


code:
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2019 Guillaume Le Vaillant <glv@posteo.net>
;;; Copyright © 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 genealogy)
  #:use-module (guix build-system python)
  #:use-module (guix git-download)
  #:use-module ((guix licenses) #:prefix license:)
  #:use-module (guix packages)
  #:use-module (gnu packages fonts)
  #:use-module (gnu packages freedesktop)
  #:use-module (gnu packages geo)
  #:use-module (gnu packages gettext)
  #:use-module (gnu packages ghostscript)
  #:use-module (gnu packages glib)
  #:use-module (gnu packages gnome)
  #:use-module (gnu packages graphviz)
  #:use-module (gnu packages gtk)
  #:use-module (gnu packages python)
  #:use-module (gnu packages python-xyz)
  #:use-module (gnu packages sqlite)
  #:use-module (gnu packages version-control))

(define-public gramps
  (package
    (name "gramps")
    (version "5.1.2")
    (source
     (origin
       (method git-fetch)
       (uri (git-reference
             (url "https://github.com/gramps-project/gramps")
             (commit (string-append "v" version))))
       (file-name (git-file-name name version))
       (sha256
        (base32 "175iwvdp6c1a8rskl2wpk4yvzl437j7hm23v481974a85qy43iv8"))))
    (build-system python-build-system)
    (native-inputs
     `(("gettext" ,gettext-minimal)
       ("intltool" ,intltool)))
    (inputs
     `(("cairo" ,cairo)
       ("font-gnu-freefont" ,font-gnu-freefont)
       ("geocode-glib" ,geocode-glib)
       ("gexiv2" ,gexiv2)
       ("ghostscript" ,ghostscript)
       ("gobject-introspection" ,gobject-introspection)
       ("gtk+" ,gtk+)
       ("gtkspell3" ,gtkspell3)
       ("graphviz" ,graphviz)
       ("librsvg" ,librsvg)
       ("osm-gps-map" ,osm-gps-map)
       ("pango" ,pango)
       ("python-bsddb3" ,python-bsddb3)
       ("python-pillow" ,python-pillow)
       ("python-pycairo" ,python-pycairo)
       ("python-pygobject" ,python-pygobject)
       ("python-pyicu" ,python-pyicu)
       ("rcs" ,rcs)
       ("sqlite" ,sqlite)
       ("xdg-utils" ,xdg-utils)))
    (arguments
     `(#:imported-modules ((guix build glib-or-gtk-build-system)
                           ,@%python-build-system-modules)
       #:modules ((ice-9 match)
                  (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-before 'check 'set-home-for-tests
           (lambda _
             (setenv "HOME" (getenv "TMPDIR"))
             #t))
         (add-before 'wrap 'wrap-with-GI_TYPELIB_PATH
           (lambda* (#:key inputs outputs #:allow-other-keys)
             (let ((out (assoc-ref outputs "out"))
                   (paths (map (match-lambda
                                 ((output . directory)
                                  (let ((girepodir (string-append
                                                    directory
                                                    "/lib/girepository-1.0")))
                                    (if (file-exists? girepodir)
                                        girepodir
                                        #f))))
                               inputs)))
               (wrap-program (string-append out "/bin/gramps")
                 `("GI_TYPELIB_PATH" ":" prefix ,(filter identity paths))))
             #t))
         (add-after 'wrap 'glib-or-gtk-wrap
           (assoc-ref glib-or-gtk:%standard-phases 'glib-or-gtk-wrap)))))
    (home-page "https://gramps-project.org")
    (synopsis "Genealogical research software")
    (description
     "Gramps is a free software project and community striving to produce
a genealogy program that is both intuitive for hobbyists and feature-complete
for professional genealogists.")
    (license license:gpl2+)))


code:
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2018 Danny Milosavljevic <dannym@scratchpost.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 genimage)
  #:use-module (guix utils)
  #:use-module (guix packages)
  #:use-module (guix git-download)
  #:use-module ((guix licenses) #:prefix license:)
  #:use-module (guix build-system gnu)
  #:use-module (guix build utils)
  #:use-module (gnu packages)
  #:use-module (gnu packages autotools)
  #:use-module (gnu packages base)
  #:use-module (gnu packages bash)
  #:use-module (gnu packages bootloaders)
  #:use-module (gnu packages cdrom)
  #:use-module (gnu packages compression)
  #:use-module (gnu packages cpio)
  #:use-module (gnu packages disk)
  #:use-module (gnu packages linux)
  #:use-module (gnu packages mtools)
  #:use-module (gnu packages pkg-config)
  #:use-module (gnu packages textutils)
  #:use-module (gnu packages virtualization))

(define-public genimage
  (package
    (name "genimage")
    (version "11")
    (source (origin
              (method git-fetch)
              (uri (git-reference
                    (url "https://github.com/pengutronix/genimage")
                    (commit (string-append "v" version))))
              (file-name (string-append name "-" version "-checkout"))
              (sha256
               (base32
                "15jmh17lvm3jw9c92bjarly7iwhmnfl322d91mprfv10ppb9ip54"))
              ;; will be shipped with release 14
              (patches (search-patches "genimage-signedness.patch"))))
    (build-system gnu-build-system)
    (arguments
     `(#:phases
       (modify-phases %standard-phases
         (add-after 'unpack 'guixify
           (lambda* (#:key inputs #:allow-other-keys)
             ;; Note to maintainers: Check ".def =" lines in source.
             (substitute* "config.c"
              (("\\.def = \"cpio\"")
               (string-append ".def = \""
                              (assoc-ref inputs "cpio")
                              "/bin/cpio\""))
              (("\\.def = \"dd\"")
               (string-append ".def = \""
                              (assoc-ref inputs "coreutils")
                              "/bin/dd\""))
              (("\\.def = \"debugfs\"")
               (string-append ".def = \""
                              (assoc-ref inputs "e2fsprogs")
                              "/sbin/debugfs\""))
              (("\\.def = \"e2fsck\"")
               (string-append ".def = \""
                              (assoc-ref inputs "e2fsprogs")
                              "/sbin/e2fsck\""))
              (("\\.def = \"genext2fs\"")
               (string-append ".def = \""
                              (assoc-ref inputs "genext2fs")
                              "/bin/genext2fs\""))
              (("\\.def = \"genisoimage\"")
               (string-append ".def = \""
                              (assoc-ref inputs "cdrkit-libre")
                              "/bin/genisoimage\""))
              (("\\.def = \"mcopy\"")
               (string-append ".def = \""
                              (assoc-ref inputs "mtools")
                              "/bin/mcopy\""))
              (("\\.def = \"mmd\"")
               (string-append ".def = \""
                              (assoc-ref inputs "mtools")
                              "/bin/mmd\""))
              ;;; Note: mkcramfs is obsolete.
              (("\\.def = \"mkdosfs\"")
               (string-append ".def = \""
                              (assoc-ref inputs "dosfstools")
                              "/sbin/mkfs.fat\""))
              (("\\.def = \"mke2fs\"")
               (string-append ".def = \""
                              (assoc-ref inputs "e2fsprogs")
                              "/sbin/mke2fs\""))
              (("\\.def = \"mkfs\\.jffs2\"")
               (string-append ".def = \""
                              (assoc-ref inputs "mtd-utils")
                              "/sbin/mkfs.jffs2\""))
              (("\\.def = \"mkfs\\.ubifs\"")
               (string-append ".def = \""
                              (assoc-ref inputs "mtd-utils")
                              "/sbin/mkfs.ubifs\""))
              (("\\.def = \"mksquashfs\"")
               (string-append ".def = \""
                              (assoc-ref inputs "squashfs-tools")
                              "/bin/mksquashfs\""))
              (("\\.def = \"qemu-img\"")
               (string-append ".def = \""
                              (assoc-ref inputs "qemu")
                              "/bin/qemu-img\""))
              (("\\.def = \"tar\"")
               (string-append ".def = \""
                              (assoc-ref inputs "tar")
                              "/bin/tar\""))
              (("\\.def = \"tune2fs\"")
               (string-append ".def = \""
                              (assoc-ref inputs "e2fsprogs")
                              "/sbin/tune2fs\""))
              (("\\.def = \"ubinize\"")
               (string-append ".def = \""
                              (assoc-ref inputs "mtd-utils")
                              "/sbin/ubinize\""))
              (("\\.def = \"mkimage\"")
               (string-append ".def = \""
                              (assoc-ref inputs "u-boot-tools")
                              "/bin/mkimage\"")))
             (substitute* "test/basic-images.test"
              ;; Work around bug in sharness.sh.
              (("mkdosfs")
               "mkfs.fat")
              ;; Work around bug in sharness.sh.
              (("dd,mkfs\\.fat,mcopy")
               "dd,mkfs_fat,mcopy")
              ;; Should be in the next upstream release.
              (("qemu_img") "qemu-img"))
             (substitute* "util.c"
              (("\"/bin/sh\"")
               (string-append "\"" (assoc-ref inputs "bash") "/bin/sh\"")))
             ;; We don't have /etc/passwd so uid 0 is not known as "root".
             ;; Thus patch it out.
             (substitute* '("test/ext2test.dump"
                            "test/ext3test.dump"
                            "test/ext4test.dump"
                            "test/ext2test-percent.dump"
                            "test/mke2fs.dump")
              (("root") "unknown"))
             #t))
         (add-before 'check 'setenv-check
           (lambda _
             ;; Our container doesn't provide access to /etc/mtab
             (setenv "EXT2FS_NO_MTAB_OK" "1")
             ;; Make test reproducible
             (setenv "GENIMAGE_MKFJFFS2" "mkfs.jffs2 -U")
             (setenv "GENIMAGE_MKE2FS" "mke2fs -E no_copy_xattrs")
             #t))
         (replace 'check
           (lambda _
             (invoke "make" "TEST_LOG_COMPILER=" "check"))))))
    (native-inputs
     `(("autoconf" ,autoconf)
       ("automake" ,automake)
       ;;; Note: cramfs is obsolete.
       ("dtc" ,dtc) ; for the tests
       ("pkg-config" ,pkg-config)
       ("util-linux" ,util-linux))) ; for the tests
    (inputs
     `(("bash" ,bash)
       ("cdrkit-libre" ,cdrkit-libre)
       ("cpio" ,cpio)
       ;; Note: invoked by final executable.
       ("coreutils" ,coreutils) ; chmod, dd
       ("dosfstools" ,dosfstools)
       ("e2fsprogs" ,e2fsprogs)
       ("genext2fs" ,genext2fs)
       ("libconfuse" ,libconfuse)
       ("mtd-utils" ,mtd-utils)
       ("mtools" ,mtools)
       ("qemu" ,qemu-minimal)
       ("squashfs-tools" ,squashfs-tools)
       ("tar" ,tar)
       ("u-boot-tools" ,u-boot-tools)))
    (synopsis "Create Flash images according to specification")
    (description "@command{genimage} creates Flash images according to a
specification file.")
    (home-page "https://github.com/pengutronix/genimage")
    (license license:gpl2)))