forked from ssi-schaefer/parity
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparity.gnu.gcc.cpp
219 lines (185 loc) · 7.05 KB
/
parity.gnu.gcc.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
/****************************************************************\
* *
* Copyright (C) 2007 by Markus Duft <markus.duft@salomon.at> *
* *
* This file is part of parity. *
* *
* parity is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as *
* published by the Free Software Foundation, either version 3 of *
* the License, or (at your option) any later version. *
* *
* parity is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General *
* Public License along with parity. If not, *
* see <http://www.gnu.org/licenses/>. *
* *
\****************************************************************/
#include <Log.h>
#include <Context.h>
#include <Timing.h>
#include <TableGnuGcc.h>
#include <Compiler.h>
#include <CollectorStubs.h>
#include <CollectorOther.h>
#include <Version.h>
#ifdef _WIN32
# include <io.h>
# include <fcntl.h>
#endif
//
// when building with parity itself, we need to be carfull, since
// all MS header files are included with _POSIX_ defined, and thus
// some things are different (fex. we need to use "old" POSIX names).
//
#ifdef __PARITY__
# define _fileno fileno
#endif
using namespace parity::utils;
using namespace parity;
//
// The following is needed for Confix to get the Executable
// name right:
// CONFIX:EXENAME('parity.gnu.gcc')
//
int main(int argc, char** argv)
{
#ifdef _WIN32
//
// set stream modes to binary to suppress the annoying \r
//
_setmode(_fileno(stdout), _O_BINARY);
_setmode(_fileno(stderr), _O_BINARY);
#endif
parity::tasks::runConfigurationLoading(argc, argv);
//
// Get out context which is needed for nearly every operation.
//
Context& context = Context::getContext();
//
// After config loading: need color mode
//
Color color(context.getColorMode());
//
// Initialize the Argument parser with the correct frontend
//
Timing::instance().start("Command Line Processing");
//
// we're gcc here, so set frontend appropriatly, overruling configuration
//
context.setFrontendType(utils::ToolchainInterixGNU);
try {
char * argv0 = strrchr(argv[0], '/'); // find last path sep
if (argv0 == NULL) {
argv0 = strrchr(argv[0], '\\'); // find last path sep
}
if (argv0 == NULL) {
argv0 = argv[0]; // no path component
} else {
++argv0; // skip last path sep
}
if (strstr(argv0, "g++") != NULL) {
context.setDefaultLanguage(utils::LanguageCpp);
} else {
context.setDefaultLanguage(utils::LanguageC);
}
/* backup configuration-set paths. */
parity::utils::PathVector cfgIncludePaths = parity::utils::Context::getContext().getIncludePaths();
parity::utils::PathVector cfgLibraryPaths = parity::utils::Context::getContext().getLibraryPaths();
/* clear configuration-set paths. */
parity::utils::Context::getContext().getIncludePaths().clear();
parity::utils::Context::getContext().getLibraryPaths().clear();
/* Avoid interference with the command line set library paths. If configuration set
* library paths are still set, the order will be wrong (command line set paths
* should take precedence. For this reason (as system library paths are already set),
* configuration set library paths are prepended to the system library paths. this
* way we end up with the desired result.
* The old method was to append the paths to library paths again after command line
* parsing, which broke, because during command line parsing, library search is already
* done, which may not work if the configuration set paths are absent. */
parity::utils::Context::getContext().getSysIncludePaths().insert(
parity::utils::Context::getContext().getSysIncludePaths().begin(),
cfgIncludePaths.begin(), cfgIncludePaths.end());
parity::utils::Context::getContext().getSysLibraryPaths().insert(
parity::utils::Context::getContext().getSysLibraryPaths().begin(),
cfgLibraryPaths.begin(), cfgLibraryPaths.end());
parity::options::UnknownArgumentVector unknown;
parity::options::CommandLine::process(argc - 1, &argv[1], parity::options::OptionTableGnuGcc, &unknown);
for(parity::options::UnknownArgumentVector::iterator it = unknown.begin(); it != unknown.end(); ++it) {
parity::utils::Path pth(*it);
pth.toNative();
if(pth.exists()) {
if(context.getPreprocess() || context.getCompileOnly()) {
// assume source file for all unknown things...
Log::verbose("assuming source: %s\n", pth.get().c_str());
context.setSourcesString(pth.get());
} else {
Log::verbose("assuming object: %s\n", pth.get().c_str());
context.setObjectsLibrariesString(pth.get());
}
} else {
Log::verbose("ignoring unknown argument: %s\n", it->c_str());
}
}
} catch(const Exception& e) {
Log::error("while processing command line: %s\n", e.what());
exit(1);
}
//
// setup default defines.
//
context.setDefinesString("__PARITY_GNU__");
context.setDefinesString("__PARITY__");
//
// GNU C++ does set the __cplusplus macro value matching the
// selected C++ standard in use. It is a bug in the MSVC C++
// compiler to leave it on 199711L, but they decided to add
// another /Zc: compiler option for backwards compatibility.
//
context.setCplusPlusMacro(true);
Timing::instance().stop("Command Line Processing");
//
// Check if there is something to do.
//
if (context.getSources().empty()) {
if(context.getCompileOnly()) {
Log::error("no source files to compile!\n");
exit(1);
}
if (context.getPreprocess()) {
// Without an explicit input file, the preprocessor reads from stdin.
bool used = false;
if (!parity::options::addSourceFromStdin("-", "", used)) {
utils::Log::error("Failed to load preprocessor input from stdin!\n");
exit(1);
}
}
}
//
// Initialization complete, startup can proceed.
//
Log::verbose("%s\n", color.yellow(PACKAGE_STRING).c_str());
Log::verbose("entering compiler stage...\n");
tasks::runCompilerStage();
//
// If we get here, we've successfully compiled (if we compiled)
// and are sure that we're not in compile only mode, etc. So we
// can go ahead with linking.
//
if(context.getObjectsLibraries().empty())
{
//
// This should barely ever happen, since ObjectsLibraries contains the
// default libraries set by the parity configuration.
//
Log::error("no input files for linking stage, did the compiler fail?");
exit(1);
}
Log::verbose("entering linker stage...\n");
tasks::runLinkerStage();
return 0;
}