root/swish-e/branches/2.6/config/ax_compare_version.m4

Revision 1939, 3.4 kB (checked in by karpet, 1 year ago)

BDB support on all the time via autoconf

Line 
1 dnl #########################################################################
2 AC_DEFUN([AX_COMPARE_VERSION], [
3   # Used to indicate true or false condition
4   ax_compare_version=false
5
6   # Convert the two version strings to be compared into a format that
7   # allows a simple string comparison.  The end result is that a version
8   # string of the form 1.12.5-r617 will be converted to the form
9   # 0001001200050617.  In other words, each number is zero padded to four
10   # digits, and non digits are removed.
11   AS_VAR_PUSHDEF([A],[ax_compare_version_A])
12   A=`echo "$1" | sed -e 's/\([[0-9]]*\)/Z\1Z/g' \
13                      -e 's/Z\([[0-9]]\)Z/Z0\1Z/g' \
14                      -e 's/Z\([[0-9]][[0-9]]\)Z/Z0\1Z/g' \
15                      -e 's/Z\([[0-9]][[0-9]][[0-9]]\)Z/Z0\1Z/g' \
16                      -e 's/[[^0-9]]//g'`
17
18   AS_VAR_PUSHDEF([B],[ax_compare_version_B])
19   B=`echo "$3" | sed -e 's/\([[0-9]]*\)/Z\1Z/g' \
20                      -e 's/Z\([[0-9]]\)Z/Z0\1Z/g' \
21                      -e 's/Z\([[0-9]][[0-9]]\)Z/Z0\1Z/g' \
22                      -e 's/Z\([[0-9]][[0-9]][[0-9]]\)Z/Z0\1Z/g' \
23                      -e 's/[[^0-9]]//g'`
24
25   dnl # In the case of le, ge, lt, and gt, the strings are sorted as necessary
26   dnl # then the first line is used to determine if the condition is true.
27   dnl # The sed right after the echo is to remove any indented white space.
28   m4_case(m4_tolower($2),
29   [lt],[
30     ax_compare_version=`echo "x$A
31 x$B" | sed 's/^ *//' | sort -r | sed "s/x${A}/false/;s/x${B}/true/;1q"`
32   ],
33   [gt],[
34     ax_compare_version=`echo "x$A
35 x$B" | sed 's/^ *//' | sort | sed "s/x${A}/false/;s/x${B}/true/;1q"`
36   ],
37   [le],[
38     ax_compare_version=`echo "x$A
39 x$B" | sed 's/^ *//' | sort | sed "s/x${A}/true/;s/x${B}/false/;1q"`
40   ],
41   [ge],[
42     ax_compare_version=`echo "x$A
43 x$B" | sed 's/^ *//' | sort -r | sed "s/x${A}/true/;s/x${B}/false/;1q"`
44   ],[
45     dnl Split the operator from the subversion count if present.
46     m4_bmatch(m4_substr($2,2),
47     [0],[
48       # A count of zero means use the length of the shorter version.
49       # Determine the number of characters in A and B.
50       ax_compare_version_len_A=`echo "$A" | awk '{print(length)}'`
51       ax_compare_version_len_B=`echo "$B" | awk '{print(length)}'`
52
53       # Set A to no more than B's length and B to no more than A's length.
54       A=`echo "$A" | sed "s/\(.\{$ax_compare_version_len_B\}\).*/\1/"`
55       B=`echo "$B" | sed "s/\(.\{$ax_compare_version_len_A\}\).*/\1/"`
56     ],
57     [[0-9]+],[
58       # A count greater than zero means use only that many subversions
59       A=`echo "$A" | sed "s/\(\([[0-9]]\{4\}\)\{m4_substr($2,2)\}\).*/\1/"`
60       B=`echo "$B" | sed "s/\(\([[0-9]]\{4\}\)\{m4_substr($2,2)\}\).*/\1/"`
61     ],
62     [.+],[
63       AC_WARNING(
64         [illegal OP numeric parameter: $2])
65     ],[])
66
67     # Pad zeros at end of numbers to make same length.
68     ax_compare_version_tmp_A="$A`echo $B | sed 's/./0/g'`"
69     B="$B`echo $A | sed 's/./0/g'`"
70     A="$ax_compare_version_tmp_A"
71
72     # Check for equality or inequality as necessary.
73     m4_case(m4_tolower(m4_substr($2,0,2)),
74     [eq],[
75       test "x$A" = "x$B" && ax_compare_version=true
76     ],
77     [ne],[
78       test "x$A" != "x$B" && ax_compare_version=true
79     ],[
80       AC_WARNING([illegal OP parameter: $2])
81     ])
82   ])
83
84   AS_VAR_POPDEF([A])dnl
85   AS_VAR_POPDEF([B])dnl
86
87   dnl # Execute ACTION-IF-TRUE / ACTION-IF-FALSE.
88   if test "$ax_compare_version" = "true" ; then
89     m4_ifvaln([$4],[$4],[:])dnl
90     m4_ifvaln([$5],[else $5])dnl
91   fi
92 ]) dnl AX_COMPARE_VERSION
93
Note: See TracBrowser for help on using the browser.