forked from OctaForge/OctaBuild
add some environment functionality
parent
88c2656862
commit
b97b71d281
|
@ -1,15 +1,24 @@
|
||||||
|
CC = (getenv CC)
|
||||||
|
|
||||||
|
if (=s $CC "") [
|
||||||
|
echo "no compiler found, using cc"
|
||||||
|
CC = "cc"
|
||||||
|
] [
|
||||||
|
echo "using compiler:" $CC
|
||||||
|
]
|
||||||
|
|
||||||
rule all test
|
rule all test
|
||||||
|
|
||||||
OBJ = (strreplace (glob "*.c") ".c" ".o")
|
OBJ = (strreplace (glob "*.c") ".c" ".o")
|
||||||
|
|
||||||
rule test $OBJ [
|
rule test $OBJ [
|
||||||
echo " LD" $target
|
echo " LD" $target
|
||||||
shell cc -o $target $sources
|
shell $CC -o $target $sources
|
||||||
]
|
]
|
||||||
|
|
||||||
rule %.o %.c [
|
rule %.o %.c [
|
||||||
echo " CC" $target
|
echo " CC" $target
|
||||||
shell cc -c -o $target $source
|
shell $CC -c -o $target $source
|
||||||
]
|
]
|
||||||
|
|
||||||
rule clean [] [
|
rule clean [] [
|
||||||
|
|
23
main.cc
23
main.cc
|
@ -266,10 +266,13 @@ static int ob_print_help(ConstCharRange a0, ostd::Stream &os, int v) {
|
||||||
" -f FILE\tSpecify the file to run (default: cubefile).\n"
|
" -f FILE\tSpecify the file to run (default: cubefile).\n"
|
||||||
" -h\t\tPrint this message.\n"
|
" -h\t\tPrint this message.\n"
|
||||||
" -j N\t\tSpecify the number of jobs to use (default: 1).\n"
|
" -j N\t\tSpecify the number of jobs to use (default: 1).\n"
|
||||||
" -e STR\t\tEvaluate a string instead of a file.");
|
" -e STR\t\tEvaluate a string instead of a file.\n"
|
||||||
|
" -E\t\tIgnore environment variables.");
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool ignore_env = false;
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
ObState os;
|
ObState os;
|
||||||
ConstCharRange pn = argv[0];
|
ConstCharRange pn = argv[0];
|
||||||
|
@ -290,7 +293,7 @@ int main(int argc, char **argv) {
|
||||||
ConstCharRange fcont;
|
ConstCharRange fcont;
|
||||||
|
|
||||||
int ac;
|
int ac;
|
||||||
while ((ac = getopt(argc, argv, "C:f:hj:")) >= 0) {
|
while ((ac = getopt(argc, argv, "C:f:hj:e:E")) >= 0) {
|
||||||
switch (ac) {
|
switch (ac) {
|
||||||
case 'C':
|
case 'C':
|
||||||
if (!ostd::directory_change(optarg))
|
if (!ostd::directory_change(optarg))
|
||||||
|
@ -307,6 +310,9 @@ int main(int argc, char **argv) {
|
||||||
case 'j':
|
case 'j':
|
||||||
os.jobs = ostd::max(1, atoi(optarg));
|
os.jobs = ostd::max(1, atoi(optarg));
|
||||||
break;
|
break;
|
||||||
|
case 'E':
|
||||||
|
ignore_env = true;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
return ob_print_help(argv[0], ostd::err, 1);
|
return ob_print_help(argv[0], ostd::err, 1);
|
||||||
break;
|
break;
|
||||||
|
@ -346,6 +352,19 @@ int main(int argc, char **argv) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
os.cs.add_command("getenv", "s", [](cscript::CsState &cs, const char *en) {
|
||||||
|
if (ignore_env) {
|
||||||
|
cs.result->set_cstr("");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const char *ret = getenv(en);
|
||||||
|
if (!ret || !ret[0]) {
|
||||||
|
cs.result->set_cstr("");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
cs.result->set_str_dup(ret);
|
||||||
|
});
|
||||||
|
|
||||||
cs_register_globs(os.cs);
|
cs_register_globs(os.cs);
|
||||||
|
|
||||||
if ((!fcont.empty() && !os.cs.run_bool(fcont)) || !os.cs.run_file(fname))
|
if ((!fcont.empty() && !os.cs.run_bool(fcont)) || !os.cs.run_file(fname))
|
||||||
|
|
Loading…
Reference in New Issue