Mateusz Piotrowski
Mateusz Piotrowski

Reputation: 9157

How to run "make" from a higher-level directory?

Let's say I'm in a subdirectory sub:

admin@pc ~/folder/subfolder $

I would like to run make on a Makefile from the folder directory.

How can I achieve it when I'm in the subfolder directory?

I had some ideas like:

admin@pc ~/folder/subfolder $ ../make
admin@pc ~/folder/subfolder $ /../make

but none of these works.

Upvotes: 1

Views: 340

Answers (3)

Mateusz Piotrowski
Mateusz Piotrowski

Reputation: 9157

This is the correct answer.

make -C .. -f Makefile

Upvotes: 0

Etan Reisner
Etan Reisner

Reputation: 81032

An alternative, built-in answer, that avoids the extra sub-shell from khachik's answer is the answer given by helpYou in their comment:

To run make from a different directory automatically you want the -C option to make.

‘-C dir’

‘--directory=dir’

Change to directory dir before reading the makefiles. 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 (see Recursive Use of make).

The -f argument simply specifies an alternate makefile to use but runs in the current directory.

The sub-shell solution is a good one and would be the correct one if make did not have a built-in solution for this.

Upvotes: 2

khachik
khachik

Reputation: 28703

And if for some reason you really need to run make in .., you can run

(cd .. && make)

Upvotes: 3

Related Questions