dnl
dnl Configuration script for LessTif
dnl $Id: configure.in,v 1.424 2006/06/10 09:22:48 dannybackx Exp $
dnl
dnl Copyright (C) 1995 Free Software Foundation, Inc.
dnl Copyright © 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005 LessTif Development Team
dnl

dnl
dnl EDIT THESE FOR A NEW RELEASE (automated by a script).
dnl
define([LESSTIF_MAJOR_VERSION], [0])
define([LESSTIF_MINOR_VERSION], [95])
define([LESSTIF_PICO_VERSION], [0])
define([LESSTIF_LAST_MAJOR_VERSION], [0])
define([LESSTIF_LAST_MINOR_VERSION], [94])
define([LESSTIF_LAST_PICO_VERSION], [4])

dnl
dnl First some auto*-related stuff
dnl The AC_INIT line is just here so we can detect whether a sensible source
dnl distribution is present.
dnl
dnl Yuck, the auto* people have changed their mind *again*.
dnl

AC_INIT(lesstif, LESSTIF_MAJOR_VERSION.LESSTIF_MINOR_VERSION.LESSTIF_PICO_VERSION)
AC_CONFIG_SRCDIR([lib/Xm-2.1/Vendor.c])
AC_CONFIG_AUX_DIR(.)
AC_PREREQ(2.59)
AM_INIT_AUTOMAKE
LIBTOOL_VERSION=0:LESSTIF_MINOR_VERSION:0

dnl
dnl This is here to pass the variables on.
dnl
AH_TEMPLATE([MAJOR_VERSION], [The major version number of this release])
AH_TEMPLATE([MINOR_VERSION], [The minor version number of this release])
AH_TEMPLATE([PICO_VERSION], [The pico version number of this release])
AC_DEFINE([MAJOR_VERSION], LESSTIF_MAJOR_VERSION, [The major version number of this release])
AC_DEFINE([MINOR_VERSION], LESSTIF_MINOR_VERSION, [The minor version number of this release])
AC_DEFINE([PICO_VERSION], LESSTIF_PICO_VERSION, [The pico version number of this release])
AH_TEMPLATE([LAST_MAJOR_VERSION], [The major version number of the previous release])
AH_TEMPLATE([LAST_MINOR_VERSION], [The minor version number of the previous release])
AH_TEMPLATE([LAST_PICO_VERSION], [The pico version number of the previous release])
AC_DEFINE([LAST_MAJOR_VERSION], LESSTIF_LAST_MAJOR_VERSION, [The major version number of the previous release])
AC_DEFINE([LAST_MINOR_VERSION], LESSTIF_LAST_MINOR_VERSION, [The minor version number of the previous release])
AC_DEFINE([LAST_PICO_VERSION], LESSTIF_LAST_PICO_VERSION, [The pico version number of the previous release])

dnl For cross-compiling?!
dnl This macro also hides all kinds of stuff we'd otherwise have to add in the
dnl right order (whichever that may be) ourselves.
dnl
AC_CANONICAL_HOST

dnl
dnl Make some maintainer-specific stuff optional
dnl
AM_MAINTAINER_MODE

dnl
dnl Override a default in libtool. We do NOT want to build static libs. They're BAD.
dnl
AC_DISABLE_STATIC

AM_CONFIG_HEADER(include/LTconfig.h)

