
# **********                                                                                  **********
# **********                            Autoconf, configure internals                         **********
# **********                                                                                  **********

AC_REVISION(norev)
AC_PREREQ([2.69])
AC_INIT
AC_CONFIG_SRCDIR([Makefile.config.in])
AC_CONFIG_HEADER(config.h)
AC_CONFIG_MACRO_DIR([m4])

CONFIGURE_RUN=yes
CONFIGURE_ARGUMENTS=$ac_configure_args
echo "Arguments to configure: $CONFIGURE_ARGUMENTS"

cd ..
SOURCE_DIR=`pwd`
cd config

# **********                                                                                  **********
# **********                                   MLDonkey version                               **********
# **********                                                                                  **********

MAJOR_VERSION=3
MINOR_VERSION=2
SUB_VERSION=1   # range 0-7 due to eMule limitations

# **********                                                                                  **********
# **********                                  check for C compiler                            **********
# **********                                                                                  **********

AC_PROG_CC
CC_VERSION=`$CC -dumpversion`
AC_EXEEXT
AC_PROG_CPP

# **********                                                                                  **********
# **********                                    System checks                                 **********
# **********                                                                                  **********

AC_CANONICAL_HOST

OS_FILES=unix
OS_FILES2=unix
SYSTEM=unknown
FIX_BROKEN_CPP=
case $host in
  *mingw*)
    SYSTEM=mingw
    OS_FILES=mingw
    OS_FILES2=mingw
    PTHREAD_LIBS="-lpthreadGC2 -lwsock32"
    PTHREAD_MINGW_CFLAGS="-DPTW32_STATIC_LIB"
    AC_MSG_CHECKING(for mingw-runtime version)
      
cat >mingw_rt_ver.c <<'END'
#include <stdio.h>
#include <_mingw.h>
main(int argc, char *argv[[]])  {

int required_runtime_major=3;       /**********     change required mingw-runtime   **********/
int required_runtime_minor=10;      /**********              version here           **********/

#ifdef __MINGW32_MAJOR_VERSION
#  ifdef __MINGW32_MINOR_VERSION
     switch(argv[[1]][[0]]) {
       case 'x':
         printf("%d.%d", __MINGW32_MAJOR_VERSION, __MINGW32_MINOR_VERSION);
         break;
       case 'y':
         if ((__MINGW32_MAJOR_VERSION == required_runtime_major && __MINGW32_MINOR_VERSION < required_runtime_minor) || 
             (__MINGW32_MAJOR_VERSION < required_runtime_major)) {
           printf("no");
           break; }
         else {
           printf("yes");
           break; }
       case 'z':
         printf("%d.%d", required_runtime_major, required_runtime_minor);
         break;
     }
     return 0;
#  else
   printf("__MINGW32_MINOR_VERSION not defined in _mingw.h");
   return 0;
#  endif
#else
 printf("__MINGW32_MAJOR_VERSION not defined in _mingw.h");
 return 0;
#endif
}
END

    $CC -o mingw_rt_ver ./mingw_rt_ver.c
    MINGW_RT_VER="`./mingw_rt_ver x`"
    MINGW_RT_VER_OK="`./mingw_rt_ver y`"
    MINGW_RT_VER_REQ="`./mingw_rt_ver z`"
    rm -f mingw_rt_ver mingw_rt_ver.*
    AC_MSG_RESULT($MINGW_RT_VER)
    if test "$MINGW_RT_VER_OK" = "no"; then
      echo "********  mingw-runtime version $MINGW_RT_VER_REQ is required  *********" 1>&2;
      exit 1
    fi
    ;;
  *cygwin*)
    SYSTEM=cygwin
    OS_FILES2=cygwin
    ;;
  *kfreebsd*)
    SYSTEM=kfreebsd
    ;;
  *freebsd*|*dragonfly*)
    SYSTEM=freebsd
    CPPFLAGS="${CPPFLAGS} -I/usr/local/include"
    LDFLAGS="${LDFLAGS} -L/usr/local/lib"
    ;;
  *openbsd*)
    SYSTEM=openbsd
    CPPFLAGS="${CPPFLAGS} -I/usr/local/include"
    LDFLAGS="${LDFLAGS} -L/usr/local/lib"
    ;;
  *netbsd*)
    SYSTEM=netbsd
    ;;
  *linux*)
    SYSTEM=linux
    ;;
  *solaris*)
    SYSTEM=solaris
    ;;
  *morphos*|*amigaos*)
    SYSTEM=morphos
    ;;
  *aix*)
    SYSTEM=aix
    ;;
  *beos*)
    SYSTEM=beos
    ;;
  *osf*)
    SYSTEM=osf
    ;;
  *irix*)
    SYSTEM=irix
    ;;
  *hppa*|*hpux*)
    SYSTEM=hpux
    ;;
  *darwin*|*rhapsody*|*macosx*)
    SYSTEM=macos
    AC_CHECK_PROG(SED, sed, sed)
    if test "$ac_cv_prog_SED" = "sed"; then
      FIX_BROKEN_CPP="| sed -n '/^\#pragma/!p'"
    else
      AC_CHECK_PROG(GREP, grep, grep)
      if test "$ac_cv_prog_GREP" = "grep"; then
        FIX_BROKEN_CPP="| grep -v '^\#pragma'"
      fi
    fi
    if test "xFIX_BROKEN_CPP" = "x"; then
      echo "Apple cpp produces broken files, your system lacks sed or grep to fix it"
      exit 1
    fi
    ;;
  *-gnu*)
    SYSTEM=hurd
    ;;
esac
if test "x$SYSTEM" = "xunknown"; then
  echo "Unknown build system, please report to the MLDonkey development team at http://mldonkey.sourceforge.net/forums/"
  exit 1
fi

# Parse git version if available

if test -d ../.git; then
  AC_MSG_NOTICE(checking git revision)
  AC_CHECK_PROG(GIT,git,yes)
  SUB_VERSION3="git"
  if test "$ac_cv_prog_GIT" = "yes"; then
    GIT_BRANCH=`git symbolic-ref -q --short HEAD`
    GIT_COMMIT=`git describe --always --tags`
    case "$GIT_BRANCH" in
    ""|"master")
      SCM_VERSION="${GIT_COMMIT}"
      ;;
    *)
      SCM_VERSION="${GIT_COMMIT}-${GIT_BRANCH}"
      ;;
    esac
  else
    AC_MSG_NOTICE(cannot determine git revision)
    SCM_VERSION=""
  fi
fi

# **********                                                                                  **********
# **********             build MLDonkey version, Required OCaml and LablGTK versions          **********
# **********                                                                                  **********

MLDONKEY_VERSION=$MAJOR_VERSION.$MINOR_VERSION.$SUB_VERSION
if test -f ./subrelease; then
  MLDONKEY_VERSION=$MLDONKEY_VERSION`cat ./subrelease`
fi
if test ! -z "$SUB_VERSION3"; then
  MLDONKEY_VERSION=$MLDONKEY_VERSION.$SUB_VERSION3
fi

MINIMUM_OCAML=4.03.0

REQUIRED_LABLGTK=1.2.7

LABLGTK_NAME=lablgtk

# **********                                                                                  **********
# **********                    Network and Feature configure switch variables                **********
# **********                                                                                  **********

# **********   currently not working Networks, can't be enabled

SOULSEEK=no
OPEN_NAPSTER=no
OPENFT=no

# **********   working Networks, enabled by default

DONKEY=yes
BITTORRENT=yes
GNUTELLA=no
GNUTELLA2=no
FASTTRACK=yes
FILETP=yes
DIRECT_CONNECT=yes

