AC_REVISION($Revision$)dnl revision of this configure.in script

AC_CONFIG_AUX_DIR(conf)
AC_INIT(Makefile.am)
AC_CANONICAL_SYSTEM
AM_CONFIG_HEADER(include/config.h)
AM_INIT_AUTOMAKE(plptools, 0.8)
AM_PROG_LIBTOOL
PLP_SET_LIBVERSION

dnl Enable Maintainer stuff
AM_MAINTAINER_MODE

dnl checks for programs
AC_AIX
AC_PROG_MAKE_SET
AC_PROG_CXX
PLP_CHECK_COMPILERS
AC_PROG_AWK
AC_PATH_PROG(SED,sed)

dnl NLS support
ALL_LINGUAS="de"
AM_GNU_GETTEXT
dnl Additional glibc-intl checks
PLP_CHECK_INTL

dnl This is stupid for two resaons:
dnl
dnl 1. It doesn't save and restore CFLAGS if it's _not_ Sun's cc
dnl    (these have been set already in AC_CHECK_COMPILERS
dnl 2. It assumes cc installed at a fixed path which may not be true
dnl    pkgadd -r can install anywhere.
dnl
dnl A correct version should check by using cc's _behavior_, not path
dnl and save and restore CFLAGS, if it's not Sun's cc.
dnl
dnl -> Commented out for now because i have gcc on Solaris, no Sun cc.
dnl If somebody complains, (s)he should send me some cc output and i
dnl can add a correct check to AC_CHECK_COMPILERS (where it belongs).
dnl Apart from that, Sun's compiler is crap anyway: It doesn't compile
dnl valid c++ code correctly.
dnl
dnl   -Fritz
dnl
dnl test "$GCC" = yes && CFLAGS="-O2 -Wall"
dnl AC_PATH_PROG(CC_PATH, $CC)
dnl test "$CC_PATH" = /opt/SUNWspro/bin/cc && CFLAGS="-xO2 -v"

dnl checking for aix
AC_MSG_CHECKING(for AIX)
if test "`uname -s 2>/dev/null`" = AIX ; then
  AC_MSG_RESULT(yes)
  AC_CHECK_LIB(bsd, hostname)
  EXTRA_OBJS=mount_aix.o
else
  AC_MSG_RESULT(no)
fi
AC_SUBST(EXTRA_OBJS)

dnl checks for libraries

dnl readline and history for plpftp
ac_enable_readline=yes
AM_CONDITIONAL(HAVE_LIBREADLINE, false)
AM_CONDITIONAL(ADD_LIBCURSES, false)
AC_ARG_ENABLE(readline,
	[  --disable-readline      disable libreadline support [no]],
	if test "$enableval" = "no" ; then
		AC_MSG_RESULT([support for libreadline disabled])
		ac_enable_readline=no
	fi
)
if test "x$ac_enable_readline" = "xyes" ; then
	PLP_CHECK_READLINE
fi

ac_enable_history=yes
AM_CONDITIONAL(HAVE_LIBHISTORY, false)
AC_ARG_ENABLE(history,
	[  --disable-history       disable libhistory support [no]],
	if test "$enableval" = "no" ; then
		AC_MSG_RESULT([support for libhistory disabled])
		ac_enable_history=no
	fi
)
if test "x$ac_enable_history" = "xyes" ; then
	AC_CHECK_LIB(history, add_history,
	[
		AC_DEFINE_UNQUOTED(HAVE_LIBHISTORY)
		have_libhistory=true
	])
	AM_CONDITIONAL(HAVE_LIBHISTORY, test x$have_libhistory = xtrue)
fi

dnl these three are for solaris
AC_CHECK_LIB(socket, socket)
AC_CHECK_LIB(nsl, gethostbyname)
ac_save_LDFLAGS=$LDFLAGS; LDFLAGS="-L/usr/ucblib -R/usr/ucblib $LDFLAGS"
AC_CHECK_LIB(rpcsoc, svcudp_create,,LDFLAGS=$ac_save_LDFLAGS)

dnl checks for mount table - if desired
ac_enable_mnttab=yes
AC_ARG_ENABLE(mnttab,
       [  --disable-mnttab        disable mnttab writing [no]],
       if test "$enableval" = "no" ; then
               AC_MSG_RESULT([support for mnttab disabled])
               ac_enable_mnttab=no
       fi
)
if test "x$ac_enable_mnttab" = "xyes" ; then
       AC_MSG_CHECKING(for mount table)
       PLP_FIND_FILE(/etc/mnttab /etc/mtab, MTAB)
       AC_MSG_RESULT($MTAB)
       test "$MTAB" = "NO" && AC_DEFINE_UNQUOTED(DONT_UPDATE_MTAB)
       AC_DEFINE_UNQUOTED(MTAB_PATH,"$MTAB")
       case "$target_alias" in
               *linux*)
                       AC_DEFINE_UNQUOTED(MTAB_TMP,"${MTAB}~")
                       ;;
               *)
                       AC_DEFINE_UNQUOTED(MTAB_TMP,"${MTAB}.plpnfsd")
                       ;;
       esac
