4 dnl ----------------------------------------------------------------
5 dnl From gcc's libiberty aclocal.m4
7 dnl See whether we need a declaration for a function.
8 AC_DEFUN([libiberty_NEED_DECLARATION],
9 [AC_MSG_CHECKING([whether $1 must be declared])
10 AC_CACHE_VAL(libiberty_cv_decl_needed_$1,
27 [char *(*pfn) = (char *(*)) $1],
28 libiberty_cv_decl_needed_$1=no, libiberty_cv_decl_needed_$1=yes)])
29 AC_MSG_RESULT($libiberty_cv_decl_needed_$1)
30 if test $libiberty_cv_decl_needed_$1 = yes; then
31 AC_DEFINE([NEED_DECLARATION_]translit($1, [a-z], [A-Z]), 1,
32 [Define if $1 is not declared in system header files.])
37 dnl ----------------------------------------------------------------
38 dnl From http://autoconf-archive.cryp.to/adl_compute_relative_paths.html
39 dnl and http://autoconf-archive.cryp.to/adl_normalize_path.html
41 dnl the adl_* functions which follow have the following copyright:
43 dnl Copyright © 2006 Alexandre Duret-Lutz <adl@gnu.org>
45 dnl This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
47 dnl This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
49 dnl You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
51 dnl As a special exception, the respective Autoconf Macro's copyright owner gives unlimited permission to copy, distribute and modify the configure scripts that are the output of Autoconf when processing the Macro. You need not follow the terms of the GNU General Public License when using or distributing such scripts, even though portions of the text of the Macro appear in them. The GNU General Public License (GPL) does govern all other use of the material that constitutes the Autoconf Macro.
53 dnl This special exception to the GPL applies to versions of the Autoconf Macro released by the Autoconf Macro Archive. When you make and distribute a modified version of the Autoconf Macro, you may extend this special exception to the GPL to apply to your modified version as well.
55 AC_DEFUN([adl_NORMALIZE_PATH],
57 # change empty paths to '.'
59 # strip trailing slashes
60 :*[[\\/]]:) $1=`echo "[$]$1" | sed 's,[[\\/]]*[$],,'` ;;
63 # squeze repeated slashes
64 case ifelse($2,,"[$]$1",$2) in
65 # if the path contains any backslashes, turn slashes into backslashes
66 *\\*) $1=`echo "[$]$1" | sed 's,\(.\)[[\\/]][[\\/]]*,\1\\\\\\\\,g'` ;;
67 # if the path contains slashes, also turn backslashes into slashes
68 *) $1=`echo "[$]$1" | sed 's,\(.\)[[\\/]][[\\/]]*,\1/,g'` ;;
72 AC_DEFUN([adl_COMPUTE_RELATIVE_PATHS],
74 _lcl_from=\[$]`echo "[$]_lcl_i" | sed 's,:.*$,,'`
75 _lcl_to=\[$]`echo "[$]_lcl_i" | sed 's,^[[^:]]*:,,' | sed 's,:[[^:]]*$,,'`
76 _lcl_result_var=`echo "[$]_lcl_i" | sed 's,^.*:,,'`
77 adl_RECURSIVE_EVAL([[$]_lcl_from], [_lcl_from])
78 adl_RECURSIVE_EVAL([[$]_lcl_to], [_lcl_to])
79 _lcl_notation="$_lcl_from$_lcl_to"
80 adl_NORMALIZE_PATH([_lcl_from],['/'])
81 adl_NORMALIZE_PATH([_lcl_to],['/'])
82 adl_COMPUTE_RELATIVE_PATH([_lcl_from], [_lcl_to], [_lcl_result_tmp])
83 adl_NORMALIZE_PATH([_lcl_result_tmp],["[$]_lcl_notation"])
84 eval $_lcl_result_var='[$]_lcl_result_tmp'
89 ## The following helper macros are too fragile to be used out
90 ## of adl_COMPUTE_RELATIVE_PATHS (mainly because they assume that
91 ## paths are normalized), that's why I'm keeping them in the same file.
92 ## Still, some of them maybe worth to reuse.
94 dnl adl_COMPUTE_RELATIVE_PATH(FROM, TO, RESULT)
95 dnl ===========================================
96 dnl Compute the relative path to go from $FROM to $TO and set the value
97 dnl of $RESULT to that value. This function work on raw filenames
98 dnl (for instead it will considerate /usr//local and /usr/local as
99 dnl two distinct paths), you should really use adl_COMPUTE_REALTIVE_PATHS
100 dnl instead to have the paths sanitized automatically.
103 dnl first_dir=/somewhere/on/my/disk/bin
104 dnl second_dir=/somewhere/on/another/disk/share
105 dnl adl_COMPUTE_RELATIVE_PATH(first_dir, second_dir, first_to_second)
106 dnl will set $first_to_second to '../../../another/disk/share'.
107 AC_DEFUN([adl_COMPUTE_RELATIVE_PATH],
108 [adl_COMPUTE_COMMON_PATH([$1], [$2], [_lcl_common_prefix])
109 adl_COMPUTE_BACK_PATH([$1], [_lcl_common_prefix], [_lcl_first_rel])
110 adl_COMPUTE_SUFFIX_PATH([$2], [_lcl_common_prefix], [_lcl_second_suffix])
111 $3="[$]_lcl_first_rel[$]_lcl_second_suffix"])
114 dnl adl_COMPUTE_COMMON_PATH(LEFT, RIGHT, RESULT)
115 dnl ============================================
116 dnl Compute the common path to $LEFT and $RIGHT and set the result to $RESULT.
119 dnl first_path=/somewhere/on/my/disk/bin
120 dnl second_path=/somewhere/on/another/disk/share
121 dnl adl_COMPUTE_COMMON_PATH(first_path, second_path, common_path)
122 dnl will set $common_path to '/somewhere/on'.
123 AC_DEFUN([adl_COMPUTE_COMMON_PATH],
125 _lcl_second_prefix_match=''
126 while test "[$]_lcl_second_prefix_match" != 0; do
127 _lcl_first_prefix=`expr "x[$]$1" : "x\([$]$3/*[[^/]]*\)"`
128 _lcl_second_prefix_match=`expr "x[$]$2" : "x[$]_lcl_first_prefix"`
129 if test "[$]_lcl_second_prefix_match" != 0; then
130 if test "[$]_lcl_first_prefix" != "[$]$3"; then
131 $3="[$]_lcl_first_prefix"
133 _lcl_second_prefix_match=0
138 dnl adl_COMPUTE_SUFFIX_PATH(PATH, SUBPATH, RESULT)
139 dnl ==============================================
140 dnl Substrack $SUBPATH from $PATH, and set the resulting suffix
141 dnl (or the empty string if $SUBPATH is not a subpath of $PATH)
145 dnl first_path=/somewhere/on/my/disk/bin
146 dnl second_path=/somewhere/on
147 dnl adl_COMPUTE_SUFFIX_PATH(first_path, second_path, common_path)
148 dnl will set $common_path to '/my/disk/bin'.
149 AC_DEFUN([adl_COMPUTE_SUFFIX_PATH],
150 [$3=`expr "x[$]$1" : "x[$]$2/*\(.*\)"`])
152 dnl adl_COMPUTE_BACK_PATH(PATH, SUBPATH, RESULT)
153 dnl ============================================
154 dnl Compute the relative path to go from $PATH to $SUBPATH, knowing that
155 dnl $SUBPATH is a subpath of $PATH (any other words, only repeated '../'
156 dnl should be needed to move from $PATH to $SUBPATH) and set the value
157 dnl of $RESULT to that value. If $SUBPATH is not a subpath of PATH,
158 dnl set $RESULT to the empty string.
161 dnl first_path=/somewhere/on/my/disk/bin
162 dnl second_path=/somewhere/on
163 dnl adl_COMPUTE_BACK_PATH(first_path, second_path, back_path)
164 dnl will set $back_path to '../../../'.
165 AC_DEFUN([adl_COMPUTE_BACK_PATH],
166 [adl_COMPUTE_SUFFIX_PATH([$1], [$2], [_lcl_first_suffix])
169 while test "[$]_lcl_tmp" != ''; do
170 _lcl_tmp=`expr "x[$]_lcl_first_suffix" : "x[[^/]]*/*\(.*\)"`
171 if test "[$]_lcl_first_suffix" != ''; then
172 _lcl_first_suffix="[$]_lcl_tmp"
178 dnl adl_RECURSIVE_EVAL(VALUE, RESULT)
179 dnl =================================
180 dnl Interpolate the VALUE in loop until it doesn't change,
181 dnl and set the result to $RESULT.
182 dnl WARNING: It's easy to get an infinite loop with some unsane input.
183 AC_DEFUN([adl_RECURSIVE_EVAL],
185 $2=`(test "x$prefix" = xNONE && prefix="$ac_default_prefix"
186 test "x$exec_prefix" = xNONE && exec_prefix="${prefix}"
188 while test "[$]_lcl_receval_old" != "[$]_lcl_receval"; do
189 _lcl_receval_old="[$]_lcl_receval"
190 eval _lcl_receval="\"[$]_lcl_receval\""
192 echo "[$]_lcl_receval")`])