# Process this file with autoconf to produce a configure script.
AC_INIT(gsoap, 2.8)
AM_INIT_AUTOMAKE(gsoap, 2.8)
AC_CONFIG_SRCDIR([gsoap/stdsoap2.cpp])
AC_CANONICAL_HOST

dnl AC_CONFIG_HEADER([config.h])
AM_CONFIG_HEADER(config.h)

dnl we use subdirs.
AC_PROG_MAKE_SET 
# Checks for programs.
AC_PROG_CXX
AC_PROG_CC
AM_PROG_LEX
AC_PROG_YACC
AC_PROG_CPP
AC_PROG_RANLIB
#AC_PROG_LIBTOOL
AC_PROG_LN_S
AC_PROG_AWK
AC_PROG_INSTALL

# AC_DECL_YYTEXT

SAMPLE_EXTRA_LIBS=

dnl Platform-specific Makefile setup
case "${host}" in
        *-*-solaris*)   platform=SUN_OS 
			SAMPLE_EXTRA_LIBS="-lxnet -lsocket -lnsl"
			;;
        *-*-sysv5*)     platform=UNIXWARE ;;
        *-*-UnixWare*)  platform=UNIXWARE ;;
        *-*-unixware*)  platform=UNIXWARE ;;
	*-*-sco3.2v5*)  platform=OPENSERVER
	                SAMPLE_EXTRA_LIBS="-lsocket"
			;;
        *-*-linux*)     platform=LINUX
dnl			if test x$debug = xtrue; then 
dnl			    CFLAGS="-g" #don't want the -O2 for debugging.
dnl			else
dnl			    CFLAGS="-O2" #don't want the -g for release compile.
dnl			fi			
			;;
	*-*-cygwin*)	platform=CYGWIN ;;
	*-*-mingw*)	platform=MINGW
			SAMPLE_EXTRA_LIBS="-lws2_32 -lkernel32 -luser32 -lgdi32"
			;;
        *-*-freebsd*)   platform=FREEBSD ;;
        *-*-openbsd*)   platform=OPENBSD ;;
        *-*-irix*)      platform=IRIX ;;
        *-*-aix*)       platform=AIX
                      case "${host}" in
                         *-*-aix4.1*)   osver=AIX41;;
                         *-*-aix4.2*)   osver=AIX42;;
                         *-*-aix4.3*)   osver=AIX43;;
                         *-*-aix4.*)    osver=AIX43;;
                         *-*-aix5.3)    osver=AIX53;;
                      esac;;
        *-sequent-*)    platform=PTX ;;
        *-*-hp*)        platform=HP_UX ;
                        case "${host}" in
                            *-*-hpux11*)  osver=HPUX11;;
                            *-*-hpux10*)  osver=HPUX10;;
                            *)            osver=HPUX11;;
                        esac;;
        *-*-mvs*)       platform=OS390 ;;
        *-*-os400*)     platform=OS400 ;;
        *-*-OS400*)     platform=OS400 ;;
        *-*-osf*)	platform=TRU64
			SAMPLE_EXTRA_LIBS="-lm"
			;;
        *-apple-*)	platform=MACOSX ;;
	*-nto-qnx)	platform=QNX
			SAMPLE_EXTRA_LIBS="-lsocket"
			;;
        *)              platform=UNKNOWN ;;
esac

AC_SUBST(SAMPLE_EXTRA_LIBS)
AC_SUBST(platform)

# Checks for header files.
AC_HEADER_STDC
AC_CHECK_HEADERS([arpa/inet.h xlocale.h errno.h fcntl.h limits.h netdb.h netinet/in.h stdlib.h string.h strings.h stdint.h sys/socket.h sys/types.h sys/time.h sys/timeb.h unistd.h poll.h openssl/ssl.h gnutls/gnutls.h zlib.h])

# Checks for typedefs, structures, and compiler characteristics.
AC_C_CONST
AC_TYPE_SIZE_T
AC_HEADER_TIME
AC_STRUCT_TM

