1{ lib
2, stdenv
3, fetchurl
4, buildPackages
5, pkg-config
6, abiVersion ? "6"
7, enableStatic ? stdenv.hostPlatform.isStatic
8, withCxx ? !stdenv.hostPlatform.useAndroidPrebuilt
9, mouseSupport ? false, gpm
10, unicodeSupport ? true
11, testers
12}:
13
14stdenv.mkDerivation (finalAttrs: {
15 version = "6.4";
16 pname = "ncurses" + lib.optionalString (abiVersion == "5") "-abi5-compat";
17
18 src = fetchurl {
19 url = "https://invisible-island.net/archives/ncurses/ncurses-${finalAttrs.version}.tar.gz";
20 hash = "sha256-aTEoPZrIfFBz8wtikMTHXyFjK7T8NgOsgQCBK+0kgVk=";
21 };
22
23 outputs = [ "out" "dev" "man" ];
24 setOutputFlags = false; # some aren't supported
25
26 configureFlags = [
27 (lib.withFeature (!enableStatic) "shared")
28 "--without-debug"
29 "--enable-pc-files"
30 "--enable-symlinks"
31 "--with-manpage-format=normal"
32 "--disable-stripping"
33 "--with-versioned-syms"
34 ] ++ lib.optional unicodeSupport "--enable-widec"
35 ++ lib.optional (!withCxx) "--without-cxx"
36 ++ lib.optional (abiVersion == "5") "--with-abi-version=5"
37 ++ lib.optional stdenv.hostPlatform.isNetBSD "--enable-rpath"
38 ++ lib.optionals stdenv.hostPlatform.isWindows [
39 "--enable-sp-funcs"
40 "--enable-term-driver"
41 ] ++ lib.optionals (stdenv.hostPlatform.isUnix && stdenv.hostPlatform.isStatic) [
42 # For static binaries, the point is to have a standalone binary with
43 # minimum dependencies. So here we make sure that binaries using this
44 # package won't depend on a terminfo database located in the Nix store.
45 "--with-terminfo-dirs=${lib.concatStringsSep ":" [
46 "/etc/terminfo" # Debian, Fedora, Gentoo
47 "/lib/terminfo" # Debian
48 "/usr/share/terminfo" # upstream default, probably all FHS-based distros
49 "/run/current-system/sw/share/terminfo" # NixOS
50 ]}"
51 ];
52
53 # Only the C compiler, and explicitly not C++ compiler needs this flag on solaris:
54 CFLAGS = lib.optionalString stdenv.isSunOS "-D_XOPEN_SOURCE_EXTENDED";
55
56 strictDeps = true;
57 depsBuildBuild = [
58 buildPackages.stdenv.cc
59 ];
60
61 nativeBuildInputs = [
62 pkg-config
63 ] ++ lib.optionals (stdenv.buildPlatform != stdenv.hostPlatform) [
64 buildPackages.ncurses
65 ];
66
67 buildInputs = lib.optional (mouseSupport && stdenv.isLinux) gpm;
68
69 preConfigure = ''
70 export PKG_CONFIG_LIBDIR="$dev/lib/pkgconfig"
71 mkdir -p "$PKG_CONFIG_LIBDIR"
72 configureFlagsArray+=(
73 "--libdir=$out/lib"
74 "--includedir=$dev/include"
75 "--bindir=$dev/bin"
76 "--mandir=$man/share/man"
77 "--with-pkg-config-libdir=$PKG_CONFIG_LIBDIR"
78 )
79 ''
80 + lib.optionalString stdenv.isSunOS ''
81 sed -i -e '/-D__EXTENSIONS__/ s/-D_XOPEN_SOURCE=\$cf_XOPEN_SOURCE//' \
82 -e '/CPPFLAGS="$CPPFLAGS/s/ -D_XOPEN_SOURCE_EXTENDED//' \
83 configure
84 CFLAGS=-D_XOPEN_SOURCE_EXTENDED
85 '';
86
87 enableParallelBuilding = true;
88
89 doCheck = false;
90
91 # When building a wide-character (Unicode) build, create backward
92 # compatibility links from the the "normal" libraries to the
93 # wide-character libraries (e.g. libncurses.so to libncursesw.so).
94 postFixup = let
95 abiVersion-extension = if stdenv.isDarwin then "${abiVersion}.$dylibtype" else "$dylibtype.${abiVersion}"; in
96 ''
97 # Determine what suffixes our libraries have
98 suffix="$(awk -F': ' 'f{print $3; f=0} /default library suffix/{f=1}' config.log)"
99 libs="$(ls $dev/lib/pkgconfig | tr ' ' '\n' | sed "s,\(.*\)$suffix\.pc,\1,g")"
100 suffixes="$(echo "$suffix" | awk '{for (i=1; i < length($0); i++) {x=substr($0, i+1, length($0)-i); print x}}')"
101
102 # Get the path to the config util
103 cfg=$(basename $dev/bin/ncurses*-config)
104
105 # symlink the full suffixed include directory
106 ln -svf . $dev/include/ncurses$suffix
107
108 for newsuffix in $suffixes ""; do
109 # Create a non-abi versioned config util links
110 ln -svf $cfg $dev/bin/ncurses$newsuffix-config
111
112 # Allow for end users who #include <ncurses?w/*.h>
113 ln -svf . $dev/include/ncurses$newsuffix
114
115 for library in $libs; do
116 for dylibtype in so dll dylib; do
117 if [ -e "$out/lib/lib''${library}$suffix.$dylibtype" ]; then
118 ln -svf lib''${library}$suffix.$dylibtype $out/lib/lib$library$newsuffix.$dylibtype
119 ln -svf lib''${library}$suffix.${abiVersion-extension} $out/lib/lib$library$newsuffix.${abiVersion-extension}
120 if [ "ncurses" = "$library" ]
121 then
122 # make libtinfo symlinks
123 ln -svf lib''${library}$suffix.$dylibtype $out/lib/libtinfo$newsuffix.$dylibtype
124 ln -svf lib''${library}$suffix.${abiVersion-extension} $out/lib/libtinfo$newsuffix.${abiVersion-extension}
125 fi
126 fi
127 done
128 for statictype in a dll.a la; do
129 if [ -e "$out/lib/lib''${library}$suffix.$statictype" ]; then
130 ln -svf lib''${library}$suffix.$statictype $out/lib/lib$library$newsuffix.$statictype
131 if [ "ncurses" = "$library" ]
132 then
133 # make libtinfo symlinks
134 ln -svf lib''${library}$suffix.$statictype $out/lib/libtinfo$newsuffix.$statictype
135 fi
136 fi
137 done
138 ln -svf ''${library}$suffix.pc $dev/lib/pkgconfig/$library$newsuffix.pc
139 done
140 done
141
142 # move some utilities to $bin
143 # these programs are used at runtime and don't really belong in $dev
144 moveToOutput "bin/clear" "$out"
145 moveToOutput "bin/reset" "$out"
146 moveToOutput "bin/tabs" "$out"
147 moveToOutput "bin/tic" "$out"
148 moveToOutput "bin/tput" "$out"
149 moveToOutput "bin/tset" "$out"
150 moveToOutput "bin/captoinfo" "$out"
151 moveToOutput "bin/infotocap" "$out"
152 moveToOutput "bin/infocmp" "$out"
153 '';
154
155 preFixup = lib.optionalString (!stdenv.hostPlatform.isCygwin && !enableStatic) ''
156 rm "$out"/lib/*.a
157 '';
158
159 meta = with lib; {
160 homepage = "https://www.gnu.org/software/ncurses/";
161 description = "Free software emulation of curses in SVR4 and more";
162 longDescription = ''
163 The Ncurses (new curses) library is a free software emulation of curses in
164 System V Release 4.0, and more. It uses Terminfo format, supports pads and
165 color and multiple highlights and forms characters and function-key
166 mapping, and has all the other SYSV-curses enhancements over BSD Curses.
167
168 The ncurses code was developed under GNU/Linux. It has been in use for
169 some time with OpenBSD as the system curses library, and on FreeBSD and
170 NetBSD as an external package. It should port easily to any
171 ANSI/POSIX-conforming UNIX. It has even been ported to OS/2 Warp!
172 '';
173 license = licenses.mit;
174 pkgConfigModules = let
175 base = [
176 "form"
177 "menu"
178 "ncurses"
179 "panel"
180 ] ++ lib.optional withCxx "ncurses++";
181 in base ++ lib.optionals unicodeSupport (map (p: p + "w") base);
182 platforms = platforms.all;
183 };
184
185 passthru = {
186 ldflags = "-lncurses";
187 inherit unicodeSupport abiVersion;
188 tests.pkg-config = testers.testMetaPkgConfig finalAttrs.finalPackage;
189 };
190})