plan9port/bin/9l

177 lines
2.7 KiB
Text
Raw Normal View History

#!/bin/sh
libsl=""
doautolib=true
verbose=false
if [ "x$1" = "x-l" ]
then
shift
doautolib=false
elif [ "x$1" = "x-v" ]
then
shift
verbose=true
fi
if $doautolib
then
ofiles=""
for i
do
case "$i" in
[^-]*.o)
ofiles="$ofiles $i"
;;
esac
done
# echo "ofiles $ofiles"
autolibs=""
if [ "x$ofiles" != "x" ]
then
a=`
nm $ofiles |
grep '__p9l_autolib_[a-zA-Z0-9+-]*$' |
sed 's/.* __p9l_autolib_//' |
sort -u
`
for i in $a
do
autolibs="$autolibs $i"
eval "need$i=true"
done
fi
# fetch dependencies out of libraries
workq="$autolibs"
while [ "x$workq" != "x" ]
do
w="$workq"
workq=""
for i in $w
do
a=`
nm $PLAN9/lib/lib$i.a |
grep '__p9l_autolib_[a-zA-Z0-9+-]*$' |
sed 's/.*__p9l_autolib_//' |
sort -u
`
okayfn="true"
for j in $a
do
if eval "[ x\$need$j = x ]"
then
autolibs="$autolibs $j"
workq="$workq $j"
eval "need$j=true"
fi
if [ $j != $i ]
then
okayfn="$okayfn && have$j"
fi
done
# echo "can$i: $okayfn"
eval "can$i() { $okayfn; }"
done
done
if $verbose
then
echo "autolibs $autolibs"
fi
for i in $autolibs
do
eval "have$i() { false; }"
done
# now find correct order
libsl=""
while [ "x$autolibs" != x ]
do
stillneed=""
didnothing=true
for i in $autolibs
do
if eval "can$i"
then
libsl="-l$i $libsl"
eval "have$i() { true; }"
didnothing=false
else
stillneed="$stillneed $i"
fi
done
# break cycle by setting the last library on the list
# to have no dependencies
if $didnothing
then
j="xxx"
for i in $autolibs
do
j=$i
done
echo "dependency cycle: $autolibs; breaking with $j"
eval "can$j() { true; }"
fi
autolibs="$stillneed"
done
if $verbose
then
echo "liborder $libsl"
fi
libsl="$libsl -l9"
if [ "x$needdraw" = xtrue ]
then
if [ "x$X11" = "x" ]
then
X11=/usr/X11R6
fi
libsl="$libsl -L$X11/lib -lX11"
fi
fi
2004-03-26 02:09:17 +00:00
extralibs="-lm"
2004-03-02 17:34:15 +00:00
tag="${SYSNAME:-`uname`}-${OBJTYPE:-`uname -m`}"
case "$tag" in
2004-03-25 23:03:22 +00:00
*OpenBSD*) ld=gcc
2004-03-26 02:09:17 +00:00
extralibs="$extralibs -lutil -lpthread"
;;
*BSD*) ld=gcc
extralibs="$extralibs -lutil"
;;
*Linux*) ld=gcc
extralibs="$extralibs -lutil"
case "`uname -r`" in
2.6.*)
extralibs="$extralibs -lpthread"
;;
esac
2004-03-25 23:03:22 +00:00
;;
*Darwin*) ld=gcc ;;
2003-11-25 02:11:11 +00:00
*SunOS*) ld="${CC9:-cc} -g"
2003-11-23 19:49:17 +00:00
extralibs="$extralibs -lrt -lpthread -lsocket -lnsl"
2004-03-25 23:03:22 +00:00
# Record paths to shared libraries to avoid needing LD_LIBRARY_PATH
for i in "$@"
do
case "$i" in
-L*)
s=`echo $i | sed 's/-L/-R/'`
extralibs="$extralibs $s"
;;
esac
done
2003-11-23 19:49:17 +00:00
;;
*)
echo do not know how to link on "$tag" 1>&2
exit 1
esac
if $verbose
then
echo $ld -L$PLAN9/lib "$@" $libsl $extralibs
fi
exec $ld -L$PLAN9/lib "$@" $libsl $extralibs