gnu: xonotic: Further explore the concept of iteration.

* gnu/packages/games.scm (xonotic)[arguments]: Use FOR-EACH in the
'install-binaries and renamed 'install-desktop-entries phases.  Use
FIND-FILES in the 'install-icons phase.  Use both in 'wrap-binaries for
brevity (and SRFI-26 for fun).  Symlink ‘xonotic’ after wrapping, so we
don't double-wrap it.
This commit is contained in:
Tobias Geerinckx-Rice 2022-08-07 02:00:00 +02:00
parent 642a3e3d7a
commit 5dee2fdae7
No known key found for this signature in database
GPG key ID: 0DB0FF884F556D79

View file

@ -7810,6 +7810,9 @@ (define-public xonotic
(list #:configure-flags (list #:configure-flags
#~(list (string-append "--prefix=" #$output) #~(list (string-append "--prefix=" #$output)
"--disable-rijndael") "--disable-rijndael")
#:modules '((guix build gnu-build-system)
(guix build utils)
(srfi srfi-26))
#:phases #:phases
#~(modify-phases %standard-phases #~(modify-phases %standard-phases
(add-before 'configure 'build-darkplaces (add-before 'configure 'build-darkplaces
@ -7841,105 +7844,66 @@ (define-public xonotic
(data (assoc-ref inputs "xonotic-data"))) (data (assoc-ref inputs "xonotic-data")))
(symlink (string-append data "/share/xonotic") (symlink (string-append data "/share/xonotic")
(string-append out "/share/xonotic"))))) (string-append out "/share/xonotic")))))
(add-after 'install 'install-desktop-entry (add-after 'install 'install-desktop-entries
(lambda* (#:key outputs #:allow-other-keys) (lambda* (#:key outputs #:allow-other-keys)
;; Add .desktop files for the 2 variants and the symlink. (let* ((out (assoc-ref outputs "out"))
(let* ((output (assoc-ref outputs "out")) (app (string-append out "/share/applications")))
(apps (string-append output "/share/applications"))) ;; Add .desktop files for the 2 variants and the symlink.
(mkdir-p apps) (for-each
(with-output-to-file (lambda (variant)
(string-append apps "/xonotic-glx.desktop") (let* ((file (if variant
(lambda _ (format #f "xonotic-~(~a~)" variant)
(format #t "xonotic"))
"[Desktop Entry]~@ (name (if variant
Name=xonotic-glx~@ (format #f "Xonotic (~a)" variant)
Comment=Xonotic glx~@ "Xonotic"))
Exec=~a/bin/xonotic-glx~@ (exec (string-append out "/bin/" file)))
TryExec=~@*~a/bin/xonotic-glx~@ (make-desktop-entry-file
Icon=xonotic~@ (string-append app "/" file ".desktop")
Categories=Game~@ #:name name
Type=Application~%" #:comment `((#f #$(package-synopsis this-package)))
output))) #:exec exec
(with-output-to-file #:try-exec exec
(string-append apps "/xonotic-sdl.desktop") #:icon "xonotic"
(lambda _ #:categories '("Game"))))
(format #t (list #f "GLX" "SDL")))))
"[Desktop Entry]~@
Name=xonotic-sdl~@
Comment=Xonotic sdl~@
Exec=~a/bin/xonotic-sdl~@
TryExec=~@*~a/bin/xonotic-sdl~@
Icon=xonotic~@
Categories=Game~@
Type=Application~%"
output)))
(with-output-to-file
(string-append apps "/xonotic.desktop")
(lambda _
(format #t
"[Desktop Entry]~@
Name=xonotic~@
Comment=Xonotic~@
Exec=~a/bin/xonotic-glx~@
TryExec=~@*~a/bin/xonotic~@
Icon=xonotic~@
Categories=Game~@
Type=Application~%"
output))))))
(add-after 'install 'install-icons (add-after 'install 'install-icons
(lambda* (#:key outputs #:allow-other-keys) (lambda* (#:key outputs #:allow-other-keys)
(let ((out (assoc-ref outputs "out"))) (let ((out (assoc-ref outputs "out")))
(with-directory-excursion "../../misc/logos/icons_png/" (for-each
(for-each (lambda (file)
(lambda (file) (let* ((size (string-filter char-numeric? file))
(let* ((size (string-filter char-numeric? file)) (icons (string-append out "/share/icons/hicolor/"
(icons (string-append out "/share/icons/hicolor/" size "x" size "/apps")))
size "x" size "/apps"))) (mkdir-p icons)
(mkdir-p icons) (copy-file file (string-append icons "/xonotic.png"))))
(copy-file file (string-append icons "/xonotic.png")))) (find-files "../../misc/logos/icons_png"
'("xonotic_16.png" "xonotic_22.png" "xonotic_24.png" "^xonotic_[0-9]+\\.png$")))))
"xonotic_32.png" "xonotic_48.png" "xonotic_64.png"
"xonotic_128.png" "xonotic_256.png" "xonotic_512.png"))))))
(add-after 'install 'install-binaries (add-after 'install 'install-binaries
(lambda* (#:key outputs #:allow-other-keys) (lambda* (#:key outputs #:allow-other-keys)
(let ((out (assoc-ref outputs "out")))
(define (install src dst)
(let ((dst (string-append out dst)))
(mkdir-p (dirname dst))
(copy-file src dst)))
(mkdir-p (string-append out "/bin"))
(install "../darkplaces/darkplaces-dedicated"
"/bin/xonotic-dedicated")
(install "../darkplaces/darkplaces-glx"
"/bin/xonotic-glx")
(install "../darkplaces/darkplaces-sdl"
"/bin/xonotic-sdl")
;; Provide a default xonotic executable, defaulting to SDL.
(symlink (string-append out "/bin/xonotic-sdl")
(string-append out "/bin/xonotic")))))
(add-after 'install-binaries 'wrap
(lambda* (#:key outputs inputs #:allow-other-keys)
;; Curl and libvorbis need to be wrapped so that we get
;; sound and networking.
(let* ((out (assoc-ref outputs "out")) (let* ((out (assoc-ref outputs "out"))
(bin (string-append out "/bin/xonotic")) (bin (string-append out "/bin")))
(bin-sdl (string-append out "/bin/xonotic-sdl")) (for-each
(bin-glx (string-append out "/bin/xonotic-glx")) (lambda (variant)
(bin-dedicated (string-append out "/bin/xonotic-dedicated")) (copy-file
(string-append "../darkplaces/darkplaces-" variant)
(string-append bin "/xonotic-" variant)))
(list "dedicated" "glx" "sdl")))))
(add-after 'install-binaries 'wrap-binaries
(lambda* (#:key outputs inputs #:allow-other-keys)
;; All games must be wrapped to get sound and networking.
(let* ((out (assoc-ref outputs "out"))
(bin (string-append out "/bin"))
(curl (assoc-ref inputs "curl")) (curl (assoc-ref inputs "curl"))
(vorbis (assoc-ref inputs "libvorbis"))) (vorbis (assoc-ref inputs "libvorbis")))
(wrap-program bin (for-each (cut wrap-program <>
`("LD_LIBRARY_PATH" ":" prefix `("LD_LIBRARY_PATH" ":" prefix
(,(string-append curl "/lib:" vorbis "/lib")))) (,(string-append curl "/lib:"
(wrap-program bin-sdl vorbis "/lib"))))
`("LD_LIBRARY_PATH" ":" prefix (find-files bin "^xonotic"))
(,(string-append curl "/lib:" vorbis "/lib"))))
(wrap-program bin-glx ;; Provide a default xonotic executable, defaulting to SDL.
`("LD_LIBRARY_PATH" ":" prefix (symlink "xonotic-sdl" (string-append bin "/xonotic"))))))))
(,(string-append curl "/lib:" vorbis "/lib"))))
(wrap-program bin-dedicated
`("LD_LIBRARY_PATH" ":" prefix
(,(string-append curl "/lib:" vorbis "/lib"))))))))))
(native-inputs (native-inputs
(list autoconf (list autoconf
automake automake