diff --git a/eval.cc b/eval.cc index 8a71d228..eee14ca1 100644 --- a/eval.cc +++ b/eval.cc @@ -426,6 +426,15 @@ void Evaluator::EvalInclude(const IncludeStmt* stmt) { ScopedTerminator st(pat); vector* files; Glob(pat.data(), &files); + if (files->size() == 0) { + for (auto inc_path : g_flags.include_dirs) { + auto to_check = (inc_path + '/' + pat.data()); + LOG("searching for %s in : %s", pat.data(), inc_path.c_str()); + Glob(to_check.c_str(), &files); + if (files->size() > 0) + break; + } + } if (stmt->should_exist) { if (files->empty()) { diff --git a/flags.cc b/flags.cc index 54828e56..1179bef7 100644 --- a/flags.cc +++ b/flags.cc @@ -70,6 +70,9 @@ void Flags::Parse(int argc, char** argv) { should_propagate = false; } else if (!strcmp(arg, "-c")) { is_syntax_check_only = true; + } else if (!strcmp(arg, "-C")) { + if (chdir(argv[++i]) != 0) + PERROR("chdir failed"); } else if (!strcmp(arg, "-i")) { is_dry_run = true; } else if (!strcmp(arg, "-s")) { @@ -159,6 +162,8 @@ void Flags::Parse(int argc, char** argv) { } else if (ParseCommandLineOptionWithArg("--writable", argv, &i, &writable_str)) { writable.push_back(writable_str); + } else if (!strncmp(arg, "--include-dir=", 14)) { + include_dirs.push_back(string(&arg[14])); } else if (arg[0] == '-') { ERROR("Unknown flag: %s", arg); } else { diff --git a/flags.h b/flags.h index 62865a35..a93d6160 100644 --- a/flags.h +++ b/flags.h @@ -68,6 +68,7 @@ struct Flags { vector targets; vector cl_vars; vector writable; + vector include_dirs; void Parse(int argc, char** argv); }; diff --git a/testcase/include_dir.sh b/testcase/include_dir.sh new file mode 100755 index 00000000..a7491d74 --- /dev/null +++ b/testcase/include_dir.sh @@ -0,0 +1,13 @@ +set -e + +mk="$@" + +cat < Makefile +test: test2 + echo PASS +include myfile.mk +EOF + +mkdir -p test_dir +echo -e "test2:\n\techo \$@" > test_dir/myfile.mk +${mk} --include-dir=test_dir 2> /dev/null