summaryrefslogtreecommitdiffstats
path: root/Tools/CLWrapper/CLWrapper.cpp
blob: 7d41f2b711b657ce2b39c90c275862854fbd9cce (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// CLWrapper.cpp : Calls the perl script parallelcl to perform parallel compilation

#define WIN32_LEAN_AND_MEAN    // Exclude rarely-used stuff from Windows headers
#include <process.h>
#include <stdio.h>
#include <string>
#include <windows.h>

using namespace std;

int wmain(int argc, wchar_t* argv[])
{
    const int numArgs = 3;

#ifndef NDEBUG
    fwprintf(stderr, L"######### im in ur IDE, compiling ur c0des ########\n");
#endif

    wstring** args = new wstring*[numArgs];

    args[0] = new wstring(L"sh");
    args[1] = new wstring(L"-c");

    args[2] = new wstring(L"\"parallelcl");
    for (int i = 1; i < argc; ++i) {
        args[2]->append(L" '");
        args[2]->append(argv[i]);
        if (i < argc - 1)
            args[2]->append(L"' ");
        else
            args[2]->append(L"'");
    }
    args[2]->append(L"\"");

    for (unsigned i = 0; i < args[2]->length(); i++) {
       if (args[2]->at(i) == '\\')
            args[2]->at(i) = '/';
    }

    wchar_t** newArgv = new wchar_t*[numArgs + 1];
    for (int i = 0; i < numArgs; i++)
        newArgv[i] = (wchar_t*)args[i]->c_str();

    newArgv[numArgs] = 0;

#ifndef NDEBUG
    fwprintf(stderr, L"exec(\"%s\", \"%s\", \"%s\", \"%s\")\n", L"sh", newArgv[0], newArgv[1], newArgv[2]);
#endif

    return _wspawnvp(_P_WAIT, L"sh", newArgv);
}