## CAFE (Channel Access interFacE)
## Author: Jan Chrin, GFA, PSI 
## 
## configure.ac is processed by autoconf 
##
## output: configure.in file for building the cafe library 
## 

#  Standard macros
AC_PREREQ(2.63)
AC_COPYRIGHT([CAFE,Jan Chrin, 2013])
AC_INIT([CAFE], [1.0.0], [Bug reports to: jan.chrin@psi.ch])

AC_CONFIG_AUX_DIR(./)

AC_CONFIG_MACRO_DIR([m4])
m4_pattern_allow([AC_CONFIG_MACRO])


AM_INIT_AUTOMAKE
AC_CONFIG_SRCDIR([./include/cafe.h])

AC_LANG_CPLUSPLUS

AC_CONFIG_HEADER([./include/config.h:./include/config.in])
AC_PROG_CXX

# library creation
AC_PROG_LIBTOOL
LT_INIT


AC_LANG([C++])



AC_DEFINE_UNQUOTED(HAVE_LINUX, 1, [linux dependency (sleep)])  

CPPFLAGS=" -fexceptions -fPIC"
#CPPFLAGS=" -pg"
# provide include directories
AC_SUBST([CAFE_CPPFLAGS], '-I$(top_srcdir)/include ')

##---------------------------------------------------------------------------
##-- EPICS -- path and options
##
  EPICS_PREFIX=""
  EPICS_INCL_PATH=""
  EPICS_LIB_PATH=""
## Add epics release  

  EPICS_MAJOR_DEFAULT="3"
  EPICS_MINOR_DEFAULT="14"
  EPICS_PATCH_DEFAULT="12"

  EPICS_MAJOR_REL=${EPICS_MAJOR_DEFAULT}
  EPICS_MINOR_REL=${EPICS_MINOR_DEFAULT}
  EPICS_PATCH_REL=${EPICS_PATCH_DEFAULT}
  
  #overwrite default with actual if determined
  if test "${CAFE_EPICS_V_MAJOR}" != ""; then
      EPICS_MAJOR_REL=${CAFE_EPICS_V_MAJOR} 
  fi
  if test "${CAFE_EPICS_V_MINOR}" != ""; then
      EPICS_MINOR_REL=${CAFE_EPICS_V_MINOR}
  fi
  if test "${CAFE_EPICS_V_PATCH}" != ""; then
      EPICS_PATCH_REL=${CAFE_EPICS_V_PATCH} 
  fi

  AC_ARG_ENABLE(
    [epics],
    AC_HELP_STRING([--enable-epics],
                   [enable epics use [default=no]]),
    [HAVE_EPICS=true],
    [HAVE_EPICS=false])

  AC_ARG_WITH(
   epics,
   AC_HELP_STRING(
     [--with-epics location of EPICS],
     [prefix where the epics libraries and include files are to be found]),
   [HAVE_EPICS=true
    EPICS_PREFIX=$withval
    EPICS_INCL_PATH="-I"${EPICS_PREFIX}"/include/ -I"${EPICS_PREFIX}"/include/os/Linux"
    EPICS_LIB_PATH=${EPICS_PREFIX}"/lib/"${EPICS_HOST_ARCH}])

		#echo "TEST ", $EPICS_LIB_PATH
##
##-- end EPICS -- path and options
##---------------------------------------------------------------------------



##===========================================================================
##== Check for header files and libraries.
##===========================================================================


