]> Dogcows Code - chaz/yoink/blob - link.sh
port new sockets stuff to winsock
[chaz/yoink] / link.sh
1 #!/bin/sh
2
3 #
4 # Yoink
5 # Run this script 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 on
10 # some platforms. If you have a newer version of GCC, you should prefer
11 # the --as-needed linker flag over this method, though they both should
12 # accomplish the same thing.
13 #
14 # This script was adapted from some public domain code written by Bram
15 # Moolenaar for Vim. The only input needed is the link command in the
16 # variable LINK. It is expected that the linker will return an error code
17 # or this will not work. The script caches the test results in the
18 # `.link/link.sed' file; delete that file if you want to redetermine the
19 # required direct dependencies.
20 #
21
22
23 # List here any libraries that are known to not be needed on some platform.
24 libraries="\
25 atk-1.0 \
26 cairo \
27 fontconfig \
28 freetype \
29 gdk-x11-2.0 \
30 gio-2.0 \
31 glib-2.0 \
32 gmodule-2.0 \
33 ogg \
34 pango-1.0 \
35 pangocairo-1.0 \
36 pangoft2-1.0 \
37 pthread \
38 vorbis \
39 $THE_END"
40
41
42 linkdir=".link"
43 logfile="$linkdir/link.log"
44 sedfile="$linkdir/link.sed"
45
46 workdir=$(mktemp -d tmp.XXXXXXXX)
47 cmdfile="$workdir/link.cmd"
48 runfile="$workdir/link.run"
49
50 tmpfile1="$workdir/link.tmp1"
51 tmpfile2="$workdir/link.tmp2"
52 tmpfile3="$workdir/link.tmp3"
53
54
55 printlog()
56 {
57 echo "link.sh: $@"
58 }
59
60 echo "$LINK " >$cmdfile
61 exitcode=0
62
63
64 if test -f $sedfile
65 then
66 printlog "The file $sedfile exists, which is now going to be used."
67 printlog "If linking fails, try deleting the $sedfile file."
68 printlog "If that fails, try creating an empty $sedfile file."
69 printlog "If that fails, configure the package with --disable-link-sh."
70 else
71 cat $cmdfile
72 if sh $cmdfile
73 then
74 mkdir -p $linkdir
75 touch $sedfile
76 cp $cmdfile $runfile
77 for libname in $libraries
78 do
79 cont=yes
80 while test -n "$cont"
81 do
82 if grep "l$libname " $runfile >/dev/null
83 then
84 if test ! -f $tmpfile1
85 then
86 printlog "Full linking works; now the fun begins."
87 printlog "See $logfile for details."
88 rm -f $logfile
89 fi
90 echo "s/-l$libname *//" >$tmpfile1
91 sed -f $sedfile <$cmdfile | sed -f $tmpfile1 >$runfile
92 # keep the last -lm; this is supposedly needed by HP-UX
93 if test $libname != "m" || grep "lm " $runfile >/dev/null
94 then
95 printlog "Trying to remove the $libname library..."
96 cat $runfile >>$logfile
97 if sh $runfile >>$logfile 2>&1
98 then
99 printlog "We don't need the $libname library!"
100 cat $tmpfile1 >>$sedfile
101 continue
102 else
103 printlog "We DO need the $libname library."
104 fi
105 fi
106 fi
107 cont=
108 cp $cmdfile $runfile
109 done
110 done
111 if test ! -f $tmpfile1
112 then
113 printlog "Linked fine, no libraries can be removed."
114 touch $tmpfile3
115 fi
116 else
117 exitcode=$?
118 fi
119 fi
120
121
122 if test -s $sedfile
123 then
124 printlog "Using $sedfile file to remove a few libraries."
125 sed -f $sedfile <$cmdfile >$runfile
126 cat $runfile
127 if sh $runfile
128 then
129 exitcode=0
130 printlog "Linked fine with a few libraries removed."
131 else
132 exitcode=$?
133 printlog "Linking failed, making $sedfile empty and trying again."
134 mv -f $sedfile $tmpfile2
135 touch $sedfile
136 fi
137 fi
138
139 if test -f $sedfile -a ! -s $sedfile -a ! -f $tmpfile3
140 then
141 printlog "Using unmodified link command."
142 cat $cmdfile
143 if sh $cmdfile
144 then
145 exitcode=0
146 printlog "Linked OK."
147 else
148 exitcode=$?
149 if test -f $tmpfile2
150 then
151 printlog "Linking doesn't work at all, removing $sedfile."
152 rm -f $sedfile
153 fi
154 fi
155 fi
156
157
158 rm -rf "$workdir"
159 exit $exitcode
160
This page took 0.035098 seconds and 4 git commands to generate.