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"
56 extralibs="$extralibs -lrt -lpthread -lsocket -lnsl"
57 # Record paths to shared libraries to avoid needing LD_LIBRARY_PATH
62 s=`echo $i | sed 's/-L/-R/'`
63 extralibs="$extralibs $s"
67 case "${SYSVERSION:-`uname -r`}" in
69 echo do not know how to link right thread library on "$tag" 1>&2
72 # Some trickery is needed to force use of
73 # alternate thread lib from /usr/lib/lwp
74 # Likely, this only works with sun cc,
75 # for other compiler/loader we would need other flags.
77 extralibs="$extralibs /usr/lib/lwp/libthread.so -R/usr/lib/lwp:/usr/lib"
86 echo do not know how to link on "$tag" 1>&2
95 elif [ "x$1" = "x-v" ]
118 l=`echo $i | sed 's/-L//'`
125 echo "ofiles $ofiles"
126 echo "lpaths $lpaths"
130 if [ "x$ofiles" != "x" ]
133 nm $nmflags $ofiles |
134 grep '__p9l_autolib_[a-zA-Z0-9+-]*$' |
135 sed 's/.*__p9l_autolib_//' |
140 autolibs="$autolibs $i"
146 echo "autolibs1 $autolibs"
149 # fetch dependencies out of libraries
151 while [ "x$workq" != "x" ]
157 # can't trust the libraries about using
158 # libthread or libdraw - we might not be linking with
159 # those object files.
164 nm $lpath/lib$i.a 2>/dev/null |
165 grep '__p9l_autolib_[a-zA-Z0-9+-]*$' |
166 sed 's/.*__p9l_autolib_//' |
168 egrep -v '^(thread|draw)$'
172 # fix up libraries that really need draw
173 if [ "x$i" = "xmemdraw" -o "x$i" = "xmemlayer" -o "x$i" = "xframe" ]
180 if eval "[ x\$need$j = x ]"
182 autolibs="$autolibs $j"
188 okayfn="$okayfn && have$j"
193 echo "can$i: $okayfn"
195 eval "can$i() { $okayfn; }"
200 echo "autolibs $autolibs"
205 eval "have$i() { false; }"
207 havethread() { false; }
209 canmemlayer() { havedraw; }
211 # now find correct order
213 while [ "x$autolibs" != x ]
222 eval "have$i() { true; }"
225 stillneed="$stillneed $i"
228 # break cycle by setting the last library on the list
229 # to have no dependencies
237 echo "dependency cycle: $autolibs; breaking with $j"
238 eval "can$j() { true; }"
240 autolibs="$stillneed"
244 echo "liborder $libsl"
248 # cycle: lib9 expects p9main, which is defined in libthread. oops.
251 libsl="$libsl -lthread -l9"
254 # cycle: lib9 netcrypt uses libsec
257 libsl="$libsl -lsec -l9"
260 if [ "x$needndb" = xtrue -a '(' -f /usr/lib/libresolv.a -o -f /usr/lib/libresolv.dylib ')' ]
262 libsl="$libsl -lresolv"
265 if [ "x$needX11" = xtrue -a "x$WSYSTYPE" != xnowsys ]
271 # x86_64 seems to put its 64-bit libraries in lib64.
272 if [ "${OBJTYPE:-`uname -m`}" = "x86_64" ]
274 libsl="$libsl -L$X11/lib64"
276 libsl="$libsl -L$X11/lib -lX11"
291 # echo "ofiles $ofiles"
293 if [ "x$ofiles" != "x" ]
297 grep '__p9l_autoframework_[a-zA-Z0-9+-]*$' |
298 sed 's/.*__p9l_autoframework_//' |
303 autoframeworks="$autoframeworks $i"
310 echo "autoframeworks $autoframeworks"
313 for i in $autoframeworks
315 eval "have$i() { false; }"
319 for i in $autoframeworks
321 frameworks="-framework $i $frameworks"
331 s=`echo $i | sed 's/-L/-Wl,-rpath,/'`
332 extralibs="$extralibs $s"
341 echo $ld -L$PLAN9/lib "$@" $libsl $extralibs $frameworks
344 xtmp=/tmp/9l.$$.$USER.out
346 sed 's/.*: In function `[^:]*: *//' $xtmp | egrep . |
347 egrep -v 'is (often|almost always) misused|is dangerous, better use'
351 if $ld -L$PLAN9/lib "$@" $libsl $extralibs $frameworks >$xtmp 2>&1