3 [ "$1" = "" ] && exit 1
5 test -f $PLAN9/config && . $PLAN9/config
14 tag="${SYSNAME:-`uname`}"
17 ld="${CC9:-gcc} $CC9FLAGS"
19 extralibs="$extralibs -lutil"
22 ld="${CC9:-cc} $CC9FLAGS"
24 extralibs="$extralibs -lutil"
28 ld="${CC9:-gcc} $CC9FLAGS"
30 extralibs="$extralibs -lutil -lresolv -lpthread"
33 ld="${CC9:-gcc} -m64 $CC9FLAGS"
36 ld="${CC9:-cc} -g $CC9FLAGS"
37 extralibs="$extralibs -lrt -lpthread -lsocket -lnsl"
38 # Record paths to shared libraries to avoid needing LD_LIBRARY_PATH
43 s=`echo $i | sed 's/-L/-R/'`
44 extralibs="$extralibs $s"
48 case "${SYSVERSION:-`uname -r`}" in
50 echo do not know how to link right thread library on "$tag" 1>&2
53 # Some trickery is needed to force use of
54 # alternate thread lib from /usr/lib/lwp
55 # Likely, this only works with sun cc,
56 # for other compiler/loader we would need other flags.
58 extralibs="$extralibs /usr/lib/lwp/libthread.so -R/usr/lib/lwp:/usr/lib"
63 ld="${CC9:-xlc_r} $CC9FLAGS"
67 echo do not know how to link on "$tag" 1>&2
76 elif [ "x$1" = "x-v" ]
99 l=`echo $i | sed 's/-L//'`
106 echo "ofiles $ofiles"
107 echo "lpaths $lpaths"
111 if [ "x$ofiles" != "x" ]
114 nm $nmflags $ofiles |
115 grep '__p9l_autolib_[a-zA-Z0-9+-]*' |
116 sed 's/.*__p9l_autolib_//; s/:.*//' |
121 autolibs="$autolibs $i"
127 echo "autolibs1 $autolibs"
130 # fetch dependencies out of libraries
132 while [ "x$workq" != "x" ]
138 # can't trust the libraries about using
139 # libthread or libdraw - we might not be linking with
140 # those object files.
145 nm $lpath/lib$i.a 2>/dev/null |
146 grep '__p9l_autolib_[a-zA-Z0-9+-]*' |
147 sed 's/.*__p9l_autolib_//; s/:.*//' |
149 egrep -v '^(thread|draw)$'
153 # fix up libraries that really need draw
154 if [ "x$i" = "xmemdraw" -o "x$i" = "xmemlayer" -o "x$i" = "xframe" ]
161 if eval "[ x\$need$j = x ]"
163 autolibs="$autolibs $j"
169 okayfn="$okayfn && have$j"
174 echo "can$i: $okayfn"
176 eval "can$i() { $okayfn; }"
181 echo "autolibs $autolibs"
186 eval "have$i() { false; }"
188 havethread() { false; }
190 canmemlayer() { havedraw; }
192 # now find correct order
194 while [ "x$autolibs" != x ]
203 eval "have$i() { true; }"
206 stillneed="$stillneed $i"
209 # break cycle by setting the last library on the list
210 # to have no dependencies
218 echo "dependency cycle: $autolibs; breaking with $j"
219 eval "can$j() { true; }"
221 autolibs="$stillneed"
225 echo "liborder $libsl"
229 # cycle: lib9 expects p9main, which is defined in libthread. oops.
232 libsl="$libsl -lthread -l9"
235 # cycle: lib9 netcrypt uses libsec
238 libsl="$libsl -lsec -l9"
241 if [ "x$needndb" = xtrue -a '(' -f /usr/lib/libresolv.a -o -f /usr/lib/libresolv.dylib ')' ]
243 libsl="$libsl -lresolv"
246 if [ "x$needX11" = xtrue -a "x$WSYSTYPE" != xnowsys ]
252 # Don't say -L with a non-existent directory: Xcode complains.
253 # x86_64 seems to put its 64-bit libraries in lib64.
254 if [ "`uname -m`" = "x86_64" -a -d "$X11/lib64" ]
256 libsl="$libsl -L$X11/lib64"
260 libsl="$libsl -L$X11/lib"
277 # echo "ofiles $ofiles"
279 if [ "x$ofiles" != "x" ]
283 grep '__p9l_autoframework_[a-zA-Z0-9+-]*$' |
284 sed 's/.*__p9l_autoframework_//' |
289 autoframeworks="$autoframeworks $i"
296 echo "autoframeworks $autoframeworks"
299 for i in $autoframeworks
301 eval "have$i() { false; }"
305 for i in $autoframeworks
307 frameworks="-framework $i $frameworks"
317 s=`echo $i | sed 's/-L/-Wl,-rpath,/'`
318 extralibs="$extralibs $s"
327 echo $ld -L$PLAN9/lib "$@" $libsl $extralibs $frameworks
330 xtmp="${TMPDIR-/tmp}/9l.$$.$USER.out"
332 sed 's/.*: In function `[^:]*: *//' $xtmp | egrep . |
333 egrep -v 'is (often|almost always) misused|is dangerous, better use|text-based stub'
337 if $ld -L$PLAN9/lib "$@" $libsl $extralibs $frameworks >$xtmp 2>&1