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 53 54 55 56 57 58 59 60
| #include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, char* argv[])
{
char* cmdLine = (char*) malloc(32768);
const char* target = getenv("GCC_TARGET");
char* prog = argv[0]+strlen(argv[0])-1;
int i;
PROCESS_INFORMATION process;
STARTUPINFO startup;
DWORD code;
if(!target)
target = "mingw32";
while(prog != argv[0] && prog[-1] != '/' && prog[-1] != '\\')
prog--;
for(i = 1; i < argc; ++i)
{
if (strcmp(argv[i], "-b") == 0)
{
if(i < argc-1)
{
i++;
target=argv[i];
}
else
{
fprintf(stderr, "expects argument after -b");
}
}
}
sprintf(cmdLine, "%s-%s", target, prog);
for(i = 1; i < argc; ++i)
{
if (strcmp(argv[i], "-b") == 0)
{
i++;
}
else
{
strcat(cmdLine, " ");
strcat(cmdLine, argv[i]);
}
}
memset(&startup, 0, sizeof(startup));
startup.cb = sizeof(startup);
CreateProcessA(0, cmdLine, 0, 0, TRUE, 0, 0, 0, &startup, &process);
WaitForSingleObject(process.hProcess, INFINITE);
GetExitCodeProcess(process.hProcess, &code);
CloseHandle(process.hThread);
CloseHandle(process.hProcess);
free(cmdLine);
return code;
} |
Partager