else
       AC_DEFINE_UNQUOTED(DONT_UPDATE_MTAB)
fi

dnl Check, if bot time.h and sys/time.h may be included
AC_HEADER_TIME

dnl Check, if compiler knows about bool
AC_CHECK_BOOL

dnl Type of sighandlers
AC_TYPE_SIGNAL

dnl checks for header files
AC_CHECK_HEADERS(sys/time.h sys/ioctl.h sys/errno.h sys/ttold.h stdlib.h)

PLP_HELP_MSG([Debugging (developer only!):])
LIBCCMALLOC=
AC_ARG_WITH(ccmalloc,
    [  --with-ccmalloc=DIR     link against ccmalloc leak-checking lib],
    [
      search_dirs="/usr/lib /lib /usr/local/lib"
      case "${withval}" in
      	yes)
		ccmalloc_dirs=${search_dirs}
		;;
	no)
		ccmalloc_dirs=
		;;
	*)
		ccmalloc_dirs="${withval} ${search_dirs}"
		;;
      esac
      AC_MSG_CHECKING(for libccmalloc)
      save_LIBS="$LIBS"
      ccmalloc_found=NO
      for d in ${ccmalloc_dirs} ; do
      	LIBS="-L$d -lccmalloc -ldl"
      	AC_TRY_LINK_FUNC(ccmalloc_report,ccmalloc_found=$d ; break)
      done
      LIBS="$save_LIBS"
      if test "${ccmalloc_found}" = "NO" ; then
      	AC_MSG_RESULT(not found)
      else
      	AC_MSG_RESULT(found)
	LIBCCMALLOC="-L$ccmalloc_found -lccmalloc -ldl"
      fi
    ]
)
AC_SUBST(LIBCCMALLOC)


dnl special options for customization

PLP_HELP_MSG([Options for overriding builtin defaults:])

AC_ARG_WITH(serial,
    [  --with-serial=DEV       override default serial line],
    [  DDEV="$withval"
      AC_MSG_RESULT(Overriding serial line: $DDEV)
    ],
    [ AC_MSG_CHECKING(for default serial line)
      PLP_FIND_CDEV(/dev/psion /dev/tty0p0 /dev/tty00 /dev/ttyS0 /dev/term/a /dev/ttyfa /dev/ttya /dev/tty0 /dev/ttyf1 /dev/cuaa1, DDEV)
      AC_MSG_RESULT($DDEV)
      test "$DDEV" = "NO" && AC_MSG_ERROR(NO serial lines. Use --with-serial.)
    ]
)
AC_DEFINE_UNQUOTED(DDEV,"$DDEV")
AC_SUBST(DDEV)

