From: Michael Tremer Date: Sat, 1 May 2021 15:34:34 +0000 (+0000) Subject: dist: Set various default variables when reading makefiles X-Git-Tag: 0.9.28~1285^2~159 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=59ab223d452e853e402f2e18bf68165bdde5e649;p=pakfire.git dist: Set various default variables when reading makefiles Signed-off-by: Michael Tremer --- diff --git a/src/libpakfire/dist.c b/src/libpakfire/dist.c index 23f58cfa9..2cfb58245 100644 --- a/src/libpakfire/dist.c +++ b/src/libpakfire/dist.c @@ -26,6 +26,7 @@ #include #include +#include #include #include #include @@ -44,14 +45,58 @@ #define PAKFIRE_MACROS_DIR "/usr/lib/pakfire/macros" #define PAKFIRE_MACROS_GLOB_PATTERN PAKFIRE_MACROS_DIR "/*.macro" -PAKFIRE_EXPORT int pakfire_read_makefile(PakfireParser* parser, Pakfire pakfire, - const char* path, struct pakfire_parser_error** error) { - int r = 1; +static int pakfire_makefile_set_defaults(Pakfire pakfire, + PakfireParser parser, const char* path) { + char buffer[1024]; + int r; - *parser = pakfire_parser_create(pakfire, NULL, NULL, PAKFIRE_PARSER_FLAGS_EXPAND_COMMANDS); - if (!*parser) { - r = 1; - goto ERROR; + // Set DISTRO_NAME + const char* name = pakfire_get_distro_name(pakfire); + if (name) + pakfire_parser_set(parser, NULL, "DISTRO_NAME", name); + + // Set DISTRO_SNAME + const char* id = pakfire_get_distro_id(pakfire); + if (id) + pakfire_parser_set(parser, NULL, "DISTRO_SNAME", name); + + // Set DISTRO_RELEASE + const char* version_id = pakfire_get_distro_version_id(pakfire); + if (version_id) + pakfire_parser_set(parser, NULL, "DISTRO_RELEASE", version_id); + + // Set DISTRO_DISTTAG + if (id && version_id) { + pakfire_string_format(buffer, "%s%s", id, version_id); + + pakfire_parser_set(parser, NULL, "DISTRO_DISTTAG", buffer); + } + + // Set DISTRO_VENDOR + const char* vendor = pakfire_get_distro_vendor(pakfire); + if (vendor) + pakfire_parser_set(parser, NULL, "DISTRO_VENDOR", vendor); + + // Set DISTRO_ARCH + const char* arch = pakfire_get_arch(pakfire); + if (arch) { + pakfire_parser_set(parser, NULL, "DISTRO_ARCH", arch); + + const char* platform = pakfire_arch_platform(arch); + if (platform) + pakfire_parser_set(parser, NULL, "DISTRO_PLATFORM", platform); + + if (vendor) { + // Set DISTRO_MACHINE + r = pakfire_arch_machine(buffer, arch, vendor); + if (!r) + pakfire_parser_set(parser, NULL, "DISTRO_MACHINE", buffer); + + // Set DISTRO_BUILDTARGET + r = pakfire_arch_buildtarget(buffer, arch, vendor); + if (!r) + pakfire_parser_set(parser, NULL, "DISTRO_BUILDTARGET", buffer); + } } // Set BASEDIR @@ -59,10 +104,28 @@ PAKFIRE_EXPORT int pakfire_read_makefile(PakfireParser* parser, Pakfire pakfire, if (dirname) { const char* root = pakfire_get_path(pakfire); - pakfire_parser_set(*parser, NULL, "BASEDIR", pakfire_path_relpath(root, dirname)); + pakfire_parser_set(parser, NULL, "BASEDIR", pakfire_path_relpath(root, dirname)); free(dirname); } + return 0; +} + +PAKFIRE_EXPORT int pakfire_read_makefile(PakfireParser* parser, Pakfire pakfire, + const char* path, struct pakfire_parser_error** error) { + int r = 1; + + *parser = pakfire_parser_create(pakfire, NULL, NULL, PAKFIRE_PARSER_FLAGS_EXPAND_COMMANDS); + if (!*parser) { + r = 1; + goto ERROR; + } + + // Set defaults + r = pakfire_makefile_set_defaults(pakfire, *parser, path); + if (r) + goto ERROR; + // Find all macros DEBUG(pakfire, "Searching for macros in %s\n", PAKFIRE_MACROS_GLOB_PATTERN); diff --git a/src/libpakfire/include/pakfire/pakfire.h b/src/libpakfire/include/pakfire/pakfire.h index 3383911c7..c2f49941e 100644 --- a/src/libpakfire/include/pakfire/pakfire.h +++ b/src/libpakfire/include/pakfire/pakfire.h @@ -93,6 +93,12 @@ int pakfire_read_makefile(PakfireParser* parser, Pakfire pakfire, const char* pa struct pakfire_config* pakfire_get_config(Pakfire pakfire); +const char* pakfire_get_distro_name(Pakfire pakfire); +const char* pakfire_get_distro_id(Pakfire pakfire); +const char* pakfire_get_distro_vendor(Pakfire pakfire); +const char* pakfire_get_distro_version(Pakfire pakfire); +const char* pakfire_get_distro_version_id(Pakfire pakfire); + #define pakfire_make_path(pakfire, dst, path) \ __pakfire_make_path(pakfire, dst, sizeof(dst) - 1, path) int __pakfire_make_path(Pakfire pakfire, char* dst, size_t length, const char* path); diff --git a/src/libpakfire/pakfire.c b/src/libpakfire/pakfire.c index ac58f62cc..4760522bd 100644 --- a/src/libpakfire/pakfire.c +++ b/src/libpakfire/pakfire.c @@ -525,6 +525,41 @@ ERROR: return r; } +const char* pakfire_get_distro_name(Pakfire pakfire) { + if (*pakfire->distro.name) + return pakfire->distro.name; + + return NULL; +} + +const char* pakfire_get_distro_id(Pakfire pakfire) { + if (*pakfire->distro.id) + return pakfire->distro.id; + + return NULL; +} + +const char* pakfire_get_distro_vendor(Pakfire pakfire) { + if (*pakfire->distro.vendor) + return pakfire->distro.vendor; + + return NULL; +} + +const char* pakfire_get_distro_version(Pakfire pakfire) { + if (*pakfire->distro.version) + return pakfire->distro.version; + + return NULL; +} + +const char* pakfire_get_distro_version_id(Pakfire pakfire) { + if (*pakfire->distro.version_id) + return pakfire->distro.version_id; + + return NULL; +} + static int pakfire_config_import_distro(Pakfire pakfire) { // Nothing to do if there is no distro section if (!pakfire_config_has_section(pakfire->config, "distro"))