-# If linking works with the full link command, try removing some libraries,
-# that are known not to be needed on at least one system.
-# Remove .link/pathdef.c if there is a new link command and compile it again.
-# There is a loop to remove libraries that appear several times.
-#
-# Notes:
-# - Can't remove Xext; It links fine but will give an error when running gvim
-# with Motif.
-# - Don't remove the last -lm: On HP-UX Vim links OK but crashes when the GTK
-# GUI is started, because the "floor" symbol could not be resolved.
-#
- cat link.cmd
- if sh link.cmd; then
- mkdir -p .link
- touch .link/link.sed
- cp link.cmd linkit.sh
- for libname in atk-1.0 cairo fontconfig freetype gdk-x11-2.0 gio-2.0 glib-2.0 gmodule-2.0 ogg pango-1.0 pangocairo-1.0 pangoft2-1.0 vorbis; do
- cont=yes
- while test -n "$cont"; do
- if grep "l$libname " linkit.sh >/dev/null; then
- if test ! -f link1.sed; then
- echo "link.sh: OK, linking works, let's try removing a few libraries."
- echo "link.sh: See .link/link.log for details."
- rm -f .link/link.log
- fi
- echo "s/-l$libname *//" >link1.sed
- sed -f .link/link.sed <link.cmd >linkit2.sh
- sed -f link1.sed <linkit2.sh >linkit.sh
- # keep the last -lm
- if test $libname != "m" || grep "lm " linkit.sh >/dev/null; then
- echo "link.sh: Trying to remove the $libname library..."
- cat linkit.sh >>.link/link.log
- # Redirect this link output, it may contain error messages which
- # should be ignored.
- if sh linkit.sh >>.link/link.log 2>&1; then
- echo "link.sh: We don't need the $libname library!"
- cat link1.sed >>.link/link.sed
- else
- echo "link.sh: We DO need the $libname library."
- cont=
- cp link.cmd linkit.sh
- fi
- else
- cont=
- cp link.cmd linkit.sh
- fi
- else
- cont=
- cp link.cmd linkit.sh
- fi
- done
- done
- if test ! -f link1.sed; then
- echo "link.sh: Linked fine, no libraries can be removed"
- touch link3.sed
- fi
- else
- exit_value=$?
- fi
+linkdir=".link"
+logfile="$linkdir/link.log"
+sedfile="$linkdir/link.sed"
+
+workdir=$(mktemp -d tmp.XXXXXXXX)
+cmdfile="$workdir/link.cmd"
+runfile="$workdir/link.run"
+
+tmpfile1="$workdir/link.tmp1"
+tmpfile2="$workdir/link.tmp2"
+tmpfile3="$workdir/link.tmp3"
+
+
+printlog()
+{
+ echo "link.sh: $@"
+}
+
+echo "$LINK " >$cmdfile
+exitcode=0
+
+
+if test -f $sedfile
+then
+ printlog "The file $sedfile exists, which is now going to be used."
+ printlog "If linking fails, try deleting the $sedfile file."
+ printlog "If that fails, try creating an empty $sedfile file."
+ printlog "If that fails, configure the package with --disable-link-sh."
+else
+ cat $cmdfile
+ if sh $cmdfile
+ then
+ mkdir -p $linkdir
+ touch $sedfile
+ cp $cmdfile $runfile
+ for libname in $libraries
+ do
+ cont=yes
+ while test -n "$cont"
+ do
+ if grep "l$libname " $runfile >/dev/null
+ then
+ if test ! -f $tmpfile1
+ then
+ printlog "Full linking works; now the fun begins."
+ printlog "See $logfile for details."
+ rm -f $logfile
+ fi
+ echo "s/-l$libname *//" >$tmpfile1
+ sed -f $sedfile <$cmdfile | sed -f $tmpfile1 >$runfile
+ # keep the last -lm; this is supposedly needed by HP-UX
+ if test $libname != "m" || grep "lm " $runfile >/dev/null
+ then
+ printlog "Trying to remove the $libname library..."
+ cat $runfile >>$logfile
+ if sh $runfile >>$logfile 2>&1
+ then
+ printlog "We don't need the $libname library!"
+ cat $tmpfile1 >>$sedfile
+ continue
+ else
+ printlog "We DO need the $libname library."
+ fi
+ fi
+ fi
+ cont=
+ cp $cmdfile $runfile
+ done
+ done
+ if test ! -f $tmpfile1
+ then
+ printlog "Linked fine, no libraries can be removed."
+ touch $tmpfile3
+ fi
+ else
+ exitcode=$?
+ fi