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

AC_INIT([linux-gpib-user],[4.3.7])
# libtool version: current:revision:age
#
# If the library source code has changed at all since the last update, then
# increment revision (`c:r:a' becomes `c:r+1:a').
#
# If any interfaces have been added, removed, or changed since the last update,
# increment current, and set revision to 0.
#
# If any interfaces have been added since the last public release, then
# increment age.
#
# If any interfaces have been removed since the last public release, then set
# age to 0.
GPIB_SO_VERSION=4:0:4
AC_CONFIG_SRCDIR([lib/ibask.c])
AM_INIT_AUTOMAKE
AM_MAINTAINER_MODE
AC_CONFIG_MACRO_DIR([m4])

dnl create a config.h file (Automake will add -DHAVE_CONFIG_H)
AC_CONFIG_HEADERS([config.h])

AC_SUBST([VERSION])
AC_SUBST([GPIB_SO_VERSION])

[ISODATE=`date +%Y-%m-%d`]
AC_SUBST([ISODATE])

AC_CANONICAL_HOST

AC_ENABLE_SHARED([yes])
AC_ENABLE_STATIC([no])
AC_ARG_ENABLE([all-bindings],[  --disable-all-bindings   Disable all language binding to libgpib],
	[BINDING_DEFAULT=$enableval],[BINDING_DEFAULT="yes"])
AC_ARG_ENABLE([guile-binding],[  --disable-guile-binding  Disable Guile binding to libgpib],
	[BIND_GUILE=$enableval],[BIND_GUILE=$BINDING_DEFAULT])
AC_ARG_ENABLE([perl-binding],[  --disable-perl-binding   Disable Perl binding to libgpib],
	[BIND_PERL=$enableval],[BIND_PERL=$BINDING_DEFAULT])
AC_ARG_ENABLE([php-binding],[  --disable-php-binding    Disable PHP binding to libgpib],
	[BIND_PHP=$enableval],[BIND_PHP=$BINDING_DEFAULT])
AC_ARG_ENABLE([python-binding],[  --disable-python-binding Disable Python binding to libgpib],
	[BIND_PYTHON=$enableval],[BIND_PYTHON=$BINDING_DEFAULT])
AC_ARG_ENABLE([tcl-binding],[  --disable-tcl-binding    Disable TCL binding to libgpib],
	[BIND_TCL=$enableval],[BIND_TCL=$BINDING_DEFAULT])
AC_ARG_ENABLE([documentation],[  --disable-documentation  Disable building pdf documentation from SGML sources],
	[BUILD_DOCS=$enableval],[BUILD_DOCS="yes"])
AC_ARG_ENABLE([html-docs],[  --disable-html-docs      Disable building html documentation from SGML sources],
	[BUILD_HTML=$enableval],[BUILD_HTML="yes"])
AC_ARG_ENABLE([manpages],[  --disable-manpages       Disable building man pages from SGML sources],
	[BUILD_MANPAGES=$enableval],[BUILD_MANPAGES="yes"])
dnl udev lib dir
AC_ARG_WITH([udev-libdir],
	[AS_HELP_STRING([--with-udev-libdir=DIR], [location to install udev scripts [PREFIX/lib/udev]])],
	[UDEV_LIBDIR=$withval], [UDEV_LIBDIR='${prefix}'/lib/udev])
AC_SUBST([UDEV_LIBDIR])

dnl Checks for programs.
AC_PROG_INSTALL
AC_PROG_CC
AM_PROG_CC_C_O
dnl Cannot use AM_PROG_LEX since it does not pass the [noyywrap] option
AC_PROG_LEX([noyywrap])
if test "$LEX" = ":" ; then
   LEX="$SHELL "$srcdir"/../missing flex"
fi
AM_MISSING_PROG(YACC,bison)

LT_INIT
#docs and manpages
AC_PATH_PROGS([SGML2PDF_PATH], [dblatex jw], [no])
if test "$SGML2PDF_PATH" = "no" ; then
	AC_MSG_NOTICE([docbook-tools neither dblatex nor jw found, disabling pdf documentation])
	BUILD_DOCS="no"
