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