dnl
dnl This used to be in acconfig.h
dnl
AH_TEMPLATE([LESSTIF_VERBOSE], [Whether to ask LessTif to be verbose])
AH_TEMPLATE([NONSTANDARD_CONVERTERS], [Whether to include nonstandard converters])
AH_TEMPLATE([LESSTIF_PRODUCTION], [Build a production version of the library])
AH_TEMPLATE([SCROLLBAR_VERBOSE], [Configure LessTif ScrollBar to be verbose])
AH_TEMPLATE([LESSTIF_EDITRES], [Enable support for EditRes])
AH_TEMPLATE([USE_XDND], [Define if you want XDND (the Drag and Drop compatible with GTK, GNOME, ...)])
AH_TEMPLATE([XTHREADS], [Define if libXt was compiled with -DXTHREADS])
AH_TEMPLATE([HAVE_LIB_XP], [Define if libXp is available])
AH_TEMPLATE([HAVE_GETHOSTNAME], [Define if gethostname() is available (may be in non-standard libs])

AC_MSG_CHECKING(where to store autoconf macro files)
ACLOCALDIR=`aclocal --print-ac-dir`
AM_CONDITIONAL(Aclocal, test x$ACLOCALDIR != x )
AC_MSG_RESULT($ACLOCALDIR)

AC_CONFIG_SUBDIRS(test)

dnl
dnl	Building a version is triggered by use of the --enable-build flags.
dnl	Check below for the current default values.
dnl
AC_MSG_RESULT([Building a Motif 2.1-compatible version])
Build12="no"
Build20="no"
Build21="yes"

dnl
dnl Figure out what to compile/link against
dnl	2.1 is deliberately first.
dnl
version_suffix="-2.1"
lib_version_suffix="-2.1"
xmVERSION="2"
xmREVISION="1"
xmVer="2.1"
AM_CONDITIONAL(Version_1_2, false)
AM_CONDITIONAL(Version_2_0, false)
AM_CONDITIONAL(Version_2_1, true)

dnl
dnl Conditionally compile editres support
dnl	The default is yes.
dnl
AC_MSG_CHECKING(whether to support EditRes)
AC_ARG_WITH(editres, [  --with-editres          enable support for EditRes])
if test -z "$with_editres"; then
  use_editres=yes
else
  use_editres=$with_editres
fi
AC_MSG_RESULT($use_editres)

if test x$use_editres = xyes
then
	AC_DEFINE(LESSTIF_EDITRES)
elif test x$use_editres = xset
then
	AC_DEFINE(LESSTIF_EDITRES)
fi

dnl
dnl Do you want XDND (the Drag and Drop compatible with GTK, GNOME, ...) ?
dnl
dnl Since it's in development, not enabled by default (yet).
dnl
AC_ARG_WITH(xdnd, [  --with-xdnd             enable support for XDND (GNOME compatible)])
if test -z "$with_xdnd"; then
  use_xdnd=no
else
  use_xdnd=$with_xdnd
fi

if test x$use_xdnd = xyes
then
	AC_DEFINE(USE_XDND)
elif test x$use_xdnd = xset
then
	AC_DEFINE(USE_XDND)
fi
AM_CONDITIONAL(UseXDND, test x$use_xdnd = xyes)

dnl
dnl Whether to include nonstandard converters
dnl
AC_ARG_ENABLE(nonstandard-conversions,
[  --enable-nonstandard-conversions
                          include nonstandard conversions])

if test "x$enable_nonstandard_conversions" != "xno" ; then
	AC_DEFINE(NONSTANDARD_CONVERTERS)
fi

dnl
dnl Build a production version of the library
dnl This will compile out XdbDebug statements
dnl (the libraries itself remain binary compatible, you can
dnl  link against a debug version, run with a production version 
dnl  and vice versa!)
dnl
AC_ARG_ENABLE(production,
[  --enable-production     build a production version])

if test "x$enable_production" = "xyes" ; then
	AC_DEFINE(LESSTIF_PRODUCTION)
fi

dnl
dnl Whether to ask LessTif to be verbose
dnl Verbose means more messages may come out of LessTif than out of Motif.
dnl
dnl DON'T DO THIS IN PRODUCTION.
dnl
AC_ARG_ENABLE(verbose,
[  --enable-verbose        configure LessTif to be verbose (default)])

if test "x$enable_verbose" != "xno" ; then
	if test "x$enable_production" != "xyes" ; then
		AC_DEFINE(LESSTIF_VERBOSE)
	fi
fi

AC_ARG_ENABLE(scrollbar-verbose,
[  --enable-scrollbar-verbose
                          configure LessTif ScrollBar to be verbose (default is no)])

if test "x$enable_scrollbar_verbose" = "xyes" ; then
	if test "x$enable_production" != "xyes" ; then
		AC_DEFINE(SCROLLBAR_VERBOSE)
	fi
fi

dnl
dnl Some generic stuff about the compiler and system library
dnl
lt_cs_test_CFLAGS=${CFLAGS+set}
AC_PROG_CC

dnl
dnl Whether to compile with -g for debugging
dnl
AC_MSG_CHECKING(compiler flags)
AC_ARG_ENABLE(debug,
[  --enable-debug          build LessTif with debugging options (-g)(default)])
dnl Don't touch compiler flags, if debugging was not explicitly specified.
dnl Use environment variables, compiler defaults, etc.
if test "x$enable_debug" = "xyes" ; then
	if test "x$CC" = "xgcc" ; then
		if test "$lt_cs_test_CFLAGS" = "set" ; then
			if [ echo "$CFLAGS" | grep -v -e "\-g" > /dev/null ] ; then
				if test $ac_cv_prog_cc_g = yes ; then
					CFLAGS="$CFLAGS -g"
				fi
			fi
		else
			warn_flags=-Wall
			if echo $CFLAGS | grep -e "\-g" > /dev/null ; then
				CFLAGS=-g
			else
				CFLAGS=
			fi
		fi
	else
		if test "$lt_cs_test_CFLAGS" = "set" ; then
			if [ echo "$CFLAGS" | grep -v -e "\-g" > /dev/null ] ; then
	 			if test $ac_cv_prog_cc_g = yes ; then
					CFLAGS="$CFLAGS -g"
				fi
			fi
		else
			warn_flags=
			if test $ac_cv_prog_cc_g = yes ; then
				CFLAGS=-g
			else
				CFLAGS=
			fi
		fi
	fi
fi
AC_MSG_RESULT("$CFLAGS $warn_flags")

AC_AIX
AM_PROG_CC_STDC
AC_EXEEXT
AC_OBJEXT
AM_PROG_LIBTOOL

dnl Use an external malloc debugging library
LT_WITH_DMALLOC
LT_WITH_DBMALLOC

dnl
dnl Some checks for required tools
dnl

dnl Required for internal static libraries we build
AC_CHECK_PROG(AR, ar, ar, ar)

dnl 'cp' should always be available!?
AC_CHECK_PROG(cp, cp, cp, cp)

dnl 'rm' should always be available!?
AC_CHECK_PROG(RM, rm, rm, rm)


AC_PROG_MAKE_SET
AC_PROG_INSTALL
AC_PROG_LN_S

dnl Some tools we use for code-generation
AC_PROG_YACC
AM_PROG_LEX

dnl Check for exuberant ctags
AC_HAVE_EXCTAGS

dnl auto* checks for ANSI C89 stuff
AC_HEADER_STDC
AC_C_CONST

dnl auto* checks for C99 stuff
AC_C_INLINE

dnl Ok, now let's assume the system is ANSI C89 conforming and
dnl do not check for those standard funcs/headers again!

AC_CHECK_HEADERS(fcntl.h         libgen.h       pwd.h)
AC_CHECK_HEADERS(sys/select.h    sys/stat.h     sys/systeminfo.h)
AC_CHECK_HEADERS(sys/time.h      sys/types.h    sys/wait.h)
AC_CHECK_HEADERS(unistd.h)
AC_CHECK_HEADERS(wchar.h         wctype.h)
AC_CHECK_HEADERS(limits.h stdint.h)
AC_HEADER_STAT

dnl These checks in fact look for several headers (see autoconf docs)
AC_HEADER_DIRENT
AC_HEADER_TIME

dnl Various other stuff. Most should be available on a 'typical' un*x system.
dnl Most/all should be specified in SUS V2, some are in
dnl Posix.1 (IEEE Std 1003.1: 1990)
AC_CHECK_FUNCS(access  basename  close  dirname  _exit  execl  execvp  fork)
AC_CHECK_FUNCS(getcwd  getdtablesize  getitimer  getopt)
AC_CHECK_FUNCS(getpid  getpwnam  getpwuid  getrlimit  getuid)
AC_CHECK_FUNCS(open  pipe  putenv)
AC_CHECK_FUNCS(setenv  setitimer  sigaction  signal  sleep  snprintf) 
AC_CHECK_FUNCS(stat  strcasecmp  strdup  strncasecmp  sysconf)
AC_CHECK_FUNCS(uname  usleep  vfprintf  vsnprintf  wait3  waitpid  write)
AC_CHECK_FUNCS(strlcat)

dnl select() is used in libXm and mwm
AC_CHECK_FUNCS(select)
AC_FUNC_SELECT_ARGTYPES

dnl
dnl This one is only needed for one obscure debugging function.
dnl
AC_CHECK_FUNCS(backtrace)

dnl
dnl Check integer sizes
dnl
dnl The constants are only used when cross compiling; if I understand the
dnl documentation well enough, those get substituted for the target.  The
dnl values given are the most common values, but may need customization if
dnl someone is desparate enough to _want_ to cross compile to a 64 bit
dnl machine from a 32 bit machine, for example.
AC_CHECK_SIZEOF(short, 2)
AC_CHECK_SIZEOF(int, 4)
AC_CHECK_SIZEOF(long, 4)
AC_CHECK_SIZEOF(long long, 8)

dnl X11 path stuff
AC_PATH_X
AC_PATH_XTRA

dnl Not only do we have to figure out whether we have a gethostname(),
dnl some systems hide it in -lnsl so we have to figure out to link
dnl it in when appropriate.
LT_HAVE_GETHOSTNAME

dnl
dnl Set the CFLAGS variable to the location of the found X-header files
dnl This is necessary for the tests below to work.
dnl Don't lose original contents of CFLAGS though.
dnl
lt_cs_save_CFLAGS="$CFLAGS"
if test "x$x_includes" != "x" ; then
  CFLAGS="$CFLAGS -I$x_includes"
fi

XTversion=""
AC_XT_VERSION6

if test "x$XTversion" = "x" ; then
  AC_XT_VERSION5
  if test "x$XTversion" = "x"; then
    AC_MSG_ERROR([The development package of the X Window System is required to compile LessTif,
		  must be at least X11r5])
  else
    AC_MSG_RESULT(revision 5)
    Editres=V5
  fi
else
  AC_MSG_RESULT(revision 6)
  Editres=V6
fi

dnl Pick up the result of previous check for other purposes
AM_CONDITIONAL(XIsR6, test x$Editres = xV6 )

dnl Check for libXp (X11 Printing extensions)
LT_HAVE_LIBXP

dnl
dnl Whether to link -lXp
dnl
AC_MSG_CHECKING(whether to link -lXp)
if test $lt_cv_libxp = yes;
then
  XPLIB="-lXp -lXext"
  AC_MSG_RESULT(yes)
else
  XPLIB=""
  AC_MSG_RESULT(no)
fi
AC_SUBST(XPLIB)

dnl
dnl Build libDtPrint (in lib/Dt) only if we have libXp and we're building a 2.1 version.
dnl
AM_CONDITIONAL(BuildLibDtPrint, test "$LT_HAVELIBXP" = "1" -a "$Build21" = "yes")

AC_PATH_MOTIF
if test -n "$motif_includes"; then
  if test "x$motif_includes" != "xNONE"; then
    MOTIF_CFLAGS="-I$motif_includes"
  fi
fi
AC_SUBST(MOTIF_CFLAGS)
if test -n "$motif_libraries"; then
  if test "x$motif_libraries" != "xNONE"; then
    MOTIF_LIBS="-L$motif_libraries"
  fi
fi
AC_SUBST(MOTIF_LIBS)

dnl Our own check for XTHREADS
LT_LIB_XTHREADS

dnl Adjust some standard variables

if test "x$warn_flags" = x; then
	CFLAGS="$lt_cs_save_CFLAGS"
else
	CFLAGS="$lt_cs_save_CFLAGS $warn_flags"
fi
GPROF_FLAGS="-pg"
GPROF_CFLAGS=""
EXTRACFLAGS=""
extralibs=""
run_libraries=""

case ${with_static} in
  yes) static_prefix=;;
  no)  static_prefix="#";;
