title: Invoking a python script from a makefile in another directory
body: <p>I have a makefile that invokes a python script that lives in the same directory as the makefile. It works just fine.<br>
  In makefile #1:</p>
  
  <pre><code>auto:
     ./myscript.py
  </code></pre>
  
  <p>Now, I have another makefile, in another directory, and wish to call the first makefile from it. 
  In makefile #2:</p>
  
  <pre><code>target:
      cd $(DIR); $(MAKE) auto;
  </code></pre>
  
  <p>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.</p>
  
  <p>On a suggestion I tried modifying makefile #2 to:</p>
  
  <pre><code>target:
      ( cd $DIR; $MAKE auto; )
  </code></pre>
  
  <p>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.</p>
  
  <p>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.</p>
  
  <p>What's going on, and what should I do?</p>
  
  <p><strong>Update</strong>:
  My comment below messed up code formatting so it's here:</p>
  
  <p>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?</p>
  
  <pre><code>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
  </code></pre>
  
  <p>I omitted that fact for simplicity, but now I wonder.</p>
  
  <p><strong>Update 2</strong>:
  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.</p>