# Bluefish HTML Editor
# Copyright (C) 1998-1999 Olivier Sessink and Chris Mazuc
# Copyright (C) 2000 Olivier Sessink
#
# 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.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

AC_INIT
AC_CONFIG_SRCDIR(src/bluefish.c)
AC_CONFIG_HEADER(src/config.h)

PACKAGE=bluefish
VERSION=0.7
AC_SUBST(PACKAGE)
AC_SUBST(VERSION)
AC_DEFINE_UNQUOTED(PACKAGE, "$PACKAGE")
AC_DEFINE_UNQUOTED(VERSION, "$VERSION")
AC_DEFINE_UNQUOTED(CURRENT_VERSION_NAME, "$PACKAGE $VERSION HTML editor")

ALL_LINGUAS="de da fr ru ro cs es el en ja it sv pt_BR hu pl nl"

dnl ************************
dnl Compiler options
dnl ************************

AC_PROG_CC
if test "$CC" = "gcc" ; then
	CFLAGS="$CFLAGS -Wall"
fi

AC_ISC_POSIX
AC_C_INLINE

AC_CANONICAL_HOST
    case $host_os in
      *cygwin* ) CYGWIN=yes;;
             * ) CYGWIN=no;;
esac
 
if test "$CYGWIN" = "yes"; then
	AC_DEFINE(WIN32)
  CFLAGS="$CFLAGS -fnative-struct"
	LIBS="$LIBS -lintl.dll"
fi  
  

AC_ARG_WITH(pentium,
[  --with-pentium          Optimizes your code for pentium cpus],[
   AC_PATH_PROGS(PGCC, pgcc, $TMP)
   	if test "$PGCC" != "" ; then
		CC = $PGCC
	fi
 	CFLAGS="-O6 -mpentium -fomit-frame-pointer -fno-exceptions -fno-rtti -pipe -s -ffast-math -fexpensive-optimizations -malign-loops=2 -malign-jumps=2 -malign-functions=2"
	echo "Using $CC $CFLAGS"
])

AC_ARG_WITH(pentiumpro,
[  --with-pentiumpro       Optimizes your code for pentiumpro cpus],[
   AC_PATH_PROGS(PGCC, pgcc, $TMP)
   	if test "$PGCC" != "" ; then
		CC = $PGCC
	fi
 	CFLAGS="-O6 -mpentiumpro -march=pentiumpro -fomit-frame-pointer -fno-exceptions -fno-rtti -pipe -s -ffast-math -fexpensive-optimizations -malign-loops=2 -malign-jumps=2 -malign-functions=2"
	echo "Using $CC $CFLAGS"
])

AC_ARG_WITH(autocomplet,
[  --with-autocomplet Turns autocompletion feature on],[
   echo "With Autocompletion",
AC_DEFINE(AUTOCOMPLET)],)

AC_ARG_WITH(attrpage,
[  --with-attrpage Turns attrpage feature on],[
   echo "With attrpage",
AC_DEFINE(ATTRPAGE)],)

AC_PROG_INSTALL

if test "x$x_includes" = "x"; then
  x_includes="/usr/include"
fi

AC_ARG_WITH(debugging_output,
[  --with-debugging-output Turns debugging output on],[
   echo "With debugging output",
AC_DEFINE(DEBUG)],)

AC_ARG_ENABLE(splash-screen,
[  --disable-splash-screen disables the splash screen],[
   echo "Without splash screen",
	AC_DEFINE(NOSPLASH)],)

dnl ************************
dnl Checks for librarries
dnl ************************

AM_GNU_GETTEXT
if test "$GMSGFMT" = "no" ; then
	echo "no gmsgfmt, disabling nls"
	USE_NLS=no
	USE_INCLUDED_LIBINTL=no
	INTLLIBS=""	
fi
if test "$MSGFMT" = "no" ; then
	echo "no msfmt, disabling nls"
	USE_NLS=no
	USE_INCLUDED_LIBINTL=no
	INTLLIBS=""
fi

if test "$USE_NLS" = "yes" ; then
	AC_DEFINE(ENABLE_NLS)
fi

LIBS="$LIBS `gtk-config --libs`"
CFLAGS="$CFLAGS `gtk-config --cflags`"

AM_PATH_GTK(1.2.0, GTK="1", GTK="0")

AC_MSG_CHECKING("for GTK  - microversion \>= 7")
GTK_CONFIG_MICRO_VERSION=`$GTK_CONFIG $gtk_config_args --version | \
           sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\3/'`
if test $GTK_CONFIG_MICRO_VERSION -gt 6 ; then
	AC_DEFINE(GTK_GT_7,1)
	AC_MSG_RESULT(yes)