# **********   predefined configure variations

MULTINET=yes
MINIMUM=no

# **********   Features, enabled by default

DONKEY_SUI=yes
DONKEY_SUI_FILE=DonkeySui2
GD=yes
BZIP2=yes
MAGIC=yes
ICONV=yes
UPNP_NATPMP=no
UPNP_NATPMP_FORCE=no

# **********

BATCH=no
FORCE_MINGW=no
PROFILE=no
DEBUG=no
DEV=no
GUI=no
CHECKBOUNDS=false
DEVFLAGS=

# **********                                                                                  **********
# **********                Network and Feature configure switches and dependency             **********
# **********                                                                                  **********

AC_ARG_ENABLE(multinet,
  AS_HELP_STRING([--disable-multinet], [disable all networks except eDonkey (with Overnet and Kademlia)]),
  [MULTINET="$enableval"])
AC_ARG_ENABLE(minimum,
  AS_HELP_STRING([--enable-minimum], [enable minimum set of features and networks (eDonkey, iconv and threads enabled)]),
  [MINIMUM="$enableval"])
AC_ARG_ENABLE(minimum,
  AS_HELP_STRING([--enable-minimum=all], [enable only eDonkey network and disable all optional features (not recommended)]),
  [MINIMUM="$enableval"])

if [ test ! "$MULTINET" = "yes" ] || [ test "$MINIMUM" = "yes" ] || [ test "$MINIMUM" = "all" ]; then
  GNUTELLA=no
  GNUTELLA2=no
  FASTTRACK=no
  DIRECT_CONNECT=no
  FILETP=no
  BITTORRENT=no
fi
if [ test "$MINIMUM" = "yes" ] || [ test "$MINIMUM" = "all" ]; then
  DONKEY_SUI=no
  GD=no
  BZIP2=no
  MAGIC=no
fi
if [ test "$MINIMUM" = "all" ]; then
  ICONV=no
fi

#AC_ARG_ENABLE(soulseek,      [  --disable-soulseek      disable support for SoulSeek], [SOULSEEK="$enableval"])
#AC_ARG_ENABLE(opennap,       [  --disable-opennap       disable support for Open Napster], [OPEN_NAPSTER="$enableval"])
AC_ARG_ENABLE(directconnect,
  AS_HELP_STRING([--disable-directconnect], [disable support for Direct Connect]),
  [DIRECT_CONNECT="$enableval"])
#AC_ARG_ENABLE(openft,        [  --disable-openft        disable support for OpenFT], [OPENFT="$enableval"])

AC_ARG_ENABLE(donkey,
  AS_HELP_STRING([--disable-donkey], [disable support for eDonkey]),
  [DONKEY="$enableval"])
AC_ARG_ENABLE(donkeysui,
  AS_HELP_STRING([--disable-donkeysui], [disable support for eMule SecureUserIdent]),
  [DONKEY_SUI="$enableval"])
AC_ARG_ENABLE(bittorrent,
  AS_HELP_STRING([--disable-bittorrent], [disable support for Bittorent]),
  [BITTORRENT="$enableval"])
AC_ARG_ENABLE(filetp,
  AS_HELP_STRING([--disable-filetp], [disable support for fileTP]),
  [FILETP="$enableval"])
AC_ARG_ENABLE(gnutella,
  AS_HELP_STRING([--disable-gnutella], [disable support for Gnutella]),
  [GNUTELLA="$enableval"])
AC_ARG_ENABLE(gnutella2,
  AS_HELP_STRING([--disable-gnutella2], [disable support for Gnutella2]),
  [GNUTELLA2="$enableval"])
AC_ARG_ENABLE(fasttrack,
  AS_HELP_STRING([--disable-fasttrack], [disable support for FastTrack]),
  [FASTTRACK="$enableval"])

AC_ARG_ENABLE(batch,
  AS_HELP_STRING([--enable-batch], [reply YES to all queries in this script]),
  [BATCH="$enableval"])
AC_ARG_ENABLE(mingw,
  AS_HELP_STRING([--enable-mingw], [force compilation with MINGW on Cygwin]),
  [FORCE_MINGW="$enableval"])
AC_ARG_ENABLE(checks,
  AS_HELP_STRING([--enable-checks], [enable bounds-checking for array/string accesses]),
  [CHECKBOUNDS="$enableval"])
if test "$CHECKBOUNDS" = "yes"; then
  CHECKBOUNDS=true
fi

AC_ARG_ENABLE(profile,
  AS_HELP_STRING([--enable-profile], [compile with gprof profiling support (enables debug)]),
  [PROFILE="$enableval"])
AC_ARG_ENABLE(debug,
  AS_HELP_STRING([--enable-debug], [compile with debugging information]),
  [DEBUG="$enableval"])
AC_ARG_ENABLE(dev,
  AS_HELP_STRING([--enable-dev], [development mode (enables debug and annot information)]),
  [DEV="$enableval"])
if test "$PROFILE" = "yes"; then
  DEBUG="yes"
fi
if test "$DEV" = "yes"; then
  DEBUG="yes"
fi
AC_ARG_ENABLE(gui,
  AS_HELP_STRING([--disable-gui], [disable GUI build (default)]),
  [GUI="$enableval"])
AC_ARG_ENABLE(gui,
  AS_HELP_STRING([--enable-gui=oldgui|newgui1|newgui2], 
                 [enable GUI (newgui2 uses GTK2 (default), other GUIs use GTK1)]),
  [GUI="$enableval"])
if test "$GUI" = "yes"; then
  GUI=newgui2
fi
if test ! "$GUI" = "newgui2"; then
  if test ! "$GUI" = "newgui1"; then
    if test ! "$GUI" = "oldgui"; then
      GUI=no
    fi
  fi
fi

AC_ARG_ENABLE(iconv,
  AS_HELP_STRING([--disable-iconv], [disable the use of iconv]),
  [ICONV="$enableval"])
AC_ARG_ENABLE(gd,
  AS_HELP_STRING([--disable-gd], [disable the use of gd]),
  [GD="$enableval"])
AC_ARG_ENABLE(bzip2,
  AS_HELP_STRING([--disable-bzip2], [disable the use of bzip2]),
  [BZIP2="$enableval"])
AC_ARG_ENABLE(magic,
  AS_HELP_STRING([--disable-magic], [disable the use of libmagic (GNU file)]),
  [MAGIC="$enableval"])
AC_ARG_ENABLE(upnp-natpmp,
  AS_HELP_STRING([--enable-upnp-natpmp], [enable the use of libminiupnpc and libnatpmp]),
  [UPNP_NATPMP="$enableval"])
AC_ARG_ENABLE(force-upnp-natpmp,
  AS_HELP_STRING([--enable-force-upnp-natpmp], [force local compilation of libminiupnpc and libnatpmp]),
  [UPNP_NATPMP_FORCE="$enableval"])

if test "$FORCE_MINGW" = "yes"; then
    CC="$CC -mno-cygwin"
    CPP="$CPP -mno-cygwin"
    OS_FILES=mingw
    OS_FILES2=mingw
    SYSTEM=mingw
fi

OCAML_PATH=

echo ""
echo "--------------------------------"
echo "     Checking system tools."
echo "--------------------------------"

AC_PROG_RANLIB
AC_CHECK_PROG(GNU_MAKE, gmake, gmake)
AC_CHECK_PROG(GNU_MAKE, make, make)

