AC_INIT(streamtuner, 0.99.99, streamtuner-bugs@nongnu.org)
AC_CONFIG_SRCDIR(src/streamtuner/st-main.c)

AC_PREREQ(2.59)

### command line arguments

ST_ARG_ENABLE(shoutcast, [do not build the SHOUTcast plugin])
ST_ARG_ENABLE(live365, [do not build the Live365 plugin])
ST_ARG_ENABLE(xiph, [do not build the Xiph plugin])
ST_ARG_ENABLE(local, [do not build the Local plugin])
ST_ARG_ENABLE(local-metadata, [disable metadata support in the Local plugin])
ST_ARG_ENABLE(python, [do not build the Python plugin])

ST_ARG_COMPILE_WARNINGS

ST_ARG_ENABLE(regression-tests, [build and run regression tests], no)

### initialization

AM_INIT_AUTOMAKE(foreign)
AM_MAINTAINER_MODE
AM_CONFIG_HEADER(config.h)
AC_PROG_LIBTOOL

if $CONFIG_SHELL ./libtool --features | grep "enable shared" >/dev/null 2>&1; then :; else
	if test "$enable_shared" = no; then
		AC_MSG_ERROR([streamtuner requires shared libraries: do not use --disable-shared])
	else
		AC_MSG_ERROR([streamtuner requires shared libraries but the target system does not support them])
	fi
fi

### i18n

GETTEXT_PACKAGE=AC_PACKAGE_NAME
AC_DEFINE_UNQUOTED(GETTEXT_PACKAGE, "$GETTEXT_PACKAGE", [Define to the gettext package name])
AC_SUBST(GETTEXT_PACKAGE)

ALL_LINGUAS="de fr hu ja pt"
AM_GLIB_GNU_GETTEXT
AM_GLIB_DEFINE_LOCALEDIR(LOCALEDIR)

AC_PROG_INTLTOOL(, no-xml)

### system features

AC_SYS_LARGEFILE

# check for ANSI C headers
AC_HEADER_STDC
if test $ac_cv_header_stdc != yes; then
	AC_MSG_ERROR([ANSI C headers not present])
fi

### build dependencies

AM_PATH_GLIB_2_0(,, [AC_MSG_ERROR([unable to find the GLib library])])

PKG_CHECK_MODULES(GTHREAD, gthread-2.0,, [AC_MSG_ERROR([unable to find the GThread library])])
PKG_CHECK_MODULES(GMODULE, gmodule-2.0,, [AC_MSG_ERROR([unable to find the GModule library])])

AM_PATH_GTK_2_0(2.4.0,, [AC_MSG_ERROR([unable to find the GTK+ library])])

AM_PATH_CURL(7.10.8,, [AC_MSG_ERROR([unable to find the libcurl library])])

if ST_FEATURE_ENABLED(xiph); then
	PKG_CHECK_MODULES(LIBXML, libxml-2.0,, [ST_FEATURE_DISABLE(xiph, [libxml not found])])
fi

if ST_FEATURE_ENABLED(local); then
	if ST_FEATURE_ENABLED(local-metadata); then
		AM_PATH_TAGLIB_C(1.2,, [ST_FEATURE_DISABLE(local-metadata, [TagLib not found])])
	fi
else
	if ST_FEATURE_ENABLED(local-metadata); then
		ST_FEATURE_DISABLE(local-metadata, [not needed], [the Local plugin is disabled])
	fi
fi

if ST_FEATURE_ENABLED(python); then
	AM_PATH_EMBEDDED_PYTHON(2.3,, [ST_FEATURE_DISABLE(python, [Python not found])])
fi
if ST_FEATURE_ENABLED(python); then
	PKG_CHECK_MODULES(PYGTK, pygtk-2.0 >= 2.4.0,, [ST_FEATURE_DISABLE(python, [PyGTK not found])])
fi

GTK_DOC_CHECK([1.0])

### install dependencies

AC_PATH_PROG(SCROLLKEEPER_CONFIG, scrollkeeper-config)
if test -z "$SCROLLKEEPER_CONFIG"; then
	AC_MSG_WARN([unable to find ScrollKeeper: documentation will not be installed])
fi

### Automake conditionals

AM_CONDITIONAL(WITH_SHOUTCAST, [ST_FEATURE_ENABLED(shoutcast)])
AM_CONDITIONAL(WITH_LIVE365, [ST_FEATURE_ENABLED(live365)])
AM_CONDITIONAL(WITH_XIPH, [ST_FEATURE_ENABLED(xiph)])
AM_CONDITIONAL(WITH_LOCAL, [ST_FEATURE_ENABLED(local)])
AM_CONDITIONAL(WITH_PYTHON, [ST_FEATURE_ENABLED(python)])

AM_CONDITIONAL(WITH_DOC, [test -n "$SCROLLKEEPER_CONFIG"])
AM_CONDITIONAL(WITH_REGRESSION_TESTS, [ST_FEATURE_ENABLED(regression-tests)])

### config.h definitions

ST_FEATURE_DEFINE(local-metadata)

### output

AC_CONFIG_FILES(Makefile
		art/Makefile
		data/Makefile
		data/streamtuner.pc
		docs/Makefile
		docs/reference/Makefile
		help/Makefile
		help/C/Makefile
		m4/Makefile
		po/Makefile.in
		src/Makefile
		src/plugins/Makefile
		src/plugins/live365/Makefile
		src/plugins/local/Makefile
		src/plugins/python/Makefile
		src/plugins/shoutcast/Makefile
		src/plugins/xiph/Makefile
		src/sglib/Makefile
		src/sgtk/Makefile
		src/streamtuner/Makefile
		src/tests/Makefile)
AC_OUTPUT

### report

cat <<EOF

$PACKAGE $VERSION is ready to be built.
The following settings will be used:

Installation prefixes
ST_REPORT_ARGS([prefix, exec-prefix])
Installation directories
ST_REPORT_ARGS([bindir, datadir, libdir, includedir])
Features
ST_REPORT_FEATURES([shoutcast, live365, xiph, local, local-metadata, python])
Type "make" to build $PACKAGE $VERSION.
EOF
