1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
|
/*
* mkpkg.h - package build tool for rawnix.org
* https://rawnix.org
*
* Copyright (c) 2025 zorz@gmx.com
* SPDX-License-Identifier: BSD-2-Clause
*/
#ifndef MKPKG_H
#define MKPKG_H
#include "lockbox_common.h"
#include "util.h"
#define MKPKG_DEFAULT_UA "mkpkg/" MKPKG_VERSION
/* ── Limits ──────────────────────────────────────────────────────────── */
#define MAX_SOURCES 256
#define MAX_BUILD_CMDS 512
#define MAX_CUSTOM_VARS 32
#define MAX_META_ITEMS 16
#define MAX_DEPS 64
#define MAX_LOCKBOX_CMDS 16
/* ── Parsed MAKEPKG data ─────────────────────────────────────────────── */
typedef struct {
char *url;
char *rename; /* NULL or rename target; "SKIP" means skip this source */
} source_t;
typedef struct {
char *name;
char *value;
} custom_var_t;
typedef struct {
char *name;
char *version;
char *release;
custom_var_t custom_vars[MAX_CUSTOM_VARS];
int custom_var_count;
source_t sources[MAX_SOURCES];
int source_count;
char *sha256sums[MAX_SOURCES];
int sha256sum_count;
/* hook functions */
char *pre_shell_cmds[MAX_BUILD_CMDS];
int pre_shell_count;
int has_pre_shell;
char *post_shell_cmds[MAX_BUILD_CMDS];
int post_shell_count;
int has_post_shell;
char *extract_cmds[MAX_BUILD_CMDS];
int extract_count;
int has_extract;
char *patch_cmds[MAX_BUILD_CMDS];
int patch_count;
int has_patch;
char *build_cmds[MAX_BUILD_CMDS];
int build_count;
char *post_build_cmds[MAX_BUILD_CMDS];
int post_build_count;
int has_post_build;
/* declarative metadata */
char *groups[MAX_META_ITEMS];
int group_count;
char *services[MAX_META_ITEMS];
int service_count;
char *permissions[MAX_META_ITEMS];
int permission_count;
char *capabilities[MAX_META_ITEMS];
int capability_count;
/* dependency lists (for lockbox) */
char *depends[MAX_DEPS];
int depend_count;
char *makedepends[MAX_DEPS];
int makedepend_count;
/* lockbox=(cmd...) or lockbox=(yes) */
char *lockbox_cmds[MAX_LOCKBOX_CMDS];
lockbox_profile_t lockbox_cmd_profiles[MAX_LOCKBOX_CMDS];
int lockbox_cmd_count;
int has_lockbox;
/* embedded signify public key from signify() block */
char *signify_pubkey;
int has_signify;
} pkgfile_t;
/* ── Build configuration ─────────────────────────────────────────────── */
typedef struct {
/* directories */
char root_dir[PATH_MAX_LEN]; /* port directory (where MAKEPKG lives) */
char source_dir[PATH_MAX_LEN]; /* where sources are downloaded */
char package_dir[PATH_MAX_LEN]; /* where .pkg.tar.gz is placed */
char work_dir[PATH_MAX_LEN]; /* build work directory */
char tmp_dir[PATH_MAX_LEN]; /* mkpkg temp files (signatures etc.) */
char rootfs[PATH_MAX_LEN]; /* -r: install to this rootfs */
/* files */
char pkgfile[PATH_MAX_LEN]; /* MAKEPKG */
char config_file[PATH_MAX_LEN]; /* /etc/mkpkg.conf */
char footprint_file[PATH_MAX_LEN]; /* .footprint / .footprint.lock */
char nostrip_file[PATH_MAX_LEN]; /* .nostrip */
char signature_file[PATH_MAX_LEN]; /* .signature / .signature.lock */
char secret_key[PATH_MAX_LEN]; /* signing key path */
/* operational flags */
int download;
int download_only;
int extract_only;
int install;
int upgrade;
int print_footprint;
int print_checksums;
int update_footprint;
int update_checksums;
int update_signature;
int update_pubkey;
int check_signature;
int show_pubkey;
int ignore_footprint;
int ignore_checksums;
int ignore_signature;
int no_strip;
int clean;
int clean_download;
int clean_footprint;
int clean_signature;
int clean_work;
int keep_work;
int resume;
int lockbox;
int no_lockbox;
/* MKPKG_COMPRESSION_MODE: gz (default), xz, zst, bz2, lz */
char compression[8];
} config_t;
/* ── parser.c ────────────────────────────────────────────────────────── */
int parse_pkgfile(const char *filename, pkgfile_t *pkgfile);
int parse_config(const char *filename, config_t *config);
void free_pkgfile(pkgfile_t *pkgfile);
char *expand_vars(const char *str, const pkgfile_t *pkgfile);
/* ── download.c ──────────────────────────────────────────────────────── */
int download_sources(pkgfile_t *pkgfile, config_t *config);
/* ── checksum.c ──────────────────────────────────────────────────────── */
int verify_checksums(pkgfile_t *pkgfile, config_t *config);
int generate_checksums(pkgfile_t *pkgfile, config_t *config);
int update_checksums(pkgfile_t *pkgfile, config_t *config);
/* streaming SHA256 — lets the package be hashed while it is written
* (arc_create_pkg sink); the result is cached so signing does not
* re-read the tarball */
void *sha256_stream_new(void);
void sha256_stream_update(void *ctx, const void *buf, size_t len);
int sha256_stream_final(void *ctx, char *result, size_t result_size);
void sha256_cache_store(const char *path, const char *sha);
int make_sig_checksums(pkgfile_t *pkgfile, config_t *config,
const char *outfile);
int bind_sig_checksums(const char *cks_path, config_t *config);
/* ── signature.c ─────────────────────────────────────────────────────── */
int verify_signature(const char *sigfile, pkgfile_t *pkgfile,
config_t *config);
int create_signature(pkgfile_t *pkgfile, config_t *config);
int show_pubkey(pkgfile_t *pkgfile);
int update_pubkey(pkgfile_t *pkgfile, config_t *config);
/* ── build.c ─────────────────────────────────────────────────────────── */
int unpack_sources(pkgfile_t *pkgfile, config_t *config,
const char *srcdir);
int strip_files(const char *pkgdir, const char *nostrip_file);
int compress_manpages(const char *pkgdir);
int remove_la_files(const char *pkgdir);
int run_shell_hook(pkgfile_t *pkgfile, config_t *config,
const char *label, char **cmds, int count);
int build_package(pkgfile_t *pkgfile, config_t *config,
const char *target);
int install_package(const char *target, int upgrade, const char *rootfs);
/* ── footprint.c ─────────────────────────────────────────────────────── */
int make_footprint(const char *pkgfile, const char *outfile);
int make_footprint_fast(const char *pkgdir, const char *outfile);
int check_footprint(const char *pkgfile, const char *fpfile,
config_t *config);
int update_footprint(const char *pkgfile, const char *fpfile,
config_t *config);
/* ── lockbox.c ───────────────────────────────────────────────────────── */
int lockbox_enter(pkgfile_t *pkgfile, config_t *config,
const char *target);
/* ── mkpkg.c (shared with build.c) ──────────────────────────────────── */
int check_directory(const char *path, int write_required);
void make_work_dir(config_t *config);
int remove_work_dir(config_t *config);
int build_needed(pkgfile_t *pkgfile, config_t *config,
const char *target);
#endif /* MKPKG_H */
|