有条件地包含RPM中的文件

时间:2013-09-12 23:03:19

标签: rpmbuild rpm-spec

如何根据正在设置的定义.rpm有条件地在_foobar中添加文件? define _foobar将包含构建根目录中的绝对路径。该文件在那里。

根据文档,我希望以下内容有效(请注意:此%files部分中有更多文件,但这是要点):

%files
%if %{_foobar}
%{_foobar}
%endif
然而,

给了我错误:

error: parse error in expression
error: /path/to/specfile:LINENO: parseExpressionBoolean returns -1

其中/path/to/specfile:LINENO.spec文件的路径以及%if行的行号。

2 个答案:

答案 0 :(得分:6)

感谢this blog post我发现了一个适合我的版本:

%files
%if %{?_foobar:1}%{!?_foobar:0}
%{_foobar}
%endif

如果设置了define,那么扩展到%if 1,否则会扩展到%if 0

如果其他人有更好的解决方案,请回答。我当然更愿意接受别人对自己的回答。

答案 1 :(得分:4)

这就是我解决问题的方法

第1步:

   In Build section .. somewhere I wrote :
 %build
  .....
  #check my condition here & if true define some macro
  %define is_valid %( if [ -f /usr/bin/myfile ]; then echo "1" ; else echo "0"; fi )
 #after his normal continuation
 .....
 ...

第2步:在安装部分

  %install
  ......
  #do something in that condition
  if %is_valid
  install -m 0644 <file>
  %endif
  #rest all your stuff
  ................

第3步:在文件部分

   %files
   if %is_valid 
   %{_dir}/<file>
   %endif

那是

有效。

PS:我不能给你完整的代码,因此给出了所有有用的代码片段

相关问题