]> git.ipfire.org Git - people/ms/pakfire.git/commitdiff
build: Add scaffolding to call build scripts
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 25 May 2021 17:14:33 +0000 (17:14 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 25 May 2021 17:14:33 +0000 (17:14 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
configure.ac
src/libpakfire/build.c

index 0a8b12bba1eccd8184afe9d1c6cd255fe253b1eb..b45a3855a490228a621eb769792ac6424db9dfa8 100644 (file)
@@ -197,6 +197,8 @@ AC_DEFINE_UNQUOTED([PAKFIRE_CACHE_PATH], ["/var/cache/${PACKAGE_NAME}"],
        [The path where Pakfire stores temporary data])
 AC_DEFINE_UNQUOTED([PAKFIRE_PRIVATE_DIR], ["/var/lib/${PACKAGE_NAME}"],
        [The path where Pakfire stores its private data])
+AC_DEFINE_UNQUOTED([PAKFIRE_SCRIPTS_DIR], ["${PREFIX}/lib/${PACKAGE_NAME}"],
+       [The path where Pakfire stores its scripts])
 
 AC_CONFIG_FILES([
        Makefile
index b79a7a6b8bdcfa19de5ce8b8de6e56d488ae3ef0..14b14f5556106c50e0468e459c9e2fc90f04fce4 100644 (file)
@@ -50,6 +50,44 @@ static const char* stages[] = {
        "\n" \
        "exit 0\n"
 
+static int pakfire_build_run_script(Pakfire pakfire, const char* filename,
+               pakfire_execute_logging_callback logging_callback, void* data) {
+       char* script = NULL;
+       size_t size = 0;
+       char path[PATH_MAX];
+
+       DEBUG(pakfire, "Running build script '%s'...\n", filename);
+
+       // Make the source path
+       pakfire_path_join(path, PAKFIRE_SCRIPTS_DIR, filename);
+
+       // Open the source script
+       FILE* f = fopen(path, "r");
+       if (!f) {
+               ERROR(pakfire, "Could not open %s: %s\n", path, strerror(errno));
+               return 1;
+       }
+
+       // Read the script into memory
+       int r = pakfire_read_file_into_buffer(f, &script, &size);
+       if (r) {
+               ERROR(pakfire, "Could not read script into memory: %s\n", strerror(errno));
+               goto ERROR;
+       }
+
+       // Execute it
+       r = pakfire_execute_script(pakfire, script, size, NULL, 0, logging_callback, data);
+       if (r) {
+               ERROR(pakfire, "Script '%s' failed with status %d\n", filename, r);
+       }
+
+ERROR:
+       if (script)
+               free(script);
+
+       return r;
+}
+
 static int append_to_array(const char*** array, const char* s) {
        unsigned int length = 0;
 
@@ -333,6 +371,11 @@ PAKFIRE_EXPORT int pakfire_build(Pakfire pakfire, const char* path,
                }
        }
 
+       // Remove static libraries
+       r = pakfire_build_run_script(pakfire, "compress-man-pages", logging_callback, data);
+       if (r)
+               goto ERROR;
+
        // Create the packages
        r = pakfire_build_packages(pakfire, makefile, target);
        if (r) {