最新消息:20190717 VPS服务器:Vultr新加坡,WordPress主题:大前端D8,统一介绍入口:关于

【已解决】Makefile中读取出文件的内容

makefile crifan 221浏览 0评论

折腾:

【已解决】更新gitbook发布脚本Makefile忽略某些book

期间,Makefile中想要读取出文件的内容

makefile read file contents

Create a variable in a makefile by reading contents of another file – Stack Overflow

试试cat

IGNORE_FILE_CONTENT := `cat $(DEPLOY_IGNORE_FILE)`

$(info IGNORE_FILE_CONTENT=$(IGNORE_FILE_CONTENT))

结果不对:

IGNORE_FILE_CONTENT=`cat /Users/crifan/dev/dev_root/gitbook/gitbook_src_root/deploy_ignore_book_crifan_com.txt`

用shell cat

IGNORE_FILE_CONTENT := $(shell cat $(DEPLOY_IGNORE_FILE))
$(info IGNORE_FILE_CONTENT=$(IGNORE_FILE_CONTENT))

结果:

可以的:

IGNORE_FILE_CONTENT=scientific_network_summary

再去试试:

FILE     := test.txt
variable :=$(file < $(FILE))

用:

IGNORE_FILE_CONTENT := $(file < $(DEPLOY_IGNORE_FILE))
$(info IGNORE_FILE_CONTENT=$(IGNORE_FILE_CONTENT))

结果:

是空的:

IGNORE_FILE_CONTENT=

看了下make版本:

➜  scientific_network_summary git:(master) ✗ make --version
GNU Make 3.81
Copyright (C) 2006  Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.

This program built for i386-apple-darwin11.3.0

是3.81,小于4.0

算了,还是用shell cat吧。

GNU make: File Function

Using the contents of a file as a variable in a Makefile | Otaqui.com

【总结】

先去用:

make --version

确认版本:

(1)make > 4.0

用:

FULL_FILE_NAME     := test.txt
variable :=$(file < $(FULL_FILE_NAME))

(2)make < 4.0

用:

FULL_FILE_NAME     := test.txt
variable :=$(shell cat $(FULL_FILE_NAME))

转载请注明:在路上 » 【已解决】Makefile中读取出文件的内容

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
57 queries in 0.084 seconds, using 18.87MB memory