dnl ---------------------------------------------------------------------------
dnl Process this file with autoconf to produce a configure script.
dnl $Id$
dnl ---------------------------------------------------------------------------
AC_INIT(src/main.c)
GNP_MAJOR_VERSION=1
GNP_MINOR_VERSION=0
GNP_MICRO_VERSION=8
GNP_VERSION=$GNP_MAJOR_VERSION.$GNP_MINOR_VERSION.$GNP_MICRO_VERSION


dnl ---------------------------------------------------------------------------
dnl for automake:
dnl ---------------------------------------------------------------------------
AUTOMAKE_OPTIONS=no-dependencies
VERSION=$GNP_VERSION
PACKAGE=gnotepad+


dnl ---------------------------------------------------------------------------
dnl Initialize automake now
dnl ---------------------------------------------------------------------------
AM_INIT_AUTOMAKE($PACKAGE, $VERSION)
AC_SUBST(GNP_VERSION)
AC_PREFIX_DEFAULT(/usr/local)


dnl ---------------------------------------------------------------------------
dnl checks for needed compilers
dnl ---------------------------------------------------------------------------
dnl CFLAGS=""
dnl if test x${CFLAGS+set} = xset ; then
dnl   :
dnl else
dnl   CFLAGS="-O2 -g"
dnl fi

AC_PROG_CC
dnl AC_PROG_CXX
dnl AC_PROG_RANLIB

dnl ---------------------------------------------------------------------------
dnl clean compiles
dnl ---------------------------------------------------------------------------
compiler_warnings=yes
AC_ARG_ENABLE(
	warnings,
	[  --disable-warnings      turn OFF gcc compiler warnings (not recommended)],
	[if test $enableval = no; then
		compiler_warnings=no
	fi]
	)

dnl ---------------------------------------------------------------------------
dnl ansi warnings
dnl ---------------------------------------------------------------------------
AC_ARG_ENABLE(
	ansi,
	[  --enable-ansi           turn ON gcc strict ansi checking [default=no]],
	,
	enable_ansi=no)

if test "$ac_cv_prog_CC" = gcc -o "$ac_cv_prog_CC" = g++; then
  if test $compiler_warnings = yes; then
    if echo "$CFLAGS" | grep "\-Wall" > /dev/null 2> /dev/null; then
      CFLAGS="$CFLAGS"
    else
      CFLAGS="$CFLAGS -Wall"
      wall_flag=yes
    fi
    if echo "$CFLAGS" | grep "\-Wmissing-prototypes" > /dev/null 2> /dev/null; then
      CFLAGS="$CFLAGS"
    else
      CFLAGS="$CFLAGS -Wmissing-prototypes"
      missing_proto_flag=yes
    fi

    if test "$wall_flag" = yes -a "$missing_proto_flag" = yes; then
      echo "updating CFLAGS with extra '-Wall -Wmissing-prototypes' options"
    else
      if test "$wall_flag" = yes; then
        echo "updating CFLAGS with extra '-Wall' option"
      else
        if test "$missing_proto_flag" = yes; then
	  echo "updating CFLAGS with extra '-Wmissing-prototypes' option"
	fi
      fi
    fi
  fi

  if test "$enable_ansi" = yes; then
    if echo "$CFLAGS" | grep "\-ansi" > /dev/null 2> /dev/null; then
      CFLAGS="$CFLAGS"
    else
      CFLAGS="$CFLAGS -ansi"
      ansi_flag=yes
    fi

    if echo "$CFLAGS" | grep "\-pedantic" > /dev/null 2> /dev/null; then
      CFLAGS="$CFLAGS"
    else
      CFLAGS="$CFLAGS -pedantic"
      pedantic_flag=yes
    fi

    if test "$ansi_flag" = yes -a "$pedantic_flag" = yes; then
	echo "updating CFLAGS with extra '-ansi -pedantic' options"
    else
      if test "$ansi_flag" = yes; then
	echo "updating CFLAGS with extra '-ansi' option"
      else
        if test "$pedantic_flag" = yes; then
	  echo "updating CFLAGS with extra '-pedantic' option"
	fi
      fi
    fi
  fi
fi



dnl ---------------------------------------------------------------------------
dnl now some other stuff
dnl AC_CANONICAL_HOST  ... needs config.guess
dnl ---------------------------------------------------------------------------
AM_CONFIG_HEADER(config.h)
AM_SANITY_CHECK
dnl AC_PROG_LN_S


dnl ---------------------------------------------------------------------------
dnl check for GTK
dnl ---------------------------------------------------------------------------
AM_PATH_GTK(1.0.5,
            [LIBS="$LIBS $GTK_LIBS"
            CFLAGS="$CFLAGS $GTK_CFLAGS"],
            AC_MSG_ERROR(Cannot find GTK+: Is gtk-config in executable path?))


dnl ---------------------------------------------------------------------------
dnl checks for correctly defined types
dnl ---------------------------------------------------------------------------
AC_TYPE_OFF_T
AC_TYPE_PID_T
AC_TYPE_SIZE_T


dnl ---------------------------------------------------------------------------
dnl checks for header files & functions
dnl ---------------------------------------------------------------------------
dnl AC_CHECK_HEADERS(sys/mman.h)
dnl AC_CHECK_FUNCS(mlockall)
dnl AC_CHECK_FUNCS(putenv)


dnl ---------------------------------------------------------------------------
dnl enable runtime debugging code
dnl ---------------------------------------------------------------------------
AC_ARG_ENABLE(
	debug,
	[  --enable-debug          use runtime debugging code [default=no]],
	echo "enabling runtime debugging code",
	enable_debug=no
	)
dnl only works with GNU make
dnl AM_CONDITIONAL(DEBUGMODE, test x$enable_debug != xno)
AC_DEFINE(APP_DEBUG)


dnl ---------------------------------------------------------------------------
dnl use flock for file locking
dnl ---------------------------------------------------------------------------
AC_ARG_ENABLE(
	flock,
	[  --enable-flock          use flock() to lock files],
	[if test $enableval = yes; then
		AC_DEFINE(USE_FLOCK)
	fi]
	)


dnl ---------------------------------------------------------------------------
dnl use fcntl for file locking (default)
dnl ---------------------------------------------------------------------------
use_fcntl=yes
AC_ARG_ENABLE(
	fcntl,
	[  --disable-fcntl         do NOT use fcntl() to lock files ],
	[if test $enableval = no; then use_fcntl=no; fi]
	)
if test $use_fcntl = yes; then
	AC_DEFINE(USE_FCNTL)
fi


dnl ---------------------------------------------------------------------------
dnl project/ide code
dnl ---------------------------------------------------------------------------
AC_ARG_ENABLE(
	project,
	[  --enable-project        use experimental project/ide features [default=no]],
	echo "enabling experimental project/ide features",
	want_project=no
	)
if test x$want_project != xno; then
	AC_DEFINE(WANT_PROJECT)
fi


dnl ---------------------------------------------------------------------------
dnl this is gnotepad+
dnl ---------------------------------------------------------------------------
AC_DEFINE(APP_GNP)


dnl ---------------------------------------------------------------------------
dnl Makefiles to create:
dnl ---------------------------------------------------------------------------
AC_OUTPUT(Makefile src/Makefile)
