source: git/m4/ax_compute_relative_paths.m4 @ f5d2647

spielwiese
Last change on this file since f5d2647 was 97a3b2, checked in by Oleksandr Motsak <motsak@…>, 10 years ago
Provide configured DIR variables into the config headers
  • Property mode set to 100644
File size: 7.6 KB
Line 
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
70AU_ALIAS([ADL_COMPUTE_RELATIVE_PATHS], [AX_COMPUTE_RELATIVE_PATHS])
71AC_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'
84done])
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
93dnl AX_COMPUTE_RELATIVE_PATH(FROM, TO, RESULT)
94dnl ===========================================
95dnl Compute the relative path to go from $FROM to $TO and set the value
96dnl of $RESULT to that value.  This function work on raw filenames
97dnl (for instead it will considerate /usr//local and /usr/local as
98dnl two distinct paths), you should really use AX_COMPUTE_REALTIVE_PATHS
99dnl instead to have the paths sanitized automatically.
100dnl
101dnl For instance:
102dnl    first_dir=/somewhere/on/my/disk/bin
103dnl    second_dir=/somewhere/on/another/disk/share
104dnl    AX_COMPUTE_RELATIVE_PATH(first_dir, second_dir, first_to_second)
105dnl will set $first_to_second to '../../../another/disk/share'.
106AC_DEFUN([AX_COMPUTE_RELATIVE_PATH],
107[AX_COMPUTE_COMMON_PATH([$1], [$2], [_lcl_common_prefix])
108AX_COMPUTE_BACK_PATH([$1], [_lcl_common_prefix], [_lcl_first_rel])
109AX_COMPUTE_SUFFIX_PATH([$2], [_lcl_common_prefix], [_lcl_second_suffix])
110$3="[$]_lcl_first_rel[$]_lcl_second_suffix"])
111
112dnl AX_COMPUTE_COMMON_PATH(LEFT, RIGHT, RESULT)
113dnl ============================================
114dnl Compute the common path to $LEFT and $RIGHT and set the result to $RESULT.
115dnl
116dnl For instance:
117dnl    first_path=/somewhere/on/my/disk/bin
118dnl    second_path=/somewhere/on/another/disk/share
119dnl    AX_COMPUTE_COMMON_PATH(first_path, second_path, common_path)
120dnl will set $common_path to '/somewhere/on'.
121AC_DEFUN([AX_COMPUTE_COMMON_PATH],
122[$3=''
123_lcl_second_prefix_match=''
124while 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
134done])
135
136dnl AX_COMPUTE_SUFFIX_PATH(PATH, SUBPATH, RESULT)
137dnl ==============================================
138dnl Substrack $SUBPATH from $PATH, and set the resulting suffix
139dnl (or the empty string if $SUBPATH is not a subpath of $PATH)
140dnl to $RESULT.
141dnl
142dnl For instace:
143dnl    first_path=/somewhere/on/my/disk/bin
144dnl    second_path=/somewhere/on
145dnl    AX_COMPUTE_SUFFIX_PATH(first_path, second_path, common_path)
146dnl will set $common_path to '/my/disk/bin'.
147AC_DEFUN([AX_COMPUTE_SUFFIX_PATH],
148[$3=`expr "x[$]$1" : "x[$]$2/*\(.*\)"`])
149
150dnl AX_COMPUTE_BACK_PATH(PATH, SUBPATH, RESULT)
151dnl ============================================
152dnl Compute the relative path to go from $PATH to $SUBPATH, knowing that
153dnl $SUBPATH is a subpath of $PATH (any other words, only repeated '../'
154dnl should be needed to move from $PATH to $SUBPATH) and set the value
155dnl of $RESULT to that value.  If $SUBPATH is not a subpath of PATH,
156dnl set $RESULT to the empty string.
157dnl
158dnl For instance:
159dnl    first_path=/somewhere/on/my/disk/bin
160dnl    second_path=/somewhere/on
161dnl    AX_COMPUTE_BACK_PATH(first_path, second_path, back_path)
162dnl will set $back_path to '../../../'.
163AC_DEFUN([AX_COMPUTE_BACK_PATH],
164[AX_COMPUTE_SUFFIX_PATH([$1], [$2], [_lcl_first_suffix])
165$3=''
166_lcl_tmp='xxx'
167while 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
173done])
174
175
176dnl AX_RECURSIVE_EVAL(VALUE, RESULT)
177dnl =================================
178dnl Interpolate the VALUE in loop until it doesn't change,
179dnl and set the result to $RESULT.
180dnl WARNING: It's easy to get an infinite loop with some unsane input.
181AC_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")`])
Note: See TracBrowser for help on using the repository browser.