diff --git a/driver/configfile.cpp b/driver/configfile.cpp index cf6c85c4..51f0bc16 100644 --- a/driver/configfile.cpp +++ b/driver/configfile.cpp @@ -12,6 +12,9 @@ #include "libconfig.h++" #include "llvm/Support/FileSystem.h" #include "llvm/Support/Path.h" +#if LDC_LLVM_VER >= 304 +#include "llvm/Support/PathV1.h" +#endif #include #include #include @@ -19,12 +22,38 @@ #if _WIN32 #define WIN32_LEAN_AND_MEAN #include +#include // Prevent name clash with LLVM #undef GetCurrentDirectory #endif namespace sys = llvm::sys; +#if LDC_LLVM_VER >= 304 +#if _WIN32 +sys::Path GetUserHomeDirectory() { + char buff[MAX_PATH]; + HRESULT res = SHGetFolderPathA(NULL, + CSIDL_FLAG_CREATE | CSIDL_APPDATA, + NULL, + SHGFP_TYPE_CURRENT, + buff); + if (res != S_OK) + assert(0 && "Failed to get user home directory"); + return sys::Path(buff); +} +#else +sys::Path GetUserHomeDirectory() { + const char* home = getenv("HOME"); + Path result; + if (home && result.set(home)) + return result; + result.set("/"); + return result; +} +#endif +#endif + #if _WIN32 static bool ReadPathFromRegistry(sys::Path& p) { @@ -81,7 +110,11 @@ bool ConfigFile::locate(sys::Path& p, const char* argv0, void* mainAddr, const c // user configuration // try ~/.ldc +#if LDC_LLVM_VER >= 304 + p = GetUserHomeDirectory(); +#else p = sys::Path::GetUserHomeDirectory(); +#endif p.appendComponent(".ldc"); p.appendComponent(filename); if (sys::fs::exists(p.str())) @@ -89,7 +122,11 @@ bool ConfigFile::locate(sys::Path& p, const char* argv0, void* mainAddr, const c #if _WIN32 // try home dir +#if LDC_LLVM_VER >= 304 + p = GetUserHomeDirectory(); +#else p = sys::Path::GetUserHomeDirectory(); +#endif p.appendComponent(filename); if (sys::fs::exists(p.str())) return true; diff --git a/driver/linker.cpp b/driver/linker.cpp index 9b56d32c..012a1ba0 100644 --- a/driver/linker.cpp +++ b/driver/linker.cpp @@ -102,7 +102,7 @@ static int linkObjToBinaryGcc(bool sharedLib) Logger::println("*** Linking executable ***"); // find gcc for linking - llvm::sys::Path gcc = getGcc(); + llvm::sys::Path gcc(getGcc()); // build arguments std::vector args; @@ -222,7 +222,7 @@ static int linkObjToBinaryWin(bool sharedLib) Logger::println("*** Linking executable ***"); // find link.exe for linking - llvm::sys::Path tool = getLink(); + llvm::sys::Path tool(getLink()); // build arguments std::vector args; @@ -346,7 +346,7 @@ void createStaticLibrary() const bool isTargetWindows = global.params.targetTriple.getOS() == llvm::Triple::Win32; // find archiver - llvm::sys::Path tool = isTargetWindows ? getLib() : getArchiver(); + llvm::sys::Path tool(isTargetWindows ? getLib() : getArchiver()); // build arguments std::vector args; diff --git a/driver/toobj.cpp b/driver/toobj.cpp index cc1149f1..0e91f688 100644 --- a/driver/toobj.cpp +++ b/driver/toobj.cpp @@ -83,7 +83,8 @@ static void assemble(const llvm::sys::Path& asmpath, const llvm::sys::Path& objp args.push_back("-m32"); // Run the compiler to assembly the program. - int R = executeToolAndWait(getGcc(), args, global.params.verbose); + llvm::sys::Path gcc(getGcc()); + int R = executeToolAndWait(gcc, args, global.params.verbose); if (R) { error("Error while invoking external assembler."); diff --git a/driver/tool.cpp b/driver/tool.cpp index 25e23906..609bfbfe 100644 --- a/driver/tool.cpp +++ b/driver/tool.cpp @@ -36,7 +36,11 @@ int executeToolAndWait(llvm::sys::Path tool, std::vector const & ar // Execute tool. std::string errstr; +#if LDC_LLVM_VER >= 304 + if (int status = llvm::sys::ExecuteAndWait(tool.str(), &realargs[0], NULL, NULL, 0, 0, &errstr)) +#else if (int status = llvm::sys::Program::ExecuteAndWait(tool, &realargs[0], NULL, NULL, 0, 0, &errstr)) +#endif { error("%s failed with status: %d", tool.c_str(), status); if (!errstr.empty()) diff --git a/gen/programs.cpp b/gen/programs.cpp index a4df987d..badb71b8 100644 --- a/gen/programs.cpp +++ b/gen/programs.cpp @@ -35,19 +35,37 @@ static cl::opt mslib("ms-lib", cl::Hidden, cl::ZeroOrMore); -sys::Path getProgram(const char *name, const cl::opt &opt, const char *envVar = 0) +#if LDC_LLVM_VER >= 304 +typedef std::string RetType; +#else +typedef sys::Path RetType; +#endif + +RetType getProgram(const char *name, const cl::opt &opt, const char *envVar = 0) { - sys::Path path; + RetType path; const char *prog = NULL; if (opt.getNumOccurrences() > 0 && opt.length() > 0 && (prog = opt.c_str())) +#if LDC_LLVM_VER >= 304 + path = sys::FindProgramByName(prog); +#else path = sys::Program::FindProgramByName(prog); +#endif if (path.empty() && envVar && (prog = getenv(envVar))) +#if LDC_LLVM_VER >= 304 + path = sys::FindProgramByName(prog); +#else path = sys::Program::FindProgramByName(prog); +#endif if (path.empty()) +#if LDC_LLVM_VER >= 304 + path = sys::FindProgramByName(name); +#else path = sys::Program::FindProgramByName(name); +#endif if (path.empty()) { error("failed to locate %s", name); @@ -57,22 +75,22 @@ sys::Path getProgram(const char *name, const cl::opt &opt, const ch return path; } -sys::Path getGcc() +RetType getGcc() { return getProgram("gcc", gcc, "CC"); } -sys::Path getArchiver() +RetType getArchiver() { return getProgram("ar", ar); } -sys::Path getLink() +RetType getLink() { return getProgram("link.exe", mslink); } -sys::Path getLib() +RetType getLib() { return getProgram("lib.exe", mslib); } diff --git a/gen/programs.h b/gen/programs.h index fda3f9de..a62d8b6f 100644 --- a/gen/programs.h +++ b/gen/programs.h @@ -14,6 +14,19 @@ #ifndef LDC_GEN_PROGRAMS_H #define LDC_GEN_PROGRAMS_H +#if LDC_LLVM_VER >= 304 + +#include + +std::string getGcc(); +std::string getArchiver(); + +// For Windows with MS tool chain +std::string getLink(); +std::string getLib(); + +#else + #include "llvm/Support/Path.h" llvm::sys::Path getGcc(); @@ -24,3 +37,5 @@ llvm::sys::Path getLink(); llvm::sys::Path getLib(); #endif + +#endif diff --git a/gen/todebug.cpp b/gen/todebug.cpp index 9e99bc53..de10353b 100644 --- a/gen/todebug.cpp +++ b/gen/todebug.cpp @@ -27,6 +27,9 @@ #include "llvm/Support/Dwarf.h" #include "llvm/Support/FileSystem.h" #include "llvm/Support/Path.h" +#if LDC_LLVM_VER >= 304 +#include "llvm/Support/PathV1.h" +#endif using namespace llvm::dwarf;