AC_PREREQ([2.63])
AC_INIT([ostree], [2013.5], [walters@verbum.org])
AC_CONFIG_HEADER([config.h])
AC_CONFIG_MACRO_DIR([m4])
AC_CONFIG_AUX_DIR([build-aux])

AM_INIT_AUTOMAKE([1.11 -Wno-portability foreign no-define tar-ustar no-dist-gzip dist-xz])
AM_MAINTAINER_MODE([enable])
AM_SILENT_RULES([yes])
AC_USE_SYSTEM_EXTENSIONS
AC_SYS_LARGEFILE

AC_PROG_CC
AM_PROG_CC_C_O

changequote(,)dnl
if test "x$GCC" = "xyes"; then
  WARN_CFLAGS="-Wall -Wstrict-prototypes -Werror=missing-prototypes \
		-Werror=implicit-function-declaration \
		-Werror=pointer-arith -Werror=init-self -Werror=format=2 \
		-Werror=format-security \
		-Werror=missing-include-dirs -Werror=aggregate-return \
		-Werror=declaration-after-statement"
fi
changequote([,])dnl
AC_SUBST(WARN_CFLAGS)

# Initialize libtool
LT_PREREQ([2.2.4])
LT_INIT([disable-static])

OSTREE_FEATURES=""
AC_SUBST([OSTREE_FEATURES])

AC_ARG_ENABLE(installed_tests,
              AS_HELP_STRING([--enable-installed-tests],
                             [Install test programs (default: no)]),,
              [enable_installed_tests=no])
AM_CONDITIONAL(BUILDOPT_INSTALL_TESTS, test x$enable_installed_tests = xyes)

AC_CHECK_HEADER([attr/xattr.h],,[AC_MSG_ERROR([You must have attr/xattr.h from libattr])])

PKG_PROG_PKG_CONFIG

AC_ARG_ENABLE(embedded-dependencies,
	    AS_HELP_STRING([--enable-embedded-dependencies], [Use embedded GLib and libsoup copies]),,
	    enable_embedded_dependencies=no)
AM_CONDITIONAL(BUILD_EMBEDDED_DEPENDENCIES, test x$enable_embedded_dependencies = xyes)
AS_IF([test x$enable_embedded_dependencies = xyes], [
  echo "NOTICE: Embedded dependencies (GLib and libsoup) enabled"
  with_soup=yes
], [
  GIO_DEPENDENCY="gio-unix-2.0 >= 2.34.0"
  PKG_CHECK_MODULES(OT_DEP_GIO_UNIX, $GIO_DEPENDENCY)

  SOUP_DEPENDENCY="libsoup-2.4 >= 2.39.1"
  AC_ARG_WITH(soup,
	    AS_HELP_STRING([--with-soup], [Use libsoup @<:@default=yes@:>@]),
	    [], [with_soup=check])
  AS_IF([test x$with_soup != xno ], [
    AC_MSG_CHECKING([for $SOUP_DEPENDENCY])
    PKG_CHECK_EXISTS($SOUP_DEPENDENCY, have_soup=yes, have_soup=no)
    AC_MSG_RESULT([$have_soup])
    AS_IF([ test x$have_soup = xno && test x$with_soup != xcheck], [
       AC_MSG_ERROR([libsoup is enabled but could not be found])
    ])
    AS_IF([test x$have_soup = xyes], [
	PKG_CHECK_MODULES(OT_DEP_SOUP, $SOUP_DEPENDENCY)
        AC_DEFINE(HAVE_LIBSOUP, 1, [Define if we have libsoup.pc])
	with_soup=yes
    ], [
	with_soup=no
    ])
  ], [ with_soup=no ])
])
if test x$with_soup != xno; then OSTREE_FEATURES="$OSTREE_FEATURES +libsoup"; fi
AM_CONDITIONAL(USE_LIBSOUP, test x$with_soup != xno)

m4_ifdef([GOBJECT_INTROSPECTION_CHECK], [
  GOBJECT_INTROSPECTION_CHECK([1.34.0])
])
AM_CONDITIONAL(BUILDOPT_INTROSPECTION, test x$found_introspection = xyes)

LIBARCHIVE_DEPENDENCY="libarchive >= 2.8.0"

GTK_DOC_CHECK([1.15], [--flavour no-tmpl])
AC_PATH_PROG([XSLTPROC], [xsltproc])

AC_ARG_WITH(libarchive,
	    AS_HELP_STRING([--without-libarchive], [Do not use libarchive]),
	    :, with_libarchive=maybe)

AS_IF([ test x$with_libarchive != xno ], [
    AC_MSG_CHECKING([for $LIBARCHIVE_DEPENDENCY])
    PKG_CHECK_EXISTS($LIBARCHIVE_DEPENDENCY, have_libarchive=yes, have_libarchive=no)
    AC_MSG_RESULT([$have_libarchive])
    AS_IF([ test x$have_libarchive = xno && test x$with_libarchive != xmaybe ], [
       AC_MSG_ERROR([libarchive is enabled but could not be found])
    ])
    AS_IF([ test x$have_libarchive = xyes], [
        AC_DEFINE(HAVE_LIBARCHIVE, 1, [Define if we have libarchive.pc])
	PKG_CHECK_MODULES(OT_DEP_LIBARCHIVE, $LIBARCHIVE_DEPENDENCY)
	with_libarchive=yes
    ], [
	with_libarchive=no
    ])
], [ with_libarchive=no ])
if test x$with_libarchive != xno; then OSTREE_FEATURES="$OSTREE_FEATURES +libarchive"; fi
AM_CONDITIONAL(USE_LIBARCHIVE, test $with_libarchive != no)

AC_ARG_WITH(dracut,
            AS_HELP_STRING([--with-dracut],
                           [Install dracut module (default: no)]),,
              [with_dracut=no])
AM_CONDITIONAL(BUILDOPT_DRACUT, test x$with_dracut = xyes)

AS_IF([test "x$with_dracut" = "xyes"], [
  AC_ARG_WITH([systemdsystemunitdir],
              AS_HELP_STRING([--with-systemdsystemunitdir=DIR], [Directory for systemd service files]),
              [],
              [with_systemdsystemunitdir=$($PKG_CONFIG --variable=systemdsystemunitdir systemd)])
  AS_IF([test "x$with_systemdsystemunitdir" != "xno"], [
    AC_SUBST([systemdsystemunitdir], [$with_systemdsystemunitdir])
  ])
])

AC_CONFIG_FILES([
Makefile
embedded-dependencies/Makefile
doc/Makefile
src/libostree/ostree-1.pc
])
AC_OUTPUT

echo "
    OSTree $VERSION
    ===============


    embedded dependencies:                        $enable_embedded_dependencies
    introspection:                                $found_introspection
    libsoup (retrieve remote HTTP repositories):  $with_soup
    libarchive (parse tar files directly):        $with_libarchive
    documentation:                                $enable_gtk_doc
    dracut:                                       $with_dracut"
AS_IF([test "x$with_dracut" = "xyes"], [
    echo "    systemd unit dir:                             $with_systemdsystemunitdir"
])
echo ""
