1{ 2 lib, 3 stdenvNoCC, 4 fetchurl, 5 qemu, 6 writeScript, 7 writeScriptBin, 8 ncurses, 9 bash, 10 coreutils, 11 unixtools, 12}: 13 14let 15 16 # We execute all OpenWatcom binaries in qemu-user, because otherwise 17 # some binaries (most notably the installer itself and wlib) fail to 18 # use the stat() systemcall. The failure mode is that it returns 19 # EOVERFLOW for completely legitimate requests. This seems like an 20 # incompatibility of new Linux kernels to run this ancient binary. 21 wrapLegacyBinary = writeScript "wrapLegacyBinary" '' 22 #!${bash}/bin/bash 23 24 set -eu 25 26 if [ $# -ne 2 ]; then 27 echo "Usage: $0 unwrapped-binary wrapped-binary" 28 exit 1 29 fi 30 31 IN="$(${coreutils}/bin/realpath $1)" 32 OUT="$2" 33 ARGV0="$(basename $2)" 34 35 cat > "$OUT" <<EOF 36 #!${bash}/bin/bash 37 38 TERMINFO=${ncurses}/share/terminfo TERM=vt100 exec ${qemu}/bin/qemu-i386 -0 $ARGV0 $IN "\$@" 39 EOF 40 41 chmod +x "$OUT" 42 ''; 43 44 wrapInPlace = writeScriptBin "wrapInPlace" '' 45 #!${bash}/bin/bash 46 47 set -eu 48 49 if [ $# -ne 1 ]; then 50 echo "Usage: $0 unwrapped-binary" 51 exit 1 52 fi 53 54 TARGET="$1" 55 56 mv "$TARGET" "$TARGET-unwrapped" 57 chmod +x "$TARGET-unwrapped" 58 59 exec ${wrapLegacyBinary} "$TARGET-unwrapped" "$TARGET" 60 ''; 61 62in 63stdenvNoCC.mkDerivation rec { 64 pname = "${passthru.prettyName}-unwrapped"; 65 version = "1.9"; 66 67 src = fetchurl { 68 url = "http://ftp.openwatcom.org/install/open-watcom-c-linux-${version}"; 69 sha256 = "1wzkvc6ija0cjj5mcyjng5b7hnnc5axidz030c0jh05pgvi4nj7p"; 70 }; 71 72 nativeBuildInputs = [ 73 wrapInPlace 74 unixtools.script 75 ]; 76 77 dontUnpack = true; 78 dontConfigure = true; 79 80 buildPhase = '' 81 cp ${src} install-bin-unwrapped 82 wrapInPlace install-bin-unwrapped 83 ''; 84 85 installPhase = '' 86 # Command line options to do an unattended install are documented in 87 # https://github.com/open-watcom/open-watcom-v2/blob/master/bld/setupgui/setup.txt 88 script -c "./install-bin-unwrapped -dDstDir=$out -dFullInstall=1 -i" 89 90 for e in $(find $out/binl -type f -executable); do 91 echo "Wrapping $e" 92 wrapInPlace "$e" 93 done 94 ''; 95 96 passthru.prettyName = "open-watcom-bin"; 97 98 meta = with lib; { 99 description = "Project to maintain and enhance the Watcom C, C++, and Fortran cross compilers and tools"; 100 sourceProvenance = with sourceTypes; [ binaryNativeCode ]; 101 homepage = "http://www.openwatcom.org/"; 102 license = licenses.watcom; 103 platforms = [ 104 "x86_64-linux" 105 "i686-linux" 106 ]; 107 maintainers = [ maintainers.blitz ]; 108 }; 109}