Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 972029
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T03:03:29+00:00 2026-05-16T03:03:29+00:00

I have a makefile that invokes a python script that lives in the same

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T03:03:29+00:00Added an answer on May 16, 2026 at 3:03 am

    This is very strange. First the easy part:

    target:
      ( cd $DIR; $MAKE auto; )
    

    The parentheses do nothing here, and Make interprets $DIR as $D followed by the letter ‘I’ and the letter ‘R’. Since the variable D is not defined, this works out to ‘IR’. Same for $MAKE.

    Now for the real problem. The makefiles as written should work. And you say it leaves directory #1 before the script runs? All I can suggest is that you try a simpler problem first. Put this in Makefile #1:

    auto:
      @echo this is makefile \#1 making $@ in $(PWD)
    

    And then use Makefile #2 to make target. This should produce

    make[1]: Entering directory 'path-to-one'
    this is makefile #1 making auto in path-to-one
    make[1]: Leaving directory 'path-to-one'
    

    If this is what it says, then there’s something screwy about your script. If it produces nothing like this, you’re failing to reach Makefile #1 at all, and maybe your DIR isn’t right. If it works but says it’s in directory #2, then my best guess is that you have another rule referring to Makefile #1. Try the experiment and let us know.

    EDIT:
    Well, that probably explains how it can leave directory #1 before the script runs. I suggest you comment out those lines and see if the problem is still there. Now about this script: what does it do and how do you know where it’s running?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a makefile that looks like: default: lua blah.lua Now, in Vim, I
I have a working makefile that builds with mingw32. Now i renamed that makefile
I have a makefile that works transparently for Linux ( x86_64 ) and OS
I have a slew of makefile targets that do the same thing: ${SOME_FILE}: ${FILES}
I have a gnu Makefile that collects version information through environment variables. Now, I
I have a Makefile that looks like this CXX = g++ -O2 -Wall all:
I have a Makefile that looks something like this: sometarget: command_one # calls fork()
I have a big makefile that I have configured with several phony targets. One
I have a makefile project that builds and links a DLL, using the command-line
I have a gnu makefile template that has served me well, but when I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.