Mercurial > mxe-octave
annotate src/build-msvctools/cc-msvc.cc @ 3337:8480924d2b85
[MSVC] Use POSIX compliant getopt version from mingw64.
* src/build-msvctools/Makefile (getopt.c, getopt.h): Use versions from
mingw64, as they're POSIX compliant.
(posixcompat.lib): New target library, replaces dirent.lib and
getopt.lib.
(dirent.lib, getopt.lib): Removed targets.
* src/build-msvctools/getopt.diff: Removed obsolete patch.
* src/build-msvctools/cc-msvc.cc: Links against posixcompat.lib instead
of dirent.lib
* src/build-msvctools/unistd.h: Include getopt.h, for POSIX compliance.
author | Michael Goffioul <michael.goffioul@gmail.com> |
---|---|
date | Fri, 29 Nov 2013 18:46:45 -0500 |
parents | b28756fd131c |
children |
rev | line source |
---|---|
3061
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
1 /* |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
2 * cc-msvc |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
3 * This code is a C translation of the cccl script from Geoffrey Wossum |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
4 * (http://cccl.sourceforge.net), with minor modifications and support for |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
5 * additional compilation flags. This tool is primarily intended to compile |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
6 * Octave source code with MSVC compiler. |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
7 * |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
8 * Copyright (C) 2006 Michael Goffioul |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
9 * |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
10 * cccl |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
11 * Wrapper around MS's cl.exe and link.exe to make them act more like |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
12 * Unix cc and ld |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
13 * |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
14 * Copyright (C) 2000-2003 Geoffrey Wossum (gwossum@acm.org) |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
15 * |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
16 * ========================================================================= |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
17 * |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
18 * This program is free software; you can redistribute it and/or modify |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
19 * it under the terms of the GNU General Public License as published by |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
20 * the Free Software Foundation; either version 2 of the License, or |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
21 * (at your option) any later version. |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
22 * |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
23 * This program is distributed in the hope that it will be useful, but |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
24 * WITHOUT ANY WARRANTY; without even the implied warranty of |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
26 * General Public License for more details. |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
27 * |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
28 * You should have received a copy of the GNU General Public License |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
29 * along with this program; If not, see <http://www.gnu.org/licenses/>. |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
30 * |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
31 * ========================================================================= |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
32 * |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
33 * Compile this file with "cl -EHs -O2 cc-msvc.cc" and install it into |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
34 * your PATH environment variable. |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
35 * |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
36 */ |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
37 |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
38 #include <iostream> |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
39 #include <string> |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
40 #include <vector> |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
41 #include <list> |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
42 #include <algorithm> |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
43 #include <io.h> |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
44 #include <stdio.h> |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
45 #define WIN32_LEAN_AND_MEAN |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
46 #include <windows.h> |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
47 |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
48 #ifdef _MSC_VER |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
49 #define popen _popen |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
50 #define pclose _pclose |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
51 #endif |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
52 |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
53 using namespace std; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
54 |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
55 static string usage_msg = |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
56 "Usage: cc-msvc [OPTIONS]\n" |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
57 "\n" |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
58 "cc-msvc is a wrapper around Microsoft's cl.exe and link.exe. It translates\n" |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
59 "parameters that Unix cc's and ld's understand to parameters that cl and link\n" |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
60 "understand."; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
61 static string version_msg = |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
62 "cc-msvc 0.1\n" |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
63 "\n" |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
64 "Copyright 2006 Michael Goffioul\n" |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
65 "This is free software; see the source for copying conditions. There is NO\n" |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
66 "waranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n"; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
67 |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
68 inline bool starts_with(const string& s, const string& prefix) |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
69 { |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
70 return (s.length() >= prefix.length() && s.find(prefix) == 0); |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
71 } |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
72 |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
73 inline bool ends_with(const string& s, const string& suffix) |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
74 { |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
75 return (s.length() >= suffix.length() && s.rfind(suffix) == s.length()-suffix.length()); |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
76 } |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
77 |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
78 static list<string> split(const string& s, char delim) |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
79 { |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
80 list<string> result; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
81 size_t current = 0, pos, len = s.length (); |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
82 |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
83 while (current < len) |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
84 { |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
85 pos = s.find (delim, current); |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
86 if (pos == string::npos) |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
87 { |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
88 result.push_back (s.substr (current)); |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
89 break; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
90 } |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
91 else |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
92 { |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
93 result.push_back (s.substr (current, pos - current)); |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
94 current = pos + 1; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
95 } |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
96 } |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
97 |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
98 return result; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
99 } |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
100 |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
101 static string get_line(FILE *fp) |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
102 { |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
103 static vector<char> buf(100); |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
104 int idx = 0; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
105 char c; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
106 |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
107 while (1) |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
108 { |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
109 c = (char)fgetc(fp); |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
110 if (c == '\n' || c == EOF) |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
111 break; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
112 if (buf.size() <= idx) |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
113 buf.resize(buf.size() + 100); |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
114 buf[idx++] = c; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
115 } |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
116 if (idx == 0) |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
117 return string(""); |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
118 else |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
119 return string(&buf[0], idx); |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
120 } |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
121 |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
122 static string process_depend(const string& s) |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
123 { |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
124 string result; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
125 string tmp(s); |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
126 |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
127 if (tmp.find(' ') != std::string::npos) |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
128 { |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
129 std::string sp; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
130 int len; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
131 |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
132 sp.resize(tmp.length()+1); |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
133 len = GetShortPathName(tmp.c_str(), &sp[0], tmp.length()+1); |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
134 sp.resize(len); |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
135 tmp = sp; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
136 } |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
137 |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
138 for (int i=0; i<tmp.length(); i++) |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
139 { |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
140 if (tmp[i] == ' ') |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
141 result += "\\ "; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
142 else if (tmp[i] == '\\' && i < tmp.length()-1 && tmp[i+1] == '\\') |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
143 { |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
144 result.push_back('/'); |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
145 i++; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
146 } |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
147 else |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
148 result.push_back(tmp[i]); |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
149 } |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
150 return result; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
151 } |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
152 |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
153 static string de_cygwin_path(const string& s) |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
154 { |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
155 string result = s; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
156 |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
157 if (starts_with(s, "/cygdrive/")) |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
158 { |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
159 string cmd = "cygpath -m \"" + s + "\""; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
160 FILE* pout = _popen(cmd.c_str(), "r"); |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
161 |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
162 if (pout != NULL) |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
163 { |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
164 result = get_line(pout); |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
165 _pclose(pout); |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
166 } |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
167 } |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
168 |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
169 return result; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
170 } |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
171 |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
172 static string quote_path(const string& s) |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
173 { |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
174 string result = de_cygwin_path(s); |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
175 |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
176 if (result.find(' ') != string::npos) |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
177 return "\"" + result + "\""; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
178 return result; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
179 } |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
180 |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
181 static string quote_define(const string& name, const string& value) |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
182 { |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
183 if (value[0] == '"') |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
184 { |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
185 string result; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
186 |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
187 for (int i=0; i<value.length(); i++) |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
188 switch (value[i]) |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
189 { |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
190 case '"': |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
191 result += "\\\""; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
192 break; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
193 case '&': |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
194 case '<': |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
195 case '>': |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
196 case '(': |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
197 case ')': |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
198 case '|': |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
199 case '^': |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
200 case '@': |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
201 result.push_back('^'); |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
202 default: |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
203 result.push_back(value[i]); |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
204 break; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
205 } |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
206 return ("\"" + name + "=" + result + "\""); |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
207 } |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
208 else |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
209 { |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
210 if (value.find_first_of("&<>()@^| ") != string::npos) |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
211 return ("\"" + name + "=" + value + "\""); |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
212 else |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
213 return (name + "=" + value); |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
214 } |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
215 } |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
216 |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
217 static string quote_quotes(const string& s) |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
218 { |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
219 string result; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
220 |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
221 if (s.find('"') != string::npos) |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
222 { |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
223 for (int i=0; i<s.length(); i++) |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
224 if (s[i] == '"') |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
225 result += "\\\""; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
226 else |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
227 result.push_back(s[i]); |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
228 } |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
229 else |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
230 result = s; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
231 |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
232 if (result.find_first_of("&<>()@^| ") != string::npos) |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
233 result = "\"" + result + "\""; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
234 |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
235 #if 0 |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
236 if (result.find_first_of("<>") != string::npos) |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
237 { |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
238 /* Could not find a better way to avoid the problem |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
239 * with those characters. */ |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
240 replace(result.begin(), result.end(), '<', '['); |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
241 replace(result.begin(), result.end(), '>', ']'); |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
242 } |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
243 #endif |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
244 |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
245 return result; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
246 } |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
247 |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
248 static int do_system(const string& cmd) |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
249 { |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
250 STARTUPINFO info; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
251 PROCESS_INFORMATION proc; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
252 DWORD result; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
253 |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
254 ZeroMemory (&info, sizeof (info)); |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
255 info.cb = sizeof (info); |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
256 ZeroMemory (&proc, sizeof (proc)); |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
257 |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
258 if (CreateProcess (NULL, (char*)cmd.c_str (), NULL, NULL, TRUE, 0, NULL, NULL, |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
259 &info, &proc)) |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
260 { |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
261 WaitForSingleObject (proc.hProcess, INFINITE); |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
262 GetExitCodeProcess (proc.hProcess, &result); |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
263 CloseHandle (proc.hProcess); |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
264 CloseHandle (proc.hThread); |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
265 } |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
266 else |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
267 result = (DWORD)-1; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
268 |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
269 return result; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
270 } |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
271 |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
272 static bool read_stdin(const char *filename) |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
273 { |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
274 char buf[1024]; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
275 int n; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
276 FILE *fout = fopen(filename, "wb"); |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
277 |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
278 if (fout == NULL) |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
279 { |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
280 cerr << filename << ": cannot open file for writing" << endl; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
281 return false; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
282 } |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
283 while ((n = fread(buf, 1, 1024, stdin)) > 0) |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
284 fwrite(buf, 1, n, fout); |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
285 fclose(fout); |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
286 return true; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
287 } |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
288 |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
289 static void replace_option(string& s, const string& opt, const string& val = string()) |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
290 { |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
291 if (starts_with(s, opt)) |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
292 s.erase(0, opt.length()).insert(0, val); |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
293 if (ends_with(s, opt)) |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
294 s.erase(s.length()-opt.length()).append(val); |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
295 |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
296 string look_str = (" " + opt + " "); |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
297 int n = opt.length(); |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
298 int pos; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
299 |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
300 while ((pos = s.find(look_str)) != string::npos) |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
301 s.replace(pos+1, n, val); |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
302 } |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
303 |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
304 static void update_environment (void) |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
305 { |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
306 char name_buffer[1024]; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
307 DWORD len = GetModuleFileName (NULL, name_buffer, sizeof (name_buffer)); |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
308 |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
309 if (len == 0 && len >= sizeof (name_buffer)) |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
310 return; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
311 |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
312 string root (name_buffer); |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
313 size_t pos = root.find_last_of ("\\/"); |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
314 |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
315 if (pos != string::npos) |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
316 root.resize (pos); |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
317 |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
318 if (root == "bin" |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
319 || ends_with (root, "\\bin") |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
320 || ends_with (root, "/bin")) |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
321 { |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
322 if (root.size () == 3) |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
323 root.clear (); |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
324 else |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
325 root.resize (root.size () - 4); |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
326 |
3112
31edb6eea0eb
[MSVC] fix cc-msvc when INCLUDE/LIB variables are empty, improve compatibility with MinGW.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
3087
diff
changeset
|
327 char * include_var_s = getenv ("INCLUDE"); |
31edb6eea0eb
[MSVC] fix cc-msvc when INCLUDE/LIB variables are empty, improve compatibility with MinGW.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
3087
diff
changeset
|
328 char * lib_var_s = getenv ("LIB"); |
31edb6eea0eb
[MSVC] fix cc-msvc when INCLUDE/LIB variables are empty, improve compatibility with MinGW.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
3087
diff
changeset
|
329 |
31edb6eea0eb
[MSVC] fix cc-msvc when INCLUDE/LIB variables are empty, improve compatibility with MinGW.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
3087
diff
changeset
|
330 string include_var = (include_var_s ? include_var_s : ""); |
31edb6eea0eb
[MSVC] fix cc-msvc when INCLUDE/LIB variables are empty, improve compatibility with MinGW.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
3087
diff
changeset
|
331 string lib_var = (lib_var_s ? lib_var_s : ""); |
3061
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
332 |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
333 if (include_var.empty ()) |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
334 include_var = "INCLUDE=" + root + "\\include"; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
335 else |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
336 include_var = "INCLUDE=" + root + "\\include;" + include_var; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
337 |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
338 if (lib_var.empty ()) |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
339 lib_var = "LIB=" + root + "\\lib"; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
340 else |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
341 lib_var = "LIB=" + root + "\\lib;" + lib_var; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
342 |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
343 putenv (include_var.c_str ()); |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
344 putenv (lib_var.c_str ()); |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
345 } |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
346 } |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
347 |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
348 int main(int argc, char **argv) |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
349 { |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
350 string clopt, linkopt, cllinkopt, sourcefile, objectfile, optarg, prog, exefile; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
351 list<string> Xlinkopt; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
352 bool gotparam, dodepend, exeoutput, doshared, debug = false, read_from_stdin, gotXlinker; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
353 bool mt_embed = true; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
354 bool no_exceptions = false, default_libs = true, incremental_link = false; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
355 bool cppmode = false; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
356 |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
357 prog = "cl"; |
3080
c0222ce8760d
[MSVC] enable MSVC compilation
Michael Goffioul <michael.goffioul@gmail.com>
parents:
3076
diff
changeset
|
358 // Default target is WinXP SP3 |
3127
e0257da7fcdc
[MSVC] only use special math.h with clgcc and similar.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
3112
diff
changeset
|
359 clopt = "-nologo -MD -DWIN32 -D__CLGCC__ -D_WIN32 -D__WIN32__ -DNTDDI_VERSION=0x05010300 -D_WIN32_WINNT=0x0501"; |
3061
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
360 linkopt = "-nologo"; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
361 cllinkopt = ""; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
362 sourcefile = ""; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
363 objectfile = ""; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
364 gotparam = false; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
365 dodepend = false; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
366 exeoutput = true; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
367 exefile = ""; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
368 doshared = false; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
369 read_from_stdin = false; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
370 gotXlinker = false; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
371 |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
372 cppmode = (ends_with (argv[0], "c++-msvc.exe") |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
373 || ends_with (argv[0], "c++-msvc") |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
374 || ends_with (argv[0], "clg++.exe") |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
375 || ends_with (argv[0], "clg++")); |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
376 if (cppmode) |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
377 clopt += " -EHsc"; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
378 |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
379 update_environment (); |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
380 |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
381 if (argc == 1) |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
382 { |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
383 cout << usage_msg << endl; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
384 return 1; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
385 } |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
386 |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
387 for (int i=1; i<argc; i++) |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
388 { |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
389 string arg = argv[i]; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
390 size_t pos; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
391 |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
392 optarg = ""; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
393 gotparam = true; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
394 |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
395 if (gotXlinker) |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
396 { |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
397 Xlinkopt.push_back(arg); |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
398 gotXlinker = false; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
399 continue; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
400 } |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
401 |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
402 if (!starts_with(arg, "-D") && (pos=arg.find('=')) != string::npos) |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
403 { |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
404 optarg = arg.substr(pos+1); |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
405 } |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
406 |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
407 if (starts_with(arg, "-D")) |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
408 { |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
409 if ((pos=arg.find('=')) != string::npos) |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
410 { |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
411 optarg = arg.substr(pos+1); |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
412 arg.resize(pos); |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
413 arg = quote_define(arg, optarg); |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
414 } |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
415 clopt += " " + arg; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
416 continue; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
417 } |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
418 |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
419 if (arg == "--version" || arg == "-V") |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
420 { |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
421 cout << version_msg << endl; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
422 return 0; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
423 } |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
424 else if (arg == "-M") |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
425 { |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
426 dodepend = true; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
427 if (!exeoutput) |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
428 clopt += " -E"; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
429 else |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
430 { |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
431 exeoutput = false; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
432 clopt += " -E -c"; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
433 } |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
434 } |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
435 else if (arg == "-P") |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
436 { |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
437 clopt += " -EP"; |
3289
b28756fd131c
* src/build-msvctools/cc-msvc.cc: Allow to preprocess-only.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
3127
diff
changeset
|
438 exeoutput = false; |
b28756fd131c
* src/build-msvctools/cc-msvc.cc: Allow to preprocess-only.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
3127
diff
changeset
|
439 } |
b28756fd131c
* src/build-msvctools/cc-msvc.cc: Allow to preprocess-only.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
3127
diff
changeset
|
440 else if (arg == "-E") |
b28756fd131c
* src/build-msvctools/cc-msvc.cc: Allow to preprocess-only.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
3127
diff
changeset
|
441 { |
b28756fd131c
* src/build-msvctools/cc-msvc.cc: Allow to preprocess-only.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
3127
diff
changeset
|
442 clopt += " -E"; |
b28756fd131c
* src/build-msvctools/cc-msvc.cc: Allow to preprocess-only.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
3127
diff
changeset
|
443 exeoutput = false; |
3061
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
444 } |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
445 else if (arg == "-ansi") |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
446 { |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
447 clopt += " -Za"; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
448 } |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
449 else if (arg == "-c") |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
450 { |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
451 if (!dodepend) |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
452 { |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
453 clopt += " -c"; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
454 exeoutput = false; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
455 } |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
456 } |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
457 else if (arg == "-g" || (starts_with(arg, "-g") && arg.length() == 3 && arg[2] >= '0' && arg[2] <= '9')) |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
458 { |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
459 clopt += " -Zi"; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
460 linkopt += " -debug"; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
461 } |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
462 else if (arg == "-d") |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
463 { |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
464 debug = true; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
465 } |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
466 else if (arg == "-shared") |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
467 { |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
468 clopt += " -LD"; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
469 linkopt += " -DLL"; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
470 doshared = true; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
471 } |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
472 else if (arg == "-mwindows") |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
473 { |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
474 linkopt += " -subsystem:windows"; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
475 } |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
476 else if (arg == "-O2" || arg == "-MD") |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
477 { |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
478 // do not pass those to the linker |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
479 clopt += (" " + arg); |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
480 } |
3112
31edb6eea0eb
[MSVC] fix cc-msvc when INCLUDE/LIB variables are empty, improve compatibility with MinGW.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
3087
diff
changeset
|
481 else if (arg == "-O3") |
31edb6eea0eb
[MSVC] fix cc-msvc when INCLUDE/LIB variables are empty, improve compatibility with MinGW.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
3087
diff
changeset
|
482 { |
31edb6eea0eb
[MSVC] fix cc-msvc when INCLUDE/LIB variables are empty, improve compatibility with MinGW.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
3087
diff
changeset
|
483 // MSVC does not support -O3, convert to -O2 instead |
31edb6eea0eb
[MSVC] fix cc-msvc when INCLUDE/LIB variables are empty, improve compatibility with MinGW.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
3087
diff
changeset
|
484 clopt += " -O2"; |
31edb6eea0eb
[MSVC] fix cc-msvc when INCLUDE/LIB variables are empty, improve compatibility with MinGW.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
3087
diff
changeset
|
485 } |
3061
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
486 else if (starts_with(arg, "-I")) |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
487 { |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
488 string path = arg.substr(2); |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
489 clopt += " -I" + quote_path(path); |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
490 } |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
491 else if (arg == "-isystem") |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
492 { |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
493 // Convert -isystem arguments into regular -I flags |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
494 if (i < argc-1) |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
495 { |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
496 arg = argv[++i]; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
497 // sysroot include prefix is not supported!! |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
498 if (arg.length () > 0 && arg[0] == '=') |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
499 { |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
500 cerr << "ERROR: isystem argument starting with '=' is not supported" << endl; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
501 return 1; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
502 } |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
503 clopt += " -I" + quote_path(arg); |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
504 } |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
505 else |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
506 { |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
507 cerr << "ERROR: isystem argument missing" << endl; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
508 return 1; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
509 } |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
510 } |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
511 else if (arg == "-isysroot" |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
512 || arg == "--sysroot") |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
513 { |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
514 // Ignore directory specifications (for the time being) |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
515 if (i < argc-1) |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
516 ++i; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
517 else |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
518 { |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
519 cerr << "ERROR: missing argument for " << arg << endl; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
520 return 1; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
521 } |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
522 } |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
523 else if (starts_with(arg, "-L")) |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
524 { |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
525 string path = arg.substr(2); |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
526 linkopt += " -LIBPATH:" + quote_path(path); |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
527 cllinkopt += " -LIBPATH:" + quote_path(path); |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
528 } |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
529 else if (arg == "-link") |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
530 { |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
531 while (++i < argc) |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
532 { |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
533 arg = argv[i]; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
534 cllinkopt += " " + arg; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
535 linkopt += " " + arg; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
536 } |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
537 } |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
538 else if (starts_with(arg, "-l")) |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
539 { |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
540 string libname = arg.substr(2) + ".lib"; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
541 if (sourcefile.empty()) |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
542 clopt += " " + libname; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
543 else |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
544 cllinkopt += " " + libname; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
545 linkopt += " " + libname; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
546 } |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
547 else if (starts_with(arg, "-Wl,")) |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
548 { |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
549 list<string> flags = split (arg.substr (4), ','); |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
550 Xlinkopt.splice (Xlinkopt.end (), flags); |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
551 } |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
552 else if (arg == "-Xlinker") |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
553 { |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
554 gotXlinker = true; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
555 } |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
556 else if (arg == "-Werror") |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
557 { |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
558 clopt += " -WX"; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
559 } |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
560 else if (arg == "-Wall") |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
561 { |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
562 //clopt += " -Wall"; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
563 } |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
564 else if (arg == "-fno-rtti") |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
565 { |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
566 clopt += " -GR-"; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
567 } |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
568 else if (arg == "-fno-exceptions") |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
569 { |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
570 no_exceptions = true; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
571 } |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
572 else if (arg == "-m386" || arg == "-m486" || arg == "-mpentium" || |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
573 arg == "-mpentiumpro" || arg == "-pedantic" || starts_with(arg, "-W") || |
3112
31edb6eea0eb
[MSVC] fix cc-msvc when INCLUDE/LIB variables are empty, improve compatibility with MinGW.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
3087
diff
changeset
|
574 arg == "-fPIC" || arg == "-nostdlib" || arg == "--export-all-symbols" || |
31edb6eea0eb
[MSVC] fix cc-msvc when INCLUDE/LIB variables are empty, improve compatibility with MinGW.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
3087
diff
changeset
|
575 starts_with(arg, "-march=") || arg == "-fomit-frame-pointer") |
3061
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
576 { |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
577 // ignore |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
578 } |
3076
b39e8dc859f7
[MSVC] enable gmplib compilation
Michael Goffioul <michael.goffioul@gmail.com>
parents:
3061
diff
changeset
|
579 else if (arg == "--output-def") |
b39e8dc859f7
[MSVC] enable gmplib compilation
Michael Goffioul <michael.goffioul@gmail.com>
parents:
3061
diff
changeset
|
580 { |
b39e8dc859f7
[MSVC] enable gmplib compilation
Michael Goffioul <michael.goffioul@gmail.com>
parents:
3061
diff
changeset
|
581 if (i < argc-1) |
b39e8dc859f7
[MSVC] enable gmplib compilation
Michael Goffioul <michael.goffioul@gmail.com>
parents:
3061
diff
changeset
|
582 ++i; |
b39e8dc859f7
[MSVC] enable gmplib compilation
Michael Goffioul <michael.goffioul@gmail.com>
parents:
3061
diff
changeset
|
583 else |
b39e8dc859f7
[MSVC] enable gmplib compilation
Michael Goffioul <michael.goffioul@gmail.com>
parents:
3061
diff
changeset
|
584 { |
b39e8dc859f7
[MSVC] enable gmplib compilation
Michael Goffioul <michael.goffioul@gmail.com>
parents:
3061
diff
changeset
|
585 cerr << "ERROR: argument missing for " << arg << endl; |
b39e8dc859f7
[MSVC] enable gmplib compilation
Michael Goffioul <michael.goffioul@gmail.com>
parents:
3061
diff
changeset
|
586 return 1; |
b39e8dc859f7
[MSVC] enable gmplib compilation
Michael Goffioul <michael.goffioul@gmail.com>
parents:
3061
diff
changeset
|
587 } |
b39e8dc859f7
[MSVC] enable gmplib compilation
Michael Goffioul <michael.goffioul@gmail.com>
parents:
3061
diff
changeset
|
588 } |
3061
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
589 else if (arg == "-noembed") |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
590 { |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
591 mt_embed = false; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
592 } |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
593 else if (arg == "-nodefaultlibs") |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
594 { |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
595 default_libs = false; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
596 } |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
597 else if (arg == "-incremental-link") |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
598 { |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
599 incremental_link = true; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
600 } |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
601 else if (arg == "-o") |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
602 { |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
603 if (i < argc-1) |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
604 { |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
605 arg = argv[++i]; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
606 if (ends_with(arg, ".o") || ends_with(arg, ".obj")) |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
607 { |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
608 clopt += " -Fo" + quote_path(arg); |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
609 objectfile = arg; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
610 } |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
611 else if (ends_with(arg, ".exe") || ends_with(arg, ".dll") || ends_with(arg, ".oct") |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
612 || ends_with(arg, ".mex")) |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
613 { |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
614 clopt += " -Fe" + quote_path(arg); |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
615 linkopt += " -out:" + quote_path(arg); |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
616 exefile = arg; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
617 } |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
618 else |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
619 { |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
620 cerr << "WARNING: unrecognized output file type " << arg << ", assuming executable" << endl; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
621 arg += ".exe"; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
622 clopt += " -Fe" + quote_path(arg); |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
623 linkopt += " -out:" + quote_path(arg); |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
624 exefile = arg; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
625 } |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
626 } |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
627 else |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
628 { |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
629 cerr << "ERROR: output file name missing" << endl; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
630 return 1; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
631 } |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
632 } |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
633 else if (ends_with(arg, ".cc") || ends_with(arg, ".cxx") || ends_with(arg, ".C")) |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
634 { |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
635 clopt += " -Tp" + quote_path(arg); |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
636 sourcefile = arg; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
637 } |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
638 else if (ends_with(arg, ".o") || ends_with(arg, ".obj") || ends_with(arg, ".a") || |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
639 ends_with(arg, ".lib") || ends_with(arg, ".so")) |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
640 { |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
641 if (ends_with(arg, ".a")) |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
642 { |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
643 if (_access(arg.c_str(), 00) != 0) |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
644 { |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
645 string libarg; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
646 int pos1 = arg.rfind('/'); |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
647 |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
648 if (pos1 != string::npos) |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
649 libarg = arg.substr(pos1+1); |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
650 else |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
651 libarg = arg; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
652 if (starts_with(libarg, "lib")) |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
653 libarg = libarg.substr(3); |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
654 libarg = arg.substr(0, pos1+1) + libarg.substr(0, libarg.length()-1) + "lib"; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
655 if (_access(libarg.c_str(), 00) == 0) |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
656 { |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
657 cerr << "WARNING: Converting " << arg << " into " << libarg << endl; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
658 arg = libarg; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
659 } |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
660 } |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
661 } |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
662 |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
663 if (sourcefile.empty()) |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
664 { |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
665 linkopt += " " + quote_path(arg); |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
666 prog = "link"; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
667 } |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
668 else |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
669 { |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
670 cllinkopt += " " + quote_path(arg); |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
671 } |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
672 } |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
673 else if (ends_with(arg, ".c") || ends_with(arg, ".cpp")) |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
674 { |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
675 clopt += " " + quote_path(arg); |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
676 sourcefile = arg; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
677 } |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
678 else if (ends_with(arg, ".dll")) |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
679 { |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
680 // trying to link against a DLL: convert to .lib file, keeping the same basename |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
681 string libarg = (" " + arg.substr(0, arg.length()-4) + ".lib"); |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
682 clopt += libarg; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
683 linkopt += libarg; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
684 } |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
685 else if (ends_with (arg, ".def")) |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
686 { |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
687 cllinkopt += " -DEF:" + arg; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
688 linkopt += " -DEF:" + arg; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
689 } |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
690 else if (arg == "-") |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
691 { |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
692 // read source file from stdin |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
693 read_from_stdin = true; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
694 } |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
695 else |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
696 { |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
697 clopt += " " + quote_quotes(arg); |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
698 linkopt += " " + quote_quotes(arg); |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
699 if (!optarg.empty()) |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
700 { |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
701 clopt += "=" + quote_quotes(optarg); |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
702 linkopt += "=" + quote_quotes(optarg); |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
703 } |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
704 } |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
705 } |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
706 |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
707 for (list<string>::const_iterator it = Xlinkopt.begin(); it != Xlinkopt.end(); ++it) |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
708 { |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
709 string arg = *it; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
710 |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
711 if (arg == "--out-implib" |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
712 || starts_with (arg, "--out-implib=")) |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
713 { |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
714 string implib; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
715 |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
716 if (arg == "--out-implib") |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
717 { |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
718 ++it; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
719 if (it != Xlinkopt.end ()) |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
720 implib = *it; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
721 else |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
722 { |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
723 cerr << "WARNING: missing import library name, ignored" << endl; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
724 continue; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
725 } |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
726 } |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
727 else |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
728 implib = arg.substr (13); |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
729 |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
730 cllinkopt += " -IMPLIB:" + implib; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
731 linkopt += " -IMPLIB:" + implib; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
732 } |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
733 else if (arg == "--enable-auto-import" |
3112
31edb6eea0eb
[MSVC] fix cc-msvc when INCLUDE/LIB variables are empty, improve compatibility with MinGW.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
3087
diff
changeset
|
734 || arg == "--enable-auto-image-base" |
31edb6eea0eb
[MSVC] fix cc-msvc when INCLUDE/LIB variables are empty, improve compatibility with MinGW.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
3087
diff
changeset
|
735 || arg == "--whole-archive" |
31edb6eea0eb
[MSVC] fix cc-msvc when INCLUDE/LIB variables are empty, improve compatibility with MinGW.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
3087
diff
changeset
|
736 || arg == "--no-whole-archive" |
31edb6eea0eb
[MSVC] fix cc-msvc when INCLUDE/LIB variables are empty, improve compatibility with MinGW.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
3087
diff
changeset
|
737 || arg == "-Bsymbolic" |
31edb6eea0eb
[MSVC] fix cc-msvc when INCLUDE/LIB variables are empty, improve compatibility with MinGW.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
3087
diff
changeset
|
738 || arg == "-s") |
3061
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
739 { |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
740 // Ignore these. |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
741 } |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
742 else if (arg == "--output-def") |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
743 { |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
744 ++it; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
745 if (it == Xlinkopt.end ()) |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
746 break; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
747 } |
3112
31edb6eea0eb
[MSVC] fix cc-msvc when INCLUDE/LIB variables are empty, improve compatibility with MinGW.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
3087
diff
changeset
|
748 else if (arg == "--image-base" |
31edb6eea0eb
[MSVC] fix cc-msvc when INCLUDE/LIB variables are empty, improve compatibility with MinGW.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
3087
diff
changeset
|
749 || starts_with(arg, "--image-base=")) |
31edb6eea0eb
[MSVC] fix cc-msvc when INCLUDE/LIB variables are empty, improve compatibility with MinGW.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
3087
diff
changeset
|
750 { |
31edb6eea0eb
[MSVC] fix cc-msvc when INCLUDE/LIB variables are empty, improve compatibility with MinGW.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
3087
diff
changeset
|
751 string base_addr; |
31edb6eea0eb
[MSVC] fix cc-msvc when INCLUDE/LIB variables are empty, improve compatibility with MinGW.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
3087
diff
changeset
|
752 |
31edb6eea0eb
[MSVC] fix cc-msvc when INCLUDE/LIB variables are empty, improve compatibility with MinGW.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
3087
diff
changeset
|
753 if (arg == "--image-base") |
31edb6eea0eb
[MSVC] fix cc-msvc when INCLUDE/LIB variables are empty, improve compatibility with MinGW.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
3087
diff
changeset
|
754 { |
31edb6eea0eb
[MSVC] fix cc-msvc when INCLUDE/LIB variables are empty, improve compatibility with MinGW.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
3087
diff
changeset
|
755 ++it; |
31edb6eea0eb
[MSVC] fix cc-msvc when INCLUDE/LIB variables are empty, improve compatibility with MinGW.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
3087
diff
changeset
|
756 if (it != Xlinkopt.end ()) |
31edb6eea0eb
[MSVC] fix cc-msvc when INCLUDE/LIB variables are empty, improve compatibility with MinGW.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
3087
diff
changeset
|
757 base_addr = *it; |
31edb6eea0eb
[MSVC] fix cc-msvc when INCLUDE/LIB variables are empty, improve compatibility with MinGW.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
3087
diff
changeset
|
758 else |
31edb6eea0eb
[MSVC] fix cc-msvc when INCLUDE/LIB variables are empty, improve compatibility with MinGW.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
3087
diff
changeset
|
759 { |
31edb6eea0eb
[MSVC] fix cc-msvc when INCLUDE/LIB variables are empty, improve compatibility with MinGW.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
3087
diff
changeset
|
760 cerr << "WARNING: missing base address, ignored" << endl; |
31edb6eea0eb
[MSVC] fix cc-msvc when INCLUDE/LIB variables are empty, improve compatibility with MinGW.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
3087
diff
changeset
|
761 continue; |
31edb6eea0eb
[MSVC] fix cc-msvc when INCLUDE/LIB variables are empty, improve compatibility with MinGW.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
3087
diff
changeset
|
762 } |
31edb6eea0eb
[MSVC] fix cc-msvc when INCLUDE/LIB variables are empty, improve compatibility with MinGW.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
3087
diff
changeset
|
763 } |
31edb6eea0eb
[MSVC] fix cc-msvc when INCLUDE/LIB variables are empty, improve compatibility with MinGW.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
3087
diff
changeset
|
764 else |
31edb6eea0eb
[MSVC] fix cc-msvc when INCLUDE/LIB variables are empty, improve compatibility with MinGW.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
3087
diff
changeset
|
765 base_addr = arg.substr (13); |
31edb6eea0eb
[MSVC] fix cc-msvc when INCLUDE/LIB variables are empty, improve compatibility with MinGW.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
3087
diff
changeset
|
766 |
31edb6eea0eb
[MSVC] fix cc-msvc when INCLUDE/LIB variables are empty, improve compatibility with MinGW.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
3087
diff
changeset
|
767 cllinkopt += " -BASE:" + base_addr; |
31edb6eea0eb
[MSVC] fix cc-msvc when INCLUDE/LIB variables are empty, improve compatibility with MinGW.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
3087
diff
changeset
|
768 linkopt += " -BASE:" + base_addr; |
31edb6eea0eb
[MSVC] fix cc-msvc when INCLUDE/LIB variables are empty, improve compatibility with MinGW.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
3087
diff
changeset
|
769 } |
3061
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
770 else |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
771 { |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
772 cllinkopt += " " + arg; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
773 linkopt += " " + arg; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
774 } |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
775 } |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
776 |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
777 if (! incremental_link) |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
778 { |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
779 std::string arg ("-incremental:no"); |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
780 |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
781 cllinkopt += " " + arg; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
782 linkopt += " " + arg; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
783 } |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
784 |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
785 if (no_exceptions) |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
786 { |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
787 replace_option(clopt, "-EHsc"); |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
788 replace_option(clopt, "-EHcs"); |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
789 replace_option(clopt, "-EHs"); |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
790 replace_option(clopt, "-EHc"); |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
791 replace_option(clopt, "-EHa"); |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
792 replace_option(clopt, "-GX-"); |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
793 replace_option(clopt, "-GX"); |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
794 } |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
795 |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
796 if (dodepend && prog != "cl") |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
797 { |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
798 cerr << "ERROR: dependency generation only possible for source file" << endl; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
799 return 1; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
800 } |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
801 |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
802 if (read_from_stdin) |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
803 { |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
804 sourcefile = "cc-msvc-tmp.c"; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
805 if (!read_stdin(sourcefile.c_str())) |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
806 { |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
807 unlink(sourcefile.c_str()); |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
808 return 1; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
809 } |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
810 clopt += (" " + sourcefile); |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
811 } |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
812 |
3087
3663f6300abf
[MSVC] enable FFTW compilation
Michael Goffioul <michael.goffioul@gmail.com>
parents:
3080
diff
changeset
|
813 if (exeoutput && sourcefile.empty()) |
3663f6300abf
[MSVC] enable FFTW compilation
Michael Goffioul <michael.goffioul@gmail.com>
parents:
3080
diff
changeset
|
814 { |
3663f6300abf
[MSVC] enable FFTW compilation
Michael Goffioul <michael.goffioul@gmail.com>
parents:
3080
diff
changeset
|
815 // It's possible all object files and libraries have been |
3663f6300abf
[MSVC] enable FFTW compilation
Michael Goffioul <michael.goffioul@gmail.com>
parents:
3080
diff
changeset
|
816 // pushed into @-files, so "prog" would still be set to "cl". |
3663f6300abf
[MSVC] enable FFTW compilation
Michael Goffioul <michael.goffioul@gmail.com>
parents:
3080
diff
changeset
|
817 // If there's no source file specified on the command line, |
3663f6300abf
[MSVC] enable FFTW compilation
Michael Goffioul <michael.goffioul@gmail.com>
parents:
3080
diff
changeset
|
818 // it's probably safe to assume we're calling the linker. |
3663f6300abf
[MSVC] enable FFTW compilation
Michael Goffioul <michael.goffioul@gmail.com>
parents:
3080
diff
changeset
|
819 |
3663f6300abf
[MSVC] enable FFTW compilation
Michael Goffioul <michael.goffioul@gmail.com>
parents:
3080
diff
changeset
|
820 prog = "link"; |
3663f6300abf
[MSVC] enable FFTW compilation
Michael Goffioul <michael.goffioul@gmail.com>
parents:
3080
diff
changeset
|
821 } |
3663f6300abf
[MSVC] enable FFTW compilation
Michael Goffioul <michael.goffioul@gmail.com>
parents:
3080
diff
changeset
|
822 |
3061
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
823 if (!exeoutput && !sourcefile.empty() && objectfile.empty()) |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
824 { |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
825 // use .o suffix by default |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
826 int pos = sourcefile.rfind('.'); |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
827 if (pos == string::npos) |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
828 objectfile = sourcefile + ".o"; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
829 else |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
830 objectfile = sourcefile.substr(0, pos) + ".o"; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
831 pos = objectfile.rfind('/'); |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
832 if (pos != string::npos) |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
833 objectfile = objectfile.substr(pos+1); |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
834 clopt += " -Fo" + objectfile; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
835 } |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
836 |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
837 if (exeoutput && exefile.empty()) |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
838 { |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
839 if (doshared) |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
840 exefile = "a.dll"; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
841 else |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
842 exefile = "a.exe"; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
843 clopt += " -Fe" + exefile; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
844 linkopt += " -out:" + exefile; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
845 } |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
846 |
3087
3663f6300abf
[MSVC] enable FFTW compilation
Michael Goffioul <michael.goffioul@gmail.com>
parents:
3080
diff
changeset
|
847 if (exeoutput && |
3663f6300abf
[MSVC] enable FFTW compilation
Michael Goffioul <michael.goffioul@gmail.com>
parents:
3080
diff
changeset
|
848 (ends_with(exefile, ".dll") || ends_with(exefile, ".DLL")) |
3663f6300abf
[MSVC] enable FFTW compilation
Michael Goffioul <michael.goffioul@gmail.com>
parents:
3080
diff
changeset
|
849 && ! doshared) |
3663f6300abf
[MSVC] enable FFTW compilation
Michael Goffioul <michael.goffioul@gmail.com>
parents:
3080
diff
changeset
|
850 { |
3663f6300abf
[MSVC] enable FFTW compilation
Michael Goffioul <michael.goffioul@gmail.com>
parents:
3080
diff
changeset
|
851 // Maybe "-shared" was missing on the command line. |
3663f6300abf
[MSVC] enable FFTW compilation
Michael Goffioul <michael.goffioul@gmail.com>
parents:
3080
diff
changeset
|
852 // Compensate for it! |
3663f6300abf
[MSVC] enable FFTW compilation
Michael Goffioul <michael.goffioul@gmail.com>
parents:
3080
diff
changeset
|
853 |
3663f6300abf
[MSVC] enable FFTW compilation
Michael Goffioul <michael.goffioul@gmail.com>
parents:
3080
diff
changeset
|
854 clopt += " -LD"; |
3663f6300abf
[MSVC] enable FFTW compilation
Michael Goffioul <michael.goffioul@gmail.com>
parents:
3080
diff
changeset
|
855 linkopt += " -DLL"; |
3663f6300abf
[MSVC] enable FFTW compilation
Michael Goffioul <michael.goffioul@gmail.com>
parents:
3080
diff
changeset
|
856 } |
3663f6300abf
[MSVC] enable FFTW compilation
Michael Goffioul <michael.goffioul@gmail.com>
parents:
3080
diff
changeset
|
857 |
3061
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
858 if (exeoutput && default_libs) |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
859 { |
3337
8480924d2b85
[MSVC] Use POSIX compliant getopt version from mingw64.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
3289
diff
changeset
|
860 cllinkopt += " posixcompat.lib msvcmath.lib shell32.lib advapi32.lib user32.lib kernel32.lib"; |
8480924d2b85
[MSVC] Use POSIX compliant getopt version from mingw64.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
3289
diff
changeset
|
861 linkopt += " posixcompat.lib msvcmath.lib shell32.lib advapi32.lib user32.lib kernel32.lib"; |
3061
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
862 } |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
863 |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
864 string opts; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
865 if (prog == "cl") |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
866 { |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
867 opts = clopt; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
868 if (!cllinkopt.empty()) |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
869 opts += " -link " + cllinkopt; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
870 } |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
871 else |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
872 opts = linkopt; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
873 |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
874 if (dodepend) |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
875 { |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
876 FILE *fd; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
877 string cmd = prog + " " + opts, line; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
878 list<string> depend_list; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
879 |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
880 if (objectfile.empty()) |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
881 { |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
882 cerr << "ERROR: object file name missing and cannot be determined" << endl; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
883 return 1; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
884 } |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
885 cout << objectfile << ":"; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
886 |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
887 fd = popen(cmd.c_str(), "r"); |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
888 if (fd == NULL) |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
889 { |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
890 cerr << "ERROR: cannot execute " << cmd << endl; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
891 return 1; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
892 } |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
893 while (!feof(fd)) |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
894 { |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
895 line = get_line(fd); |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
896 if (starts_with(line, "#line")) |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
897 { |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
898 int pos1 = line.find('"'), pos2 = line.find('"', pos1+1); |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
899 depend_list.push_back(process_depend(line.substr(pos1+1, pos2-pos1-1))); |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
900 } |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
901 } |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
902 pclose(fd); |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
903 |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
904 depend_list.sort(); |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
905 depend_list.unique(); |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
906 for (list<string>::const_iterator it=depend_list.begin(); it!=depend_list.end(); ++it) |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
907 cout << " \\" << endl << " " << *it; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
908 cout << endl; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
909 return 0; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
910 } |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
911 else |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
912 { |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
913 string cmd = prog + " " + opts; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
914 int cmdresult; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
915 |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
916 if (debug) |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
917 cout << cmd << endl; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
918 if ((cmdresult=do_system(cmd)) == 0 && exeoutput) |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
919 { |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
920 // auto-embed the manifest, if any |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
921 if (exefile.empty()) |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
922 { |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
923 if (!sourcefile.empty()) |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
924 { |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
925 if (doshared) |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
926 exefile = sourcefile + ".dll"; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
927 else |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
928 exefile = sourcefile + ".exe"; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
929 } |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
930 else |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
931 { |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
932 cerr << "ERROR: cannot determine the output executable file" << endl; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
933 return 1; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
934 } |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
935 } |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
936 |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
937 if (_access((exefile + ".manifest").c_str(), 00) == 0) |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
938 { |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
939 // Do not auto-embed for conftest.exe (temporary executable generated |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
940 // by configure scripts): this avoids wrong test results when an AV |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
941 // software is scanning the executable while mt.exe tries to update it |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
942 // (results in "mt.exe:general error c101008d:..." |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
943 // |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
944 // This should be harmless for common situations (can only be a problem |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
945 // if the target application uses conftest.exe as executable name; but |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
946 // I don't know any). |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
947 |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
948 if (mt_embed && exefile != "conftest.exe") |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
949 { |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
950 cmd = "mt -nologo -outputresource:" + exefile |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
951 + (doshared ? ";2" : ";1") + " -manifest " + exefile + ".manifest"; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
952 |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
953 if (debug) |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
954 cout << cmd << endl; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
955 |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
956 cmdresult = do_system(cmd); |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
957 |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
958 if (cmdresult == 0) |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
959 _unlink((exefile + ".manifest").c_str()); |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
960 } |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
961 } |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
962 } |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
963 |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
964 if (read_from_stdin) |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
965 unlink(sourcefile.c_str()); |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
966 |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
967 return cmdresult; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
968 } |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
969 } |