3 test -f $PLAN9/config && . $PLAN9/config
12 tag="${SYSNAME:-`uname`}-${OBJTYPE:-`uname -m`}"
15 ld="${CC9:-gcc} $CC9FLAGS"
17 extralibs="$extralibs -lutil"
20 ld="${CC9:-cc} $CC9FLAGS"
22 extralibs="$extralibs -lutil"
26 ld="${CC9:-gcc} $CC9FLAGS"
28 extralibs="$extralibs -lutil -lresolv -lpthread"
31 ld="${CC9:-gcc} -m64 $CC9FLAGS"
34 ld="${CC9:-gcc} -m32 $CC9FLAGS"
37 ld="${CC9:-cc} -g $CC9FLAGS"
38 extralibs="$extralibs -lrt -lpthread -lsocket -lnsl"
39 # Record paths to shared libraries to avoid needing LD_LIBRARY_PATH
44 s=`echo $i | sed 's/-L/-R/'`
45 extralibs="$extralibs $s"
49 case "${SYSVERSION:-`uname -r`}" in
51 echo do not know how to link right thread library on "$tag" 1>&2
54 # Some trickery is needed to force use of
55 # alternate thread lib from /usr/lib/lwp
56 # Likely, this only works with sun cc,
57 # for other compiler/loader we would need other flags.
59 extralibs="$extralibs /usr/lib/lwp/libthread.so -R/usr/lib/lwp:/usr/lib"
64 ld="${CC9:-xlc_r} -g -O0 $CC9FLAGS"
66 extralibs="$extralibs -lpthread"
69 echo do not know how to link on "$tag" 1>&2
78 elif [ "x$1" = "x-v" ]
101 l=`echo $i | sed 's/-L//'`
108 echo "ofiles $ofiles"
109 echo "lpaths $lpaths"
113 if [ "x$ofiles" != "x" ]
116 nm $nmflags $ofiles |
117 grep '__p9l_autolib_[a-zA-Z0-9+-]*' |
118 sed 's/.*__p9l_autolib_//; s/:.*//' |
123 autolibs="$autolibs $i"
129 echo "autolibs1 $autolibs"
132 # fetch dependencies out of libraries
134 while [ "x$workq" != "x" ]
140 # can't trust the libraries about using
141 # libthread or libdraw - we might not be linking with
142 # those object files.
147 nm $lpath/lib$i.a 2>/dev/null |
148 grep '__p9l_autolib_[a-zA-Z0-9+-]*' |
149 sed 's/.*__p9l_autolib_//; s/:.*//' |
151 egrep -v '^(thread|draw)$'
155 # fix up libraries that really need draw
156 if [ "x$i" = "xmemdraw" -o "x$i" = "xmemlayer" -o "x$i" = "xframe" ]
163 if eval "[ x\$need$j = x ]"
165 autolibs="$autolibs $j"
171 okayfn="$okayfn && have$j"
176 echo "can$i: $okayfn"
178 eval "can$i() { $okayfn; }"
183 echo "autolibs $autolibs"
188 eval "have$i() { false; }"
190 havethread() { false; }
192 canmemlayer() { havedraw; }
194 # now find correct order
196 while [ "x$autolibs" != x ]
205 eval "have$i() { true; }"
208 stillneed="$stillneed $i"
211 # break cycle by setting the last library on the list
212 # to have no dependencies
220 echo "dependency cycle: $autolibs; breaking with $j"
221 eval "can$j() { true; }"
223 autolibs="$stillneed"
227 echo "liborder $libsl"
231 # cycle: lib9 expects p9main, which is defined in libthread. oops.
234 libsl="$libsl -lthread -l9"
237 # cycle: lib9 netcrypt uses libsec
240 libsl="$libsl -lsec -l9"
243 if [ "x$needndb" = xtrue -a '(' -f /usr/lib/libresolv.a -o -f /usr/lib/libresolv.dylib ')' ]
245 libsl="$libsl -lresolv"
248 if [ "x$needX11" = xtrue -a "x$WSYSTYPE" != xnowsys ]
254 # Don't say -L with a non-existent directory: Xcode complains.
255 # x86_64 seems to put its 64-bit libraries in lib64.
256 if [ "${OBJTYPE:-`uname -m`}" = "x86_64" -a -d "$X11/lib64" ]
258 libsl="$libsl -L$X11/lib64"
262 libsl="$libsl -L$X11/lib"
279 # echo "ofiles $ofiles"
281 if [ "x$ofiles" != "x" ]
285 grep '__p9l_autoframework_[a-zA-Z0-9+-]*$' |
286 sed 's/.*__p9l_autoframework_//' |
291 autoframeworks="$autoframeworks $i"
298 echo "autoframeworks $autoframeworks"
301 for i in $autoframeworks
303 eval "have$i() { false; }"
307 for i in $autoframeworks
309 frameworks="-framework $i $frameworks"
319 s=`echo $i | sed 's/-L/-Wl,-rpath,/'`
320 extralibs="$extralibs $s"
329 echo $ld -L$PLAN9/lib "$@" $libsl $extralibs $frameworks
332 xtmp="${TMPDIR-/tmp}/9l.$$.$USER.out"
334 sed 's/.*: In function `[^:]*: *//' $xtmp | egrep . |
335 egrep -v 'is (often|almost always) misused|is dangerous, better use|text-based stub'
339 if $ld -L$PLAN9/lib "$@" $libsl $extralibs $frameworks >$xtmp 2>&1