##---------------------------------------------------------------------------
##-- EPICS -- check header files and libs
##
  AC_LANG_PUSH([C++])

  if test $HAVE_EPICS == true; then

  # Change flags: if all tests are successfull, accept this changes; if
  # the tests are not successfull, use the old flags.
    if test "${EPICS_PREFIX}" != "" ; then
      TEMP_CPPFLAGS=${CPPFLAGS}
      CPPFLAGS=${CPPFLAGS}" "${EPICS_INCL_PATH}
      TEMP_LDFLAGS=${LDFLAGS}
      LDFLAGS=${LDFLAGS}" -L"${EPICS_LIB_PATH}" -Wl,-rpath,"${EPICS_LIB_PATH}
    fi
	
    if test x$HAVE_EPICS == xtrue ; then
       AC_CHECK_HEADERS(
       [cadef.h],
       [HAVE_EPICS=true],
       [HAVE_EPICS=false
       AC_MSG_WARN(cadef.h not found!)],
       [])
    fi

    if test x$HAVE_EPICS == xtrue ; then
       AC_CHECK_HEADERS(
       [epicsTypes.h],
       [HAVE_EPICS=true],
       [HAVE_EPICS=false
       AC_MSG_WARN(epicsTypes.h not found!)],
       [])
    fi


    if test x$HAVE_EPICS == xtrue ; then
       AC_CHECK_LIB(ca,[main],
       [HAVE_EPICS=true],
       [HAVE_EPICS=false
       AC_MSG_WARN(libca either not found or not operational!)])
    fi

		
    if test x$HAVE_EPICS == xtrue ; then
       AC_CHECK_LIB(Com,[main],
       [HAVE_EPICS=true],
       [HAVE_EPICS=false
       AC_MSG_WARN(libCom either not found or not operational!)])
    fi

    if test x$HAVE_EPICS == xtrue ; then
       AC_CHECK_LIB(dl,[main],
       [HAVE_EPICS=true],
       [HAVE_EPICS=false
       AC_MSG_WARN(libdl either not found or not operational!)])
    fi

    #echo " HAVE EPICS? "  $HAVE_EPICS x$HAVE_EPICS

    # If all checks are OK we add rlog to the CXXFLAGS.
    if test x$HAVE_EPICS != xtrue ; then
      if test "${EPICS_PREFIX}" != "" ; then
  		  CPPFLAGS=${TEMP_CPPFLAGS}
	      LDFLAGS=${TEMP_LDFLAGS}
       fi
    
    fi	
    
    echo "LDFLAGS__> $LDFLAGS "
  
    if test x$HAVE_EPICS == xtrue ; then
      AC_DEFINE_UNQUOTED(HAVE_EPICS,  ${EPICS_MAJOR_REL}.${EPICS_MINOR_REL}.${EPICS_PATCH_REL}, [epics version])
      AC_DEFINE_UNQUOTED(EPICS_MAJOR,  ${EPICS_MAJOR_REL}, [epics major release])
      AC_DEFINE_UNQUOTED(EPICS_MINOR,  ${EPICS_MINOR_REL}, [epics minor release])
      AC_DEFINE_UNQUOTED(EPICS_PATCH,  ${EPICS_PATCH_REL}, [epics patch release])
    fi
 fi

 
  AC_LANG_POP
##
##-- end EPICS -- check header files and libs
##---------------------------------------------------------------------------


##---------------------------------------------------------------------------
##-- BOOST -- path and options - 
##-- Boost libraries are mainly header-only, i.e. they consist of header files
##-- containing templates and inline functions, and require no separately-compiled
##-- library binaries or special treatment when linking
##
  BOOST_PREFIX=""
  BOOST_INCL_PATH=""
  BOOST_LIB_PATH=""
  BOOST_OPTION=""

  AC_ARG_ENABLE(
    [boost-inc],
    AC_HELP_STRING([--enable-boost-inc],
                   [enable boost use [default=no]]),
    [HAVE_BOOST_=true],
    [HAVE_BOOST_=false])

  AC_ARG_WITH(
   boost-inc,
   AC_HELP_STRING(
     [--with-boost-inc = location of BOOST],
     [prefix giving the boost base directory]),
   [HAVE_BOOST_=true
    BOOST_PREFIX=$withval
    BOOST_INCL_PATH="-I"${BOOST_PREFIX}"/boost -I"${BOOST_PREFIX}
    #BOOST_LIB_PATH=${BOOST_PREFIX}"/lib "
		])
		
		   
  AC_ARG_ENABLE(
    [boost-lib],
    AC_HELP_STRING([--enable-boost-lib],
                   [enable boost lib use [default=no]]),
    [HAVE_BOOST_LIB_=true],
    [HAVE_BOOST_LIB_=false])
		

  AC_ARG_WITH(
   boost-lib,
   AC_HELP_STRING(
     [--with-boost-lib = location of BOOST],
     [prefix giving the boost base directory]),
   [HAVE_BOOST_LIB=true   
    BOOST_LIB_PATH=$withval
		])

##
##-- end BOOST -- path and options
##---------------------------------------------------------


##---------------------------------------------------------------------------
##-- BOOST -- check header files (and lib if selected) only
##
 AC_LANG_PUSH([C++])
 
