;;; /***************************************************************************
;;; *
;;; *
;;; * Copyright (C) 2016, 2017, 2018 Nils Gillmann <gillmann@gnunet.org>.
;;; *
;;; * This file is an appendum to gnURL, based on cURL/libcurl.
;;; *
;;; * This software is licensed as described in the file COPYING, which
;;; * you should have received as part of this distribution. The terms
;;; * are also available at https://curl.haxx.se/docs/copyright.html.
;;; *
;;; * You may opt to use, copy, modify, merge, publish, distribute and/or sell
;;; * copies of the Software, and permit persons to whom the Software is
;;; * furnished to do so, under the terms of the COPYING file.
;;; *
;;; * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
;;; * KIND, either express or implied.
;;; *
;;; ***************************************************************************/


(use-modules
 (ice-9 popen)
 (ice-9 match)
 (ice-9 rdelim)
 (srfi srfi-1)
 (guix packages)
 (guix build-system gnu)
 (guix gexp)
 (guix utils)
 ((guix build utils) #:select (with-directory-excursion))
 (gnu packages)
 (gnu packages base)
 (gnu packages autotools)
 (gnu packages gnunet)
 (gnu packages libidn))

(define %source-dir (dirname (current-filename)))

(define-public gnurl-git
  (package
    (inherit gnurl)
    (name "gnurl-git")
    (version (string-append "7.61.1-" "dev"))
    (source
     (local-file %source-dir
                 #:recursive? #t))
    (native-inputs
     `(("autoconf" ,autoconf)
       ("automake" ,automake)
       ,@(package-native-inputs gnurl)))
    (arguments
     ;;`(;#:configure-flags '("--enable-gnurl")
     `(#:configure-flags '("--disable-ntlm-wb")
       #:test-target "test"
       #:parallel-tests? #f
       #:phases
       ;; We have to patch runtests.pl in tests/ directory
       (modify-phases %standard-phases
         (add-after 'unpack 'autoconf
           (lambda _
             (zero? (system* "sh" "buildconf"))))
         (add-after 'install 'move-man3-pages
           (lambda* (#:key outputs #:allow-other-keys)
             ;; Move section 3 man pages to "doc".
             (let ((out (assoc-ref outputs "out"))
                   (doc (assoc-ref outputs "doc")))
               (mkdir-p (string-append doc "/share/man"))
               (rename-file (string-append out "/share/man/man3")
                            (string-append doc "/share/man/man3"))
               #t)))
         (replace 'check
           (lambda _
             ;; It is unclear why test1026 fails, however the content of it
             ;; suggests that it is not vital for gnurl.
             ;;(delete-file "tests/data/test1026")

             (substitute* "tests/runtests.pl"
               (("/bin/sh") (which "sh")))

             ;; Make test output more verbose.
             (zero? (system* "make" "-C" "tests" "test"))
             #t)))))))
           ;; (add-after 'build 'dist
           ;;   (lambda _
           ;;     (zero? (system* "maketgz" "7.56.0-dev"))))))))))
           ;; (add-after 'check 'dist-check
           ;;   (lambda _
           ;;     (zero? (system* "make" "distcheck"))))))))))

gnurl-git
