]>
Commit | Line | Data |
---|---|---|
1 | /*############################################################################# | |
2 | # # | |
3 | # Pakfire - The IPFire package management system # | |
4 | # Copyright (C) 2023 Pakfire development team # | |
5 | # # | |
6 | # This program is free software: you can redistribute it and/or modify # | |
7 | # it under the terms of the GNU General Public License as published by # | |
8 | # the Free Software Foundation, either version 3 of the License, or # | |
9 | # (at your option) any later version. # | |
10 | # # | |
11 | # This program is distributed in the hope that it will be useful, # | |
12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # | |
13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # | |
14 | # GNU General Public License for more details. # | |
15 | # # | |
16 | # You should have received a copy of the GNU General Public License # | |
17 | # along with this program. If not, see <http://www.gnu.org/licenses/>. # | |
18 | # # | |
19 | #############################################################################*/ | |
20 | ||
21 | #include <argp.h> | |
22 | ||
23 | #include "command.h" | |
24 | #include "dist.h" | |
25 | #include "pakfire.h" | |
26 | ||
27 | #include <pakfire/dist.h> | |
28 | #include <pakfire/pakfire.h> | |
29 | ||
30 | static const char* args_doc = "dist MAKEFILES..."; | |
31 | ||
32 | static const char* doc = "Creates source packages from makefiles"; | |
33 | ||
34 | #define MAX_MAKEFILES 32 | |
35 | ||
36 | struct config { | |
37 | const char* resultdir; | |
38 | ||
39 | // Makefiles | |
40 | char* makefiles[MAX_MAKEFILES]; | |
41 | unsigned int num_makefiles; | |
42 | }; | |
43 | ||
44 | static error_t parse(int key, char* arg, struct argp_state* state, void* data) { | |
45 | struct config* config = data; | |
46 | ||
47 | switch (key) { | |
48 | case ARGP_KEY_ARG: | |
49 | if (config->num_makefiles >= MAX_MAKEFILES) | |
50 | return -ENOBUFS; | |
51 | ||
52 | config->makefiles[config->num_makefiles++] = arg; | |
53 | break; | |
54 | ||
55 | default: | |
56 | return ARGP_ERR_UNKNOWN; | |
57 | } | |
58 | ||
59 | return 0; | |
60 | } | |
61 | ||
62 | int cli_dist(void* data, int argc, char* argv[]) { | |
63 | struct pakfire* pakfire = NULL; | |
64 | struct config config = { | |
65 | .resultdir = NULL, | |
66 | }; | |
67 | char cwd[PATH_MAX]; | |
68 | int r; | |
69 | ||
70 | struct cli_config* cli_config = data; | |
71 | ||
72 | // Parse the command line | |
73 | r = cli_parse(NULL, NULL, args_doc, doc, parse, 0, argc, argv, &config); | |
74 | if (r) | |
75 | goto ERROR; | |
76 | ||
77 | // Set result directory to PWD | |
78 | if (!config.resultdir) | |
79 | config.resultdir = getcwd(cwd, sizeof(cwd)); | |
80 | ||
81 | // Setup pakfire | |
82 | r = cli_setup_pakfire(&pakfire, cli_config); | |
83 | if (r) | |
84 | goto ERROR; | |
85 | ||
86 | // Process all packages | |
87 | for (unsigned int i = 0; i < config.num_makefiles; i++) { | |
88 | r = pakfire_dist(pakfire, config.makefiles[i], config.resultdir, NULL); | |
89 | if (r) { | |
90 | fprintf(stderr, "Could not dist %s\n", config.makefiles[i]); | |
91 | goto ERROR; | |
92 | } | |
93 | } | |
94 | ||
95 | ERROR: | |
96 | if (pakfire) | |
97 | pakfire_unref(pakfire); | |
98 | ||
99 | return r; | |
100 | } |