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