#!/bin/sh

if [ `id -u` != 0 ]; then
	echo "you must be root to run this!"
	exit 1
fi

if [ ! -x /usr/bin/install_name_tool ]; then
	echo "can't run /usr/bin/install_name_tool"
	exit 2
fi

LIBS="dps dpstk freetype GL GLU ICE oldX psres SM X11 Xaw Xaw Xext Xfont Xft Xi Xmu Xmuu Xp Xpm Xrandr Xrender Xt XTrap Xtst"

for lib in $LIBS; do
	FULLNAME=`find /usr/X11R6/lib -type f -name lib${lib}.\*.dylib`
	VERSION=`echo $FULLNAME | sed -e "s,^.*/lib${lib}.,," -e "s,.dylib$,,"`
	MAJOR=`echo $VERSION | cut -d. -f1`
	/usr/bin/install_name_tool -change /usr/X11R6/lib/lib${lib}.${VERSION}.dylib /usr/X11R6/lib/lib${lib}.${MAJOR}.dylib /usr/X11R6/lib/lib${lib}.${VERSION}.dylib
done