if test $HAVE_BOOST_LIB_ == true ; then
 
	
  TEMP_LDFLAGS=${LDFLAGS}
  LDFLAGS=${LDFLAGS}" -L"${BOOST_LIB_PATH}"  -Wl,-rpath,"${BOOST_LIB_PATH}
  echo ${BOOST_LIB_PATH}
	echo ${LDFLAGS}


	  if test x$HAVE_BOOST_LIB_ == xtrue ; then
	    AC_CHECK_LIB(boost_thread,[main],
	      [],
		    [HAVE_BOOST_LIB=false
		    AC_MSG_WARN(boost_thread not found!)])
		fi
	

    # If all checks are OK we add boost lib version to the FLAGS.
	if test x$HAVE_BOOST_LIB_ != xtrue ; then
		            
        	LDFLAGS=${TEMP_LDFLAGS}
      
     
	fi

       	if test x$HAVE_BOOST_LIB_ == xtrue ; then
	        AC_DEFINE_UNQUOTED(HAVE_BOOST_THREAD, 1, [boost thread library])  
        fi
				
	
fi	

#if test x$HAVE_BOOST_LIB_ != xtrue ; then
#	        AC_DEFINE_UNQUOTED(HAVE_LINUX, 1, [linux dependency (sleep)])  
#        fi



if test $HAVE_BOOST_ == true ; then

	# Change flags: if all tests are successful, accept these additions, 
	# else use the old flags.
	if test "${BOOST_PREFIX}" != "" ; then
	  TEMP_CPPFLAGS=${CPPFLAGS}
	  CPPFLAGS=${CPPFLAGS}" "${BOOST_INCL_PATH}
	
	  echo ${BOOST_INCL_PATH}
	  echo ${CPPFLAGS}
	
	fi
	
	if test x$HAVE_BOOST_ == xtrue ; then
	  AC_CHECK_HEADERS(
	  [multi_index_container.hpp],
	  [HAVE_BOOST_=true],
	  [HAVE_BOOST_=false
	  AC_MSG_WARN(multi_index_container.hpp not found!)],
	  [])
	fi

	if test x$HAVE_BOOST_ != xtrue ; then
	   if test "${BOOST_PREFIX}" != "" ; then
  		  CPPFLAGS=${TEMP_CPPFLAGS}
		  	echo ${CPPFLAGS}
	   fi
	fi

       	if test x$HAVE_BOOST_ == xtrue ; then
	       AC_DEFINE_UNQUOTED(HAVE_BOOST, 1, [Availability of boost])
	
	      fi
		
fi

  AC_LANG_POP
##
##-- end BOOST-- check header files only
##-----------------------------


##---------------------------------------------------------------------------
##-- Qt4 -- path and options
##
  QT4_PREFIX=""
  QT4_INCL_PATH=""
  QT4_LIB_PATH=""

  AC_ARG_ENABLE(
    [qt4-inc],
    AC_HELP_STRING([--enable-qt4-inc],
                   [enable Qt version 4 use [default=no]]),
    [HAVE_QT4_=true],
    [HAVE_QT4_=false])
    
    
  AC_ARG_ENABLE(
    [qt4-lib],
    AC_HELP_STRING([--enable-qt4-lib],
                   [enable Qt version 4 use [default=no]]),
    [HAVE_QT4_=true],
    [HAVE_QT4_=false])

#Only if enable flag is set

  if test $HAVE_QT4_ == true ; then

  AC_ARG_WITH(
    qt4-inc,
    AC_HELP_STRING([--with-qt4-inc=PREFIX],
      [prefix, parent directory where the Qt version 4 library is installed]),
    [HAVE_QT4_=true
     QT4_PREFIX=$withval   
     QT4_INCL_PATH=${QT4_INCL_PATH}" -I"${QT4_PREFIX}"/QtCore "     
     QT4_INCL_PATH=${QT4_INCL_PATH}" -I"${QT4_PREFIX}"/QtXml "   
    ])
    
    
  AC_ARG_WITH(
    qt4-lib,
    AC_HELP_STRING([--with-qt4-lib=PREFIX],
      [prefix, parent directory where the Qt version 4 library is installed]),
    [HAVE_QT4_=true
     QT4_LIB_PATH=$withval
     QT4_LIB_PATH=${QT4_LIB_PATH}
    ])
    
  fi
    