# Checks for library functions.
AC_FUNC_MKTIME
AC_TYPE_SIGNAL
AC_FUNC_STRFTIME
AC_CHECK_FUNCS([random gettimeofday ftime localtime_r timegm gmtime gmtime_r memset select socket snprintf strchr strerror strerror_r strrchr strstr strtol strtoul strtoll strtoull strtold strtod strtof strtold_l strtod_l strtof_l sscanf sscanf_l sprintf_l wctomb mbtowc poll])

dnl Function test depending on platform
dnl AIX Has incompatible gethostbyname_r
if test $platform != AIX -a $platform != TRU64; then
  AC_CHECK_FUNCS([gethostbyname_r])
  AC_FUNC_MALLOC
fi

dnl the debug build options adds symbols to compiler output (-g for g++)
AC_ARG_ENABLE(debug,
[  --enable-debug	  add debug symbols for debugging],
[case "${enableval}" in
  yes) debug=true ;;
  no)  debug=false ;;
  *) AC_MSG_ERROR(bad value ${enableval} for --enable-debug) ;;
esac],[debug=false])
AM_CONDITIONAL(DEBUG_COMPILE, test x$debug = xtrue)
if test x$debug = xtrue; then 
    SOAPCPP2_DEBUG="-DDEBUG" ##define DEBUG for debugging
else
    SOAPCPP2_DEBUG=
fi			
AC_SUBST(SOAPCPP2_DEBUG)

dnl set the default soapcpp2 import path
SOAPCPP2_IMPORTPATH="-DSOAPCPP_IMPORT_PATH=\"\\\"${datadir}/gsoap/import\\\"\""
#SOAPCPP2_IMPORTPATH="-DSOAPCPP2_IMPORT_PATH=\"\\\"`pwd`/gsoap/import\\\"\""
AC_SUBST(SOAPCPP2_IMPORTPATH)

dnl set the default wsdl2h import path
WSDL2H_IMPORTPATH="-DWSDL_IMPORT_PATH=\"\\\"${datadir}/gsoap/WS\\\"\""
#WSDL2H_IMPORTPATH="-DWSDL2H_IMPORT_PATH=\"\\\"`pwd`/gsoap/WS\\\"\""
AC_SUBST(WSDL2H_IMPORTPATH)

dnl the disable-namespaces option adds the -DWITH_NONAMESPACES to the
dnl library compilation thus disabling namespaces
AC_ARG_ENABLE(namespaces,
              [AC_HELP_STRING([--disable-namespaces],
                              [compile library without namespaces])],
              [with_namespaces="$enable_ns"],
              [with_namespaces="yes"])

AC_MSG_CHECKING(for disable namespaces in library)
if test "x$with_namespaces" = "xyes"; then
  AC_MSG_RESULT(no)
else
  AC_MSG_RESULT(yes)
  SOAPCPP2_NONAMESPACES="-DWITH_NONAMESPACES" ##define to remove nsmap link dependence
fi
AC_SUBST(SOAPCPP2_NONAMESPACES)

dnl the disable-ssl option removes the dependence on OpenSSL
AC_ARG_ENABLE(ssl,
              [AC_HELP_STRING([--disable-ssl],
                              [build without SSL/TLS])],
              [with_openssl="$enable_openssl"],
              [with_openssl="yes"])

dnl the enable-gnutls option enables GNUTLS in favor of OpenSSL
AC_ARG_ENABLE(gnutls,
              [AC_HELP_STRING([--enable-gnutls],
                              [build with GNUTLS SSL/TLS])],
              [with_gnutls="yes"],
              [with_gnutls="$enable_gnutls"])

AC_MSG_CHECKING(for disable openssl in library)
if test "x$with_openssl" = "xyes"; then
  AC_MSG_RESULT(no)
  AC_MSG_CHECKING(for enable gnutls in library)
  if test "x$with_gnutls" = "xyes"; then
    AC_MSG_RESULT(yes)
    WSDL2H_EXTRA_FLAGS="-DWITH_GNUTLS -DWITH_GZIP"
    WSDL2H_EXTRA_LIBS="-lgnutls -lgcrypt -lz"
    SAMPLE_SSL_LIBS="-lgnutls -lgcrypt -lz"
    WSDL2H_SOAP_CPP_LIB="libgsoapssl++.a"
  else
    AC_MSG_RESULT(no)
    WSDL2H_EXTRA_FLAGS="-DWITH_OPENSSL -DWITH_GZIP"
    WSDL2H_EXTRA_LIBS="-lssl -lcrypto -lz"
    SAMPLE_SSL_LIBS="-lssl -lcrypto -lz"
    WSDL2H_SOAP_CPP_LIB="libgsoapssl++.a"
  fi
