1 # The functions in this file provide support for relocatability of
2 # shell scripts. They should be included near the beginning of each
3 # shell script in a relocatable program, by adding @relocatable_sh@
4 # and causing the script to be expanded with AC_CONFIG_FILES. A
5 # small amount of additional code must be added and adapted to the
6 # package by hand; see doc/relocatable-maint.texi (in Gnulib) for
9 # Copyright (C) 2003-2017 Free Software Foundation, Inc.
11 # This program is free software: you can redistribute it and/or modify
12 # it under the terms of the GNU General Public License as published by
13 # the Free Software Foundation; either version 3 of the License, or
14 # (at your option) any later version.
16 # This program is distributed in the hope that it will be useful,
17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 # GNU General Public License for more details.
21 # You should have received a copy of the GNU General Public License
22 # along with this program. If not, see <http://www.gnu.org/licenses/>.
25 # Support for relocatability.
26 func_find_curr_installdir
()
28 # Determine curr_installdir, even taking into account symlinks.
30 case "$curr_executable" in
32 *) # Need to look in the PATH.
33 if test "${PATH_SEPARATOR+set}" != set; then
34 # Determine PATH_SEPARATOR by trying to find /bin/sh in a PATH which
35 # contains only /bin. Note that ksh looks also at the FPATH variable,
36 # so we have to set that as well for the test.
38 (PATH
='/bin;/bin'; FPATH
=$PATH; sh
-c :) >/dev
/null
2>&1 \
39 && { (PATH
='/bin:/bin'; FPATH
=$PATH; sh
-c :) >/dev
/null
2>&1 \
43 save_IFS
="$IFS"; IFS
="$PATH_SEPARATOR"
46 test -z "$dir" && dir
=.
47 for exec_ext
in ''; do
48 if test -f "$dir/$curr_executable$exec_ext"; then
49 curr_executable
="$dir/$curr_executable$exec_ext"
58 case "$curr_executable" in
60 *) curr_executable
=`pwd`/"$curr_executable" ;;
63 sed_dirname
='s,/[^/]*$,,'
64 sed_linkdest
='s,^.* -> \(.*\),\1,p'
66 lsline
=`LC_ALL=C ls -l "$curr_executable"`
69 linkdest
=`echo "$lsline" | sed -n -e "$sed_linkdest"`
71 /* | ?
:/* | ?
:\\*) curr_executable
="$linkdest" ;;
72 *) curr_executable
=`echo "$curr_executable" | sed -e "$sed_dirname"`/"$linkdest" ;;
77 curr_installdir
=`echo "$curr_executable" | sed -e 's,/[^/]*$,,'`
79 curr_installdir
=`cd "$curr_installdir" && pwd`
83 # Compute the original/current installation prefixes by stripping the
84 # trailing directories off the original/current installation directories.
85 orig_installprefix
="$orig_installdir"
86 curr_installprefix
="$curr_installdir"
88 orig_last
=`echo "$orig_installprefix" | sed -n -e 's,^.*/\([^/]*\)$,\1,p'`
89 curr_last
=`echo "$curr_installprefix" | sed -n -e 's,^.*/\([^/]*\)$,\1,p'`
90 if test -z "$orig_last" ||
test -z "$curr_last"; then
93 if test "$orig_last" != "$curr_last"; then
96 orig_installprefix
=`echo "$orig_installprefix" | sed -e 's,/[^/]*$,,'`
97 curr_installprefix
=`echo "$curr_installprefix" | sed -e 's,/[^/]*$,,'`