RPM 规范文件 - 是否可以动态填充规范文件变量 [英] RPM spec file - Is it possible to dynamically populate a spec file variable
问题描述
我有一个规范文件.我需要定义一个规范变量,该变量从系统上的一行文件中获取其值.
I have a spec file. I need to %define a spec variable that gets its value from a one line file on the system.
例如
%define path `cat /home/user/path_file`
在 path_file 中是一行
and in path_file is one line
/var/www/html/hosts
这部分有效.我说从 RPM BUILD 输出开始,有时 ${path}
的值实际上是我的命令 cat/home/user/path_file
有时值是path_file (/var/www/html/hosts) 应该是什么?
This partially works. I say that begins in the RPM BUILD output sometimes the value of ${path}
is literally my command cat /home/user/path_file
and sometimes the value is the line in the path_file (/var/www/html/hosts) as it should be?
推荐答案
您可以使用规范文件顶部的 %(cmd)
定义 rpmbuild 变量.请注意,命令在括号中,而不是大括号中.一个例子:
You can define rpmbuild variables with %(cmd)
at the top of the spec file. Notice the command is in parenthesis, not curly brackets. An example:
%define whoami %(whoami)
在规范文件的其他地方,例如脚本或构建/安装部分,像这样在大括号中正常使用变量:
And elsewhere in the spec file, such as a script or the build/install sections, use the variable as normal in the curly brackets like this:
echo "The user that built this is %{whoami}"
cmd
可以是任何东西,包括您的 cat 命令.小心 - 当另一个用户重建规范文件时,它可能找不到该文件.所以最好像这样使用 %{sourcedir} 宏:
The cmd
can be anything, including your cat command. Be careful - when another user rebuilds the spec file it may not find the file. So it'll be preferable to use the %{sourcedir} macro like this:
%define path %(cat %{sourcedir}/path_file)
并确保 path_file
在源目录中并作为源包含在规范文件中.
And make sure that path_file
is in the source directory and included as a source in the spec file.
这篇关于RPM 规范文件 - 是否可以动态填充规范文件变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!