1 | #include <stdlib.h>
|
---|
2 |
|
---|
3 | int main(int argc, const char **argv) {
|
---|
4 | char *omdev, *cd, *make;
|
---|
5 | int prefixlen;
|
---|
6 | if (argc != 2) {
|
---|
7 | fprintf(stderr, "Usage: %s [model-prefix]\n", argc > 0 ? *argv : "OpenModelica-Compile");
|
---|
8 | return 1;
|
---|
9 | }
|
---|
10 | prefixlen = strlen(argv[1]);
|
---|
11 | logfile = malloc(prefixlen + 10);
|
---|
12 | sprintf(logfile, "%s.log", argv[1]);
|
---|
13 | freopen(logfile, "w", stdout);
|
---|
14 | unsetenv("GCC_EXEC_PREFIX");
|
---|
15 | unsetenv("CPLUS_INCLUDE_PATH");
|
---|
16 | unsetenv("C_INCLUDE_PATH");
|
---|
17 | unsetenv("LIBRARY_PATH");
|
---|
18 | omdev = getenv("OMDEV");
|
---|
19 | if (!omdev) {
|
---|
20 | char *omhome;
|
---|
21 | omhome = getenv("OPENMODELICAHOME");
|
---|
22 | if (!omhome) {
|
---|
23 | fprintf(stderr, "OPENMODELICAHOME was not set; aborting");
|
---|
24 | return 1;
|
---|
25 | }
|
---|
26 | mingw = malloc(strlen(omhome) + 10);
|
---|
27 | sprintf(mingw, "%s\\MinGW", omhome);
|
---|
28 | } else {
|
---|
29 | mingw = malloc(strlen(omhome) + 25);
|
---|
30 | sprintf(mingw, "%s\\tools\\MinGW", omdev);
|
---|
31 | }
|
---|
32 | cd = get_current_dir_name();
|
---|
33 | path = malloc(strlen(cd)*2 + 50);
|
---|
34 | sprintf(path, "%s;%s\..\libexec\gcc\mingw32\4.4.0\;");
|
---|
35 | printf("Setting MINGW=%s\n", mingw);
|
---|
36 | printf("Setting PATH=%s\n", path);
|
---|
37 | setenv("MINGW", mingw);
|
---|
38 | setenv("PATH", path);
|
---|
39 | make = malloc(strlen(mingw) + +prefixlen + 100);
|
---|
40 | sprintf(make, "%s\bin\mingw32-make -f %s.makefile 2>&1");
|
---|
41 | printf("Executing command: %s\n", make);
|
---|
42 | return system(make);
|
---|
43 | /* let the OS free() */
|
---|
44 | }
|
---|