else
	AC_DEFINE(GTK_GT_7,0)
	AC_MSG_RESULT(no)
fi

if test "$GTK" = "0"; then
  AC_MSG_ERROR(GTK was not detected, or a sufficent version was not found. This is a bad thing)
fi

AC_CHECK_LIB(posix4, nanosleep, 
	LIBS="$LIBS -lposix4"
	AC_DEFINE(HAVE_NANOSLEEP),
	AC_CHECK_LIB(rt, nanosleep, 
		LIBS="$LIBS -lrt"
		AC_DEFINE(HAVE_NANOSLEEP)
	)
)

AC_ARG_WITH(perl,
[  --with-perl       Adds perl to bluefish],[
  AC_PATH_PROG(PERL_EXE,perl,no)
        LIBS="$LIBS `$PERL_EXE -MExtUtils::Embed -e ldopts` "
        CFLAGS="$CFLAGS `$PERL_EXE -MExtUtils::Embed -e ccopts` "
  PERL_HEADER=`$PERL_EXE -MExtUtils::Embed -e xsinit -- -o src/perl_local.h`
  AC_DEFINE(PERL)
        echo "Using Embedded Perl System"
])

dnl Check if system supports the graphical libraries
AC_CHECK_LIB(ungif, main, GLIBS="-lungif",
AC_CHECK_LIB(gif,main, GLIBS="-lgif"))
AC_CHECK_LIB(jpeg, main, GLIBS="$GLIBS -ljpeg")
AC_CHECK_LIB(png, main, GLIBS="$GLIBS -lpng")
AC_CHECK_LIB(tiff, main, GLIBS="$GLIBS -ltiff")
AC_CHECK_LIB(z, main, GLIBS="$GLIBS -lz")

dnl Check if system supports the gdk_imlib library
  HAVE_LIBGDK_IMLIB=""
  AC_PATH_PROG(IMLIB_CONFIG,imlib-config,no)
  if test "$IMLIB_CONFIG" != "no"; then
	LIBS="$LIBS `$IMLIB_CONFIG --libs-gdk` "
	CFLAGS="$CFLAGS `$IMLIB_CONFIG --cflags-gdk` "
	AC_CHECK_LIB(gdk_imlib, main,
	AC_DEFINE(HAVE_LIBGDK_IMLIB,1)
	,AC_MSG_WARN(*** imlib disabled (library not found) ***)
	)
  fi

dnl Check if system supports the gdk_pixbuf library
        HAVE_GDK_PIXBUF=""
        AC_PATH_PROG(GNOME_CONFIG,gnome-config,no)
        if test "$GNOME_CONFIG" != "no"; then
	LIBS="$LIBS `$GNOME_CONFIG --libs gdk_pixbuf`"
	CFLAGS="$CFLAGS `$GNOME_CONFIG --cflags gnomeui`"
	AC_CHECK_LIB(gdk_pixbuf, gdk_pixbuf_new,
	AC_DEFINE(HAVE_GDK_PIXBUF,1)
	,AC_MSG_WARN(*** gdk_pixbuf disabled (library not found) ***)
	)
	fi

localedir='${prefix}/share/locale'
AC_SUBST(localedir)

dnl ************************
dnl Checks for header files.
dnl ************************

AC_HEADER_STDC
AC_CHECK_HEADERS(stdlib.h unistd.h string.h errno.h stdio.h sys/stat.h ctype.h getopt.h math.h time.h sys/types.h fcntl.h netdb.h netinet/in.h sys/socket.h arpa/inet.h dirent.h sys/select.h sys/time.h sys/ipc.h)

dnl ************************
dnl Checks for external programs.
dnl ************************

if test "$CYGWIN" = "yes"; then
	AC_PATH_PROG(WEBLINT, weblint, weblint)
	AC_PATH_PROG(NETSCAPE, netscape, netscape, $PATH=$PATH)
	AC_PATH_PROG(TIDY, tidy, tidy)

	AC_DEFINE_UNQUOTED(WEBLINT_COMMAND,"$WEBLINT")
	AC_DEFINE_UNQUOTED(WHERE_IS_NETSCAPE, "$NETSCAPE")
	AC_DEFINE_UNQUOTED(WHERE_IS_TIDY, "$TIDY")

