3 test -f $PLAN9/config && . $PLAN9/config
12 tag="${SYSNAME:-`uname`}-${OBJTYPE:-`uname -m`}"
17 extralibs="$extralibs -lutil"
20 extralibs="$extralibs -lkse"
23 extralibs="$extralibs -lpthread"
30 extralibs="$extralibs -lutil"
35 extralibs="$extralibs -lutil"
41 extralibs="$extralibs -lutil"
42 case "${SYSVERSION:-`uname -r`}" in
44 extralibs="$extralibs -lpthread"
53 extralibs="$extralibs -lrt -lpthread -lsocket -lnsl"
54 # Record paths to shared libraries to avoid needing LD_LIBRARY_PATH
59 s=`echo $i | sed 's/-L/-R/'`
60 extralibs="$extralibs $s"
64 case "${SYSVERSION:-`uname -r`}" in
66 echo do not know how to link right thread library on "$tag" 1>&2
69 # Some trickery is needed to force use of
70 # alternate thread lib from /usr/lib/lwp
71 # Likely, this only works with sun cc,
72 # for other compiler/loader we would need other flags.
74 extralibs="$extralibs /usr/lib/lwp/libthread.so -R/usr/lib/lwp:/usr/lib"
83 echo do not know how to link on "$tag" 1>&2
92 elif [ "x$1" = "x-v" ]
115 l=`echo $i | sed 's/-L//'`
122 echo "ofiles $ofiles"
123 echo "lpaths $lpaths"
127 if [ "x$ofiles" != "x" ]
130 nm $nmflags $ofiles |
131 grep '__p9l_autolib_[a-zA-Z0-9+-]*$' |
132 sed 's/.*__p9l_autolib_//' |
137 autolibs="$autolibs $i"
143 echo "autolibs1 $autolibs"
146 # fetch dependencies out of libraries
148 while [ "x$workq" != "x" ]
154 # can't trust the libraries about using
155 # libthread or libdraw - we might not be linking with
156 # those object files.
161 nm $lpath/lib$i.a 2>/dev/null |
162 grep '__p9l_autolib_[a-zA-Z0-9+-]*$' |
163 sed 's/.*__p9l_autolib_//' |
165 egrep -v '^(thread|draw)$'
169 # fix up libraries that really need draw
170 if [ "x$i" = "xmemdraw" -o "x$i" = "xmemlayer" -o "x$i" = "xframe" ]
177 if eval "[ x\$need$j = x ]"
179 autolibs="$autolibs $j"
185 okayfn="$okayfn && have$j"
190 echo "can$i: $okayfn"
192 eval "can$i() { $okayfn; }"
197 echo "autolibs $autolibs"
202 eval "have$i() { false; }"
204 havethread() { false; }
206 canmemlayer() { havedraw; }
208 # now find correct order
210 while [ "x$autolibs" != x ]
219 eval "have$i() { true; }"
222 stillneed="$stillneed $i"
225 # break cycle by setting the last library on the list
226 # to have no dependencies
234 echo "dependency cycle: $autolibs; breaking with $j"
235 eval "can$j() { true; }"
237 autolibs="$stillneed"
241 echo "liborder $libsl"
245 # cycle: lib9 expects p9main, which is defined in libthread. oops.
248 libsl="$libsl -lthread -l9"
251 # cycle: lib9 netcrypt uses libsec
254 libsl="$libsl -lsec -l9"
257 if [ "x$needndb" = xtrue -a '(' -f /usr/lib/libresolv.a -o -f /usr/lib/libresolv.dylib ')' ]
259 libsl="$libsl -lresolv"
262 if [ "x$needX11" = xtrue -a "x$WSYSTYPE" != xnowsys ]
268 # x86_64 seems to put its 64-bit libraries in lib64.
269 if [ "${OBJTYPE:-`uname -m`}" = "x86_64" ]
271 libsl="$libsl -L$X11/lib64"
273 libsl="$libsl -L$X11/lib -lX11"
288 # echo "ofiles $ofiles"
290 if [ "x$ofiles" != "x" ]
294 grep '__p9l_autoframework_[a-zA-Z0-9+-]*$' |
295 sed 's/.*__p9l_autoframework_//' |
300 autoframeworks="$autoframeworks $i"
307 echo "autoframeworks $autoframeworks"
310 for i in $autoframeworks
312 eval "have$i() { false; }"
316 for i in $autoframeworks
318 frameworks="-framework $i $frameworks"
328 s=`echo $i | sed 's/-L/-Wl,-rpath,/'`
329 extralibs="$extralibs $s"
338 echo $ld -L$PLAN9/lib "$@" $libsl $extralibs $frameworks
341 xtmp=/tmp/9l.$$.$USER.out
343 sed 's/.*: In function `[^:]*: *//' $xtmp | egrep . |
344 egrep -v 'is (often|almost always) misused|is dangerous, better use'
348 if $ld -L$PLAN9/lib "$@" $libsl $extralibs $frameworks >$xtmp 2>&1