ncurses.scm 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2012, 2013, 2014, 2015, 2017, 2018 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 Nils Gillmann <ng0@n0.is>
  6. ;;; Copyright © 2016 Efraim Flashner <efraim@flashner.co.il>
  7. ;;; Copyright © 2016 Jan Nieuwenhuizen <janneke@gnu.org>
  8. ;;; Copyright © 2017 Marius Bakke <mbakke@fastmail.com>
  9. ;;; Copyright © 2018, 2019 Tobias Geerinckx-Rice <me@tobias.gr>
  10. ;;;
  11. ;;; This file is part of GNU Guix.
  12. ;;;
  13. ;;; GNU Guix is free software; you can redistribute it and/or modify it
  14. ;;; under the terms of the GNU General Public License as published by
  15. ;;; the Free Software Foundation; either version 3 of the License, or (at
  16. ;;; your option) any later version.
  17. ;;;
  18. ;;; GNU Guix is distributed in the hope that it will be useful, but
  19. ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
  20. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. ;;; GNU General Public License for more details.
  22. ;;;
  23. ;;; You should have received a copy of the GNU General Public License
  24. ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
  25. (define-module (gnu packages ncurses)
  26. #:use-module (gnu packages)
  27. #:use-module (guix licenses)
  28. #:use-module (guix packages)
  29. #:use-module (guix download)
  30. #:use-module (guix build-system gnu)
  31. #:use-module (guix build-system perl)
  32. #:use-module (gnu packages)
  33. #:use-module (gnu packages perl)
  34. #:use-module (gnu packages pkg-config)
  35. #:use-module (gnu packages swig)
  36. #:use-module (gnu packages linux)
  37. #:use-module (guix utils))
  38. (define-public ncurses
  39. (package
  40. (name "ncurses")
  41. (version "6.1")
  42. (source (origin
  43. (method url-fetch)
  44. (uri (string-append "mirror://gnu/ncurses/ncurses-"
  45. (car (string-split version #\-))
  46. ".tar.gz"))
  47. (sha256
  48. (base32
  49. "05qdmbmrrn88ii9f66rkcmcyzp1kb1ymkx7g040lfkd1nkp7w1da"))))
  50. (build-system gnu-build-system)
  51. (outputs '("out"
  52. "doc")) ;1 MiB of man pages
  53. (arguments
  54. (let ((patch-makefile-phase
  55. '(lambda _
  56. (for-each patch-makefile-SHELL
  57. (find-files "." "Makefile.in"))
  58. #t))
  59. (configure-phase
  60. ;; The 'configure' script does not understand '--docdir', so we must
  61. ;; override that and use '--mandir' instead.
  62. '(lambda* (#:key build target outputs configure-flags
  63. #:allow-other-keys)
  64. (let ((out (assoc-ref outputs "out"))
  65. (doc (assoc-ref outputs "doc")))
  66. (apply invoke "./configure"
  67. (string-append "SHELL=" (which "sh"))
  68. (string-append "--build=" build)
  69. (string-append "--prefix=" out)
  70. (string-append "--mandir=" doc "/share/man")
  71. (if target
  72. (cons (string-append "--host=" target)
  73. configure-flags)
  74. configure-flags))
  75. #t)))
  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. (copy-file (assoc-ref (or native-inputs inputs) "rollup-patch")
  83. (string-append (getcwd) "/rollup-patch.sh.bz2"))
  84. (invoke "bzip2" "-d" "rollup-patch.sh.bz2")
  85. (invoke "sh" "rollup-patch.sh")
  86. #t))
  87. (remove-shebang-phase
  88. '(lambda _
  89. ;; To avoid retaining a reference to the bootstrap Bash via the
  90. ;; shebang of the 'ncursesw6-config' script, simply remove that
  91. ;; shebang: it'll work just as well without it. Likewise, do not
  92. ;; retain a reference to the "doc" output.
  93. (substitute* "misc/ncurses-config.in"
  94. (("#!@SHELL@")
  95. "# No shebang here, use /bin/sh!\n")
  96. (("@SHELL@ \\$0")
  97. "$0")
  98. (("mandir=.*$")
  99. "mandir=share/man"))
  100. #t))
  101. (post-install-phase
  102. `(lambda* (#:key outputs #:allow-other-keys)
  103. (let ((out (assoc-ref outputs "out")))
  104. ;; When building a wide-character (Unicode) build, create backward
  105. ;; compatibility links from the the "normal" libraries to the
  106. ;; wide-character ones (e.g. libncurses.so to libncursesw.so).
  107. ,@(if (target-mingw?)
  108. '( ;; TODO: create .la files to link to the .dll?
  109. (with-directory-excursion (string-append out "/bin")
  110. (for-each
  111. (lambda (lib)
  112. (define lib.dll
  113. (string-append "lib" lib ".dll"))
  114. (define libw6.dll
  115. (string-append "lib" lib "w6.dll"))
  116. (when (file-exists? libw6.dll)
  117. (format #t "creating symlinks for `lib~a'~%" lib)
  118. (symlink libw6.dll lib.dll)))
  119. '("curses" "ncurses" "form" "panel" "menu"))))
  120. '())
  121. (with-directory-excursion (string-append out "/lib")
  122. (for-each (lambda (lib)
  123. (define libw.a
  124. (string-append "lib" lib "w.a"))
  125. (define lib.a
  126. (string-append "lib" lib ".a"))
  127. ,@(if (not (target-mingw?))
  128. '((define libw.so.x
  129. (string-append "lib" lib "w.so.6"))
  130. (define lib.so.x
  131. (string-append "lib" lib ".so.6"))
  132. (define lib.so
  133. (string-append "lib" lib ".so"))
  134. (define packagew.pc
  135. (string-append lib "w.pc"))
  136. (define package.pc
  137. (string-append lib ".pc")))
  138. '())
  139. (when (file-exists? libw.a)
  140. (format #t "creating symlinks for `lib~a'~%" lib)
  141. (symlink libw.a lib.a)
  142. ,@(if (not (target-mingw?))
  143. '((symlink libw.so.x lib.so.x)
  144. (false-if-exception (delete-file lib.so))
  145. (call-with-output-file lib.so
  146. (lambda (p)
  147. (format p "INPUT (-l~aw)~%" lib)))
  148. (with-directory-excursion "pkgconfig"
  149. (format #t "creating symlink for `~a'~%"
  150. package.pc)
  151. (when (file-exists? packagew.pc)
  152. (symlink packagew.pc package.pc))))
  153. '())))
  154. '("curses" "ncurses" "form" "panel" "menu")))
  155. #t))))
  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. ;; MinGW: Use term-driver created for the MinGW port.
  179. ,@(if (target-mingw?) '("--enable-term-driver") '()))))
  180. #:tests? #f ; no "check" target
  181. #:phases (modify-phases %standard-phases
  182. (replace 'configure ,configure-phase)
  183. (add-after 'install 'post-install
  184. ,post-install-phase)
  185. (add-before 'configure 'patch-makefile-SHELL
  186. ,patch-makefile-phase)
  187. (add-after 'unpack 'remove-unneeded-shebang
  188. ,remove-shebang-phase)))))
  189. (self-native-input? #t) ; for `tic'
  190. (native-inputs
  191. `(("pkg-config" ,pkg-config)))
  192. (native-search-paths
  193. (list (search-path-specification
  194. (variable "TERMINFO_DIRS")
  195. (files '("share/terminfo")))))
  196. (synopsis "Terminal emulation (termcap, terminfo) library")
  197. (description
  198. "GNU Ncurses is a library which provides capabilities to write text to
  199. a terminal in a terminal-independent manner. It supports pads and color as
  200. well as multiple highlights and forms characters. It is typically used to
  201. implement user interfaces for command-line applications. The accompanying
  202. ncursesw library provides wide character support.")
  203. (license x11)
  204. (home-page "https://www.gnu.org/software/ncurses/")))
  205. (define-public ncurses/gpm
  206. (package/inherit ncurses
  207. (name "ncurses-with-gpm")
  208. (arguments
  209. (substitute-keyword-arguments (package-arguments ncurses)
  210. ((#:configure-flags cf)
  211. `(cons (string-append "--with-gpm="
  212. (assoc-ref %build-inputs "gpm")
  213. "/lib/libgpm.so.2")
  214. ,cf))))
  215. (inputs
  216. `(("gpm" ,gpm)))))
  217. (define-public dialog
  218. (package
  219. (name "dialog")
  220. (version "1.3-20190211")
  221. (source (origin
  222. (method url-fetch)
  223. (uri (string-append
  224. "https://invisible-mirror.net/archives/dialog/dialog-"
  225. version ".tgz"))
  226. (sha256
  227. (base32
  228. "1lx0bvradzx1zl7znlrsnyljcs596r7wamkhyq37ikbxsy4y5h29"))))
  229. (build-system gnu-build-system)
  230. (arguments
  231. `(#:tests? #f)) ; no test suite
  232. (inputs
  233. `(("ncurses" ,ncurses)))
  234. (synopsis "Curses widgets")
  235. (description "Dialog is a script-interpreter which provides a set of
  236. curses widgets, such as dialog boxes.")
  237. (home-page "https://invisible-island.net/dialog/dialog.html")
  238. ;; Includes the gpl3 file "config.sub" from Automake.
  239. (license (list lgpl2.1 gpl3))))
  240. (define-public perl-curses
  241. (package
  242. (name "perl-curses")
  243. (version "1.36")
  244. (source
  245. (origin
  246. (method url-fetch)
  247. (uri (string-append "mirror://cpan/authors/id/G/GI/GIRAFFED/"
  248. "Curses-" version ".tar.gz"))
  249. (sha256
  250. (base32
  251. "0r6xd9wr0c25rr28zixhqipak575zqsfb7r7f2693i9il1dpj554"))))
  252. (build-system perl-build-system)
  253. (inputs
  254. `(("ncurses" ,ncurses)))
  255. (arguments
  256. `(#:make-maker-flags (list "PANELS" "MENUS")
  257. #:phases
  258. (modify-phases %standard-phases
  259. (add-before
  260. 'configure 'set-curses-ldflags
  261. (lambda* (#:key inputs #:allow-other-keys)
  262. (let* ((ncurses (assoc-ref inputs "ncurses"))
  263. (include (string-append ncurses "/include"))
  264. (lib (string-append ncurses "/lib")))
  265. (setenv "CURSES_LIBTYPE" "ncurses")
  266. (setenv "CURSES_CFLAGS" (string-append "-I" include))
  267. (setenv "CURSES_PANEL_CFLAGS" (string-append "-I" include))
  268. (setenv "CURSES_MENU_CFLAGS" (string-append "-I" include))
  269. (setenv "CURSES_FORM_CFLAGS" (string-append "-I" include))
  270. (setenv "CURSES_LDFLAGS" (string-append "-L" lib " -lncurses"))
  271. (setenv "CURSES_PANEL_LDFLAGS" (string-append "-L" lib " -lpanel"))
  272. (setenv "CURSES_MENU_LDFLAGS" (string-append "-L" lib " -lmenu"))
  273. (setenv "CURSES_FORM_LDFLAGS" (string-append "-L" lib " -lform"))
  274. #t))))))
  275. (home-page "https://metacpan.org/release/Curses")
  276. (synopsis "Terminal screen handling and optimization")
  277. (description
  278. "@code{Curses} is the interface between Perl and the curses library
  279. of your system.")
  280. (license perl-license)))
  281. (define-public stfl
  282. (package
  283. (name "stfl")
  284. (version "0.24")
  285. (source
  286. (origin
  287. (method url-fetch)
  288. (uri (string-append "http://www.clifford.at/stfl/stfl-"
  289. version ".tar.gz"))
  290. (sha256
  291. (base32
  292. "1460d5lc780p3q38l3wc9jfr2a7zlyrcra0li65aynj738cam9yl"))))
  293. (build-system gnu-build-system)
  294. (arguments
  295. '(#:tests? #f ; no test target
  296. #:make-flags (list (string-append "prefix=" (assoc-ref %outputs "out")))
  297. #:phases
  298. (modify-phases %standard-phases
  299. (delete 'configure) ; there is no configure script
  300. ;; in our ncurses, the headers are in /include
  301. (add-before 'build 'patch-ncursesw
  302. (lambda _
  303. (substitute* "stfl_internals.h"
  304. (("ncursesw/") ""))
  305. #t))
  306. (add-after 'install 'install-missing-symlink
  307. (lambda* (#:key outputs #:allow-other-keys)
  308. (let* ((out (assoc-ref outputs "out"))
  309. (lib (string-append out "/lib")))
  310. ;; Some programs look for libstfl.so.0.
  311. (symlink "libstfl.so" (string-append lib "/libstfl.so.0"))))))))
  312. (inputs `(("ncurses" ,ncurses)))
  313. (native-inputs `(("swig" ,swig)))
  314. (home-page "http://www.clifford.at/stfl/")
  315. (synopsis "Structured terminal forms library")
  316. (description "Stfl is a library which implements a curses-based widget
  317. set for text terminals.")
  318. (license lgpl3+)))