From 42fe824ea8255869a5b5df8be9703dfabefba11b Mon Sep 17 00:00:00 2001 From: Thomas Voss Date: Thu, 18 Jan 2024 10:37:21 +0100 Subject: Support custom CFLAGS and CC --- make.c | 39 +++++++++++++++++++++++---------------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/make.c b/make.c index 12764da..d56967c 100644 --- a/make.c +++ b/make.c @@ -75,23 +75,30 @@ main(int argc, char **argv) cmdprc(c); } } else { - if (foutdated("grab", "src/grab.c", "src/da.h")) { - for (int i = 0; i < 2; i++) { - char buf[] = "-DGIT_GRAB=X"; - buf[sizeof(buf) - 2] = i + '0'; - - cmdadd(&c, CC, CFLAGS); - cmdadd(&c, buf); - if (!Pflag) - cmdadd(&c, "-DGRAB_DO_PCRE=1", "-lpcre2-posix"); - if (debug) - cmdadd(&c, CFLAGS_DEBUG); - else - cmdadd(&c, CFLAGS_RELEASE); - cmdadd(&c, "-o", i == 0 ? "grab" : "git-grab", "src/grab.c"); - cmdprc(c); - } + struct strv cc = {0}; + struct strv cflags = {0}; + + env_or_default(&cc, "CC", CC); + if (debug) + env_or_default(&cflags, "CFLAGS", CFLAGS, CFLAGS_DEBUG); + else + env_or_default(&cflags, "CFLAGS", CFLAGS, CFLAGS_RELEASE); + + for (int i = 0; i < 2; i++) { + char buf[] = "-DGIT_GRAB=X"; + buf[sizeof(buf) - 2] = i + '0'; + + cmdaddv(&c, cc.buf, cc.len); + cmdaddv(&c, cflags.buf, cflags.len); + cmdadd(&c, buf); + if (!Pflag) + cmdadd(&c, "-DGRAB_DO_PCRE=1", "-lpcre2-posix"); + cmdadd(&c, "-o", i == 0 ? "grab" : "git-grab", "src/grab.c"); + cmdprc(c); } + + strvfree(&cc); + strvfree(&cflags); } return EXIT_SUCCESS; -- cgit v1.2.3