首页 > 解决方案 > 为什么 make 坚持要求文件是最新的

问题描述

考虑这个 FreeBSD 上 Makefile 的简单示例。

all: hello

hello: hello.o
     gcc -o hello hello.o

hello.o: hello.c
     gcc -c hello.c

clean:
     rm hello.o hello

不管我做什么,改变 hello.c,或者即使我改变 Makefile 中的内容来完成废话,make 说:

`makefile' is up to date.

有什么可以解释那里发生了什么?

标签: makefilegnu-makefreebsd

解决方案


我猜你对makefile有点混乱。请注意(对于 GNU Make):By default, when make looks for the makefile, it tries the following names, in order: GNUmakefile, makefile and Makefile.- 确保您尚未创建 GNUmakefile`

当谈到FreeBSD基础make时,它将是:If no -f makefile makefile option is given, make will try to open 'makefile' then 'Makefile' in order to find the specifications.

我能想象的唯一情况如下:

> cat Makefile
all: hello

hello: hello.o
    cc -o hello hello.o


hello.o: hello.c
    cc -c hello.c

clean:
    rm hello.o hello
> make
cc -c hello.c
cc -o hello hello.o
> ./hello
Hello world!
> make clean
rm hello.o hello
> touch makefile
> echo "makefile:" > .depend
> make
`makefile' is up to date.

推荐阅读