~ubuntu-branches/ubuntu/hardy/autoconf-archive/hardy

« back to all changes in this revision

Viewing changes to htmldoc/relpaths.html

  • Committer: Bazaar Package Importer
  • Author(s): Martin A. Godisch
  • Date: 2004-06-26 09:43:57 UTC
  • Revision ID: james.westby@ubuntu.com-20040626094357-3be3jwcz1vcdhpe8
Tags: upstream-20040616
ImportĀ upstreamĀ versionĀ 20040616

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
 
2
"http://www.w3.org/TR/html4/strict.dtd">
 
3
 
 
4
<html lang="en">
 
5
<head>
 
6
  <title>Autoconf Macro: relpaths</title>
 
7
  <link rel="stylesheet" type="text/css" href="ac-archive.css">
 
8
</head>
 
9
 
 
10
<body>
 
11
  <table summary="web navigation" style="width:100%;">
 
12
    <tbody>
 
13
      <tr>
 
14
        <td style="width:50%;" align="center">[<a href="index.html">Macro Index
 
15
        Page</a>]</td>
 
16
 
 
17
        <td style="width:50%;" align="center">[<a href=
 
18
        "../m4source/relpaths.m4">Download M4 Source</a>]</td>
 
19
      </tr>
 
20
    </tbody>
 
21
  </table>
 
22
  <hr>
 
23
 
 
24
  <h1>relpaths</h1>
 
25
 
 
26
  <h2>Synopsis</h2>
 
27
 
 
28
  <div class="indent">
 
29
    <p style="text-align:left; white-space:nowrap;">
 
30
    <code>adl_COMPUTE_RELATIVE_PATHS(PATH_LIST)</code></p>
 
31
  </div>
 
32
 
 
33
  <h2>Description</h2>
 
34
 
 
35
  <div class="indent">
 
36
    <p>PATH_LIST is a space-separated list of colon-separated triplets of the
 
37
    form 'FROM:TO:RESULT'. This function iterates over these triplets and set
 
38
    $RESULT to the relative path from $FROM to $TO. Note that $FROM and $TO
 
39
    needs to be absolute filenames for this macro to success.</p>
 
40
 
 
41
    <p>For instance,</p>
 
42
    <pre>
 
43
   first=/usr/local/bin
 
44
   second=/usr/local/share
 
45
   adl_COMPUTE_RELATIVE_PATHS([first:second:fs second:first:sf])
 
46
   # $fs is set to ../share
 
47
   # $sf is set to ../bin
 
48
</pre>
 
49
 
 
50
    <p>$FROM and $TO are both eval'ed recursively and normalized, this means
 
51
    that you can call this macro with autoconf's dirnames like `prefix' or
 
