From: Michael Tremer Date: Tue, 25 May 2021 17:14:33 +0000 (+0000) Subject: build: Add scaffolding to call build scripts X-Git-Tag: 0.9.28~1285^2~75 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8d0f3a3538269378ea037e85d558e6006e6a676d;p=pakfire.git build: Add scaffolding to call build scripts Signed-off-by: Michael Tremer --- diff --git a/configure.ac b/configure.ac index 0a8b12bba..b45a3855a 100644 --- a/configure.ac +++ b/configure.ac @@ -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 diff --git a/src/libpakfire/build.c b/src/libpakfire/build.c index b79a7a6b8..14b14f555 100644 --- a/src/libpakfire/build.c +++ b/src/libpakfire/build.c @@ -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) {