dnl Process this file with autoconf to produce a configure script.

AC_INIT(jpilot.c)

AC_CONFIG_HEADER(config.h)

AM_PROG_LIBTOOL
AC_PROG_INSTALL
AC_ISC_POSIX

dnl Checks for programs.
AC_PROG_CC

PACKAGE=jpilot
VERSION=0.98
#PACKAGE=$package
#VERSION=$version

# Compile options
ccoptions=""
AC_ARG_WITH(ccoptions,
[  --with-ccoptions=       Options to pass to your C compiler])

if test "x$with_ccoptions" != "x"; then
   ccoptions=$with_ccoptions
   CFLAGS=""
   AC_MSG_CHECKING(for supplied cc options)
   AC_MSG_RESULT(Using supplied cc options $ccoptions)
fi
AC_SUBST(ccoptions)
cflags=$CFLAGS
AC_SUBST(cflags)

dnl start gettext

AC_DEFINE_UNQUOTED(PACKAGE, "$PACKAGE")
AC_DEFINE_UNQUOTED(VERSION, "$VERSION")
AC_SUBST(PACKAGE)
AC_SUBST(VERSION)

ALL_LINGUAS="ja de fr da sv"

dnl ud_GNU_GETTEXT
dnl AM_WITH_NLS()
AM_GNU_GETTEXT

dnl AC_LINK_FILES($nls_cv_header_libgt, $nls_cv_header_intl)

dnl end gettext

dnl Check for pilot-link libs
pilot_prefix=""
AC_ARG_WITH(pilot_prefix,
 [  --with-pilot-prefix=    Prefix to top level of pilot-link files
                            (e.g., = /usr/local if the pilot-link includes
                             are in /usr/local/include
                             and libs are in /usr/local/lib)])

if test "x$with_pilot_prefix" != "x"; then
   pilot_prefix=$with_pilot_prefix
fi

dnl Make sure that the pilot-link stuff actually exists
AC_MSG_CHECKING(for pilot-link header files)
pilotinclude=no
for pilot_incl in $pilot_prefix/include /usr/include /usr/local/include \
    /usr/extra/pilot/include /usr/include/libpisock; do
   if test -r "$pilot_incl/pi-config.h" ; then
      pilotinclude=yes
      PILOT_FLAGS="$PILOT_FLAGS -I$pilot_incl"
      break
   fi
done

if test $pilotinclude = no ; then
   AC_MSG_RESULT(no)
   AC_MSG_ERROR(Could not find the pilot-link header files)
else
   AC_MSG_RESULT(found at $pilot_incl)
fi


dnl Maybe installed
AC_MSG_CHECKING(for pilot library files)
pilotlibs=no
PILOT_LIBS="-lpisock"

for pilot_libs in $pilot_prefix/lib /usr/lib /usr/local/lib/ \
  /usr/extra/pilot/lib ; do
   if test -r "$pilot_libs/libpisock.so" ; then
      pilotlibs=yes
      PILOT_LIBS="-L$pilot_libs $PILOT_LIBS"
      break
   fi
   if test -r "$pilot_libs/libpisock.a" ; then
      pilotlibs=yes
      PILOT_LIBS="-L$pilot_libs $PILOT_LIBS"
      break
   fi
   if test -r "$pilot_libs/libpisock.sl" ; then
      pilotlibs=yes
      PILOT_LIBS="-L$pilot_libs $PILOT_LIBS"
      break
   fi
done

if test $pilotlibs = no ; then
   AC_MSG_RESULT(no)
   AC_MSG_ERROR(Could not find the pilot-link libraries)
else
   AC_MSG_RESULT(found at $pilot_libs)
fi

dnl Solaris needs the socket library
AC_CHECK_LIB(socket, main, PILOT_LIBS=$PILOT_LIBS" -lsocket", , )

AC_ARG_ENABLE(pl-test, [  --disable-pl-test       Do not try to compile \
a test pilot-link program], enable_pl_test=no, enable_pl_test=yes)

if test "x$enable_pl_test" = "xyes"; then
   dnl Link a tiny program to make sure we have the environment right
   AC_MSG_CHECKING(to see if I can compile a pilot link program)
   ac_save_CFLAGS="$CFLAGS"
   CFLAGS="$CFLAGS $PILOT_FLAGS"
   ac_save_LIBS="$LIBS"
   LIBS="$LIBS $PILOT_LIBS"

   pilotcompile=no

   AC_TRY_LINK([#include "pi-config.h" 
#include "pi-socket.h"], [pi_close (0);] , pilotcompile=yes, , )


   if test $pilotcompile = no ; then
      AC_MSG_RESULT(no)
      AC_MSG_ERROR(Could not compile a test pilot-link program)
   else
      AC_MSG_RESULT(ok)
      AC_SUBST(PILOT_FLAGS)
      AC_SUBST(PILOT_LIBS)
   fi

CFLAGS="$save_CFLAGS"
LIBS="$save_LIBS"

fi


AC_ARG_ENABLE(plugins, [  --disable-plugins       Do not compile plugin support]\
, enable_plugins=no, enable_plugins=yes)

if test "x$enable_plugins" = "xyes"; then
   dnl Check for shared library calls
   AC_MSG_CHECKING(for dlopen)
   save_LIBS="$LIBS"
   LIBS="$LIBS -ldl"
   AC_TRY_LINK([#include <dlfcn.h>], [dlopen("huh",0);] , have_dlopen=yes, , )
   LIBS="$save_LIBS"

   if test "x$have_dlopen" = "xyes"; then
      AC_DEFINE(ENABLE_PLUGINS)
      AC_MSG_RESULT(ok, plugin support enabled)
   else
      AC_MSG_RESULT(Could not find dlopen - not using plugin support)
   fi
else
   AC_MSG_RESULT(Plugin support disabled by configure options)
fi



dnl Checking for GTK version
AM_PATH_GTK(1.2.0,,
  AC_MSG_ERROR([*** GTK >= 1.2.0 not installed - please install first ***]))

dnl Checks for header files.
AC_HEADER_STDC
AC_HEADER_SYS_WAIT
AC_CHECK_HEADERS(fcntl.h sys/file.h sys/time.h unistd.h string.h locale.h)

dnl Checks for typedefs, structures, and compiler characteristics.
AC_TYPE_PID_T
AC_HEADER_TIME
AC_STRUCT_TM

dnl Checks for library functions.
AC_TYPE_SIGNAL
AC_FUNC_STRFTIME
AC_FUNC_UTIME_NULL
#AC_CHECK_FUNCS(mkdir mktime select strdup strstr setenv)
AC_CHECK_FUNCS(memmove strchr memcpy strdup setenv \
	       getcwd strerror)
AC_CHECK_FUNCS(setenv)

AC_ARG_WITH(japanese,
[  --with-japanese         Use this for japanese support])
japanese=""
if test "x$with_japanese" != "x"; then
   AC_DEFINE(WITH_JAPANESE)
   AC_MSG_RESULT(Japanese support $japanese)
fi
AC_SUBST(japanese)

AC_ARG_WITH(with_flock,
[  --with-flock            Substitute flock instead of fnctl (for NFS)])
if test "x$with_flock" != "x"; then
   AC_DEFINE(USE_FLOCK)
   AC_MSG_RESULT(Using flock instead of fnctl)
fi

AC_OUTPUT([Makefile intl/Makefile po/Makefile.in],
[sed -e "/POTFILES =/r po/POTFILES" po/Makefile.in > po/Makefile])

dnl AC_OUTPUT(Makefile)
