aboutsummaryrefslogtreecommitdiff
path: root/vendor/librune/make.c
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/librune/make.c')
-rw-r--r--vendor/librune/make.c86
1 files changed, 50 insertions, 36 deletions
diff --git a/vendor/librune/make.c b/vendor/librune/make.c
index c8a2d4d..a7227c9 100644
--- a/vendor/librune/make.c
+++ b/vendor/librune/make.c
@@ -1,6 +1,7 @@
#include <errno.h>
#include <glob.h>
#include <libgen.h>
+#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
@@ -26,48 +27,59 @@
cmdclr(&c); \
} while (0)
+#define streq(a, b) (!strcmp(a, b))
+
static void work(void *);
static int globerr(const char *, int);
int
main(int argc, char **argv)
{
- cmd_t c = {0};
- size_t n;
- glob_t g;
- tpool_t tp;
-
cbsinit(argc, argv);
rebuild();
- if (chdir(dirname(*argv)) == -1)
- die("chdir");
-
- if (glob("lib/utf8/*.c", 0, globerr, &g)
- || glob("lib/gbrk/*.c", GLOB_APPEND, globerr, &g))
- {
- die("glob");
+ if (argc > 1) {
+ if (streq(argv[1], "clean")) {
+ cmd_t c = {0};
+ cmdadd(&c, "find", ".", "-name", "*.[ao]", "-delete");
+ cmdprc(c);
+ } else {
+ diex("invalid subcommand -- '%s'", argv[1]);
+ exit(EXIT_FAILURE);
+ }
+ } else {
+ cmd_t c = {0};
+ size_t n;
+ glob_t g;
+ tpool_t tp;
+
+ if (glob("lib/*/*.c", 0, globerr, &g))
+ die("glob");
+
+ if ((n = nproc()) == -1) {
+ if (errno)
+ die("nproc");
+ n = 8;
+ }
+
+ tpinit(&tp, n);
+ for (size_t i = 0; i < g.gl_pathc; i++)
+ tpenq(&tp, work, g.gl_pathv[i], NULL);
+ tpwait(&tp);
+ tpfree(&tp);
+
+ for (size_t i = 0; i < g.gl_pathc; i++)
+ g.gl_pathv[i][strlen(g.gl_pathv[i]) - 1] = 'o';
+
+ if (foutdatedv("librune.a", (const char **)g.gl_pathv, g.gl_pathc)) {
+ cmdadd(&c, "ar", "rcs", "librune.a");
+ cmdaddv(&c, g.gl_pathv, g.gl_pathc);
+ cmdprc(c);
+ }
+
+ globfree(&g);
}
- if ((n = nproc()) == -1) {
- if (errno)
- die("nproc");
- n = 8;
- }
-
- tpinit(&tp, n);
- for (size_t i = 0; i < g.gl_pathc; i++)
- tpenq(&tp, work, g.gl_pathv[i], NULL);
- tpwait(&tp);
- tpfree(&tp);
-
- cmdadd(&c, "ar", "rcs", "librune.a");
- for (size_t i = 0; i < g.gl_pathc; i++)
- g.gl_pathv[i][strlen(g.gl_pathv[i]) - 1] = 'o';
- cmdaddv(&c, g.gl_pathv, g.gl_pathc);
- cmdprc(c);
-
- globfree(&g);
return EXIT_SUCCESS;
}
@@ -82,11 +94,13 @@ work(void *p)
die("strdup");
dst[strlen(dst) - 1] = 'o';
- env_or_default(&sv, "CC", CC);
- env_or_default(&sv, "CFLAGS", CFLAGS);
- cmdaddv(&c, sv.buf, sv.len);
- cmdadd(&c, "-Iinclude", "-fPIC", "-o", dst, "-c", src);
- cmdprc(c);
+ if (foutdated(dst, src)) {
+ env_or_default(&sv, "CC", CC);
+ env_or_default(&sv, "CFLAGS", CFLAGS);
+ cmdaddv(&c, sv.buf, sv.len);
+ cmdadd(&c, "-Iinclude", "-fPIC", "-o", dst, "-c", src);
+ cmdprc(c);
+ }
free(dst);
}