fi
AC_PATH_PROG([JW_PATH], [jw], [no])
if test "$JW_PATH" = "no" ; then
	AC_MSG_NOTICE([docbook-tools jw not found, disabling html documentation])
	BUILD_HTML="no"
fi
# look for manpage xsl file in various locations
AC_CHECK_FILE(/usr/share/sgml/docbook/xsl-ns-stylesheets/manpages/docbook.xsl, AC_SUBST([DOCBOOK_XSL],
	      ["/usr/share/sgml/docbook/xsl-ns-stylesheets/manpages/docbook.xsl"]))
AC_CHECK_FILE(/usr/share/sgml/docbook/xsl-stylesheets/manpages/docbook.xsl, AC_SUBST([DOCBOOK_XSL],
              ["/usr/share/sgml/docbook/xsl-stylesheets/manpages/docbook.xsl"]))
AC_CHECK_FILE(/usr/share/xml/docbook/xsl-stylesheets-1.79.2/manpages/docbook.xsl, AC_SUBST([DOCBOOK_XSL],
              ["/usr/share/xml/docbook/xsl-stylesheets-1.79.2/manpages/docbook.xsl"]))
AC_PATH_PROGS([SGML2XML_PATH], [sgml2xml osgml2xml], [no])
AC_PATH_PROG([XSLTPROC_PATH], [xsltproc], [no])
if test "$SGML2XML_PATH" = "no" || test "$XSLTPROC_PATH" = "no" || test -z $DOCBOOK_XSL ; then
	AC_MSG_NOTICE([sgml-man tools  not found, disabling building man pages])
	BUILD_MANPAGES="no"
fi


if test "$BIND_PYTHON" = "yes"; then
	AM_PATH_PYTHON([3.0],,[:])
	if test "$PYTHON" = :; then
	   	AC_MSG_NOTICE([no usable python found, disabling python binding])
		BIND_PYTHON="no"
	fi
fi

if test "$BIND_PERL" = "yes"; then
   AC_PATH_PROG([PERL], [perl], [no], [])
   if test "$PERL" = "no"; then
      AC_MSG_NOTICE([perl not found, disabling perl binding])
      BIND_PERL="no"
    fi
fi

if test "$BIND_TCL" = "yes"; then
   SC_PATH_TCLCONFIG   
   if [[ $no_tcl ]]; then
        AC_MSG_NOTICE([TCL config not found, disabling TCL binding])
        BIND_TCL="no"
   else
	SC_LOAD_TCLCONFIG
   fi
fi

if test "$BIND_PHP" = "yes"; then
   AC_PATH_PROG([PHP_CONFIG], [php-config], [no],[])
   if test "$PHP_CONFIG" = "no"; then
      AC_MSG_NOTICE([php-config not found, disabling PHP binding])
      BIND_PHP="no"
   fi
else
   PHP_CONFIG="no"
fi

dnl Checks for libraries.
if test "$BIND_GUILE" = "yes"; then
AC_CHECK_LIB([guile],[gh_define],[echo this prevents default actions from occurring > /dev/null],
	[BIND_GUILE="no";AC_MSG_NOTICE([libguile not found, disabling guile binding])],[])
fi

AC_CHECK_LIB([readline], [readline], 
  	     [readline_lib=yes;AC_SUBST([LIB_READLINE_LDFLAGS], ["-lreadline -lncurses"])],
	     [],
	     [-lncurses])
		       
dnl Checks for header files.
AC_CHECK_HEADERS(unistd.h sys/param.h sys/time.h time.h sys/mkdev.h sys/sysmacros.h string.h memory.h fcntl.h dirent.h sys/ndir.h ndir.h alloca.h locale.h )

if test "$BIND_PYTHON" = "yes"; then
AM_CHECK_PYTHON_HEADERS([],[BIND_PYTHON=no;AC_MSG_NOTICE([python headers not found, disabling python binding])])
fi

if test "$BIND_GUILE" = "yes"; then
AC_CHECK_HEADER([libguile.h],[],[BIND_GUILE="no";AC_MSG_NOTICE([libguile headers not found, disabling guile binding])])
fi