esac

dnl
dnl Look for a tool to convert HTML into ASCII
dnl
LT_HTML2TXT

dnl
dnl check for man2html
dnl
dnl Hmm, a standard man2html may not be the right tool ...
LT_HAVE_MAN2HTML

AC_MSG_CHECKING(whether to build the tests)
BuildTest=""
BuildTestDir=""

AC_ARG_ENABLE(build-tests,
[  --enable-build-tests    build test tree],
test "$enable_build_tests" = "yes" && BuildTests="yes" && BuildTestDir="test"
test "$enable_build_tests" = "no" && BuildTests="no" && BuildTestsDir="")

if test -z "$BuildTests" ; then
AC_CACHE_VAL(lt_cv_buildtests, [ lt_cv_buildtests="no" ])	dnl Here's the default
BuildTests=$lt_cv_buildtests
else
lt_cv_buildTests=$BuildTests
fi
test "$BuildTests" = "yes" && BuildTestDir="test"

AC_MSG_RESULT($BuildTests)

dnl
dnl Experimental ! Keith Packard's Xft
dnl
AC_FIND_XFT

dnl
dnl Now ensure that all required variables get substituted!
dnl

dnl AC_SUBST(libdir)
AC_SUBST(bindir)

dnl We might have a bit too much redundant data here, but who cares ...
dnl AC_SUBST(version)
AC_SUBST(version_suffix)
AC_SUBST(lib_version_suffix)

