#! /bin/sh
#
# ltversion script
# $Id: ltversion,v 1.8 2001/08/09 13:23:30 amai Exp $
#
# Contributed from:  Pavel Roskin <pavel_roskin@geocities.com>
#
# ltversion VERSION [PREFIX]
#    Set Motif-$VERSION compatible LessTif library as a default for
#    newly compiled programs.
#    The library should be in $PREFIX (or where mwm is found)


if test x"$1" = x
then
	echo "Usage:"
	echo "$0 VERSION [PREFIX]"
	echo "    Set Motif-\$VERSION compatible LessTif environment (headers&libs) as default"
	echo "    for newly compiled programs"
	echo "    \$VERSION may be either '1.2', '2.0' or '2.1'"
	echo "    The library should be in \$PREFIX/lib"
	echo "    (By default \$PREFIX is the parent directory of the mwm directory)"
	exit 1
else
	lt_version="$1"
fi

if test x"$2" = x
then
	lt_prefix=`which mwm | sed -n -e 's/^\([^ ]*\)\/bin\/mwm$/\1/p'`
	if test x"$lt_prefix" = x
	then
		echo "FATAL: Cannot find mwm - specify prefix explicitly"
		exit 2
	fi
else
	lt_prefix="$2"
fi


#
# libXm
#

# Link libXm.la
if test -f "$lt_prefix"/LessTif/Motif"$lt_version"/lib/libXm.la; then
	rm -rf "$lt_prefix"/lib/libXm.la
	ln -s "$lt_prefix"/LessTif/Motif"$lt_version"/lib/libXm.la "$lt_prefix"/lib/libXm.la
else
	echo "FATAL: Cannot find ${lt_prefix}/LessTif/Motif${lt_version}/lib/libXm.la"
	exit 11
fi

# Extract names for shared and static libXm
shared_lib=`sed -n -e 's/^library_names=.\(.* \)\?\([^ ]*\).$/\2/p' "$lt_prefix"/lib/libXm.la`
static_lib=`sed -n -e 's/^old_library=.\(.* \)\?\([^ ]*\).$/\2/p' "$lt_prefix"/lib/libXm.la`

# Link shared libXm
if test -f "$lt_prefix"/LessTif/Motif"$lt_version"/lib/"$shared_lib"; then
	rm -rf "$lt_prefix"/lib/"$shared_lib"
	ln -s "$lt_prefix"/LessTif/Motif"$lt_version"/lib/"$shared_lib" "$lt_prefix"/lib/"$shared_lib"
fi

# Link static libXm
if test -f "$lt_prefix"/LessTif/Motif"$lt_version"/lib/"$static_lib"; then
	rm -rf "$lt_prefix"/lib/"$static_lib"
	ln -s "$lt_prefix"/LessTif/Motif"$lt_version"/lib/"$static_lib" "$lt_prefix"/lib/"$static_lib"
fi


#
# libMrm
#

# Link libMrm.la
if test -f "$lt_prefix"/LessTif/Motif"$lt_version"/lib/libMrm.la; then
	rm -rf "$lt_prefix"/lib/libMrm.la
	ln -s "$lt_prefix"/LessTif/Motif"$lt_version"/lib/libMrm.la "$lt_prefix"/lib/libMrm.la
else
	echo "FATAL: Cannot find ${lt_prefix}/LessTif/Motif${lt_version}/lib/libMrm.la"
	exit 12
fi

shared_lib=`sed -n -e 's/^library_names=.\(.* \)\?\([^ ]*\).$/\2/p' "$lt_prefix"/lib/libMrm.la`
static_lib=`sed -n -e 's/^old_library=.\(.* \)\?\([^ ]*\).$/\2/p' "$lt_prefix"/lib/libMrm.la`

# Link shared libMrm
if test -f "$lt_prefix"/LessTif/Motif"$lt_version"/lib/"$shared_lib"; then
	rm -rf "$lt_prefix"/lib/"$shared_lib"
	ln -s "$lt_prefix"/LessTif/Motif"$lt_version"/lib/"$shared_lib" "$lt_prefix"/lib/"$shared_lib"
fi

# Link static libMrm
if test -f "$lt_prefix"/LessTif/Motif"$lt_version"/lib/"$static_lib"; then
	rm -rf "$lt_prefix"/lib/"$static_lib"
	ln -s "$lt_prefix"/LessTif/Motif"$lt_version"/lib/"$static_lib" "$lt_prefix"/lib/"$static_lib"
fi


#
# libUil
#

# Link libUil.la
if test -f "$lt_prefix"/LessTif/Motif"$lt_version"/lib/libUil.la; then
	rm -rf "$lt_prefix"/lib/libUil.la
	ln -s "$lt_prefix"/LessTif/Motif"$lt_version"/lib/libUil.la "$lt_prefix"/lib/libUil.la
else
	echo "FATAL: Cannot find ${lt_prefix}/LessTif/Motif${lt_version}/lib/libUil.la"
	exit 13
fi

shared_lib=`sed -n -e 's/^library_names=.\(.* \)\?\([^ ]*\).$/\2/p' "$lt_prefix"/lib/libUil.la`
static_lib=`sed -n -e 's/^old_library=.\(.* \)\?\([^ ]*\).$/\2/p' "$lt_prefix"/lib/libUil.la`

# Link shared libUil
if test -f "$lt_prefix"/LessTif/Motif"$lt_version"/lib/"$shared_lib"; then
	rm -rf "$lt_prefix"/lib/"$shared_lib"
	ln -s "$lt_prefix"/LessTif/Motif"$lt_version"/lib/"$shared_lib" "$lt_prefix"/lib/"$shared_lib"
fi

# Link static libUil
if test -f "$lt_prefix"/LessTif/Motif"$lt_version"/lib/"$static_lib"; then
	rm -rf "$lt_prefix"/lib/"$static_lib"
	ln -s "$lt_prefix"/LessTif/Motif"$lt_version"/lib/"$static_lib" "$lt_prefix"/lib/"$static_lib"
fi


#
# Headers
#

# Link Xm/ headers
if test -d "$lt_prefix"/LessTif/Motif"$lt_version"/include/Xm; then
	rm -rf "$lt_prefix"/include/Xm
	ln -sf "$lt_prefix"/LessTif/Motif"$lt_version"/include/Xm "$lt_prefix"/include/Xm
else
	echo "Warning: Cannot find ${lt_prefix}/LessTif/Motif${lt_version}/include/Xm"
#	exit 21
fi

# Link Mrm/ headers
if test -d "$lt_prefix"/LessTif/Motif"$lt_version"/include/Mrm; then
	rm -rf "$lt_prefix"/include/Mrm
	ln -sf "$lt_prefix"/LessTif/Motif"$lt_version"/include/Mrm "$lt_prefix"/include/Mrm
else
	echo "Warning: Cannot find ${lt_prefix}/LessTif/Motif${lt_version}/include/Mrm"
#	exit 22
fi

# Link uil/ headers
if test -d "$lt_prefix"/LessTif/Motif"$lt_version"/include/uil; then
	rm -rf "$lt_prefix"/include/uil
	ln -sf "$lt_prefix"/LessTif/Motif"$lt_version"/include/uil "$lt_prefix"/include/uil
else
	echo "Warning: Cannot find ${lt_prefix}/LessTif/Motif${lt_version}/include/uil"
#	exit 23
fi


# The End
echo "Done."
exit 0
