sabotage-linux / netbsd-curses

libcurses and dependencies taken from netbsd and brought into a portable shape (at least to musl or glibc)
Other
147 stars 14 forks source link
c curses linux ncurses netbsd-curses portable

netbsd-libcurses portable edition

this is a port of netbsd's curses library for usage on Linux systems (tested and developed on sabotage linux, based on musl libc). It should be possible to use on other POSIX platforms as well with minor changes.

it supports widechar (like the ncursesw build variant) and is close to being a 100% feature-complete drop-in replacement for ncurses.

to this date, there are only 3 implementations of the curses API:

Why do we need an ncurses replacement ?

Table 1: Comparison between ncurses and netbsd curses

NCURSES NETBSD CURSES
Size of extracted source 15.8 MB 3.3 MB
Installed size 15.9 MB 1.3 MB
Installed size w/debuginfo 128.3 MB 19.9 MB
Build time (make -j2) 59 sec 9 sec
size of libncursesw.so 346 KB 150 KB
size of static linked nano 334 KB 288 KB

when scaling up to more build jobs, it is expected that netbsd curses fares a lot better since its Makefile is fully parallelizable, while ncurses spends a lot of time in a single process executing the configure script.

Differences from ncurses

TODO

Compilation

netbsd-curses ships without a configure script, and requires GNU make. variables for compilation can be passed directly to make, or be saved into config.mak. recognized variables are:

examples:

make CFLAGS="-Os -Wall -fPIC" PREFIX=/usr/local -j4 all install
make CFLAGS=-O2 LDFLAGS=-static PREFIX=/usr all-static install-static

example config.mak:

CFLAGS = -O3 -Wall
PREFIX = /usr
DESTDIR = foo

if you're using config.mak, you can just run make && make install and the variables will be picked up automatically.

the all and install Makefile targets will build/install all programs, shared and static libs, and headers. the all-static and install-static targets will build/install all programs, static libs, and headers. the all-dynamic and install-dynamic targets will build/install all programs shared libs, and headers.

the all build can be sped up by putting -fPIC in CFLAGS. this has the effect that the same object files will be used for the dynamic and static libs; otherwise they will be compiled twice with different CFLAGS.

Compiled-in terminal database

support for about a dozen common TERMs is built-in already. if you need one that's not included, you can either add yours to libterminfo/genterms or make terminfo/terminfo.cdb and install the result to either $PREFIX/share/terminfo.cdb or $HOME/.terminfo.cdb.

Compiling software against netbsd-curses

the functionality that ncurses offers is usually (if not configured to split into several separate libs) available in a single libncurses library. netbsd-curses on the other hand has it always split into libcurses and libterminfo. this difference requires to give the build system a hint that it needs to link to both libcurses and libterminfo.

with these instructions it is easy to compile the majority of ncurses apps without problems against netbsd-curses.

a small percentage of apps written for ncurses poke at internals and need light patching:

if you have trouble compiling a specific package, first look at the sabotage linux build recipes. if you still can't get the package to compile, feel free to open an issue at the netbsd-curses issue tracker.

License

libcurses, tset and tput are (C) 1980-1994 "The Regents of the University of California" licensed under the 3-clause BSD license. Everything else is (C) 1999-2016 The NetBSD Foundation, Inc. and Contributors, licensed under the 2-clause BSD license. see COPYING for the full text, and in doubt, consult the copyright clauses in the respective .c files. Files without copyright clauses in the file header are explicitly released under the terms of the 2-clause BSD license as well.

APPENDIX A: Test Setup used for comparison in Table 1

All tests were done on a dual core x86_64 sabotage linux system, with the following features: installation of shared and static libs, headers, etc, i.e. make -j2 all install. ncurses and netbsd curses were both configured with support for widechars, and built-in terminfo database for a handful of terminals.

CFLAGS (optimized for size):
-g0 -fdata-sections -ffunction-sections -Os -fno-unwind-tables
-fno-asynchronous-unwind-tables -Wa,--noexecstack

LDFLAGS:
-s -Wl,--gc-sections -Wl,-z,relro,-z,now

netbsd curses was installed without manpages (ncurses: 1.1 MB) and terminfo database (ncurses: 6.4MB). the debug info build was created with -g3 and debuginfo stripped into external files via objcopy.

APPENDIX B: History of NetBSD curses

Thomas Dickey did a thorough investigation on the history of NetBSD curses.