AC_SUBST(xmVERSION)
AC_SUBST(xmREVISION)
AC_SUBST(xmVer)

AC_SUBST(Build12)
AC_SUBST(Build20)
AC_SUBST(Build21)

AC_SUBST(BuildTestDir)

AC_SUBST(CFLAGS)
AC_SUBST(x_lib_path)
AC_SUBST(x_libraries)
AC_SUBST(x_inc_path)
AC_SUBST(x_includes)
AC_SUBST(motif_libraries)
AC_SUBST(motif_includes)
AC_SUBST(Editres)
AC_SUBST(extralibs)
AC_SUBST(subdirs)
AC_SUBST(LIBTOOL_VERSION)
AC_SUBST(AS)
AC_SUBST(DLLTOOL)
AC_SUBST(OBJDUMP)
AC_SUBST(MAJOR_VERSION, LESSTIF_MAJOR_VERSION)
AC_SUBST(MINOR_VERSION, LESSTIF_MINOR_VERSION)
AC_SUBST(PICO_VERSION, LESSTIF_PICO_VERSION)
AC_SUBST(LAST_MAJOR_VERSION, LESSTIF_LAST_MAJOR_VERSION)
AC_SUBST(LAST_MINOR_VERSION, LESSTIF_LAST_MINOR_VERSION)
AC_SUBST(LAST_PICO_VERSION, LESSTIF_LAST_PICO_VERSION)
AC_SUBST(ACLOCALDIR)

