Blob
1 #!/bin/sh3 libsl=""5 doautolib=true6 verbose=false8 if [ "x$1" = "x-l" ]9 then10 shift11 doautolib=false12 elif [ "x$1" = "x-v" ]13 then14 shift15 verbose=true16 fi18 target=a.out19 if [ "x$1" = "x-o" ]20 then21 target=$222 fi24 if $doautolib25 then26 ofiles=""27 for i28 do29 case "$i" in30 *.o)31 ofiles="$ofiles $i"32 ;;33 esac34 done36 # echo "ofiles $ofiles"37 autolibs=""38 if [ "x$ofiles" != "x" ]39 then40 a=`41 nm $ofiles |42 grep '__p9l_autolib_[a-zA-Z0-9+-]*$' |43 sed 's/.*__p9l_autolib_//' |44 sort -u45 `46 for i in $a47 do48 autolibs="$autolibs $i"49 eval "need$i=true"50 done51 fi53 # fetch dependencies out of libraries54 workq="$autolibs"55 while [ "x$workq" != "x" ]56 do57 w="$workq"58 workq=""59 for i in $w60 do61 a=`62 nm $PLAN9/lib/lib$i.a |63 grep '__p9l_autolib_[a-zA-Z0-9+-]*$' |64 sed 's/.*__p9l_autolib_//' |65 sort -u66 `67 okayfn="true"68 for j in $a69 do70 if eval "[ x\$need$j = x ]"71 then72 autolibs="$autolibs $j"73 workq="$workq $j"74 eval "need$j=true"75 fi76 if [ $j != $i ]77 then78 okayfn="$okayfn && have$j"79 fi80 done81 # echo "can$i: $okayfn"82 eval "can$i() { $okayfn; }"83 done84 done85 if $verbose86 then87 echo "autolibs $autolibs"88 fi90 for i in $autolibs91 do92 eval "have$i() { false; }"93 done95 # now find correct order96 libsl=""97 while [ "x$autolibs" != x ]98 do99 stillneed=""100 didnothing=true101 for i in $autolibs102 do103 if eval "can$i"104 then105 libsl="-l$i $libsl"106 eval "have$i() { true; }"107 didnothing=false108 else109 stillneed="$stillneed $i"110 fi111 done112 # break cycle by setting the last library on the list113 # to have no dependencies114 if $didnothing115 then116 j="xxx"117 for i in $autolibs118 do119 j=$i120 done121 echo "dependency cycle: $autolibs; breaking with $j"122 eval "can$j() { true; }"123 fi124 autolibs="$stillneed"125 done126 if $verbose127 then128 echo "liborder $libsl"129 fi130 libsl="$libsl -l9"132 if [ "x$needdraw" = xtrue ]133 then134 if [ "x$X11" = "x" ]135 then136 X11=/usr/X11R6137 fi138 libsl="$libsl -L$X11/lib -lX11"139 fi140 fi142 extralibs="-lm"143 tag="${SYSNAME:-`uname`}-${OBJTYPE:-`uname -m`}"144 case "$tag" in145 *OpenBSD*)146 ld=gcc147 extralibs="$extralibs -lutil -lpthread"148 ;;149 *FreeBSD*)150 ld=gcc151 extralibs="$extralibs -lutil"152 case "`uname -r`" in153 [5-9].*)154 extralibs="$extralibs -lpthread"155 ;;156 esac157 ;;158 *BSD*)159 ld=gcc160 extralibs="$extralibs -lutil"161 ;;162 *Linux*)163 ld=gcc164 extralibs="$extralibs -lutil"165 case "`uname -r`" in166 2.6.*)167 extralibs="$extralibs -lpthread"168 ;;169 esac170 ;;171 *Darwin*)172 ld=gcc173 ;;174 *SunOS*)175 ld="${CC9:-cc} -g"176 extralibs="$extralibs -lrt -lpthread -lsocket -lnsl"177 # Record paths to shared libraries to avoid needing LD_LIBRARY_PATH178 for i in "$@"179 do180 case "$i" in181 -L*)182 s=`echo $i | sed 's/-L/-R/'`183 extralibs="$extralibs $s"184 ;;185 esac186 done187 ;;188 *)189 echo do not know how to link on "$tag" 1>&2190 exit 1191 esac193 if $verbose194 then195 echo $ld -L$PLAN9/lib "$@" $libsl $extralibs196 fi197 if ! $ld -L$PLAN9/lib "$@" $libsl $extralibs198 then199 rm -f $target200 exit 1201 fi202 exit 0