/* * 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 */