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
|
||||
|
||||
OBJ = (strreplace (glob "*.c") ".c" ".o")
|
||||
|
||||
rule test $OBJ [
|
||||
echo " LD" $target
|
||||
shell cc -o $target $sources
|
||||
shell $CC -o $target $sources
|
||||
]
|
||||
|
||||
rule %.o %.c [
|
||||
echo " CC" $target
|
||||
shell cc -c -o $target $source
|
||||
shell $CC -c -o $target $source
|
||||
]
|
||||
|
||||
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"
|
||||
" -h\t\tPrint this message.\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;
|
||||
}
|
||||
|
||||
static bool ignore_env = false;
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
ObState os;
|
||||
ConstCharRange pn = argv[0];
|
||||
|
@ -290,7 +293,7 @@ int main(int argc, char **argv) {
|
|||
ConstCharRange fcont;
|
||||
|
||||
int ac;
|
||||
while ((ac = getopt(argc, argv, "C:f:hj:")) >= 0) {
|
||||
while ((ac = getopt(argc, argv, "C:f:hj:e:E")) >= 0) {
|
||||
switch (ac) {
|
||||
case 'C':
|
||||
if (!ostd::directory_change(optarg))
|
||||
|
@ -307,6 +310,9 @@ int main(int argc, char **argv) {
|
|||
case 'j':
|
||||
os.jobs = ostd::max(1, atoi(optarg));
|
||||
break;
|
||||
case 'E':
|
||||
ignore_env = true;
|
||||
break;
|
||||
default:
|
||||
return ob_print_help(argv[0], ostd::err, 1);
|
||||
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);
|
||||
|
||||
if ((!fcont.empty() && !os.cs.run_bool(fcont)) || !os.cs.run_file(fname))
|
||||
|
|
Loading…
Reference in New Issue