# #
#############################################################################*/
-#include <errno.h>
-#include <getopt.h>
-#include <limits.h>
-#include <stdlib.h>
+#include <argp.h>
#include "command.h"
#include "dist.h"
+#include "pakfire.h"
#include <pakfire/dist.h>
#include <pakfire/pakfire.h>
-#define MAX_MAKEFILES 128
+static const char* args_doc = "dist MAKEFILES...";
+
+static const char* doc = "Creates source packages from makefiles";
+
+#define MAX_MAKEFILES 32
struct config {
const char* resultdir;
-};
-static void help(void) {
- printf(
- "%s [OPTIONS...] dist MAKEFILES...\n\n"
- "Options:\n"
- " -h --help Show help\n",
- program_invocation_short_name
- );
+ // Makefiles
+ char* makefiles[MAX_MAKEFILES];
+ unsigned int num_makefiles;
+};
- exit(0);
-}
+static error_t parse(int key, char* arg, void* data) {
+ struct config* config = data;
-static int parse_argv(int argc, char* argv[]) {
- static const struct option options[] = {
- { "help", no_argument, NULL, 'h' },
- { NULL },
- };
- int c;
+ switch (key) {
+ case ARGP_KEY_ARG:
+ if (config->num_makefiles >= MAX_MAKEFILES)
+ return -ENOBUFS;
- for (;;) {
- c = getopt_long(argc, argv, "h", options, NULL);
- if (c < 0)
+ config->makefiles[config->num_makefiles++] = arg;
break;
- switch (c) {
- case 'h':
- help();
-
- case '?':
- return -EINVAL;
-
- default:
- break;
- }
+ default:
+ return ARGP_ERR_UNKNOWN;
}
return 0;
}
-int cli_dist(struct pakfire* pakfire, int argc, char* argv[]) {
+int cli_dist(void* data, int argc, char* argv[]) {
+ struct pakfire* pakfire = NULL;
struct config config = {
.resultdir = NULL,
};
char cwd[PATH_MAX];
int r;
- // Parse commandline
- r = parse_argv(argc, argv);
+ struct cli_config* cli_config = data;
+
+ // Parse the command line
+ r = cli_parse(NULL, NULL, args_doc, doc, parse, argc, argv, &config);
if (r)
- return r;
+ goto ERROR;
// Set result directory to PWD
if (!config.resultdir)
config.resultdir = getcwd(cwd, sizeof(cwd));
- // Run for all arguments
- for (int i = 0; i < argc; i++) {
+ // Setup pakfire
+ r = cli_setup_pakfire(&pakfire, cli_config);
+ if (r)
+ goto ERROR;
+
+ // Process all packages
+ for (unsigned int i = 0; i < config.num_makefiles; i++) {
r = pakfire_dist(pakfire, argv[i], config.resultdir, NULL);
- if (r)
- break;
+ if (r) {
+ fprintf(stderr, "Could not dist %s\n", config.makefiles[i]);
+ goto ERROR;
+ }
}
+ERROR:
+ if (pakfire)
+ pakfire_unref(pakfire);
+
return r;
}
static const struct command commands[] = {
{ "build", cli_build, 1, -1, 0 },
{ "clean", cli_clean, 0, 0, 0 },
+ { "dist", cli_dist, 1, -1, 0 },
#if 0
- { "dist", 0, cli_dist },
{ "image", 0, cli_image },
{ "info", 0, cli_info },
{ "provides", 0, cli_provides },