##
##---------------------------------------------------------------------------



##---------------------------------------------------------------------------
##-- Qt version 4 -- check header files and libs
##
  AC_LANG_PUSH([C++])

  if test $HAVE_QT4_ == true ; then

	  # Change flags: if all tests are successfull, accept this changes; if
	  # the tests are not successfull, use the old flags.
    if test "${QT4_PREFIX}" != "" ; then
      TEMP_CPPFLAGS=${CPPFLAGS}
      CPPFLAGS=${CPPFLAGS}" "${QT4_INCL_PATH}
      TEMP_LDFLAGS=${LDFLAGS}
      LDFLAGS=${LDFLAGS}" -L"${QT4_LIB_PATH}"  -Wl,-rpath,"${QT4_LIB_PATH}
    fi

    if test x$HAVE_QT4_ == xtrue ; then
      AC_CHECK_HEADERS(
        [qxml.h],
	      [HAVE_QT4_=true],
	      [HAVE_QT4_=false
               AC_MSG_WARN(qxml.h not found!)],
	      [])
	  fi

	  if test x$HAVE_QT4_ == xtrue ; then
	    AC_CHECK_LIB(QtCore,[main],
	      [],
		    [HAVE_QT4_=false
		    AC_MSG_WARN(libQtCore not found!)])
		fi

	  if test x$HAVE_QT4_ == xtrue ; then
	    AC_CHECK_LIB(QtXml,[main],
	      [],
		    [HAVE_QT4=false
		    AC_MSG_WARN(libQtXml not found!)])
		fi
	

    # If all checks are OK we add Qt version 4 to the FLAGS.
	if test x$HAVE_QT4_ != xtrue ; then
		
      	if test "${QT4_PREFIX}" != "" ; then
        	CPPFLAGS=${TEMP_CPPFLAGS}
        	LDFLAGS=${TEMP_LDFLAGS}
      		fi
     
	fi

       	if test x$HAVE_QT4_ == xtrue ; then
	   AC_DEFINE_UNQUOTED(HAVE_QT4, 1,[Availability of Qt version 4 confirmed])
        fi

 fi
  AC_LANG_POP
##
##-- end QT4 -- check header files and libs


##---------------------------------------------------------------------------
##---------------------------------------------------------------------------
##-- Zeromq -- path and options -
##-- Zeromq header files required
##

  ZEROMQ_PREFIX=""
  ZEROMQ_INCL_PATH=""
  ZEROMQ_LIB_PATH=""
  ZEROMQ_OPTION=""

  AC_ARG_ENABLE(
	[zeromq-inc],
	AC_HELP_STRING([--enable-zeromq-inc],
				   [enable zeromq use [default=no]]),
	[HAVE_ZEROMQ_=true],
	[HAVE_ZEROMQ_=false])

  AC_ARG_WITH(
   zeromq-inc,
   AC_HELP_STRING(
	 [--with-zeromq-inc = location of zeromq],
	 [prefix giving the zeromq base directory]),
   [HAVE_ZEROMQ_=true
	ZEROMQ_PREFIX=$withval
	ZEROMQ_INCL_PATH="-I"${ZEROMQ_PREFIX}
	])


  AC_ARG_ENABLE(
	[zeromq-lib],
	AC_HELP_STRING([--enable-zeromq-lib],
				   [enable zeromq use [default=no]]),
	[HAVE_ZEROMQ_=true],
	[HAVE_ZEROMQ_=false])
   
  AC_ARG_WITH(
    zeromq-lib,
    AC_HELP_STRING([--with-zeromq-lib=PREFIX],
      [prefix, parent directory where the zeromq version library is installed]),
    [HAVE_ZEROMQ_=true
     ZEROMQ_LIB_PATH=$withval
     ZEROMQ_LIB_PATH=${ZEROMQ_LIB_PATH}
    ])
    
##
##-- end ZEROMQ -- path and options
##---------------------------------------------------------


##---------------------------------------------------------------------------
##-- ZEROMQ -- check header files and library
##
 AC_LANG_PUSH([C++])