AC_ARG_WITH(speed,
    [  --with-speed=SPEED      override default serial speed [115200]],
    [ DSPEED="$withval"
      AC_MSG_RESULT(Overriding serial speed: $DSPEED) ],
    [ DSPEED=115200
      AC_MSG_RESULT(Using default serial speed: $DSPEED)
    ]
)
AC_DEFINE_UNQUOTED(DSPEED,$DSPEED)
AC_SUBST(DSPEED)

AC_ARG_WITH(port,
    [  --with-port=PORT        override default port [7501]],
    [ DPORT="$withval"
      AC_MSG_RESULT(Overriding port: $DPORT) ],
    [ DPORT=7501
      AC_MSG_RESULT(Using default port: $DPORT)
    ]
)
AC_DEFINE_UNQUOTED(DPORT,$DPORT)
AC_SUBST(DPORT)

AC_ARG_WITH(drive,
    [  --with-drive=DRIVE      override default Psion drive [AUTO]],
    [ DDRIVE="$withval"
      AC_MSG_RESULT(Overriding drive: $DDRIVE) ],
    [ DDRIVE='AUTO'
      AC_MSG_RESULT(Using default Psion drive: $DDRIVE)
    ]
)
AC_DEFINE_UNQUOTED(DDRIVE,"$DDRIVE")

AC_ARG_WITH(basedir,
    [  --with-basedir=DIR      override default Psion directory [\\\\]],
    [ DBASEDIR="$withval"
      AC_MSG_RESULT(Overriding directory: $DBASEDIR) ],
    [ DBASEDIR='\\'
      AC_MSG_RESULT(Using default Psion directory: $DBASEDIR)
    ]
)
AC_DEFINE_UNQUOTED(DBASEDIR,"$DBASEDIR")

AC_ARG_WITH(mountdir,
    [  --with-mountdir=DIR     override default mount point [/mnt/psion]],
    [ DMOUNTPOINT="$withval"
      AC_MSG_RESULT(Overriding mount point: $DMOUNTPOINT) ],
    [ DMOUNTPOINT="/mnt/psion"
      AC_MSG_RESULT(Using default mount point: $DMOUNTPOINT)
    ]
)
AC_DEFINE_UNQUOTED(DMOUNTPOINT,"$DMOUNTPOINT")
AC_SUBST(DMOUNTPOINT)

dnl KDE stuff
PLP_HELP_MSG([Options for activating sub packages:])
ac_enable_kde=no
AM_CONDITIONAL(BUILD_KDE, false)
AC_ARG_ENABLE(kde,
	[  --enable-kde            build KDE2 stuff [no]],
	if test "$enableval" = "yes" ; then
		AC_MSG_RESULT([Will build KDE2 stuff])
		ac_enable_kde=yes
	fi
)
PLP_HELP_MSG([Options, only needed when building KDE2 stuff:])
if test "x$ac_enable_kde" = "xyes" ; then
	AC_PATH_KDE
	AC_CHECK_KDEMAXPATHLEN
	KDE_CHECK_FINAL
	AM_KDE_WITH_NLS
	AM_CONDITIONAL(BUILD_KDE, true)
fi

AC_OUTPUT(
	Makefile
	intl/Makefile
	po/Makefile.in
	lib/Makefile
	ncpd/Makefile
	plpftp/Makefile
	plpnfsd/Makefile
	kde2/Makefile
	kde2/kioslave/Makefile
	kde2/plugins/Makefile
	kde2/kpsion/Makefile
	kde2/po/Makefile
	kde2/po/de/Makefile
	kde2/mime/Makefile
	kde2/mime/icons/Makefile
	kde2/doc/Makefile
	kde2/doc/en/Makefile
	plpbackup/Makefile
	doc/Makefile
	doc/api/Makefile
	include/config.h
	etc/psion
	doc/ncpd.man
	doc/plpnfsd.man
	doc/plpftp.man
)