summaryrefslogtreecommitdiffstats
path: root/src/ninja.cc
diff options
context:
space:
mode:
authorPeter Collingbourne <peter@pcc.me.uk>2011-09-22 16:04:03 (GMT)
committerPeter Collingbourne <peter@pcc.me.uk>2011-10-15 19:23:50 (GMT)
commit7cf2bdffe2a95ea5e30e9c3166ef4398add8e6b9 (patch)
tree2b8cd622a0fa858beb0b91da121255a82274272b /src/ninja.cc
parent07c1f9b14b5f7071a5def7d09414ec852a4372ef (diff)
downloadNinja-7cf2bdffe2a95ea5e30e9c3166ef4398add8e6b9.zip
Ninja-7cf2bdffe2a95ea5e30e9c3166ef4398add8e6b9.tar.gz
Ninja-7cf2bdffe2a95ea5e30e9c3166ef4398add8e6b9.tar.bz2
Implement generator rules
Introduce a rule attribute "generator" which, if present, specifies that this rule is used to re-invoke the generator program. Files built using generator rules are treated specially in two ways: firstly, they will not be rebuilt if the command line changes; and secondly, they are not cleaned by default. A command line flag "-g" is introduced for the clean tool, which causes it to remove generator files. Fixes issue #102.
Diffstat (limited to 'src/ninja.cc')
-rw-r--r--src/ninja.cc23
1 files changed, 21 insertions, 2 deletions
diff --git a/src/ninja.cc b/src/ninja.cc
index 5e8d2e4..5b96ca1 100644
--- a/src/ninja.cc
+++ b/src/ninja.cc
@@ -358,6 +358,23 @@ int CmdRules(State* state, int argc, char* argv[]) {
}
int CmdClean(State* state, int argc, char* argv[], const BuildConfig& config) {
+ bool generator = false;
+
+ optind = 1;
+ int opt;
+ while ((opt = getopt(argc, argv, "g")) != -1) {
+ switch (opt) {
+ case 'g':
+ generator = true;
+ break;
+ default:
+ Usage(config);
+ return 1;
+ }
+ }
+ argv += optind;
+ argc -= optind;
+
Cleaner cleaner(state, config);
if (argc >= 1)
{
@@ -381,7 +398,7 @@ int CmdClean(State* state, int argc, char* argv[], const BuildConfig& config) {
}
}
else {
- return cleaner.CleanAll();
+ return cleaner.CleanAll(generator);
}
}
@@ -479,8 +496,10 @@ reload:
return CmdTargets(&state, argc, argv);
if (tool == "rules")
return CmdRules(&state, argc, argv);
+ // The clean tool uses getopt, and expects argv[0] to contain the name of
+ // the tool, i.e. "clean".
if (tool == "clean")
- return CmdClean(&state, argc, argv, config);
+ return CmdClean(&state, argc+1, argv-1, config);
Error("unknown tool '%s'", tool.c_str());
}