#
# "$Id: configure.in 407 2006-11-13 18:54:02Z mike $"
#
# Configure script for fldiff, a graphical diff program.
#
# Copyright 2005-2006 by Michael Sweet
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License v2 as published
# by the Free Software Foundation.
#
# 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.
#

dnl We need at least autoconf 2.50...
AC_PREREQ(2.50)

AC_INIT(fldiff.cxx)

dnl Version number...
VERSION="1.1"
AC_SUBST(VERSION)
AC_DEFINE_UNQUOTED(VERSION, "fldiff $VERSION")

dnl Get the operating system and version number...
uname=`uname`
uversion=`uname -r | sed -e '1,$s/[[^0-9]]//g'`
if test "x$uname" = xIRIX64; then
    uname="IRIX"
fi
if test "x$uname" = x; then
    # MingW doesn't provide any output when uname is run, even with "-s"...
    uname="CYGWIN"
fi

dnl Clear default debugging options and set normal optimization by
dnl default unless the user asks for debugging specifically.
CXXFLAGS="${CXXFLAGS:=}"
AC_SUBST(CXXFLAGS)

LDFLAGS="${LDFLAGS:=}"
AC_SUBST(LDFLAGS)

OPTIM="-O"
AC_SUBST(OPTIM)

AC_ARG_ENABLE(debug, [  --enable-debug          turn on debugging [default=no]],
if eval "test x$enable_debug = xyes"; then
 	OPTIM="-g"
else
	LDFLAGS="$LDFLAGS -s"
fi)

AC_ARG_WITH(docdir, [  --with-docdir           set directory for documentation],
	docdir="$withval",
	docdir="NONE")
AC_SUBST(docdir)

dnl Checks for programs...
AC_PROG_CC
AC_PROG_CXX
AC_PATH_PROG(CP,cp)
AC_PATH_PROG(MKDIR,mkdir)
AC_PATH_PROG(RM,rm)

dnl Check for FLTK...
AC_PATH_PROG(FLTKCONFIG,fltk-config)

if test "x$FLTKCONFIG" = x; then
	AC_MSG_ERROR([Sorry, fldiff requires FLTK 1.1.x.])
else
	CXXFLAGS="`$FLTKCONFIG --use-images --cflags` $CXXFLAGS"
	LIBS="`$FLTKCONFIG --use-images --ldflags` $LIBS"
fi

AC_SUBST(FLTKCONFIG)

dnl Update compiler options...
if test -n "$GCC"; then
	# Starting with GCC 3.0, you must link C++ programs against either
	# libstdc++ (shared by default), or libsupc++ (always static).  If
	# you care about binary portability between Linux distributions,
	# you need to either 1) build your own GCC with static C++ libraries
	# or 2) link using gcc and libsupc++.  We choose the latter since
	# fldiff doesn't (currently) use any of the stdc++ library.
	#
	# Also, GCC 3.0.x still has problems compiling some code.  You may
	# or may not have success with it.  USE 3.0.x WITH EXTREME CAUTION!
	#
	# Previous versions of GCC do not have the reliance on the stdc++
	# or g++ libraries, so the extra supc++ library is not needed.

	AC_MSG_CHECKING(if libsupc++ is required)

 	SUPC="`$CXX -print-file-name=libsupc++.a 2>/dev/null`"
 	if test -n "$SUPC" -a "$SUPC" != "libsupc++.a"; then
 		# This is gcc 3.x, and it knows of libsupc++, so we need it
 		LIBS="$LIBS -lsupc++"
		AC_MSG_RESULT(yes)
	else
		AC_MSG_RESULT(no)
 	fi

	if test "x$uname" != xDarwin; then
		CXX="$CC"
	fi

	if test -z "$OPTIM"; then
        	OPTIM="-O2 -fforce-mem -fforce-addr -fcaller-saves"
	fi

	OPTIM="-Wall -Wno-return-type $OPTIM"

	# See if GCC supports -fno-rtti...
	AC_MSG_CHECKING(if GCC supports -fno-rtti)
	OLDCFLAGS="$CFLAGS"
	CFLAGS="$CFLAGS -fno-rtti"
	AC_TRY_COMPILE(,,
		CXXFLAGS="$CXXFLAGS -fno-rtti"
		AC_MSG_RESULT(yes),
		AC_MSG_RESULT(no))
	CFLAGS="$OLDCFLAGS"

	# See if GCC supports -fno-exceptions...
	AC_MSG_CHECKING(if GCC supports -fno-exceptions)
	OLDCFLAGS="$CFLAGS"
	CFLAGS="$CFLAGS -fno-exceptions"
	AC_TRY_COMPILE(,,
		OPTIM="$OPTIM -fno-exceptions"
		AC_MSG_RESULT(yes),
		AC_MSG_RESULT(no))
	CFLAGS="$OLDCFLAGS"

	# See if we are running HP-UX or Solaris; if so, try the
	# -fpermissive option...
	case $uname in
		SunOS* | HP-UX*)
			AC_MSG_CHECKING(if GCC supports -fpermissive)

			OLDCFLAGS="$CFLAGS"
			CFLAGS="$CFLAGS -fpermissive"
			AC_TRY_COMPILE(,,
				OPTIM="$OPTIM -fpermissive"
				AC_MSG_RESULT(yes),
				AC_MSG_RESULT(no))
			CFLAGS="$OLDCFLAGS"
			;;
		*)
			;;
	esac
