Mercurial > projects > ldc
comparison gen/linker.cpp @ 1299:847b767b2d0b
Factor out the code to find gcc, and add a command-line option to override the
default executable name.
This should help cross-compilation by allowing a cross-gcc to be specified from
the configuration file instead of only through the CC environment variable.
author | Frits van Bommel <fvbommel wxs.nl> |
---|---|
date | Mon, 04 May 2009 13:32:16 +0200 |
parents | 461a85f0db31 |
children | 2bebd938548f |
comparison
equal
deleted
inserted
replaced
1298:7e303f9f16c7 | 1299:847b767b2d0b |
---|---|
12 | 12 |
13 #define NO_COUT_LOGGER | 13 #define NO_COUT_LOGGER |
14 #include "gen/logger.h" | 14 #include "gen/logger.h" |
15 #include "gen/cl_options.h" | 15 #include "gen/cl_options.h" |
16 #include "gen/optimizer.h" | 16 #include "gen/optimizer.h" |
17 #include "gen/programs.h" | |
17 | 18 |
18 ////////////////////////////////////////////////////////////////////////////// | 19 ////////////////////////////////////////////////////////////////////////////// |
19 | 20 |
20 // Is this useful? | 21 // Is this useful? |
21 llvm::cl::opt<bool> quiet("quiet", | 22 llvm::cl::opt<bool> quiet("quiet", |
214 Logger::println("*** Linking executable ***"); | 215 Logger::println("*** Linking executable ***"); |
215 | 216 |
216 // error string | 217 // error string |
217 std::string errstr; | 218 std::string errstr; |
218 | 219 |
219 const char *cc; | |
220 #if !_WIN32 | |
221 cc = getenv("CC"); | |
222 if (!cc) | |
223 #endif | |
224 cc = "gcc"; | |
225 | |
226 // find gcc for linking | 220 // find gcc for linking |
227 llvm::sys::Path gcc = llvm::sys::Program::FindProgramByName(cc); | 221 llvm::sys::Path gcc = getGcc(); |
228 if (gcc.isEmpty()) | 222 // get a string version for argv[0] |
229 { | 223 std::string gccStr = gcc.toString(); |
230 gcc.set(cc); | |
231 } | |
232 | 224 |
233 // build arguments | 225 // build arguments |
234 std::vector<const char*> args; | 226 std::vector<const char*> args; |
235 | 227 |
236 // first the program name ?? | 228 // first the program name ?? |
237 args.push_back(cc); | 229 args.push_back(gccStr.c_str()); |
238 | 230 |
239 // object files | 231 // object files |
240 for (int i = 0; i < global.params.objfiles->dim; i++) | 232 for (int i = 0; i < global.params.objfiles->dim; i++) |
241 { | 233 { |
242 char *p = (char *)global.params.objfiles->data[i]; | 234 char *p = (char *)global.params.objfiles->data[i]; |