if test "x$GNU_MAKE" != "x"; then
  AC_MSG_CHECKING( [if $GNU_MAKE is GNU make] )
  $GNU_MAKE --version > /dev/null 2>&1
  if test "$?" != "0"; then
    AC_MSG_RESULT([no])
        AC_MSG_ERROR(GNU make not found)
  else
    AC_MSG_RESULT([yes])
  fi
else
  AC_MSG_ERROR(GNU make not found)
fi

AC_CHECK_PROG(COMPRESS, bzip2, bzip2)
AC_CHECK_PROG(COMPRESS, gzip, gzip)

if test "$ac_cv_prog_COMPRESS" = "bzip2"; then
   COMPRESS_EXT=bz2
else
   COMPRESS_EXT=gz
fi

AC_PATH_PROG(PERL, perl, perl)
AC_CHECK_PROG(RPMBUILD,rpmbuild,rpmbuild)
AC_CHECK_PROG(RPMBUILD,rpm,rpm)

AC_CHECK_PROG(WGET, wget, wget)
if test -z "$ac_cv_prog_WGET"; then
  $CC -o wget wget.c || echo "Cannot compile wget.c"
  AC_PATH_PROG(WGET, wget,,$SOURCE_DIR/config)
  ac_cv_prog_WGET="$ac_cv_path_WGET"
fi
WGET="$ac_cv_prog_WGET"

echo "----------------------------------------"
echo "     Checking system tools finished."
echo "----------------------------------------"
echo ""
echo "--------------------------------"
echo "     Checking OCaml compiler."
echo "--------------------------------"

CONFIG_DIR=$SOURCE_DIR/config
PATCH_DIR=$SOURCE_DIR/patches
LOCAL_DIR=$PATCH_DIR/local
BUILD_DIR=$PATCH_DIR/build

AC_ARG_ENABLE(local-prefix,
  AS_HELP_STRING([--enable-local-prefix=DIR], [specify path for temporary tools installation (DIR must be absolute)]),
  [LOCAL_DIR="$enableval"])

AC_PATH_PROG(OCAMLC,ocamlc.opt,"",[$PATH])
AC_CHECK_TOOL(OCAMLC,ocamlc,ocamlrun ocamlc)
AC_PATH_PROG(CAMLP4, camlp4,"",[$PATH])

if [ test -z "$OCAMLC" ] || [ test -z "$CAMLP4" ]; then
   echo "OCaml or Camlp4 missing, local build of OCaml is not supported anymore"
   exit 1
else
  OCAMLVERSION=`$OCAMLC -v | sed -n -e 's|.*version* *\(.*\)$|\1|p' `
  if test "$OCAMLVERSION" \< "$MINIMUM_OCAML"; then
    echo "Detected OCaml $OCAMLVERSION, required at least $MINIMUM_OCAML, local build of OCaml is not supported anymore"
    exit 1
  fi
fi

AC_PATH_PROG(OCAMLOPT, ocamlopt.opt, ,[$PATH])
AC_PATH_PROG(OCAMLOPT, ocamlopt, no, [$PATH])
AC_PATH_PROG(OCAMLDEP, ocamldep, ocamldep, [$PATH])
AC_PATH_PROG(OCAMLLEX, ocamllex.opt, , [$PATH])
AC_PATH_PROG(OCAMLLEX, ocamllex, ocamllex, [$PATH])
AC_PATH_PROG(OCAMLYACC, ocamlyacc, ocamlyacc, [$PATH])
AC_PATH_PROG(OCAMLDOC, ocamldoc, ocamldoc, [$PATH])
AC_PATH_PROG(OCAMLMKTOP, ocamlmktop, ocamlmktop, [$PATH])
AC_PATH_PROG(CAMLP4, camlp4, camlp4, [$PATH])
AC_PATH_PROG(CAMLP4OF, camlp4of, $CAMLP4 pa_o.cmo pr_o.cmo Camlp4QuotationExpander.cmo Camlp4GrammarParser.cmo, [$PATH])

OCAMLVERSION=`$OCAMLC -v | sed -n -e 's|.*version* *\(.*\)$|\1|p' `
OCAMLVERSION_MAJOR=`echo $OCAMLVERSION | sed -n -e 's/^\([[0-9]]*\.[[0-9]]*\).*/\1/' -e 's/\.//gp'`
OCAMLLIB=`$OCAMLC -where`

# check if native dynlink is supported and therefore needed for linking
CAMLP4LIB_OPT="camlp4lib.cmxa"
CAMLP4LIB_BYTE="camlp4lib.cma"
if test -f $OCAMLLIB/dynlink.cma; then
  CAMLP4LIB_BYTE="dynlink.cma $CAMLP4LIB_BYTE"
fi
if test -f $OCAMLLIB/dynlink.cmxa; then
  CAMLP4LIB_OPT="dynlink.cmxa $CAMLP4LIB_OPT"
fi

# force usage of supported OCaml versions
if test "$OCAMLVERSION" \< "$MINIMUM_OCAML"; then
  echo "******** OCaml version >= $MINIMUM_OCAML required  *********" 1>&2;
  echo "*******  Check http://ocaml.org/  ********" 1>&2;
  exit 1
fi

if test "$OCAMLOPT" = "no"; then
  TARGET_TYPE=byte
  OCAMLLIB_EXT=cma
else
  TARGET_TYPE=opt
  OCAMLLIB_EXT=cmxa

  OCAMLOPTVERSION=`$OCAMLOPT -v | sed -n -e 's|.*version* *\(.*\)$|\1|p' `

  test "$OCAMLOPTVERSION" = "$OCAMLVERSION" || {
    echo "******** Expected ocamlopt version $OCAMLVERSION , but got $OCAMLOPTVERSION *********" 1>&2;
    echo "*******  Check http://ocaml.org/  ********" 1>&2;
    exit 1; }
fi

echo "-------------------------------------------"
echo "     Checking OCaml $OCAMLVERSION finished."
echo "-------------------------------------------"


if test "$PROFILE" = "yes"; then
   OCAMLOPT="$OCAMLOPT -p"
   CFLAGS="$CFLAGS -pg"
fi
if test "$FORCE_MINGW" = "yes"; then
    OCAMLC="$OCAMLC -ccopt -mno-cygwin"
    OCAMLOPT="$OCAMLOPT -ccopt -mno-cygwin"
    OCAMLMKTOP="$OCAMLMKTOP -ccopt -mno-cygwin"
fi
if test "$DEBUG" = "yes"; then
    OCAMLC="$OCAMLC -g"
    OCAMLOPT="$OCAMLOPT -g"
fi

if test "$DEV" = "yes"; then
  DEVFLAGS="-annot -bin-annot -w @a\$(MINUS_WARNING)"
fi

NUMS_INCLUDE=
NUMS=yes
AC_MSG_CHECKING([ocaml num library])
if ! test -f $OCAMLLIB/nums.$OCAMLLIB_EXT; then
  if test -f $OCAMLLIB/num/nums.$OCAMLLIB_EXT; then
    NUMS_INCLUDE="-I +num"
  else
    NUMS_PATH="`ocamlfind query num 2> /dev/null`"
    if test "$NUMS_PATH" != ""; then
      NUMS_INCLUDE="-I $NUMS_PATH"
    else
      NUMS=no
    fi
  fi
fi

if test "$NUMS" = "no"; then
  AC_MSG_RESULT([no])
else
  AC_MSG_RESULT([found $NUMS_INCLUDE])
fi

echo ""
echo "----------------------------------"
echo "     Checking system headers."
echo "----------------------------------"

ifelse(AC_ACVERSION, [2.13], [],
[dnl Large file enabled
   AC_SYS_LARGEFILE

])

