Skip to content

Commit

Permalink
Add command line options to override CC/CXX
Browse files Browse the repository at this point in the history
  • Loading branch information
SanderMertens committed Apr 20, 2024
1 parent 652aefa commit 0479eb1
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
4 changes: 2 additions & 2 deletions drivers/lang/c/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ static
const char *cc(
bake_src_lang lang)
{
const char *default_cxx = NULL, *cxx = ut_getenv("CXX");
const char *default_cc = NULL, *cc = ut_getenv("CC");
const char *cxx = ut_getenv("CXX");
const char *cc = ut_getenv("CC");

if (cc && !strlen(cc)) cc = NULL;
if (cxx && !strlen(cxx)) cxx = NULL;
Expand Down
22 changes: 21 additions & 1 deletion src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ bool load_bundles = false;
/* Compile to target other than current */
const char *target = NULL;

/* Override CC/CXX */
const char *env_cc = NULL;
const char *env_cxx = NULL;

/* Override configuration */
bool strict = false;
bool optimize = false;
Expand Down Expand Up @@ -112,6 +116,8 @@ void bake_usage(void)
printf(" --cfg <configuration> Specify configuration id\n");
printf(" --env <environment> Specify environment id\n");
printf(" --target <target> Specify compilation target\n");
printf(" --cc <compiler> Override CC environment variable\n");
printf(" --cxx <compiler> Override CXX environment variable\n");
printf(" --strict Manually enable strict compiler options\n");
printf(" --optimize Manually enable compiler optimizations\n");
printf(" --loop-test Manually enable vectorization analysis\n");
Expand Down Expand Up @@ -306,6 +312,8 @@ int bake_parse_args(
ARG(0, "env", env = argv[i + 1]; i ++);
ARG(0, "cfg", cfg = argv[i + 1]; i ++);
ARG(0, "target", target = argv[i + 1]; i ++);
ARG(0, "cc", env_cc = argv[i + 1]; i ++);
ARG(0, "cxx", env_cxx = argv[i + 1]; i ++);
ARG(0, "strict", strict = true );
ARG(0, "profile-build", profile_build = true );
ARG(0, "optimize", optimize = true );
Expand Down Expand Up @@ -1339,7 +1347,6 @@ void bake_message(
}

int main(int argc, const char *argv[]) {

if (ut_getenv("BAKE_ENVIRONMENT")) {
env = ut_getenv("BAKE_ENVIRONMENT");
}
Expand Down Expand Up @@ -1378,6 +1385,19 @@ int main(int argc, const char *argv[]) {
ut_log_pop();
}

if (env_cc) {
ut_setenv("CC", env_cc);
if (!strcmp(env_cc, "gcc")) {
ut_setenv("CXX", "g++");
} else if (!strcmp(env_cc, "clang")) {
ut_setenv("CXX", "clang++");
}
}

if (env_cxx) {
ut_setenv("CXX", env_cc);
}

ut_log_push("init");

/* Initialize package loader for default home, arch, os and config */
Expand Down

0 comments on commit 0479eb1

Please sign in to comment.