Merge branch 'master' 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 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 #t)))))
329 (inputs (map (lambda (package)
330 (list (package-name package) package))
331 packages))
332 (synopsis "Union of SDL libraries")
333 (description
334 "A union of SDL and its extension libraries. A union is required because
335 sdl-config assumes that all of the headers and libraries are in the same
336 directory.")
337 (home-page (package-home-page sdl))
338 (license (package-license sdl))))
339
340 (define (propagated-inputs-with-sdl2 package)
341 "Replace the \"sdl\" propagated input of PACKAGE with SDL2."
342 (map (match-lambda
343 (("sdl" _)
344 `("sdl2" ,sdl2))
345 (other other))
346 (package-propagated-inputs package)))
347
348 (define-public sdl2-image
349 (package (inherit sdl-image)
350 (name "sdl2-image")
351 (version "2.0.2")
352 (source (origin
353 (method url-fetch)
354 (uri
355 (string-append "https://www.libsdl.org/projects/SDL_image/release/SDL2_image-"
356 version ".tar.gz"))
357 (sha256
358 (base32
359 "1s3ciydixrgv34vlf45ak5syq5nlfaqf19wf162lbz4ixxd0gpvj"))))
360 (propagated-inputs
361 (propagated-inputs-with-sdl2 sdl-image))))
362
363 (define-public sdl2-mixer
364 (package (inherit sdl-mixer)
365 (name "sdl2-mixer")
366 (version "2.0.2")
367 (source (origin
368 (method url-fetch)
369 (uri
370 (string-append "http://www.libsdl.org/projects/SDL_mixer/release/SDL2_mixer-"
371 version ".tar.gz"))
372 (modules '((guix build utils)))
373 (snippet '(begin
374 ;; Remove bundled libraries.
375 (delete-file-recursively "external")
376 #t))
377 (sha256
378 (base32
379 "1fw3kkqi5346ai5if4pxrcbhs5c4vv3a4smgz6fl6kyaxwkmwqaf"))))
380 (propagated-inputs
381 (propagated-inputs-with-sdl2 sdl-mixer))))
382
383 (define-public sdl2-ttf
384 (package (inherit sdl-ttf)
385 (name "sdl2-ttf")
386 (version "2.0.14")
387 (source (origin
388 (method url-fetch)
389 (uri
390 (string-append "https://www.libsdl.org/projects/SDL_ttf/release/SDL2_ttf-"
391 version ".tar.gz"))
392 (modules '((guix build utils)))
393 (snippet (begin
394 ;; Remove bundled libraries.
395 '(delete-file-recursively "external")
396 #t))
397 (sha256
398 (base32
399 "0xljwcpvd2knrjdfag5b257xqayplz55mqlszrqp0kpnphh5xnrl"))))
400 (propagated-inputs
401 (propagated-inputs-with-sdl2 sdl-ttf))))
402
403 (define-public guile-sdl
404 (package
405 (name "guile-sdl")
406 (version "0.5.2")
407 (source (origin
408 (method url-fetch)
409 (uri
410 (string-append "mirror://gnu/guile-sdl/guile-sdl-"
411 version ".tar.xz"))
412 (sha256
413 (base32
414 "0cjgs012a9922hn6xqwj66w6qmfs3nycnm56hyykx5n3g5p7ag01"))))
415 (build-system gnu-build-system)
416 (native-inputs
417 `(("pkg-config" ,pkg-config)
418 ;; Required by test suite.
419 ("xorg-server" ,xorg-server)
420 ("libjpeg" ,libjpeg)))
421 (inputs
422 `(("guile" ,guile-2.2)
423 ("sdl-union" ,(sdl-union))))
424 (arguments
425 '(#:configure-flags
426 (list (string-append "--with-sdl-prefix="
427 (assoc-ref %build-inputs "sdl-union")))
428 #:modules ((ice-9 popen)
429 (guix build utils)
430 (guix build gnu-build-system))
431
432 #:parallel-build? #f ; parallel build fails
433
434 #:phases
435 (modify-phases %standard-phases
436 (add-before 'configure 'fix-env-and-patch
437 (lambda* (#:key inputs #:allow-other-keys)
438 (setenv "GUILE_AUTO_COMPILE" "0")
439 ;; SDL_image needs to dlopen libjpeg in the test suite.
440 (setenv "LD_LIBRARY_PATH"
441 (string-append (assoc-ref inputs "libjpeg") "/lib"))
442
443 ;; Change the site directory /site/X.Y like Guile expects.
444 (substitute* "build-aux/guile-baux/re-prefixed-site-dirs"
445 (("\"/site\"")
446 (let ((effective
447 (read
448 (open-pipe* OPEN_READ
449 "guile" "-c"
450 "(write (effective-version))"))))
451 (string-append "\"/site/" effective "\""))))
452
453 ;; Skip tests that rely on sound support, which is unavailable in
454 ;; the build environment.
455 (substitute* "test/Makefile.in"
456 (("HAVE_MIXER = .*$")
457 "HAVE_MIXER = 0\n"))
458 #t))
459 (add-before 'check 'start-xorg-server
460 (lambda* (#:key inputs #:allow-other-keys)
461 ;; The test suite requires a running X server.
462 (system (format #f "~a/bin/Xvfb :1 &"
463 (assoc-ref inputs "xorg-server")))
464 (setenv "DISPLAY" ":1")
465 #t))
466 (add-before 'check 'skip-cursor-test
467 (lambda _
468 ;; XXX: This test sometimes enters an endless loop, and sometimes
469 ;; crashes with:
470 ;; guile: xcb_io.c:147: append_pending_request: Assertion `!xcb_xlib_unknown_seq_number' failed.
471 ;; Skip it.
472 (substitute* "test/cursor.scm"
473 (("\\(SDL:init .*" all)
474 (string-append "(exit 77) ;" all "\n")))
475 #t)))))
476 (synopsis "Guile interface for SDL (Simple DirectMedia Layer)")
477 (description "Guile-SDL is a set of bindings to the Simple DirectMedia
478 Layer (SDL). With them, Guile programmers can have easy access to graphics,
479 sound and device input (keyboards, joysticks, mice, etc.).")
480 (home-page "https://www.gnu.org/software/guile-sdl/")
481 (license gpl3+)))
482
483 (define-public guile-sdl2
484 (package
485 (name "guile-sdl2")
486 (version "0.2.0")
487 (source (origin
488 (method url-fetch)
489 (uri (string-append
490 "https://files.dthompson.us/guile-sdl2/guile-sdl2-"
491 version ".tar.gz"))
492 (sha256
493 (base32
494 "0yq9lsl17cdvj77padvpk3jcw2g6g0pck9jrchc7n2767rrc012b"))))
495 (build-system gnu-build-system)
496 (arguments
497 '(#:make-flags '("GUILE_AUTO_COMPILE=0")
498 #:configure-flags
499 (list (string-append "--with-libsdl2-prefix="
500 (assoc-ref %build-inputs "sdl2"))
501 (string-append "--with-libsdl2-image-prefix="
502 (assoc-ref %build-inputs "sdl2-image"))
503 (string-append "--with-libsdl2-ttf-prefix="
504 (assoc-ref %build-inputs "sdl2-ttf"))
505 (string-append "--with-libsdl2-mixer-prefix="
506 (assoc-ref %build-inputs "sdl2-mixer")))))
507 (native-inputs
508 `(("guile" ,guile-2.2)
509 ("pkg-config" ,pkg-config)))
510 (inputs
511 `(("sdl2" ,sdl2)
512 ("sdl2-image" ,sdl2-image)
513 ("sdl2-mixer" ,sdl2-mixer)
514 ("sdl2-ttf" ,sdl2-ttf)))
515 (synopsis "Guile bindings for SDL2")
516 (home-page "https://dthompson.us/projects/guile-sdl2.html")
517 (description
518 "Guile-SDL2 provides Guile Scheme bindings for the SDL2 C shared library.
519 The bindings are written in pure Scheme using Guile's foreign function
520 interface.")
521 (license lgpl3+)))