2003-11-23 18:29:08 +00:00
|
|
|
#!/bin/sh
|
|
|
|
|
2005-01-17 20:57:57 +00:00
|
|
|
test -f $PLAN9/config && . $PLAN9/config
|
2005-01-04 21:13:58 +00:00
|
|
|
libsl=""
|
2005-10-19 03:15:30 +00:00
|
|
|
frameworks=""
|
2005-01-07 06:40:17 +00:00
|
|
|
doautolib=true
|
2005-10-19 03:15:30 +00:00
|
|
|
doautoframework=true
|
2005-01-07 06:40:17 +00:00
|
|
|
verbose=false
|
2005-01-04 21:13:58 +00:00
|
|
|
|
|
|
|
if [ "x$1" = "x-l" ]
|
|
|
|
then
|
|
|
|
shift
|
2005-01-07 06:40:17 +00:00
|
|
|
doautolib=false
|
2005-10-19 03:15:30 +00:00
|
|
|
doautoframework=false
|
2005-01-04 21:13:58 +00:00
|
|
|
elif [ "x$1" = "x-v" ]
|
|
|
|
then
|
|
|
|
shift
|
2005-01-07 06:40:17 +00:00
|
|
|
verbose=true
|
2005-01-04 21:13:58 +00:00
|
|
|
fi
|
|
|
|
|
2005-01-07 18:51:26 +00:00
|
|
|
target=a.out
|
|
|
|
if [ "x$1" = "x-o" ]
|
|
|
|
then
|
|
|
|
target=$2
|
|
|
|
fi
|
|
|
|
|
2005-01-07 06:40:17 +00:00
|
|
|
if $doautolib
|
2005-01-04 21:13:58 +00:00
|
|
|
then
|
|
|
|
ofiles=""
|
|
|
|
for i
|
|
|
|
do
|
|
|
|
case "$i" in
|
2005-01-14 04:24:09 +00:00
|
|
|
*.[ao])
|
2005-01-04 21:13:58 +00:00
|
|
|
ofiles="$ofiles $i"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
# echo "ofiles $ofiles"
|
|
|
|
autolibs=""
|
|
|
|
if [ "x$ofiles" != "x" ]
|
|
|
|
then
|
2005-01-07 06:40:17 +00:00
|
|
|
a=`
|
2005-01-04 21:13:58 +00:00
|
|
|
nm $ofiles |
|
|
|
|
grep '__p9l_autolib_[a-zA-Z0-9+-]*$' |
|
2005-01-07 07:28:36 +00:00
|
|
|
sed 's/.*__p9l_autolib_//' |
|
2005-01-04 21:13:58 +00:00
|
|
|
sort -u
|
|
|
|
`
|
2005-01-07 06:40:17 +00:00
|
|
|
for i in $a
|
|
|
|
do
|
|
|
|
autolibs="$autolibs $i"
|
|
|
|
eval "need$i=true"
|
|
|
|
done
|
2005-01-04 21:13:58 +00:00
|
|
|
fi
|
2005-01-07 06:40:17 +00:00
|
|
|
|
|
|
|
# fetch dependencies out of libraries
|
|
|
|
workq="$autolibs"
|
|
|
|
while [ "x$workq" != "x" ]
|
2005-01-04 21:13:58 +00:00
|
|
|
do
|
2005-01-07 06:40:17 +00:00
|
|
|
w="$workq"
|
|
|
|
workq=""
|
|
|
|
for i in $w
|
|
|
|
do
|
2005-01-14 04:24:09 +00:00
|
|
|
# can't trust the libraries about using
|
|
|
|
# libthread - we might not be linking with
|
|
|
|
# those object files.
|
2005-01-07 06:40:17 +00:00
|
|
|
a=`
|
2005-07-13 10:45:25 +00:00
|
|
|
nm $PLAN9/lib/lib$i.a 2>/dev/null |
|
2005-01-07 06:40:17 +00:00
|
|
|
grep '__p9l_autolib_[a-zA-Z0-9+-]*$' |
|
|
|
|
sed 's/.*__p9l_autolib_//' |
|
2005-01-14 04:24:09 +00:00
|
|
|
sort -u |
|
|
|
|
grep -v thread
|
2005-01-07 06:40:17 +00:00
|
|
|
`
|
|
|
|
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
|
2005-01-04 21:13:58 +00:00
|
|
|
done
|
2005-01-07 06:40:17 +00:00
|
|
|
if $verbose
|
|
|
|
then
|
|
|
|
echo "autolibs $autolibs"
|
|
|
|
fi
|
|
|
|
|
2005-01-04 21:13:58 +00:00
|
|
|
for i in $autolibs
|
|
|
|
do
|
2005-01-07 06:40:17 +00:00
|
|
|
eval "have$i() { false; }"
|
2005-01-04 21:13:58 +00:00
|
|
|
done
|
2005-01-13 04:49:19 +00:00
|
|
|
havethread() { false; }
|
2005-02-11 16:52:08 +00:00
|
|
|
havesec() { false; }
|
2005-01-07 06:40:17 +00:00
|
|
|
|
|
|
|
# now find correct order
|
|
|
|
libsl=""
|
|
|
|
while [ "x$autolibs" != x ]
|
2005-01-04 21:13:58 +00:00
|
|
|
do
|
2005-01-07 06:40:17 +00:00
|
|
|
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
|
2005-01-04 21:13:58 +00:00
|
|
|
then
|
2005-01-07 06:40:17 +00:00
|
|
|
j="xxx"
|
|
|
|
for i in $autolibs
|
|
|
|
do
|
|
|
|
j=$i
|
|
|
|
done
|
|
|
|
echo "dependency cycle: $autolibs; breaking with $j"
|
|
|
|
eval "can$j() { true; }"
|
2005-01-04 21:13:58 +00:00
|
|
|
fi
|
2005-01-07 06:40:17 +00:00
|
|
|
autolibs="$stillneed"
|
2005-01-04 21:13:58 +00:00
|
|
|
done
|
2005-01-07 06:40:17 +00:00
|
|
|
if $verbose
|
|
|
|
then
|
|
|
|
echo "liborder $libsl"
|
|
|
|
fi
|
2005-01-04 21:13:58 +00:00
|
|
|
libsl="$libsl -l9"
|
2005-01-07 06:40:17 +00:00
|
|
|
|
2005-01-13 04:49:19 +00:00
|
|
|
# cycle: lib9 expects p9main, which is defined in libthread. oops.
|
2005-01-14 04:24:09 +00:00
|
|
|
if havethread
|
2005-01-13 04:49:19 +00:00
|
|
|
then
|
2005-01-14 04:24:09 +00:00
|
|
|
libsl="$libsl -lthread -l9"
|
2005-01-13 04:49:19 +00:00
|
|
|
fi
|
|
|
|
|
2005-02-11 16:52:08 +00:00
|
|
|
# cycle: lib9 netcrypt uses libsec
|
|
|
|
if havesec
|
|
|
|
then
|
|
|
|
libsl="$libsl -lsec -l9"
|
|
|
|
fi
|
|
|
|
|
2005-01-07 06:40:17 +00:00
|
|
|
if [ "x$needdraw" = xtrue ]
|
2005-01-04 21:13:58 +00:00
|
|
|
then
|
|
|
|
if [ "x$X11" = "x" ]
|
|
|
|
then
|
|
|
|
X11=/usr/X11R6
|
|
|
|
fi
|
2005-01-18 05:59:34 +00:00
|
|
|
# x86_64 seems to put its 64-bit libraries in lib64.
|
|
|
|
if [ "${OBJTYPE:-`uname -m`}" = "x86_64" ]
|
|
|
|
then
|
|
|
|
libsl="$libsl -L$X11/lib64"
|
|
|
|
fi
|
2005-01-04 21:13:58 +00:00
|
|
|
libsl="$libsl -L$X11/lib -lX11"
|
|
|
|
fi
|
|
|
|
fi
|
2005-10-19 03:15:30 +00:00
|
|
|
if $doautoframework
|
|
|
|
then
|
|
|
|
ofiles=""
|
|
|
|
for i
|
|
|
|
do
|
|
|
|
case "$i" in
|
|
|
|
*.[ao])
|
|
|
|
ofiles="$ofiles $i"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
# echo "ofiles $ofiles"
|
|
|
|
autoframeworks=""
|
|
|
|
if [ "x$ofiles" != "x" ]
|
|
|
|
then
|
|
|
|
a=`
|
|
|
|
nm $ofiles |
|
|
|
|
grep '__p9l_autoframework_[a-zA-Z0-9+-]*$' |
|
|
|
|
sed 's/.*__p9l_autoframework_//' |
|
|
|
|
sort -u
|
|
|
|
`
|
|
|
|
for i in $a
|
|
|
|
do
|
|
|
|
autoframeworks="$autoframeworks $i"
|
|
|
|
eval "need$i=true"
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
|
|
|
|
if $verbose
|
|
|
|
then
|
|
|
|
echo "autoframeworks $autoframeworks"
|
|
|
|
fi
|
|
|
|
|
|
|
|
for i in $autoframeworks
|
|
|
|
do
|
|
|
|
eval "have$i() { false; }"
|
|
|
|
done
|
|
|
|
|
|
|
|
frameworks=""
|
|
|
|
for i in $autoframeworks
|
|
|
|
do
|
|
|
|
frameworks="-framework $i $frameworks"
|
|
|
|
done
|
|
|
|
fi
|
2005-01-04 21:13:58 +00:00
|
|
|
|
2004-03-26 02:09:17 +00:00
|
|
|
extralibs="-lm"
|
2004-03-02 17:34:15 +00:00
|
|
|
tag="${SYSNAME:-`uname`}-${OBJTYPE:-`uname -m`}"
|
2003-11-23 18:29:08 +00:00
|
|
|
case "$tag" in
|
2005-01-07 18:06:47 +00:00
|
|
|
*FreeBSD*)
|
|
|
|
ld=gcc
|
2005-01-19 00:25:38 +00:00
|
|
|
userpath=true
|
2005-01-07 18:06:47 +00:00
|
|
|
extralibs="$extralibs -lutil"
|
|
|
|
case "`uname -r`" in
|
2005-02-08 19:13:57 +00:00
|
|
|
5.2.*)
|
|
|
|
extralibs="$extralibs -lkse"
|
|
|
|
;;
|
2005-01-07 18:06:47 +00:00
|
|
|
[5-9].*)
|
|
|
|
extralibs="$extralibs -lpthread"
|
2004-03-26 02:09:17 +00:00
|
|
|
;;
|
2005-01-07 18:06:47 +00:00
|
|
|
esac
|
|
|
|
;;
|
|
|
|
*BSD*)
|
|
|
|
ld=gcc
|
2005-01-19 00:25:38 +00:00
|
|
|
userpath=true
|
2005-01-07 18:06:47 +00:00
|
|
|
extralibs="$extralibs -lutil"
|
|
|
|
;;
|
|
|
|
*Linux*)
|
|
|
|
ld=gcc
|
2005-01-19 00:25:38 +00:00
|
|
|
userpath=true
|
2005-01-07 18:06:47 +00:00
|
|
|
extralibs="$extralibs -lutil"
|
2005-01-17 20:57:57 +00:00
|
|
|
case "${SYSVERSION:-`uname -r`}" in
|
2005-01-07 18:06:47 +00:00
|
|
|
2.6.*)
|
|
|
|
extralibs="$extralibs -lpthread"
|
2004-03-26 02:09:17 +00:00
|
|
|
;;
|
2005-01-07 18:06:47 +00:00
|
|
|
esac
|
|
|
|
;;
|
|
|
|
*Darwin*)
|
|
|
|
ld=gcc
|
|
|
|
;;
|
|
|
|
*SunOS*)
|
|
|
|
ld="${CC9:-cc} -g"
|
|
|
|
extralibs="$extralibs -lrt -lpthread -lsocket -lnsl"
|
|
|
|
# Record paths to shared libraries to avoid needing LD_LIBRARY_PATH
|
2005-01-16 20:56:40 +00:00
|
|
|
for i in "$libsl $@"
|
2005-01-07 18:06:47 +00:00
|
|
|
do
|
|
|
|
case "$i" in
|
|
|
|
-L*)
|
|
|
|
s=`echo $i | sed 's/-L/-R/'`
|
|
|
|
extralibs="$extralibs $s"
|
2004-09-17 22:09:31 +00:00
|
|
|
;;
|
|
|
|
esac
|
2005-01-07 18:06:47 +00:00
|
|
|
done
|
2005-02-08 18:01:04 +00:00
|
|
|
case "${SYSVERSION:-`uname -r`}" in
|
|
|
|
5.[67])
|
|
|
|
echo do not know how to link right thread library on "$tag" 1>&2
|
|
|
|
;;
|
|
|
|
5.8)
|
|
|
|
# Some trickery is needed to force use of
|
|
|
|
# alternate thread lib from /usr/lib/lwp
|
|
|
|
# Likely, this only works with sun cc,
|
|
|
|
# for other compiler/loader we would need other flags.
|
|
|
|
ld="$ld -i"
|
|
|
|
extralibs="$extralibs /usr/lib/lwp/libthread.so -R/usr/lib/lwp:/usr/lib"
|
|
|
|
;;
|
|
|
|
esac
|
2005-01-07 18:06:47 +00:00
|
|
|
;;
|
2003-11-23 18:29:08 +00:00
|
|
|
*)
|
|
|
|
echo do not know how to link on "$tag" 1>&2
|
|
|
|
exit 1
|
|
|
|
esac
|
|
|
|
|
2005-01-19 00:25:38 +00:00
|
|
|
case "$userpath" in
|
|
|
|
true)
|
2005-01-16 20:56:40 +00:00
|
|
|
for i in "$libsl $@"
|
|
|
|
do
|
|
|
|
case "$i" in
|
|
|
|
-L*)
|
|
|
|
s=`echo $i | sed 's/-L/-Wl,-rpath,/'`
|
|
|
|
extralibs="$extralibs $s"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2005-01-07 06:40:17 +00:00
|
|
|
if $verbose
|
2005-01-04 21:13:58 +00:00
|
|
|
then
|
2005-10-19 03:15:30 +00:00
|
|
|
echo $ld -L$PLAN9/lib "$@" $libsl $extralibs $frameworks
|
2005-01-04 21:13:58 +00:00
|
|
|
fi
|
2005-03-18 18:50:33 +00:00
|
|
|
|
|
|
|
xtmp=/tmp/9l.$$.$USER.out
|
|
|
|
xxout() {
|
2005-11-27 23:58:32 +00:00
|
|
|
egrep -v 'is almost always misused|: In function `' $xtmp
|
2005-03-18 18:50:33 +00:00
|
|
|
rm -f $xtmp
|
|
|
|
}
|
|
|
|
|
2005-10-19 03:15:30 +00:00
|
|
|
if $ld -L$PLAN9/lib "$@" $libsl $extralibs $frameworks >$xtmp 2>&1
|
2005-01-07 20:40:44 +00:00
|
|
|
then
|
2005-03-18 18:50:33 +00:00
|
|
|
xxout
|
2005-01-13 04:49:19 +00:00
|
|
|
exit 0
|
|
|
|
else
|
2005-03-18 18:50:33 +00:00
|
|
|
xxout
|
2005-01-07 18:51:26 +00:00
|
|
|
rm -f $target
|
|
|
|
exit 1
|
2005-01-07 20:40:44 +00:00
|
|
|
fi
|
2005-01-13 04:49:19 +00:00
|
|
|
|