Rpm & rpmbuild - using a global environment variable in the% files section

I struggled for a while with this. So I wrote a .specs file for my project, and everything went well. Rpm is built, the installation is smooth ... but then I had problems, because now I have to use a custom global environment variable to set the installation path.

This will give the% files section as such:

%files
%defattr(-,root,root)
$INSTALLPATH/Crystal/bin/Crystal.jar

Where Crystal is my project name, and INSTALLPATH is defined in env thanks to the export command line. Then when I run buildrpm -ba Crystal.specs I have the following error:

error: File must begin with "/" : $INSTALLPATH/Crystal/bin/Crystal.jar

I tried to define the macro inside the .rpmmacros file as such:% _installpath $ INSTALLPATH

And in my specification file, when I do echo% {_ installpath} I get the value set in .rpmmacros. But if I use it in% files:

%files
%defattr(-,root,root)
%{_installpath}/Crystal/bin/Crystal.jar

I get the same error again!

error: File must begin with "/" : $INSTALLPATH/Crystal/bin/Crystal.jar

I also tried to define a variable with the specs file, and I have the same sad result. It seems like as long as my variable / macro references $ INSTALL, then% of the files will not accept it. But I have to use this env variable!

So, all that I could think of. Anyone got it? Any help would be greatly appreciated.

Many thanks!

+6
source share
1 answer

The section %filesdoes not extend shell variables. You cannot do that.

You have a couple of options that I can see idle. You can

  • ( %install what-have-you), %files -f files.lst

  • $INSTALLPATH rpm

    # For RPM >= 4.7.0
    %_installpath %{getenv:INSTALLPATH}
    # For RPM < 4.7.0
    %_installpath %{lua:print(os.getenv("INSTALLPATH"))}
    
+6

All Articles