~vcs-imports/mysql-udf-regexp/trunk

« back to all changes in this revision

Viewing changes to ax_compare_version.m4

  • Committer: hartmut
  • Date: 2006-09-27 03:11:49 UTC
  • Revision ID: vcs-imports@canonical.com-20060927031149-nitx03y6ytqcocyj
initial

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
dnl (from http://autoconf-archive.cryp.to/ax_compare_version.m4 )
 
2
dnl
 
3
dnl @synopsis AX_COMPARE_VERSION(VERSION_A, OP, VERSION_B, [ACTION-IF-TRUE], [ACTION-IF-FALSE])
 
4
dnl
 
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.
 
11
dnl
 
12
dnl The six basic comparisons are available, as well as checking
 
13
dnl equality limited to a certain number of minor-version levels.
 
14
dnl
 
15
dnl The operator OP determines what type of comparison to do, and can
 
16
dnl be one of:
 
17
dnl
 
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)
 
24
dnl
 
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.
 
27
dnl
 
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
 
32
dnl
 
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
 
36
dnl 'false' as well.
 
37
dnl
 
38
dnl Examples:
 
39
dnl
 
40
dnl   AX_COMPARE_VERSION([3.15.7],[lt],[3.15.8])
 
41
dnl   AX_COMPARE_VERSION([3.15],[lt],[3.15.8])
 
42
dnl
 
43
dnl would both be true.
 
44
dnl
 
45
dnl   AX_COMPARE_VERSION([3.15.7],[eq],[3.15.8])
 
46
dnl   AX_COMPARE_VERSION([3.15],[gt],[3.15.8])
 
47
dnl
 
48
dnl would both be false.
 
49
dnl
 
50
dnl   AX_COMPARE_VERSION([3.15.7],[eq2],[3.15.8])
 
51
dnl
 
52
dnl would be true because it is only comparing two minor versions.
 
53
dnl
 
54
dnl   AX_COMPARE_VERSION([3.15.7],[eq0],[3.15])
 
55
dnl
 
56
dnl would be true because it is only comparing the lesser number of
 
57
dnl minor versions of the two values.
 
58
dnl
 
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.
 
62
dnl
 
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.
 
67
dnl
 
68
dnl @category Misc
 
69
dnl @author Tim Toolan <toolan@ele.uri.edu>
 
70
dnl @version 2004-03-01
 
71
dnl @license GPLWithACException
 
72
 
 
73
dnl #########################################################################
 
74
AC_DEFUN([AX_COMPARE_VERSION], [
 
75
  # Used to indicate true or false condition
 
76
  ax_compare_version=false
 
77
 
 
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' \
 
88
                     -e 's/[[^0-9]]//g'`
 
89
 
 
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' \
 
95
                     -e 's/[[^0-9]]//g'`
 
96
 
 
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),
 
101
  [lt],[
 
102
    ax_compare_version=`echo "x$A
 
103
x$B" | sed 's/^ *//' | sort -r | sed "s/x${A}/false/;s/x${B}/true/;1q"`
 
104
  ],
 
105
  [gt],[
 
106
    ax_compare_version=`echo "x$A
 
107
x$B" | sed 's/^ *//' | sort | sed "s/x${A}/false/;s/x${B}/true/;1q"`
 
108
  ],
 
109
  [le],[
 
110
    ax_compare_version=`echo "x$A
 
111
x$B" | sed 's/^ *//' | sort | sed "s/x${A}/true/;s/x${B}/false/;1q"`
 
112
  ],
 
113
  [ge],[
 
114
    ax_compare_version=`echo "x$A
 
115
x$B" | sed 's/^ *//' | sort -r | sed "s/x${A}/true/;s/x${B}/false/;1q"`
 
116
  ],[
 
117
    dnl Split the operator from the subversion count if present.
 
118
    m4_bmatch(m4_substr($2,2),
 
119
    [0],[
 
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)}'`
 
124
 
 
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/"`
 
128
    ],
 
129
    [[0-9]+],[
 
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/"`
 
133
    ],
 
134
    [.+],[
 
135
      AC_WARNING(
 
136
        [illegal OP numeric parameter: $2])
 
137
    ],[])
 
138
 
 
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"
 
143
 
 
144
    # Check for equality or inequality as necessary.
 
145
    m4_case(m4_tolower(m4_substr($2,0,2)),
 
146
    [eq],[
 
147
      test "x$A" = "x$B" && ax_compare_version=true
 
148
    ],
 
149
    [ne],[
 
150
      test "x$A" != "x$B" && ax_compare_version=true
 
151
    ],[
 
152
      AC_WARNING([illegal OP parameter: $2])
 
153
    ])
 
154
  ])
 
155
 
 
156
  AS_VAR_POPDEF([A])dnl
 
157
  AS_VAR_POPDEF([B])dnl
 
158
 
 
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
 
163
  fi
 
164
]) dnl AX_COMPARE_VERSION