aboutsummaryrefslogtreecommitdiff
path: root/src/recipes.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/recipes.c')
-rw-r--r--src/recipes.c78
1 files changed, 78 insertions, 0 deletions
diff --git a/src/recipes.c b/src/recipes.c
new file mode 100644
index 0000000..5f387b4
--- /dev/null
+++ b/src/recipes.c
@@ -0,0 +1,78 @@
+/*
+
+ pkgit - package it!
+
+ Copyright (C) 2026 dacctal
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+*/
+
+#include <unistd.h>
+
+#include "common.h"
+#include "files.h"
+#include "log.h"
+#include "pkg.h"
+
+static bool pkg_fetch_sources(package_t *pkg) {
+ if (!pkg_hook_fetch_sources(pkg)) {
+ log_error(GREEN "%.*s" COLOR_RESET " fetch failed",
+ str_fmt(&pkg->name));
+ return false;
+ }
+ return true;
+}
+
+static bool pkg_enter(package_t *pkg) {
+ if (!is_directory(pkg->src.data)) {
+ log_error(GREEN "%.*s" COLOR_RESET " is not a directory",
+ str_fmt(&pkg->src));
+ return false;
+ }
+ chdir(pkg->src.data);
+ return true;
+}
+
+bool pkg_setup(package_t *pkg) {
+ if (!pkg_enter(pkg)) return false;
+ if (!pkg_hook_setup(pkg)) return false;
+ return true;
+}
+
+bool pkg_build(package_t *pkg) {
+ if (!pkg_enter(pkg)) return false;
+ if (!pkg_hook_build(pkg)) return false;
+ return true;
+}
+
+bool pkg_install(package_t *pkg) {
+ if (!pkg_fetch_sources(pkg)) return false;
+ if (!pkg_enter(pkg)) return false;
+ if (!pkg_hook_setup(pkg)) return false;
+ if (!pkg_hook_build(pkg)) return false;
+ if (!pkg_hook_install(pkg)) return false;
+ return true;
+}
+
+bool pkg_remove(package_t *pkg) {
+ if (!pkg_enter(pkg)) return false;
+ if (!pkg_hook_setup(pkg)) return false;
+ return true;
+}
+
+bool pkg_update(package_t *pkg) {
+ if (!pkg_enter(pkg)) return false;
+ if (!pkg_hook_setup(pkg)) return false;
+ return true;
+}