dnl Process this file with autoconf to produce a configure script.
dnl -- for a clean build, run: aclocal && autoheader && automake -a && autoconf
AC_PREREQ(2.5)
AC_INIT(ratts, [0.04], [moocow@ling.uni-potsdam.de])

dnl
dnl source & aux
dnl
AC_CONFIG_AUX_DIR(config)

dnl
dnl save user's CFLAGS,CPPFLAGS
dnl
UCPPFLAGS="$CPPFLAGS"
UCFLAGS="$CFLAGS"

dnl
dnl use automake
dnl
AM_INIT_AUTOMAKE(ratts, [0.04])

dnl
dnl use autoheader
dnl
AM_CONFIG_HEADER([src/config.h])


dnl
dnl Programs, prefix
dnl
AC_PROG_CC
AC_PROG_INSTALL
AC_PREFIX_DEFAULT(/usr/local)

dnl
dnl Substitutions
dnl 
AC_SUBST(DEFS)
AC_SUBST(AFLAGS)
AC_SUBST(DFLAGS)
AC_SUBST(IFLAGS)
AC_SUBST(LFLAGS)
AC_SUBST(OFLAGS)
AC_SUBST(WFLAGS)
AC_SUBST(LD)

AC_SUBST(PDEXT)

dnl version stuff (automatically exported?)
AC_SUBST(PACKAGE_VERSION)
AC_SUBST(PACKAGE_NAME)
AC_SUBST(BUGREPORT)

dnl ----- begin imported rsynth configuration stuff

dnl other flags
AC_ISC_POSIX

dnl Checks for header files.
AC_HEADER_STDC
AC_CHECK_HEADERS([fcntl.h limits.h sys/types.h sys/file.h sys/ioctl.h sys/time.h unistd.h],
	[],
	AC_MSG_WARN([-----------------------------------------------------------------])
	AC_MSG_WARN([could not find standard C headers -- things may get ugly])
	AC_MSG_WARN([-----------------------------------------------------------------]),
	[/* nonempty includes: compile only */])
if test "$ac_cv_header_stdc" != yes; then
 AC_CHECK_FUNCS(strchr memcpy)
 AC_CHECK_HEADERS(memory.h malloc.h)
fi 

dnl more header files
AC_CHECK_HEADERS([math.h sys/param.h sys/signal.h sys/stat.h],
	[],
	AC_MSG_WARN([-----------------------------------------------------------------])
	AC_MSG_WARN([could not find some C headers -- things may get ugly])
	AC_MSG_WARN([-----------------------------------------------------------------]),
	[/* nonempty includes: compile only */])

dnl Checks for typedefs, structures, and compiler characteristics.
AC_C_CONST
AC_TYPE_OFF_T

dnl See if float can be used in protos followed by K&R definition
AC_MSG_CHECKING(if we can use float in prototypes)
AC_TRY_COMPILE([#include "$srcdir/src/proto.h"],[
} int func PROTO((float a));
int func(a) float a; { ],AC_MSG_RESULT(yes),[
AC_DEFINE(NOPROTOFLOAT,1,[Define this if float can be used in protos followed by K&R definition])
AC_MSG_RESULT(no)
])
dnl ----- end imported rsynth configuration stuff


dnl
dnl enable invidual externals?
dnl 
AC_ARG_ENABLE(object-externals,
	AC_HELP_STRING([--enable-object-externals],
	               [Build single-object externals in addition to library (default=no)]),
	[want_obj_externs="$enableval"],
	[want_obj_externs="no"])
if test "$want_obj_externs" != "no" ; then
  PD_OBJECT_EXTERNALS="\
        klatt~\$(EXEEXT) \
	holmes\$(EXEEXT) \
	holmes-feat\$(EXEEXT) \
	phones2holmes\$(EXEEXT) \
	guessphones\$(EXEEXT) \
        number2text\$(EXEEXT) \
	rattshash\$(EXEEXT) \
	rattstok\$(EXEEXT) \
	toupper\$(EXEEXT) \
	spellout\$(EXEEXT)"
  want_shameless_plugs="yes"
fi
AC_SUBST(PD_OBJECT_EXTERNALS)


dnl
dnl enable shameless plugs?
dnl 
AC_ARG_ENABLE([shameless-plugs],
	AC_HELP_STRING([--enable-shameless-plugs],
	               [Report library objects verbosely at library load-time (default=no)]),
	[want_shameless_plugs="$enableval"])
