Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

This fixes issue #157 #159

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions eval.cc
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,15 @@ void Evaluator::EvalInclude(const IncludeStmt* stmt) {
ScopedTerminator st(pat);
vector<string>* 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);
Copy link
Collaborator

@Colecf Colecf Nov 23, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems that in GNU make, the include directories are not searched using globs. You can test this with:

root/
   Makefile - include foo*.mk
   dir1
      fooa.mk

make -Idir1 gives "foo*.mk: No such file or directory", but if you change the include to fooa.mk explicitly, it works.

if (files->size() > 0)
break;
}
}

if (stmt->should_exist) {
if (files->empty()) {
Expand Down
5 changes: 5 additions & 0 deletions flags.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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")) {
Expand Down Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions flags.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ struct Flags {
vector<Symbol> targets;
vector<StringPiece> cl_vars;
vector<string> writable;
vector<string> include_dirs;

void Parse(int argc, char** argv);
};
Expand Down
13 changes: 13 additions & 0 deletions testcase/include_dir.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
set -e

mk="$@"

cat <<EOF > 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