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