AC_INIT([scmxx],[0.9.0],[Hendrik Sattler <post@hendrik-sattler.de>])
AC_REVISION($Revision: 529 $)
AC_PREREQ(2.59)
AC_CONFIG_HEADER([src/config.h src/timeincl.h src/intincl.h src/gtincl.h])

AC_CANONICAL_HOST
CFLAGS="${CFLAGS} -D_GNU_SOURCE -D_REENTRANT -W -Wall -Wno-format-y2k"
CPPFLAGS="${CPPFLAGS} ${CFLAGS}"
AC_PROG_CC
AC_PROG_CPP
AC_CHECK_TOOL(LD,ld,:)
AC_PROG_INSTALL
AC_HEADER_STDC
AC_HEADER_TIME
AC_CHECK_HEADERS(arpa/inet.h)
AC_C_BIGENDIAN()

AH_TEMPLATE(
    [NO_CFMAKERAW],
    [define this to include own cfmakeraw()]
)
AC_CHECK_FUNC(
    cfmakeraw,
    [],
    [AC_DEFINE(NO_CFMAKERAW)]
)

AC_CHECK_HEADERS(math.h)
AC_CHECK_LIB(m,log10)
AC_CHECK_FUNCS(log10 labs)

AC_CHECK_HEADERS(langinfo.h)
AH_TEMPLATE(
    [NO_NL_LANGINFO],
    [define this to include nl_langinfo() replacement]
)
AC_CHECK_FUNC(
    nl_langinfo,
    [],
    [AC_DEFINE(NO_NL_LANGINFO)
     AC_MSG_NOTICE(Input/output is limited to ASCII.)
    ]
)

MY_SEARCH_PARSELIB

AC_CHECK_HEADERS(
    iconv.h,
    [AC_CHECK_LIB(
	 [iconv],
	 [libiconv],
         [],
         [AC_CHECK_FUNC(
              iconv,
	      [],
	      [AC_MSG_ERROR(You need to get libiconv or a newer GNU libc.)]
          )]
     )
     MY_DECL_ICONV_CONST    
     ],
    [AC_MSG_ERROR(You need to get libiconv or a newer GNU libc.)]
)

AC_CHECK_HEADERS(
    libintl.h,
    [AC_SEARCH_LIBS(gettext,
	                  intl,
	                  [AC_PATH_PROG(MSGFMT,msgfmt)
                           AC_PATH_PROG(MSGINIT,msginit)
                           AC_PATH_PROG(MSGMERGE,msgmerge)
                           AC_PATH_PROG(XGETTEXT,xgettext)
	                  ],
	                  [AC_MSG_NOTICE(No translation will be available during runtime.)]
                   )
    ],
    [AC_MSG_NOTICE(No translation will be available during runtime.)]
)


AC_PATH_PROG(DB2X_XSLTPROC,db2x_xsltproc)
AC_PATH_PROG(DB2X_MANXML,db2x_manxml)
AC_PATH_PROG(XSLTPROC,xsltproc)
   
AH_TEMPLATE(
    [GETTEXT_DIRNAME],
    [This defines the dirname for bindtextdomain]
)
if [[ "${prefix}" = "NONE" ]]; then \
    prefix=${ac_default_prefix}; \
fi
GETTEXT_DIRNAME="$(eval echo $datadir/locale)"
AC_DEFINE_UNQUOTED(GETTEXT_DIRNAME,"$GETTEXT_DIRNAME")

