为什么 make 坚持文件是最新的

Why does make insist that the files are up to date

考虑 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.

可以解释一下那里发生了什么吗?

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

当涉及到基于 FreeBSDmake 时,它将是: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.