AC_CHECK_HEADER(readline/readline.h,[readline_h=yes])
AC_CHECK_HEADER(readline/history.h,[history_h=yes])
if test "$readline_lib" = "yes" && test "$readline_h" = "yes" && test "$history_h" = "yes"; then
   AC_SUBST([LIB_READLINE_CFLAGS], ["-DREADLINE"])
fi

if test "$BIND_TCL" != "no"; then
SAVE_CPPFLAGS=$CPPFLAGS
CPPFLAGS="$CPPFLAGS $TCL_INCLUDE_SPEC"
AC_CHECK_HEADER([tcl.h],[],[BIND_TCL="no";AC_MSG_NOTICE([TCL headers not found, disabling TCL binding])])
CPPFLAGS=$SAVE_CPPFLAGS
fi

if test "$PHP_CONFIG" != "no"; then
SAVE_CPPFLAGS=$CPPFLAGS
CPPFLAGS="$CPPFLAGS $($PHP_CONFIG --includes) -D_GNU_SOURCE"
AC_CHECK_HEADER([php.h],[],[BIND_PHP="no";AC_MSG_NOTICE([PHP headers not found, disabling PHP binding])])
CPPFLAGS=$SAVE_CPPFLAGS
fi

AC_HEADER_MAJOR
AC_FUNC_ALLOCA
AC_STRUCT_TM
AC_STRUCT_ST_BLOCKS
AC_FUNC_CLOSEDIR_VOID
AC_CHECK_FUNCS([mkfifo])
AC_CHECK_FUNC([mknod])

dnl Checks for typedefs, structures, and compiler characteristics.

dnl Checks for library functions.

LIBGPIB_CFLAGS="-I\$(top_srcdir)/include -D_REENTRANT"
LIBGPIB_LDFLAGS="\$(top_builddir)/lib/libgpib.la -lpthread"
AC_SUBST([LIBGPIB_CFLAGS])
AC_SUBST([LIBGPIB_LDFLAGS])
IBMAJOR=160
AC_SUBST([IBMAJOR])
AC_DEFINE([IBMAJOR],[160],[Major number of device files])

echo
echo Configuration:
AM_CONDITIONAL([BUILD_DOCS], [test "$BUILD_DOCS" = "yes"])
echo "pdf documentation: $BUILD_DOCS"
AM_CONDITIONAL([BUILD_HTML], [test "$BUILD_HTML" = "yes"])
echo "html documentation: $BUILD_HTML"
AM_CONDITIONAL([BUILD_MANPAGES], [test "$BUILD_MANPAGES" = "yes"])
echo "man pages: $BUILD_MANPAGES"
AM_CONDITIONAL([BIND_GUILE], [test "$BIND_GUILE" = "yes"])
echo "Guile binding: $BIND_GUILE"
AM_CONDITIONAL([BIND_PERL], [test "$BIND_PERL" = "yes"])
echo "Perl binding: $BIND_PERL"
AM_CONDITIONAL([BIND_PHP], [test "$BIND_PHP" = "yes"])
echo "PHP binding: $BIND_PHP"
AM_CONDITIONAL([BIND_PYTHON], [test "$BIND_PYTHON" = "yes"])
echo "Python binding: $BIND_PYTHON"
AM_CONDITIONAL([BIND_TCL], [test "$BIND_TCL" = "yes"])
echo "TCL binding: $BIND_TCL"
AX_DEFINE_DIR([SYSCONFDIR], [sysconfdir], [System configuration directory])
AS_ECHO "sysconfdir: [$SYSCONFDIR]"
AS_ECHO ""

AC_CONFIG_FILES([\
	Makefile \
	drivers/Makefile \
	lib/Makefile \
	lib/libgpib.pc \
	lib/gpib_config/Makefile \
	examples/Makefile \
	test/Makefile \
	doc/Makefile \
	include/Makefile \
	include/gpib/Makefile \
	language/Makefile \
	language/guile/Makefile \
	language/php/Makefile \
	language/php/TESTS/Makefile \
	language/python/Makefile \
	language/tcl/Makefile \
	usb/Makefile \
	usb/ni_usb_gpib/Makefile \
	usb/agilent_82357a/Makefile \
	usb/lpvo_usb_gpib/Makefile \

])
AC_OUTPUT

