#!/bin/shtest -f $PF9/$objtype/config && . $PF9/$objtype/configlibsl=""frameworks=""doautolib=truedoautoframework=trueverbose=falseif [ "x$1" = "x-l" ]then shift doautolib=false doautoframework=falseelif [ "x$1" = "x-v" ]then shift verbose=truefitarget=a.outif [ "x$1" = "x-o" ]then target=$2fiif $doautolibthen ofiles="" for i do case "$i" in *.[a$O]) ofiles="$ofiles $i" ;; esac done # echo "ofiles $ofiles" autolibs="" if [ "x$ofiles" != "x" ] then a=` ${TOOLPFX}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 if $verbose then echo "autolibs1 $autolibs" fi # fetch dependencies out of libraries workq="$autolibs 9" while [ "x$workq" != "x" ] do w="$workq" workq="" for i in $w do # can't trust the libraries about using # libthread or libdraw - we might not be linking with # those object files. a=` ${TOOLPFX}nm $PF9/$objtype/lib/lib$i.a 2>/dev/null | grep '__p9l_autolib_[a-zA-Z0-9+-]*$' | sed 's/.*__p9l_autolib_//' | sort -u | egrep -v '^(thread|draw)$' ` # fix up libraries that really need draw if [ "x$i" = "xmemdraw" -o "x$i" = "xmemlayer" -o "x$i" = "xframe" ] then a="$a draw" fi 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 if $verbose then echo "can$i: $okayfn" fi eval "can$i() { $okayfn; }" done done if $verbose then echo "autolibs $autolibs" fi for i in $autolibs do eval "have$i() { false; }" done havethread() { false; } havesec() { false; } canmemlayer() { havedraw; } # 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" # cycle: lib9 expects p9main, which is defined in libthread. oops. if havethread then libsl="$libsl -lthread -l9" fi # cycle: lib9 netcrypt uses libsec if havesec then libsl="$libsl -lsec -l9" fi# if [ "x$needndb" = xtrue -a '(' -f /usr/lib/libresolv.a -o -f /usr/lib/libresolv.dylib ')' ]# then# libsl="$libsl -lresolv"# fi if [ "x$needdraw" = xtrue -a "x$WSYSTYPE" != xnowsys ] then libsl="$libsl -lgdi32 -lthread -l9" fifiif $doautoframeworkthen ofiles="" for i do case "$i" in *.[ao]) ofiles="$ofiles $i" ;; esac done # echo "ofiles $ofiles" autoframeworks="" if [ "x$ofiles" != "x" ] then a=` ${TOOLPFX}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" donefi#always use gccld=${TOOLPFX}gcccase $objtype inmingw) startfiles= extralibs="-lm -lws2_32 -ladvapi32 -lmpr -lshell32 -lole32 -luuid" ldflags= ;;cygwin) startfiles="$MSYSdir/lib/crt0.o $MSYSdir/lib/binmode.o " ldflags="-mcygwin -nostartfiles" extralibs="-lcygwin -lc -lkernel32 -lm" ;;esacif $verbosethen echo $ld $ldflags -L$PF9/$objtype/lib $startfiles "$@" $libsl $extralibs $frameworksfixtmp=/tmp/9l.$$.$USER.outxxout() { sed 's/.*: In function `[^:]*: *//' $xtmp | egrep . | egrep -v 'is almost always misused|is dangerous, better use' rm -f $xtmp}if $ld $ldflags -L$PF9/$objtype/lib $startfiles "$@" $libsl $extralibs $frameworks >$xtmp 2>&1then xxout exit 0else xxout rm -f $target exit 1fi
#!/bin/sh
test -f $PF9/$objtype/config && . $PF9/$objtype/config
libsl=""
frameworks=""
doautolib=true
doautoframework=true
verbose=false
if [ "x$1" = "x-l" ]
then
shift
doautolib=false
doautoframework=false
elif [ "x$1" = "x-v" ]
then
shift
verbose=true
fi
target=a.out
if [ "x$1" = "x-o" ]
then
target=$2
fi
if $doautolib
then
ofiles=""
for i
do
case "$i" in
*.[a$O])
ofiles="$ofiles $i"
;;
esac
done
# echo "ofiles $ofiles"
autolibs=""
if [ "x$ofiles" != "x" ]
then
a=`
${TOOLPFX}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
if $verbose
then
echo "autolibs1 $autolibs"
fi
# fetch dependencies out of libraries
workq="$autolibs 9"
while [ "x$workq" != "x" ]
do
w="$workq"
workq=""
for i in $w
do
# can't trust the libraries about using
# libthread or libdraw - we might not be linking with
# those object files.
a=`
${TOOLPFX}nm $PF9/$objtype/lib/lib$i.a 2>/dev/null |
grep '__p9l_autolib_[a-zA-Z0-9+-]*$' |
sed 's/.*__p9l_autolib_//' |
sort -u |
egrep -v '^(thread|draw)$'
`
# fix up libraries that really need draw
if [ "x$i" = "xmemdraw" -o "x$i" = "xmemlayer" -o "x$i" = "xframe" ]
then
a="$a draw"
fi
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
if $verbose
then
echo "can$i: $okayfn"
fi
eval "can$i() { $okayfn; }"
done
done
if $verbose
then
echo "autolibs $autolibs"
fi
for i in $autolibs
do
eval "have$i() { false; }"
done
havethread() { false; }
havesec() { false; }
canmemlayer() { havedraw; }
# 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"
# cycle: lib9 expects p9main, which is defined in libthread. oops.
if havethread
then
libsl="$libsl -lthread -l9"
fi
# cycle: lib9 netcrypt uses libsec
if havesec
then
libsl="$libsl -lsec -l9"
fi
# if [ "x$needndb" = xtrue -a '(' -f /usr/lib/libresolv.a -o -f /usr/lib/libresolv.dylib ')' ]
# then
# libsl="$libsl -lresolv"
# fi
if [ "x$needdraw" = xtrue -a "x$WSYSTYPE" != xnowsys ]
then
libsl="$libsl -lgdi32 -lthread -l9"
fi
fi
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=`
${TOOLPFX}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
#always use gcc
ld=${TOOLPFX}gcc
case $objtype in
mingw)
startfiles=
extralibs="-lm -lws2_32 -ladvapi32 -lmpr -lshell32 -lole32 -luuid"
ldflags=
;;
cygwin)
startfiles="$MSYSdir/lib/crt0.o $MSYSdir/lib/binmode.o "
ldflags="-mcygwin -nostartfiles"
extralibs="-lcygwin -lc -lkernel32 -lm"
;;
esac
if $verbose
then
echo $ld $ldflags -L$PF9/$objtype/lib $startfiles "$@" $libsl $extralibs $frameworks
fi
xtmp=/tmp/9l.$$.$USER.out
xxout() {
sed 's/.*: In function `[^:]*: *//' $xtmp | egrep . |
egrep -v 'is almost always misused|is dangerous, better use'
rm -f $xtmp
}
if $ld $ldflags -L$PF9/$objtype/lib $startfiles "$@" $libsl $extralibs $frameworks >$xtmp 2>&1
then
xxout
exit 0
else
xxout
rm -f $target
exit 1
fi