On Sat, Jul 30, 2011 at 09:38:29PM +0200, Thomas Spura wrote:
On Sat, 30 Jul 2011 19:44:41 +0300 Jussi Lehtola wrote:
Hi,
I tried using %global gccver %(gcc -dumpversion) %if %{gccver} >= 4.6.0 foo here %endif
to conditionalize usage of quadruple precision support in a spec file that ships on multiple distros, but the comparison gives the error
parseExpressionBoolean returns -1
Is there a way to check if the gcc version is sufficient with some rpm macro?
Using python for parsing seems to work, but it looks a bit weird ;)
%global true_or_false %(python -c "print('%{gccver}' >= '4.6.0')")
Watch out, this is very dangerous! You are comparing strings, not versions:
print '4.6.2' >= '4.6.12'
True
The better way would be to use distutils.version:
from distutils.version import StrictVersion print StrictVersion('4.6.2') >= StrictVersion('4.6.12')
False
It is possible to write this one one line, but that looks reall ugly:
%global true_or_false %(python -c "from distutils.version import StrictVersion as v; print v(%{gccver}) >= v('4.6.0')")
HTH, Niels
%if %{true_or_false} == "True" echo "true" %else echo "false" %endif
Hope that helps, Thomsa -- devel mailing list devel@lists.fedoraproject.org https://admin.fedoraproject.org/mailman/listinfo/devel