在生成文件中使用eval [英] Using eval in make file

查看:217
本文介绍了在生成文件中使用eval的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我运行一个buildroot make,并在此构建过程中创建了一个文本文件.发生这种情况后,将运行另一个make作为构建的一部分.我想将生成的文件的内容读入一个变量并使用它们.这不起作用,因为在我的buildroot开始时,它会认为该文件不存在,因此,即使它是在运行代码之前生成的,make仍已确定该文件不存在.

I run a buildroot make and during this build process a text file is created. After this happens another make as part of the build is run. I want to read the contents of the generated file into a variable and use them. This doesn't work as at the start of my buildroot make it sees the file as not existing, so even though it is generated before the code is run make has already decided it doesn't exist.

读取的文件格式:

  str1 str2 1.1.0_nightlybuild (1389:1497M@trunk)

我正在尝试使用eval(这应该在运行时检查文件内容).但是问题仍然存在,创建文件后似乎无法读取文件.似乎make可能正在扩展变量,因此eval不起作用.

I am trying to use eval (this should check the file contents at the time of running). However the problem persists, I do not seem to be able to read from the file after it is created. It seems make might be expanding the variable and so eval does not work.

没有从文件内容中设置任何变量.我检查并正确生成了文件,因此,如果我再次运行make,则在文件已生成后,一切正常.评估不是正确的方法吗?

None of the variables are being set from the file contents. I check and the file has been generated correctly so if I run the make again, when the file has already been generated, everything works fine. Is eval not the correct way to do this?

因此该文件在make开头不存在,存在并随后运行以下代码:

So the file does not exist at the start of make, comes into existence and then this code is run:

define EXAMPLE
    $(eval s := $(shell cat output/target/version.txt)) 
    $(eval FILENAME_BIN=$(word 1, $(s)).$(word 2, $(s)).$(word 3, $(s)).bin)
    $(eval FILENAME_JFFS2=$(word 1, $(s)).$(word 2, $(s)).$(word 3, $(s)).jffs2)
    mv $(BINARIES_DIR)/$(BOOTIMAGE) $(BINARIES_DIR)/$(FILENAME_BIN)
    mv $(BINARIES_DIR)/$(JFFS2IMAGE) $(BINARIES_DIR)/$(FILENAME_JFFS2)
endef

它不起作用,将生成文件,随后的构建将起作用,只是该过程开始时第一个不存在该文件的文件.由于没有填充从文件读取的变量,因此第一次将文件简称为...bin...jffs2.工作时,这些文件称为str1.str2.1.1.0_nightlybuild.bin str1.str2. 1.1.0_nightlybuild.jffs2

It does not work, the file is generated and subsequent builds will work, just not the first one where the file does not exist at the start of the process. The first time the files are simply called ...bin and ...jffs2 as the variables read from the file are not populated. When it works the files are called str1.str2.1.1.0_nightlybuild.bin str1.str2. 1.1.0_nightlybuild.jffs2

这是真实的用例生成文件 http://pastebin.com/6GdKcUg6 TEST_DEFAULT_RENAME是我所在的位置尝试读取文件时,我正在使用buildroot(所以有很多make文件),当我在buildroot进程中按下make时,会沿版本创建txt,然后此代码尝试读取此文件,但它不起作用除非在我在buildroot目录中输入make之前就存在version.text.如您所见,我通过cat在其他地方使用version.txt,但是效果很好.

Here is the real use case makefile http://pastebin.com/6GdKcUg6 TEST_DEFAULT_RENAME is where I am trying to read in a file, I am using buildroot (so a lot of make files), when I hit make during the buildroot process version.txt is created along the way, this code then tries to read this file but it does not work unless version.text is there before I enter the make in the buildroot directory. As you can see I use version.txt elsewhere via cat but that works fine.

推荐答案

我运行一个buildroot make,并在此构建过程中创建了一个文本文件.发生这种情况后,将运行另一个make作为构建的一部分.我想将生成的文件的内容读入一个变量并使用它们.这不起作用,因为在我的buildroot开始时,它会认为该文件不存在,因此,即使它是在运行代码之前生成的,make仍已确定该文件不存在.

I run a buildroot make and during this build process a text file is created. After this happens another make as part of the build is run. I want to read the contents of the generated file into a variable and use them. This doesn't work as at the start of my buildroot make it sees the file as not existing, so even though it is generated before the code is run make has already decided it doesn't exist.

发生这种情况是因为另一个make 不知道 buildroot make 会产生什么,即缺少依赖项信息(这就是为什么递归make有问题).换句话说,另一个make 不知道 buildroot make 会生成version.txt.

This happens because another make does not know what buildroot make produces, i.e. the dependency information is missing (this is why recursive make is problematic). In other words, another make does not know that buildroot make produces version.txt.

想到一些解决方案:

  1. 具有一个shell脚本,该脚本可以依次调用makefile,例如make -f buildroot.mk && make -f another.mk.这样another.mk会观察buildroot.mk产生的所有文件.

  1. Have a shell script that invokes the makefiles in sequence, e.g. make -f buildroot.mk && make -f another.mk. This way another.mk observes all files produced by buildroot.mk.

another.mk调用buildroot.mk > 第一阶段 ,然后评估目标和依赖项.例如:

Invoke buildroot.mk from another.mk during the first phase, before the targets and dependencies are evaluated. E.g.:

# At the top level, not in a rule.
$(shell ${MAKE} -f buildroot.mk)
# now version.txt is available
version := $(shell cat version.txt)

  • buildroot.mk完成后,another.mk会自动重新启动.做1和2的更复杂的方法:

  • Have another.mk restart itself when buildroot.mk has completed. A more complicated way of doing 1 and 2:

    $ cat buildroot.mk 
    version.txt :
        echo "str1 str2 1.1.0_nightlybuild (1389:1497M@trunk)" > $@
    
    $ cat another.mk
    all :
        @echo "$@ has completed."
    
    ifdef MAKE_RESTARTS
    s := $(shell cat version.txt))
    FILENAME_BIN := $(word 1, $(s)).$(word 2, $(s)).$(word 3, $(s)).bin
    FILENAME_JFFS2 := $(word 1, $(s)).$(word 2, $(s)).$(word 3, $(s)).jffs2
    $(info ${FILENAME_BIN})
    $(info ${FILENAME_JFFS2})
    else
    another.mk : version.txt
        touch $@
    endif
    
    version.txt :
        $(MAKE) -f buildroot.mk
    
    .PHONY: all version.txt
    
    $ make -f another.mk 
    make -f buildroot.mk
    make[1]: Entering directory '~/tmp'
    echo "str1 str2 1.1.0_nightlybuild (1389:1497M@trunk)" > version.txt
    make[1]: Leaving directory '~/tmp'
    touch another.mk
    str1.str2.1.1.0_nightlybuild.bin
    str1.str2.1.1.0_nightlybuild.jffs2
    all has completed.
    
    $ make -f another.mk 
    make -f buildroot.mk
    make[1]: Entering directory '~/tmp'
    make[1]: 'version.txt' is up to date.
    make[1]: Leaving directory '~/tmp'
    touch another.mk
    str1.str2.1.1.0_nightlybuild.bin
    str1.str2.1.1.0_nightlybuild.jffs2
    all has completed.
    

  • 这篇关于在生成文件中使用eval的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