How to call Makefile located in other directory?

24,045

GNU make accepts many options, notably -C to change directory before running, and -f for giving the Makefile to follow.

Combine them appropriately.

Consider using remake to ease debugging (notably with -x) of Makefile related issues. With GNU make version 4 or better, also use make --trace...

You could have your own executable shell script (e.g. in your $HOME/bin/ which would be in your $PATH) which uses both cd and make).

You could consider other build automation tools (ninja perhaps)

Read also P.Miller's paper Recursive Make considered harmful

Share:
24,045
Rookie
Author by

Rookie

Updated on July 05, 2022

Comments

  • Rookie
    Rookie almost 2 years

    I am trying to do this:

    I want to call a make (Makefile exists in some other directory, abc path can be used) from a shell script located in a different directory. How do I do this?

    Since shell scripting does not allow me to cd into the Makefile directory and execute make, how can I write the shell command (by giving path to the Makefile to be executed) to execute make?

  • Rookie
    Rookie over 11 years
    Thank you so much! I shall look at these alternatives!
  • Rookie
    Rookie over 11 years
    How do i call a C program (instead of make) which exists in other directory? I have the .o file in the other directory.
  • Basile Starynkevitch
    Basile Starynkevitch over 11 years
    You should ask another question. You first need to compile your C program into an executable, and then you run that executable, perhaps by giving its full path. Notice that *.o files are not executable binaries.
  • Rookie
    Rookie over 11 years
    Thanks Basile! I was able to do this as well.