incorporated vim's link.sh; -i arg reports commit
[chaz/yoink] / link.sh
1 #!/bin/sh
2
3 #
4 # Yoink
5 # Execute this file to link the executable with fewer direct dependencies.
6 #
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.
12 #
13
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.
17 #
18 # Author: Bram Moolenaar
19 # Last change: 2006 Sep 26
20 # License: Public domain
21 #
22 # Warning: This fails miserably if the linker doesn't return an error code!
23 #
24 # Otherwise this script is fail-safe, falling back to the original full link
25 # command if anything fails.
26
27 echo "$LINK " >link.cmd
28 exit_value=0
29
30 #
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.
33 #
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."
38 else
39
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.
44 #
45 # Notes:
46 # - Can't remove Xext; It links fine but will give an error when running gvim
47 # with Motif.
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.
50 #
51 cat link.cmd
52 if sh link.cmd; then
53 mkdir -p .link
54 touch .link/link.sed
55 cp link.cmd linkit.sh
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
57 cont=yes
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."
63 rm -f .link/link.log
64 fi
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
68 # keep the last -lm
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
73 # should be ignored.
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
77 else
78 echo "link.sh: We DO need the $libname library."
79 cont=
80 cp link.cmd linkit.sh
81 fi
82 else
83 cont=
84 cp link.cmd linkit.sh
85 fi
86 else
87 cont=
88 cp link.cmd linkit.sh
89 fi
90 done
91 done
92 if test ! -f link1.sed; then
93 echo "link.sh: Linked fine, no libraries can be removed"
94 touch link3.sed
95 fi
96 else
97 exit_value=$?
98 fi
99 fi
100
101 #
102 # Now do the real linking.
103 #
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
107 cat linkit.sh
108 if sh linkit.sh; then
109 exit_value=0
110 echo "link.sh: Linked fine with a few libraries removed"
111 else
112 exit_value=$?
113 echo "link.sh: Linking failed, making .link/link.sed empty and trying again"
114 mv -f .link/link.sed link2.sed
115 touch .link/link.sed
116 fi
117 fi
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"
120 cat link.cmd
121 if sh link.cmd; then
122 exit_value=0
123 echo "link.sh: Linked OK"
124 else
125 exit_value=$?
126 if test -f link2.sed; then
127 echo "link.sh: Linking doesn't work at all, removing .link/link.sed"
128 rm -f .link/link.sed
129 fi
130 fi
131 fi
132
133 #
134 # cleanup
135 #
136 rm -f link.cmd linkit.sh link1.sed link2.sed link3.sed linkit2.sh
137
138 #
139 # return an error code if something went wrong
140 #
141 exit $exit_value
142
This page took 0.03469 seconds and 4 git commands to generate.