sdl.scm 19 KB

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