3 test -f $PLAN9/config && . $PLAN9/config
12 tag="${SYSNAME:-`uname`}"
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:-cc} -g $CC9FLAGS"
35 extralibs="$extralibs -lrt -lpthread -lsocket -lnsl"
36 # Record paths to shared libraries to avoid needing LD_LIBRARY_PATH
41 s=`echo $i | sed 's/-L/-R/'`
42 extralibs="$extralibs $s"
46 case "${SYSVERSION:-`uname -r`}" in
48 echo do not know how to link right thread library on "$tag" 1>&2
51 # Some trickery is needed to force use of
52 # alternate thread lib from /usr/lib/lwp
53 # Likely, this only works with sun cc,
54 # for other compiler/loader we would need other flags.
56 extralibs="$extralibs /usr/lib/lwp/libthread.so -R/usr/lib/lwp:/usr/lib"
61 ld="${CC9:-xlc_r} $CC9FLAGS"
65 echo do not know how to link on "$tag" 1>&2
74 elif [ "x$1" = "x-v" ]
97 l=`echo $i | sed 's/-L//'`
104 echo "ofiles $ofiles"
105 echo "lpaths $lpaths"
109 if [ "x$ofiles" != "x" ]
112 nm $nmflags $ofiles |
113 grep '__p9l_autolib_[a-zA-Z0-9+-]*' |
114 sed 's/.*__p9l_autolib_//; s/:.*//' |
119 autolibs="$autolibs $i"
125 echo "autolibs1 $autolibs"
128 # fetch dependencies out of libraries
130 while [ "x$workq" != "x" ]
136 # can't trust the libraries about using
137 # libthread or libdraw - we might not be linking with
138 # those object files.
143 nm $lpath/lib$i.a 2>/dev/null |
144 grep '__p9l_autolib_[a-zA-Z0-9+-]*' |
145 sed 's/.*__p9l_autolib_//; s/:.*//' |
147 egrep -v '^(thread|draw)$'
151 # fix up libraries that really need draw
152 if [ "x$i" = "xmemdraw" -o "x$i" = "xmemlayer" -o "x$i" = "xframe" ]
159 if eval "[ x\$need$j = x ]"
161 autolibs="$autolibs $j"
167 okayfn="$okayfn && have$j"
172 echo "can$i: $okayfn"
174 eval "can$i() { $okayfn; }"
179 echo "autolibs $autolibs"
184 eval "have$i() { false; }"
186 havethread() { false; }
188 canmemlayer() { havedraw; }
190 # now find correct order
192 while [ "x$autolibs" != x ]
201 eval "have$i() { true; }"
204 stillneed="$stillneed $i"
207 # break cycle by setting the last library on the list
208 # to have no dependencies
216 echo "dependency cycle: $autolibs; breaking with $j"
217 eval "can$j() { true; }"
219 autolibs="$stillneed"
223 echo "liborder $libsl"
227 # cycle: lib9 expects p9main, which is defined in libthread. oops.
230 libsl="$libsl -lthread -l9"
233 # cycle: lib9 netcrypt uses libsec
236 libsl="$libsl -lsec -l9"
239 if [ "x$needndb" = xtrue -a '(' -f /usr/lib/libresolv.a -o -f /usr/lib/libresolv.dylib ')' ]
241 libsl="$libsl -lresolv"
244 if [ "x$needX11" = xtrue -a "x$WSYSTYPE" != xnowsys ]
250 # Don't say -L with a non-existent directory: Xcode complains.
251 # x86_64 seems to put its 64-bit libraries in lib64.
252 if [ "`uname -m`" = "x86_64" -a -d "$X11/lib64" ]
254 libsl="$libsl -L$X11/lib64"
258 libsl="$libsl -L$X11/lib"
275 # echo "ofiles $ofiles"
277 if [ "x$ofiles" != "x" ]
281 grep '__p9l_autoframework_[a-zA-Z0-9+-]*$' |
282 sed 's/.*__p9l_autoframework_//' |
287 autoframeworks="$autoframeworks $i"
294 echo "autoframeworks $autoframeworks"
297 for i in $autoframeworks
299 eval "have$i() { false; }"
303 for i in $autoframeworks
305 frameworks="-framework $i $frameworks"
315 s=`echo $i | sed 's/-L/-Wl,-rpath,/'`
316 extralibs="$extralibs $s"
325 echo $ld -L$PLAN9/lib "$@" $libsl $extralibs $frameworks
328 xtmp="${TMPDIR-/tmp}/9l.$$.$USER.out"
330 sed 's/.*: In function `[^:]*: *//' $xtmp | egrep . |
331 egrep -v 'is (often|almost always) misused|is dangerous, better use|text-based stub'
335 if $ld -L$PLAN9/lib "$@" $libsl $extralibs $frameworks >$xtmp 2>&1