【问题标题】:Conditionally include file in an RPM有条件地在 RPM 中包含文件
【发布时间】:2013-09-17 12:19:36
【问题描述】:

如何根据是否设置定义 _foobar 有条件地将文件包含在 .rpm 中?定义 _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 所在行的行号。

【问题讨论】:

    标签: rpmbuild rpm-spec


    【解决方案1】:

    感谢this blog post 我找到了适合我的版本:

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

    如果设置了定义,则扩展为%if 1,否则扩展为%if 0

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

    【讨论】:

    【解决方案2】:

    这就是我解决问题的方法

    第 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 : 我不能给你完整的代码,所以给你所有有用的 sn-p

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-12-29
      • 1970-01-01
      • 2016-04-05
      • 1970-01-01
      • 2019-09-19
      • 2012-03-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多