AH_TEMPLATE(
    [TTYPORT],
    [This defines the default device to open parameter --device which overwrites this setting]
)
AC_ARG_WITH(
    [device],
    AS_HELP_STRING(--with-device=DEV,Use DEV as default else value depends on system),
    [device=$withval],
    [case $host in
     *-*-linux*)
       device="/dev/ttyS0"
       BLUETOOTH_LIBS=""
       AH_TEMPLATE([HAVE_LIBBLUETOOTH],[define this if you want to use and link to libbluetooth])
       LIBSOLD=$LIBS
       AC_CHECK_HEADERS(bluetooth/bluetooth.h,
                        [AC_CHECK_LIB(bluetooth,
			              str2ba,
			              BLUETOOTH_LIBS="-lbluetooth $BLUETOOTH_LIBS"
			              AC_DEFINE(HAVE_LIBBLUETOOTH)
                                     )
                        ],
                        AC_MSG_NOTICE(Bluetooth header files not found)
                       )
       LIBS=$LIBSOLD
       ;;
     *-*-cygwin*)
       device="/dev/com1"
       ;;
     *-*-mingw32*)
       device="COM1"
       CFLAGS="${CFLAGS} -DWINDOWS_API"
       LIBS="${LIBS} -lshlwapi -lws2_32"
       AC_CHECK_HEADERS(windows.h shlobj.h shlwapi.h winsock2.h,
                        [],
                        [AC_MSG_ERROR(You need to get the w32api mingw package.)]
                       )
       AC_CHECK_HEADERS(ws2bth.h,[],[],[
#include <winsock2.h>
                                       ]
		       )
       ;;
     *-*-os2*)
dnl For further OS/2 support, see INSTALL.OS2
       device="COM1"
       CFLAGS="${CFLAGS} -DOS2_API"
       ;;
     *-*-sunos* | *-*-solaris*)
dnl The values below may not be fully correct.
dnl I only know Solaris8/Sparc, maybe Solaris for x86 is different.
       device="/dev/ttya"
       ;;
     *-*-freebsd*)
dnl FreeBSD value is for x86.
       device="/dev/tty00"
       LIBSOLD=$LIBS
       AC_CHECK_HEADERS(sys/bitstring.h netgraph/bluetooth/include/ng_btsocket.h bluetooth.h,
                        [AC_CHECK_LIB(bluetooth,
			              bt_aton,
			              BLUETOOTH_LIBS="-lbluetooth $BLUETOOTH_LIBS"
			              AC_DEFINE(HAVE_LIBBLUETOOTH)
                                     )
                        ]
                       )
       LIBS=$LIBSOLD
       ;;
     *-*-netbsd*)
dnl NetBSD is guessed.
       device="/dev/tty00"
       ;;
     *-*-openbsd*)
dnl Values that people told me. If you know better, tell me.
dnl OpenBSD value refers to OpenBSD/Sparc.
       device="/dev/ttya"
       ;;
     *)
dnl The default value defaults to the first non-numbered tty device
       AC_MSG_WARN(System $host not known.)
       device=`ls -1 /dev/tty[^0-9]* | head -n 1`
       AC_MSG_WARN(Guessing: ${device})
       ;;
     esac
    ]
)
AC_MSG_NOTICE(Using $device as default device.)
AC_DEFINE_UNQUOTED(TTYPORT,"$device")


AH_TEMPLATE(
    [TTYSPEED],
    [This defines the default serial baudrate, valid values may depend on system]
)
AC_ARG_WITH(
    [baudrate],
    AS_HELP_STRING(--with-baudrate=SPEED,Set baud rate to SPEED @<:@19200@:>@),
    [baudrate=$withval],
    [baudrate=19200]
)
AC_MSG_NOTICE(Using $baudrate as default baudrate.)    
AC_DEFINE_UNQUOTED(TTYSPEED,"$baudrate")

AC_SUBST(LD)
AC_SUBST(GETTEXT_DIRNAME)
AC_SUBST(PACKAGE_NAME)
AC_SUBST(PARSELIB)
AC_SUBST(LIBS)
AC_SUBST(BLUETOOTH_LIBS)
AC_SUBST(OBJEXT)
AC_SUBST(EXEEXT)
AC_CONFIG_FILES(Makefile src/Makefile src/Makefile.sub docs/Makefile po/Makefile)
AC_OUTPUT