dnl Check for native endianness.
AC_C_BIGENDIAN(,,
  [AC_MSG_ERROR([Machine endianness could not be determined])]
)
if test "x$WORDS_BIGENDIAN" = "x"; then
  NATIVEENDIAN=LittleEndian
else
  NATIVEENDIAN=BigEndian
fi
AC_SUBST(NATIVEENDIAN)

# various header files
AC_CHECK_FUNCS(setrlimit getrlimit strerror_r strerror posix_fallocate)
AC_CHECK_HEADERS(byteswap.h,,)
AC_CHECK_HEADERS([sys/utsname.h])
AC_CHECK_HEADERS(arpa/inet.h,,)
AC_CHECK_HEADERS([sys/types.h sys/time.h sys/resource.h netinet/in_systm.h netinet/in.h netinet/ip.h],,,
[#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
#ifdef HAVE_SYS_TIME_H
#include <sys/time.h>
#endif
#ifdef HAVE_NETINET_IN_SYSTM_H
#include <netinet/in_systm.h>
#endif
#ifdef HAVE_NETINET_IN_H
#include <netinet/in.h>
#endif
])

# poll if possible
AC_CHECK_HEADERS(sys/poll.h,,)
AC_CHECK_FUNCS(poll,,)

AC_CHECK_HEADERS(sys/vfs.h,,)
AC_CHECK_HEADERS(sys/statvfs.h,,)
AC_CHECK_HEADERS([sys/param.h sys/mount.h],,,
[#if HAVE_SYS_PARAM_H
#include <sys/param.h>
#endif
])
echo "-------------------------------------------"
echo "     Checking system headers finished."
echo "-------------------------------------------"
echo ""
echo "-----------------------------------"
echo "     Checking system libraries."
echo "-----------------------------------"
echo "----- checking zlib (required)"
AC_CHECK_LIB(z,inflate,,[echo "Zlib missing, did you install zlib and zlib-developer packages?"; exit 1])
AC_CHECK_HEADERS(zlib.h,,[echo "Zlib missing, did you install zlib and zlib-developer packages?"; exit 1])
AC_CHECK_LIB(z,zlibVersion,[AC_DEFINE(HAVE_ZLIBVERSION, 1, zlib)])

if test "$BZIP2" != "no"; then
  echo "----- checking bzlib (optional)"
  AC_CHECK_HEADERS(bzlib.h,[AC_CHECK_LIB(bz2,BZ2_bzReadOpen,[BZIP2=yes],[BZIP2=no])],[BZIP2=no])
fi

if test "$BZIP2" = "yes"; then
  AC_CHECK_LIB(bz2,BZ2_bzlibVersion,[AC_DEFINE(HAVE_BZLIBVERSION, 1, bzip2)])
  AC_DEFINE(USE_BZIP2, 1, [Define to 1 if you have bzip2 support.])
else
  AC_MSG_NOTICE(bzlib not available)
fi

if test "$UPNP_NATPMP_FORCE" = "yes"; then
        UPNP_NATPMP=yes
        cd $PATCH_DIR
        MINIUPNPC=miniupnpc-2.2.8
        LIBNATPMP=libnatpmp-20230423
        $WGET http://miniupnp.tuxfamily.org/files/$MINIUPNPC.tar.gz
        $WGET http://miniupnp.tuxfamily.org/files/$LIBNATPMP.tar.gz
        mkdir -p $BUILD_DIR $LOCAL_DIR/usr/bin $LOCAL_DIR/usr/lib $LOCAL_DIR/usr/include/miniupnpc
        cd $BUILD_DIR
        rm -rf $LIBNATPMP $MINIUPNPC
        tar -xzf $PATCH_DIR/$MINIUPNPC.tar.gz
        tar -xzf $PATCH_DIR/$LIBNATPMP.tar.gz
        if test -f $PATCH_DIR/$LIBNATPMP.patch; then
          echo Patching ...
          patch -p0 < $PATCH_DIR/$LIBNATPMP.patch
        fi
        cd $BUILD_DIR/$LIBNATPMP
        $GNU_MAKE all install PREFIX=$LOCAL_DIR
        cd $BUILD_DIR/$MINIUPNPC
        $GNU_MAKE all install PREFIX=$LOCAL_DIR/usr
        cd $CONFIG_DIR
        rm -rf $BUILD_DIR/$LIBNATPMP $BUILD_DIR/$MINIUPNPC
        CPPFLAGS="${CPPFLAGS} -I$LOCAL_DIR/usr/include"
        LDFLAGS="${LDFLAGS} -L$LOCAL_DIR/usr/lib"
fi

if test "$UPNP_NATPMP" = "yes"; then
  echo "----- checking libminiupnpc >= 1.6 (optional)"
  AC_CHECK_HEADERS(miniupnpc/miniupnpc.h,[AC_CHECK_LIB(miniupnpc,upnpDiscover,[UPNP_NATPMP=yes],[UPNP_NATPMP=no])],[UPNP_NATPMP=no])
fi

if test "$UPNP_NATPMP" = "yes"; then
  echo "----- checking libnatpmp >= 20110808 (optional)"
  AC_CHECK_HEADERS(natpmp.h,[AC_CHECK_LIB(natpmp,initnatpmp,[UPNP_NATPMP=yes],[UPNP_NATPMP=no])],[UPNP_NATPMP=no])
fi

if test "$UPNP_NATPMP" = "yes"; then
  AC_DEFINE(ENABLE_UPNP_NATPMP, 1, [Define to 1 if you have libminiupnpc & libnatpmp for port forwarding support.])
  UPNP_NATPMP_LIBS="-lminiupnpc -lnatpmp $LIBS"
  UPNP_NATPMP_STATIC_LIBS="-lminiupnpc -lnatpmp $LIBS"
fi

if test "$MAGIC" != "no"; then
  echo "----- checking libmagic (GNU file) (optional)"
  AC_CHECK_HEADERS(magic.h,
    [AC_CHECK_LIB(magic,magic_file,
      [AC_CHECK_DECL([MAGIC_ERROR], [MAGIC=yes], [MAGIC=no],[#include <magic.h>])],
      [MAGIC=no])],
    [MAGIC=no])
fi

if test "$MAGIC" = "yes"; then
  MAGICLIB=Magic_magic
else
  MAGICLIB=Magic_nomagic
  AC_MSG_NOTICE(libmagic not available)
fi

GD_JPG=no
GD_PNG=no
if test "$GD" != "no"; then
  echo "----- checking gd (optional)"
  GD=no
  LIBGD=no
  SAVE_LIBS=$LIBS
  SAVE_CFLAGS=$CFLAGS
  SAVE_LDFLAGS=$LDFLAGS
  AC_CHECK_PROG(GDLIBCONFIG, gdlib-config, gdlib-config)
  if test "$ac_cv_prog_GDLIBCONFIG" = "gdlib-config"; then
    GD_LIBS=`$GDLIBCONFIG --libs`
    $GDLIBCONFIG --static-libs > /dev/null 2>&1
    if test "$?" = "0"; then
      GD_STATIC_LIBS=`$GDLIBCONFIG --static-libs`
    fi
    GD_LIBS2="$LIBS -lgd $GD_LIBS"
    LIBS=$GD_LIBS2
    GD_CFLAGS=`$GDLIBCONFIG --cflags`
    CFLAGS="$CFLAGS $GD_CFLAGS"
    GD_LDFLAGS=`$GDLIBCONFIG --ldflags`
    LDFLAGS="$LDFLAGS $GD_LDFLAGS"
    AC_MSG_CHECKING(for libgd > 2.0.14)
    GDVERSION=`$GDLIBCONFIG --version`
    GDMAJORVERSION=`$GDLIBCONFIG --majorversion`
    GDMINORVERSION=`$GDLIBCONFIG --minorversion`
    GDREVISION=`$GDLIBCONFIG --revision`
    case $GDMAJORVERSION in
        1)
            AC_MSG_RESULT(no (found $GDVERSION))
            LIBGD=no
            ;;
        2)
            if test $GDMINORVERSION -ge 1; then
                AC_MSG_RESULT($GDVERSION)
                LIBGD=yes
            else
                if test $GDREVISION -gt 14; then
                    AC_MSG_RESULT($GDVERSION)
                    LIBGD=yes
                else
                    AC_MSG_RESULT(no (found $GDVERSION))
                    LIBGD=no
                fi
            fi
            ;;
        *)
            AC_MSG_RESULT($GDVERSION)
            LIBGD=yes
            ;;
    esac
  else
    LIBGD=yes
  fi

  if test "$LIBGD" = "yes"; then
    AC_CHECK_HEADERS(gd.h,[LIBGD=yes],[LIBGD=no])
  fi

  if test "$LIBGD" = "yes"; then
    AC_MSG_CHECKING(for gdImageCreate in -lgd)
    AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <gd.h>]], [[gdImageCreate (0,0);]])],[LIBGD=yes],[LIBGD=no])
    AC_MSG_RESULT($LIBGD)
    LIBS=$SAVE_LIBS

    if test "$LIBGD" = "no"; then
      AC_MSG_NOTICE([not found, trying another method])
      AC_CHECK_LIB(gd, gdImageCreate, [LIBGD=yes], [LIBGD=no])
    fi
  fi

  if test "$LIBGD" = "yes"; then
    LIBPNG=no
