将文件中的值读入变量

时间:2012-08-29 14:22:31

标签: bash makefile

我在Windows中使用make,我想从文件中读取几个值,以用作makefile中的变量。

我有一个包含以下行的文件:

/* A comment */
#define SOME_STRING "ABCDE"

/* A comment         "     " */
#define BLANK_STRING "     "

/* A comment */
#define SOME_VERSION 01.01a01

我想在makefile中最终得到两个变量。一个设置为 ABCDE ,另一个设置为 01.01a01

这也可以使用makefile中调用的一些bash命令来完成。我是makefiles,bash和stackoverflow的新手,所以请耐心等待我!

由于

斯蒂芬

2 个答案:

答案 0 :(得分:1)

all:
  echo $(SOME_VERSION)

imports: input_file
  sed -n 's/^#define \([^ ]*\) \("*[^"]*"*\)/\1=\2/p' input_file > imports

include imports

答案 1 :(得分:0)

VARS := $(shell  sed -n "s/^\#define .* //p" filename)

A = $(word 1, $(VARS))
B = $(word 2, $(VARS))