Conditionally include file in an RPM

非 Y 不嫁゛ 提交于 2019-12-06 04:05:46

This is how I solved my problem

step 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
 .....
 ...

Step 2: in install section

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

Step 3:in files section

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

That's it

It works.

PS : I cannot give you full code hence giving all useful snippet

Thanks to this blog post I found a version that works for me:

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

What this does is to expand to %if 1 if the define is set and %if 0 otherwise.

If someone else has a better solution, please answer. I'll certainly prefer accepting someone else's answer over my own.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!