diff options
| author | dacctal <dacctal@symlinx.net> | 2026-05-24 10:23:38 +0000 |
|---|---|---|
| committer | dacctal <dacctal@symlinx.net> | 2026-05-24 10:23:38 +0000 |
| commit | aa0d78815004ae6b0c4a42b0e024f5c4ef555ae2 (patch) | |
| tree | 62f97b4c5acfdb98003568466f878fbd3d6b9dfb /src/link_install.c | |
| parent | 83d471f2c1d1b1fa6be51f41e4f1c36ab19d7094 (diff) | |
c rewrite
Diffstat (limited to 'src/link_install.c')
| -rw-r--r-- | src/link_install.c | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/src/link_install.c b/src/link_install.c new file mode 100644 index 0000000..9f658d4 --- /dev/null +++ b/src/link_install.c @@ -0,0 +1,76 @@ +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> +#include <sys/stat.h> +#include <dirent.h> + +#include "link_install.h" +#include "vars.h" + +static int is_executable(const char *path) { + return (access(path, X_OK) == 0); +} + +static int is_dir(const char *path) { + struct stat st; + if (stat(path, &st) == 0) { + return S_ISDIR(st.st_mode); + } + return 0; +} + +static const char* get_extension(const char *path) { + const char *dot = strrchr(path, '.'); + return dot ? dot : ""; +} + +void link_install(const char *build_dir) { + DIR *dir = opendir(build_dir); + if (!dir) return; + + struct dirent *entry; + while ((entry = readdir(dir)) != NULL) { + if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0) { + continue; + } + + char src_path[MAX_PATH_LEN]; + char link_path[MAX_PATH_LEN]; + snprintf(src_path, sizeof(src_path), "%s/%s", build_dir, entry->d_name); + + const char *ext = get_extension(entry->d_name); + + if (strncmp(ext, ".so", 3) == 0) { + snprintf(link_path, sizeof(link_path), "%s/%s", lib, entry->d_name); + if (!file_exists(link_path)) { + symlink(src_path, link_path); + if (is_verbose) { + printf("%slinked library: %s\n", print_pkgit, src_path); + } + } + } else if (is_executable(src_path) && !is_dir(src_path)) { + if (strcmp(entry->d_name, "bldit") != 0 && + strcmp(entry->d_name, "build.sh") != 0 && + strcmp(entry->d_name, "compile.sh") != 0) { + snprintf(link_path, sizeof(link_path), "%s/%s", bin, entry->d_name); + if (!file_exists(link_path)) { + symlink(src_path, link_path); + if (is_verbose) { + printf("%slinked executable: %s\n", print_pkgit, src_path); + } + } + } + } else if (strcmp(ext, ".h") == 0) { + snprintf(link_path, sizeof(link_path), "%s/%s", inc, entry->d_name); + if (!file_exists(link_path)) { + symlink(src_path, link_path); + if (is_verbose) { + printf("%slinked include: %s\n", print_pkgit, src_path); + } + } + } + } + + closedir(dir); +}
\ No newline at end of file |
