From 4f5480a6986eb3d908d558ca01575e5f2e973a59 Mon Sep 17 00:00:00 2001 From: Daniele Lacamera Date: Sun, 6 Oct 2024 12:40:38 +0200 Subject: [PATCH] fix: use CFLAGS environment variable --- src/cjit.c | 7 +++++++ test/cflags.c | 19 +++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100755 test/cflags.c diff --git a/src/cjit.c b/src/cjit.c index 0741691..2fd365b 100644 --- a/src/cjit.c +++ b/src/cjit.c @@ -857,6 +857,7 @@ int main(int argc, char **argv) { // const char *progname = "cjit"; static bool verbose = false; static bool version = false; + static char *extra_cflags = NULL; char tmptemplate[] = "/tmp/CJIT-exec.XXXXXX"; char *tmpdir = NULL; int res = 1; @@ -875,6 +876,12 @@ int main(int argc, char **argv) { _err("Could not initialize tcc"); exit(1); } + // get the extra cflags from the CFLAGS env variable + if(getenv("CFLAGS")) { + extra_cflags = getenv("CFLAGS"); + _err("CFLAGS: %s",extra_cflags); + tcc_set_options(TCC, extra_cflags); + } // initialize the tmpdir for execution #ifndef LIBC_MINGW32 diff --git a/test/cflags.c b/test/cflags.c new file mode 100755 index 0000000..df3a0b8 --- /dev/null +++ b/test/cflags.c @@ -0,0 +1,19 @@ +/* Test CFLAGS env parsing + * run me successfully only with: + * CFLAGS="-DALLOWED=1" cjit test/cflags.c + */ + +#if !defined(ALLOWED) || (ALLOWED != 1) + +#error Running this program is not allowed. Please compile with -DALLOWED=1 + +#else + +#include + +int main(void) +{ + printf("Success.\n"); + return 0; +} +#endif