blob: 6e5c50f74d8d01031ffbb18bf19a7438ce673ff0 [file] [log] [blame]
Bram Moolenaar071d4272004-06-13 20:20:40 +00001#! /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
Bram Moolenaar22e193d2010-11-03 22:32:24 +01008# Last change: 2010 Nov 03
Bram Moolenaarc81e5e72007-05-05 18:24:42 +00009# License: Public domain
Bram Moolenaar071d4272004-06-13 20:20:40 +000010#
11# Warning: This fails miserably if the linker doesn't return an error code!
12#
13# Otherwise this script is fail-safe, falling back to the original full link
14# command if anything fails.
15
Yee Cheng Chin5d035252023-10-15 09:50:53 +020016echo "$LINK " >link_$PROG.cmd
Bram Moolenaar071d4272004-06-13 20:20:40 +000017exit_value=0
18
Bram Moolenaar22e193d2010-11-03 22:32:24 +010019if test "$LINK_AS_NEEDED" = yes; then
20 echo "link.sh: \$LINK_AS_NEEDED set to 'yes': invoking linker directly."
Yee Cheng Chin5d035252023-10-15 09:50:53 +020021 cat link_$PROG.cmd
22 if sh link_$PROG.cmd; then
Bram Moolenaar22e193d2010-11-03 22:32:24 +010023 exit_value=0
24 echo "link.sh: Linked fine"
25 else
26 exit_value=$?
27 echo "link.sh: Linking failed"
28 fi
29else
30 if test -f auto/link.sed; then
31
Bram Moolenaar071d4272004-06-13 20:20:40 +000032#
33# If auto/link.sed already exists, use it. We assume a previous run of
34# link.sh has found the correct set of libraries.
35#
Bram Moolenaar071d4272004-06-13 20:20:40 +000036 echo "link.sh: The file 'auto/link.sed' exists, which is going to be used now."
37 echo "link.sh: If linking fails, try deleting the auto/link.sed file."
38 echo "link.sh: If this fails too, try creating an empty auto/link.sed file."
39else
40
41# If linking works with the full link command, try removing some libraries,
42# that are known not to be needed on at least one system.
43# Remove auto/pathdef.c if there is a new link command and compile it again.
44# There is a loop to remove libraries that appear several times.
45#
46# Notes:
47# - Can't remove Xext; It links fine but will give an error when running gvim
48# with Motif.
49# - Don't remove the last -lm: On HP-UX Vim links OK but crashes when the GTK
50# GUI is started, because the "floor" symbol could not be resolved.
51#
Yee Cheng Chin5d035252023-10-15 09:50:53 +020052 cat link_$PROG.cmd
53 if sh link_$PROG.cmd; then
Bram Moolenaar071d4272004-06-13 20:20:40 +000054 touch auto/link.sed
Yee Cheng Chin5d035252023-10-15 09:50:53 +020055 cp link_$PROG.cmd linkit_$PROG.sh
youcai1acc67a2024-05-30 19:31:36 +020056 for libname in SM ICE nsl dnet dnet_stub inet socket dir iconv Xt Xmu Xp Xpm X11 Xdmcp x w perl dl pthread thread readline m crypt attr; do
Bram Moolenaar071d4272004-06-13 20:20:40 +000057 cont=yes
58 while test -n "$cont"; do
Yee Cheng Chin5d035252023-10-15 09:50:53 +020059 if grep "l$libname " linkit_$PROG.sh >/dev/null; then
60 if test ! -f link1_$PROG.sed; then
Bram Moolenaar63235082010-05-18 21:41:09 +020061 echo "link.sh: OK, linking works, let's try omitting a few libraries."
Bram Moolenaar071d4272004-06-13 20:20:40 +000062 echo "link.sh: See auto/link.log for details."
63 rm -f auto/link.log
64 fi
Yee Cheng Chin5d035252023-10-15 09:50:53 +020065 echo "s/-l$libname *//" >link1_$PROG.sed
66 sed -f auto/link.sed <link_$PROG.cmd >linkit2_$PROG.sh
67 sed -f link1_$PROG.sed <linkit2_$PROG.sh >linkit_$PROG.sh
Bram Moolenaar071d4272004-06-13 20:20:40 +000068 # keep the last -lm
Yee Cheng Chin5d035252023-10-15 09:50:53 +020069 if test $libname != "m" || grep "lm " linkit_$PROG.sh >/dev/null; then
Bram Moolenaar63235082010-05-18 21:41:09 +020070 echo "link.sh: Trying to omit the $libname library..."
Yee Cheng Chin5d035252023-10-15 09:50:53 +020071 cat linkit_$PROG.sh >>auto/link.log
Bram Moolenaar071d4272004-06-13 20:20:40 +000072 # Redirect this link output, it may contain error messages which
73 # should be ignored.
Yee Cheng Chin5d035252023-10-15 09:50:53 +020074 if sh linkit_$PROG.sh >>auto/link.log 2>&1; then
Bram Moolenaar63235082010-05-18 21:41:09 +020075 echo "link.sh: Vim doesn't need the $libname library!"
Yee Cheng Chin5d035252023-10-15 09:50:53 +020076 cat link1_$PROG.sed >>auto/link.sed
Bram Moolenaar071d4272004-06-13 20:20:40 +000077 rm -f auto/pathdef.c
78 else
Bram Moolenaar63235082010-05-18 21:41:09 +020079 echo "link.sh: Vim DOES need the $libname library."
Bram Moolenaar071d4272004-06-13 20:20:40 +000080 cont=
Yee Cheng Chin5d035252023-10-15 09:50:53 +020081 cp link_$PROG.cmd linkit_$PROG.sh
Bram Moolenaar071d4272004-06-13 20:20:40 +000082 fi
83 else
84 cont=
Yee Cheng Chin5d035252023-10-15 09:50:53 +020085 cp link_$PROG.cmd linkit_$PROG.sh
Bram Moolenaar071d4272004-06-13 20:20:40 +000086 fi
87 else
88 cont=
Yee Cheng Chin5d035252023-10-15 09:50:53 +020089 cp link_$PROG.cmd linkit_$PROG.sh
Bram Moolenaar071d4272004-06-13 20:20:40 +000090 fi
91 done
92 done
93 if test ! -f auto/pathdef.c; then
94 $MAKE objects/pathdef.o
95 fi
Yee Cheng Chin5d035252023-10-15 09:50:53 +020096 if test ! -f link1_$PROG.sed; then
Bram Moolenaar63235082010-05-18 21:41:09 +020097 echo "link.sh: Linked fine, no libraries can be omitted"
Yee Cheng Chin5d035252023-10-15 09:50:53 +020098 touch link3_$PROG.sed
Bram Moolenaar071d4272004-06-13 20:20:40 +000099 fi
100 else
101 exit_value=$?
102 fi
103fi
104
105#
106# Now do the real linking.
107#
108if test -s auto/link.sed; then
Bram Moolenaar63235082010-05-18 21:41:09 +0200109 echo "link.sh: Using auto/link.sed file to omit a few libraries"
Yee Cheng Chin5d035252023-10-15 09:50:53 +0200110 sed -f auto/link.sed <link_$PROG.cmd >linkit_$PROG.sh
111 cat linkit_$PROG.sh
112 if sh linkit_$PROG.sh; then
Bram Moolenaar071d4272004-06-13 20:20:40 +0000113 exit_value=0
Bram Moolenaar63235082010-05-18 21:41:09 +0200114 echo "link.sh: Linked fine with a few libraries omitted"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000115 else
116 exit_value=$?
117 echo "link.sh: Linking failed, making auto/link.sed empty and trying again"
Yee Cheng Chin5d035252023-10-15 09:50:53 +0200118 mv -f auto/link.sed link2_$PROG.sed
Bram Moolenaar071d4272004-06-13 20:20:40 +0000119 touch auto/link.sed
120 rm -f auto/pathdef.c
121 $MAKE objects/pathdef.o
122 fi
123fi
Yee Cheng Chin5d035252023-10-15 09:50:53 +0200124if test -f auto/link.sed -a ! -s auto/link.sed -a ! -f link3_$PROG.sed; then
Bram Moolenaar071d4272004-06-13 20:20:40 +0000125 echo "link.sh: Using unmodified link command"
Yee Cheng Chin5d035252023-10-15 09:50:53 +0200126 cat link_$PROG.cmd
127 if sh link_$PROG.cmd; then
Bram Moolenaar071d4272004-06-13 20:20:40 +0000128 exit_value=0
129 echo "link.sh: Linked OK"
130 else
131 exit_value=$?
Yee Cheng Chin5d035252023-10-15 09:50:53 +0200132 if test -f link2_$PROG.sed; then
Bram Moolenaar071d4272004-06-13 20:20:40 +0000133 echo "link.sh: Linking doesn't work at all, removing auto/link.sed"
134 rm -f auto/link.sed
135 fi
136 fi
137fi
138
Bram Moolenaar22e193d2010-11-03 22:32:24 +0100139fi
140
Bram Moolenaar071d4272004-06-13 20:20:40 +0000141#
142# cleanup
143#
Yee Cheng Chin5d035252023-10-15 09:50:53 +0200144rm -f link_$PROG.cmd linkit_$PROG.sh link1_$PROG.sed link2_$PROG.sed \
145 link3_$PROG.sed linkit2_$PROG.sh
Bram Moolenaar071d4272004-06-13 20:20:40 +0000146
147#
148# return an error code if something went wrong
149#
150exit $exit_value
151
152# vim:set sw=2 et: