SetMaxDop value for MS SQL database using PowerShell
March 26, 2018
Tag the AWS EBS volume with disk drive letter or label
March 26, 2018

How to run `make` command from another directory

Sometimes while doing some automation we need to run the make command from another directory i.e. from where the Makefile is not present.

So what option make command provides?


-C dir, –directory=dir Change to directory dir before reading the makefiles or doing anything else. If multiple -C options are specified, each is interpreted relative to the previous one: -C / -C etc. is equivalent to -C /etc. This is typically used with recursive invocations of make.


So, for Example:

make -C /path/to/dir

(make sure ‘C’ is in upper case)

Also to run `make` recursively as explaine on gnu site here

Recursive use of make means using make as a command in a makefile. This technique is useful when you want separate makefiles for various subsystems that compose a larger system. For example, suppose you have a sub-directory subdir which has its own makefile, and you would like the containing directory’s makefile to run make on the sub-directory.

You can do it by writing this:

$(MAKE) -C subdir