# saving current variables
    SAVE_LIBS_PNG=$LIBS
    SAVE_CFLAGS_PNG=$CFLAGS
    SAVE_LDFLAGS_PNG=$LDFLAGS
    AC_CHECK_PROG(PNGLIBCONFIG, libpng-config, libpng-config)
    if test "$ac_cv_prog_PNGLIBCONFIG" = "libpng-config"; then
# check libpng-config contents and update system variables
      PNG_LIBS=`$PNGLIBCONFIG --libs`
      LIBS="$LIBS $PNG_LIBS"
      PNG_CFLAGS=`$PNGLIBCONFIG --cflags`
      CFLAGS="$CFLAGS $PNG_CFLAGS"
      PNG_LDFLAGS=`$PNGLIBCONFIG --ldflags`
      LDFLAGS="$LDFLAGS $PNG_LDFLAGS"
    fi
    AC_CHECK_LIB(png, png_create_read_struct , [LIBPNG=yes])
# restore variables
    LIBS=$SAVE_LIBS_PNG
    CFLAGS=$SAVE_CFLAGS_PNG
    LDFLAGS=$SAVE_LDFLAGS_PNG

    if test "$LIBPNG" = "no"; then
      AC_MSG_NOTICE(png support not available)
    else
      LIBGD_PNG=no
      LIBS=$GD_LIBS2
      AC_MSG_CHECKING(for gdImagePng in -lgd)
      AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <gd.h>]], [[gdImagePng (0,0);]])],[LIBGD_PNG=yes],[LIBGD_PNG=no])
      AC_MSG_RESULT($LIBGD_PNG)
      LIBS=$SAVE_LIBS

      if test "$LIBGD_PNG" = "no"; then
        AC_MSG_NOTICE([not found, trying another method])
        AC_CHECK_LIB(gd, gdImagePng, [LIBGD_PNG=yes], [LIBGD_PNG=no])
      fi

      AC_MSG_CHECKING(for png support in libgd)
      if test "$LIBGD_PNG" = "yes"; then
        GD=yes
        GD_PNG=yes
        GD_LIBS="$GD_LIBS $PNG_LIBS"
        AC_MSG_RESULT(yes)
        AC_CHECK_LIB(png, png_access_version_number,[AC_DEFINE(HAVE_PNGVERSION, 1, libpng)])
        AC_DEFINE(HAVE_GD_PNG, 1, [Define to 1 if you have png support in libgd.])
      else
        AC_MSG_RESULT(no)
      fi
    fi

    LIBJPEG=no
    AC_CHECK_LIB(jpeg, jpeg_CreateCompress, [LIBJPEG=yes])

    if test "$LIBJPEG" = "no"; then
      AC_MSG_NOTICE(jpeg support not available)
    else
      LIBGD_JPG=no
      LIBS=$GD_LIBS2
      AC_MSG_CHECKING(for gdImageJpeg in -lgd)
      AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <gd.h>]], [[gdImageJpeg (0,0,0);]])],[LIBGD_JPG=yes],[LIBGD_JPG=no])
      AC_MSG_RESULT($LIBGD_JPG)
      LIBS=$SAVE_LIBS

      if test "$LIBGD_JPG" = "no"; then
        AC_MSG_NOTICE([not found, trying another method])
        AC_CHECK_LIB(gd, gdImageJpeg, [LIBGD_JPG=yes], [LIBGD_JPG=no])
      fi

      AC_MSG_CHECKING(for jpeg support in libgd)
      if test "$LIBGD_JPG" = "yes"; then
        GD=yes
        GD_JPG=yes
        GD_LIBS="$GD_LIBS -ljpeg"
        AC_DEFINE(HAVE_GD_JPG, 1, [Define to 1 if you have jpg support in libgd.])
        AC_MSG_RESULT(yes)
      else
        AC_MSG_RESULT(no)
      fi
    fi
  else
    AC_MSG_NOTICE(libgd not available)
  fi
  LIBS=$SAVE_LIBS
  CFLAGS=$SAVE_CFLAGS
  LDFLAGS=$SAVE_LDFLAGS
fi

if test "$GD" != "no"; then
  GDGRAPHICS=DriverGraphics_gd
else
  GDGRAPHICS=DriverGraphics_nogd
fi

if test "$ICONV" = "yes"; then
  echo "----- checking iconv (optional)"
  AM_ICONV
  if test "$am_cv_func_iconv" != "yes"; then
    AC_DEFINE(DISABLE_ICONV, 1, [Define to 1 if you want to replace iconv and related with stubs.])
    ICONV=no
  else
  LIBS="$LIBS $LIBICONV"
  AC_CHECK_FUNCS([locale_charset],,
  AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <langinfo.h>]], [[char* cs = nl_langinfo(CODESET);]])],[AC_MSG_NOTICE(found nl_langinfo(CODESET))],[echo "Your iconv implementation is incomplete"; exit 1]))
  AC_CHECK_LIB(charset,locale_charset)
  AC_CHECK_HEADERS([libcharset.h])
  AC_CHECK_HEADERS([langinfo.h])
  AC_CHECK_HEADERS([locale.h])
  fi
else
  AC_DEFINE(DISABLE_ICONV, 1, [Define to 1 if you want to replace iconv and related with stubs.])
  ICONV=no
fi

echo "----- checking pthread support"
AX_PTHREAD