if test $HAVE_ZEROMQ_ == true ; then

	# Change flags: if all tests are successful, accept these additions,
	# else use the old flags.
	if test "${ZEROMQ_PREFIX}" != "" ; then
	TEMP_CPPFLAGS=${CPPFLAGS}
	CPPFLAGS=${CPPFLAGS}" "${ZEROMQ_INCL_PATH}
	TEMP_LDFLAGS=${LDFLAGS}
  LDFLAGS=${LDFLAGS}" -L"${ZEROMQ_LIB_PATH}"  -Wl,-rpath,"${ZEROMQ_LIB_PATH}
	echo ${ZEROMQ_INCL_PATH}
	echo ${CPPFLAGS}
	fi

	if test x$HAVE_ZEROMQ_ == xtrue ; then
	AC_CHECK_HEADERS(
	[zmq.h],
	[HAVE_ZEROMQ_=true],
	[HAVE_ZEROMQ_=false
	AC_MSG_WARN(zmq.h not found!)],
	[])
	fi

		if test x$HAVE_ZEROMQ_ == xtrue ; then
	    AC_CHECK_LIB(zmq,[main],
	      [],
		    [HAVE_ZEROMQ=false
		    AC_MSG_WARN(libzmq not found!)])
		fi
	

    # If all checks are OK we add Zeromq to the FLAGS.
		
		if test x$HAVE_ZEROMQ_ != xtrue ; then
		 if test "${ZEROMQ_PREFIX}" != "" ; then
		 	 CPPFLAGS=${TEMP_CPPFLAGS}
			 LDFLAGS=${TEMP_LDFLAGS}
				echo ${CPPFLAGS}
	 		fi
		fi


		if test x$HAVE_ZEROMQ_ == xtrue ; then
	  AC_DEFINE_UNQUOTED(HAVE_ZEROMQ, 1, [Availability of zeromq])
		
	fi
fi

  AC_LANG_POP
##
##-- end ZEROMQ-- check header files and lib
##-----------------------------




##---------------------------------------------------------------------------
##---------------------------------------------------------------------------
##-- JSON -- path and options -
##-- JSON header files required
##

  JSON_PREFIX=""
  JSON_INCL_PATH=""
  JSON_LIB_PATH=""
  JSON_OPTION=""

  AC_ARG_ENABLE(
	[json-inc],
	AC_HELP_STRING([--enable-json-inc],
				   [enable json use [default=no]]),
	[HAVE_JSON_=true],
	[HAVE_JSON_=false])

  AC_ARG_WITH(
   json-inc,
   AC_HELP_STRING(
	 [--with-json-inc = location of json],
	 [prefix giving the json base directory]),
   [HAVE_JSON_=true
	JSON_PREFIX=$withval
	JSON_INCL_PATH="-I"${JSON_PREFIX}
	])


  AC_ARG_ENABLE(
	[json-lib],
	AC_HELP_STRING([--enable-json-lib],
				   [enable json use [default=no]]),
	[HAVE_JSON_=true],
	[HAVE_JSON_=false])
   
  AC_ARG_WITH(
    json-lib,
    AC_HELP_STRING([--with-json-lib=PREFIX],
      [prefix, parent directory where the json version library is installed]),
    [HAVE_JSON_=true
     JSON_LIB_PATH=$withval
     JSON_LIB_PATH=${JSON_LIB_PATH}
    ])
    
##
##-- end JSON -- path and options
##---------------------------------------------------------




##---------------------------------------------------------------------------
##-- JSON -- check header files only
##
 AC_LANG_PUSH([C++])

if test $HAVE_JSON_ == true ; then

	# Change flags: if all tests are successful, accept these additions,
	# else use the old flags.
	if test "${JSON_PREFIX}" != "" ; then
	TEMP_CPPFLAGS=${CPPFLAGS}
	CPPFLAGS=${CPPFLAGS}" "${JSON_INCL_PATH}
	TEMP_LDFLAGS=${LDFLAGS}
  LDFLAGS=${LDFLAGS}" -L"${JSON_LIB_PATH}"  -Wl,-rpath,"${JSON_LIB_PATH}
	echo ${JSON_INCL_PATH}
	echo ${CPPFLAGS}
	fi

	if test x$HAVE_JSON_ == xtrue ; then
	AC_CHECK_HEADERS(
	[json/json.h],
	[HAVE_JSON_=true],
	[HAVE_JSON_=false
	AC_MSG_WARN(json.h not found!)],
	[])
	fi

		if test x$HAVE_JSON_ == xtrue ; then
	    AC_CHECK_LIB(json_linux-gcc-4.4.7_libmt,[main],
	      [],
		    [HAVE_JSON=false
		    AC_MSG_WARN(libjson_linux-gcc-4.4.7_libmt not found!)])
		fi
	

    # If all checks are OK we add json to the FLAGS.
		
		if test x$HAVE_JSON_ != xtrue ; then
		 if test "${JSON_PREFIX}" != "" ; then
		 	 CPPFLAGS=${TEMP_CPPFLAGS}
			 LDFLAGS=${TEMP_LDFLAGS}
				echo ${CPPFLAGS}
	 		fi
		fi


		if test x$HAVE_JSON_ == xtrue ; then
	    AC_DEFINE_UNQUOTED(HAVE_JSON, 1, [Availability of json])
		fi
