forked from OctaForge/OctaBuild
default val arg for getenv, add extreplace for extension subst
parent
d1bb66976e
commit
adf3c0f068
|
@ -1,11 +1,6 @@
|
||||||
CC = (getenv CC)
|
CC = (getenv CC cc)
|
||||||
if (=s $CC "") [
|
|
||||||
CC = "cc"
|
|
||||||
]
|
|
||||||
|
|
||||||
rule default test
|
OBJ = (extreplace (glob *.c) .c .o)
|
||||||
|
|
||||||
OBJ = (strreplace (glob "*.c") ".c" ".o")
|
|
||||||
|
|
||||||
rule test $OBJ [
|
rule test $OBJ [
|
||||||
echo " LD" $target
|
echo " LD" $target
|
||||||
|
@ -37,3 +32,7 @@ action test_invoke [
|
||||||
depend foo.o foo.h
|
depend foo.o foo.h
|
||||||
depend bar.o bar.h
|
depend bar.o bar.h
|
||||||
depend test.o [foo.h bar.h]
|
depend test.o [foo.h bar.h]
|
||||||
|
|
||||||
|
// default rule
|
||||||
|
|
||||||
|
rule default test
|
23
globs.cc
23
globs.cc
|
@ -159,4 +159,27 @@ void cs_register_globs(cscript::CsState &cs) {
|
||||||
auto fnames = cscript::util::list_explode(lst);
|
auto fnames = cscript::util::list_explode(lst);
|
||||||
cs.result->set_str(ob_expand_globs(fnames).disown());
|
cs.result->set_str(ob_expand_globs(fnames).disown());
|
||||||
});
|
});
|
||||||
|
|
||||||
|
cs.add_command("extreplace", "sss", [](cscript::CsState &cs,
|
||||||
|
const char *lst,
|
||||||
|
const char *oldext,
|
||||||
|
const char *newext) {
|
||||||
|
String ret;
|
||||||
|
if (oldext[0] == '.') ++oldext;
|
||||||
|
if (newext[0] == '.') ++newext;
|
||||||
|
auto fnames = cscript::util::list_explode(lst);
|
||||||
|
for (ConstCharRange it: fnames.iter()) {
|
||||||
|
if (!ret.empty()) ret += ' ';
|
||||||
|
auto dot = ostd::find_last(it, '.');
|
||||||
|
if (!dot.empty() && ((dot + 1) == oldext)) {
|
||||||
|
ret += ostd::slice_until(it, dot);
|
||||||
|
ret += '.';
|
||||||
|
ret += newext;
|
||||||
|
} else {
|
||||||
|
ret += it;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
cs.result->set_str(ret.iter());
|
||||||
|
ret.disown();
|
||||||
|
});
|
||||||
}
|
}
|
10
main.cc
10
main.cc
|
@ -438,16 +438,20 @@ int main(int argc, char **argv) {
|
||||||
((ObState &)cs).rule_add(file, deps, nullptr);
|
((ObState &)cs).rule_add(file, deps, nullptr);
|
||||||
});
|
});
|
||||||
|
|
||||||
os.cs.add_commandn("getenv", "s", [](CsState &cs, TvalRange args) {
|
os.cs.add_commandn("getenv", "ss", [](CsState &cs, TvalRange args) {
|
||||||
if (((ObState &)cs).ignore_env) {
|
if (((ObState &)cs).ignore_env) {
|
||||||
cs.result->set_cstr("");
|
cs.result->set_cstr("");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
auto ret = ob_get_env(args[0].get_str());
|
auto ret = ob_get_env(args[0].get_str());
|
||||||
if (ret.empty())
|
if (ret.empty()) {
|
||||||
cs.result->set_cstr("");
|
if (!args[1].get_str().empty())
|
||||||
|
cs.result->set_str_dup(args[1].get_str());
|
||||||
else
|
else
|
||||||
|
cs.result->set_cstr("");
|
||||||
|
} else {
|
||||||
cs.result->set_str_dup(ret);
|
cs.result->set_str_dup(ret);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
os.cs.add_command("invoke", "s", [](CsState &cs, const char *name) {
|
os.cs.add_command("invoke", "s", [](CsState &cs, const char *name) {
|
||||||
|
|
Loading…
Reference in New Issue