#!/bin/sh

mkdir -p build
rm -f icons/big/*.ml_icon
rm -f icons/small/*.ml_icon
rm -f icons/*.ml_icon
rm -f *.cma *.cmxa *.a
rm -f mlgnut mlnap mlbt mldonkey mlslsk mldonkey_gui*
rm -f build/*.cma build/*.cmxa build/*.a
touch .depend

case "`uname -s`" in
  *FreeBSD*)
    CPPFLAGS="${CPPFLAGS} -I/usr/local/include"
    export CPPFLAGS
    LDFLAGS="${LDFLAGS} -L/usr/local/lib"
    export LDFLAGS
    ;;
  *)
    ;;
esac

if test ! -d config; then
    echo "Missing ./config/ directory. Re-download mldonkey"
else
    cd config \
    && if test ! -f ./configure; then
          if which autoconf259; then
              ac="autoconf259"
          else if which autoconf-2.59; then
              ac="autoconf-2.59"
          else if which autoconf-2.5x; then
              ac="autoconf-2.5x"
          else
              ac="autoconf"
          fi; fi; fi
          echo "Running Autoconf ($ac)..."
          $ac
       fi \
    && if test ! -f ../Makefile; then
          echo "Running m4 to generate Makefile..."
          m4 Makefile.in > ../Makefile
       fi \
    && ./configure $*
fi