fi

  AC_LANG_POP
##
##-- end JSON-- check header files only
##-----------------------------











##---------------------------------------------------------------------------
##---------------------------------------------------------------------------
##-- CURL -- path and options -
##-- CURL header files required
##

  CURL_PREFIX=""
  CURL_INCL_PATH=""
  CURL_LIB_PATH=""
  CURL_OPTION=""

  AC_ARG_ENABLE(
	[curl-inc],
	AC_HELP_STRING([--enable-curl-inc],
				   [enable curl use [default=no]]),
	[HAVE_CURL_=true],
	[HAVE_CURL_=false])

  AC_ARG_WITH(
   curl-inc,
   AC_HELP_STRING(
	 [--with-curl-inc = location of curl],
	 [prefix giving the curl base directory]),
   [HAVE_CURL_=true
	CURL_PREFIX=$withval
	CURL_INCL_PATH="-I"${CURL_PREFIX}
	])


  AC_ARG_ENABLE(
	[curl-lib],
	AC_HELP_STRING([--enable-curl-lib],
				   [enable curl use [default=no]]),
	[HAVE_CURL_=true],
	[HAVE_CURL_=false])
   
  AC_ARG_WITH(
    curl-lib,
    AC_HELP_STRING([--with-curl-lib=PREFIX],
      [prefix, parent directory where the curl version library is installed]),
    [HAVE_CURL_=true
     CURL_LIB_PATH=$withval
     CURL_LIB_PATH=${CURL_LIB_PATH}
    ])
    
##
##-- end CURL -- path and options
##---------------------------------------------------------






##---------------------------------------------------------------------------
##-- CURL -- check header files only
##
 AC_LANG_PUSH([C++])

if test $HAVE_CURL_ == true ; then

	# Change flags: if all tests are successful, accept these additions,
	# else use the old flags.
	if test "${CURL_PREFIX}" != "" ; then
	TEMP_CPPFLAGS=${CPPFLAGS}
	CPPFLAGS=${CPPFLAGS}" "${CURL_INCL_PATH}
	TEMP_LDFLAGS=${LDFLAGS}
  LDFLAGS=${LDFLAGS}" -L"${CURL_LIB_PATH}"  -Wl,-rpath,"${CURL_LIB_PATH}
	echo ${CURL_INCL_PATH}
	echo ${CPPFLAGS}
	fi

	if test x$HAVE_CURL_ == xtrue ; then
	AC_CHECK_HEADERS(
	[curl/curl.h],
	[HAVE_CURL_=true],
	[HAVE_CURL_=false
	AC_MSG_WARN(curl/curl.h not found!)],
	[])
	fi

		if test x$HAVE_CURL_ == xtrue ; then
	    AC_CHECK_LIB(curl,[main],
	      [],
		    [HAVE_CURL=false
		    AC_MSG_WARN(libcurl not found!)])
		fi
	

    # If all checks are OK we add curl to the FLAGS.
		
		if test x$HAVE_CURL_ != xtrue ; then
		 if test "${CURL_PREFIX}" != "" ; then
		 	 CPPFLAGS=${TEMP_CPPFLAGS}
			 LDFLAGS=${TEMP_LDFLAGS}
				echo ${CPPFLAGS}
	 		fi
		fi


		if test x$HAVE_CURL_ == xtrue ; then
	    AC_DEFINE_UNQUOTED(HAVE_CURL, 1, [Availability of curl])
		fi
fi

  AC_LANG_POP
##
##-- end CURL-- check header files only
##-----------------------------





