root/sil.scm

(define-module (hidamari-blue sil)
  #:use-module (guix packages)
  #:use-module (guix utils)
  #:use-module (guix download)
  #:use-module (guix build-system gnu)
  #:use-module (guix build-system cmake)
  #:use-module ((guix licenses) #:renamer (symbol-prefix-proc 'license:))
  #:use-module (gnu packages)
  #:use-module (gnu packages pkg-config)
  #:use-module (gnu packages ncurses)
  #:use-module (gnu packages compression)
  #:use-module (gnu packages xorg))

;;; status: its playable, but some cache files can't be in initalized, and the tutorial is not installed
;;; TODO: style with guix-devel mode

(define-public sil
  (package
   (name "sil")
   (version "1.30")
   (source
    (origin (method url-fetch/zipbomb)
            (uri (string-append "http://www.amirrorclear.net/flowers/game/sil/Sil-"
                                "130"
                                "-src.zip"))
            (sha256
             (base32
              "0gh9gp7y6bqv8vgykppghcqn6jq1fpmls0yc30v8alv02pqk2h07"))
            (modules '((guix build utils)))
            (snippet
             '(begin
                ;; delete sound files because of unclear licencing,
                ;; they only seem to be used in the osx builds anyway.
                ;; copying.txt says:
                ;; * the sounds are freeware, whatever that means.
                (delete-file-recursively "Sil/lib/xtra/sound/")

                ;; fixes tutorial when USE_PRIVATE_SAVE_PATH is used
                (substitute* "Sil/src/main.c"
                             ;; "Sil/src/main-crb.c"
                             ;; "Sil/src/main-coca-NMcC.m"
                             ;; "Sil/src/main-coca-win.c"
                             (("ANGBAND_DIR_APEX, \"tutorial\"")
                              "ANGBAND_DIR_XTRA, \"tutorial\""))
                (rename-file "Sil/lib/apex/tutorial" "Sil/lib/xtra/tutorial")

                ;; fixes data when installing to readonly directory
                (substitute* "Sil/src/init2.c"
                             (("path_build\\(buf, sizeof\\(buf\\), ANGBAND_DIR_USER, \"scores\"\\);")
                              "
path_build(buf, sizeof(buf), ANGBAND_DIR_USER, \"data\");
ANGBAND_DIR_DATA = string_make(buf);

path_build(buf, sizeof(buf), ANGBAND_DIR_USER, \"scores\");"))
                (substitute* "Sil/src/main.c"
                             (("#ifdef USE_PRIVATE_SAVE_PATH")
                              "#ifdef USE_PRIVATE_SAVE_PATH
    path_build(dirpath, sizeof(dirpath), subdirpath, \"data\");
    mkdir(dirpath, 0700);"))

                (substitute* "Sil/src/config.h"
                             ;; TODO is this a bug?
                             (("# ifdef PRIVATE_USER_PATH")
                              "# ifndef PRIVATE_USER_PATH"))))))
   (build-system gnu-build-system)
   (arguments '(#:tests?
                #f
                #:make-flags (let* ((out (assoc-ref %outputs "out")))
                               ;; disable the default terminal mode, only pick x11
                               ;; GCU termnial mode uses the outdated libcurses
                               (list
                                (string-append "CFLAGS= -Wall -O1 -pipe -g -D\"USE_X11\" -DPRIVATE_USER_PATH=\\\"~/.sil\\\" -DDEFAULT_PATH=\\\"" out "/share/sil\\\" -DUSE_PRIVATE_SAVE_PATH=1")
                                "LIBS= -lX11"
                                "-Csrc"
                                "-f" "Makefile.std")
                               )
                #:phases
                (modify-phases %standard-phases
                               (add-after 'unpack 'move-to-right-dir
                                          (lambda* (#:key source #:allow-other-keys)
                                            ;; use fetch/zipbomb to avoid __MACOSX dir
                                            (chdir "Sil")))
                               (delete 'configure)
                               (replace 'install
                                        (lambda* (#:key outputs version name #:allow-other-keys)
                                          ;; TODO get actual name and version from package
                                          (define name "sil")
                                          (define version "1.30")
                                          (let ((out (assoc-ref outputs "out")))
                                            (mkdir-p (string-append out "/bin"))
                                            (mkdir-p (string-append out "/share/sil"))
                                            (mkdir-p (string-append out "/share/doc/sil"))

                                            (substitute* "silx"
                                                         (("/bin/sh")
                                                          (which "bash"))
                                                         (("./sil")
                                                          (string-append out "/bin/" name)))

                                            (copy-file "src/sil" (string-append out "/bin/" name))
                                            (copy-file "silx" (string-append out "/bin/" name "x"))
                                            (copy-recursively "lib" (string-append out "/share/sil"))
                                            (copy-file (string-append "Sil " "1.3" " Manual.pdf")
                                                       (string-append out "/share/doc/sil/Manual.pdf"))
                                            ))))))
   (inputs `(("libx11" ,libx11)))
   (native-inputs `(("unzip" ,unzip)))
   (synopsis "tactical roguelike adventure game")
   (description "Sil is a computer role-playing game with a strong emphasis on
discovery and tactical combat. It has a simple but rich combat system which
allows for a great variety of choice.")
   (home-page "http://www.amirrorclear.net/flowers/game/sil/")
   (license (list license:gpl2          ; src is dual licenced with the angband license
                  license:public-domain ; 16x16 graphics
                  license:cc-by-sa3.0   ; 32x32 graphics
                  license:x11-style     ; the fonts have various x11-style licenses
                  ))))

;; (define-public sil-q
;;   (let ((commit "398947f1ced65f1be1213b7e232bd6a2e2f78d28"))
;;     (package
;;      (name "sil-q")
;;      (version "1.3.2")
;;      (inherit sil)
;;      (origin (method git-fetch)
;;              (uri (url "https://github.com/sil-quirk/sil-q")
;;                   (commit commit)))
;;      (arguments (append
;;                  '(#:phases
;;                    (modify-phases (package-phases sil)
;;                                   (remove 'move-to-right-dir)))
;;                  (package-arguments sil))))))