如何从上级目录运行"make"?

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

假设我在子目录中 sub:

admin@pc ~/folder/subfolder $

我想 运行 makefolder 目录中的 Makefile

subfolder目录下如何实现?

我有一些想法:

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

但是 none 这些作品。

这是正确答案。

make -C .. -f Makefile

如果出于某种原因你确实需要 运行 make in ..,你可以 运行

(cd .. && make)

另一种内置答案避免了 khachik 答案中的额外子 shell 是 helpYou 在他们的评论中给出的答案:

为了 运行 从不同的目录自动生成你想要 -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).

-f 参数仅指定要使用的备用生成文件,但 运行 在当前目录中。

sub-shell 解决方案是一个很好的解决方案,如果 make 没有内置解决方案,这将是正确的解决方案。