1 /// Wrapper which accepts DMC command-line syntax
2 /// and passes the transformed options to a MSVC cl.exe.
3 module msvc_dmc;
4 
5 import std.algorithm.searching;
6 import std.array;
7 import std.file;
8 import std.path;
9 import std.process;
10 import std.stdio;
11 
12 int main(string[] args)
13 {
14     auto cl = environment.get("MSVC_CC",
15         environment.get("VCINSTALLDIR", `\Program Files (x86)\Microsoft Visual Studio 10.0\VC\`)
16             .buildPath("bin", "amd64", "cl.exe"));
17     string[] newArgs = [cl];
18     newArgs ~= "/nologo";
19     newArgs ~= `/Ivcbuild`;
20     newArgs ~= `/Iroot`;
21     newArgs ~= `/FIwarnings.h`;
22     bool compilingOnly;
23 
24     foreach (arg; args[1..$])
25     {
26         switch (arg)
27         {
28             case "-Ae": // "enable exception handling"
29                 newArgs ~= "/EHa";
30                 break;
31             case "-c": // "skip the link, do compile only"
32                 newArgs ~= "/c";
33                 compilingOnly = true;
34                 break;
35             case "-cpp": // "source files are C++"
36                 newArgs ~= "/TP";
37                 break;
38             case "-e": // "show results of preprocessor"
39                 break;
40             case "-g": // "generate debug info"
41             case "-gl": // "debug line numbers only"
42                 newArgs ~= "/Zi";
43                 break;
44             case "-wx": // "treat warnings as errors"
45                 newArgs ~= "/WX";
46                 break;
47             default:
48                 if (arg.startsWith("-I")) // "#include file search path"
49                 {
50                     foreach (path; arg[2..$].split(";"))
51                         if (path != `\dm\include`)
52                             newArgs ~= "/I" ~ path;
53                 }
54                 else
55                 if (arg.startsWith("-o")) // "output filename"
56                     newArgs ~= "/F" ~ (compilingOnly ? "o" : "e") ~ arg[2..$];
57                 else
58                 if (arg[0] != '/' && arg[0] != '-' && !exists(arg) && exists(arg ~ ".c"))
59                     newArgs ~= arg ~ ".c";
60                 else
61                     newArgs ~= arg;
62                 break;
63         }
64     }
65     stderr.writeln(escapeShellCommand(newArgs));
66     return spawnProcess(newArgs).wait();
67 }