##---------------------------------------------------------------------------
##---------------------------------------------------------------------------
##-- Python -- path and options -
##-- Python header files required for callback
##

  PYTHON_PREFIX=""
  PYTHON_INCL_PATH=""
  PYTHON_LIB_PATH=""
  PYTHON_OPTION=""

  AC_ARG_ENABLE(
	[python-inc],
	AC_HELP_STRING([--enable-python-inc],
				   [enable python use [default=no]]),
	[HAVE_PYTHON_=true],
	[HAVE_PYTHON_=false])

  AC_ARG_WITH(
   python-inc,
   AC_HELP_STRING(
	 [--with-python-inc = location of python],
	 [prefix giving the python base directory]),
   [HAVE_PYTHON_=true
	PYTHON_PREFIX=$withval
	PYTHON_INCL_PATH="-I"${PYTHON_PREFIX}
	])


  AC_ARG_ENABLE(
	[python-lib],
	AC_HELP_STRING([--enable-python-lib],
				   [enable python use [default=no]]),
	[HAVE_PYTHON_=true],
	[HAVE_PYTHON_=false])
   
  AC_ARG_WITH(
    python-lib,
    AC_HELP_STRING([--with-python-lib=PREFIX],
      [prefix, parent directory where the python version library is installed]),
    [HAVE_PYTHON_=true
     PYTHON_LIB_PATH=$withval
     PYTHON_LIB_PATH=${PYTHON_LIB_PATH}
    ])
    
##
##-- end PYTHON -- path and options
##---------------------------------------------------------


##---------------------------------------------------------------------------
##-- PYTHON -- check header files only
##
 AC_LANG_PUSH([C++])

if test $HAVE_PYTHON_ == true ; then

	# Change flags: if all tests are successful, accept these additions,
	# else use the old flags.
	if test "${PYTHON_PREFIX}" != "" ; then
	TEMP_CPPFLAGS=${CPPFLAGS}
	CPPFLAGS=${CPPFLAGS}" "${PYTHON_INCL_PATH}
	TEMP_LDFLAGS=${LDFLAGS}
  LDFLAGS=${LDFLAGS}" -L"${PYTHON_LIB_PATH}"  -Wl,-rpath,"${PYTHON_LIB_PATH}
	echo ${PYTHON_INCL_PATH}
	echo ${CPPFLAGS}
	fi

	if test x$HAVE_PYTHON_ == xtrue ; then
	AC_CHECK_HEADERS(
	[Python.h],
	[HAVE_PYTHON_=true],
	[HAVE_PYTHON_=false
	AC_MSG_WARN(Python.h not found!)],
	[])
	fi

		if test x$HAVE_PYTHON_ == xtrue ; then
	    AC_CHECK_LIB(python3.5m,[main],
	      [],
		    [HAVE_PYTHON=false
		    AC_MSG_WARN(libpython3.5m not found!)])
		fi
	

    # If all checks are OK we add Qt version 4 to the FLAGS.
		
		if test x$HAVE_PYTHON_ != xtrue ; then
		 if test "${PYTHON_PREFIX}" != "" ; then
		 	 CPPFLAGS=${TEMP_CPPFLAGS}
			 LDFLAGS=${TEMP_LDFLAGS}
				echo ${CPPFLAGS}
	 		fi
		fi


		if test x$HAVE_PYTHON_ == xtrue ; then
	  AC_DEFINE_UNQUOTED(HAVE_PYTHON, 1, [Availability of python])
		##_PYCAFE_EXT IF FLAG SET ELSE USE DEFAULT PYCAFE_API_H	
	  AC_DEFINE_UNQUOTED(HAVE_PYCAFE_EXT, 0, [pycafe extern C])	
	fi
fi

  AC_LANG_POP
##
##-- end PYTHON-- check header files only
##-----------------------------





