mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-08-17 21:29:20 +00:00
For PR351: \
* Remove IsLibrary and GetLibraryPath, replaced by FindLibrary in ../Path.cpp \ * Implement GetSystemLibraryPaths and GetBytecodeLibraryPaths, instead of the \ GetSystemLibraryPath1 and GetSystemLibraryPath2 methods git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@18862 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
ccb23a13e9
commit
1b6b99bffc
@ -46,67 +46,61 @@ Path::GetRootDirectory() {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline bool IsLibrary(Path& path, const std::string& basename) {
|
static void getPathList(const char*path, std::vector<sys::Path>& Paths) {
|
||||||
if (path.appendFile(std::string("lib") + basename)) {
|
const char* at = path;
|
||||||
if (path.appendSuffix(Path::GetDLLSuffix()) && path.readable())
|
const char* delim = strchr(at, ':');
|
||||||
return true;
|
Path tmpPath;
|
||||||
else if (path.elideSuffix() && path.appendSuffix("a") && path.readable())
|
while( delim != 0 ) {
|
||||||
return true;
|
std::string tmp(at, size_t(delim-at));
|
||||||
else if (path.elideSuffix() && path.appendSuffix("o") && path.readable())
|
if (tmpPath.setDirectory(tmp))
|
||||||
return true;
|
if (tmpPath.readable())
|
||||||
else if (path.elideSuffix() && path.appendSuffix("bc") && path.readable())
|
Paths.push_back(tmpPath);
|
||||||
return true;
|
at = delim + 1;
|
||||||
} else if (path.elideFile() && path.appendFile(basename)) {
|
delim = strchr(at, ':');
|
||||||
if (path.appendSuffix(Path::GetDLLSuffix()) && path.readable())
|
|
||||||
return true;
|
|
||||||
else if (path.elideSuffix() && path.appendSuffix("a") && path.readable())
|
|
||||||
return true;
|
|
||||||
else if (path.elideSuffix() && path.appendSuffix("o") && path.readable())
|
|
||||||
return true;
|
|
||||||
else if (path.elideSuffix() && path.appendSuffix("bc") && path.readable())
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
path.clear();
|
if (*at != 0)
|
||||||
return false;
|
if (tmpPath.setDirectory(std::string(at)))
|
||||||
|
if (tmpPath.readable())
|
||||||
|
Paths.push_back(tmpPath);
|
||||||
|
|
||||||
|
}
|
||||||
|
void
|
||||||
|
Path::GetSystemLibraryPaths(std::vector<sys::Path>& Paths) {
|
||||||
|
#ifdef LTDL_SHLIBPATH_VAR
|
||||||
|
char* env_var = getenv(LTDL_SHLIBPATH_VAR);
|
||||||
|
if (env_var != 0) {
|
||||||
|
getPathList(env_var,Paths);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
// FIXME: Should this look at LD_LIBRARY_PATH too?
|
||||||
|
Paths.push_back(sys::Path("/usr/local/lib/"));
|
||||||
|
Paths.push_back(sys::Path("/usr/X11R6/lib/"));
|
||||||
|
Paths.push_back(sys::Path("/usr/lib/"));
|
||||||
|
Paths.push_back(sys::Path("/lib/"));
|
||||||
}
|
}
|
||||||
|
|
||||||
Path
|
void
|
||||||
Path::GetLibraryPath(const std::string& basename,
|
Path::GetBytecodeLibraryPaths(std::vector<sys::Path>& Paths) {
|
||||||
const std::vector<std::string>& LibPaths) {
|
char * env_var = getenv("LLVM_LIB_SEARCH_PATH");
|
||||||
Path result;
|
if (env_var != 0) {
|
||||||
|
getPathList(env_var,Paths);
|
||||||
// Try the paths provided
|
|
||||||
for (std::vector<std::string>::const_iterator I = LibPaths.begin(),
|
|
||||||
E = LibPaths.end(); I != E; ++I ) {
|
|
||||||
if (result.setDirectory(*I) && IsLibrary(result,basename))
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
#ifdef LLVMGCCDIR
|
||||||
// Try the LLVM lib directory in the LLVM install area
|
{
|
||||||
if (result.setDirectory(LLVM_LIBDIR) && IsLibrary(result,basename))
|
Path tmpPath(std::string(LLVMGCCDIR) + "bytecode-libs/");
|
||||||
return result;
|
if (tmpPath.readable())
|
||||||
|
Paths.push_back(tmpPath);
|
||||||
// Try /usr/lib
|
|
||||||
if (result.setDirectory("/usr/lib/") && IsLibrary(result,basename))
|
|
||||||
return result;
|
|
||||||
|
|
||||||
// Try /lib
|
|
||||||
if (result.setDirectory("/lib/") && IsLibrary(result,basename))
|
|
||||||
return result;
|
|
||||||
|
|
||||||
// Can't find it, give up and return invalid path.
|
|
||||||
result.clear();
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
Path
|
#ifdef LLVM_LIBDIR
|
||||||
Path::GetSystemLibraryPath1() {
|
{
|
||||||
return Path("/lib/");
|
Path tmpPath;
|
||||||
|
if (tmpPath.setDirectory(LLVM_LIBDIR))
|
||||||
|
if (tmpPath.readable())
|
||||||
|
Paths.push_back(tmpPath);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
Path
|
GetSystemLibraryPaths(Paths);
|
||||||
Path::GetSystemLibraryPath2() {
|
|
||||||
return Path("/usr/lib/");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Path
|
Path
|
||||||
@ -162,9 +156,10 @@ bool Path::hasMagicNumber(const std::string &Magic) const {
|
|||||||
int fd = ::open(path.c_str(),O_RDONLY);
|
int fd = ::open(path.c_str(),O_RDONLY);
|
||||||
if (fd < 0)
|
if (fd < 0)
|
||||||
return false;
|
return false;
|
||||||
if (0 != ::read(fd, buf, len))
|
size_t read_len = ::read(fd, buf, len);
|
||||||
return false;
|
|
||||||
close(fd);
|
close(fd);
|
||||||
|
if (len != read_len)
|
||||||
|
return false;
|
||||||
buf[len] = '\0';
|
buf[len] = '\0';
|
||||||
return Magic == buf;
|
return Magic == buf;
|
||||||
}
|
}
|
||||||
@ -203,14 +198,6 @@ Path::isBytecodeFile() const {
|
|||||||
(buffer[3] == 'c' || buffer[3] == 'm'));
|
(buffer[3] == 'c' || buffer[3] == 'm'));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
|
||||||
Path::isArchive() const {
|
|
||||||
if (readable()) {
|
|
||||||
return hasMagicNumber("!<arch>\012");
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
Path::exists() const {
|
Path::exists() const {
|
||||||
return 0 == access(path.c_str(), F_OK );
|
return 0 == access(path.c_str(), F_OK );
|
||||||
|
@ -46,67 +46,61 @@ Path::GetRootDirectory() {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline bool IsLibrary(Path& path, const std::string& basename) {
|
static void getPathList(const char*path, std::vector<sys::Path>& Paths) {
|
||||||
if (path.appendFile(std::string("lib") + basename)) {
|
const char* at = path;
|
||||||
if (path.appendSuffix(Path::GetDLLSuffix()) && path.readable())
|
const char* delim = strchr(at, ':');
|
||||||
return true;
|
Path tmpPath;
|
||||||
else if (path.elideSuffix() && path.appendSuffix("a") && path.readable())
|
while( delim != 0 ) {
|
||||||
return true;
|
std::string tmp(at, size_t(delim-at));
|
||||||
else if (path.elideSuffix() && path.appendSuffix("o") && path.readable())
|
if (tmpPath.setDirectory(tmp))
|
||||||
return true;
|
if (tmpPath.readable())
|
||||||
else if (path.elideSuffix() && path.appendSuffix("bc") && path.readable())
|
Paths.push_back(tmpPath);
|
||||||
return true;
|
at = delim + 1;
|
||||||
} else if (path.elideFile() && path.appendFile(basename)) {
|
delim = strchr(at, ':');
|
||||||
if (path.appendSuffix(Path::GetDLLSuffix()) && path.readable())
|
|
||||||
return true;
|
|
||||||
else if (path.elideSuffix() && path.appendSuffix("a") && path.readable())
|
|
||||||
return true;
|
|
||||||
else if (path.elideSuffix() && path.appendSuffix("o") && path.readable())
|
|
||||||
return true;
|
|
||||||
else if (path.elideSuffix() && path.appendSuffix("bc") && path.readable())
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
path.clear();
|
if (*at != 0)
|
||||||
return false;
|
if (tmpPath.setDirectory(std::string(at)))
|
||||||
|
if (tmpPath.readable())
|
||||||
|
Paths.push_back(tmpPath);
|
||||||
|
|
||||||
|
}
|
||||||
|
void
|
||||||
|
Path::GetSystemLibraryPaths(std::vector<sys::Path>& Paths) {
|
||||||
|
#ifdef LTDL_SHLIBPATH_VAR
|
||||||
|
char* env_var = getenv(LTDL_SHLIBPATH_VAR);
|
||||||
|
if (env_var != 0) {
|
||||||
|
getPathList(env_var,Paths);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
// FIXME: Should this look at LD_LIBRARY_PATH too?
|
||||||
|
Paths.push_back(sys::Path("/usr/local/lib/"));
|
||||||
|
Paths.push_back(sys::Path("/usr/X11R6/lib/"));
|
||||||
|
Paths.push_back(sys::Path("/usr/lib/"));
|
||||||
|
Paths.push_back(sys::Path("/lib/"));
|
||||||
}
|
}
|
||||||
|
|
||||||
Path
|
void
|
||||||
Path::GetLibraryPath(const std::string& basename,
|
Path::GetBytecodeLibraryPaths(std::vector<sys::Path>& Paths) {
|
||||||
const std::vector<std::string>& LibPaths) {
|
char * env_var = getenv("LLVM_LIB_SEARCH_PATH");
|
||||||
Path result;
|
if (env_var != 0) {
|
||||||
|
getPathList(env_var,Paths);
|
||||||
// Try the paths provided
|
|
||||||
for (std::vector<std::string>::const_iterator I = LibPaths.begin(),
|
|
||||||
E = LibPaths.end(); I != E; ++I ) {
|
|
||||||
if (result.setDirectory(*I) && IsLibrary(result,basename))
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
#ifdef LLVMGCCDIR
|
||||||
// Try the LLVM lib directory in the LLVM install area
|
{
|
||||||
if (result.setDirectory(LLVM_LIBDIR) && IsLibrary(result,basename))
|
Path tmpPath(std::string(LLVMGCCDIR) + "bytecode-libs/");
|
||||||
return result;
|
if (tmpPath.readable())
|
||||||
|
Paths.push_back(tmpPath);
|
||||||
// Try /usr/lib
|
|
||||||
if (result.setDirectory("/usr/lib/") && IsLibrary(result,basename))
|
|
||||||
return result;
|
|
||||||
|
|
||||||
// Try /lib
|
|
||||||
if (result.setDirectory("/lib/") && IsLibrary(result,basename))
|
|
||||||
return result;
|
|
||||||
|
|
||||||
// Can't find it, give up and return invalid path.
|
|
||||||
result.clear();
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
Path
|
#ifdef LLVM_LIBDIR
|
||||||
Path::GetSystemLibraryPath1() {
|
{
|
||||||
return Path("/lib/");
|
Path tmpPath;
|
||||||
|
if (tmpPath.setDirectory(LLVM_LIBDIR))
|
||||||
|
if (tmpPath.readable())
|
||||||
|
Paths.push_back(tmpPath);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
Path
|
GetSystemLibraryPaths(Paths);
|
||||||
Path::GetSystemLibraryPath2() {
|
|
||||||
return Path("/usr/lib/");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Path
|
Path
|
||||||
@ -162,9 +156,10 @@ bool Path::hasMagicNumber(const std::string &Magic) const {
|
|||||||
int fd = ::open(path.c_str(),O_RDONLY);
|
int fd = ::open(path.c_str(),O_RDONLY);
|
||||||
if (fd < 0)
|
if (fd < 0)
|
||||||
return false;
|
return false;
|
||||||
if (0 != ::read(fd, buf, len))
|
size_t read_len = ::read(fd, buf, len);
|
||||||
return false;
|
|
||||||
close(fd);
|
close(fd);
|
||||||
|
if (len != read_len)
|
||||||
|
return false;
|
||||||
buf[len] = '\0';
|
buf[len] = '\0';
|
||||||
return Magic == buf;
|
return Magic == buf;
|
||||||
}
|
}
|
||||||
@ -203,14 +198,6 @@ Path::isBytecodeFile() const {
|
|||||||
(buffer[3] == 'c' || buffer[3] == 'm'));
|
(buffer[3] == 'c' || buffer[3] == 'm'));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
|
||||||
Path::isArchive() const {
|
|
||||||
if (readable()) {
|
|
||||||
return hasMagicNumber("!<arch>\012");
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
Path::exists() const {
|
Path::exists() const {
|
||||||
return 0 == access(path.c_str(), F_OK );
|
return 0 == access(path.c_str(), F_OK );
|
||||||
|
Loading…
Reference in New Issue
Block a user