AC_INIT(acinclude.m4) dnl a source file from your sub dir

AC_CONFIG_AUX_DIR(admin)
dnl AC_CANONICAL_SYSTEM 

VERSION="0.3.7"
RELEASE="1"
LARGEFILESUPPORT="-D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE"

if echo "$VERSION" | grep cvs >/dev/null 2>&1; then
 VERSION=$VERSION"`date +%Y%m%d`"
dnl RELEASE="`date +%Y%m%d`"
fi

AC_SUBST(VERSION)
AC_SUBST(RELEASE)

AM_INIT_AUTOMAKE([dclib],[$VERSION])

AC_PREFIX_DEFAULT(/usr/local)
dnl test prefix
if test "x$prefix" = "xNONE"; then
  prefix=$ac_default_prefix
  ac_configure_args="$ac_configure_args --prefix $prefix"
fi

# disable lfs
AC_ARG_ENABLE(lfs,
[  --disable-lfs           disable largefile support ],
[ LARGEFILESUPPORT="" ]
)

all_includes="$all_includes $LARGEFILESUPPORT"
AC_SUBST(all_includes)

AC_ARG_ENABLE(debug,
[  --enable-debug[=ARG]           enable debug support ],
[ 
case $enableval in
yes)
all_includes="-DDEBUG $all_includes"
;;
full)
all_includes="-DDEBUG $all_includes"
;;
esac
]
)

AC_SUBST(all_includes)

AC_CHECK_COMPILERS
dnl AC_ENABLE_SHARED(yes)
dnl AC_ENABLE_STATIC(yes)
AC_SUBST(all_includes)
AC_SUBST(all_libraries)
dnl AM_KDE_WITH_NLS
AM_CONFIG_HEADER(config.h)
AC_HEADER_STDC
AC_PROG_RANLIB
AC_PROG_LIBTOOL

AC_CHECK_HEADER(bzlib.h, , AC_MSG_ERROR([bzlib headers not found. install bzlib devel package]) )
AC_CHECK_LIB(bz2, BZ2_bzlibVersion, , AC_MSG_ERROR([bzlib not found. install bzlib package]) )
AC_FIND_BZIP2()

AC_CHECK_SOCKLEN_T

dnl XML
AM_PATH_XML2( 2.0.0, , AC_MSG_ERROR(libxml2 must be installed.) )

dnl check some includes
AC_CHECK_HEADER(inttypes.h,       [ AC_DEFINE(HAVE_INTTYPES_H,1,[Defines if your system have the inttypes.h header file])], )
AC_CHECK_HEADER(stdint.h,         [ AC_DEFINE(HAVE_STDINT_H,1,[Defines if your system have the stdint.h header file])], )
AC_CHECK_HEADER(unistd.h,         [ AC_DEFINE(HAVE_UNISTD_H,1,[Defines if your system have the unistd.h header file])], )
AC_CHECK_HEADER(fcntl.h,          [ AC_DEFINE(HAVE_FCNTL_H,1,[Defines if your system have the fcntl.h header file])], )
AC_CHECK_HEADER(limits.h,         [ AC_DEFINE(HAVE_LIMITS_H,1,[Defines if your system have the limits.h header file])], )
AC_CHECK_HEADER(sys/dustat.h,     [ AC_DEFINE(HAVE_SYS_DUSTAT_H,1,[Defines if your system have the sys/dustat.h header file])], )
AC_CHECK_HEADER(sys/filio.h,      [ AC_DEFINE(HAVE_SYS_FILIO_H,1,[Defines if your system have the sys/filio.h header file])], )
AC_CHECK_HEADER(sys/filsys.h,     [ AC_DEFINE(HAVE_SYS_FILSYS_H,1,[Defines if your system have the sys/filsys.h header file])], )
AC_CHECK_HEADER(sys/mount.h,      [ AC_DEFINE(HAVE_SYS_MOUNT_H,1,[Defines if your system have the sys/mount.h header file])], )
AC_CHECK_HEADER(sys/param.h,      [ AC_DEFINE(HAVE_SYS_PARAM_H,1,[Defines if your system have the sys/param.h header file])], )
AC_CHECK_HEADER(sys/sockio.h,     [ AC_DEFINE(HAVE_SYS_SOCKIO_H,1,[Defines if your system have the sys/sockio.h header file])] , )
AC_CHECK_HEADER(sys/statfs.h,     [ AC_DEFINE(HAVE_SYS_STATFS_H,1,[Defines if your system have the sys/statfs.h header file])] , )
AC_CHECK_HEADER(sys/statvfs.h,    [ AC_DEFINE(HAVE_SYS_STATVFS_H,1,[Defines if your system have the sys/statvfs.h header file])] , )
AC_CHECK_HEADER(sys/termios.h,    [ AC_DEFINE(HAVE_SYS_TERMIOS_H,1,[Defines if your system have the sys/termios.h header file])], )
AC_CHECK_HEADER(sys/vfs.h,        [ AC_DEFINE(HAVE_SYS_VFS_H,1,[Defines if your system have the sys/vfs.h header file])], )
AC_CHECK_HEADER(sys/fs/s5param.h, [ AC_DEFINE(HAVE_SYS_FS_S5PARAM_H,1,[Defines if your system have the sys/fs/s5param.h header file])], )

