From 0a9060e335d59f0ccaf5d9600abbcb938db30928 Mon Sep 17 00:00:00 2001 From: Thomas Voss Date: Tue, 23 Jan 2024 16:06:31 +0100 Subject: Bump librune version --- vendor/librune/make.c | 86 ++++++++++++++++++++++++++++++--------------------- 1 file changed, 50 insertions(+), 36 deletions(-) (limited to 'vendor/librune/make.c') 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 #include #include +#include #include #include #include @@ -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); } -- cgit v1.2.3