dnl 
dnl This need 'splain'in Lucy!!!
dnl The new autoconf will be setting a default cache_file=/dev/null.
dnl To avoid all of the problems associated with parseing the long list
dnl of possibilities from the --enable-build-* and --enable-default-*
dnl args our sub-configures need to know the result of these options.
dnl We used to rely on the cache_file being shared, now we don't have a
dnl cache file. So instead, let's explicitly export the vars that we 
dnl need to make an inteligent decision.
dnl

export lt_cv_default12 lt_cv_default20 lt_cv_default21

dnl
dnl Which output files do we generate ?
dnl

AC_CONFIG_FILES([\
Makefile \
autopackage/default.apspec \
autopackage/Makefile \
scripts/Makefile \
scripts/autoconf/Makefile \
scripts/FreeBSD/Makefile \
scripts/RedHat/Makefile \
scripts/RedHat/lesstif.spec \
scripts/Slackware/Makefile \
scripts/Slackware/disklesstif1 \
scripts/Slackware/doinst.sh \
scripts/OS2/Makefile \
scripts/motif-config \
include/Makefile \
include/Motif-2.1/Makefile \
include/Motif-2.1/Mrm/Makefile \
include/Motif-2.1/Xm/Makefile \
include/Motif-2.1/uil/Makefile \
include/Motif-2.1/XmI/Makefile \
lib/Makefile \
lib/config/Makefile \
lib/config/Imake.tmpl \
lib/config/LessTif.tmpl \
lib/config/mxmkmf \
lib/Xm-2.1/Makefile \
lib/Mrm-2.1/Makefile \
lib/Uil-2.1/Makefile \
lib/Dt/Makefile \
clients/Makefile \
clients/Motif-2.1/Makefile \
clients/Motif-2.1/mwm/Makefile \
clients/Motif-2.1/uil/Makefile \
clients/Motif-2.1/xmbind/Makefile \
doc/Makefile \
doc/www.lesstif.org/Makefile \
doc/www.lesstif.org/images/Makefile \
doc/lessdox/Makefile \
doc/lessdox/clients/Makefile \
doc/lessdox/widgets/Makefile \
doc/lessdox/functions/Makefile])
AC_OUTPUT

dnl
dnl The End.
dnl
