Makefiles: reading a file with 'pure make syntaxis' (no shell commands)

时光毁灭记忆、已成空白 提交于 2019-12-22 11:27:29

问题


I want to read the content of a text file and assign it to a variable in my makefile. I read the make manual ch 8.6: The file function, and wrote this simple snippet in my makefile:

# Snippet from my makefile

my_var = $(file < C:/full/path/to/my_file.txt)

all:
    @echo $(my_var)

I get the following error:

*** Invalid file operation: < C:/full/path/to/my_file.txt.  Stop.

I deliberately choose for the $(file ..) instead of the $(shell ..) function to read out the file. That's because my makefile should be as platform independent as possible. The $(file ..) function is pure makefile-syntax, whereas the $(shell ..) function contains shell-syntax.

What am I doing wrong?


回答1:


You'll need to upgrade to at least make 4.2 if you want to read files with $(file <).



来源:https://stackoverflow.com/questions/39080029/makefiles-reading-a-file-with-pure-make-syntaxis-no-shell-commands

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!