#include <fts.h>
#include <dirent.h>
#include <fcntl.h>
+#include <glob.h>
#include <stddef.h>
#include <stdlib.h>
#include <pakfire/types.h>
#include <pakfire/util.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;
+
+ *parser = pakfire_parser_create(pakfire, NULL, NULL, PAKFIRE_PARSER_FLAGS_EXPAND_COMMANDS);
+ if (!*parser) {
+ r = 1;
+ goto ERROR;
+ }
+
+ // XXX set defaults
+
+ // Find all macros
+ char* macros = pakfire_make_path(pakfire, PAKFIRE_MACROS_GLOB_PATTERN);
+ if (!macros)
+ goto ERROR;
+
+ DEBUG(pakfire, "Searching for macros in %s\n", macros);
+
+ glob_t globmacros;
+ r = glob(macros, 0, NULL, &globmacros);
+ free(macros);
+
+ // Handle any errors
+ switch (r) {
+ case 0:
+ case GLOB_NOMATCH:
+ break;
+
+ case GLOB_NOSPACE:
+ errno = ENOMEM;
+ goto ERROR;
+
+ case GLOB_ABORTED:
+ goto ERROR;
+
+ default:
+ ERROR(pakfire, "glob() returned an unhandled error: %d\n", r);
+ goto ERROR;
+ }
+
+ DEBUG(pakfire, "Found %zu macro(s)\n", globmacros.gl_pathc);
+
+ // Read all macros
+ for (unsigned int i = 0; i < globmacros.gl_pathc; i++) {
+ // Parse the file
+ r = pakfire_parser_read_file(*parser, globmacros.gl_pathv[i], error);
+ if (r)
+ goto ERROR;
+ }
+
+ globfree(&globmacros);
+
+ // Finally, parse the makefile
+ r = pakfire_parser_read_file(*parser, path, error);
+ if (r)
+ goto ERROR;
+
+ return 0;
+
+ERROR:
+ globfree(&globmacros);
+
+ if (*parser) {
+ pakfire_parser_unref(*parser);
+ *parser = NULL;
+ }
+
+ return r;
+}
+
static int pakfire_dist_download_source(Pakfire pakfire, const char* filename,
const char* cache_path) {
struct pakfire_downloader* downloader;
#include <ctype.h>
#include <errno.h>
#include <ftw.h>
-#include <glob.h>
#include <linux/limits.h>
#include <stddef.h>
#include <stdio.h>
// Restore errno
errno = saved_errno;
}
-
-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;
- }
-
- // XXX set defaults
-
- // Find all macros
- char* macros = pakfire_make_path(pakfire, PAKFIRE_MACROS_GLOB_PATTERN);
- if (!macros)
- goto ERROR;
-
- DEBUG(pakfire, "Searching for macros in %s\n", macros);
-
- glob_t globmacros;
- r = glob(macros, 0, NULL, &globmacros);
- free(macros);
-
- // Handle any errors
- switch (r) {
- case 0:
- case GLOB_NOMATCH:
- break;
-
- case GLOB_NOSPACE:
- errno = ENOMEM;
- goto ERROR;
-
- case GLOB_ABORTED:
- goto ERROR;
-
- default:
- ERROR(pakfire, "glob() returned an unhandled error: %d\n", r);
- goto ERROR;
- }
-
- DEBUG(pakfire, "Found %zu macro(s)\n", globmacros.gl_pathc);
-
- // Read all macros
- for (unsigned int i = 0; i < globmacros.gl_pathc; i++) {
- // Parse the file
- r = pakfire_parser_read_file(*parser, globmacros.gl_pathv[i], error);
- if (r)
- goto ERROR;
- }
-
- globfree(&globmacros);
-
- // Finally, parse the makefile
- r = pakfire_parser_read_file(*parser, path, error);
- if (r)
- goto ERROR;
-
- return 0;
-
-ERROR:
- globfree(&globmacros);
-
- if (*parser) {
- pakfire_parser_unref(*parser);
- *parser = NULL;
- }
-
- return r;
-}