if test "$want_shameless_plugs" == "yes" ; then
  AC_DEFINE(RATTS_SHAMELESS,1,
	[Define this to report library objects verbosely at library load-time.])
fi



dnl
dnl pd-directory/ies
dnl 
AC_ARG_WITH(pd-dir,
	AC_HELP_STRING([--with-pd-dir=DIR], [PD base directory (default=PREFIX/pd)]),
	[pddir="$withval"],
	[pddir="\${prefix}/pd"])
pddocdir="${pddir}/doc/5.reference"
AC_SUBST(pddir)
AC_SUBST(pddocdir)



AC_ARG_WITH(pd-include,
	AC_HELP_STRING([--with-pd-include=DIR], [PD include directory (default=NONE)]),
	[pdincludedir="$withval"],
	[pdincludedir=""])
if test -n "$pdincludedir" ; then
  IFLAGS="$IFLAGS -I$pdincludedir"
fi
AC_SUBST(pdincludedir)

AC_ARG_WITH(pd-extdir,
	AC_HELP_STRING([--with-pd-extdir=DIR], [Directory for PD externals (default=PDDIR/externs)]),
	[pdexternsdir="$withval"],
	[pdexternsdir="$pddir/externs"])
AC_SUBST(pdexternsdir)

dnl
dnl Check for m_pd.h
dnl
CPPFLAGS="$CPPFLAGS $IFLAGS"
AC_CHECK_HEADER(m_pd.h,[],
	AC_MSG_WARN([-----------------------------------------------------------------])
	AC_MSG_WARN([could not find PD header file 'm_pd.h' -- things might get ugly.])
	AC_MSG_WARN([-----------------------------------------------------------------]),
	[/* nonempty includes: compile only */])


dnl
dnl debug version?
dnl
AC_MSG_CHECKING([whether we are building a debug version])
AC_ARG_ENABLE([debug],
	AC_HELP_STRING([--enable-debug],[build debug version (default=no)]))
if test "$enable_debug" == "yes" ; then
  AC_MSG_RESULT(yes)
  DEBUG="yes"
  AC_DEFINE(KLATT_DEBUG,1,
	[Define this to include debugging code for the 'klatt~' external.])
  AC_DEFINE(HOLMES_DEBUG,1,
	[Define this to include debugging code for the 'holmes' external.])
else
  AC_MSG_RESULT(no)
  DEBUG="no"
fi
AC_SUBST(DEBUG)



dnl
dnl machine-dependent variables
dnl
LD=ld
if test `uname -s` = Linux; 
then
  LFLAGS="-export_dynamic -shared"
  if test "$DEBUG" == "no"; then
    #OFLAGS="-O6 -funroll-loops -fomit-frame-pointer -finline-limit-10000000"
    OFLAGS="-O6 -funroll-loops -fomit-frame-pointer"
  else
    OFLAGS="-g"
  fi
  PDEXT=pd_linux	
fi

if test `uname -m` = alpha; 
then 
 AFLAGS="-mieee  -mcpu=ev56"; 
 OFLAGS="$CFLAGS"
fi

if test `uname -s` = IRIX64; 
then
  LFLAGS="-n32 -DUNIX -DIRIX -DN32 -woff 1080,1064,1185 \
	-OPT:roundoff=3 -OPT:IEEE_arithmetic=3 -OPT:cray_ivdep=true \
	-shared -rdata_shared"
  OFLAGS="$CFLAGS"
  PDEXT=pd_irix6
fi

if test `uname -s` = IRIX32; 
then
  LFLAGS="-o32 -DUNIX -DIRIX -O2 -shared -rdata_shared"
  OFLAGS="$CFLAGS"
  PDEXT=pd_irix5
fi

dnl
dnl Flags for MacOSX, borrowed from pd-0.35-test16
dnl
if test `uname -s` = Darwin;
then
  LD=cc
  LFLAGS="-bundle -undefined suppress  -flat_namespace"
  PDEXT=pd_darwin
  DFLAGS="$DFLAGS -DMACOSX"

  if test "$DEBUG" == "no"; then
    OFLAGS="-O2"
  else
    OFLAGS="-g"
  fi
fi

dnl
dnl restore user's CFLAGS
dnl
CFLAGS="$UCFLAGS"
CPPFLAGS="$UCPPFLAGS"

AC_OUTPUT(config/Makefile src/Makefile dict/Makefile Makefile)
