开发者

makefile : foreach error

I have this in my makefile,

 rcFiles =  .vim .vimrc .gitconfig .hgrc .screenrc .Xresources .dircolors .bashrc .ctags .bash_completion.d
 install:
     @$(foreach f,$(rcFiles), [ -f $(HOME)/$f ] || ln -v -s $(PWD)/$f $(HOME)/ ;  )

if .bashrc exits and I try

 make install

I get

 ln: creating symbolic link `/home/user/.vim': File exists
 ln: creating symbolic link `/home/user/.bash_completion.d': File exi开发者_如何转开发sts

and the process is aborted. why no prevented this problem the conditional?


ln -sfvn source target

The --force flag makes it replace an existing link The --no-dereference avoids creating 'subdirectory' links for links to directory, if the link existed already (useful for the .bash_completion.d and .vim dirs)

rcFiles =  .vim .vimrc .gitconfig .hgrc .screenrc .Xresources .dircolors .bashrc .ctags .bash_completion.d
 install:
     @$(foreach f,$(rcFiles), [ -f $(HOME)/$f ] || ln -v -f -n -s $(PWD)/$f $(HOME)/ ;  )

Alternatively

     @$(foreach f,$(rcFiles), [ -e $(HOME)/$f ] || ln -v -f -n -s $(PWD)/$f $(HOME)/ ;  )

To not only detect files (-f) but also directories. You might want to explicitely check for files and directories [ -f ... || -d ... ].


[ -f $(HOME)/$f ]

is true only if $(HOME)/$f is (expands to) a file. The things you're getting errors on (.vim and .bash_completion.d) are directories. Try this instead:

[ -e "$(HOME)/$f" ]

(The double quotes are not strictly necessary, but will save you grief in the event that $(HOME)/$f were to expand to something with shell metacharacters in it.)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