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