How to get pattern rules to match file names with spaces in Makefile?

巧了我就是萌 提交于 2019-12-04 06:30:34

I don't believe so. The notion of a list of whitespace-separated tokens being passed around as a string is pretty deeply ingrained in make. Those lists are parsed and reparsed. There's a reason why spaces in directory and file names is considered bad practice in the UNIX world.

This is a kludge, but as of today, people still get given paths with spaces in sometimes.

Anyway, making a link instead of directly accessing the directory in the % rule works OK.

# GNU makefile
DIR_WITH_SPACE=/c/Users/me/My\ Code

# *** DOESN'T WORK ***
%.h : $(DIR_WITH_SPACE)/%.h
    cp -v "$<" "$@"

fix:
  ln -s $(DIR_WITH_SPACES) dir_fixed

# Does work :)
%.h : dir_fixed/%.h
    cp -v "$<" "$@"
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!