##---------------------------------------------------------------------------
##---------------------------------------------------------------------------
##-- Python2 -- path and options -
##-- Python2 header files required for callback
##

  PYTHON2_PREFIX=""
  PYTHON2_INCL_PATH=""
  PYTHON2_LIB_PATH=""
  PYTHON2_OPTION=""

  AC_ARG_ENABLE(
	[python2-inc],
	AC_HELP_STRING([--enable-python2-inc],
				   [enable python2 use [default=no]]),
	[HAVE_PYTHON2_=true],
	[HAVE_PYTHON2_=false])

  AC_ARG_WITH(
   python2-inc,
   AC_HELP_STRING(
	 [--with-python2-inc = location of python2],
	 [prefix giving the python2 base directory]),
   [HAVE_PYTHON2_=true
	PYTHON2_PREFIX=$withval
	PYTHON2_INCL_PATH="-I"${PYTHON2_PREFIX}
	])


  AC_ARG_ENABLE(
	[python2-lib],
	AC_HELP_STRING([--enable-python2-lib],
				   [enable python2 use [default=no]]),
	[HAVE_PYTHON2_=true],
	[HAVE_PYTHON2_=false])
   
  AC_ARG_WITH(
    python2-lib,
    AC_HELP_STRING([--with-python2-lib=PREFIX],
      [prefix, parent directory where the python2 version library is installed]),
    [HAVE_PYTHON2_=true
     PYTHON2_LIB_PATH=$withval
     PYTHON2_LIB_PATH=${PYTHON2_LIB_PATH}
    ])
    
##
##-- end PYTHON2 -- path and options
##---------------------------------------------------------


##---------------------------------------------------------------------------
##-- PYTHON2 -- check header files only
##
 AC_LANG_PUSH([C++])

if test $HAVE_PYTHON2_ == true ; then

	# Change flags: if all tests are successful, accept these additions,
	# else use the old flags.
	if test "${PYTHON2_PREFIX}" != "" ; then
	TEMP_CPPFLAGS=${CPPFLAGS}
	CPPFLAGS=${CPPFLAGS}" "${PYTHON2_INCL_PATH}
	TEMP_LDFLAGS=${LDFLAGS}
  LDFLAGS=${LDFLAGS}" -L"${PYTHON2_LIB_PATH}"  -Wl,-rpath,"${PYTHON2_LIB_PATH}
	echo ${PYTHON2_INCL_PATH}
	echo ${CPPFLAGS}
	fi

	if test x$HAVE_PYTHON2_ == xtrue ; then
	AC_CHECK_HEADERS(
	[Python.h],
	[HAVE_PYTHON2_=true],
	[HAVE_PYTHON2_=false
	AC_MSG_WARN(Python.h not found!)],
	[])
	fi

		if test x$HAVE_PYTHON2_ == xtrue ; then
	    AC_CHECK_LIB(python2.7,[main],
	      [],
		    [HAVE_PYTHON2=false
		    AC_MSG_WARN(libpython2.7 not found!)])
		fi
	

    # If all checks are OK we add Qt version 4 to the FLAGS.
		
		if test x$HAVE_PYTHON2_ != xtrue ; then
		 if test "${PYTHON2_PREFIX}" != "" ; then
		 	 CPPFLAGS=${TEMP_CPPFLAGS}
			 LDFLAGS=${TEMP_LDFLAGS}
				echo ${CPPFLAGS}
	 		fi
		fi


		if test x$HAVE_PYTHON2_ == xtrue ; then
	  AC_DEFINE_UNQUOTED(HAVE_PYTHON, 1, [Availability of python2])
		##_PYCAFE_EXT IF FLAG SET ELSE USE DEFAULT PYCAFE_API_H	
	  AC_DEFINE_UNQUOTED(HAVE_PYCAFE_EXT, 0, [pycafe extern C])	
	fi
fi

  AC_LANG_POP
##
##-- end PYTHON-- check header files only
##-----------------------------

















CPPFLAGS=$CPPFLAGS
echo "REPORTING -> current CPPFLAGS = "$CPPFLAGS
LDFLAGS=$LDFLAGS
echo "REPORTING -> current LDFLAGS = "$LDFLAGS

##
##-- end  Check
##--

# Generate makefiles

AC_SUBST(AM_CPPFLAGS, $CPPFLAGS)
AC_SUBST(AM_LDFLAGS, $LDFLAGS)

AM_CONDITIONAL(HAVE_PYTHON_, test x$HAVE_PYTHON_ == xtrue)
AM_CONDITIONAL(HAVE_PYCAFE_EXT, test x$HAVE_PYCAFE_EXT == xtrue)

AM_CONDITIONAL(HAVE_ZEROMQ_, test x$HAVE_ZEROMQ_ == xtrue)

AC_CONFIG_FILES([makefile
		src/makefile
		include/makefile])

AC_OUTPUT
