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