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