#!/bin/sh
# fixltconfig v1.3.2  (c) 8.11.99 by Andreas Ley  (u) 9.6.2004
# Fixes unwanted ltconfig features
# - don't add path lists
# - generate shared libraries, not shared objects on aix
# - don't fix *.la paths

usage()
{
	echo "Usage: `basename $0` [-h] [filename [...]]" >&2
	exit 1
}

set -- `getopt hx $*` || usage

TRACE=false
while :; do
	case $1 in
		-h)     sed '1d;s/^# *//;/^$/q' $0; usage;;
		-x)	set -x; TRACE=true; shift;;
		--)     shift; break;;
	esac
done

test $# -eq 0 && set -- `find . -name ltconfig -o -name ltmain.sh`

for file do
	echo "${file}..."
	#
	# Ok, this is difficult, so at least _some_ documentation here: :)
	#
	perl -pi.orig -e '$version_type=$1 if (/version_type=(.*)/);
	#
	# This removes path lists from HP-UX shared libaries. Since we often
	# move libraries (e.g. from /usr/segment/lib to /usr/machine/lib) after
	# installation, the path lists would usually be wrong.
	#
	s/\s*\+b \$install_libdir//;
	#
	# This rule changes the building process from shared objects to shared
	# libraries on AIX - because that'"'"'s what we usually need.
	#
	s/(.*-o \$objdir\/)\$soname(.*-bnoentry.*)'"'"'/$1shr.o$2 && ar cr \$objdir\/\$soname \$objdir\/shr.o'"'"'/;
	#
	# A tribute to autoconf 2.12
	#
	s/\/\/'"'"'\\'"'"''"'"'/$& | sort -u/;
	s/;\$AR cru \$lib \$objdir\/\$soname//;
	if (/AIX has no versioning support, so we append a major version to the name./) {
		<>;
		undef $_;
	}
	#
	# This rule fixes autoconf 2.12 ltconfigs, which omit the major version
	# number for IRIX shared libraries soname_spec and library_names_spec.
	# This has been fixed in autoconf 2.13.
	#
	s/soname_spec='"'"'\${libname}\${release}.so'"'"'/soname_spec='"'"'\${libname}\${release}.so.\$major'"'"'/ if ($version_type eq "osf");
	s/(library_names_spec='"'"'\${libname}\${release}.so.\$versuffix) (\$libname.so'"'"')/$1 \${libname}\${release}.so.\$major $2/ if ($version_type eq "osf");
	#
	# ltconfig uses /usr/bin/file to check for shared libraries, but we
	# don'"'"'t have /usr/bin/file everywhere - in fact, it'"'"'s not
	# installed on a base debian system.
	#
	s/file_magic_cmd=\/usr\/bin\/file/file_magic_cmd=\/usr\/machine\/bin\/file/ if ($version_type eq "linux");
	#
	# ltmain.sh rebuilds *.la paths
	# (But it has to, since local libraries have a /tmp/... path)
	# Better move the *.la back to /usr/machine/lib
	#
	#s/(newdependency_lib.*)\$libdir\/\$name/$1\$deplib/;
	' ${file}
done

exit 0
