]>
Commit | Line | Data |
---|---|---|
7456f3b5 SG |
1 | dnl as-ac-expand.m4 0.2.0 |
2 | dnl autostars m4 macro for expanding directories using configure's prefix | |
3 | dnl thomas@apestaart.org | |
4 | dnl | |
5 | ||
6 | dnl AS_AC_EXPAND(VAR, CONFIGURE_VAR) | |
7 | dnl example | |
8 | dnl AS_AC_EXPAND(SYSCONFDIR, $sysconfdir) | |
9 | dnl will set SYSCONFDIR to /usr/local/etc if prefix=/usr/local | |
10 | ||
11 | AC_DEFUN([AS_AC_EXPAND], | |
12 | [ | |
13 | EXP_VAR=[$1] | |
14 | FROM_VAR=[$2] | |
15 | ||
16 | dnl first expand prefix and exec_prefix if necessary | |
17 | prefix_save=$prefix | |
18 | exec_prefix_save=$exec_prefix | |
19 | ||
20 | dnl if no prefix given, then use /usr/local, the default prefix | |
21 | if test "x$prefix" = "xNONE"; then | |
22 | prefix="$ac_default_prefix" | |
23 | fi | |
24 | dnl if no exec_prefix given, then use prefix | |
25 | if test "x$exec_prefix" = "xNONE"; then | |
26 | exec_prefix=$prefix | |
27 | fi | |
28 | ||
29 | full_var="$FROM_VAR" | |
30 | dnl loop until it doesn't change anymore | |
31 | while true; do | |
32 | new_full_var="`eval echo $full_var`" | |
33 | if test "x$new_full_var" = "x$full_var"; then break; fi | |
34 | full_var=$new_full_var | |
35 | done | |
36 | ||
37 | dnl clean up | |
38 | full_var=$new_full_var | |
39 | AC_SUBST([$1], "$full_var") | |
40 | ||
41 | dnl restore prefix and exec_prefix | |
42 | prefix=$prefix_save | |
43 | exec_prefix=$exec_prefix_save | |
44 | ]) | |
45 | ||
46 | dnl Available from the GNU Autoconf Macro Archive at: | |
47 | dnl http://www.gnu.org/software/ac-archive/htmldoc/ax_compare_version.html | |
48 | AC_DEFUN([AX_COMPARE_VERSION], [ | |
49 | # Used to indicate true or false condition | |
50 | ax_compare_version=false | |
51 | # Convert the two version strings to be compared into a format that | |
52 | # allows a simple string comparison. The end result is that a version | |
53 | # string of the form 1.12.5-r617 will be converted to the form | |
54 | # 0001001200050617. In other words, each number is zero padded to four | |
55 | # digits, and non digits are removed. | |
56 | AS_VAR_PUSHDEF([A],[ax_compare_version_A]) | |
57 | A=`echo "$1" | sed -e 's/\([[0-9]]*\)/Z\1Z/g' \ | |
58 | -e 's/Z\([[0-9]]\)Z/Z0\1Z/g' \ | |
59 | -e 's/Z\([[0-9]][[0-9]]\)Z/Z0\1Z/g' \ | |
60 | -e 's/Z\([[0-9]][[0-9]][[0-9]]\)Z/Z0\1Z/g' \ | |
61 | -e 's/[[^0-9]]//g'` | |
62 | ||
63 | AS_VAR_PUSHDEF([B],[ax_compare_version_B]) | |
64 | B=`echo "$3" | sed -e 's/\([[0-9]]*\)/Z\1Z/g' \ | |
65 | -e 's/Z\([[0-9]]\)Z/Z0\1Z/g' \ | |
66 | -e 's/Z\([[0-9]][[0-9]]\)Z/Z0\1Z/g' \ | |
67 | -e 's/Z\([[0-9]][[0-9]][[0-9]]\)Z/Z0\1Z/g' \ | |
68 | -e 's/[[^0-9]]//g'` | |
69 | ||
70 | dnl # In the case of le, ge, lt, and gt, the strings are sorted as necessary | |
71 | dnl # then the first line is used to determine if the condition is true. | |
72 | dnl # The sed right after the echo is to remove any indented white space. | |
73 | m4_case(m4_tolower($2), | |
74 | [lt],[ | |
75 | ax_compare_version=`echo "x$A | |
76 | x$B" | sed 's/^ *//' | sort -r | sed "s/x${A}/false/;s/x${B}/true/;1q"` | |
77 | ], | |
78 | [gt],[ | |
79 | ax_compare_version=`echo "x$A | |
80 | x$B" | sed 's/^ *//' | sort | sed "s/x${A}/false/;s/x${B}/true/;1q"` | |
81 | ], | |
82 | [le],[ | |
83 | ax_compare_version=`echo "x$A | |
84 | x$B" | sed 's/^ *//' | sort | sed "s/x${A}/true/;s/x${B}/false/;1q"` | |
85 | ], | |
86 | [ge],[ | |
87 | ax_compare_version=`echo "x$A | |
88 | x$B" | sed 's/^ *//' | sort -r | sed "s/x${A}/true/;s/x${B}/false/;1q"` | |
89 | ],[ | |
90 | dnl Split the operator from the subversion count if present. | |
91 | m4_bmatch(m4_substr($2,2), | |
92 | [0],[ | |
93 | # A count of zero means use the length of the shorter version. | |
94 | # Determine the number of characters in A and B. | |
95 | ax_compare_version_len_A=`echo "$A" | awk '{print(length)}'` | |
96 | ax_compare_version_len_B=`echo "$B" | awk '{print(length)}'` | |
97 | ||
98 | # Set A to no more than B's length and B to no more than A's length. | |
99 | A=`echo "$A" | sed "s/\(.\{$ax_compare_version_len_B\}\).*/\1/"` | |
100 | B=`echo "$B" | sed "s/\(.\{$ax_compare_version_len_A\}\).*/\1/"` | |
101 | ], | |
102 | [[0-9]+],[ | |
103 | # A count greater than zero means use only that many subversions | |
104 | A=`echo "$A" | sed "s/\(\([[0-9]]\{4\}\)\{m4_substr($2,2)\}\).*/\1/"` | |
105 | B=`echo "$B" | sed "s/\(\([[0-9]]\{4\}\)\{m4_substr($2,2)\}\).*/\1/"` | |
106 | ], | |
107 | [.+],[ | |
108 | AC_WARNING( | |
109 | [illegal OP numeric parameter: $2]) | |
110 | ],[]) | |
111 | ||
112 | # Pad zeros at end of numbers to make same length. | |
113 | ax_compare_version_tmp_A="$A`echo $B | sed 's/./0/g'`" | |
114 | B="$B`echo $A | sed 's/./0/g'`" | |
115 | A="$ax_compare_version_tmp_A" | |
116 | ||
117 | # Check for equality or inequality as necessary. | |
118 | m4_case(m4_tolower(m4_substr($2,0,2)), | |
119 | [eq],[ | |
120 | test "x$A" = "x$B" && ax_compare_version=true | |
121 | ], | |
122 | [ne],[ | |
123 | test "x$A" != "x$B" && ax_compare_version=true | |
124 | ],[ | |
125 | AC_WARNING([illegal OP parameter: $2]) | |
126 | ]) | |
127 | ]) | |
128 | ||
129 | AS_VAR_POPDEF([A])dnl | |
130 | AS_VAR_POPDEF([B])dnl | |
131 | ||
132 | dnl # Execute ACTION-IF-TRUE / ACTION-IF-FALSE. | |
133 | if test "$ax_compare_version" = "true" ; then | |
134 | m4_ifvaln([$4],[$4],[:])dnl | |
135 | m4_ifvaln([$5],[else $5])dnl | |
136 | fi | |
137 | ]) dnl AX_COMPARE_VERSION |