From a1593ad8e4bdbd5f821cf9006587f2ff97dd965f Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Sat, 24 Feb 2024 15:31:26 -0500 Subject: [PATCH] Make CC an environment variable that's read from --- Makefile | 2 +- nextlang.c | 12 +++++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index f5682ee..e44a17e 100644 --- a/Makefile +++ b/Makefile @@ -40,7 +40,7 @@ tags: ctags *.[ch] **/*.[ch] test: nextlang - for f in tests/*; do echo -e "\x1b[1;4m$$f\x1b[m"; VERBOSE=0 ./nextlang "$$f" || break; done + for f in tests/*; do echo -e "\x1b[1;4m$$f\x1b[m"; VERBOSE=0 CC=tcc ./nextlang "$$f" || break; done clean: rm -f nextlang *.o SipHash/halfsiphash.o builtins/*.o libnext.so diff --git a/nextlang.c b/nextlang.c index 62a3fee..0e52a79 100644 --- a/nextlang.c +++ b/nextlang.c @@ -79,11 +79,13 @@ int main(int argc, char *argv[]) const char *ldflags = "-Wl,-rpath '-Wl,$ORIGIN'"; - // const char *run = heap_strf("tcc -run %s %s %s -", cflags, ldflags, ldlibs); - const char *run = heap_strf("gcc -x c %s %s %s - -o program && ./program", cflags, ldflags, ldlibs); - FILE *cc = popen(run, "w"); - CORD_put(program, cc); - fclose(cc); + const char *cc = getenv("CC"); + if (!cc) cc = "tcc"; + const char *run = streq(cc, "tcc") ? heap_strf("tcc -run %s %s %s -", cflags, ldflags, ldlibs) + : heap_strf("gcc -x c %s %s %s - -o program && ./program", cflags, ldflags, ldlibs); + FILE *runner = popen(run, "w"); + CORD_put(program, runner); + fclose(runner); return 0; }