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

Rinita picture Rinita · Sep 17, 2014 · Viewed 15.6k times · Source

I have been struggling for a while with this one. So I wrote a .specs file for my project and everything went fine. The rpm is built, the installation is smooth... but then I got some trouble because now, I have to use a custom global environment variable to set the install path.

This would give a %files section as such :

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

Where Crystal is my project name, and INSTALLPATH is defined within env thanks to the export commandline. Then, when running buildrpm -ba Crystal.specs I have the following error:

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

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

And in my specs file, when i do echo %{_installpath} I get the value I set in the .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 defining a variable with the specs file and I have the same sad result. It looks like as long as my variable/macro is referencing to $INSTALL, then %files won't accept it. But I have to use this env variable!

So that's all I could think about. Anyone got a clue? Any help would be greatly appreciated.

Thanks a lot in advance!

Answer

Etan Reisner picture Etan Reisner · Sep 17, 2014

The %files section does not expand shell variables. You cannot do this that way.

You have a couple options that I can see offhand. You can

  • generate a file with a list of your files (during %install or what-have-you) and then use %files -f files.lst

  • expand $INSTALLPATH at rpm macro definition time with:

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