7
|
1 #! /bin/sh
|
|
2 #
|
|
3 # link.sh -- try linking Vim with different sets of libraries, finding the
|
|
4 # minimal set for fastest startup. The problem is that configure adds a few
|
|
5 # libraries when they exist, but this doesn't mean they are needed for Vim.
|
|
6 #
|
|
7 # Author: Bram Moolenaar
|
137
|
8 # Last change: 2005 Jan 25
|
7
|
9 #
|
|
10 # Warning: This fails miserably if the linker doesn't return an error code!
|
|
11 #
|
|
12 # Otherwise this script is fail-safe, falling back to the original full link
|
|
13 # command if anything fails.
|
|
14
|
|
15 echo "$LINK " >link.cmd
|
|
16 exit_value=0
|
|
17
|
|
18 #
|
|
19 # If auto/link.sed already exists, use it. We assume a previous run of
|
|
20 # link.sh has found the correct set of libraries.
|
|
21 #
|
|
22 if test -f auto/link.sed; then
|
|
23 echo "link.sh: The file 'auto/link.sed' exists, which is going to be used now."
|
|
24 echo "link.sh: If linking fails, try deleting the auto/link.sed file."
|
|
25 echo "link.sh: If this fails too, try creating an empty auto/link.sed file."
|
|
26 else
|
|
27
|
|
28 # If linking works with the full link command, try removing some libraries,
|
|
29 # that are known not to be needed on at least one system.
|
|
30 # Remove auto/pathdef.c if there is a new link command and compile it again.
|
|
31 # There is a loop to remove libraries that appear several times.
|
|
32 #
|
|
33 # Notes:
|
|
34 # - Can't remove Xext; It links fine but will give an error when running gvim
|
|
35 # with Motif.
|
|
36 # - Don't remove the last -lm: On HP-UX Vim links OK but crashes when the GTK
|
|
37 # GUI is started, because the "floor" symbol could not be resolved.
|
|
38 #
|
|
39 cat link.cmd
|
|
40 if sh link.cmd; then
|
|
41 touch auto/link.sed
|
|
42 cp link.cmd linkit.sh
|
|
43 for libname in SM ICE nsl dnet dnet_stub inet socket dir elf iconv Xt Xmu Xp Xpm X11 Xdmcp x w dl pthread thread readline m perl crypt attr; do
|
|
44 cont=yes
|
|
45 while test -n "$cont"; do
|
|
46 if grep "l$libname " linkit.sh >/dev/null; then
|
|
47 if test ! -f link1.sed; then
|
|
48 echo "link.sh: OK, linking works, let's try removing a few libraries."
|
|
49 echo "link.sh: See auto/link.log for details."
|
|
50 rm -f auto/link.log
|
|
51 fi
|
|
52 echo "s/-l$libname *//" >link1.sed
|
|
53 sed -f auto/link.sed <link.cmd >linkit2.sh
|
|
54 sed -f link1.sed <linkit2.sh >linkit.sh
|
|
55 # keep the last -lm
|
|
56 if test $libname != "m" || grep "lm " linkit.sh >/dev/null; then
|
|
57 echo "link.sh: Trying to remove the $libname library..."
|
|
58 cat linkit.sh >>auto/link.log
|
|
59 # Redirect this link output, it may contain error messages which
|
|
60 # should be ignored.
|
|
61 if sh linkit.sh >>auto/link.log 2>&1; then
|
|
62 echo "link.sh: We don't need the $libname library!"
|
|
63 cat link1.sed >>auto/link.sed
|
|
64 rm -f auto/pathdef.c
|
|
65 else
|
|
66 echo "link.sh: We DO need the $libname library."
|
|
67 cont=
|
|
68 cp link.cmd linkit.sh
|
|
69 fi
|
|
70 else
|
|
71 cont=
|
|
72 cp link.cmd linkit.sh
|
|
73 fi
|
|
74 else
|
|
75 cont=
|
|
76 cp link.cmd linkit.sh
|
|
77 fi
|
|
78 done
|
|
79 done
|
|
80 if test ! -f auto/pathdef.c; then
|
|
81 $MAKE objects/pathdef.o
|
|
82 fi
|
|
83 if test ! -f link1.sed; then
|
|
84 echo "link.sh: Linked fine, no libraries can be removed"
|
|
85 touch link3.sed
|
|
86 fi
|
|
87 else
|
|
88 exit_value=$?
|
|
89 fi
|
|
90 fi
|
|
91
|
|
92 #
|
|
93 # Now do the real linking.
|
|
94 #
|
|
95 if test -s auto/link.sed; then
|
|
96 echo "link.sh: Using auto/link.sed file to remove a few libraries"
|
|
97 sed -f auto/link.sed <link.cmd >linkit.sh
|
|
98 cat linkit.sh
|
|
99 if sh linkit.sh; then
|
|
100 exit_value=0
|
|
101 echo "link.sh: Linked fine with a few libraries removed"
|
|
102 else
|
|
103 exit_value=$?
|
|
104 echo "link.sh: Linking failed, making auto/link.sed empty and trying again"
|
|
105 mv -f auto/link.sed link2.sed
|
|
106 touch auto/link.sed
|
|
107 rm -f auto/pathdef.c
|
|
108 $MAKE objects/pathdef.o
|
|
109 fi
|
|
110 fi
|
|
111 if test -f auto/link.sed -a ! -s auto/link.sed -a ! -f link3.sed; then
|
|
112 echo "link.sh: Using unmodified link command"
|
|
113 cat link.cmd
|
|
114 if sh link.cmd; then
|
|
115 exit_value=0
|
|
116 echo "link.sh: Linked OK"
|
|
117 else
|
|
118 exit_value=$?
|
|
119 if test -f link2.sed; then
|
|
120 echo "link.sh: Linking doesn't work at all, removing auto/link.sed"
|
|
121 rm -f auto/link.sed
|
|
122 fi
|
|
123 fi
|
|
124 fi
|
|
125
|
|
126 #
|
|
127 # cleanup
|
|
128 #
|
|
129 rm -f link.cmd linkit.sh link1.sed link2.sed link3.sed linkit2.sh
|
|
130
|
|
131 #
|
|
132 # return an error code if something went wrong
|
|
133 #
|
|
134 exit $exit_value
|
|
135
|
|
136 # vim:set sw=2 et:
|