else  

	AC_PATH_PROG(WEBLINT, weblint, /usr/bin/weblint)
	AC_PATH_PROG(NETSCAPE, netscape, /usr/local/netscape/netscape, $PATH=$PATH:/usr/local/netscape)
	AC_PATH_PROG(TIDY, tidy, /usr/bin/tidy)
	AC_PATH_PROG(RXVT, rxvt, /usr/X11R6/bin/rxvt)
	AC_PATH_PROG(MIDNIGHT_COMMANDER, mc, /usr/bin/mc)
	AC_PATH_PROG(FIND, find, /usr/bin/find)
	AC_PATH_PROG(GREP, grep, /bin/grep)

	AC_DEFINE_UNQUOTED(WEBLINT_COMMAND,"$WEBLINT")
	AC_DEFINE_UNQUOTED(WHERE_IS_NETSCAPE, "$NETSCAPE")
	AC_DEFINE_UNQUOTED(NETSCAPE_COMMAND, "$NETSCAPE -remote openURL(%s)")
	AC_DEFINE_UNQUOTED(WHERE_IS_TIDY, "$TIDY")
  AC_DEFINE_UNQUOTED(TIDY_COMMAND, "$TIDY -quiet --wrap 0")
	AC_DEFINE_UNQUOTED(WHERE_IS_RXVT, "$RXVT")
	AC_DEFINE_UNQUOTED(WHERE_IS_MC, "$MIDNIGHT_COMMANDER")
	AC_DEFINE_UNQUOTED(MC_COMMAND, "$RXVT -fn 10x20 -e $MIDNIGHT_COMMANDER &")
	AC_DEFINE_UNQUOTED(PATH_TO_FIND, "$FIND")
	AC_DEFINE_UNQUOTED(PATH_TO_GREP, "$GREP")
	AC_DEFINE_UNQUOTED(RCFILE_DEFAULTS, "external_filters: Tidy: $TIDY -quiet --wrap 0 \nexternal_commands: Midnight Commander: $RXVT -fn 10x20 -e $MIDNIGHT_COMMANDER &\nnotebook_tab_position: bottom\nbrowser_command: $NETSCAPE -remote openURL(%s)\n")
	
fi

dnl **************************
dnl  For the spell checker
dnl **************************

dnl don't define WITH_SPC if you want to build without spell-checker 
AC_DEFINE(WITH_SPC)

AC_PATH_PROG(ISPELL, ispell, /usr/bin/ispell )
AC_DEFINE_UNQUOTED(ISPELL_COMMAND, "$ISPELL")

dnl Checks select argument types
AC_FUNC_SELECT_ARGTYPES
AC_HEADER_TIME

dnl ************************
dnl For the internal preview (taken from the gimp)
dnl ************************

AC_ARG_WITH(internal-preview,
[  --with-internal-preview Enable the internal preview (EXPERIMENTAL)],[

	AC_PATH_PROG(GNOME_CONFIG,gnome-config,no)
	if test "$GNOME_CONFIG" = "no"; then
	  dnl Test for standalone GtkXMHTML widget
	  INTERNAL_PREVIEW=""
	  AC_CHECK_LIB(gtkxmhtml, main,
	    GTKXMHTML_CFLAGS=""
	    GTKXMHTML_LIBS="-lgtkxmhtml"
	    INTERNAL_PREVIEW=yes ,
	    AC_MSG_WARN(*** Internal pre-view disabled (GtkXMHTML library not found) ***))
	else
	  GTKXMHTML_CFLAGS=`$GNOME_CONFIG --cflags gnomeui`
	  GTKXMHTML_LIBS=`$GNOME_CONFIG --libs gtkxmhtml`
	  INTERNAL_PREVIEW=yes
	fi

	if test "$INTERNAL_PREVIEW" = "yes" ; then
	AC_DEFINE(WITH_INTERNAL_PREVIEW)
	LIBS="$LIBS $GTKXMHTML_LIBS"
	CFLAGS="$CFLAGS $GTKXMHTML_CFLAGS"
	fi
])

dnl ************************
dnl Program locations
dnl ************************

AC_PREFIX_DEFAULT("/usr/local")

echo "defining bindir=$bindir"

AC_ARG_ENABLE(bluefish-datadir,
[  --disable-bluefish-datadir Don't use a bluefish specific datadir],[
   pkgdatadir=${datadir}
],[
	pkgdatadir=${datadir}/${PACKAGE}
])
echo "defining pkgdatadir=$pkgdatadir"
AC_SUBST(pkgdatadir)
AC_DEFINE_UNQUOTED(PKGDATADIR, "${pkgdatadir}")
AC_DEFINE_UNQUOTED(PREFIX, "${prefix}")

AC_CONFIG_FILES(Makefile src/Makefile intl/Makefile po/Makefile.in man/Makefile data/Makefile)
AC_OUTPUT

echo "-----------"
echo "If you like this program, please let me know and send me"
echo "a postcard and tell me which country/state you're from:"
echo ""
echo "Olivier Sessink"
echo "Haarweg 17"
echo "6709 PH"
echo "Wageningen"
echo "the Netherlands"
echo "-----------"
