(define-module (snam-butler)
  #:use-module ((guix licenses) #:prefix license:)
  #:use-module (guix packages)
  #:use-module (guix download)
  #:use-module (guix utils)
  #:use-module (gnu packages base)
  #:use-module (gnu packages compression)
  #:use-module (gnu packages gcc)
  #:use-module (nonguix build-system binary))


(use-modules (srfi srfi-8)
             (web client)
             (web response)
             (web uri))

(define-public snam-butler
  (package
   (name "snam-butler")
   (version "15.21.0")
   (source (origin
            (method url-fetch)
            (uri (uri->string
                  (receive (response _txt) (http-get (string-append "https://broth.itch.zone/butler/linux-amd64/" version "/archive/default"))
                    (response-location response))))
            (sha256
             (base32
              "071frbwjclb0g9gkfh2lxcbkk4c57jhppr8f3dhcgbswvvmgqh5n"))))
   (build-system binary-build-system)
   (supported-systems '("x86_64-linux"))
   (arguments
    `(#:patchelf-plan
      `(("butler"
         ("libc" "zlib" "libstdc++")))
      #:install-plan
      `(("." ("butler") "bin/"))
      #:phases
      (modify-phases %standard-phases
        	     ;; this is required because standard unpack expects
        	     ;; the archive to contain a directory with everything inside it,
        	     ;; while butler's release .tar.gz only contains the `bb` binary.
        	     (replace 'unpack
        		      (lambda* (#:key inputs #:allow-other-keys)
        			(system* (which "tar")
        				 "-xzf"
        				 (assoc-ref inputs "source"))
        			#t)))
      ))
   (inputs
    `(("zlib" ,zlib)))
   (native-inputs
    `(("tar" ,tar)))
   (synopsis "The tool provided by itch.io to manage your itch.io games and tools")
   (description
    "butler is a small command-line tool that lets you:

- Upload builds of your games quickly & reliably to itch.io
- Generate patches and apply them offline
- Run a few other utility commands")
   (home-page "https://itch.io/docs/butler/")
   (license license:expat)))

snam-butler
