5 # Execute this file to link the executable with fewer direct dependencies.
7 # You shouldn't call this directly; instead, use the configure script's
8 # --enable-link-sh option and run make normally. This isn't enabled by
9 # default because there is the potential for runtime linking problems. If
10 # you have a newer version of GCC, you should prefer the --as-needed linker
11 # flag over this method, though they both should accomplish the same thing.
14 # link.sh -- try linking Vim with different sets of libraries, finding the
15 # minimal set for fastest startup. The problem is that configure adds a few
16 # libraries when they exist, but this doesn't mean they are needed for Vim.
18 # Author: Bram Moolenaar
19 # Last change: 2006 Sep 26
20 # License: Public domain
22 # Warning: This fails miserably if the linker doesn't return an error code!
24 # Otherwise this script is fail-safe, falling back to the original full link
25 # command if anything fails.
27 echo "$LINK " >link.cmd
31 # If .link/link.sed already exists, use it. We assume a previous run of
32 # link.sh has found the correct set of libraries.
34 if test -f .link
/link.
sed; then
35 echo "link.sh: The file '.link/link.sed' exists, which is going to be used now."
36 echo "link.sh: If linking fails, try deleting the .link/link.sed file."
37 echo "link.sh: If this fails too, try creating an empty .link/link.sed file."
40 # If linking works with the full link command, try removing some libraries,
41 # that are known not to be needed on at least one system.
42 # Remove .link/pathdef.c if there is a new link command and compile it again.
43 # There is a loop to remove libraries that appear several times.
46 # - Can't remove Xext; It links fine but will give an error when running gvim
48 # - Don't remove the last -lm: On HP-UX Vim links OK but crashes when the GTK
49 # GUI is started, because the "floor" symbol could not be resolved.
56 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
58 while test -n "$cont"; do
59 if grep "l$libname " linkit.sh
>/dev
/null
; then
60 if test ! -f link1.
sed; then
61 echo "link.sh: OK, linking works, let's try removing a few libraries."
62 echo "link.sh: See .link/link.log for details."
65 echo "s/-l$libname *//" >link1.
sed
66 sed -f .link
/link.
sed <link.cmd
>linkit2.sh
67 sed -f link1.
sed <linkit2.sh
>linkit.sh
69 if test $libname != "m" || grep "lm " linkit.sh
>/dev
/null
; then
70 echo "link.sh: Trying to remove the $libname library..."
71 cat linkit.sh
>>.link
/link.log
72 # Redirect this link output, it may contain error messages which
74 if sh linkit.sh
>>.link
/link.log
2>&1; then
75 echo "link.sh: We don't need the $libname library!"
76 cat link1.
sed >>.link
/link.
sed
78 echo "link.sh: We DO need the $libname library."
92 if test ! -f link1.
sed; then
93 echo "link.sh: Linked fine, no libraries can be removed"
102 # Now do the real linking.
104 if test -s .link
/link.
sed; then
105 echo "link.sh: Using .link/link.sed file to remove a few libraries"
106 sed -f .link
/link.
sed <link.cmd
>linkit.sh
108 if sh linkit.sh
; then
110 echo "link.sh: Linked fine with a few libraries removed"
113 echo "link.sh: Linking failed, making .link/link.sed empty and trying again"
114 mv -f .link
/link.
sed link2.
sed
118 if test -f .link
/link.
sed -a ! -s .link
/link.
sed -a ! -f link3.
sed; then
119 echo "link.sh: Using unmodified link command"
123 echo "link.sh: Linked OK"
126 if test -f link2.
sed; then
127 echo "link.sh: Linking doesn't work at all, removing .link/link.sed"
136 rm -f link.cmd linkit.sh link1.
sed link2.
sed link3.
sed linkit2.sh
139 # return an error code if something went wrong