jm_FILE_SYSTEM_USAGE( [], )
jm_FSTYPENAME

# Check for SunOS statfs brokenness wrt partitions 2GB and larger.
# If <sys/vfs.h> exists and struct statfs has a member named f_spare,
# enable the work-around code in fsusage.c.
AC_MSG_CHECKING([for statfs that truncates block counts])
AC_CACHE_VAL(fu_cv_sys_truncating_statfs,
[AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
#if !defined(sun) && !defined(__sun)
choke -- this is a workaround for a Sun-specific problem
#endif
#include <sys/types.h>
#include <sys/vfs.h>]],
  [[struct statfs t; long c = *(t.f_spare);]])],
  [fu_cv_sys_truncating_statfs=yes],
  [fu_cv_sys_truncating_statfs=no])])
if test $fu_cv_sys_truncating_statfs = yes; then
  AC_DEFINE(STATFS_TRUNCATES_BLOCK_COUNTS, 1,
[  Define if the block counts reported by statfs may be truncated to 2GB
   and the correct values may be stored in the f_spare array.
   (SunOS 4.1.2, 4.1.3, and 4.1.3_U1 are reported to have this problem.
   SunOS 4.1.1 seems not to be affected.)])
fi
AC_MSG_RESULT($fu_cv_sys_truncating_statfs)

AC_DEFUN(AC_CHECK_STRUCT_STATVFS_T,
[
AC_MSG_CHECKING([for struct statvfs_t])
AC_CACHE_VAL(ac_cv_func_struct_statvfs_t,
[
AC_LANG_SAVE
AC_LANG_CPLUSPLUS
ac_libs_safe="$LIBS"
LIBS="$LIBS $LIBUCB"
AC_TRY_LINK([
# include <sys/statvfs.h>
int statvfs ();
],
[
struct statvfs_t fsd;
],
ac_cv_func_struct_statvfs_t=yes,
ac_cv_func_struct_statvfs_t=no)
LIBS="$ac_libs_safe"
AC_LANG_RESTORE
])
AC_MSG_RESULT($ac_cv_func_struct_statvfs_t)
if eval "test \"`echo $ac_cv_func_struct_statvfs_t`\" = yes"; then
  AC_DEFINE(HAVE_STRUCT_STATVFS_T, 1, [Define if you have the struct statvfs_t])
fi
])

AC_CHECK_STRUCT_STATVFS_T

