]> git.ipfire.org Git - pakfire.git/commitdiff
build: Require ELF interpreters
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 3 Jan 2025 08:52:39 +0000 (08:52 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 3 Jan 2025 08:52:39 +0000 (08:52 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/pakfire/build.c

index 5e5563da5cc7f69ea3530c1a65d38c513d76ea6a..57ba341ab02122df6876b1b1db997adb89b3edfa 100644 (file)
@@ -34,6 +34,7 @@
 #include <pakfire/ctx.h>
 #include <pakfire/deps.h>
 #include <pakfire/dist.h>
+#include <pakfire/elf.h>
 #include <pakfire/env.h>
 #include <pakfire/file.h>
 #include <pakfire/i18n.h>
@@ -613,10 +614,45 @@ ERROR:
        return r;
 }
 
+static int pakfire_build_find_elf_requires(
+               struct pakfire_ctx* ctx, struct pakfire_file* file, struct pakfire_find_deps_ctx* deps) {
+       struct pakfire_elf* elf = NULL;
+       int r;
+
+       // Try to open the ELF file
+       r = pakfire_elf_open_file(&elf, ctx, file);
+       if (r < 0) {
+               switch (-r) {
+                       // This does not seem to be an ELF file
+                       case ENOTSUP:
+                               return 0;
+
+                       // Raise any other errors
+                       default:
+                               goto ERROR;
+               }
+       }
+
+       // Fetch the interpreter
+       const char* interpreter = pakfire_elf_interpreter(elf);
+       if (interpreter) {
+               r = pakfire_package_add_dep(deps->pkg, PAKFIRE_PKG_REQUIRES, "%s", interpreter);
+               if (r < 0)
+                       goto ERROR;
+       }
+
+ERROR:
+       if (elf)
+               pakfire_elf_unref(elf);
+
+       return r;
+}
+
 static int __pakfire_build_find_requires(
                struct pakfire_ctx* ctx, struct pakfire_file* file, void* data) {
        struct pakfire_find_deps_ctx* deps = data;
        const char* path = NULL;
+       int r;
 
        // Fetch the file path
        path = pakfire_file_get_path(file);
@@ -632,9 +668,20 @@ static int __pakfire_build_find_requires(
                return 0;
 
        // Handle pkg-config files
-       if (pakfire_path_match("**.pc", path))
+       else if (pakfire_path_match("**.pc", path))
                return pakfire_build_find_pkgconfig_requires(ctx, file, deps);
 
+       // Split certain file types differently
+       switch (pakfire_file_get_type(file)) {
+               // Regular files
+               case S_IFREG:
+                       // Handle ELF files
+                       r = pakfire_build_find_elf_requires(ctx, file, deps);
+                       if (r < 0)
+                               return r;
+                       break;
+       }
+
        return 0;
 }