AC_PREREQ(2.52)
AC_INIT(liboobs, 3.0.0, http://bugzilla.gnome.org/enter_bug.cgi?product=gnome-system-tools)
AC_CONFIG_SRCDIR(oobs/oobs-session.c)
AM_INIT_AUTOMAKE(AC_PACKAGE_NAME, AC_PACKAGE_VERSION)
m4_ifdef([AM_SILENT_RULES],[AM_SILENT_RULES([yes])])

AM_CONFIG_HEADER(config.h)

AM_MAINTAINER_MODE

AM_PROG_LIBTOOL

# Sets GLIB_GENMARSHAL and GLIB_MKENUMS
AM_PATH_GLIB_2_0()

AC_ISC_POSIX
AC_PROG_CC
AM_PROG_CC_STDC
AC_HEADER_STDC
AC_PROG_INSTALL
AC_PROG_MAKE_SET

# libtool versioning
#
# See http://sources.redhat.com/autobook/autobook/autobook_91.html#SEC91 for details
#
LT_CURRENT=5
LT_REVISION=1
LT_AGE=0
AC_SUBST(LT_CURRENT)
AC_SUBST(LT_REVISION)
AC_SUBST(LT_AGE)

GLIB_REQUIRED=2.14.0
DBUS_REQUIRED=0.70
STB_REQUIRED=2.10.1
HAL_REQUIRED=0.5.9

dnl set gettext stuff

GETTEXT_PACKAGE=liboobs
AC_SUBST(GETTEXT_PACKAGE)
AC_DEFINE_UNQUOTED(GETTEXT_PACKAGE,"$GETTEXT_PACKAGE",[The name of the gettext domain])

dnl Check for gtk-doc
GTK_DOC_CHECK([1.25])

dnl =====================================================
dnl required packages detection
dnl =====================================================
PKG_CHECK_MODULES(OOBS, [
		  dbus-glib-1 >= $DBUS_REQUIRED
		  glib-2.0    >= $GLIB_REQUIRED
		  gobject-2.0 >= $GLIB_REQUIRED
		  system-tools-backends-2.0 >= $STB_REQUIRED
		  ])

OOBS_CFLAGS="-DDBUS_API_SUBJECT_TO_CHANGE $OOBS_CFLAGS"

AC_SUBST(OOBS_LIBS)
AC_SUBST(OOBS_CFLAGS)

dnl =====================================================
dnl HAL detection
dnl =====================================================
PKG_CHECK_MODULES(HAL, hal >= $HAL_REQUIRED, have_hal=yes, have_hal=no)

AC_ARG_WITH([hal],
        [AS_HELP_STRING([--with-hal],
        [Enable HAL support.])],
        [with_hal="$withval"],[with_hal="no"])

if test x"$have_hal" = x"yes" && test x"$with_hal" = x"yes"; then
        AC_DEFINE(WITH_HAL,,"Using HAL")
else
        if test x"$with_hal" = x"yes"; then
                AC_MSG_ERROR([HAL Library requirements ($HAL_REQUIRED)
not met; consider using --with-hal=no option, or adjusting the PKG_CONFIG_PATH
environment variable if your libraries are in a nonstandard prefix so pkg-config
can find them.])
        else
                AC_MSG_WARN([HAL Library requirements ($HAL_REQUIRED) not met; disabling HAL support.])
        fi
fi

AC_SUBST(HAL_LIBS)
AC_SUBST(HAL_CFLAGS)

AC_CHECK_LIB(crypt, crypt, , [AC_MSG_ERROR(crypt library is required.)])
AC_CHECK_HEADER(crypt.h, AC_DEFINE(HAVE_CRYPT_H, "", [whether it has crypt function]))

AC_CHECK_HEADER(utmpx.h,,AC_MSG_ERROR([utmpx.h not found]))

AC_MSG_CHECKING(whether rtnetlink exists)
AC_TRY_CPP([
#include <sys/types.h>
#include <sys/socket.h>
#include <linux/netlink.h>
#include <linux/rtnetlink.h>
], have_rtnetlink=yes, have_rtnetlink=no)

AC_MSG_RESULT($have_rtnetlink)
AM_CONDITIONAL(HAVE_RTNETLINK, test x$have_rtnetlink = xyes)

#### gcc warning flags (taken from PolicyKit-gnome)

if test "x$GCC" = "xyes"; then
  changequote(,)dnl
  case " $CFLAGS " in
  *[\ \	]-Wall[\ \	]*) ;;
  *) CFLAGS="$CFLAGS -Wall" ;;
  esac

  case " $CFLAGS " in
  *[\ \	]-Wchar-subscripts[\ \	]*) ;;
  *) CFLAGS="$CFLAGS -Wchar-subscripts" ;;
  esac

  case " $CFLAGS " in
  *[\ \	]-Wmissing-declarations[\ \	]*) ;;
  *) CFLAGS="$CFLAGS -Wmissing-declarations" ;;
  esac

  case " $CFLAGS " in
  *[\ \	]-Wnested-externs[\ \	]*) ;;
  *) CFLAGS="$CFLAGS -Wnested-externs" ;;
  esac

  case " $CFLAGS " in
  *[\ \	]-Wpointer-arith[\ \	]*) ;;
  *) CFLAGS="$CFLAGS -Wpointer-arith" ;;
  esac

  case " $CFLAGS " in
  *[\ \	]-Wcast-align[\ \	]*) ;;
  *) CFLAGS="$CFLAGS -Wcast-align" ;;
  esac

  case " $CFLAGS " in
  *[\ \	]-Wsign-compare[\ \	]*) ;;
  *) CFLAGS="$CFLAGS -Wsign-compare" ;;
  esac

  case " $CFLAGS " in
  *[\ \	]-Wformat[\ \	]*) ;;
  *) CFLAGS="$CFLAGS -Wformat" ;;
  esac

  case " $CFLAGS " in
  *[\ \	]-Wformat-security[\ \	]*) ;;
  *) CFLAGS="$CFLAGS -Wformat-security" ;;
  esac

  changequote([,])dnl
fi

AC_OUTPUT([
Makefile
doc/Makefile
doc/reference/Makefile
oobs/Makefile
liboobs-1.pc
])

echo "configuration:
        use netlink: ${have_rtnetlink}
        use HAL:     ${have_hal}
        doc build:   ${enable_gtk_doc}
"
