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