Trim leading ./ when kati includes a file
diff --git a/eval.cc b/eval.cc
index 1f0af87..9d984da 100644
--- a/eval.cc
+++ b/eval.cc
@@ -224,7 +224,7 @@
}
Var* var_list = LookupVar("MAKEFILE_LIST");
- var_list->AppendVar(this, NewLiteral(Intern(fname)));
+ var_list->AppendVar(this, NewLiteral(Intern(TrimLeadingCurdir(fname))));
for (AST* ast : mk->asts()) {
LOG("%s", ast->DebugString().c_str());
ast->Eval(this);
diff --git a/eval.go b/eval.go
index cb2ddfe..736c7e1 100644
--- a/eval.go
+++ b/eval.go
@@ -450,6 +450,7 @@
}
for _, fn := range files {
+ fn = trimLeadingCurdir(fn)
if IgnoreOptionalInclude != "" && ast.op == "-include" && matchPattern(fn, IgnoreOptionalInclude) {
continue
}
diff --git a/rule.cc b/rule.cc
index 88f713c..7c882a3 100644
--- a/rule.cc
+++ b/rule.cc
@@ -24,15 +24,6 @@
namespace {
-// Strip leading sequences of './' from file names, so that ./file
-// and file are considered to be the same file.
-// From http://www.gnu.org/software/make/manual/make.html#Features
-StringPiece TrimLeadingCurdir(StringPiece s) {
- while (s.substr(0, 2) == "./")
- s = s.substr(2);
- return s;
-}
-
static void ParseInputs(Rule* r, StringPiece s) {
bool is_order_only = false;
for (StringPiece input : WordScanner(s)) {
diff --git a/strutil.cc b/strutil.cc
index 1c8c068..80b5de9 100644
--- a/strutil.cc
+++ b/strutil.cc
@@ -383,3 +383,9 @@
}
return e;
}
+
+StringPiece TrimLeadingCurdir(StringPiece s) {
+ while (s.substr(0, 2) == "./")
+ s = s.substr(2);
+ return s;
+}
diff --git a/strutil.h b/strutil.h
index 8ab2667..368ee23 100644
--- a/strutil.h
+++ b/strutil.h
@@ -127,4 +127,9 @@
size_t FindEndOfLine(StringPiece s, size_t e, size_t* lf_cnt);
+// Strip leading sequences of './' from file names, so that ./file
+// and file are considered to be the same file.
+// From http://www.gnu.org/software/make/manual/make.html#Features
+StringPiece TrimLeadingCurdir(StringPiece s);
+
#endif // STRUTIL_H_
diff --git a/testcase/makefile_list.mk b/testcase/makefile_list.mk
index fbb7cb0..e529c8f 100644
--- a/testcase/makefile_list.mk
+++ b/testcase/makefile_list.mk
@@ -16,4 +16,4 @@
-include foo.mk bar.mk
-include bar.mk
-include foo.mk
--include foo.mk
+-include ./././foo.mk