# require autoconf 2.52
AC_PREREQ(2.52)

AC_INIT(gnomine)

AM_CONFIG_HEADER(config.h)
AM_INIT_AUTOMAKE(gnome-games, 2.4.0)

AC_PROG_INTLTOOL

AM_MAINTAINER_MODE

SCROLLKEEPER_REQUIRED=0.3.8
AC_SUBST(SCROLLKEEPER_REQUIRED)

AC_ISC_POSIX
AC_PROG_CC
AC_STDC_HEADERS
AM_PROG_LIBTOOL

GNOME_CHECK_CXX

GAMES_CHECK_GUILE

LIBGNOMEUI_REQUIRED=1.105.0
LIBGNOME_REQUIRED=1.105.0

PKG_CHECK_MODULES(GNOME_GAMES, libgnome-2.0 >= $LIBGNOME_REQUIRED libgnomeui-2.0 >= $LIBGNOMEUI_REQUIRED gconf-2.0 >= 1.1.5 gnome-vfs-module-2.0 >= 1.9.11)
AC_SUBST(GNOME_GAMES_CFLAGS)
AC_SUBST(GNOME_GAMES_LIBS)

PKG_CHECK_MODULES(ESD, esound)
AC_SUBST(ESD_CFLAGS)
AC_SUBST(ESD_LIBS)
if test "x$ESD_CFLAGS" = "x" ; then
	CFLAGS="$CFLAGS -DNO_ESD"
fi

GETTEXT_PACKAGE=gnome-games
AC_SUBST(GETTEXT_PACKAGE)
AC_DEFINE_UNQUOTED(GETTEXT_PACKAGE,"$GETTEXT_PACKAGE", [The gettext package name])
ALL_LINGUAS="am ar az be bg bn ca cs cy da de el en_GB es et eu fa fi fr ga gl he hi hu id it ja ko lt lv mk ml mn ms nl nn no pl pt pt_BR ro ru sk sl sr sr@Latn sv tr uk vi wa zh_CN zh_TW"
AM_GLIB_GNU_GETTEXT
# Since there is controversy over using it, we will check for it.
AC_CHECK_FUNCS(ngettext)

GNOME_COMPILE_WARNINGS(yes) 
GNOME_CXX_WARNINGS(yes)

CFLAGS="$CFLAGS $GNOME_GAMES_CFLAGS $WARN_CFLAGS"

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

AM_GCONF_SOURCE_2
AC_PATH_PROG(GCONFTOOL, gconftool-2)