else
  AC_MSG_RESULT(yes)
  WSDL2H_EXTRA_FLAGS=
  WSDL2H_EXTRA_LIBS=
  SAMPLE_SSL_LIBS=
  WSDL2H_SOAP_CPP_LIB="libgsoap++.a"
fi
AC_SUBST(WSDL2H_EXTRA_FLAGS)
AC_SUBST(WSDL2H_EXTRA_LIBS)
AC_SUBST(SAMPLE_SSL_LIBS)
AC_SUBST(WSDL2H_SOAP_CPP_LIB)

dnl enable the compile of the samples
AC_ARG_ENABLE(samples,
[  --enable-samples	  enable compile for the gsoap samples],
[case "${enableval}" in
  yes) samples=true ;;
  no)  samples=false ;;
  *) AC_MSG_ERROR(bad value ${enableval} for --enable-samples) ;;
esac],[samples=false])
AM_CONDITIONAL(ENABLE_SAMPLES, test x$samples = xtrue)
AC_SUBST(ENABLE_SAMPLES)

if test x$samples = xtrue; then
   SAMPLE_DIRS=". samples"
else
   SAMPLE_DIRS=
fi
AC_SUBST(SAMPLE_DIRS)

if test x$LEX = xflex; then
   LEX_DEFINE=-DWITH_FLEX
   LEX_FLAGS="-l"
else
   AC_MSG_WARN(No 'flex' command detected on current path: trying existing scanner, but this may fail to build wsdl2h)
   LEX_DEFINE=-DWITH_LEX
   LEX_FLAGS=
fi
AC_SUBST(LEX_DEFINE)
AC_SUBST(LEX_FLAGS)
AC_SUBST(LEXLIB)

dnl check if we must define -DWITH_BISON
if test "$YACC" = "bison -y"; then
   BISON_DEFINE=-DWITH_BISON
   YACC_LIB=
else
   BISON_DEFINE=-DWITH_YACC
   YACC_LIB="-ly"
fi
AC_SUBST(BISON_DEFINE)
AC_SUBST(YACC_LIB)

AC_CONFIG_FILES([ Makefile \
    gsoap.pc gsoap++.pc gsoapck.pc gsoapck++.pc gsoapssl.pc gsoapssl++.pc \
    gsoap/Makefile \
    gsoap/src/Makefile \
    gsoap/wsdl/Makefile \
    gsoap/samples/Makefile \
    gsoap/samples/autotest/Makefile \
    gsoap/samples/calc/Makefile \
    gsoap/samples/calc++/Makefile \
    gsoap/samples/databinding/Makefile \
    gsoap/samples/dime/Makefile \
    gsoap/samples/dom/Makefile \
    gsoap/samples/oneway/Makefile \
    gsoap/samples/oneway++/Makefile \
    gsoap/samples/factory/Makefile \
    gsoap/samples/factorytest/Makefile \
    gsoap/samples/gmt/Makefile \
    gsoap/samples/googleapi/Makefile \
    gsoap/samples/hello/Makefile \
    gsoap/samples/httpcookies/Makefile \
    gsoap/samples/lu/Makefile \
    gsoap/samples/magic/Makefile \
    gsoap/samples/mashup/Makefile \
    gsoap/samples/mashup++/Makefile \
    gsoap/samples/mtom/Makefile \
    gsoap/samples/mtom-stream/Makefile \
    gsoap/samples/polytest/Makefile \
    gsoap/samples/roll/Makefile \
    gsoap/samples/router/Makefile \
    gsoap/samples/rss/Makefile \
    gsoap/samples/ssl/Makefile \
    gsoap/samples/template/Makefile \
    gsoap/samples/udp/Makefile \
    gsoap/samples/varparam/Makefile \
    gsoap/samples/wsa/Makefile \
    gsoap/samples/wsrm/Makefile \
    gsoap/samples/wsse/Makefile \
    gsoap/samples/xml-rpc/Makefile
])
AC_OUTPUT