52
    `datadir'. For example:</p>
 
53
    <pre>
 
54
   adl_COMPUTE_RELATIVE_PATHS([bindir:datadir:bin_to_data])
 
55
</pre>
 
56
 
 
57
    <p>adl_COMPUTE_RELATIVE_PATHS should also works with DOS filenames.</p>
 
58
 
 
59
    <p>You may want to use this macro in order to make your package
 
60
    relocatable. Instead of hardcoding $datadir into your programs just encode
 
61
    $bin_to_data and try to determine $bindir at run-time.</p>
 
62
 
 
63
    <p>This macro requires adl_NORMALIZE_PATH.</p>
 
64
  </div>
 
65
 
 
66
  <h2>Version</h2>
 
67
 
 
68
  <div class="indent">
 
69
    <p>1.1 (last modified: 2001-05-25)</p>
 
70
  </div>
 
71
 
 
72
  <h2>Author</h2>
 
73
 
 
74
  <div class="indent">
 
75
    <p>Alexandre Duret-Lutz &lt;duret_g@epita.fr&gt;</p>
 
76
  </div>
 
77
 
 
78
  <h2>M4 Source Code</h2>
 
79
 
 
80
  <div class="indent">
 
81
    <pre class="m4source">
 
82
AC_DEFUN([adl_COMPUTE_RELATIVE_PATHS],
 
83
[for _lcl_i in $1; do
 
84
  _lcl_from=\[$]`echo "[$]_lcl_i" | sed 's,:.*$,,'`
 
85
  _lcl_to=\[$]`echo "[$]_lcl_i" | sed 's,^[[^:]]*:,,' | sed 's,:[[^:]]*$,,'`
 
86
  _lcl_result_var=`echo "[$]_lcl_i" | sed 's,^.*:,,'`
 
87
  adl_RECURSIVE_EVAL([[$]_lcl_from], [_lcl_from])
 
88
  adl_RECURSIVE_EVAL([[$]_lcl_to], [_lcl_to])
 
89
  _lcl_notation="$_lcl_from$_lcl_to"
 
90
  adl_NORMALIZE_PATH([_lcl_from],['/'])
 
91
  adl_NORMALIZE_PATH([_lcl_to],['/'])
 
92
  adl_COMPUTE_RELATIVE_PATH([_lcl_from], [_lcl_to], [_lcl_result_tmp])
 
93
  adl_NORMALIZE_PATH([_lcl_result_tmp],["[$]_lcl_notation"])
 
94
  eval $_lcl_result_var='[$]_lcl_result_tmp'
 
95
done])
 
96
 
 
97
## Note:
 
98
## *****
 
99
## The following helper macros are too fragile to be used out
 
100
## of adl_COMPUTE_RELATIVE_PATHS (mainly because they assume that
 
101
## paths are normalized), that's why I'm keeping them in the same file.
 
102
## Still, some of them maybe worth to reuse.
 
103
 
 
104
dnl adl_COMPUTE_RELATIVE_PATH(FROM, TO, RESULT)
 
105
dnl ===========================================
 
106
dnl Compute the relative path to go from $FROM to $TO and set the value
 
107
dnl of $RESULT to that value.  This function work on raw filenames
 
108
dnl (for instead it will considerate /usr//local and /usr/local as
 
109
dnl two distinct paths), you should really use adl_COMPUTE_REALTIVE_PATHS
 
110
dnl instead to have the paths sanitized automatically.
 
111
dnl
 
112
dnl For instance:
 
113
dnl    first_dir=/somewhere/on/my/disk/bin
 
114
dnl    second_dir=/somewhere/on/another/disk/share
 
115
dnl    adl_COMPUTE_RELATIVE_PATH(first_dir, second_dir, first_to_second)
 
116
dnl will set $first_to_second to '../../../another/disk/share'.
 
117
AC_DEFUN([adl_COMPUTE_RELATIVE_PATH],
 
118
[adl_COMPUTE_COMMON_PATH([$1], [$2], [_lcl_common_prefix])
 
119
adl_COMPUTE_BACK_PATH([$1], [_lcl_common_prefix], [_lcl_first_rel])
 
120
adl_COMPUTE_SUFFIX_PATH([$2], [_lcl_common_prefix], [_lcl_second_suffix])
 
121
$3="[$]_lcl_first_rel[$]_lcl_second_suffix"])
 
122
 
 
123
dnl adl_COMPUTE_COMMON_PATH(LEFT, RIGHT, RESULT)
 
124
dnl ============================================
 
125
dnl Compute the common path to $LEFT and $RIGHT and set the result to $RESULT.
 
126
dnl
 
127
dnl For instance:
 
128
dnl    first_path=/somewhere/on/my/disk/bin
 
129
dnl    second_path=/somewhere/on/another/disk/share
 
130
dnl    adl_COMPUTE_COMMON_PATH(first_path, second_path, common_path)
 
131
dnl will set $common_path to '/somewhere/on'.
 
132
AC_DEFUN([adl_COMPUTE_COMMON_PATH],
 
133
[$3=''
 
134
_lcl_second_prefix_match=''
 
135
while test "[$]_lcl_second_prefix_match" != 0; do
 
136
  _lcl_first_prefix=`expr "x[$]$1" : "x\([$]$3/*[[^/]]*\)"`
 
137
  _lcl_second_prefix_match=`expr "x[$]$2" : "x[$]_lcl_first_prefix"`
 
138
  if test "[$]_lcl_second_prefix_match" != 0; then
 
139
    if test "[$]_lcl_first_prefix" != "[$]$3"; then
 
140
      $3="[$]_lcl_first_prefix"
 
141
    else
 
142
      _lcl_second_prefix_match=0
 
143
    fi
 
144
  fi
 
145
done])
 
146
 
 
147
dnl adl_COMPUTE_SUFFIX_PATH(PATH, SUBPATH, RESULT)
 
148
dnl ==============================================
 
149
dnl Substrack $SUBPATH from $PATH, and set the resulting suffix
 
150
dnl (or the empty string if $SUBPATH is not a subpath of $PATH)
 
151
dnl to $RESULT.
 
152
dnl
 
153
dnl For instace:
 
154
dnl    first_path=/somewhere/on/my/disk/bin
 
155
dnl    second_path=/somewhere/on
 
156
dnl    adl_COMPUTE_SUFFIX_PATH(first_path, second_path, common_path)
 
157
dnl will set $common_path to '/my/disk/bin'.
 
158
AC_DEFUN([adl_COMPUTE_SUFFIX_PATH],
 
159
[$3=`expr "x[$]$1" : "x[$]$2/*\(.*\)"`])
 
160
 
 
161
dnl adl_COMPUTE_BACK_PATH(PATH, SUBPATH, RESULT)
 
162
dnl ============================================
 
163
dnl Compute the relative path to go from $PATH to $SUBPATH, knowing that
 
164
dnl $SUBPATH is a subpath of $PATH (any other words, only repeated '../'
 
165
dnl should be needed to move from $PATH to $SUBPATH) and set the value
 
166
dnl of $RESULT to that value.  If $SUBPATH is not a subpath of PATH,
 
167
dnl set $RESULT to the empty string.
 
168
dnl
 
169
dnl For instance:
 
170
dnl    first_path=/somewhere/on/my/disk/bin
 
171
dnl    second_path=/somewhere/on
 
172
dnl    adl_COMPUTE_BACK_PATH(first_path, second_path, back_path)
 
173
dnl will set $back_path to '../../../'.
 
174
AC_DEFUN([adl_COMPUTE_BACK_PATH],
 
175
[adl_COMPUTE_SUFFIX_PATH([$1], [$2], [_lcl_first_suffix])
 
176
$3=''
 
177
_lcl_tmp='xxx'
 
178
while test "[$]_lcl_tmp" != ''; do
 
179
  _lcl_tmp=`expr "x[$]_lcl_first_suffix" : "x[[^/]]*/*\(.*\)"`
 
180
  if test "[$]_lcl_first_suffix" != ''; then
 
181
     _lcl_first_suffix="[$]_lcl_tmp"
 
182
     $3="../[$]$3"
 
183
  fi
 
184
done])
 
185
 
 
186
 
 
187
dnl adl_RECURSIVE_EVAL(VALUE, RESULT)
 
188
dnl =================================
 
189
dnl Interpolate the VALUE in loop until it doesn't change,
 
190
dnl and set the result to $RESULT.
 
191
dnl WARNING: It's easy to get an infinite loop with some unsane input.
 
192
AC_DEFUN([adl_RECURSIVE_EVAL],
 
193
[_lcl_receval="$1"
 
194
$2=`(test "x$prefix" = xNONE &amp;&amp; prefix="$ac_default_prefix"
 
195
     test "x$exec_prefix" = xNONE &amp;&amp; exec_prefix="${prefix}"
 
196
     _lcl_receval_old=''
 
197
     while test "[$]_lcl_receval_old" != "[$]_lcl_receval"; do
 
198
       _lcl_receval_old="[$]_lcl_receval"
 
199
       eval _lcl_receval="\"[$]_lcl_receval\""
 
200
     done
 
201
     echo "[$]_lcl_receval")`])
 
202
</pre>
 
203
  </div>
 
204
 
 
205
  <h2>Copyright</h2>
 
206
 
 
207
  <div class="indent">
 
208
    <a href="COPYING.html">GNU General Public License</a> with this special
 
209
    <a href="COPYING-Exception.html">exception</a>.
 
210
  </div>
 
211
</body>
 
212
</html>