# On linux plaforms, we will have to check that includes from kernel are
# available. glibc version test was shamelessly taken from
# http://public.activestate.com/gsar/APC/perl-5.8.x/Configure
GLIBC_VERSION=""
case $host in
        *linux*)
           echo "----- GNU C Library version"
           AC_CHECK_HEADERS(linux/limits.h,, [
             OLD_CPPFLAGS=$CPPFLAGS
             CPPFLAGS="-I /usr/src/linux/include"
             AC_CHECK_HEADER(linux/types.h,[CONFIG_INCLUDES="-I /usr/src/linux/include"])
             CPPFLAGS=$OLD_CPPFLAGS]
           )
           AC_CHECK_HEADERS(gnu/libc-version.h,[AC_MSG_CHECKING(for GNU C Library version)

cat >try.c <<'EOCP'
/* Find out version of GNU C library.  __GLIBC__ and __GLIBC_MINOR__
   alone are insufficient to distinguish different versions, such as
   2.0.6 and 2.0.7.  The function gnu_get_libc_version() appeared in
   libc version 2.1.0.      A. Dougherty,  June 3, 2002.
*/
#include <stdio.h>
int main(void)
{
#ifdef __GLIBC__
#   ifdef __GLIBC_MINOR__
#       if __GLIBC__ >= 2 && __GLIBC_MINOR__ >= 1
#           include <gnu/libc-version.h>
    printf("%s\n",  gnu_get_libc_version());
#       else
    printf("%d.%d\n",  __GLIBC__, __GLIBC_MINOR__);
#       endif
#   else
printf("%d\n",  __GLIBC__);
#   endif
    return 0;
#else
    return 1;
#endif
}
EOCP

           $CC -o try ./try.c
           GLIBC_VERSION="`./try`"
           AC_MSG_RESULT($GLIBC_VERSION)
           rm -f try try.*],)
        ;;
        *)         ;;
esac

echo "---------------------------------------------"
echo "     Checking system libraries finished."
echo "---------------------------------------------"
echo ""

CXX_VERSION=
echo "--------------------------------------"
echo "     Checking activated networks."
echo "--------------------------------------"

  if test "$DONKEY" = "yes"; then
    AC_MSG_CHECKING(eDonkey)
    AC_MSG_RESULT(yes)
  else
    DONKEY_SUI=no
  fi

  if test "$DONKEY_SUI" = "yes"; then
    AC_PROG_CXX
    AC_CHECK_TOOL(NEWCXX, [$CXX], [no])
    if test x"$NEWCXX" = x"no"
    then
      CXX=
      DONKEY_SUI=no
      AC_MSG_CHECKING(eDonkey SUI)
      AC_MSG_RESULT(no - C++ compiler missing)
    else
      CXX=$NEWCXX
      CXX_VERSION=`$CXX -dumpversion`
      AC_LANG_PUSH([C++])
      AC_CHECK_HEADERS([cryptopp/rsa.h],,[DONKEY_SUI=no])
      AC_LANG_POP([C++])
      AC_MSG_CHECKING(eDonkey SUI)
      if test "$DONKEY_SUI" = "yes"; then
        AC_MSG_RESULT(yes)
        DONKEY_SUI_FILE=DonkeySui1
        AC_DEFINE(HAVE_CRYPTOPP, 1, cryptopp)
      else
        AC_MSG_RESULT(no - CryptoPP library missing)
      fi
    fi
  fi

  if test "$BITTORRENT" = "yes"; then
    AC_MSG_CHECKING(BitTorrent)
    if test "$NUMS" != "no"; then
      AC_MSG_RESULT(yes)
    else
      BITTORRENT=no
      AC_MSG_RESULT([no - ocaml num library missing])
    fi
  fi

  if test "$FILETP" = "yes"; then
    AC_MSG_CHECKING(FileTP)
    AC_MSG_RESULT(yes)
  fi

  if test "$GNUTELLA" = "yes"; then
    AC_MSG_CHECKING(Gnutella)
    AC_MSG_RESULT(yes)
  fi

  if test "$GNUTELLA2" = "yes"; then
    AC_MSG_CHECKING(G2)
    AC_MSG_RESULT(yes)
  fi

  if test "$FASTTRACK" = "yes"; then
    AC_MSG_CHECKING(Fasttrack)
    AC_MSG_RESULT(yes)
  fi

  if test "$DIRECT_CONNECT" = "yes"; then
    AC_MSG_CHECKING(DirectConnect)
    if test "$BZIP2" = "yes"; then
      AC_MSG_RESULT(yes)
    else
      DIRECT_CONNECT=no
      AC_MSG_RESULT([no - bzip2 library missing])
    fi
  fi

  if test "$SOULSEEK" = "yes"; then
    AC_MSG_CHECKING(Soulseek)
    AC_MSG_RESULT(yes)
  fi

  if test "$OPEN_NAPSTER" = "yes"; then
    AC_MSG_CHECKING(OpenNapster)
    AC_MSG_RESULT(yes)
  fi

  if test "$OPENFT" = "yes"; then
    AC_MSG_CHECKING(OpenFT)
    AC_MSG_RESULT(yes)
  fi
echo "-----------------------------------------------"
echo "     Checking activated networks finished."
echo "-----------------------------------------------"

if test -f $OCAMLLIB/lablgl.cma; then
  LABLGL_CMA=lablgl.cma
fi

if test -f $OCAMLLIB/lablgl.$OCAMLLIB_EXT; then
  LABLGL_CMXA=lablgl.$OCAMLLIB_EXT
fi

# Check for GTK only if we want to build the GUI
if test ! "$GUI" = "no"; then
  echo "---------------------------------------------------------"
  echo "Checking the libraries required to build the GTK GUI."
  echo "---------------------------------------------------------"
  if test "$GUI" = "newgui2"; then
      REQUIRED_GTK=2.4.0
      PKG_GTK=gtk+-2.0
      AC_MSG_CHECKING(for GTK+ - version >= $REQUIRED_GTK)
      if pkg-config --atleast-version $REQUIRED_GTK $PKG_GTK; then
        AC_MSG_RESULT(yes)
        REQUIRED_RSVG=2.4.0
        PKG_RSVG=librsvg-2.0
        AC_MSG_CHECKING(for librsvg - version >= $REQUIRED_RSVG)
        if pkg-config --atleast-version $REQUIRED_RSVG $PKG_RSVG; then
          GTK_CONFIG="pkg-config $PKG_GTK $PKG_RSVG"
          REQUIRED_LABLGTK=2.14.2
          LABLGTK_NAME=lablgtk2
          AC_MSG_RESULT(yes)
        else
          GTK_CONFIG=no
          AC_MSG_RESULT(no)
        fi
      else
        GTK_CONFIG=no
        AC_MSG_RESULT(no)
      fi
  else
    if test "$OS_FILES2" = "mingw"; then
      REQUIRED_GTK=1.3.0
      PKG_GTK=gtk+-1.3-win32-production
      AC_MSG_CHECKING(for GTK+ - version >= $REQUIRED_GTK)
      if pkg-config --atleast-version $REQUIRED_GTK $PKG_GTK; then
        GTK_CONFIG="pkg-config $PKG_GTK"
        AC_MSG_RESULT(yes)
      else
        GTK_CONFIG=no
        AC_MSG_RESULT(no)
      fi
    else
      AC_CHECK_PROG(GTK_CONFIG, gtk-config, gtk-config, no)
      if test "$GTK_CONFIG" = "no"; then
        AC_MSG_RESULT(no)
      else
        AC_MSG_RESULT(yes)
      fi
    fi
  fi
else
  GTK_CONFIG=no
fi
if test "$GTK_CONFIG" = "no"; then
     LABLGTK_CONFIG=no
