]> git.ipfire.org Git - pakfire.git/commitdiff
dist: Set various default variables when reading makefiles
authorMichael Tremer <michael.tremer@ipfire.org>
Sat, 1 May 2021 15:34:34 +0000 (15:34 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sat, 1 May 2021 15:34:34 +0000 (15:34 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/dist.c
src/libpakfire/include/pakfire/pakfire.h
src/libpakfire/pakfire.c

index 23f58cfa9d616a80ac9c022fb62daa68d47ff12f..2cfb58245dc3cd8ac13e952bbb8222a8878e9b7e 100644 (file)
@@ -26,6 +26,7 @@
 #include <stddef.h>
 #include <stdlib.h>
 
+#include <pakfire/arch.h>
 #include <pakfire/dist.h>
 #include <pakfire/downloader.h>
 #include <pakfire/logging.h>
 #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);
index 3383911c74e6fbb91fbd0947d9a10849385a2537..c2f49941e0f8bd40788c530a5630e760b2400df0 100644 (file)
@@ -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);
index ac58f62cc6b06edfbe57e6d1ea54f63422b2e0fa..4760522bde6d41d08f4d7fc0e8ea66675ecedbe1 100644 (file)
@@ -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"))