Skip to content

Commit 980920a

Browse files
author
Sebastian Pop
committed
use DEFAULT_SYSROOT
llvm-svn: 154792
1 parent 5c9e184 commit 980920a

File tree

7 files changed

+32
-15
lines changed

7 files changed

+32
-15
lines changed

clang/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ set(CLANG_RESOURCE_DIR "" CACHE STRING
6666
set(C_INCLUDE_DIRS "" CACHE STRING
6767
"Colon separated list of directories clang will search for headers.")
6868

69+
set(GCC_INSTALL_PREFIX "" CACHE PATH "Directory where gcc is installed." )
70+
set(DEFAULT_SYSROOT "" CACHE PATH
71+
"Default <path> to all compiler invocations for --sysroot=<path>." )
72+
6973
set(CLANG_VENDOR "" CACHE STRING
7074
"Vendor-specific text for showing with version information.")
7175

clang/include/clang/Config/config.h.cmake

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,11 @@
44
/* Relative directory for resource files */
55
#define CLANG_RESOURCE_DIR "${CLANG_RESOURCE_DIR}"
66

7-
/* Directory where gcc is installed. */
8-
#define GCC_INSTALL_PREFIX "${GCC_INSTALL_PREFIX}"
9-
107
/* Directories clang will search for headers */
118
#define C_INCLUDE_DIRS "${C_INCLUDE_DIRS}"
9+
10+
/* Default <path> to all compiler invocations for --sysroot=<path>. */
11+
#define DEFAULT_SYSROOT "${DEFAULT_SYSROOT}"
12+
13+
/* Directory where gcc is installed. */
14+
#define GCC_INSTALL_PREFIX "${GCC_INSTALL_PREFIX}"

clang/include/clang/Config/config.h.in

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,16 @@
99
/* Relative directory for resource files */
1010
#undef CLANG_RESOURCE_DIR
1111

12-
/* Directory where gcc is installed. */
13-
#undef GCC_INSTALL_PREFIX
14-
1512
/* Directories clang will search for headers */
1613
#undef C_INCLUDE_DIRS
1714

1815
/* Linker version detected at compile time. */
1916
#undef HOST_LINK_VERSION
2017

18+
/* Default <path> to all compiler invocations for --sysroot=<path>. */
19+
#undef DEFAULT_SYSROOT
20+
21+
/* Directory where gcc is installed. */
22+
#undef GCC_INSTALL_PREFIX
23+
2124
#endif

clang/include/clang/Driver/Compilation.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@ class Compilation {
9292
return FailureResultFiles;
9393
}
9494

95+
/// Returns the sysroot path.
96+
StringRef getSysRoot() const;
97+
9598
/// getArgsForToolChain - Return the derived argument list for the
9699
/// tool chain \arg TC (or the default tool chain, if TC is not
97100
/// specified).

clang/lib/Driver/Compilation.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,3 +230,7 @@ void Compilation::initCompilationForDiagnostics(void) {
230230
Redirects[1] = new const llvm::sys::Path();
231231
Redirects[2] = new const llvm::sys::Path();
232232
}
233+
234+
StringRef Compilation::getSysRoot(void) const {
235+
return getDriver().SysRoot;
236+
}

clang/lib/Driver/Driver.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ Driver::Driver(StringRef ClangExecutable,
4949
bool IsProduction,
5050
DiagnosticsEngine &Diags)
5151
: Opts(createDriverOptTable()), Diags(Diags),
52-
ClangExecutable(ClangExecutable), UseStdLib(true),
53-
DefaultTargetTriple(DefaultTargetTriple),
52+
ClangExecutable(ClangExecutable), SysRoot(DEFAULT_SYSROOT),
53+
UseStdLib(true), DefaultTargetTriple(DefaultTargetTriple),
5454
DefaultImageName(DefaultImageName),
5555
DriverTitle("clang \"gcc-compatible\" driver"),
5656
CCPrintOptionsFilename(0), CCPrintHeadersFilename(0),
@@ -660,9 +660,7 @@ bool Driver::HandleImmediateArgs(const Compilation &C) {
660660
llvm::outs() << "\n";
661661
llvm::outs() << "libraries: =" << ResourceDir;
662662

663-
std::string sysroot;
664-
if (Arg *A = C.getArgs().getLastArg(options::OPT__sysroot_EQ))
665-
sysroot = A->getValue(C.getArgs());
663+
StringRef sysroot = C.getSysRoot();
666664

667665
for (ToolChain::path_list::const_iterator it = TC.getFilePaths().begin(),
668666
ie = TC.getFilePaths().end(); it != ie; ++it) {

clang/lib/Driver/Tools.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -377,10 +377,11 @@ void Clang::AddPreprocessingOptions(Compilation &C,
377377

378378
// If we have a --sysroot, and don't have an explicit -isysroot flag, add an
379379
// -isysroot to the CC1 invocation.
380-
if (Arg *A = Args.getLastArg(options::OPT__sysroot_EQ)) {
380+
StringRef sysroot = C.getSysRoot();
381+
if (sysroot != "") {
381382
if (!Args.hasArg(options::OPT_isysroot)) {
382383
CmdArgs.push_back("-isysroot");
383-
CmdArgs.push_back(A->getValue(Args));
384+
CmdArgs.push_back(C.getArgs().MakeArgString(sysroot));
384385
}
385386
}
386387

@@ -4016,9 +4017,10 @@ void darwin::Link::AddLinkArgs(Compilation &C,
40164017

40174018
// Give --sysroot= preference, over the Apple specific behavior to also use
40184019
// --isysroot as the syslibroot.
4019-
if (const Arg *A = Args.getLastArg(options::OPT__sysroot_EQ)) {
4020+
StringRef sysroot = C.getSysRoot();
4021+
if (sysroot != "") {
40204022
CmdArgs.push_back("-syslibroot");
4021-
CmdArgs.push_back(A->getValue(Args));
4023+
CmdArgs.push_back(C.getArgs().MakeArgString(sysroot));
40224024
} else if (const Arg *A = Args.getLastArg(options::OPT_isysroot)) {
40234025
CmdArgs.push_back("-syslibroot");
40244026
CmdArgs.push_back(A->getValue(Args));

0 commit comments

Comments
 (0)