aboutsummaryrefslogtreecommitdiff
path: root/make.c
diff options
context:
space:
mode:
authorThomas Voss <mail@thomasvoss.com> 2024-11-13 20:21:43 +0100
committerThomas Voss <mail@thomasvoss.com> 2024-11-13 20:21:43 +0100
commitaa8fe6e1094651217771cb8744af73b1418ff9b6 (patch)
treef9ac7c06982a51092e4cd79d82a930cd5471405b /make.c
parentffcb9954a9ab4c0ddbc9458be67f9c40ab13ae7a (diff)
Add an install target
Diffstat (limited to 'make.c')
-rw-r--r--make.c48
1 files changed, 43 insertions, 5 deletions
diff --git a/make.c b/make.c
index b1d4d4d..761a1e5 100644
--- a/make.c
+++ b/make.c
@@ -3,6 +3,7 @@
#include <glob.h>
#include <langinfo.h>
#include <libgen.h>
+#include <limits.h>
#include <locale.h>
#include <stdarg.h>
#include <stdint.h>
@@ -19,6 +20,14 @@
#define flagset(o) (flags & UINT32_C(1)<<(o)-'a')
+#define EXEC(cmd) \
+ do { \
+ cmdput(cmd); \
+ if (cmdexec(cmd) != EXIT_SUCCESS) \
+ exit(EXIT_FAILURE); \
+ strszero(&cmd); \
+ } while (false)
+
[[noreturn, gnu::format(printf, 1, 2)]]
static void err(const char *, ...);
static void build_mlib(void);
@@ -107,14 +116,43 @@ usage:
} else if (strcmp(argv[0], "distclean") == 0) {
strspushl(&cmd, "rm", "-f", "grab", "git-grab", "make");
if (fexists("vendor/mlib/make")) {
- cmdput(cmd);
- if (cmdexec(cmd) != EXIT_SUCCESS)
- exit(EXIT_FAILURE);
- strszero(&cmd);
+ EXEC(cmd);
strspushl(&cmd, "vendor/mlib/make", "clean");
}
} else if (strcmp(argv[0], "install") == 0) {
- /* TODO: Add install target */
+ char *p;
+ const char *ev;
+ static char prefix[PATH_MAX + 1];
+ static char bindir[PATH_MAX + 1];
+ static char mandir[PATH_MAX + 1];
+
+ p = prefix;
+ if ((ev = getenv("DESTDIR")) != nullptr)
+ p = stpncpy(p, ev, sizeof(prefix) - 1);
+ if ((ev = getenv("PREFIX")) != nullptr)
+ strncpy(p, ev, sizeof(prefix) - 1 - (p - prefix));
+ else
+ strncpy(p, "/usr/local", sizeof(prefix) - 1 - (p - prefix));
+
+ snprintf(bindir, sizeof(bindir), "%s/%s", prefix, "bin");
+ snprintf(mandir, sizeof(mandir), "%s/%s", prefix, "share/man/man1");
+
+ if (binexists("strip")) {
+ strspushl(&cmd, "strip", "-s", "grab", "git-grab");
+ EXEC(cmd);
+ }
+
+ strspushl(&cmd, "mkdir", "-p", bindir, mandir);
+ EXEC(cmd);
+
+ strspushl(&cmd, "cp", "grab", "git-grab", bindir);
+ EXEC(cmd);
+
+ strspushl(&cmd, "cp", "man/grab.1", "man/git-grab.1", mandir);
+ EXEC(cmd);
+
+ strsfree(&cmd);
+ return EXIT_SUCCESS;
} else {
err(strcmp(nl_langinfo(CODESET), "UTF-8") == 0
? "invalid subcommand ā€” ā€˜%sā€™"