#!/bin/sh # # Yoink # Run this script to link the executable with fewer direct dependencies. # # You shouldn't call this directly; instead, use the configure script's # --enable-link-sh option and run make normally. This isn't enabled by # default because there is the potential for runtime linking problems on # some platforms. If you have a newer version of GCC, you should prefer # the --as-needed linker flag over this method, though they both should # accomplish the same thing. # # This script was adapted from some public domain code written by Bram # Moolenaar for Vim. The only input needed is the link command in the # variable LINK. It is expected that the linker will return an error code # or this will not work. The script caches the test results in the # `.link/link.sed' file; delete that file if you want to redetermine the # required direct dependencies. # # List here any libraries that are known to not be needed on some platform. libraries="\ 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 \ pthread \ vorbis \ $THE_END" 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 fi if test -s $sedfile then printlog "Using $sedfile file to remove a few libraries." sed -f $sedfile <$cmdfile >$runfile cat $runfile if sh $runfile then exitcode=0 printlog "Linked fine with a few libraries removed." else exitcode=$? printlog "Linking failed, making $sedfile empty and trying again." mv -f $sedfile $tmpfile2 touch $sedfile fi fi if test -f $sedfile -a ! -s $sedfile -a ! -f $tmpfile3 then printlog "Using unmodified link command." cat $cmdfile if sh $cmdfile then exitcode=0 printlog "Linked OK." else exitcode=$? if test -f $tmpfile2 then printlog "Linking doesn't work at all, removing $sedfile." rm -f $sedfile fi fi fi rm -rf "$workdir" exit $exitcode