I have a makefile that invokes a python script that lives in the same directory as the makefile. It works just fine.
In makefile #1:
auto:
./myscript.py
Now, I have another makefile, in another directory, and wish to call the first makefile from it. In makefile #2:
target:
cd $(DIR); $(MAKE) auto;
The problem is, when the script runs, it runs as though it's in the same dir as makefile #2. On stdout, I see "make[3]: Leaving directory" and the path to #1, just after the make is executed and before the script is run.
On a suggestion I tried modifying makefile #2 to:
target:
( cd $DIR; $MAKE auto; )
but that's interpreted as "cd IR; AKE auto". When I replace the parentheses around DIR and MAKE, I get the same behavior as before.
I've tried modifying the python script by having it assume it's in dir #2 and giving it a path to #1, but the behavior doesn't change.
What's going on, and what should I do?
Update: My comment below messed up code formatting so it's here:
I tried this out and got essentially what you describe. Might it have anything to do with the fact that target auto invokes a "makefile.rules" file?
auto:
@echo this is makefile \#1 making $@ in $(PWD)
FLAG=1 $(MAKE) -f makefile.rules rulestargetA
FLAG=2 $(MAKE) -f makefile.rules rulestargetB
./myscript.py
I omitted that fact for simplicity, but now I wonder.
Update 2: I don't understand why the makefiles aren't causing myscript.py to be run as though it's in the directory in which it resides, but I have been trying to get the script to operate correctly even when invoked from a different directory. It opens a couple of subprocesses, runs an executable in each subprocess, and saves the stdout from each subprocess to files. Python's subprocess.Popen passes in the current working directory, which would be where the script is invoked from, not where it resides, by default. I've added script to pass in the residential directory as cwd into the Popen call. For some reason, though, when I run myscript.py in its own directory it works, but when I invoke it from elsewhere (from the command line) it hangs in proc.communicate(). I should solve this python issue, but I'd still like to know why the external makefile can't invoke this script as from its own directory.