else
  AC_MSG_CHECKING(for native code $LABLGTK_NAME)
  if test -f $OCAMLLIB/$LABLGTK_NAME/lablgtk.$OCAMLLIB_EXT; then
     if test "$GUI" = "newgui2"; then
       if test -f $OCAMLLIB/$LABLGTK_NAME/lablrsvg.$OCAMLLIB_EXT; then
         AC_MSG_RESULT(yes)
         LABLGTK_CONFIG=yes
       else
         AC_MSG_RESULT(no)
         LABLGTK_CONFIG=no
         if test -f $OCAMLLIB/$LABLGTK_NAME/lablrsvg.cma; then
           echo "---------------------------------------------------------"
           echo "lablrsvg is not installed properly. See the INSTALL.txt"
           echo "file of mldonkey to see how to compile $LABLGTK_NAME. You"
           echo "probably forgot to call 'make opt' before 'make install'."
           echo "---------------------------------------------------------"
         else
           echo "---------------------------------------------------------"
           echo "lablrsvg is not installed. See the INSTALL.txt file of"
           echo "mldonkey to see how to compile $LABLGTK_NAME. Librsvg"
           echo "may not be installed when you compiled $LABLGTK_NAME."
           echo "---------------------------------------------------------"
         fi
       fi
     else
       AC_MSG_RESULT(yes)
       LABLGTK_CONFIG=yes
     fi
  else
     AC_MSG_RESULT(no)
     LABLGTK_CONFIG=no
     if test -f $OCAMLLIB/$LABLGTK_NAME/lablgtk.cma; then
       echo "-------------------------------------------------------------"
       echo "$LABLGTK_NAME is not installed properly. See the INSTALL.txt"
       echo "file of mldonkey to see how to compile $LABLGTK_NAME. You"
       echo "probably forgot to call 'make opt' before 'make install'."
       echo "-------------------------------------------------------------"
     else
       echo "Do you want this script to try to download and install $LABLGTK_NAME"
       echo "LOCALLY in mldonkey directory ?"
       if test "$BATCH" = "no"; then read i <&1; else i=yes; fi
       case "$i" in
        y* | Y*)

         cd $PATCH_DIR
         LABLGTK_DIST=lablgtk-"$REQUIRED_LABLGTK".tar.gz
         rm -rf lablgtk-"$REQUIRED_LABLGTK"
         if test ! -f "$LABLGTK_DIST"; then
           echo Downloading ...
           $WGET -O "$LABLGTK_DIST".tmp http://www.math.nagoya-u.ac.jp/~garrigue/soft/olabl/dist/"$LABLGTK_DIST" && mv "$LABLGTK_DIST".tmp "$LABLGTK_DIST"
           rm -f "$LABLGTK_DIST".tmp
         fi
         if test ! -f "$LABLGTK_DIST"; then exit 1; fi

         mkdir -p $BUILD_DIR
         cd $BUILD_DIR
         echo Uncompressing ...
         gzip -cd $PATCH_DIR/lablgtk-"$REQUIRED_LABLGTK".tar.gz | tar xf -
         (cd lablgtk-"$REQUIRED_LABLGTK"
          if test -f $PATCH_DIR/lablgtk-"$REQUIRED_LABLGTK".patch; then
            echo Patching ...
            patch -p0 < $PATCH_DIR/lablgtk-"$REQUIRED_LABLGTK".patch
          fi
          PATH=$OCAML_PATH:$PATH
          export PATH
          echo $PATH

          if test "$GUI" = "newgui2"; then
            ./configure --prefix=$LOCAL_DIR
            $GNU_MAKE world
            $GNU_MAKE install
          else
            $GNU_MAKE configure
            $GNU_MAKE
            $GNU_MAKE opt
            $GNU_MAKE install
          fi

          cd ..
          rm -rf lablgtk-"$REQUIRED_LABLGTK"
         )
         cd $CONFIG_DIR
         if test -f $OCAMLLIB/$LABLGTK_NAME/lablgtk.$OCAMLLIB_EXT; then
            LABLGTK_CONFIG=yes
         else
            echo "Installation of $LABLGTK_NAME failed"
            LABLGTK_CONFIG=no
         fi
         ;;
        *);;
      esac
     fi
  fi
fi

if test "$GUI" = "newgui2" ; then
  GUIS="mldonkey_gui\$(EXE)"
  GTKCFLAGS="`pkg-config --cflags-only-I gtk+-2.0`"
  GTKLLIBS="`pkg-config --libs-only-L gtk+-2.0`"
  GTKLFLAGS="`pkg-config --libs-only-l gtk+-2.0` -lX11"
else
  GUIS="mldonkey_gui\$(EXE) mldonkey_gui2\$(EXE)"
fi

if test "$LABLGTK_CONFIG" = "no"; then
  GUI="no"
else
  MORE_TARGETS="$MORE_TARGETS $GUIS"
  AC_MSG_CHECKING(GToolbox.popup_menu args)
  GTOOLBOX="$OCAMLLIB/$LABLGTK_NAME/gToolbox.mli"
  grep popup $GTOOLBOX | grep -i button 2> /dev/null && GTOOLBOX_ARGS=new
  if test "$GTOOLBOX_ARGS" = "new"; then
    GTOOLBOX_POPUPMENU=' ~button: button ~time: time '
    AC_MSG_RESULT(new)
  else
    GTOOLBOX_POPUPMENU=' ~x: button ~y: time '
    AC_MSG_RESULT(old)
  fi
  echo "---------------------------------------------------------"
  echo "End of GTK GUI configuration."
  echo "---------------------------------------------------------"
fi

if test "$OS_FILES" = "mingw"; then
   OCAMLDEP_OPTIONS="-slash"
fi

AC_SUBST(LIBS)
AC_SUBST(CFLAGS)
AC_SUBST(CPPFLAGS)
AC_SUBST(CXXFLAGS)
AC_SUBST(LDFLAGS)
AC_SUBST(CC)
AC_SUBST(CPP)
AC_SUBST(CXX)
AC_SUBST(FIX_BROKEN_CPP)
AC_SUBST(CONFIG_INCLUDES)
AC_SUBST(OCAMLC)
AC_SUBST(OCAMLLIB)
AC_SUBST(OCAMLOPT)
AC_SUBST(OCAMLLEX)
AC_SUBST(OCAMLYACC)
AC_SUBST(OCAMLDEP)
AC_SUBST(OCAMLDEP_OPTIONS)
AC_SUBST(CAMLP4)
AC_SUBST(CAMLP4OF)
AC_SUBST(CAMLP4LIB_OPT)
AC_SUBST(CAMLP4LIB_BYTE)
AC_SUBST(PERL)
AC_SUBST(OCAMLDOC)
AC_SUBST(OCAMLMKTOP)
AC_SUBST(SYSTEM)
AC_SUBST(MORE_TARGETS)
AC_SUBST(MORE_SUBDIRS)
AC_SUBST(LABLGL_CMA)
AC_SUBST(LABLGL_CMXA)
AC_SUBST(ICONV)
AC_SUBST(OPEN_NAPSTER)
AC_SUBST(DIRECT_CONNECT)
AC_SUBST(GNUTELLA)
AC_SUBST(GNUTELLA2)
AC_SUBST(BITTORRENT)
AC_SUBST(FILETP)
AC_SUBST(SOULSEEK)
AC_SUBST(OPENFT)
AC_SUBST(FASTTRACK)
AC_SUBST(DONKEY)
AC_SUBST(DONKEY_SUI)
AC_SUBST(DONKEY_SUI_FILE)
AC_SUBST(DONKEY_SERVER)
AC_SUBST(GUI)
AC_SUBST(REQUIRED_LABLGTK)
AC_SUBST(COMPRESS)
AC_SUBST(COMPRESS_EXT)
AC_SUBST(CHECKBOUNDS)
AC_SUBST(MLDONKEY_VERSION)
AC_SUBST(SCM_VERSION)
AC_SUBST(MAJOR_VERSION)
AC_SUBST(MINOR_VERSION)
AC_SUBST(SUB_VERSION)
AC_SUBST(GTOOLBOX_POPUPMENU)
AC_SUBST(OS_FILES)
AC_SUBST(OS_FILES2)
AC_SUBST(TARGET_TYPE)
AC_SUBST(RPMBUILD)
AC_SUBST(GTKCFLAGS)
AC_SUBST(GTKLLIBS)
AC_SUBST(GTKLFLAGS)
AC_SUBST(GD)
AC_SUBST(GD_JPG)
AC_SUBST(GD_PNG)
AC_SUBST(GDGRAPHICS)
AC_SUBST(GD_LIBS)
AC_SUBST(GD_STATIC_LIBS)
AC_SUBST(GD_CFLAGS)
AC_SUBST(GD_LDFLAGS)
AC_SUBST(BZIP2)
AC_SUBST(MAGIC)
AC_SUBST(MAGICLIB)
AC_SUBST(UPNP_NATPMP)
AC_SUBST(UPNP_NATPMP_LIBS)
AC_SUBST(UPNP_NATPMP_STATIC_LIBS)
BUILD_SYSTEM="`uname -s` `uname -m` `uname -r`"
AC_SUBST(BUILD_SYSTEM)
AC_SUBST(GLIBC_VERSION)
AC_SUBST(CC_VERSION)
AC_SUBST(CXX_VERSION)
AC_SUBST(CONFIGURE_ARGUMENTS)
AC_SUBST(CONFIGURE_RUN)
AC_SUBST(DEVFLAGS)
AC_SUBST(OCAMLVERSION_MAJOR)
AC_SUBST(NUMS_INCLUDE)

