diff options
author | Thomas Voss <mail@thomasvoss.com> | 2024-01-18 10:37:21 +0100 |
---|---|---|
committer | Thomas Voss <mail@thomasvoss.com> | 2024-01-18 10:37:21 +0100 |
commit | 42fe824ea8255869a5b5df8be9703dfabefba11b (patch) | |
tree | 319e2baa2836260c9c621d1980993a4bf706560f | |
parent | ab8c6f957e1e2d9b24acc00413c28fb2020e1516 (diff) |
Support custom CFLAGS and CC
-rw-r--r-- | make.c | 39 |
1 files changed, 23 insertions, 16 deletions
@@ -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; |