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"
68 echo do not know how to link on "$tag" 1>&2
77 elif [ "x$1" = "x-v" ]
100 l=`echo $i | sed 's/-L//'`
107 echo "ofiles $ofiles"
108 echo "lpaths $lpaths"
112 if [ "x$ofiles" != "x" ]
115 nm $nmflags $ofiles |
116 grep '__p9l_autolib_[a-zA-Z0-9+-]*' |
117 sed 's/.*__p9l_autolib_//; s/:.*//' |
122 autolibs="$autolibs $i"
128 echo "autolibs1 $autolibs"
131 # fetch dependencies out of libraries
133 while [ "x$workq" != "x" ]
139 # can't trust the libraries about using
140 # libthread or libdraw - we might not be linking with
141 # those object files.
146 nm $lpath/lib$i.a 2>/dev/null |
147 grep '__p9l_autolib_[a-zA-Z0-9+-]*' |
148 sed 's/.*__p9l_autolib_//; s/:.*//' |
150 egrep -v '^(thread|draw)$'
154 # fix up libraries that really need draw
155 if [ "x$i" = "xmemdraw" -o "x$i" = "xmemlayer" -o "x$i" = "xframe" ]
162 if eval "[ x\$need$j = x ]"
164 autolibs="$autolibs $j"
170 okayfn="$okayfn && have$j"
175 echo "can$i: $okayfn"
177 eval "can$i() { $okayfn; }"
182 echo "autolibs $autolibs"
187 eval "have$i() { false; }"
189 havethread() { false; }
191 canmemlayer() { havedraw; }
193 # now find correct order
195 while [ "x$autolibs" != x ]
204 eval "have$i() { true; }"
207 stillneed="$stillneed $i"
210 # break cycle by setting the last library on the list
211 # to have no dependencies
219 echo "dependency cycle: $autolibs; breaking with $j"
220 eval "can$j() { true; }"
222 autolibs="$stillneed"
226 echo "liborder $libsl"
230 # cycle: lib9 expects p9main, which is defined in libthread. oops.
233 libsl="$libsl -lthread -l9"
236 # cycle: lib9 netcrypt uses libsec
239 libsl="$libsl -lsec -l9"
242 if [ "x$needndb" = xtrue -a '(' -f /usr/lib/libresolv.a -o -f /usr/lib/libresolv.dylib ')' ]
244 libsl="$libsl -lresolv"
247 if [ "x$needX11" = xtrue -a "x$WSYSTYPE" != xnowsys ]
253 # Don't say -L with a non-existent directory: Xcode complains.
254 # x86_64 seems to put its 64-bit libraries in lib64.
255 if [ "${OBJTYPE:-`uname -m`}" = "x86_64" -a -d "$X11/lib64" ]
257 libsl="$libsl -L$X11/lib64"
261 libsl="$libsl -L$X11/lib"
278 # echo "ofiles $ofiles"
280 if [ "x$ofiles" != "x" ]
284 grep '__p9l_autoframework_[a-zA-Z0-9+-]*$' |
285 sed 's/.*__p9l_autoframework_//' |
290 autoframeworks="$autoframeworks $i"
297 echo "autoframeworks $autoframeworks"
300 for i in $autoframeworks
302 eval "have$i() { false; }"
306 for i in $autoframeworks
308 frameworks="-framework $i $frameworks"
318 s=`echo $i | sed 's/-L/-Wl,-rpath,/'`
319 extralibs="$extralibs $s"
328 echo $ld -L$PLAN9/lib "$@" $libsl $extralibs $frameworks
331 xtmp="${TMPDIR-/tmp}/9l.$$.$USER.out"
333 sed 's/.*: In function `[^:]*: *//' $xtmp | egrep . |
334 egrep -v 'is (often|almost always) misused|is dangerous, better use|text-based stub'
338 if $ld -L$PLAN9/lib "$@" $libsl $extralibs $frameworks >$xtmp 2>&1