AUTOCONF=../src/utils/lib/autoconf.ml
GTK_AUTOCONF=../src/utils/lib/gAutoconf.ml
AC_CONFIG_FILES([\
  Makefile.config \
  mldonkey.rc \
  $AUTOCONF.new $GTK_AUTOCONF.new \
   ../src/utils/bitstring/bitstring.ml \
   ../src/utils/lib/magic.ml \
   ../src/networks/donkey/donkeySui.ml \
   ../src/daemon/driver/driverGraphics.ml \
   ../packages/rpm/mldonkey.spec \
   ../packages/rpm/Makefile \
   ../packages/slackware/mldonkey.options])
AC_OUTPUT
diff $AUTOCONF.new $AUTOCONF 2> /dev/null > /dev/null || cp -f $AUTOCONF.new $AUTOCONF
diff $GTK_AUTOCONF.new $GTK_AUTOCONF 2> /dev/null > /dev/null || cp -f $GTK_AUTOCONF.new $GTK_AUTOCONF

cd ..

echo ""
echo "Building dependencies (if it blocks, try '$GNU_MAKE depend' to see the problem)"
$GNU_MAKE depend 2> /dev/null > /dev/null || echo "Building dependencies fails: try: '$GNU_MAKE depend'"

echo ""
printf "Configuring MLDonkey %s completed.\n" "$MLDONKEY_VERSION"
if test ! -z "$SCM_VERSION"; then
  echo " - SCM     $SCM_VERSION"
fi
echo " - host    $host"
echo " - system  $SYSTEM"

echo ""
echo "Network modules:"
printf " - eDonkey           "
if test "$DONKEY" = "yes"; then
  if test "$DONKEY_SUI" = "yes"; then
    echo "enabled (eMule SUI enabled)"
  else
    echo "enabled (eMule SUI disabled)"
  fi
else
  echo "        disabled"
fi

printf " - BitTorrent        "
if test "$BITTORRENT" = "yes"; then
  echo "enabled"
else
  if test "$NUMS" != "no"; then
    echo "        disabled"
  else
    echo "        disabled - ocaml num library missing (must be installed manually when building with OCaml >= 4.06)"
  fi
fi

printf " - FileTP (aka wget) "
if test "$FILETP" = "yes"; then
  echo "enabled"
else
  echo "        disabled"
fi

printf " - Fasttrack         "
if test "$FASTTRACK" = "yes"; then
  echo "enabled"
else
  echo "        disabled"
fi

printf " - Gnutella          "
if test "$GNUTELLA" = "yes"; then
  echo "enabled (warning: this network module is unmaintained)"
else
  echo "        disabled - unmaintained"
fi

printf " - Gnutella2         "
if test "$GNUTELLA2" = "yes"; then
  echo "enabled (warning: this network module is unmaintained)"
else
  echo "        disabled - unmaintained"
fi

printf " - Direct Connect    "
if test "$DIRECT_CONNECT" = "yes"; then
  echo "enabled"
else
  echo "        disabled"
fi

printf " - Open Napster      "
if test "$OPEN_NAPSTER" = "yes"; then
  echo "enabled          - currently not usable"
else
  echo "        disabled - currently not usable"
fi

printf " - Soulseek          "
if test "$SOULSEEK" = "yes"; then
  echo "enabled          - currently not usable"
else
  echo "        disabled - currently not usable"
fi

printf " - OpenFT            "
if test "$OPENFT" = "yes"; then
  echo "enabled          - currently not usable"
else
  echo "        disabled - currently not usable"
fi

echo ""
echo "Core features:"

echo " - zlib (required)   enabled"

printf " - bzip2             "
if test "$BZIP2" = "yes"; then
  echo "enabled"
else
  echo "        disabled"
fi

printf " - iconv             "
if test "$ICONV" = "yes"; then
  echo "enabled"
else
  echo "        disabled"
fi

printf " - libmagic          "
if test "$MAGIC" = "yes"; then
  echo "enabled"
else
  echo "        disabled"
fi

printf " - upnp & natpmp     "
if test "$UPNP_NATPMP" = "yes"; then
  echo "enabled"
else
  echo "        disabled"
fi

printf " - graphical stats   "
if test "$GD" = "yes"; then
  echo "enabled"
  printf "   - png support     "
  if test "$GD_PNG" = "yes"; then
    echo "enabled"
  else
    echo "        disabled"
  fi

  printf "   - jpg support     "
  if test "$GD_JPG" = "yes"; then
    echo "enabled"
  else
    echo "        disabled"
  fi
else
  echo "        disabled"
fi

if test "$LABLGTK_CONFIG" = "yes"; then
  echo ""
  printf "\n - GUI support       "
  if test "$GUI" = "newgui1"; then
    echo "GTK1 newgui"
  else
    if test "$GUI" = "newgui2"; then
      echo "GTK2 GUI"
    else
      echo "GTK1 oldgui"
    fi
  fi
fi

if test "$OLDGUI_NO_31" = "yes"; then
  echo " - GUI support       GTK1 oldgui does not work with Ocaml 3.1*, disabled"
fi

if test "$TARGET_TYPE" = "byte"; then
  OCAML_TYPE="- byte code"
  COMPILE_TARGET=".byte"
fi
echo ""
echo "Compilers:"
echo " - OCaml version     $OCAMLVERSION $OCAML_TYPE"
echo " - $CC version       $CC_VERSION"
if test "x$CXX" != "x"; then
  echo " - $CXX version       $CXX_VERSION"
fi

echo ""
echo "Now execute '$GNU_MAKE' to start compiling. Good luck!"

echo ""
echo "To compile a static code execute:     $GNU_MAKE mlnet$COMPILE_TARGET.static"
echo "To clean the build directory execute: $GNU_MAKE maintainerclean"
