diff options
author | Joseph Hunkeler <jhunkeler@gmail.com> | 2020-02-07 00:56:22 -0500 |
---|---|---|
committer | Joseph Hunkeler <jhunkeler@gmail.com> | 2020-02-07 00:56:22 -0500 |
commit | 68f1b56117d6b777bf6974c4773fd77fb3a82ad0 (patch) | |
tree | 856ac7ab32d1ec92ba40312cbc75b829f97b223b /src | |
parent | 0f48e8fe62cab6b191d523566603350225735218 (diff) | |
download | spmc-68f1b56117d6b777bf6974c4773fd77fb3a82ad0.tar.gz |
Use libraries associated with a program to determine lib directory
Diffstat (limited to 'src')
-rw-r--r-- | src/rpath.c | 26 |
1 files changed, 21 insertions, 5 deletions
diff --git a/src/rpath.c b/src/rpath.c index 5dbe8db..31bc581 100644 --- a/src/rpath.c +++ b/src/rpath.c @@ -210,30 +210,45 @@ char *rpath_autodetect(const char *filename) { chdir(start); char *visit = NULL; // Current directory - char tmp[PATH_MAX]; // Current directory with lib directory appended char relative[PATH_MAX]; // Generated relative path to lib directory char sep[2]; // Holds the platform's directory separator // Initialize character arrays; - tmp[0] = '\0'; relative[0] = '\0'; sprintf(sep, "%c", DIRSEP); while(1) { + StrList *libs = NULL; + // Where are we in the file system? if((visit = getcwd(NULL, PATH_MAX)) == NULL) { exit(errno); } + // Using the current visit path, check if it contains a lib directory - snprintf(tmp, PATH_MAX, "%s%c%s", visit, DIRSEP, "lib"); + char *tmp = join((char *[]) {visit, "lib", NULL}, DIRSEPS); + if (access(tmp, F_OK) == 0) { strcat(relative, "lib"); - has_real_libdir = 1; // gate for memory allocation below + libs = shlib_deps(filename); + for (size_t i = 0; i < strlist_count(libs); i++) { + char *checkpath = join((char *[]) {tmp, strlist_item(libs, i), NULL}, DIRSEPS); + if (exists(checkpath) == 0) { + if (SPM_GLOBAL.verbose) { + printf("found lib: %s\n", checkpath); + } + has_real_libdir = 1; // gate for memory allocation below + } + free(checkpath); + } + strlist_free(libs); + free(tmp); free(visit); break; } - // Reaching the top of the file system indicates our search for a lib directory failed + // Reaching the top of the file system indicates our search for a lib directory failed else if (strcmp(visit, "/") == 0) { + free(tmp); free(visit); break; } @@ -244,6 +259,7 @@ char *rpath_autodetect(const char *filename) { // Step one directory level back chdir(".."); + free(tmp); free(visit); } |