## Begin tests for scrollkeeper
AC_PATH_PROG(SCROLLKEEPER_CONFIG, scrollkeeper-config,no)
if test x$SCROLLKEEPER_CONFIG = xno; then
  AC_MSG_ERROR(Couldn't find scrollkeeper-config, please install the scrollkeeper packaga)
fi

sys_dir_h_found=no
old_CPPFLAGS="$CPPFLAGS"
UCB_CFLAGS=
AC_CHECK_HEADER(sys/dir.h, [sys_dir_h_found=yes],
  [AC_MSG_CHECKING([for sys/dir.h in /usr/ucbinclude or /usr/ucblib/sparcv9])
   CPPFLAGS="-I /usr/ucbinclude -I /usr/ucblib/sparcv9"
   AC_TRY_COMPILE([#include <sys/dir.h>],
     [scandir(".", 0, 0, 0);],
     [UCB_CFLAGS="-I/usr/ucbinclude -I/usr/ucblib/sparcv9"
      AC_MSG_RESULT(yes)
      sys_dir_h_found=yes
     ],
     AC_MSG_RESULT(no))
  ])
AC_SUBST(UCB_CFLAGS)

AC_CHECK_HEADERS(sys/dirent.h)

if test x$sys_dir_h_found = xyes; then
  AC_DEFINE(HAVE_SYS_DIR_H,,[System has sys/dir/h])
  AC_MSG_CHECKING([if sys/dir.h defines struct direct or dirent])
  AC_TRY_COMPILE([#include <sys/dir.h>],
    [struct direct *dummy;],
    [AC_MSG_RESULT(direct)
     AC_DEFINE(HAVE_STRUCT_DIRECT,1,[Define if scandir() works with struct direct rather than struct dirent])
    ],
    [AC_TRY_COMPILE([#include <sys/dir.h>],
     [struct dirent *dummy;],
     [AC_MSG_RESULT(dirent)]
     [AC_MSG_RESULT(none)])
    ])
fi
CPPFLAGS="$old_CPPFLAGS"

old_LDFLAGS="$LDFLAGS"
UCB_LDFLAGS=
AC_CHECK_FUNC(scandir, [], [
  LDFLAGS="$LDFLAGS -L/usr/ucblib"
  AC_CHECK_LIB(ucb, scandir,
    [UCB_LDFLAGS="-L/usr/ucblib -lucb"], [
      LDFLAGS="$old_LDFLAGS -L/usr/ucblib/sparcv9"
      AC_CHECK_LIB(ucb, scandir,
	[UCB_LDFLAGS="-L/usr/ucblib/sparcv9 -lucb"],
        AC_MSG_ERROR([No implementation of scandir found])
      )
    ]
  )
])
LDFLAGS="$old_LDFLAGS"
AC_SUBST(UCB_LDFLAGS)

if test "x${prefix}" = "xNONE"; then
   AC_DEFINE_UNQUOTED(GNOME_ICONDIR, "${ac_default_prefix}/share/pixmaps", [Pix
map directory])
else
   AC_DEFINE_UNQUOTED(GNOME_ICONDIR, "${prefix}/share/pixmaps", [Pixmap directo
ry])
fi

AC_ARG_ENABLE(setgid,
  [  --disable-setgid           Disable the use of setgid binaries],
  [case "${enableval}" in
    yes) setgid=true ;;
    no)  setgid=false ;;
    *) AC_MSG_ERROR(bad value ${enableval} for --disable-setgid) ;;
   esac],[setgid=true])
AC_SUBST(setgid)

AC_ARG_WITH(scores-group,
[  --with-scores-group=group    Group for the high score tables and binaries],
scores_group="$withval",scores_group="games")
AC_SUBST(scores_group)
AC_ARG_WITH(scores-user,
[  --with-scores-user=user    User for the high score tables],
scores_user="$withval",scores_user="games")
AC_SUBST(scores_user)

scoredir='${localstatedir}/games'
AC_SUBST(scoredir)

AC_OUTPUT([
gnome-games.spec
Makefile
po/Makefile.in
libgames-support/Makefile
blackjack/Makefile
blackjack/data/Makefile
blackjack/help/Makefile
blackjack/help/C/Makefile
blackjack/pixmaps/Makefile
blackjack/src/Makefile
gnect/Makefile
gnect/src/Makefile
gnect/data/Makefile
gnect/pixmaps/Makefile
gnect/help/Makefile
gnect/help/C/Makefile
gnomine/Makefile
gnomine/help/Makefile
gnomine/help/C/Makefile
gnome-stones/Makefile
gnome-stones/graphics/Makefile
gnome-stones/objects/Makefile
gnome-stones/sounds/Makefile
gnome-stones/help/Makefile
gnome-stones/help/C/Makefile
same-gnome/Makefile
same-gnome/help/Makefile
same-gnome/help/C/Makefile
mahjongg/Makefile
mahjongg/help/Makefile
mahjongg/help/C/Makefile
gtali/Makefile
gtali/pix/Makefile
gtali/help/Makefile
gtali/help/C/Makefile
gtali/help/da/Makefile
iagno/Makefile
iagno/sounds/Makefile
iagno/help/Makefile
iagno/help/C/Makefile
gataxx/Makefile
gataxx/sounds/Makefile
gataxx/help/Makefile
gataxx/help/C/Makefile
gnotravex/Makefile
gnotravex/help/Makefile
gnotravex/help/C/Makefile
gnotski/Makefile
gnotski/help/Makefile
gnotski/help/C/Makefile
glines/Makefile
glines/help/Makefile
glines/help/C/Makefile
gdk-card-image/Makefile
gnometris/Makefile
gnometris/pix/Makefile
gnobots2/Makefile
gnobots2/help/Makefile
gnobots2/help/C/Makefile
gnobots2/help/da/Makefile
gnobots2/help/es/Makefile
gnobots2/help/it/Makefile
gnibbles/Makefile
gnibbles/help/Makefile
gnibbles/help/C/Makefile
gnibbles/sounds/Makefile
aisleriot/Makefile
aisleriot/help/Makefile
aisleriot/help/C/Makefile
])

echo "
Configuration:

	Source code location:	  	   ${srcdir}
	Compiler:		  	   ${CC}

	Compile Gnometris
	(Have c++ compiler):		   ${ac_cv_prog_cxx_works}
	Compile AisleRiot (Have guile):	   ${ac_cv_guile_found}

        Use setgid binaries                $setgid
        Scores user                        $scores_user
        Scores & setgid group              $scores_group
"
if grep -q "$scores_group:" /etc/group ; then 
:;
else
echo
echo "Warning: The $scores_group group does not exist. Installation will"
echo "         succeed, but high score logging will not work. To specify a"
echo "         different group use the --with-scores-group option."
echo
fi

libgnomeprefix=`pkg-config libgnome-2.0 --variable=prefix`
if test x$libgnomeprefix = x$prefix -o x$libgnomeprefix = x$prefix/ ; then
:;
else
echo "Warning: This package is not being installed with the same prefix"
echo "         as libgnome. This may lead to problems with the high"
echo "         score tables not being found correctly. The solution"
echo "         is to use the --localstatedir option. For example,"
echo "         Red Hat 9 needs --localstatedir=/var/lib if you are"
echo "         using the default libgnome package since scores are stored"
echo "         in /var/lib/games/."
fi
