Merge branch 'staging' into core-updates
[jackhill/guix/guix.git] / gnu / packages / sdl.scm
1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2013, 2015, 2017 David Thompson <dthompson2@worcester.edu>
3 ;;; Copyright © 2014 Mark H Weaver <mhw@netris.org>
4 ;;; Copyright © 2015, 2017 Sou Bunnbu <iyzsong@member.fsf.org>
5 ;;; Copyright © 2015 Alex Kost <alezost@gmail.com>
6 ;;; Copyright © 2016, 2017 Efraim Flashner <efraim@flashner.co.il>
7 ;;; Copyright © 2017, 2018, 2019 Rutger Helling <rhelling@mykolab.com>
8 ;;; Copyright © 2018, 2019 Tobias Geerinckx-Rice <me@tobias.gr>
9 ;;; Copyright © 2018, 2019 Ricardo Wurmus <rekado@elephly.net>
10 ;;; Copyright © 2019 Kei Kebreau <kkebreau@posteo.net>
11 ;;; Copyright © 2019 Nicolas Goaziou <mail@nicolasgoaziou.fr>
12 ;;; Copyright © 2019 Marius Bakke <mbakke@fastmail.com>
13 ;;;
14 ;;; This file is part of GNU Guix.
15 ;;;
16 ;;; GNU Guix is free software; you can redistribute it and/or modify it
17 ;;; under the terms of the GNU General Public License as published by
18 ;;; the Free Software Foundation; either version 3 of the License, or (at
19 ;;; your option) any later version.
20 ;;;
21 ;;; GNU Guix is distributed in the hope that it will be useful, but
22 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
23 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 ;;; GNU General Public License for more details.
25 ;;;
26 ;;; You should have received a copy of the GNU General Public License
27 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
28
29 (define-module (gnu packages sdl)
30 #:use-module (ice-9 match)
31 #:use-module (srfi srfi-1)
32 #:use-module (srfi srfi-26)
33 #:use-module (gnu packages)
34 #:use-module ((guix licenses) #:hide (freetype))
35 #:use-module (guix packages)
36 #:use-module (guix download)
37 #:use-module (guix utils)
38 #:use-module (guix build-system gnu)
39 #:use-module (guix build-system trivial)
40 #:use-module (gnu packages audio)
41 #:use-module (gnu packages fcitx)
42 #:use-module (gnu packages fontutils)
43 #:use-module (gnu packages freedesktop)
44 #:use-module (gnu packages glib)
45 #:use-module (gnu packages guile)
46 #:use-module (gnu packages ibus)
47 #:use-module (gnu packages image)
48 #:use-module (gnu packages linux)
49 #:use-module (gnu packages mp3)
50 #:use-module (gnu packages pkg-config)
51 #:use-module (gnu packages pulseaudio)
52 #:use-module (gnu packages gl)
53 #:use-module (gnu packages xdisorg)
54 #:use-module (gnu packages xiph)
55 #:use-module (gnu packages xorg)
56 #:export (sdl-union))
57
58 (define-public sdl
59 (package
60 (name "sdl")
61 (version "1.2.15")
62 (source (origin
63 (method url-fetch)
64 (uri
65 (string-append "https://libsdl.org/release/SDL-"
66 version ".tar.gz"))
67 (sha256
68 (base32
69 "005d993xcac8236fpvd1iawkz4wqjybkpn8dbwaliqz5jfkidlyn"))
70 (patches (search-patches "sdl-libx11-1.6.patch"))))
71 (build-system gnu-build-system)
72 (arguments
73 '(;; Explicitly link against shared libraries instead of dlopening them.
74 ;; For X11, ALSA, and PulseAudio.
75 ;; OpenGL library is still dlopened at runtime.
76 #:configure-flags '("--disable-alsa-shared"
77 "--disable-pulseaudio-shared"
78 "--disable-x11-shared"
79 ;; Explicitly link with mesa.
80 ;; This add mesa to libsdl's RUNPATH, to make dlopen
81 ;; finding the libGL from mesa at runtime.
82 "LDFLAGS=-lGL")
83
84 #:make-flags '("V=1") ;build verbosely
85
86 #:tests? #f)) ; no check target
87 (propagated-inputs
88 ;; SDL headers include X11 headers.
89 `(("libx11" ,libx11)
90 ("libcap" ,libcap) ; 'libSDL.la' contain `-lcap'.
91 ;; TODO: Since building Mesa with Meson it is now necessary that Mesa is
92 ;; a propogated input. We still need to figure out why, possibly due to a
93 ;; change in pkg-config.
94 ("mesa" ,mesa)))
95 (native-inputs `(("pkg-config" ,pkg-config)))
96 (inputs `(("libxrandr" ,libxrandr)
97 ("glu" ,glu)
98 ("alsa-lib" ,alsa-lib)
99 ("pulseaudio" ,pulseaudio)))
100 (outputs '("out" "debug"))
101 (synopsis "Cross platform game development library")
102 (description "Simple DirectMedia Layer is a cross-platform development
103 library designed to provide low level access to audio, keyboard, mouse,
104 joystick, and graphics hardware.")
105 (home-page "https://libsdl.org/")
106 (license lgpl2.1)))
107
108 (define-public sdl2
109 (package (inherit sdl)
110 (name "sdl2")
111 (version "2.0.9")
112 (source (origin
113 (method url-fetch)
114 (uri
115 (string-append "https://libsdl.org/release/SDL2-"
116 version ".tar.gz"))
117 (sha256
118 (base32
119 "1c94ndagzkdfqaa838yqg589p1nnqln8mv0hpwfhrkbfczf8cl95"))))
120 (arguments
121 (substitute-keyword-arguments (package-arguments sdl)
122 ((#:configure-flags flags)
123 `(append '("--disable-wayland-shared" "--enable-video-kmsdrm"
124 "--disable-kmsdrm-shared")
125 ,flags))
126 ((#:make-flags flags ''())
127 ;; Add the Fcitx header files to GCCs "system header" search path
128 ;; in order to suppress compiler warnings induced by those:
129 ;; .../include/fcitx-utils/utarray.h:178:9: error: ISO C90 forbids
130 ;; mixed declarations and code [-Werror=declaration-after-statement]
131 `(append (list (string-append "C_INCLUDE_PATH="
132 (assoc-ref %build-inputs "fcitx")
133 "/include"))
134 ,flags))))
135 (inputs
136 ;; SDL2 needs to be built with ibus support otherwise some systems
137 ;; experience a bug where input events are doubled.
138 ;;
139 ;; For more information, see: https://dev.solus-project.com/T1721
140 (append `(("dbus" ,dbus)
141 ("fcitx" ,fcitx) ; helps with CJK input
142 ("glib" ,glib)
143 ("ibus" ,ibus)
144 ("libxkbcommon" ,libxkbcommon)
145 ("wayland" ,wayland)
146 ("wayland-protocols" ,wayland-protocols))
147 (package-inputs sdl)))
148 (license bsd-3)))
149
150 (define-public libmikmod
151 (package
152 (name "libmikmod")
153 (version "3.3.11.1")
154 (source (origin
155 (method url-fetch)
156 (uri (list
157 (string-append "mirror://sourceforge/mikmod/libmikmod/"
158 version "/libmikmod-" version ".tar.gz")
159 ;; Older versions are sometimes moved to:
160 (string-append "mirror://sourceforge/mikmod/"
161 "outdated_versions/libmikmod/"
162 version "/libmikmod-" version ".tar.gz")))
163 (sha256
164 (base32
165 "06bdnhb0l81srdzg6gn2v2ydhhaazza7rshrcj3q8dpqr3gn97dd"))))
166 (build-system gnu-build-system)
167 (arguments
168 ;; By default, libmikmod tries to dlopen libasound etc., which won't work
169 ;; unless the right libalsa happens to be in $LD_LIBRARY_PATH. Pass
170 ;; '--disable-dl' to avoid that.
171 '(#:configure-flags '("--disable-dl")))
172 (synopsis "Library for module sound formats")
173 (description
174 "MikMod is able to play a wide range of module formats, as well as
175 digital sound files. It can take advantage of particular features of your
176 system, such as sound redirection over the network.")
177 (license lgpl2.1)
178 (home-page "http://mikmod.sourceforge.net/")))
179
180 (define-public sdl-gfx
181 (package
182 (name "sdl-gfx")
183 (version "2.0.26")
184 (source (origin
185 (method url-fetch)
186 (uri
187 (string-append "http://www.ferzkopp.net/Software/SDL_gfx-2.0/SDL_gfx-"
188 version ".tar.gz"))
189 (sha256
190 (base32
191 "0ijljhs0v99dj6y27hc10z6qchyp8gdp4199y6jzngy6dzxlzsvw"))))
192 (build-system gnu-build-system)
193 (outputs '("out" "debug"))
194 (arguments
195 `(,@(if (any (cute string-prefix? <> (or (%current-system)
196 (%current-target-system)))
197 '("x86_64" "i686"))
198 ;; mmx is supported only on Intel processors.
199 '()
200 '(#:configure-flags '("--disable-mmx")))))
201 (propagated-inputs `(("sdl" ,sdl)))
202 (synopsis "SDL graphics primitives library")
203 (description "SDL_gfx provides graphics drawing primitives, rotozoom and
204 other supporting functions for SDL.")
205 (home-page "http://www.ferzkopp.net/joomla/software-mainmenu-14/4-ferzkopps-linux-software/19-sdlgfx")
206 (license zlib)))
207
208 (define-public sdl-image
209 (package
210 (name "sdl-image")
211 (version "1.2.12")
212 (source (origin
213 (method url-fetch)
214 (uri
215 (string-append "https://www.libsdl.org/projects/SDL_image/release/SDL_image-"
216 version ".tar.gz"))
217 (sha256
218 (base32
219 "16an9slbb8ci7d89wakkmyfvp7c0cval8xw4hkg0842nhhlp540b"))))
220 (build-system gnu-build-system)
221 (outputs '("out" "debug"))
222 (arguments
223 ;; Explicitly link against shared libraries instead of dlopening them.
224 '(#:configure-flags '("--disable-jpg-shared"
225 "--disable-png-shared"
226 "--disable-tif-shared"
227 "--disable-webp-shared")))
228 (native-inputs `(("pkg-config" ,pkg-config)))
229 ;; libjpeg, libpng, and libtiff are propagated inputs because the
230 ;; SDL_image headers include the headers of these libraries. SDL is a
231 ;; propagated input because the pkg-config file refers to SDL's pkg-config
232 ;; file.
233 (propagated-inputs `(("sdl" ,sdl)
234 ("libjpeg" ,libjpeg)
235 ("libpng" ,libpng)
236 ("libtiff" ,libtiff)
237 ("libwebp" ,libwebp)))
238 (synopsis "SDL image loading library")
239 (description "SDL_image is an image file loading library for SDL that
240 supports the following formats: BMP, GIF, JPEG, LBM, PCX, PNG, PNM, TGA, TIFF,
241 WEBP, XCF, XPM, and XV.")
242 (home-page "https://www.libsdl.org/projects/SDL_image/")
243 (license zlib)))
244
245 (define-public sdl-mixer
246 (package
247 (name "sdl-mixer")
248 (version "1.2.12")
249 (source (origin
250 (method url-fetch)
251 (uri
252 (string-append "https://www.libsdl.org/projects/SDL_mixer/release/SDL_mixer-"
253 version ".tar.gz"))
254 (sha256
255 (base32
256 "0alrhqgm40p4c92s26mimg9cm1y7rzr6m0p49687jxd9g6130i0n"))))
257 (build-system gnu-build-system)
258 (outputs '("out" "debug"))
259 ;; no check target
260 ;; use libmad instead of smpeg
261 ;; explicitly link against shared libraries instead of dlopening them
262 (arguments `(#:tests? #f
263 #:configure-flags '("--enable-music-mp3-mad-gpl"
264 "--disable-music-mod-shared"
265 "--disable-music-fluidsynth-shared"
266 "--disable-music-ogg-shared"
267 "--disable-music-flac-shared"
268 "--disable-music-mp3-shared")))
269 (inputs `(("libvorbis" ,libvorbis)
270 ("libflac" ,flac)
271 ("libmad" ,libmad)
272 ("libmikmod" ,libmikmod)
273 ("libmodplug" ,libmodplug)))
274 ;; FIXME: Add libfluidsynth
275 (propagated-inputs `(("sdl" ,sdl)))
276 (synopsis "SDL multi-channel audio mixer library")
277 (description "SDL_mixer is a multi-channel audio mixer library for SDL.
278 It supports any number of simultaneously playing channels of 16 bit stereo
279 audio, plus a single channel of music. Supported format include FLAC, MOD,
280 MIDI, Ogg Vorbis, and MP3.")
281 (home-page "https://www.libsdl.org/projects/SDL_mixer/")
282 (license zlib)))
283
284 (define-public sdl-net
285 (package
286 (name "sdl-net")
287 (version "1.2.8")
288 (source (origin
289 (method url-fetch)
290 (uri
291 (string-append "https://www.libsdl.org/projects/SDL_net/release/SDL_net-"
292 version ".tar.gz"))
293 (sha256
294 (base32
295 "1d5c9xqlf4s1c01gzv6cxmg0r621pq9kfgxcg3197xw4p25pljjz"))))
296 (build-system gnu-build-system)
297 (propagated-inputs `(("sdl" ,sdl)))
298 (native-inputs `(("pkg-config" ,pkg-config)))
299 (outputs '("out" "debug"))
300 (synopsis "SDL networking library")
301 (description "SDL_net is a small, cross-platform networking library for
302 SDL.")
303 (home-page "https://www.libsdl.org/projects/SDL_net/")
304 (license zlib)))
305
306 (define-public sdl-ttf
307 (package
308 (name "sdl-ttf")
309 (version "2.0.11")
310 (source (origin
311 (method url-fetch)
312 (uri
313 (string-append "https://www.libsdl.org/projects/SDL_ttf/release/SDL_ttf-"
314 version ".tar.gz"))
315 (sha256
316 (base32
317 "1dydxd4f5kb1288i5n5568kdk2q7f8mqjr7i7sd33nplxjaxhk3j"))))
318 (build-system gnu-build-system)
319 (propagated-inputs `(("sdl" ,sdl)))
320 (inputs `(("freetype" ,freetype)
321 ("mesa" ,mesa)))
322 (native-inputs `(("pkg-config" ,pkg-config)))
323 (outputs '("out" "debug"))
324 (synopsis "SDL TrueType font library")
325 (description "SDL_ttf is a TrueType font rendering library for SDL.")
326 (home-page "https://www.libsdl.org/projects/SDL_ttf/")
327 (license zlib)))
328
329 (define* (sdl-union #:optional (packages (list sdl sdl-gfx sdl-net sdl-ttf
330 sdl-image sdl-mixer)))
331 "Return 'sdl-union' package which is a union of PACKAGES.
332 If PACKAGES are not specified, all SDL packages are used."
333 (package
334 (name "sdl-union")
335 (version (package-version sdl))
336 (source #f)
337 (build-system trivial-build-system)
338 (arguments
339 '(#:modules ((guix build union))
340 #:builder (begin
341 (use-modules (ice-9 match)
342 (guix build union))
343 (match %build-inputs
344 (((names . directories) ...)
345 (union-build (assoc-ref %outputs "out")
346 directories)
347 #t)))))
348 (inputs (map (lambda (package)
349 (list (package-name package) package))
350 packages))
351 (synopsis "Union of SDL libraries")
352 (description
353 "A union of SDL and its extension libraries. A union is required because
354 sdl-config assumes that all of the headers and libraries are in the same
355 directory.")
356 (home-page (package-home-page sdl))
357 (license (package-license sdl))))
358
359 (define (propagated-inputs-with-sdl2 package)
360 "Replace the \"sdl\" propagated input of PACKAGE with SDL2."
361 (map (match-lambda
362 (("sdl" _)
363 `("sdl2" ,sdl2))
364 (other other))
365 (package-propagated-inputs package)))
366
367 (define-public sdl2-gfx
368 (package (inherit sdl-gfx)
369 (name "sdl2-gfx")
370 (version "1.0.4")
371 (source (origin
372 (method url-fetch)
373 (uri
374 (string-append "https://www.ferzkopp.net/Software/SDL2_gfx/SDL2_gfx-"
375 version ".tar.gz"))
376 (sha256
377 (base32
378 "0qk2ax7f7grlxb13ba0ll3zlm8780s7j8fmrhlpxzjgdvldf1q33"))))
379 (propagated-inputs
380 (propagated-inputs-with-sdl2 sdl-gfx))))
381
382 (define-public sdl2-image
383 (package (inherit sdl-image)
384 (name "sdl2-image")
385 (version "2.0.4")
386 (source
387 (origin
388 (method url-fetch)
389 (uri
390 (string-append "https://www.libsdl.org/projects/SDL_image/release/"
391 "SDL2_image-" version ".tar.gz"))
392 (sha256
393 (base32 "1b6f7002bm007y3zpyxb5r6ag0lml51jyvx1pwpj9sq24jfc8kp7"))))
394 (propagated-inputs
395 (propagated-inputs-with-sdl2 sdl-image))))
396
397 (define-public sdl2-mixer
398 (package (inherit sdl-mixer)
399 (name "sdl2-mixer")
400 (version "2.0.4")
401 (source
402 (origin
403 (method url-fetch)
404 (uri
405 (string-append "http://www.libsdl.org/projects/SDL_mixer/release/"
406 "SDL2_mixer-" version ".tar.gz"))
407 (modules '((guix build utils)))
408 (snippet '(begin
409 ;; Remove bundled libraries.
410 (delete-file-recursively "external")
411 #t))
412 (sha256
413 (base32 "0694vsz5bjkcdgfdra6x9fq8vpzrl8m6q96gh58df7065hw5mkxl"))))
414 (propagated-inputs
415 (propagated-inputs-with-sdl2 sdl-mixer))))
416
417 (define-public sdl2-net
418 (package (inherit sdl-net)
419 (name "sdl2-net")
420 (version "2.0.1")
421 (source
422 (origin
423 (method url-fetch)
424 (uri
425 (string-append "http://www.libsdl.org/projects/SDL_net/release/"
426 "SDL2_net-" version ".tar.gz"))
427 (sha256
428 (base32
429 "08cxc1bicmyk89kiks7izw1rlx5ng5n6xpy8fy0zxni3b9z8mkhm"))))
430 (propagated-inputs
431 (propagated-inputs-with-sdl2 sdl-net))))
432
433 (define-public sdl2-ttf
434 (package (inherit sdl-ttf)
435 (name "sdl2-ttf")
436 (version "2.0.15")
437 (source (origin
438 (method url-fetch)
439 (uri
440 (string-append "https://www.libsdl.org/projects/SDL_ttf/release/SDL2_ttf-"
441 version ".tar.gz"))
442 (modules '((guix build utils)))
443 (snippet (begin
444 ;; Remove bundled libraries.
445 '(delete-file-recursively "external")
446 #t))
447 (sha256
448 (base32
449 "0cyd48dipc0m399qy8s03lci8b0bpiy8xlkvrm2ia7wcv0dfpv59"))))
450 (propagated-inputs
451 (propagated-inputs-with-sdl2 sdl-ttf))))
452
453 (define-public guile-sdl
454 (package
455 (name "guile-sdl")
456 (version "0.5.2")
457 (source (origin
458 (method url-fetch)
459 (uri
460 (string-append "mirror://gnu/guile-sdl/guile-sdl-"
461 version ".tar.xz"))
462 (sha256
463 (base32
464 "0cjgs012a9922hn6xqwj66w6qmfs3nycnm56hyykx5n3g5p7ag01"))))
465 (build-system gnu-build-system)
466 (native-inputs
467 `(("pkg-config" ,pkg-config)
468 ;; Required by test suite.
469 ("xorg-server" ,xorg-server)
470 ("libjpeg" ,libjpeg)))
471 (inputs
472 `(("guile" ,guile-2.2)
473 ("sdl-union" ,(sdl-union))))
474 (arguments
475 '(#:configure-flags
476 (list (string-append "--with-sdl-prefix="
477 (assoc-ref %build-inputs "sdl-union")))
478 #:modules ((ice-9 popen)
479 (guix build utils)
480 (guix build gnu-build-system))
481
482 #:parallel-build? #f ; parallel build fails
483
484 #:phases
485 (modify-phases %standard-phases
486 (add-before 'configure 'fix-env-and-patch
487 (lambda* (#:key inputs #:allow-other-keys)
488 (setenv "GUILE_AUTO_COMPILE" "0")
489 ;; SDL_image needs to dlopen libjpeg in the test suite.
490 (setenv "LD_LIBRARY_PATH"
491 (string-append (assoc-ref inputs "libjpeg") "/lib"))
492
493 ;; Change the site directory /site/X.Y like Guile expects.
494 (substitute* "build-aux/guile-baux/re-prefixed-site-dirs"
495 (("\"/site\"")
496 (let ((effective
497 (read
498 (open-pipe* OPEN_READ
499 "guile" "-c"
500 "(write (effective-version))"))))
501 (string-append "\"/site/" effective "\""))))
502
503 ;; Skip tests that rely on sound support, which is unavailable in
504 ;; the build environment.
505 (substitute* "test/Makefile.in"
506 (("HAVE_MIXER = .*$")
507 "HAVE_MIXER = 0\n"))
508 #t))
509 (add-before 'check 'start-xorg-server
510 (lambda* (#:key inputs #:allow-other-keys)
511 ;; The test suite requires a running X server.
512 (system (format #f "~a/bin/Xvfb :1 &"
513 (assoc-ref inputs "xorg-server")))
514 (setenv "DISPLAY" ":1")
515 #t))
516 (add-before 'check 'skip-cursor-test
517 (lambda _
518 ;; XXX: This test sometimes enters an endless loop, and sometimes
519 ;; crashes with:
520 ;; guile: xcb_io.c:147: append_pending_request: Assertion `!xcb_xlib_unknown_seq_number' failed.
521 ;; Skip it.
522 (substitute* "test/cursor.scm"
523 (("\\(SDL:init .*" all)
524 (string-append "(exit 77) ;" all "\n")))
525 #t)))))
526 (synopsis "Guile interface for SDL (Simple DirectMedia Layer)")
527 (description "Guile-SDL is a set of bindings to the Simple DirectMedia
528 Layer (SDL). With them, Guile programmers can have easy access to graphics,
529 sound and device input (keyboards, joysticks, mice, etc.).")
530 (home-page "https://www.gnu.org/software/guile-sdl/")
531 (license gpl3+)))
532
533 (define-public guile-sdl2
534 (package
535 (name "guile-sdl2")
536 (version "0.4.0")
537 (source (origin
538 (method url-fetch)
539 (uri (string-append "https://files.dthompson.us/guile-sdl2/"
540 "guile-sdl2-" version ".tar.gz"))
541 (sha256
542 (base32
543 "0zcxwgyadwpbhq6h5mv2569c3kalgra26zc186y9fqiyyzmh1v9s"))))
544 (build-system gnu-build-system)
545 (arguments
546 '(#:make-flags '("GUILE_AUTO_COMPILE=0")
547 #:configure-flags
548 (list (string-append "--with-libsdl2-prefix="
549 (assoc-ref %build-inputs "sdl2"))
550 (string-append "--with-libsdl2-image-prefix="
551 (assoc-ref %build-inputs "sdl2-image"))
552 (string-append "--with-libsdl2-ttf-prefix="
553 (assoc-ref %build-inputs "sdl2-ttf"))
554 (string-append "--with-libsdl2-mixer-prefix="
555 (assoc-ref %build-inputs "sdl2-mixer")))))
556 (native-inputs
557 `(("guile" ,guile-2.2)
558 ("pkg-config" ,pkg-config)))
559 (inputs
560 `(("sdl2" ,sdl2)
561 ("sdl2-image" ,sdl2-image)
562 ("sdl2-mixer" ,sdl2-mixer)
563 ("sdl2-ttf" ,sdl2-ttf)))
564 (synopsis "Guile bindings for SDL2")
565 (home-page "https://dthompson.us/projects/guile-sdl2.html")
566 (description
567 "Guile-SDL2 provides Guile Scheme bindings for the SDL2 C shared library.
568 The bindings are written in pure Scheme using Guile's foreign function
569 interface.")
570 (license lgpl3+)))