#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
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);
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"))