#!/bin/sh

FINK_PREFIX="$1"; shift

export FC_LIB="$FINK_PREFIX/lib/fontconfig2/lib"
export FT_LIB="$FINK_PREFIX/lib/freetype219/lib"
export X11_ROOT=/usr/X11R6
if [ -d /usr/X11 ]; then
	export X11_ROOT=/usr/X11
fi

if [ -e "$X11_ROOT/lib/libfreetype.la" ]; then
	if [ -e "$X11_ROOT/lib/libfontconfig.la" ]; then

		install -d -m 755 "$FC_LIB"

		sed -e "s|-L$X11_ROOT/lib||g" \
		    -e "s|$X11_ROOT/lib/libfreetype.la|-L$FT_LIB $FT_LIB/libfreetype.la|" \
		    -e "s|/usr/lib/libexpat.la|-L$FINK_PREFIX/lib $FINK_PREFIX/lib/libexpat.la|" \
		    -e "s|libdir=$X11_ROOT/lib|libdir=$FC_LIB|" \
		    -e "s|libfontconfig\.[0-9]*\.[0-9]*\.[0-9]*\.dylib||" \
			"$X11_ROOT/lib/libfontconfig.la" > "$FC_LIB/libfontconfig.fink.la"

	else
		echo "WARNING: $X11_ROOT/lib/libfontconfig.la does not exist, skipping."
	fi
else
	echo "WARNING: $X11_ROOT/lib/libfreetype.la does not exist, skipping."
fi

if [ ! -e "$FC_LIB/libfontconfig.fink.la" ]; then
	# we have to make a fake one
	cat <<END >"$FC_LIB/libfontconfig.fink.la"
# libfontconfig.la - a libtool library file
# Generated by ltmain.sh - GNU libtool 1.5.22 (1.1220.2.365 2005/12/18 22:14:06)
#
# Please DO NOT delete this file!
# It is necessary for linking the library.

# The name that we can dlopen(3).
dlname='libfontconfig.1.dylib'

# Names of this library.
library_names='libfontconfig.1.dylib libfontconfig.dylib '

# The name of the static archive.
old_library=''

# Libraries that this one depends upon.
dependency_libs=''

# Version information for libfontconfig.
current=4
age=3
revision=0

# Is this an already installed library?
installed=yes

# Should we warn about portability when linking against -modules?
shouldnotlink=no

# Files to dlopen/dlpreopen
dlopen=''
dlpreopen=''

# Directory that this library needs to be installed in:
libdir=$FINK_PREFIX/lib/fontconfig2/lib
END

fi
/bin/ln -sfh "libfontconfig.fink.la" \
   "$FC_LIB/libfontconfig.la"

if [ -e "$X11_ROOT/lib/pkgconfig/fontconfig.pc" ]; then

	install -d -m 755 "$FC_LIB/pkgconfig"

	sed -e "s|$X11_ROOT|$FINK_PREFIX/lib/fontconfig2|" \
		"$X11_ROOT/lib/pkgconfig/fontconfig.pc" \
		> "$FC_LIB/pkgconfig/fontconfig.fink.pc"

	/bin/ln -sfh "fontconfig.fink.pc" \
		"$FC_LIB/pkgconfig/fontconfig.pc"

else
	echo "WARNING: $X11_root/lib/pkgconfig/fontconfig.pc does not exist, skipping."
fi

exit 0