AC_CHECK_FUNC(strtoull,  [ AC_DEFINE(HAVE_STRTOULL,1,[Defines if your system have the strtoull function])] )
AC_CHECK_FUNC(strtouq,   [ AC_DEFINE(HAVE_STRTOUQ,1,[Defines if your system have the strtouq function])] )
AC_CHECK_FUNC(usleep,    [ AC_DEFINE(HAVE_USLEEP,1,[Defines if your system have the usleep function])] )
AC_CHECK_FUNC(nanosleep, [ AC_DEFINE(HAVE_NANOSLEEP,1,[Defines if your system have the nanosleep function])] )

AC_ARG_WITH(socks,[  --with-socks            use the socks library], [AC_DEFINE(HAVE_SOCKS,1,[use the socks library])])

dnl #### This appears to be deficient with later versions of SOCKS.
if test "x${with_socks}" = xyes
then
  AC_CHECK_LIB(resolv, main)
  AC_CHECK_LIB(socks, Rconnect)
fi

AC_DEFUN(AC_STRUCT_SA_LEN, 
[dnl 
# 
# Test to see, if we have BSD4.4 sa_len -field in the "struct sockaddr*" 
# 
AC_CACHE_CHECK([for 'sa_len' in 'struct sockaddr'], ac_cv_struct_sa_len, 
[AC_TRY_COMPILE([#include <sys/types.h> 
#include <sys/socket.h>], [struct sockaddr sa; sa.sa_len = 0; ], 
ac_cv_struct_sa_len=yes, ac_cv_struct_sa_len=no)]) 
if test "$ac_cv_struct_sa_len" = yes; then 
AC_DEFINE(HAVE_SA_LEN, 1, [Define if you have sa_len -field in the "struct sockaddr*]) 
fi 
])

AC_STRUCT_SA_LEN

dnl define datapath
AC_MSG_CHECKING([for DCLib-datapath])
DCLIB_DATAPATH=`echo $prefix/share`
AC_DEFINE_UNQUOTED(DCLIB_DATAPATH, "$DCLIB_DATAPATH", [DCLib-Datapath])
AC_MSG_RESULT([$DCLIB_DATAPATH])

dnl Checks for libraries.
AC_CHECK_SIZEOF(unsigned long long int, 8)
AC_CHECK_SIZEOF(unsigned long int, 4)
AC_CHECK_SIZEOF(unsigned int, 4)
AC_CHECK_SIZEOF(unsigned short int, 2)
AC_CHECK_SIZEOF(unsigned char, 1)

AC_CHECK_FUNCS(memmove bcopy)

#
# check for lrint
#
AC_DEFUN(AC_CHECK_LRINT,
[
AC_MSG_CHECKING([for lrint])
AC_CACHE_VAL(ac_cv_lrint,
[
AC_LANG_SAVE
AC_LANG_CPLUSPLUS
ac_libs_safe="$LIBS"
LIBS="$LIBS $all_libraries"
AC_TRY_LINK([
# include <math.h>
],
[
if ( lrint(0) ) {};
],
ac_cv_lrint=yes,
ac_cv_lrint=no)
LIBS="$ac_libs_safe"
AC_LANG_RESTORE
])
AC_MSG_RESULT($ac_cv_lrint)
if eval "test \"`echo $ac_cv_lrint`\" = yes"; then
  AC_DEFINE(HAVE_LRINT, 1, [Define if you have lrint])
  fi
])

AC_CHECK_LRINT()

#
# check ssl lib
#
KDE_CHECK_SSL

AC_CONFIG_FILES([ Makefile ])
AC_CONFIG_FILES([ dclib.spec ])
AC_CONFIG_FILES([ dclib.lsm ])
AC_CONFIG_FILES([ dclib.pc ])
AC_CONFIG_FILES([ dclib/Makefile ])
AC_CONFIG_FILES([ dclib/core/Makefile ])
AC_CONFIG_FILES([ dclib/hash/Makefile ])
AC_OUTPUT
