337 lines · 5.6 KB · Text
RawDownload
#!/bin/sh objtype=$cputypetest -f $PF9/$objtype/config && . $PF9/$objtype/configlibsl=""frameworks=""doautolib=truedoautoframework=trueverbose=false if [ "x$1" = "x-l" ]then	shift	doautolib=false	doautoframework=falseelif [ "x$1" = "x-v" ]then	shift	verbose=truefi target=a.outif [ "x$1" = "x-o" ]then	target=$2fi if $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=`			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"	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=`				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		if [ "x$X11" = "x" ]		then			X11=/usr/X11R6		fi		# x86_64 seems to put its 64-bit libraries in lib64.		if [ "${OBJTYPE:-`uname -m`}" = "x86_64" ]		then			libsl="$libsl -L$X11/lib64"		fi		libsl="$libsl -L$X11/lib -lX11"	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=`			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 extralibs="-lm"tag="${SYSNAME:-`uname`}-${OBJTYPE:-`uname -m`}"case "$tag" in*FreeBSD*)	ld=gcc	userpath=true	extralibs="$extralibs -lutil"	case "`uname -r`" in	5.2.*)		extralibs="$extralibs -lkse"		;;	[5-9].*)		extralibs="$extralibs -lpthread"		;;	esac	;;*BSD*)	ld=gcc	userpath=true	extralibs="$extralibs -lutil"	;;*Linux*)	ld=gcc	userpath=true	extralibs="$extralibs -lutil"	case "${SYSVERSION:-`uname -r`}" in	2.6.*)		extralibs="$extralibs -lpthread"		;;	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 	for i in "$libsl $@"	do		case "$i" in		-L*)			s=`echo $i | sed 's/-L/-R/'`			extralibs="$extralibs $s"			;;		esac	done	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	;;*)	echo do not know how to link on "$tag" 1>&2	exit 1esac case "$userpath" intrue)	for i in "$libsl $@"	do		case "$i" in		-L*)			s=`echo $i | sed 's/-L/-Wl,-rpath,/'`			extralibs="$extralibs $s"			;;		esac	done	;;esac if $verbosethen	echo $ld -L$PF9/$objtype/lib "$@" $libsl $extralibs $frameworksfi xtmp=/tmp/9l.$$.$USER.outxxout() {	sed 's/.*: In function `[^:]*: *//' $xtmp | egrep . | 	egrep -v 'is (often|almost always) misused|is dangerous, better use' 	rm -f $xtmp} if ! havethread && -L$PF9/$objtype/lib "$@" $libsl $frameworks >$xtmp 2>&1then	xxout	exit 0elif $ld -L$PF9/$objtype/lib "$@" $libsl $extralibs $frameworks >$xtmp 2>&1then	xxout	exit 0else	xxout	rm -f $target	exit 1fi