3 test -f $PLAN9/config && . $PLAN9/config
12 tag="${SYSNAME:-`uname`}-${OBJTYPE:-`uname -m`}"
17 extralibs="$extralibs -lutil"
22 extralibs="$extralibs -lutil"
28 extralibs="$extralibs -lutil -lresolv"
29 case "${SYSVERSION:-`uname -r`}" in
30 2.6.* | [3-9].* | [1-9][0-9].*)
31 extralibs="$extralibs -lpthread"
43 extralibs="$extralibs -lrt -lpthread -lsocket -lnsl"
44 # Record paths to shared libraries to avoid needing LD_LIBRARY_PATH
49 s=`echo $i | sed 's/-L/-R/'`
50 extralibs="$extralibs $s"
54 case "${SYSVERSION:-`uname -r`}" in
56 echo do not know how to link right thread library on "$tag" 1>&2
59 # Some trickery is needed to force use of
60 # alternate thread lib from /usr/lib/lwp
61 # Likely, this only works with sun cc,
62 # for other compiler/loader we would need other flags.
64 extralibs="$extralibs /usr/lib/lwp/libthread.so -R/usr/lib/lwp:/usr/lib"
73 echo do not know how to link on "$tag" 1>&2
82 elif [ "x$1" = "x-v" ]
105 l=`echo $i | sed 's/-L//'`
112 echo "ofiles $ofiles"
113 echo "lpaths $lpaths"
117 if [ "x$ofiles" != "x" ]
120 nm $nmflags $ofiles |
121 grep '__p9l_autolib_[a-zA-Z0-9+-]*$' |
122 sed 's/.*__p9l_autolib_//' |
127 autolibs="$autolibs $i"
133 echo "autolibs1 $autolibs"
136 # fetch dependencies out of libraries
138 while [ "x$workq" != "x" ]
144 # can't trust the libraries about using
145 # libthread or libdraw - we might not be linking with
146 # those object files.
151 nm $lpath/lib$i.a 2>/dev/null |
152 grep '__p9l_autolib_[a-zA-Z0-9+-]*$' |
153 sed 's/.*__p9l_autolib_//' |
155 egrep -v '^(thread|draw)$'
159 # fix up libraries that really need draw
160 if [ "x$i" = "xmemdraw" -o "x$i" = "xmemlayer" -o "x$i" = "xframe" ]
167 if eval "[ x\$need$j = x ]"
169 autolibs="$autolibs $j"
175 okayfn="$okayfn && have$j"
180 echo "can$i: $okayfn"
182 eval "can$i() { $okayfn; }"
187 echo "autolibs $autolibs"
192 eval "have$i() { false; }"
194 havethread() { false; }
196 canmemlayer() { havedraw; }
198 # now find correct order
200 while [ "x$autolibs" != x ]
209 eval "have$i() { true; }"
212 stillneed="$stillneed $i"
215 # break cycle by setting the last library on the list
216 # to have no dependencies
224 echo "dependency cycle: $autolibs; breaking with $j"
225 eval "can$j() { true; }"
227 autolibs="$stillneed"
231 echo "liborder $libsl"
235 # cycle: lib9 expects p9main, which is defined in libthread. oops.
238 libsl="$libsl -lthread -l9"
241 # cycle: lib9 netcrypt uses libsec
244 libsl="$libsl -lsec -l9"
247 if [ "x$needndb" = xtrue -a '(' -f /usr/lib/libresolv.a -o -f /usr/lib/libresolv.dylib ')' ]
249 libsl="$libsl -lresolv"
252 if [ "x$needX11" = xtrue -a "x$WSYSTYPE" != xnowsys ]
258 # Don't say -L with a non-existent directory: Xcode complains.
259 # x86_64 seems to put its 64-bit libraries in lib64.
260 if [ "${OBJTYPE:-`uname -m`}" = "x86_64" -a -d "$X11/lib64" ]
262 libsl="$libsl -L$X11/lib64"
266 libsl="$libsl -L$X11/lib"
283 # echo "ofiles $ofiles"
285 if [ "x$ofiles" != "x" ]
289 grep '__p9l_autoframework_[a-zA-Z0-9+-]*$' |
290 sed 's/.*__p9l_autoframework_//' |
295 autoframeworks="$autoframeworks $i"
302 echo "autoframeworks $autoframeworks"
305 for i in $autoframeworks
307 eval "have$i() { false; }"
311 for i in $autoframeworks
313 frameworks="-framework $i $frameworks"
323 s=`echo $i | sed 's/-L/-Wl,-rpath,/'`
324 extralibs="$extralibs $s"
333 echo $ld -L$PLAN9/lib "$@" $libsl $extralibs $frameworks
336 xtmp="${TMPDIR-/tmp}/9l.$$.$USER.out"
338 sed 's/.*: In function `[^:]*: *//' $xtmp | egrep . |
339 egrep -v 'is (often|almost always) misused|is dangerous, better use|text-based stub'
343 if $ld -L$PLAN9/lib "$@" $libsl $extralibs $frameworks >$xtmp 2>&1