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