dnl Process this file with autoconf to produce a configure script. 
AC_INIT([denemo], [0.8.22], [denemo-devel@gnu.org])
AC_CONFIG_SRCDIR([src/main.c])
AM_INIT_AUTOMAKE([tar-pax]) 
dnl AM_INIT_AUTOMAKE([foreign -Wall -Werror gnu tar-pax])
dnl AC_CANONICAL_SYSTEM
AM_CONFIG_HEADER(config.h)

AC_CONFIG_MACRO_DIR([m4])
AM_MAINTAINER_MODE
dnl AM_BINRELOC
dnl ALL_LINGUAS="es fr sv"
AM_GNU_GETTEXT([external])
AM_GNU_GETTEXT_VERSION
AC_PROG_LN_S
AC_PROG_MKDIR_P
AM_PROG_CC_C_O

dnl Checks for programs.
AC_PROG_CPP
AC_PROG_CXX
AC_PROG_INSTALL
AC_PROG_YACC
AM_PROG_LEX
GUILE_FLAGS

AM_PROG_LIBTOOL

PKG_CHECK_MODULES(GTK2, gtk+-2.0 >= 2.0.3)
CFLAGS="$CFLAGS $GTK2_CFLAGS"
LIBS="$GTK2_LIBS"

PKG_CHECK_MODULES(GUILE, guile-1.8 >= 1.8)
LIBS="$LIBS $GUILE_LIBS"
CFLAGS="$CFLAGS $GUILE_CFLAGS"

PKG_CHECK_MODULES(XML2, libxml-2.0 >= 2.3.10)
CFLAGS="$CFLAGS $XML2_CFLAGS"
LIBS="$LIBS $XML2_LIBS"

PKG_CHECK_MODULES(GTKSOURCEVIEW, gtksourceview-2.0 >= 2.0)
CFLAGS="$CFLAGS $GTKSOURCEVIEW_CFLAGS"
LIBS="$LIBS $GTKSOURCEVIEW_LIBS"

PKG_CHECK_MODULES(RSVG, librsvg-2.0 >= 2.0)
CFLAGS="$CFLAGS $RSVG_CFLAGS"
LIBS="$LIBS $RSVG_LIBS"

AC_ARG_ENABLE(
  jack,
  AC_HELP_STRING([--enable-jack], [use JACK @<:@default=no@:>@]),
  [
    if test "x$enableval" != "xno"; then
      usejack=yes
    fi
  ])

if test "x$usejack" = "xyes"; then
  PKG_CHECK_MODULES(JACK, jack >= 0.102.0)
  CFLAGS="$CFLAGS -D_HAVE_JACK_ $JACK_CFLAGS"
  LIBS="$LIBS -D_HAVE_JACK_ $JACK_LIBS"
fi

AC_ARG_ENABLE(
  fluidsynth,
  AC_HELP_STRING([--enable-fluidsynth], [use FLUIDSYNTH @<:@default=yes@:>@]),
  [ 
    if test "x$enableval" != "xno"; then
      usefluidsynth=yes
    fi 
  ], [ usefluidsynth=yes ])

if test "x$usefluidsynth" = "xyes"; then
  PKG_CHECK_MODULES(FLUIDSYNTH, fluidsynth >= 1.0.8)
  CFLAGS="$CFLAGS -D_HAVE_FLUIDSYNTH_ $FLUIDSYNTH_CFLAGS"
  LIBS="$LIBS -D_HAVE_FLUIDSYNTH_ $FLUIDSYNTH_LIBS"
fi

AC_ARG_ENABLE(
  portaudio,
  AC_HELP_STRING([--enable-portaudio], [use PORTAUDIO @<:@default=yes@:>@]),
  [ 
    if test "x$enableval" != "xno"; then
      useportaudio=yes
    fi 
  ], [ useportaudio=yes ])

