]>
Commit | Line | Data |
---|---|---|
5f9bc3d2 MT |
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 | ||
7014986e | 21 | #include <argp.h> |
5f9bc3d2 MT |
22 | |
23 | #include "command.h" | |
24 | #include "dist.h" | |
7014986e | 25 | #include "pakfire.h" |
5f9bc3d2 MT |
26 | |
27 | #include <pakfire/dist.h> | |
28 | #include <pakfire/pakfire.h> | |
29 | ||
7014986e MT |
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 | |
5f9bc3d2 MT |
35 | |
36 | struct config { | |
37 | const char* resultdir; | |
5f9bc3d2 | 38 | |
7014986e MT |
39 | // Makefiles |
40 | char* makefiles[MAX_MAKEFILES]; | |
41 | unsigned int num_makefiles; | |
42 | }; | |
5f9bc3d2 | 43 | |
d673ca6c | 44 | static error_t parse(int key, char* arg, struct argp_state* state, void* data) { |
7014986e | 45 | struct config* config = data; |
5f9bc3d2 | 46 | |
7014986e MT |
47 | switch (key) { |
48 | case ARGP_KEY_ARG: | |
49 | if (config->num_makefiles >= MAX_MAKEFILES) | |
50 | return -ENOBUFS; | |
5f9bc3d2 | 51 | |
7014986e | 52 | config->makefiles[config->num_makefiles++] = arg; |
5f9bc3d2 MT |
53 | break; |
54 | ||
7014986e MT |
55 | default: |
56 | return ARGP_ERR_UNKNOWN; | |
5f9bc3d2 MT |
57 | } |
58 | ||
59 | return 0; | |
60 | } | |
61 | ||
7014986e MT |
62 | int cli_dist(void* data, int argc, char* argv[]) { |
63 | struct pakfire* pakfire = NULL; | |
5f9bc3d2 MT |
64 | struct config config = { |
65 | .resultdir = NULL, | |
66 | }; | |
67 | char cwd[PATH_MAX]; | |
68 | int r; | |
69 | ||
7014986e MT |
70 | struct cli_config* cli_config = data; |
71 | ||
72 | // Parse the command line | |
9b8d2c6e | 73 | r = cli_parse(NULL, NULL, args_doc, doc, parse, 0, argc, argv, &config); |
5f9bc3d2 | 74 | if (r) |
7014986e | 75 | goto ERROR; |
5f9bc3d2 MT |
76 | |
77 | // Set result directory to PWD | |
78 | if (!config.resultdir) | |
79 | config.resultdir = getcwd(cwd, sizeof(cwd)); | |
80 | ||
7014986e MT |
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++) { | |
fb15efc3 | 88 | r = pakfire_dist(pakfire, config.makefiles[i], config.resultdir, NULL); |
7014986e MT |
89 | if (r) { |
90 | fprintf(stderr, "Could not dist %s\n", config.makefiles[i]); | |
91 | goto ERROR; | |
92 | } | |
5f9bc3d2 MT |
93 | } |
94 | ||
7014986e MT |
95 | ERROR: |
96 | if (pakfire) | |
97 | pakfire_unref(pakfire); | |
98 | ||
5f9bc3d2 MT |
99 | return r; |
100 | } |