1
dnl (from http://autoconf-archive.cryp.to/ax_compare_version.m4 )
3
dnl @synopsis AX_COMPARE_VERSION(VERSION_A, OP, VERSION_B, [ACTION-IF-TRUE], [ACTION-IF-FALSE])
5
dnl This macro compares two version strings. It is used heavily in the
6
dnl macro _AX_PATH_BDB for library checking. Due to the various number
7
dnl of minor-version numbers that can exist, and the fact that string
8
dnl comparisons are not compatible with numeric comparisons, this is
9
dnl not necessarily trivial to do in a autoconf script. This macro
10
dnl makes doing these comparisons easy.
12
dnl The six basic comparisons are available, as well as checking
13
dnl equality limited to a certain number of minor-version levels.
15
dnl The operator OP determines what type of comparison to do, and can
18
dnl eq - equal (test A == B)
19
dnl ne - not equal (test A != B)
20
dnl le - less than or equal (test A <= B)
21
dnl ge - greater than or equal (test A >= B)
22
dnl lt - less than (test A < B)
23
dnl gt - greater than (test A > B)
25
dnl Additionally, the eq and ne operator can have a number after it to
26
dnl limit the test to that number of minor versions.
28
dnl eq0 - equal up to the length of the shorter version
29
dnl ne0 - not equal up to the length of the shorter version
30
dnl eqN - equal up to N sub-version levels
31
dnl neN - not equal up to N sub-version levels
33
dnl When the condition is true, shell commands ACTION-IF-TRUE are run,
34
dnl otherwise shell commands ACTION-IF-FALSE are run. The environment
35
dnl variable 'ax_compare_version' is always set to either 'true' or
40
dnl AX_COMPARE_VERSION([3.15.7],[lt],[3.15.8])
41
dnl AX_COMPARE_VERSION([3.15],[lt],[3.15.8])
43
dnl would both be true.
45
dnl AX_COMPARE_VERSION([3.15.7],[eq],[3.15.8])
46
dnl AX_COMPARE_VERSION([3.15],[gt],[3.15.8])
48
dnl would both be false.
50
dnl AX_COMPARE_VERSION([3.15.7],[eq2],[3.15.8])
52
dnl would be true because it is only comparing two minor versions.
54
dnl AX_COMPARE_VERSION([3.15.7],[eq0],[3.15])
56
dnl would be true because it is only comparing the lesser number of
57
dnl minor versions of the two values.
59
dnl Note: The characters that separate the version numbers do not
60
dnl matter. An empty string is the same as version 0. OP is evaluated
61
dnl by autoconf, not configure, so must be a string, not a variable.
63
dnl The author would like to acknowledge Guido Draheim whose advice
64
dnl about the m4_case and m4_ifvaln functions make this macro only
65
dnl include the portions necessary to perform the specific comparison
66
dnl specified by the OP argument in the final configure script.
69
dnl @author Tim Toolan <toolan@ele.uri.edu>
70
dnl @version 2004-03-01
71
dnl @license GPLWithACException
73
dnl #########################################################################
74
AC_DEFUN([AX_COMPARE_VERSION], [
75
# Used to indicate true or false condition
76
ax_compare_version=false
78
# Convert the two version strings to be compared into a format that
79
# allows a simple string comparison. The end result is that a version
80
# string of the form 1.12.5-r617 will be converted to the form
81
# 0001001200050617. In other words, each number is zero padded to four
82
# digits, and non digits are removed.
83
AS_VAR_PUSHDEF([A],[ax_compare_version_A])
84
A=`echo "$1" | sed -e 's/\([[0-9]]*\)/Z\1Z/g' \
85
-e 's/Z\([[0-9]]\)Z/Z0\1Z/g' \
86
-e 's/Z\([[0-9]][[0-9]]\)Z/Z0\1Z/g' \
87
-e 's/Z\([[0-9]][[0-9]][[0-9]]\)Z/Z0\1Z/g' \
90
AS_VAR_PUSHDEF([B],[ax_compare_version_B])
91
B=`echo "$3" | sed -e 's/\([[0-9]]*\)/Z\1Z/g' \
92
-e 's/Z\([[0-9]]\)Z/Z0\1Z/g' \
93
-e 's/Z\([[0-9]][[0-9]]\)Z/Z0\1Z/g' \
94
-e 's/Z\([[0-9]][[0-9]][[0-9]]\)Z/Z0\1Z/g' \
97
dnl # In the case of le, ge, lt, and gt, the strings are sorted as necessary
98
dnl # then the first line is used to determine if the condition is true.
99
dnl # The sed right after the echo is to remove any indented white space.
100
m4_case(m4_tolower($2),
102
ax_compare_version=`echo "x$A
103
x$B" | sed 's/^ *//' | sort -r | sed "s/x${A}/false/;s/x${B}/true/;1q"`
106
ax_compare_version=`echo "x$A
107
x$B" | sed 's/^ *//' | sort | sed "s/x${A}/false/;s/x${B}/true/;1q"`
110
ax_compare_version=`echo "x$A
111
x$B" | sed 's/^ *//' | sort | sed "s/x${A}/true/;s/x${B}/false/;1q"`
114
ax_compare_version=`echo "x$A
115
x$B" | sed 's/^ *//' | sort -r | sed "s/x${A}/true/;s/x${B}/false/;1q"`
117
dnl Split the operator from the subversion count if present.
118
m4_bmatch(m4_substr($2,2),
120
# A count of zero means use the length of the shorter version.
121
# Determine the number of characters in A and B.
122
ax_compare_version_len_A=`echo "$A" | awk '{print(length)}'`
123
ax_compare_version_len_B=`echo "$B" | awk '{print(length)}'`
125
# Set A to no more than B's length and B to no more than A's length.
126
A=`echo "$A" | sed "s/\(.\{$ax_compare_version_len_B\}\).*/\1/"`
127
B=`echo "$B" | sed "s/\(.\{$ax_compare_version_len_A\}\).*/\1/"`
130
# A count greater than zero means use only that many subversions
131
A=`echo "$A" | sed "s/\(\([[0-9]]\{4\}\)\{m4_substr($2,2)\}\).*/\1/"`
132
B=`echo "$B" | sed "s/\(\([[0-9]]\{4\}\)\{m4_substr($2,2)\}\).*/\1/"`
136
[illegal OP numeric parameter: $2])
139
# Pad zeros at end of numbers to make same length.
140
ax_compare_version_tmp_A="$A`echo $B | sed 's/./0/g'`"
141
B="$B`echo $A | sed 's/./0/g'`"
142
A="$ax_compare_version_tmp_A"
144
# Check for equality or inequality as necessary.
145
m4_case(m4_tolower(m4_substr($2,0,2)),
147
test "x$A" = "x$B" && ax_compare_version=true
150
test "x$A" != "x$B" && ax_compare_version=true
152
AC_WARNING([illegal OP parameter: $2])
156
AS_VAR_POPDEF([A])dnl
157
AS_VAR_POPDEF([B])dnl
159
dnl # Execute ACTION-IF-TRUE / ACTION-IF-FALSE.
160
if test "$ax_compare_version" = "true" ; then
161
m4_ifvaln([$4],[$4],[:])dnl
162
m4_ifvaln([$5],[else $5])dnl
164
]) dnl AX_COMPARE_VERSION