1 | # ============================================================================= |
---|
2 | # http://www.gnu.org/software/autoconf-archive/ax_compute_relative_paths.html |
---|
3 | # ============================================================================= |
---|
4 | # |
---|
5 | # SYNOPSIS |
---|
6 | # |
---|
7 | # AX_COMPUTE_RELATIVE_PATHS(PATH_LIST) |
---|
8 | # |
---|
9 | # DESCRIPTION |
---|
10 | # |
---|
11 | # PATH_LIST is a space-separated list of colon-separated triplets of the |
---|
12 | # form 'FROM:TO:RESULT'. This function iterates over these triplets and |
---|
13 | # set $RESULT to the relative path from $FROM to $TO. Note that $FROM and |
---|
14 | # $TO needs to be absolute filenames for this macro to success. |
---|
15 | # |
---|
16 | # For instance, |
---|
17 | # |
---|
18 | # first=/usr/local/bin |
---|
19 | # second=/usr/local/share |
---|
20 | # AX_COMPUTE_RELATIVE_PATHS([first:second:fs second:first:sf]) |
---|
21 | # # $fs is set to ../share |
---|
22 | # # $sf is set to ../bin |
---|
23 | # |
---|
24 | # $FROM and $TO are both eval'ed recursively and normalized, this means |
---|
25 | # that you can call this macro with autoconf's dirnames like `prefix' or |
---|
26 | # `datadir'. For example: |
---|
27 | # |
---|
28 | # AX_COMPUTE_RELATIVE_PATHS([bindir:datadir:bin_to_data]) |
---|
29 | # |
---|
30 | # AX_COMPUTE_RELATIVE_PATHS should also works with DOS filenames. |
---|
31 | # |
---|
32 | # You may want to use this macro in order to make your package |
---|
33 | # relocatable. Instead of hardcoding $datadir into your programs just |
---|
34 | # encode $bin_to_data and try to determine $bindir at run-time. |
---|
35 | # |
---|
36 | # This macro requires AX_NORMALIZE_PATH. |
---|
37 | # |
---|
38 | # LICENSE |
---|
39 | # |
---|
40 | # Copyright (c) 2008 Alexandre Duret-Lutz <adl@gnu.org> |
---|
41 | # |
---|
42 | # This program is free software; you can redistribute it and/or modify it |
---|
43 | # under the terms of the GNU General Public License as published by the |
---|
44 | # Free Software Foundation; either version 2 of the License, or (at your |
---|
45 | # option) any later version. |
---|
46 | # |
---|
47 | # This program is distributed in the hope that it will be useful, but |
---|
48 | # WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
49 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General |
---|
50 | # Public License for more details. |
---|
51 | # |
---|
52 | # You should have received a copy of the GNU General Public License along |
---|
53 | # with this program. If not, see <http://www.gnu.org/licenses/>. |
---|
54 | # |
---|
55 | # As a special exception, the respective Autoconf Macro's copyright owner |
---|
56 | # gives unlimited permission to copy, distribute and modify the configure |
---|
57 | # scripts that are the output of Autoconf when processing the Macro. You |
---|
58 | # need not follow the terms of the GNU General Public License when using |
---|
59 | # or distributing such scripts, even though portions of the text of the |
---|
60 | # Macro appear in them. The GNU General Public License (GPL) does govern |
---|
61 | # all other use of the material that constitutes the Autoconf Macro. |
---|
62 | # |
---|
63 | # This special exception to the GPL applies to versions of the Autoconf |
---|
64 | # Macro released by the Autoconf Archive. When you make and distribute a |
---|
65 | # modified version of the Autoconf Macro, you may extend this special |
---|
66 | # exception to the GPL to apply to your modified version as well. |
---|
67 | |
---|
68 | #serial 6 |
---|
69 | |
---|
70 | AU_ALIAS([ADL_COMPUTE_RELATIVE_PATHS], [AX_COMPUTE_RELATIVE_PATHS]) |
---|
71 | AC_DEFUN([AX_COMPUTE_RELATIVE_PATHS], |
---|
72 | [for _lcl_i in $1; do |
---|
73 | _lcl_from=\[$]`echo "[$]_lcl_i" | sed 's,:.*$,,'` |
---|
74 | _lcl_to=\[$]`echo "[$]_lcl_i" | sed 's,^[[^:]]*:,,' | sed 's,:[[^:]]*$,,'` |
---|
75 | _lcl_result_var=`echo "[$]_lcl_i" | sed 's,^.*:,,'` |
---|
76 | AX_RECURSIVE_EVAL([[$]_lcl_from], [_lcl_from]) |
---|
77 | AX_RECURSIVE_EVAL([[$]_lcl_to], [_lcl_to]) |
---|
78 | _lcl_notation="$_lcl_from$_lcl_to" |
---|
79 | AX_NORMALIZE_PATH([_lcl_from],['/']) |
---|
80 | AX_NORMALIZE_PATH([_lcl_to],['/']) |
---|
81 | AX_COMPUTE_RELATIVE_PATH([_lcl_from], [_lcl_to], [_lcl_result_tmp]) |
---|
82 | AX_NORMALIZE_PATH([_lcl_result_tmp],["[$]_lcl_notation"]) |
---|
83 | eval $_lcl_result_var='[$]_lcl_result_tmp' |
---|
84 | done]) |
---|
85 | |
---|
86 | ## Note: |
---|
87 | ## ***** |
---|
88 | ## The following helper macros are too fragile to be used out |
---|
89 | ## of AX_COMPUTE_RELATIVE_PATHS (mainly because they assume that |
---|
90 | ## paths are normalized), that's why I'm keeping them in the same file. |
---|
91 | ## Still, some of them maybe worth to reuse. |
---|
92 | |
---|
93 | dnl AX_COMPUTE_RELATIVE_PATH(FROM, TO, RESULT) |
---|
94 | dnl =========================================== |
---|
95 | dnl Compute the relative path to go from $FROM to $TO and set the value |
---|
96 | dnl of $RESULT to that value. This function work on raw filenames |
---|
97 | dnl (for instead it will considerate /usr//local and /usr/local as |
---|
98 | dnl two distinct paths), you should really use AX_COMPUTE_REALTIVE_PATHS |
---|
99 | dnl instead to have the paths sanitized automatically. |
---|
100 | dnl |
---|
101 | dnl For instance: |
---|
102 | dnl first_dir=/somewhere/on/my/disk/bin |
---|
103 | dnl second_dir=/somewhere/on/another/disk/share |
---|
104 | dnl AX_COMPUTE_RELATIVE_PATH(first_dir, second_dir, first_to_second) |
---|
105 | dnl will set $first_to_second to '../../../another/disk/share'. |
---|
106 | AC_DEFUN([AX_COMPUTE_RELATIVE_PATH], |
---|
107 | [AX_COMPUTE_COMMON_PATH([$1], [$2], [_lcl_common_prefix]) |
---|
108 | AX_COMPUTE_BACK_PATH([$1], [_lcl_common_prefix], [_lcl_first_rel]) |
---|
109 | AX_COMPUTE_SUFFIX_PATH([$2], [_lcl_common_prefix], [_lcl_second_suffix]) |
---|
110 | $3="[$]_lcl_first_rel[$]_lcl_second_suffix"]) |
---|
111 | |
---|
112 | dnl AX_COMPUTE_COMMON_PATH(LEFT, RIGHT, RESULT) |
---|
113 | dnl ============================================ |
---|
114 | dnl Compute the common path to $LEFT and $RIGHT and set the result to $RESULT. |
---|
115 | dnl |
---|
116 | dnl For instance: |
---|
117 | dnl first_path=/somewhere/on/my/disk/bin |
---|
118 | dnl second_path=/somewhere/on/another/disk/share |
---|
119 | dnl AX_COMPUTE_COMMON_PATH(first_path, second_path, common_path) |
---|
120 | dnl will set $common_path to '/somewhere/on'. |
---|
121 | AC_DEFUN([AX_COMPUTE_COMMON_PATH], |
---|
122 | [$3='' |
---|
123 | _lcl_second_prefix_match='' |
---|
124 | while test "[$]_lcl_second_prefix_match" != 0; do |
---|
125 | _lcl_first_prefix=`expr "x[$]$1" : "x\([$]$3/*[[^/]]*\)"` |
---|
126 | _lcl_second_prefix_match=`expr "x[$]$2" : "x[$]_lcl_first_prefix"` |
---|
127 | if test "[$]_lcl_second_prefix_match" != 0; then |
---|
128 | if test "[$]_lcl_first_prefix" != "[$]$3"; then |
---|
129 | $3="[$]_lcl_first_prefix" |
---|
130 | else |
---|
131 | _lcl_second_prefix_match=0 |
---|
132 | fi |
---|
133 | fi |
---|
134 | done]) |
---|
135 | |
---|
136 | dnl AX_COMPUTE_SUFFIX_PATH(PATH, SUBPATH, RESULT) |
---|
137 | dnl ============================================== |
---|
138 | dnl Substrack $SUBPATH from $PATH, and set the resulting suffix |
---|
139 | dnl (or the empty string if $SUBPATH is not a subpath of $PATH) |
---|
140 | dnl to $RESULT. |
---|
141 | dnl |
---|
142 | dnl For instace: |
---|
143 | dnl first_path=/somewhere/on/my/disk/bin |
---|
144 | dnl second_path=/somewhere/on |
---|
145 | dnl AX_COMPUTE_SUFFIX_PATH(first_path, second_path, common_path) |
---|
146 | dnl will set $common_path to '/my/disk/bin'. |
---|
147 | AC_DEFUN([AX_COMPUTE_SUFFIX_PATH], |
---|
148 | [$3=`expr "x[$]$1" : "x[$]$2/*\(.*\)"`]) |
---|
149 | |
---|
150 | dnl AX_COMPUTE_BACK_PATH(PATH, SUBPATH, RESULT) |
---|
151 | dnl ============================================ |
---|
152 | dnl Compute the relative path to go from $PATH to $SUBPATH, knowing that |
---|
153 | dnl $SUBPATH is a subpath of $PATH (any other words, only repeated '../' |
---|
154 | dnl should be needed to move from $PATH to $SUBPATH) and set the value |
---|
155 | dnl of $RESULT to that value. If $SUBPATH is not a subpath of PATH, |
---|
156 | dnl set $RESULT to the empty string. |
---|
157 | dnl |
---|
158 | dnl For instance: |
---|
159 | dnl first_path=/somewhere/on/my/disk/bin |
---|
160 | dnl second_path=/somewhere/on |
---|
161 | dnl AX_COMPUTE_BACK_PATH(first_path, second_path, back_path) |
---|
162 | dnl will set $back_path to '../../../'. |
---|
163 | AC_DEFUN([AX_COMPUTE_BACK_PATH], |
---|
164 | [AX_COMPUTE_SUFFIX_PATH([$1], [$2], [_lcl_first_suffix]) |
---|
165 | $3='' |
---|
166 | _lcl_tmp='xxx' |
---|
167 | while test "[$]_lcl_tmp" != ''; do |
---|
168 | _lcl_tmp=`expr "x[$]_lcl_first_suffix" : "x[[^/]]*/*\(.*\)"` |
---|
169 | if test "[$]_lcl_first_suffix" != ''; then |
---|
170 | _lcl_first_suffix="[$]_lcl_tmp" |
---|
171 | $3="../[$]$3" |
---|
172 | fi |
---|
173 | done]) |
---|
174 | |
---|
175 | |
---|
176 | dnl AX_RECURSIVE_EVAL(VALUE, RESULT) |
---|
177 | dnl ================================= |
---|
178 | dnl Interpolate the VALUE in loop until it doesn't change, |
---|
179 | dnl and set the result to $RESULT. |
---|
180 | dnl WARNING: It's easy to get an infinite loop with some unsane input. |
---|
181 | AC_DEFUN([AX_RECURSIVE_EVAL], |
---|
182 | [_lcl_receval="$1" |
---|
183 | $2=`(test "x$prefix" = xNONE && prefix="$ac_default_prefix" |
---|
184 | test "x$exec_prefix" = xNONE && exec_prefix="${prefix}" |
---|
185 | _lcl_receval_old='' |
---|
186 | while test "[$]_lcl_receval_old" != "[$]_lcl_receval"; do |
---|
187 | _lcl_receval_old="[$]_lcl_receval" |
---|
188 | eval _lcl_receval="\"[$]_lcl_receval\"" |
---|
189 | done |
---|
190 | echo "[$]_lcl_receval")`]) |
---|