if test "x$useportaudio" = "xyes"; then
  PKG_CHECK_MODULES(PORTAUDIO, portaudio-2.0 >= 19)
  CFLAGS="$CFLAGS -D_HAVE_PORTAUDIO_ $PORTAUDIO_CFLAGS"
  dnl CFLAGS="$CFLAGS $PORTAUDIO_CFLAGS"
  LIBS="$LIBS $PORTAUDIO_LIBS"

  PKG_CHECK_MODULES(LIBAUBIO, aubio >= 0.3.2)
  CFLAGS="$CFLAGS $LIBAUBIO_CFLAGS"
  LIBS="$LIBS $LIBAUBIO_LIBS"

  PKG_CHECK_MODULES(FFTW, fftw3 >= 3.1.2)
  CFLAGS="$CFLAGS $FFTW_CFLAGS"
  LIBS="$LIBS $FFTW_LIBS"

  PKG_CHECK_MODULES(samplerate, samplerate >= 0.1.2)
  CFLAGS="$CFLAGS $samplerate_CFLAGS"
  LIBS="$LIBS $samplerate_LIBS"
fi

dnl Options for configuration
build_debug=no
AC_ARG_ENABLE(
  debug,
  AC_HELP_STRING([--enable-debug], [enable debug code @<:@default=no@:>@]),
  [
    if test "x$enableval" != "xno"; then
      build_debug=yes
      CFLAGS="$CFLAGS -DDEBUG -g"
      CXXFLAGS="$CXXFLAGS -DDEBUG -g"
    fi
  ])


dnl Memory debugging
mem_debug=no
AC_ARG_ENABLE(
  mem,
  AC_HELP_STRING([--enable-mem], [enable memory debugging @<:@default=no@:>@]),
  [
    if test "x$enableval" != "xno"; then
      mem_debug=yes
    fi
  ])
if test "x$mem_debug" = "xyes"; then LDFLAGS="$LDFLAGS -lefence"; fi


dnl Build documentation
build_doc=no
AC_ARG_ENABLE(
  doc,
  AC_HELP_STRING(
    [--enable-doc],[enable documentation build @<:@default=no@:>@]),
  [
    if test "x$enableval" != "xno"; then
      build_doc=yes
    fi
  ])
AM_CONDITIONAL(DENEMO_BUILD_DOC,[test "$build_doc" = "yes"])


dnl Checks for header files.

AC_CHECK_HEADERS(sys/soundcard.h)
AC_CHECK_HEADERS(errno.h)
AC_CHECK_HEADERS(getopt.h sys/wait.h wait.h sys/time.h sys/resource.h)

AC_TRY_COMPILE(
  [#include <signal.h>], [int mysignal = SIGCHLD;],
  [AC_DEFINE(HAVE_SIGCHLD, 1, [Define to 1 if SIGCHLD signal is available])])

AC_TRY_LINK(
  [#include <stdio.h>],
  [
    FILE * fp;
    flockfile (fp);
    ftrylockfile (fp);
    funlockfile (fp);
  ],
  [AC_DEFINE(HAVE_FILE_LOCKS, 1, [Define to 1 if file locking is available])])

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

dnl Checks for library functions.

dnl Set PACKAGE_LOCALE_DIR in config.h.


if test "${prefix}" = "NONE"; then
  prefix=${ac_default_prefix}
  AC_SUBST(prefix)
fi

pkgdatadir=${datadir}/${PACKAGE}
PACKAGE_DATA_DIR=${datadir}/${PACKAGE}
AC_SUBST(pkgdatadir)
AC_SUBST(PACKAGE_DATA_DIR)
 
dnl
dnl Force sysconfdir=/etc if no --sysconfdir=xxx passed
dnl
if test $sysconfdir = $\{prefix\}/etc; then
  sysconfdir=/etc/${PACKAGE}
else 
  sysconfdir=$sysconfdir/${PACKAGE}    
fi
AC_SUBST(sysconfdir)

dnl Set PACKAGE_SOURCE_DIR in config.h.
packagesrcdir=`cd $srcdir && pwd`
AC_DEFINE_UNQUOTED(
  PACKAGE_SOURCE_DIR, "${packagesrcdir}", [set package source dir])

dnl Gettext stuff

AC_SUBST(CFLAGS)
AC_SUBST(CPPFLAGS)
AC_SUBST(LDFLAGS)


AC_OUTPUT(
[
  m4/Makefile 
  Makefile 
  denemo.spec
  src/Makefile 
  pixmaps/Makefile 
  doc/Makefile
  doc/transformations/Makefile
  doc/images/Makefile
  actions/Makefile
  examples/Makefile
  templates/Makefile
  po/Makefile.in
  fonts/Makefile
  soundfonts/Makefile
  libsmf/Makefile
])