else
	case $uname in
		AIX*)
			if test -z "$OPTIM"; then
				OPTIM="-O2"
			fi
			;;
		HP-UX*)
			if test -z "$OPTIM"; then
				OPTIM="+O2"
			fi
			OPTIM="$OPTIM +DAportable"
			;;
        	IRIX*)
			if test -z "$OPTIM"; then
        			OPTIM="-O2"
			fi
			if test $uversion -ge 62; then
				OPTIM="$OPTIM -n32 -mips3"
				OPTIM="$OPTIM -OPT:Olimit=3000"
				OPTIM="-fullwarn -woff 1209,1506,1692 $OPTIM"
			else
				OPTIM="-fullwarn $OPTIM"
			fi
			;;
		SunOS*)
			# Solaris
			if test -z "$OPTIM"; then
				OPTIM="-xO4"
			fi
			;;
		*)
			# Running some other operating system; inform the user they
			# should contribute the necessary options to
			# epm@easysw.com...
			echo "Building fldiff with default compiler optimizations; contact"
			echo "fldiff@easysw.com with the uname and compiler options needed for"
			echo "your platform, or set the CFLAGS and CXXFLAGS environment"
			echo "variable before running configure."
			;;
	esac
fi

dnl Fix "prefix" variable if it hasn't been specified...
if test "$prefix" = "NONE"; then
	prefix="/usr/local"
fi

dnl Fix "exec_prefix" variable if it hasn't been specified...
if test "$exec_prefix" = "NONE"; then
	exec_prefix="$prefix"
fi

dnl Fix "datadir" variable if it hasn't been specified...
if test "$datadir" = "\${prefix}/share"; then
	datadir="$prefix/share"
fi

dnl Fix "docdir" variable if it hasn't been specified...
if test "$docdir" = "NONE"; then
	docdir="$datadir/doc/fldiff"
fi

dnl Fix "mandir" variable if it hasn't been specified...
if test "$mandir" = "\${prefix}/man" -a "$prefix" = "/usr"; then
	case "$uname" in
        	*BSD* | Darwin* | Linux*)
        		# BSD, Darwin (MacOS X), and Linux
        		mandir="/usr/share/man"
        		;;
        	IRIX*)
        		# SGI IRIX
        		mandir="/usr/share/catman/u_man"
        		;;
        	*)
        		# All others
        		mandir="/usr/man"
        		;;
	esac
fi

dnl See if we have the X11 desktop stuff used by GNOME and KDE...
AC_MSG_CHECKING(if GNOME/KDE desktop is in use)
desktopdir=""
for dir in /usr/share/applnk /etc/X11/applnk; do
	if test -d $dir; then
		desktopdir=$dir
		break
	fi
done

if test x$desktopdir = x; then
	AC_MSG_RESULT(no)
	INSTALLDESKTOP=""
	UNINSTALLDESKTOP=""
else
	AC_MSG_RESULT(yes)
	INSTALLDESKTOP="install-desktop"
	UNINSTALLDESKTOP="uninstall-desktop"
fi

AC_SUBST(desktopdir)
AC_SUBST(INSTALLDESKTOP)
AC_SUBST(UNINSTALLDESKTOP)

dnl Output the makefile and list file...
AC_OUTPUT(Makefile fldiff.list)

#
# End of "$Id: configure.in 407 2006-11-13 18:54:02Z mike $".
#
