How do I express the following logic in a Makefile?
if $(XORG_VERSION) > "7.7"
<do some thing>
fi
Conditional Parts of Makefiles only provides ifeq or ifneq.
I use the sort
function to compare values lexicographically. The idea is, sort the list of two values, $(XORG_VERSION)
and 7.7
, then take the first value - if it's 7.7
then the version is the same or greater.
ifeq "7.7" "$(word 1, $(sort 7.7 $(XORG_VERSION)))"
<do some thing>
endif
Adjust 7.7
to 7.8
if you need the strict greater-than condition.
This approach improves portability by avoiding shell scripts and concomitant assumptions about the capabilities of the available OS shell. However, it fails if the lexicographic ordering is not equivalent to the numerical ordering, for example when comparing 7.7
and 7.11
.
You're not restricted to using the make
conditional statements - each command is a shell command which may be as complex as you need (including a shell conditional statement):
Consider the following makefile
:
dummy:
if [ ${xyz} -gt 8 ] ; then \
echo urk!! ${xyz} ;\
fi
When you use xyz=7 make --silent
, there is no output. When you use xyz=9 make --silent
, it outputs urk!! 9
as expected.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With