tuicam: init at 0.0.2 (#377825)
[NixPkgs.git] / pkgs / development / compilers / open-watcom / wrapper.nix
blob878253f2caf36b309a2ca414df705b2da8bd2162
1 # Arguments that this derivation gets when it is created with `callPackage`
3   stdenv,
4   lib,
5   symlinkJoin,
6   makeWrapper,
7   runCommand,
8   file,
9 }:
11 open-watcom:
13 let
14   wrapper =
15     { }:
16     let
17       archToBindir =
18         with stdenv.hostPlatform;
19         if isx86 then
20           "bin"
21         else if isAarch then
22           "arm"
23         # we don't support running on AXP
24         # don't know what MIPS, PPC bindirs are called
25         else
26           throw "Don't know where ${system} binaries are located!";
28       binDirs =
29         with stdenv.hostPlatform;
30         if isWindows then
31           [
32             (lib.optionalString is64bit "${archToBindir}nt64")
33             "${archToBindir}nt"
34             (lib.optionalString is32bit "${archToBindir}w")
35           ]
36         else if (isDarwin) then
37           [
38             (lib.optionalString is64bit "${archToBindir}o64")
39             # modern Darwin cannot execute 32-bit code anymore
40             (lib.optionalString is32bit "${archToBindir}o")
41           ]
42         else
43           [
44             (lib.optionalString is64bit "${archToBindir}l64")
45             "${archToBindir}l"
46           ];
47       # TODO
48       # This works good enough as-is, but should really only be targetPlatform-specific
49       # but we don't support targeting DOS, OS/2, 16-bit Windows etc Nixpkgs-wide so this needs extra logic
50       includeDirs =
51         with stdenv.hostPlatform;
52         [
53           "h"
54         ]
55         ++ lib.optional isWindows "h/nt"
56         ++ lib.optional isLinux "lh";
57       listToDirs = list: lib.strings.concatMapStringsSep ":" (dir: "${placeholder "out"}/${dir}") list;
58       name = "${open-watcom.passthru.prettyName}-${open-watcom.version}";
59     in
60     symlinkJoin {
61       inherit name;
63       paths = [ open-watcom ];
65       nativeBuildInputs = [ makeWrapper ];
67       postBuild = ''
68         mkdir $out/bin
70         for binDir in ${lib.strings.concatStringsSep " " binDirs}; do
71           for exe in $(find ${open-watcom}/$binDir \
72           -type f -executable \
73           ${lib.optionalString stdenv.hostPlatform.isLinux "-not -iname '*.so' -not -iname '*.exe'"} \
74           ); do
75             if [ ! -f $out/bin/$(basename $exe) ]; then
76               makeWrapper $exe $out/bin/$(basename $exe) \
77                 --set WATCOM ${open-watcom} \
78                 --prefix PATH : ${listToDirs binDirs} \
79                 --set EDPATH ${open-watcom}/eddat \
80                 --set INCLUDE ${listToDirs includeDirs}
81             fi
82           done
83         done
84       '';
86       passthru = {
87         unwrapped = open-watcom;
88         tests =
89           let
90             wrapped = wrapper { };
91           in
92           {
93             simple = runCommand "${name}-test-simple" { nativeBuildInputs = [ wrapped ]; } ''
94               cat <<EOF >test.c
95               #include <stdio.h>
96               int main() {
97                 printf ("Testing OpenWatcom C89 compiler.\n");
98                 return 0;
99               }
100               EOF
101               cat test.c
102               wcl386 -fe=test_c test.c
103               # Only test execution if hostPlatform is targetable
104               ${lib.optionalString (!stdenv.hostPlatform.isDarwin && !stdenv.hostPlatform.isAarch) "./test_c"}
106               cat <<EOF >test.cpp
107               #include <string>
108               #include <iostream>
109               int main() {
110                 std::cout << "Testing OpenWatcom C++ library implementation." << std::endl;
111                 watcom::istring HELLO ("HELLO");
112                 if (HELLO != "hello") {
113                   return 1;
114                 }
115                 if (HELLO.find ("ello") != 1) {
116                   return 2;
117                 }
118                 return 0;
119               }
120               EOF
121               cat test.cpp
122               wcl386 -fe=test_cpp test.cpp
123               # Only test execution if hostPlatform is targetable
124               ${lib.optionalString (!stdenv.hostPlatform.isDarwin && !stdenv.hostPlatform.isAarch) "./test_cpp"}
125               touch $out
126             '';
127             cross =
128               runCommand "${name}-test-cross"
129                 {
130                   nativeBuildInputs = [
131                     wrapped
132                     file
133                   ];
134                 }
135                 ''
136                   cat <<EOF >test.c
137                   #include <stdio.h>
138                   int main() {
139                     printf ("Testing OpenWatcom cross-compilation.\n");
140                     return 0;
141                   }
142                   EOF
143                   cat test.c
145                   echo "Test compiling"
146                   wcl386 -bcl=linux -fe=linux test.c
147                   wcl386 -bcl=nt -fe=nt test.c
148                   wcl386 -bcl=dos4g -fe=dos4g test.c
149                   wcl -bcl=windows -fe=windows test.c
150                   wcl -bcl=dos -fe=dos test.c
152                   echo "Test file format"
153                   file ./linux | grep "32-bit" | grep "Linux"
154                   file ./nt.exe | grep "PE32" | grep "Windows"
155                   file ./dos4g.exe | grep "MS-DOS" | grep "LE executable"
156                   file ./windows.exe | grep "MS-DOS" | grep "Windows 3.x"
157                   file ./dos.exe | grep "MS-DOS" | grep -v "LE" | grep -v "Windows 3.x"
158                   touch $out
159                 '';
160           };
161       };
163       inherit (open-watcom) meta;
164     };
166 lib.makeOverridable wrapper