AC_INIT(fjbtndrv, 2.3.2, [http://fjbtndrv.sourceforge.net])
AC_PREREQ([2.57])
AM_INIT_AUTOMAKE([gnu 1.9])

AM_CONFIG_HEADER(config.h)
AC_SUBST(CFLAGS)
AC_SUBST(CPPFLAGS)

AC_PROG_CC
AM_PROG_CC_STDC
AC_PROG_CPP
AC_PROG_CXX
AC_GNU_SOURCE
AC_PROG_INSTALL
#alge
AM_PROG_CC_C_O


AC_HEADER_STDC

AM_ICONV
AM_GNU_GETTEXT([external])
AM_GNU_GETTEXT_VERSION([0.16.1])

PKG_CHECK_MODULES(XRANDR, [x11 xrandr])
PKG_CHECK_MODULES(XINPUT, [x11 xi xext xtst])
AC_SUBST(X11_CFLAGS)
AC_SUBST(X11_LIBS)

PKG_CHECK_MODULES(HAL, [hal >= 0.5.8])
AC_SUBST(HAL_CFLAGS)
AC_SUBST(HAL_LIBS)

AC_ARG_ENABLE([kernel-module],
  AS_HELP_STRING([--disable-kernel-module],
    [Disable building the kernel module (Default: enabled)]),
  [enable_kernel_module=$enableval], [enable_kernel_module=yes])
AM_CONDITIONAL(BUILD_KERNEL_MODULE, [test x$enable_kernel_module = xyes])

AC_ARG_ENABLE([xosd],
  AS_HELP_STRING([--disable-xosd],
    [Disable OSD support (Default: auto)]),
  [enable_xosd=$enableval], [enable_xosd=auto])
if test x$enable_xosd != xno; then
  AM_PATH_LIBXOSD([has_xosd=yes], [has_xosd=no])
  if test x$enable_xosd = xyes -a x$has_xosd != xyes; then
    AC_MSG_ERROR([xosd library not found])
  fi
  enable_xosd=$has_xosd
fi
if test x$enable_xosd = xyes; then
  AC_DEFINE(ENABLE_XOSD, [], [enable osd support])
fi
AM_CONDITIONAL(HAVE_XOSD, [test x$enable_xosd = xyes])

AC_ARG_ENABLE([debug],
  AS_HELP_STRING([--enable-debug],
    [Enable debug output (Default: disabled)]),
  [enable_debug=$enableval], [enable_debug=no])
if test x$enable_debug = xyes; then
  AC_DEFINE(DEBUG, [], [debug output])
fi

AC_ARG_ENABLE([fscd],
  AS_HELP_STRING([--disable-fscd],
    [Don't build and install fscd, but fscrotd (Default: enabled)]),
  [enable_fscd=$enableval], [enable_fscd=yes])
AM_CONDITIONAL(BUILD_FSCD, [test x$enable_fscd = xyes])

AC_ARG_WITH(script-dir,
  AS_HELP_STRING([--with-script-dir=dir],
                 [location of the helper scripts (Default: LIBDIR/fjbtndrv)]),
  scriptdir="$withval",
  scriptdir="${libdir}/fjbtndrv")
AC_SUBST(scriptdir)

AC_ARG_WITH(repeat-rate,
  AS_HELP_STRING([--with-repeat-rate=rate],
                 [repeat rate for autorepeat (Default: 16)]),
  repeat_rate=$withval,
  repeat_rate=16)
if test x$repeat_rate != xno; then
  AC_DEFINE_UNQUOTED(REPEAT_RATE, [$repeat_rate], [autorepeat rate])
fi

AC_ARG_WITH(repeat-delay,
  AS_HELP_STRING([--with-repeat-delay=msec],
                 [delay befor autorepeat (Default: 700)]),
  repeat_delay=$withval,
  repeat_delay=700)
if test x$repeat_rate != xno; then
  if test x$repeat_delay = xno; then
    repeat_delay=0
  fi
  AC_DEFINE_UNQUOTED(REPEAT_DELAY, [$repeat_delay], [autorepeat delay])
fi

AC_ARG_WITH(sticky-timeout,
  AS_HELP_STRING([--with-sticky-timeout=msec],
                 [timeout for sticky modification keys (Default: 1400)]),
  sticky_timeout=$withval,
  sticky_timeout=1400)
if test x$sticky_timeout != xno; then
  AC_DEFINE_UNQUOTED(STICKY_TIMEOUT, [$sticky_timeout], [sticky timeout])
fi

AC_ARG_ENABLE([brightness-keys],
  AS_HELP_STRING([--disable-brightness-keys],
    [Don't handle the brightness keys (Default: enabled)]),
  [enable_brightness_keys=$enableval], [enable_brightness_keys=yes])
AC_ARG_ENABLE([brightness-control],
  AS_HELP_STRING([--disable-brightness-control],
    [Disable brightness handling completely (Default: enabled)]),
  [enable_brightness_control=$enableval], [enable_brightness_control=yes])
if test x$enable_brightness_control = xyes; then
  AC_DEFINE(BRIGHTNESS_CONTROL, [], [brightness control])
else
  enable_brightness_keys=no
fi
if test x$enable_brightness_keys = xyes; then
  AC_DEFINE(BRIGHTNESS_KEYS, [], [handle brightness up/down keys])
fi

AC_CONFIG_FILES([
  Makefile
  src/Makefile
  po/Makefile.in
  contrib/Makefile
])

AC_OUTPUT

echo "

  F J B T N D R V

  Copyright (C) 2006-2011  Robert Gerlach

  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation; either version 2 of the License, or
  (at your option) any later version.

  See file COPYING for more details.


        prefix:         ${prefix}
        debug:          ${enable_debug}
        osd support:    ${enable_xosd}

        autorepeat:     ${repeat_rate} chars/s after a ${repeat_delay}ms delay
        sticky keys:    ${sticky_timeout}ms

  Type 'make' to build and then 'sudo make install' to install fjbtndrv tools.
"
