How to run make file from any directory?

General solution

(cd /other/dir && make)

will not change your shell's current directory, but will run make with the indicated working directory.

The && will ensure that make doesn't run if there's an error in the cd part of the command (e.g., the directory doesn't exist, or you don't have access to it).

The above approach is useful for all sorts of commands, not just make. For this reason it is worth learning and remembering.

Specific solution

Check the man page for a -C option.

Several Unix commands started out without this option but had it added to them at some time (e.g. with GNU implementation)


You could use

make -C dir

to change to directory dir before reading the pointed makefile. Please notice that option -C is capitalized.

Tags:

Makefile

Make