#! /bin/sh

##  DOS cross-compilation for libcaca -- Sam Hocevar <sam@hocevar.net>

set -x
set -e

# Clean up our working directory
SRCDIR="`pwd`"
DIRNAME="libcaca-dos-`sed -ne 's/^AM_INIT_AUTOMAKE(.*, \(.*\)).*/\1/p' configure.ac`"
INSTALLDIR="`pwd`/${DIRNAME}"
BUILDDIR="${INSTALLDIR}/build"
rm -Rf "${INSTALLDIR}"
rm -f "${INSTALLDIR}.zip"
mkdir "${INSTALLDIR}"
mkdir "${BUILDDIR}"

cd "${BUILDDIR}"
# Build for DOS
"${SRCDIR}/configure" --host=i386-pc-msdosdjgpp --prefix=/ --bindir=/ --libdir=/ --disable-imlib2 --disable-doc --disable-ruby --disable-csharp --disable-cxx
make pkglibdir=/lib pkgdatadir=/data
# Install into our private directory
make install DESTDIR="${INSTALLDIR}" pkglibdir=/lib pkgdatadir=/
cd "${SRCDIR}"
rm -Rf "${BUILDDIR}"

i386-pc-msdosdjgpp-strip "${INSTALLDIR}/"*.exe

mkdir "${INSTALLDIR}/doc"
for f in COPYING COPYING.LGPL COPYING.GPL README AUTHORS NEWS NOTES THANKS; do
   sed -e 's/$/^M/' < "${SRCDIR}/${f}" > "${INSTALLDIR}/doc/${f}.txt"
done

rm -Rf "${INSTALLDIR}/share"
rm -Rf "${INSTALLDIR}/man"
rm -Rf "${INSTALLDIR}/include"
rm -Rf "${INSTALLDIR}/pkg-config"
rm -f "${INSTALLDIR}/caca-config"
rm -f "${INSTALLDIR}/"*.a
rm -f "${INSTALLDIR}/"*.la

# Pack the directory
zip "${DIRNAME}.zip" `find "${DIRNAME}"`
rm -Rf "${INSTALLDIR}"

