Merge branch 'master' into staging
[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.10")
112 (source (origin
113 (method url-fetch)
114 (uri
115 (string-append "https://libsdl.org/release/SDL2-"
116 version ".tar.gz"))
117 (patches (search-patches "sdl2-mesa-compat.patch"))
118 (sha256
119 (base32
120 "0mqxp6w5jhbq6y1j690g9r3gpzwjxh4czaglw8x05l7hl49nqrdl"))))
121 (arguments
122 (substitute-keyword-arguments (package-arguments sdl)
123 ((#:configure-flags flags)
124 `(append '("--disable-wayland-shared" "--enable-video-kmsdrm"
125 "--disable-kmsdrm-shared")
126 ,flags))
127 ((#:make-flags flags ''())
128 ;; Add the Fcitx header files to GCCs "system header" search path
129 ;; in order to suppress compiler warnings induced by those:
130 ;; .../include/fcitx-utils/utarray.h:178:9: error: ISO C90 forbids
131 ;; mixed declarations and code [-Werror=declaration-after-statement]
132 `(append (list (string-append "C_INCLUDE_PATH="
133 (assoc-ref %build-inputs "fcitx")
134 "/include"))
135 ,flags))))
136 (inputs
137 ;; SDL2 needs to be built with ibus support otherwise some systems
138 ;; experience a bug where input events are doubled.
139 ;;
140 ;; For more information, see: https://dev.solus-project.com/T1721
141 (append `(("dbus" ,dbus)
142 ("fcitx" ,fcitx) ; helps with CJK input
143 ("glib" ,glib)
144 ("ibus" ,ibus)
145 ("libxkbcommon" ,libxkbcommon)
146 ("libxcursor" ,libxcursor) ; enables X11 cursor support
147 ("wayland" ,wayland)
148 ("wayland-protocols" ,wayland-protocols))
149 (package-inputs sdl)))
150 (license bsd-3)))
151
152 (define-public libmikmod
153 (package
154 (name "libmikmod")
155 (version "3.3.11.1")
156 (source (origin
157 (method url-fetch)
158 (uri (list
159 (string-append "mirror://sourceforge/mikmod/libmikmod/"
160 version "/libmikmod-" version ".tar.gz")
161 ;; Older versions are sometimes moved to:
162 (string-append "mirror://sourceforge/mikmod/"
163 "outdated_versions/libmikmod/"
164 version "/libmikmod-" version ".tar.gz")))
165 (sha256
166 (base32
167 "06bdnhb0l81srdzg6gn2v2ydhhaazza7rshrcj3q8dpqr3gn97dd"))))
168 (build-system gnu-build-system)
169 (arguments
170 ;; By default, libmikmod tries to dlopen libasound etc., which won't work
171 ;; unless the right libalsa happens to be in $LD_LIBRARY_PATH. Pass
172 ;; '--disable-dl' to avoid that.
173 '(#:configure-flags '("--disable-dl")))
174 (synopsis "Library for module sound formats")
175 (description
176 "MikMod is able to play a wide range of module formats, as well as
177 digital sound files. It can take advantage of particular features of your
178 system, such as sound redirection over the network.")
179 (license lgpl2.1)
180 (home-page "http://mikmod.sourceforge.net/")))
181
182 (define-public sdl-gfx
183 (package
184 (name "sdl-gfx")
185 (version "2.0.26")
186 (source (origin
187 (method url-fetch)
188 (uri
189 (string-append "http://www.ferzkopp.net/Software/SDL_gfx-2.0/SDL_gfx-"
190 version ".tar.gz"))
191 (sha256
192 (base32
193 "0ijljhs0v99dj6y27hc10z6qchyp8gdp4199y6jzngy6dzxlzsvw"))))
194 (build-system gnu-build-system)
195 (outputs '("out" "debug"))
196 (arguments
197 `(,@(if (any (cute string-prefix? <> (or (%current-system)
198 (%current-target-system)))
199 '("x86_64" "i686"))
200 ;; mmx is supported only on Intel processors.
201 '()
202 '(#:configure-flags '("--disable-mmx")))))
203 (propagated-inputs `(("sdl" ,sdl)))
204 (synopsis "SDL graphics primitives library")
205 (description "SDL_gfx provides graphics drawing primitives, rotozoom and
206 other supporting functions for SDL.")
207 (home-page "http://www.ferzkopp.net/joomla/software-mainmenu-14/4-ferzkopps-linux-software/19-sdlgfx")
208 (license zlib)))
209
210 (define-public sdl-image
211 (package
212 (name "sdl-image")
213 (version "1.2.12")
214 (source (origin
215 (method url-fetch)
216 (uri
217 (string-append "https://www.libsdl.org/projects/SDL_image/release/SDL_image-"
218 version ".tar.gz"))
219 (sha256
220 (base32
221 "16an9slbb8ci7d89wakkmyfvp7c0cval8xw4hkg0842nhhlp540b"))))
222 (build-system gnu-build-system)
223 (outputs '("out" "debug"))
224 (arguments
225 ;; Explicitly link against shared libraries instead of dlopening them.
226 '(#:configure-flags '("--disable-jpg-shared"
227 "--disable-png-shared"
228 "--disable-tif-shared"
229 "--disable-webp-shared")))
230 (native-inputs `(("pkg-config" ,pkg-config)))
231 ;; libjpeg, libpng, and libtiff are propagated inputs because the
232 ;; SDL_image headers include the headers of these libraries. SDL is a
233 ;; propagated input because the pkg-config file refers to SDL's pkg-config
234 ;; file.
235 (propagated-inputs `(("sdl" ,sdl)
236 ("libjpeg" ,libjpeg)
237 ("libpng" ,libpng)
238 ("libtiff" ,libtiff)
239 ("libwebp" ,libwebp)))
240 (synopsis "SDL image loading library")
241 (description "SDL_image is an image file loading library for SDL that
242 supports the following formats: BMP, GIF, JPEG, LBM, PCX, PNG, PNM, TGA, TIFF,
243 WEBP, XCF, XPM, and XV.")
244 (home-page "https://www.libsdl.org/projects/SDL_image/")
245 (license zlib)))
246
247 (define-public sdl-mixer
248 (package
249 (name "sdl-mixer")
250 (version "1.2.12")
251 (source (origin
252 (method url-fetch)
253 (uri
254 (string-append "https://www.libsdl.org/projects/SDL_mixer/release/SDL_mixer-"
255 version ".tar.gz"))
256 (sha256
257 (base32
258 "0alrhqgm40p4c92s26mimg9cm1y7rzr6m0p49687jxd9g6130i0n"))))
259 (build-system gnu-build-system)
260 (outputs '("out" "debug"))
261 ;; no check target
262 ;; use libmad instead of smpeg
263 ;; explicitly link against shared libraries instead of dlopening them
264 (arguments `(#:tests? #f
265 #:configure-flags '("--enable-music-mp3-mad-gpl"
266 "--disable-music-mod-shared"
267 "--disable-music-fluidsynth-shared"
268 "--disable-music-ogg-shared"
269 "--disable-music-flac-shared"
270 "--disable-music-mp3-shared")))
271 (inputs `(("libvorbis" ,libvorbis)
272 ("libflac" ,flac)
273 ("libmad" ,libmad)
274 ("libmikmod" ,libmikmod)
275 ("libmodplug" ,libmodplug)))
276 ;; FIXME: Add libfluidsynth
277 (propagated-inputs `(("sdl" ,sdl)))
278 (synopsis "SDL multi-channel audio mixer library")
279 (description "SDL_mixer is a multi-channel audio mixer library for SDL.
280 It supports any number of simultaneously playing channels of 16 bit stereo
281 audio, plus a single channel of music. Supported format include FLAC, MOD,
282 MIDI, Ogg Vorbis, and MP3.")
283 (home-page "https://www.libsdl.org/projects/SDL_mixer/")
284 (license zlib)))
285
286 (define-public sdl-net
287 (package
288 (name "sdl-net")
289 (version "1.2.8")
290 (source (origin
291 (method url-fetch)
292 (uri
293 (string-append "https://www.libsdl.org/projects/SDL_net/release/SDL_net-"
294 version ".tar.gz"))
295 (sha256
296 (base32
297 "1d5c9xqlf4s1c01gzv6cxmg0r621pq9kfgxcg3197xw4p25pljjz"))))
298 (build-system gnu-build-system)
299 (propagated-inputs `(("sdl" ,sdl)))
300 (native-inputs `(("pkg-config" ,pkg-config)))
301 (outputs '("out" "debug"))
302 (synopsis "SDL networking library")
303 (description "SDL_net is a small, cross-platform networking library for
304 SDL.")
305 (home-page "https://www.libsdl.org/projects/SDL_net/")
306 (license zlib)))
307
308 (define-public sdl-ttf
309 (package
310 (name "sdl-ttf")
311 (version "2.0.11")
312 (source (origin
313 (method url-fetch)
314 (uri
315 (string-append "https://www.libsdl.org/projects/SDL_ttf/release/SDL_ttf-"
316 version ".tar.gz"))
317 (sha256
318 (base32
319 "1dydxd4f5kb1288i5n5568kdk2q7f8mqjr7i7sd33nplxjaxhk3j"))))
320 (build-system gnu-build-system)
321 (propagated-inputs `(("sdl" ,sdl)))
322 (inputs `(("freetype" ,freetype)
323 ("mesa" ,mesa)))
324 (native-inputs `(("pkg-config" ,pkg-config)))
325 (outputs '("out" "debug"))
326 (synopsis "SDL TrueType font library")
327 (description "SDL_ttf is a TrueType font rendering library for SDL.")
328 (home-page "https://www.libsdl.org/projects/SDL_ttf/")
329 (license zlib)))
330
331 (define* (sdl-union #:optional (packages (list sdl sdl-gfx sdl-net sdl-ttf
332 sdl-image sdl-mixer)))
333 "Return 'sdl-union' package which is a union of PACKAGES.
334 If PACKAGES are not specified, all SDL packages are used."
335 (package
336 (name "sdl-union")
337 (version (package-version sdl))
338 (source #f)
339 (build-system trivial-build-system)
340 (arguments
341 '(#:modules ((guix build union))
342 #:builder (begin
343 (use-modules (ice-9 match)
344 (guix build union))
345 (match %build-inputs
346 (((names . directories) ...)
347 (union-build (assoc-ref %outputs "out")
348 directories)
349 #t)))))
350 (inputs (map (lambda (package)
351 (list (package-name package) package))
352 packages))
353 (synopsis "Union of SDL libraries")
354 (description
355 "A union of SDL and its extension libraries. A union is required because
356 sdl-config assumes that all of the headers and libraries are in the same
357 directory.")
358 (home-page (package-home-page sdl))
359 (license (package-license sdl))))
360
361 (define (propagated-inputs-with-sdl2 package)
362 "Replace the \"sdl\" propagated input of PACKAGE with SDL2."
363 (map (match-lambda
364 (("sdl" _)
365 `("sdl2" ,sdl2))
366 (other other))
367 (package-propagated-inputs package)))
368
369 (define-public sdl2-gfx
370 (package (inherit sdl-gfx)
371 (name "sdl2-gfx")
372 (version "1.0.4")
373 (source (origin
374 (method url-fetch)
375 (uri
376 (string-append "https://www.ferzkopp.net/Software/SDL2_gfx/SDL2_gfx-"
377 version ".tar.gz"))
378 (sha256
379 (base32
380 "0qk2ax7f7grlxb13ba0ll3zlm8780s7j8fmrhlpxzjgdvldf1q33"))))
381 (propagated-inputs
382 (propagated-inputs-with-sdl2 sdl-gfx))))
383
384 (define-public sdl2-image
385 (package (inherit sdl-image)
386 (name "sdl2-image")
387 (version "2.0.4")
388 (source
389 (origin
390 (method url-fetch)
391 (uri
392 (string-append "https://www.libsdl.org/projects/SDL_image/release/"
393 "SDL2_image-" version ".tar.gz"))
394 (sha256
395 (base32 "1b6f7002bm007y3zpyxb5r6ag0lml51jyvx1pwpj9sq24jfc8kp7"))))
396 (propagated-inputs
397 (propagated-inputs-with-sdl2 sdl-image))))
398
399 (define-public sdl2-mixer
400 (package (inherit sdl-mixer)
401 (name "sdl2-mixer")
402 (version "2.0.4")
403 (source
404 (origin
405 (method url-fetch)
406 (uri
407 (string-append "http://www.libsdl.org/projects/SDL_mixer/release/"
408 "SDL2_mixer-" version ".tar.gz"))
409 (modules '((guix build utils)))
410 (snippet '(begin
411 ;; Remove bundled libraries.
412 (delete-file-recursively "external")
413 #t))
414 (sha256
415 (base32 "0694vsz5bjkcdgfdra6x9fq8vpzrl8m6q96gh58df7065hw5mkxl"))))
416 (propagated-inputs
417 (propagated-inputs-with-sdl2 sdl-mixer))))
418
419 (define-public sdl2-net
420 (package (inherit sdl-net)
421 (name "sdl2-net")
422 (version "2.0.1")
423 (source
424 (origin
425 (method url-fetch)
426 (uri
427 (string-append "http://www.libsdl.org/projects/SDL_net/release/"
428 "SDL2_net-" version ".tar.gz"))
429 (sha256
430 (base32
431 "08cxc1bicmyk89kiks7izw1rlx5ng5n6xpy8fy0zxni3b9z8mkhm"))))
432 (propagated-inputs
433 (propagated-inputs-with-sdl2 sdl-net))))
434
435 (define-public sdl2-ttf
436 (package (inherit sdl-ttf)
437 (name "sdl2-ttf")
438 (version "2.0.15")
439 (source (origin
440 (method url-fetch)
441 (uri
442 (string-append "https://www.libsdl.org/projects/SDL_ttf/release/SDL2_ttf-"
443 version ".tar.gz"))
444 (modules '((guix build utils)))
445 (snippet (begin
446 ;; Remove bundled libraries.
447 '(delete-file-recursively "external")
448 #t))
449 (sha256
450 (base32
451 "0cyd48dipc0m399qy8s03lci8b0bpiy8xlkvrm2ia7wcv0dfpv59"))))
452 (propagated-inputs
453 (propagated-inputs-with-sdl2 sdl-ttf))))
454
455 (define-public guile-sdl
456 (package
457 (name "guile-sdl")
458 (version "0.5.2")
459 (source (origin
460 (method url-fetch)
461 (uri
462 (string-append "mirror://gnu/guile-sdl/guile-sdl-"
463 version ".tar.xz"))
464 (sha256
465 (base32
466 "0cjgs012a9922hn6xqwj66w6qmfs3nycnm56hyykx5n3g5p7ag01"))))
467 (build-system gnu-build-system)
468 (native-inputs
469 `(("pkg-config" ,pkg-config)
470 ;; Required by test suite.
471 ("xorg-server" ,xorg-server)
472 ("libjpeg" ,libjpeg)))
473 (inputs
474 `(("guile" ,guile-2.2)
475 ("sdl-union" ,(sdl-union))))
476 (arguments
477 '(#:configure-flags
478 (list (string-append "--with-sdl-prefix="
479 (assoc-ref %build-inputs "sdl-union")))
480 #:modules ((ice-9 popen)
481 (guix build utils)
482 (guix build gnu-build-system))
483
484 #:parallel-build? #f ; parallel build fails
485
486 #:phases
487 (modify-phases %standard-phases
488 (add-before 'configure 'fix-env-and-patch
489 (lambda* (#:key inputs #:allow-other-keys)
490 (setenv "GUILE_AUTO_COMPILE" "0")
491 ;; SDL_image needs to dlopen libjpeg in the test suite.
492 (setenv "LD_LIBRARY_PATH"
493 (string-append (assoc-ref inputs "libjpeg") "/lib"))
494
495 ;; Change the site directory /site/X.Y like Guile expects.
496 (substitute* "build-aux/guile-baux/re-prefixed-site-dirs"
497 (("\"/site\"")
498 (let ((effective
499 (read
500 (open-pipe* OPEN_READ
501 "guile" "-c"
502 "(write (effective-version))"))))
503 (string-append "\"/site/" effective "\""))))
504
505 ;; Skip tests that rely on sound support, which is unavailable in
506 ;; the build environment.
507 (substitute* "test/Makefile.in"
508 (("HAVE_MIXER = .*$")
509 "HAVE_MIXER = 0\n"))
510 #t))
511 (add-before 'check 'start-xorg-server
512 (lambda* (#:key inputs #:allow-other-keys)
513 ;; The test suite requires a running X server.
514 (system (format #f "~a/bin/Xvfb :1 &"
515 (assoc-ref inputs "xorg-server")))
516 (setenv "DISPLAY" ":1")
517 #t))
518 (add-before 'check 'skip-cursor-test
519 (lambda _
520 ;; XXX: This test sometimes enters an endless loop, and sometimes
521 ;; crashes with:
522 ;; guile: xcb_io.c:147: append_pending_request: Assertion `!xcb_xlib_unknown_seq_number' failed.
523 ;; Skip it.
524 (substitute* "test/cursor.scm"
525 (("\\(SDL:init .*" all)
526 (string-append "(exit 77) ;" all "\n")))
527 #t)))))
528 (synopsis "Guile interface for SDL (Simple DirectMedia Layer)")
529 (description "Guile-SDL is a set of bindings to the Simple DirectMedia
530 Layer (SDL). With them, Guile programmers can have easy access to graphics,
531 sound and device input (keyboards, joysticks, mice, etc.).")
532 (home-page "https://www.gnu.org/software/guile-sdl/")
533 (license gpl3+)))
534
535 (define-public guile-sdl2
536 (package
537 (name "guile-sdl2")
538 (version "0.4.0")
539 (source (origin
540 (method url-fetch)
541 (uri (string-append "https://files.dthompson.us/guile-sdl2/"
542 "guile-sdl2-" version ".tar.gz"))
543 (sha256
544 (base32
545 "0zcxwgyadwpbhq6h5mv2569c3kalgra26zc186y9fqiyyzmh1v9s"))))
546 (build-system gnu-build-system)
547 (arguments
548 '(#:make-flags '("GUILE_AUTO_COMPILE=0")
549 #:configure-flags
550 (list (string-append "--with-libsdl2-prefix="
551 (assoc-ref %build-inputs "sdl2"))
552 (string-append "--with-libsdl2-image-prefix="
553 (assoc-ref %build-inputs "sdl2-image"))
554 (string-append "--with-libsdl2-ttf-prefix="
555 (assoc-ref %build-inputs "sdl2-ttf"))
556 (string-append "--with-libsdl2-mixer-prefix="
557 (assoc-ref %build-inputs "sdl2-mixer")))))
558 (native-inputs
559 `(("guile" ,guile-2.2)
560 ("pkg-config" ,pkg-config)))
561 (inputs
562 `(("sdl2" ,sdl2)
563 ("sdl2-image" ,sdl2-image)
564 ("sdl2-mixer" ,sdl2-mixer)
565 ("sdl2-ttf" ,sdl2-ttf)))
566 (synopsis "Guile bindings for SDL2")
567 (home-page "https://dthompson.us/projects/guile-sdl2.html")
568 (description
569 "Guile-SDL2 provides Guile Scheme bindings for the SDL2 C shared library.
570 The bindings are written in pure Scheme using Guile's foreign function
571 interface.")
572 (license lgpl3+)))