Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to call Makefile located in other directory?

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?

like image 993
Rookie Avatar asked Nov 17 '12 23:11

Rookie


People also ask

How do I run a makefile in another directory?

Use cd ./dir && make && pwd inside Makefile . The && was exactly what I needed to change a directory and execute a command there, then drop back to the main folder to finish the build.

How do I invoke a makefiles in subdirectories?

# Register all subdirectories in the project's root directory. SUBDIRS := $(wildcard */.) # Recurse `make` into each subdirectory. $(SUBDIRS): FORCE $(MAKE) -C $@ # A target without prerequisites and a recipe, and there is no file named `FORCE`.

How do you set a path for make?

You can use the -C flag to specify the path to your makefile. This way you can execute it from a different directory. The -f flag has a different use. With that flag you can execute a makefile with a name other than makefile .


1 Answers

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

like image 148
Basile Starynkevitch Avatar answered Sep 19 '22 03:09

Basile Starynkevitch