Makefile中是否可能依赖符号链接?
我的项目中需要几个符号链接.
I need a couple of symlinks in my project.
从src/openlayers
,必须在contrib/openlayers
中将文件夹img
和theme
进行符号链接. contrib/openlayers
文件夹也应该自动创建.
From src/openlayers
, folders img
and theme
have to be symlinked in contrib/openlayers
. The contrib/openlayers
folder should also be created automatically.
.PHONY: run
run: contrib/openlayers/theme contrib/openlayers/img
../bin/pserve development.ini --reload
contrib/openlayers/theme:
ln -s src/openlayers/theme $@
contrib/openlayers/img:
ln -s src/openlayers/img $@
但是此规则尝试每次创建符号链接. (我在ln
上放置了-f
标志,因此每次都会重新创建符号链接.)
But this rule tries to create symlinks every time. (I put -f
flag to ln
, so it re-creates the symlinks every time.)
当然可以. Make将所有内容都视为文件,包括符号链接.它将检查文件是否存在(由于您没有列出任何先决条件,因此没有时间戳比较).对于符号链接,它实际上是在检查链接指向的内容,而不是链接本身.
Sure, this can work. Make treats everything like a file, including a symlink. It will check if the file exists (since you don't list any prerequisites, there is no timestamp comparison). In the case of a symlink it's really checking whatever the link points to, of course, not the link itself.
您没有显示执行此操作时会发生什么,但是根据您的描述,正在发生以下两种情况之一:(a)contrib/openlayers目录不存在,因此ln命令正在生成错误并且未创建因此,make当然会在下次运行该符号链接时尝试重新创建它,或者(b)您的符号链接创建不正确并且没有指向任何东西,这意味着当make尝试查看它是否存在时,它会失败,并且make会尝试重新创建它它.
You don't show what happens when you do this but based on your description one of two things is happening: either (a) the contrib/openlayers directory doesn't exist so the ln command is generating an error and not creating the symlink so of course make will try to recreate it the next time it runs, or (b) your symlink is being created incorrectly and pointing to nothing, which means when make tries to see if it exists it fails and make will try to recreate it.
例如,如果您的src
目录是您的contrib
目录的同级目录,则您的符号链接只是错误的;您会得到:
If, for example, your src
directory is a sibling of your contrib
directory, then your symlinks are just wrong; you'll get:
contrib/openlayers/theme -> src/openlayers/theme
或者,当内核尝试解决它时:
Or, when the kernel tries to resolve it:
contrib/openlayers/src/openlayers/theme
这不是您想要的.我建议您使用这样的东西:
It's highly unlikely that's what you want. I suggest you use something like this:
contrib/openlayers/theme:
mkdir -p contrib/openlayers
ln -s ../../src/openlayers/theme contrib/openlayers/theme
然后验证一旦创建了符号链接,该链接实际上会指向您想要的位置.
Then verify that the symlink, once created, actually points where you want it to go.