Skip to content

Commit

Permalink
fix: use CFLAGS environment variable
Browse files Browse the repository at this point in the history
  • Loading branch information
danielinux committed Oct 6, 2024
1 parent 3887d98 commit 6ea4f52
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/cjit.c
Original file line number Diff line number Diff line change
Expand Up @@ -858,6 +858,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;
char *code = NULL;
Expand All @@ -877,6 +878,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
Expand Down
19 changes: 19 additions & 0 deletions test/cflags.c
Original file line number Diff line number Diff line change
@@ -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 <stdio.h>

int main(void)
{
printf("Success.\n");
return 0;
}
#endif

0 comments on commit 6ea4f52

Please sign in to comment.