Mercurial > projects > ldc
comparison gen/programs.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 | |
children | a376776e2301 |
comparison
equal
deleted
inserted
replaced
1298:7e303f9f16c7 | 1299:847b767b2d0b |
---|---|
1 #include "gen/programs.h" | |
2 | |
3 #include "llvm/Support/CommandLine.h" | |
4 #include "llvm/System/Program.h" | |
5 | |
6 #include "root.h" // error(char*) | |
7 #include "mars.h" // fatal() | |
8 | |
9 using namespace llvm; | |
10 | |
11 static cl::opt<std::string> gcc("gcc", | |
12 cl::desc("GCC to use for assembling and linking"), | |
13 cl::Hidden, | |
14 cl::ZeroOrMore); | |
15 | |
16 | |
17 sys::Path getGcc() { | |
18 const char *cc = NULL; | |
19 | |
20 if (gcc.getNumOccurrences() > 0 && gcc.length() > 0) | |
21 cc = gcc.c_str(); | |
22 | |
23 if (!cc) | |
24 #if !_WIN32 | |
25 cc = getenv("CC"); | |
26 if (!cc) | |
27 #endif | |
28 cc = "gcc"; | |
29 | |
30 sys::Path path = sys::Program::FindProgramByName(cc); | |
31 if (path.empty() && !cc) { | |
32 if (cc) { | |
33 path.set(cc); | |
34 } else { | |
35 error("failed to locate gcc"); | |
36 fatal(); | |
37 } | |
38 } | |
39 | |
40 return path; | |
41 } |