at 23.05-pre 130 lines 4.0 kB view raw
1# Arguments that this derivation gets when it is created with `callPackage` 2{ stdenv 3, lib 4, symlinkJoin 5, makeWrapper 6, runCommand 7, file 8}: 9 10open-watcom: 11 12let 13 wrapper = 14 {}: 15 let 16 binDirs = with stdenv.hostPlatform; if isWindows then [ 17 (lib.optionalString is64bit "binnt64") 18 "binnt" 19 (lib.optionalString is32bit "binw") 20 ] else if (isDarwin && is64bit) then [ 21 "bino64" 22 ] else [ 23 (lib.optionalString is64bit "binl64") 24 "binl" 25 ]; 26 includeDirs = with stdenv.hostPlatform; [ 27 "h" 28 ] 29 ++ lib.optional isWindows "h/nt" 30 ++ lib.optional isLinux "lh"; 31 listToDirs = list: lib.strings.concatMapStringsSep ":" (dir: "${placeholder "out"}/${dir}") list; 32 name = "${open-watcom.passthru.prettyName}-${open-watcom.version}"; 33 in 34 symlinkJoin { 35 inherit name; 36 37 paths = [ open-watcom ]; 38 39 nativeBuildInputs = [ makeWrapper ]; 40 41 postBuild = '' 42 mkdir $out/bin 43 44 for binDir in ${lib.strings.concatStringsSep " " binDirs}; do 45 for exe in $(find ${open-watcom}/$binDir \ 46 -type f -executable \ 47 ${lib.optionalString stdenv.hostPlatform.isLinux "-not -iname '*.so' -not -iname '*.exe'"} \ 48 ); do 49 if [ ! -f $out/bin/$(basename $exe) ]; then 50 makeWrapper $exe $out/bin/$(basename $exe) \ 51 --set WATCOM ${open-watcom} \ 52 --prefix PATH : ${listToDirs binDirs} \ 53 --set EDPATH ${open-watcom}/eddat \ 54 --set INCLUDE ${listToDirs includeDirs} 55 fi 56 done 57 done 58 ''; 59 60 passthru = { 61 unwrapped = open-watcom; 62 tests = let 63 wrapped = wrapper { }; 64 in { 65 simple = runCommand "${name}-test-simple" { nativeBuildInputs = [ wrapped ]; } '' 66 cat <<EOF >test.c 67 #include <stdio.h> 68 int main() { 69 printf ("Testing OpenWatcom C89 compiler.\n"); 70 return 0; 71 } 72 EOF 73 cat test.c 74 # Darwin target not supported, only host 75 wcl386 -fe=test_c test.c 76 ${lib.optionalString (!stdenv.hostPlatform.isDarwin) "./test_c"} 77 78 cat <<EOF >test.cpp 79 #include <string> 80 #include <iostream> 81 int main() { 82 std::cout << "Testing OpenWatcom C++ library implementation." << std::endl; 83 watcom::istring HELLO ("HELLO"); 84 if (HELLO != "hello") { 85 return 1; 86 } 87 if (HELLO.find ("ello") != 1) { 88 return 2; 89 } 90 return 0; 91 } 92 EOF 93 cat test.cpp 94 # Darwin target not supported, only host 95 wcl386 -fe=test_cpp test.cpp 96 ${lib.optionalString (!stdenv.hostPlatform.isDarwin) "./test_cpp"} 97 touch $out 98 ''; 99 cross = runCommand "${name}-test-cross" { nativeBuildInputs = [ wrapped file ]; } '' 100 cat <<EOF >test.c 101 #include <stdio.h> 102 int main() { 103 printf ("Testing OpenWatcom cross-compilation.\n"); 104 return 0; 105 } 106 EOF 107 cat test.c 108 109 echo "Test compiling" 110 wcl386 -bcl=linux -fe=linux test.c 111 wcl386 -bcl=nt -fe=nt test.c 112 wcl386 -bcl=dos4g -fe=dos4g test.c 113 wcl -bcl=windows -fe=windows test.c 114 wcl -bcl=dos -fe=dos test.c 115 116 echo "Test file format" 117 file ./linux | grep "32-bit" | grep "Linux" 118 file ./nt.exe | grep "PE32" | grep "Windows" 119 file ./dos4g.exe | grep "MS-DOS" | grep "LE executable" 120 file ./windows.exe | grep "MS-DOS" | grep "Windows 3.x" 121 file ./dos.exe | grep "MS-DOS" | grep -v "LE" | grep -v "Windows 3.x" 122 touch $out 123 ''; 124 }; 125 }; 126 127 inherit (open-watcom) meta; 128 }; 129in 130lib.makeOverridable wrapper