ncurses.scm 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2012, 2013, 2014, 2015, 2017, 2018, 2019 Ludovic Courtès <ludo@gnu.org>
  3. ;;; Copyright © 2014, 2016 Mark H Weaver <mhw@netris.org>
  4. ;;; Copyright © 2015, 2017 Leo Famulari <leo@famulari.name>
  5. ;;; Copyright © 2016 Nikita <nikita@n0.is>
  6. ;;; Copyright © 2016 Efraim Flashner <efraim@flashner.co.il>
  7. ;;; Copyright © 2016 Jan Nieuwenhuizen <janneke@gnu.org>
  8. ;;; Copyright © 2017, 2019, 2020, 2021 Marius Bakke <marius@gnu.org>
  9. ;;; Copyright © 2018, 2019 Tobias Geerinckx-Rice <me@tobias.gr>
  10. ;;; Copyright © 2020 Michael Rohleder <mike@rohleder.de>
  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. (define-module (gnu packages ncurses)
  27. #:use-module (gnu packages)
  28. #:use-module (guix licenses)
  29. #:use-module (guix packages)
  30. #:use-module (guix download)
  31. #:use-module (guix build-system gnu)
  32. #:use-module (guix build-system perl)
  33. #:use-module (gnu packages)
  34. #:use-module (gnu packages perl)
  35. #:use-module (gnu packages pkg-config)
  36. #:use-module (gnu packages swig)
  37. #:use-module (gnu packages linux)
  38. #:use-module (guix utils)
  39. #:use-module (ice-9 match))
  40. (define-public ncurses
  41. (package
  42. (name "ncurses")
  43. (version "6.2.20210619")
  44. (source (origin
  45. (method url-fetch)
  46. (uri (string-append "mirror://gnu/ncurses/ncurses-"
  47. (version-major+minor version)
  48. ".tar.gz"))
  49. (sha256
  50. (base32
  51. "17bcm2z1rdx5gmzj5fb8cp7f28aw5b4g2z4qvvqg3yg0fq66wc1h"))))
  52. (build-system gnu-build-system)
  53. (outputs '("out"
  54. "doc")) ;1 MiB of man pages
  55. (arguments
  56. (let ((patch-makefile-phase
  57. '(lambda _
  58. (for-each patch-makefile-SHELL
  59. (find-files "." "Makefile.in"))))
  60. (configure-phase
  61. ;; The 'configure' script does not understand '--docdir', so we must
  62. ;; override that and use '--mandir' instead.
  63. '(lambda* (#:key build target outputs configure-flags
  64. #:allow-other-keys)
  65. (let ((out (assoc-ref outputs "out"))
  66. (doc (assoc-ref outputs "doc")))
  67. (apply invoke "./configure"
  68. (string-append "SHELL=" (which "sh"))
  69. (string-append "--build=" build)
  70. (string-append "--prefix=" out)
  71. (string-append "--mandir=" doc "/share/man")
  72. (if target
  73. (cons (string-append "--host=" target)
  74. configure-flags)
  75. configure-flags)))))
  76. (apply-rollup-patch-phase
  77. ;; Ncurses distributes "stable" patchsets to be applied on top
  78. ;; of the release tarball. These are only available as shell
  79. ;; scripts(!) so we decompress and apply them in a phase.
  80. ;; See <https://invisible-mirror.net/archives/ncurses/6.1/README>.
  81. '(lambda* (#:key inputs native-inputs #:allow-other-keys)
  82. (let ((rollup-patch (assoc-ref (or native-inputs inputs)
  83. "rollup-patch")))
  84. (when rollup-patch
  85. (copy-file rollup-patch
  86. (string-append (getcwd) "/rollup-patch.sh.bz2"))
  87. (invoke "bzip2" "-d" "rollup-patch.sh.bz2")
  88. (invoke "sh" "rollup-patch.sh")))))
  89. (remove-shebang-phase
  90. '(lambda _
  91. ;; To avoid retaining a reference to the bootstrap Bash via the
  92. ;; shebang of the 'ncursesw6-config' script, simply remove that
  93. ;; shebang: it'll work just as well without it. Likewise, do not
  94. ;; retain a reference to the "doc" output.
  95. (substitute* "misc/ncurses-config.in"
  96. (("#!@SHELL@")
  97. "# No shebang here, use /bin/sh!\n")
  98. (("@SHELL@ \\$0")
  99. "$0")
  100. (("mandir=.*$")
  101. "mandir=share/man"))))
  102. (post-install-phase
  103. `(lambda* (#:key outputs #:allow-other-keys)
  104. (let ((out (assoc-ref outputs "out")))
  105. ;; When building a wide-character (Unicode) build, create backward
  106. ;; compatibility links from the the "normal" libraries to the
  107. ;; wide-character ones (e.g. libncurses.so to libncursesw.so).
  108. ,@(if (target-mingw?)
  109. '( ;; TODO: create .la files to link to the .dll?
  110. (with-directory-excursion (string-append out "/bin")
  111. (for-each
  112. (lambda (lib)
  113. (define lib.dll
  114. (string-append "lib" lib ".dll"))
  115. (define libw6.dll
  116. (string-append "lib" lib "w6.dll"))
  117. (when (file-exists? libw6.dll)
  118. (format #t "creating symlinks for `lib~a'~%" lib)
  119. (symlink libw6.dll lib.dll)))
  120. '("curses" "ncurses" "form" "panel" "menu"))))
  121. '())
  122. (with-directory-excursion (string-append out "/lib")
  123. (for-each (lambda (lib)
  124. (define libw.a
  125. (string-append "lib" lib "w.a"))
  126. (define lib.a
  127. (string-append "lib" lib ".a"))
  128. ,@(if (not (target-mingw?))
  129. '((define libw.so.x
  130. (string-append "lib" lib "w.so.6"))
  131. (define lib.so.x
  132. (string-append "lib" lib ".so.6"))
  133. (define lib.so
  134. (string-append "lib" lib ".so"))
  135. (define packagew.pc
  136. (string-append lib "w.pc"))
  137. (define package.pc
  138. (string-append lib ".pc")))
  139. '())
  140. (when (file-exists? libw.a)
  141. (format #t "creating symlinks for `lib~a'~%" lib)
  142. (symlink libw.a lib.a)
  143. ,@(if (not (target-mingw?))
  144. '((symlink libw.so.x lib.so.x)
  145. (false-if-exception (delete-file lib.so))
  146. (call-with-output-file lib.so
  147. (lambda (p)
  148. (format p "INPUT (-l~aw)~%" lib)))
  149. (with-directory-excursion "pkgconfig"
  150. (format #t "creating symlink for `~a'~%"
  151. package.pc)
  152. (when (file-exists? packagew.pc)
  153. (symlink packagew.pc package.pc))))
  154. '())))
  155. '("curses" "ncurses" "form" "panel" "menu")))))))
  156. `(#:configure-flags
  157. ,(cons*
  158. 'quasiquote
  159. `(("--with-shared" "--without-debug" "--enable-widec"
  160. "--enable-pc-files"
  161. ,(list 'unquote '(string-append "--with-pkg-config-libdir="
  162. (assoc-ref %outputs "out")
  163. "/lib/pkgconfig"))
  164. ;; By default headers land in an `ncursesw' subdir, which is not
  165. ;; what users expect.
  166. ,(list 'unquote '(string-append "--includedir=" (assoc-ref %outputs "out")
  167. "/include"))
  168. "--enable-overwrite" ;really honor --includedir
  169. ;; Make sure programs like 'tic', 'reset', and 'clear' have a
  170. ;; correct RUNPATH.
  171. ,(list 'unquote '(string-append "LDFLAGS=-Wl,-rpath=" (assoc-ref %outputs "out")
  172. "/lib"))
  173. ;; Starting from ncurses 6.1, "make install" runs "install -s"
  174. ;; by default, which doesn't work for cross-compiled binaries
  175. ;; because it invokes 'strip' instead of 'TRIPLET-strip'. Work
  176. ;; around this.
  177. ,@(if (%current-target-system) '("--disable-stripping") '())
  178. ;; Do not assume a default search path in ld, even if it is only to
  179. ;; filter it out in ncurses-config. Mainly because otherwise it ends
  180. ;; up using the libdir from binutils, which makes little sense and
  181. ;; causes an unnecessary runtime dependency.
  182. "cf_cv_ld_searchpath=/no-ld-searchpath"
  183. ;; MinGW: Use term-driver created for the MinGW port.
  184. ,@(if (target-mingw?) '("--enable-term-driver") '()))))
  185. #:tests? #f ; no "check" target
  186. #:phases (modify-phases %standard-phases
  187. (add-after 'unpack 'apply-rollup-patch
  188. ,apply-rollup-patch-phase)
  189. (replace 'configure ,configure-phase)
  190. (add-after 'install 'post-install
  191. ,post-install-phase)
  192. (add-before 'configure 'patch-makefile-SHELL
  193. ,patch-makefile-phase)
  194. (add-before 'patch-source-shebangs 'remove-unneeded-shebang
  195. ,remove-shebang-phase)))))
  196. (native-inputs
  197. `(,@(if (%current-target-system)
  198. `(("self" ,this-package)) ;for `tic'
  199. '())
  200. ("rollup-patch"
  201. ,(origin
  202. (method url-fetch)
  203. (uri (match (string-split (version-major+minor+point version) #\.)
  204. ((major minor point)
  205. (string-append "https://invisible-mirror.net/archives"
  206. "/ncurses/" major "." minor "/ncurses-"
  207. major "." minor "-" point "-patch.sh.bz2"))))
  208. (sha256
  209. (base32
  210. "1b6522cvi4066bgh9lp93q8lk93zcjjssvnw1512z447xvazy2y6"))))
  211. ("pkg-config" ,pkg-config)))
  212. (native-search-paths
  213. (list (search-path-specification
  214. (variable "TERMINFO_DIRS")
  215. (files '("share/terminfo")))))
  216. (synopsis "Terminal emulation (termcap, terminfo) library")
  217. (description
  218. "GNU Ncurses is a library which provides capabilities to write text to
  219. a terminal in a terminal-independent manner. It supports pads and color as
  220. well as multiple highlights and forms characters. It is typically used to
  221. implement user interfaces for command-line applications. The accompanying
  222. ncursesw library provides wide character support.")
  223. (license x11)
  224. (home-page "https://www.gnu.org/software/ncurses/")))
  225. (define-public ncurses/gpm
  226. (package/inherit ncurses
  227. (name "ncurses-with-gpm")
  228. (arguments
  229. (substitute-keyword-arguments (package-arguments ncurses)
  230. ((#:configure-flags cf)
  231. `(cons (string-append "--with-gpm="
  232. (assoc-ref %build-inputs "gpm")
  233. "/lib/libgpm.so.2")
  234. ,cf))))
  235. (inputs
  236. `(("gpm" ,gpm)))))
  237. (define-public dialog
  238. (package
  239. (name "dialog")
  240. (version "1.3-20201126")
  241. (source (origin
  242. (method url-fetch)
  243. (uri (string-append
  244. "https://invisible-mirror.net/archives/dialog/dialog-"
  245. version ".tgz"))
  246. (sha256
  247. (base32
  248. "0riqmp2xl2j2yxx69nyg8jbm2fyi5fp4clcf6zi5jfm3irn3l8y9"))))
  249. (build-system gnu-build-system)
  250. (inputs
  251. `(("ncurses" ,ncurses)))
  252. (synopsis "Curses widgets")
  253. (description "Dialog is a script-interpreter which provides a set of
  254. curses widgets, such as dialog boxes.")
  255. (home-page "https://invisible-island.net/dialog/dialog.html")
  256. (license lgpl2.1)))
  257. (define-public perl-curses
  258. (package
  259. (name "perl-curses")
  260. (version "1.36")
  261. (source
  262. (origin
  263. (method url-fetch)
  264. (uri (string-append "mirror://cpan/authors/id/G/GI/GIRAFFED/"
  265. "Curses-" version ".tar.gz"))
  266. (sha256
  267. (base32
  268. "0r6xd9wr0c25rr28zixhqipak575zqsfb7r7f2693i9il1dpj554"))))
  269. (build-system perl-build-system)
  270. (inputs
  271. `(("ncurses" ,ncurses)))
  272. (arguments
  273. `(#:make-maker-flags (list "PANELS" "MENUS")
  274. #:phases
  275. (modify-phases %standard-phases
  276. (add-before
  277. 'configure 'set-curses-ldflags
  278. (lambda* (#:key inputs #:allow-other-keys)
  279. (let* ((ncurses (assoc-ref inputs "ncurses"))
  280. (include (string-append ncurses "/include"))
  281. (lib (string-append ncurses "/lib")))
  282. (setenv "CURSES_LIBTYPE" "ncurses")
  283. (setenv "CURSES_CFLAGS" (string-append "-I" include))
  284. (setenv "CURSES_PANEL_CFLAGS" (string-append "-I" include))
  285. (setenv "CURSES_MENU_CFLAGS" (string-append "-I" include))
  286. (setenv "CURSES_FORM_CFLAGS" (string-append "-I" include))
  287. (setenv "CURSES_LDFLAGS" (string-append "-L" lib " -lncurses"))
  288. (setenv "CURSES_PANEL_LDFLAGS" (string-append "-L" lib " -lpanel"))
  289. (setenv "CURSES_MENU_LDFLAGS" (string-append "-L" lib " -lmenu"))
  290. (setenv "CURSES_FORM_LDFLAGS" (string-append "-L" lib " -lform"))
  291. #t))))))
  292. (home-page "https://metacpan.org/release/Curses")
  293. (synopsis "Terminal screen handling and optimization")
  294. (description
  295. "@code{Curses} is the interface between Perl and the curses library
  296. of your system.")
  297. (license perl-license)))
  298. (define-public stfl
  299. (package
  300. (name "stfl")
  301. (version "0.24")
  302. (source
  303. (origin
  304. (method url-fetch)
  305. (uri (string-append "http://www.clifford.at/stfl/stfl-"
  306. version ".tar.gz"))
  307. (sha256
  308. (base32
  309. "1460d5lc780p3q38l3wc9jfr2a7zlyrcra0li65aynj738cam9yl"))))
  310. (build-system gnu-build-system)
  311. (arguments
  312. '(#:tests? #f ; no test target
  313. #:make-flags (list (string-append "prefix=" (assoc-ref %outputs "out")))
  314. #:phases
  315. (modify-phases %standard-phases
  316. (delete 'configure) ; there is no configure script
  317. ;; in our ncurses, the headers are in /include
  318. (add-before 'build 'patch-ncursesw
  319. (lambda _
  320. (substitute* "stfl_internals.h"
  321. (("ncursesw/") ""))
  322. #t))
  323. (add-after 'install 'install-missing-symlink
  324. (lambda* (#:key outputs #:allow-other-keys)
  325. (let* ((out (assoc-ref outputs "out"))
  326. (lib (string-append out "/lib")))
  327. ;; Some programs look for libstfl.so.0.
  328. (symlink "libstfl.so" (string-append lib "/libstfl.so.0"))))))))
  329. (inputs `(("ncurses" ,ncurses)))
  330. (native-inputs `(("swig" ,swig)))
  331. (home-page "http://www.clifford.at/stfl/")
  332. (synopsis "Structured terminal forms library")
  333. (description "Stfl is a library which implements a curses-based widget
  334. set for text terminals.")
  335. (license lgpl3+)))