abb*_*bot 11 code-generation makefile
我正在尝试编写一个Makefile,它应该下载一些来源,当且仅当它们丢失时.
就像是:
hello: hello.c
gcc -o hello hello.c
hello.c:
wget -O hello.c http://example.org/hello.c
Run Code Online (Sandbox Code Playgroud)
但是当然这会导致hello.c每次运行make命令时都会下载.我希望hello.c只有在缺少时才能通过此Makefile下载.这可能与GNU make有关,如果是这样的话怎么办?
Jes*_*erE 13
我的猜测是wget不会更新hello.c上的时间戳,但会保留远程时间戳.这导致make相信hello.c已经过时并尝试再次下载它.尝试
hello.c:
wget ...
touch $@
Run Code Online (Sandbox Code Playgroud)
编辑:wget的-N选项将阻止wget下载任何东西,除非远程文件更新(但它仍然会检查远程文件的时间戳,当然.)
只有在缺失的情况下,Makefile您hello.c才会下载.也许你做错了什么?参见例如:
hello: hello.c
gcc -o hello hello.c
hello.c:
echo 'int main() {}' > hello.c
Run Code Online (Sandbox Code Playgroud)
和:
% make
echo 'int main() {}' > hello.c
gcc -o hello hello.c
% rm hello
% make
gcc -o hello hello.c
% rm hello*
% make
echo 'int main() {}' > hello.c
gcc -o hello hello.c
Run Code Online (Sandbox Code Playgroud)
(该echo命令未第二次执行)
由于Makefile应该可以正常工作,因此您需要检查一些不太可能的情况:
1)检查您是否有任何.PHONY提及源文件的规则.
2)检查源目标名称是否与您正在下载的文件路径匹配.
您还可以尝试运行make -d以查看为什么make认为需要"重新构建"源文件.