[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
symlink calculation in bootstrap script
From: |
Bruno Haible |
Subject: |
symlink calculation in bootstrap script |
Date: |
Mon, 9 Oct 2006 14:33:46 +0200 |
User-agent: |
KMail/1.9.1 |
Hi,
Here's a patch to lift a few restrictions in the bootstrap script.
2006-10-08 Bruno Haible <address@hidden>
* bootstrap (func_relativize): New function, taken from gnulib-tool.
(symlink_to_gnulib): Use it.
*** bootstrap.bak 2006-10-07 15:40:13.000000000 +0200
--- bootstrap 2006-10-08 14:14:24.000000000 +0200
***************
*** 245,267 ****
fi;;
esac
symlink_to_gnulib()
{
src=$GNULIB_SRCDIR/$1
dst=${2-$1}
- dot_dots=
-
case $src in
! /*) ;;
*)
! case /$dst/ in
! *//* | */../* | */./* | /*/*/*/*/*/)
! echo >&2 "$0: invalid symlink calculation: $src -> $dst"
! exit 1;;
! /*/*/*/*/) dot_dots=../../../;;
! /*/*/*/) dot_dots=../../;;
! /*/*/) dot_dots=../;;
! esac;;
esac
test -f "$src" && {
--- 251,304 ----
fi;;
esac
+ # func_relativize DIR1 DIR2
+ # computes a relative pathname RELDIR such that DIR1/RELDIR = DIR2.
+ # Input:
+ # - DIR1 relative pathname, relative to the current directory
+ # - DIR2 relative pathname, relative to the current directory
+ # Output:
+ # - reldir relative pathname of DIR2, relative to DIR1
+ func_relativize ()
+ {
+ dir0=`pwd`
+ dir1="$1"
+ dir2="$2"
+ sed_first='s,^\([^/]*\)/.*$,\1,'
+ sed_rest='s,^[^/]*/*,,'
+ sed_last='s,^.*/\([^/]*\)$,\1,'
+ sed_butlast='s,/*[^/]*$,,'
+ while test -n "$dir1"; do
+ first=`echo "$dir1" | sed -e "$sed_first"`
+ if test "$first" != "."; then
+ if test "$first" = ".."; then
+ dir2=`echo "$dir0" | sed -e "$sed_last"`/"$dir2"
+ dir0=`echo "$dir0" | sed -e "$sed_butlast"`
+ else
+ first2=`echo "$dir2" | sed -e "$sed_first"`
+ if test "$first2" = "$first"; then
+ dir2=`echo "$dir2" | sed -e "$sed_rest"`
+ else
+ dir2="../$dir2"
+ fi
+ dir0="$dir0"/"$first"
+ fi
+ fi
+ dir1=`echo "$dir1" | sed -e "$sed_rest"`
+ done
+ reldir="$dir2"
+ }
+
symlink_to_gnulib()
{
src=$GNULIB_SRCDIR/$1
dst=${2-$1}
case $src in
! /*) reldir=$src;;
*)
! case $dst in
! /*) reldir=$src;;
! *) func_relativize "$dst" "$src";;
! esac
esac
test -f "$src" && {
***************
*** 269,276 ****
src_ls=`ls -diL "$src" 2>/dev/null` && set $src_ls && src_i=$1 &&
dst_ls=`ls -diL "$dst" 2>/dev/null` && set $dst_ls && dst_i=$1 &&
test "$src_i" = "$dst_i" || {
! echo "$0: ln -fs $dot_dots$src $dst" &&
! ln -fs "$dot_dots$src" "$dst"
}
}
}
--- 306,313 ----
src_ls=`ls -diL "$src" 2>/dev/null` && set $src_ls && src_i=$1 &&
dst_ls=`ls -diL "$dst" 2>/dev/null` && set $dst_ls && dst_i=$1 &&
test "$src_i" = "$dst_i" || {
! echo "$0: ln -fs $reldir $dst" &&
! ln -fs "$reldir" "$dst"
}
}
}
- symlink calculation in bootstrap script,
Bruno Haible <=