]> git.ipfire.org Git - pakfire.git/commitdiff
build: Find makefiles and build them all
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 15 Jun 2021 11:16:53 +0000 (11:16 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 15 Jun 2021 11:16:53 +0000 (11:16 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/build.c

index 0444800c72d8c8d7cb55caeb79b59fbf287fba16..b6975f49c6ee586e7dc7f3dba962d7867cb67614 100644 (file)
@@ -19,6 +19,7 @@
 #############################################################################*/
 
 #include <errno.h>
+#include <glob.h>
 #include <stdlib.h>
 #include <sys/mount.h>
 
@@ -761,43 +762,12 @@ static int pakfire_build_run_post_build_scripts(Pakfire pakfire, const char* bui
        return 0;
 }
 
-PAKFIRE_EXPORT int pakfire_build(Pakfire pakfire, const char* path,
-               const char* target, const char* id, int flags,
-               pakfire_execute_logging_callback logging_callback, void* data) {
+static int pakfire_build_makefile(Pakfire pakfire, const char* path, const char* target,
+               const char* id, int flags, pakfire_execute_logging_callback logging_callback, void* data) {
        PakfireParser makefile = NULL;
        char buildroot[PATH_MAX];
        struct pakfire_parser_error* error = NULL;
-       char* generated_id = NULL;
-       int r;
-
-       // Check for valid input
-       if (!path) {
-               errno = EINVAL;
-               return 1;
-       }
-
-       // The default target is the local repository path
-       if (!target) {
-               PakfireRepo repo = pakfire_get_repo(pakfire, "local");
-               if (!repo) {
-                       errno = EINVAL;
-                       return 1;
-               }
-
-               target = pakfire_repo_get_path(repo);
-               pakfire_repo_unref(repo);
-       }
-
-       const char* packages[] = {
-               path, NULL
-       };
-
-       // Install the package into the build environment
-       r = pakfire_install(pakfire, packages, 0, NULL);
-       if (r) {
-               ERROR(pakfire, "Could not install %s\n", path);
-               goto ERROR;
-       }
+       int r = 1;
 
        const char* root = pakfire_get_path(pakfire);
 
@@ -826,15 +796,6 @@ PAKFIRE_EXPORT int pakfire_build(Pakfire pakfire, const char* path,
                goto ERROR;
        }
 
-       // If no build ID was passed, we generate a random one
-       if (!id) {
-               generated_id = pakfire_generate_uuid();
-               if (!generated_id)
-                       goto ERROR;
-
-               id = generated_id;
-       }
-
        // Set BUILDROOT
        pakfire_parser_set(makefile, NULL, "BUILDROOT", buildroot_rel, 0);
 
@@ -863,8 +824,6 @@ PAKFIRE_EXPORT int pakfire_build(Pakfire pakfire, const char* path,
        }
 
 ERROR:
-       if (generated_id)
-               free(generated_id);
        if (makefile)
                pakfire_parser_unref(makefile);
 
@@ -874,6 +833,80 @@ ERROR:
        return r;
 }
 
+PAKFIRE_EXPORT int pakfire_build(Pakfire pakfire, const char* path,
+               const char* target, const char* id, int flags,
+               pakfire_execute_logging_callback logging_callback, void* data) {
+       char makefiles[PATH_MAX];
+       char* generated_id = NULL;
+       glob_t buffer;
+       int r = 1;
+
+       // Check for valid input
+       if (!path) {
+               errno = EINVAL;
+               return 1;
+       }
+
+       // The default target is the local repository path
+       if (!target) {
+               PakfireRepo repo = pakfire_get_repo(pakfire, "local");
+               if (!repo) {
+                       errno = EINVAL;
+                       return 1;
+               }
+
+               target = pakfire_repo_get_path(repo);
+               pakfire_repo_unref(repo);
+       }
+
+       // If no build ID was passed, we generate a random one
+       if (!id) {
+               generated_id = pakfire_generate_uuid();
+               if (!generated_id)
+                       goto ERROR;
+
+               id = generated_id;
+       }
+
+       const char* packages[] = {
+               path, NULL
+       };
+
+       // Install the package into the build environment
+       r = pakfire_install(pakfire, packages, 0, NULL);
+       if (r) {
+               ERROR(pakfire, "Could not install %s\n", path);
+               goto ERROR;
+       }
+
+       // Where are the makefiles located?
+       r = pakfire_make_path(pakfire, makefiles, "/usr/src/packages/*/*.nm");
+       if (r < 0)
+               goto ERROR;
+
+       // Find all makefiles
+       r = glob(makefiles, 0, NULL, &buffer);
+       if (r) {
+               ERROR(pakfire, "glob() on %s failed: %m\n", makefiles);
+               goto ERROR;
+       }
+
+       // Iterate over all makefiles
+       for (unsigned int i = 0; i < buffer.gl_pathc; i++) {
+               r = pakfire_build_makefile(pakfire, buffer.gl_pathv[i], target, id, flags,
+                       logging_callback, data);
+               if (r)
+                       goto ERROR;
+       }
+
+ERROR:
+       if (generated_id)
+               free(generated_id);
+       globfree(&buffer);
+
+       return r;
+}
+
 PAKFIRE_EXPORT int pakfire_shell(Pakfire pakfire) {
        const char* argv[] = {
                "/bin/bash", "--login", NULL,