dnl Link to easy tutorial on using autoconf/automake.
dnl ftp://ftp.ugcs.caltech.edu/pub/elef/autotools/toolsmanual.html

dnl Process this file with autoconf to produce a configure script.
AC_INIT(linuxtrade.c)
RPM_RELEASE=1
AC_SUBST(RPM_RELEASE)
AM_INIT_AUTOMAKE(linuxtrade,  3.65)
AM_CONFIG_HEADER(config.h)
AC_PREFIX_DEFAULT(/usr)

dnl Checks for programs.
AC_PROG_CC
AC_PROG_INSTALL

dnl Add -Wall if gcc
if test "$GCC" = "yes"; then
	CFLAGS="$CFLAGS -Wall -Wno-format-y2k"
fi

dnl Checks for libraries.
dnl Replace `main' with a function in -lncurses:
AC_CHECK_LIB(ncurses, initscr)
AC_CHECK_LIB(panel, new_panel)
AC_CHECK_LIB(m, floor)
AC_CHECK_LIB(pthread, pthread_create)
AC_CHECK_LIB(c_r, pthread_create)
AC_CHECK_LIB(glib, g_tree_new)
AC_CHECK_LIB(socket, socket)
AC_CHECK_LIB(nsl, gethostbyname)

dnl Checks for header files.
AC_HEADER_STDC
AC_CHECK_HEADERS(malloc.h stdint.h)

dnl Checks for typedefs, structures, and compiler characteristics.
AC_STRUCT_TM

dnl Checks for library functions.
# AC_FUNC_SETVBUF_REVERSED
AC_FUNC_STRFTIME
AC_FUNC_VPRINTF
AC_CHECK_FUNCS(putenv socket strdup lrint)

dnl Normally, we link this statically for faster execution and binary
dnl portability.  However, static linking is broken on MacOS X (or at
dnl least I don't know what pixie dust is needed to get it to work).
dnl
dnl If you aim to distribute binaries for your distro, then please insure
dnl that you distribute binaries for both glibc 2.2.x and glibc 2.3.
dnl The easiest way to achieve this is to distribute binaries statically
dnl linked against glibc 2.2.x.  Its also possible to create static
dnl binaries using glibc 2.3, but this could be risky.  A dynamic binary
dnl created using glibc 2.3 *will not* run on a glibc 2.2.x system;
dnl please avoid distributing these unless you provide both sets of
dnl binaries.  I wish to avoid forcing still-mainstream users to upgrade
dnl their libraries in order to run my program.
AM_CONDITIONAL(STATIC, test `uname` != Darwin)

dnl Figure out what libs we need to link with libcurl programs
CURL_LIBS=`curl-config --libs`
AC_SUBST(CURL_LIBS)
CURL_CFLAGS=`curl-config --cflags`
CFLAGS="$CFLAGS $CURL_CFLAGS"

AC_OUTPUT(Makefile linuxtrade.spec linuxtrade.1 index.html register.html)
