dnl Process this file with autoconf to produce a configure script.
dnl
AC_PREREQ(2.13)
AC_INIT(fvwm/fvwm.c)

dnl should be "yes" only within the released distribution
ISRELEASED=yes
version=2.5.10
VERSIONINFO=""

dnl date of the released version (please zero pad the day in the last 2 dates)
dnl for example: "4 February 2003", "04 Feb 2003", "2003-02-04"
RELDATELONG="19 March 2004"
RELDATESHORT="19-Mar-2004"
RELDATENUM="2004-3-19"

dnl constant variable settings
FVWMNAMEUCASE="FVWM"
FVWMNAMELONG="F? Virtual Window Manager"
FVWMHOMEPAGE="http://fvwm.org/"
FVWMFTP="ftp.fvwm.org"
FVWMFTPDIR="/pub/ftp"
FVWMALTFTP="metalab.unc.edu"
FVWMALTFTPDIR="/pub/Linux/X11/window-managers/"
FVWMLIST="fvwm@fvwm.org"
FVWMWORKERSLIST="fvwm-workers@fvwm.org"
FVWMWORKERSLISTLONG="fvwm workers list <fvwm-workers@fvwm.org>"
MANPAGE_PREAMBLE='.\" WARNING: This file was automatically generated.  Edit the .in file instead.'

if test x"$ISRELEASED" != xyes; then
	VERSIONINFO=" (from cvs)"
	RELDATELONG="(not released yet)"
	RELDATESHORT="(not released yet)"
	RELDATENUM="(not released yet)"
#	# migo: unfortunately this nice idea can't work, it is not updated.
#	# I will think more about this, maybe autoconf-2.50+ has a solution.
#	if test -d CVS/ -a -f CVS/Entries && \
#		date +%Y-%m-%d -d 'Wed Sep  4 12:36:50 2002' >/dev/null 2>&1
#	then
#		# this is not the exact date, but better than the current date
#		for file in CVS/Entries */CVS/Entries; do
#			changelog_date="`cat $file | grep /ChangeLog/ \
#				| cut -d/ -f4`"
#			test x"$changelog_date" != x && \
#			date +%Y-%m-%d -d "$changelog_date" >>changelog_dates
#		done
#		changelog_date=`cat changelog_dates | sort -r -u | head -1`
#		VERSIONINFO=" (from cvs $changelog_date)"
#		rm -f changelog_dates
#	fi
fi

AC_SUBST(ISRELEASED)
AC_DEFINE_UNQUOTED(VERSIONINFO, "$VERSIONINFO")
AC_SUBST(VERSIONINFO)
AC_SUBST(RELDATELONG)
AC_SUBST(RELDATESHORT)
AC_SUBST(RELDATENUM)
AC_SUBST(FVWMNAMEUCASE)
AC_SUBST(FVWMNAMELONG)
AC_SUBST(FVWMHOMEPAGE)
AC_SUBST(FVWMFTP)
AC_SUBST(FVWMFTPDIR)
AC_SUBST(FVWMALTFTP)
AC_SUBST(FVWMALTFTPDIR)
AC_SUBST(FVWMLIST)
AC_SUBST(FVWMWORKERSLIST)
AC_SUBST(FVWMWORKERSLISTLONG)
AC_SUBST(MANPAGE_PREAMBLE)

AM_INIT_AUTOMAKE(fvwm, ${version})
AM_CONFIG_HEADER(config.h)

dnl installation paths
FVWM_MODULESUBDIR=/${PACKAGE}/${VERSION}
FVWM_DATASUBDIR=/${PACKAGE}

AC_ARG_ENABLE(package-subdirs,
  [  --disable-package-subdirs  do not create subdirs for modules and data],
  [if test x"$enableval" = xno; then FVWM_MODULESUBDIR=""; FVWM_DATASUBDIR="";
  fi], [])

FVWM_MODULEDIR='${libexecdir}'"$FVWM_MODULESUBDIR"
FVWM_DATADIR='${datadir}'"$FVWM_DATASUBDIR"
FVWM_PERLLIBDIR='${datadir}'"$FVWM_DATASUBDIR/perllib"
FVWM_CONFDIR='${sysconfdir}'dnl used _only_ to search for system.fvwm2rc

AC_SUBST(FVWM_MODULEDIR)
AC_SUBST(FVWM_DATADIR)
AC_SUBST(FVWM_PERLLIBDIR)
AC_SUBST(FVWM_CONFDIR)


dnl Various configure-time options
dnl

AC_ARG_ENABLE(dmalloc,
  [  --enable-dmalloc        enable support for the dmalloc debugging library],
  [ac_cv_dmalloc="$enableval"],
  [ac_cv_dmalloc="no"])

AC_ARG_ENABLE(efence,
  [  --enable-efence         enable support for the efence debugging library],
  [ac_cv_efence="$enableval"],
  [ac_cv_efence="no"])

smr_SWITCH(command-log, command logging, off, FVWM_COMMAND_LOG)
smr_SWITCH(debug-msgs, debugging messages, off, FVWM_DEBUG_MSGS)
dnl dummy: smr_SWITCH(sm, dummy for test script, on, SESSION)

dnl FIXME: default value should be derived from computed path to X
dnl includes.  Actually, this should probably not appear in configure
dnl at all: it is settable at runtime, and only confuses the issue to
dnl have it settable here too.
dnl
AC_MSG_CHECKING(imagepath)
val="/usr/include/X11/bitmaps:/usr/include/X11/pixmaps"
AC_ARG_WITH(imagepath,
[  --with-imagepath=PATH   colon-delimited search path for images],
[ case "$withval" in
  no)
    AC_MSG_ERROR([Can not disable image path.])
    ;;
  yes)
    ;;
  *)
    val="$withval"
    ;;
  esac ])
AC_DEFINE_UNQUOTED(FVWM_IMAGEPATH, "$val")
FVWM_IMAGEPATH="$val"
AC_SUBST(FVWM_IMAGEPATH)
AC_MSG_RESULT($val)

dnl Minimal checks for programs: enough to enable checking for
dnl optional libraries.
AC_PROG_CC
AC_PROG_CPP

dnl added -Wall for gcc, what about for others?
if test "x$GCC" = "xyes"; then
  CFLAGS="$CFLAGS -Wall -Wno-implicit-int"
fi

dnl Help finding POSIX functions on some systems
AC_ISC_POSIX
AC_MINIX

dnl catch -Werror and similar options when running configure
AC_TRY_COMPILE([#include <stdio.h>],
[int i; static j; int *p; char *c;
  switch (*p = p = *c) { case 0: printf("%Q", c, p); }
  *c = &i; c = p;
  while (1 || (unsigned int)3 >= 0 || ((int)-1) == ((unsigned int)1));
  return;], , AC_MSG_ERROR("
configure is not able to compile programs with warnings.  Please
remove all offending options like -Werror from the CFLAGS and
CPPFLAGS variables and run configure again."))

dnl Need to know where X is, for finding some libraries (e.g. xpm)
no_x=""
AC_PATH_XTRA
if test x"$no_x" = x"yes"; then
  echo
  echo "X11 libraries or header files could not be found.  Please make"
  echo "sure the X11 development package is installed on your system."
  echo "If it is definitely installed, try setting the include and library"
  echo "paths with the --x-include and --x-libraries options of configure."
  echo "Fvwm can not be compiled without the X11 development environment."
  echo
  echo "Aborting."
  echo
  exit 1
fi

dnl 'unset' is not portable, but setting to null is not enough to avoid using
dnl the cached value!  For ancient shells "rm config.cache" is a solution.
UNSET=true
if unset UNSET 2>/dev/null; then UNSET=unset; fi


dnl ********* multibyte
dnl FreeBSD has libxpg4, check this and use if found.
AC_CANONICAL_HOST
case $host_os in
freebsd*)
	AC_CHECK_LIB(xpg4, setlocale, [LIBS="$LIBS -lxpg4"]);;
*)
	;;
esac

dnl *** pkg-config
dnl unfortunately, we need pkg-config for the detection of certain libs:
dnl - certain version of fontconfig (without fontconfig-config
AM_CHECK_PKG_CONFIG

dnl ********* session management
dnl Check the availability of SM; we don't have to add any extra libraries,
dnl since -lSM -lICE are in X_PRE_LIBS when they exist.
dnl [old check] AC_CHECK_LIB(SM, SmcOpenConnection, AC_DEFINE(SESSION), ,
dnl [old check]            [$X_LIBS $X_PRE_LIBS -lX11 $X_EXTRA_LIBS])

problem_sm=""

AC_ARG_ENABLE(sm,
  [  --disable-sm            disable session management support],
  [ if test x"$enableval" = xyes; then
    with_sm="yes, check"
  else
    with_sm="no"
    problem_sm=": Explicitly disabled"
  fi ],
  [ with_sm="not specified, check" ]
)

if test x"$with_sm" != xno; then
  dnl Uncomment the following and comment out AC_CHECK_LIB to get --with-sm-*
  dnl $UNSET ac_cv_lib_SM_SmcOpenConnection
  dnl $UNSET ac_cv_header_X11_SM_SMlib_h
  dnl smr_CHECK_LIB(sm, SM, adds session management support, SmcOpenConnection,
  dnl   X11/SM/SMlib.h,
  dnl   [$X_LIBS $X_PRE_LIBS $X_EXTRA_LIBS], $X_CFLAGS)
  dnl test "$sm_LIBS" && AC_DEFINE(SESSION)

  $UNSET ac_cv_lib_SM_SmcOpenConnection
  AC_CHECK_LIB(SM, SmcOpenConnection, with_sm=yes; AC_DEFINE(SESSION),
    with_sm=no; problem_sm=": Failed to detect libSM",
    [$X_LIBS $X_PRE_LIBS -lX11 $X_EXTRA_LIBS])
fi
dnl AC_SUBST(sm_LIBS)
dnl AC_SUBST(sm_CFLAGS)


dnl Checking for optional libraries
dnl Default is to use them if found; can be disable using --without
dnl These are put up front so that if they are requested, but
dnl configure fails to find them, we fail early.


dnl ********* shape extension
dnl smr_SWITCH(shape, shape extensions, on, SHAPE)
AC_ARG_ENABLE(shape,
  [  --disable-shape         disable shaped window support],
  [ if test x"$enableval" = xyes; then
    with_shape="yes, check"
  else
    with_shape="no"
    problem_shape=": Explicitly disabled"
  fi ],
  [ with_shape="not specified, check" ]
)

if test x"$with_shape" != xno; then
  $UNSET ac_cv_lib_Xext_XShapeQueryExtension
  AC_CHECK_LIB(Xext, XShapeQueryExtension,
               with_shape=yes; AC_DEFINE(SHAPE),
               with_shape=no;
               problem_shape=": Failed to detect Shape extension",
               [$X_LIBS $X_PRE_LIBS -lX11 $X_EXTRA_LIBS])
fi

dnl ********* MIT Shared Memory Extension
AC_ARG_ENABLE(shm,
  [  --disable-shm           disable MIT Shared Memory Extension],
  [ if test x"$enableval" = xyes; then
    with_shm="yes, check"
  else
    with_shm="no"
    problem_shm=": Explicitly disabled"
  fi ],
  [ with_shm="not specified, check" ]
)

if test x"$with_shm" != xno; then
  $UNSET ac_cv_lib_Xext_XShmQueryExtension
  AC_CHECK_LIB(Xext, XShmQueryExtension,
               with_shm=yes; AC_DEFINE(HAVE_XSHM),
               with_shm=no;
               problem_shm=": Can't detect MIT Shared Memory ext.",
               [$X_LIBS $X_PRE_LIBS -lX11 $X_EXTRA_LIBS])
fi

dnl ********* xinerama
problem_xinerama=""

AC_ARG_ENABLE(xinerama,
  [  --disable-xinerama      disable Xinerama multi screen support],
  [ if test x"$enableval" = xyes; then
    with_xinerama="yes, check"
  else
    with_xinerama="no"
    problem_xinerama=": Explicitly disabled"
  fi ],
  [ with_xinerama="not specified, check" ]
)

if test x"$with_xinerama" != xno; then
  $UNSET ac_cv_lib_Xinerama_XineramaIsActive
  AC_CHECK_LIB(Xinerama, XineramaIsActive,
    with_xinerama=yes; Xinerama_LIBS=-lXinerama; AC_DEFINE(HAVE_XINERAMA),
    with_xinerama=no; Xinerama_LIBS=
    problem_xinerama=": Failed to detect libXinerama",
    [$X_LIBS $X_PRE_LIBS -lXext -lX11 $X_EXTRA_LIBS])
fi
AC_SUBST(Xinerama_LIBS)
AC_SUBST(Xinerama_CFLAGS)

dnl ********* xinerama-emulation
smr_SWITCH(xinerama-emulation, Xinerama emulation on one screen (useful only for developers), off,
           USE_XINERAMA_EMULATION)
if test x"$enable_xinerama_emulation" = xyes; then
  with_xinerama_emulation=yes
else
  with_xinerama_emulation=no
fi

dnl ********* xrender
problem_xrender=""
AC_ARG_ENABLE(xrender,
  [  --disable-xrender       disable Xrender alpha-blend rendering ],
  [ if test x"$enableval" = xyes; then
    with_xrender="yes, check"
  else
    with_xrender="no"
    problem_xrender=": Explicitly disabled"
  fi ],
  [ with_xrender="not specified, check" ]
)

if test x"$with_xrender" != xno; then
  $UNSET ac_cv_lib_Xrender_XRenderComposite
  AC_CHECK_LIB(Xrender, XRenderComposite,
    with_xrender=yes; Xrender_LIBS=-lXrender; AC_DEFINE(HAVE_XRENDER),
    with_xrender=no; Xrender_LIBS=
    problem_xrender=": Failed to detect libXrender",
    [$X_LIBS $X_PRE_LIBS -lXext -lX11 $X_EXTRA_LIBS])
fi
AC_SUBST(Xrender_LIBS)
AC_SUBST(Xrender_CFLAGS)

dnl ********* xft
problem_xft=""

AC_ARG_ENABLE(xft,
  [  --disable-xft           disable Xft anti-aliased font rendering],
  [ if test x"$enableval" = xyes; then
    with_xft="yes, check"
  else
    with_xft="no"
    problem_xft=": Explicitly disabled"
  fi ],
  [
    with_xft="not specified, check"
  ]
)

if test x"$with_xft" != xno; then

  dnl first check for freetype2
  have_freetype=no
  AM_CHECK_FT2(6.1.0)
  if test x"$no_ft" = x; then
    have_freetype=yes
  else
    have_freetype=no
    problem_xft=": Can't detect freetype2 >= 6.1.0/2.0.6"
  fi

  dnl check for fontconfig for Xft 2
  have_fontconfig=no
  if test x"$have_freetype" != xno ; then
    AM_CHECK_FC(1.0.1)
    if test x"$no_fc" = x ; then
      have_fontconfig=yes
    else
      have_fontconfig=no
      problem_xft=": Can't detect fontconfig >= 1.0.1"
    fi
  fi

  dnl now check for Xft 2
  with_xft=no
  if test x"$have_fontconfig" != xno ; then
    # Xft 2
    AM_CHECK_XFT(2.0.0)
    if test x"$no_xft" = x; then
      with_xft=yes
      problem_xft=" (version 2)"
      AC_DEFINE(HAVE_XFT2)
      AC_DEFINE(HAVE_XFT)
      AC_DEFINE(HAVE_XFT_UTF8)
      Xft_LIBS=$XFT_LIBS
      Xft_CFLAGS=$XFT_CFLAGS
    else
      problem_xft=": Can't detect Xft2, detected fontconfig"
    fi
  fi

  dnl if Xft2 not detected check for Xft1
  if test x"$have_freetype" != xno -a x"$with_xft" != xyes; then
    #Xft 1
    $UNSET ac_cv_lib_XftConfigSubstitute
    $UNSET ac_cv_lib_Xft_XftFontOpen
    $UNSET ac_cv_lib_Xft_XftDrawStringUtf8
    AC_CHECK_LIB(Xft, XftFontOpen,
      with_xft=yes, with_xft=no,
      [$X_LIBS $X_PRE_LIBS -lXext -lX11 $X_EXTRA_LIBS $FT2_LIBS $Xrender_LIBS])
    if test x"$with_xft" = xyes ; then
      AC_CHECK_LIB(Xft, XftConfigSubstitute, is_xft1=yes, is_xft1=no,
        [$X_LIBS $X_PRE_LIBS -lXext -lX11 $X_EXTRA_LIBS $FT2_LIBS $Xrender_LIBS])
      if test x"$is_xft1" = xyes; then
        Xft_LIBS="-lXft $FT2_LIBS"
	Xft_CFLAGS="$Xft_CFLAGS $FT2_CFLAGS"
        problem_xft=" (version 1)"
        AC_DEFINE(HAVE_XFT)
      else
        with_xft=no
        problem_xft=": Can't detect Xft 1 or fontconfig"
      fi
    else
      problem_xft=": Can't detect Xft 1 or 2 and fontconfig"
    fi
    if test x"$with_xft" = xyes; then
      AC_CHECK_LIB(Xft, XftDrawStringUtf8, AC_DEFINE(HAVE_XFT_UTF8),,
        [$X_LIBS $X_PRE_LIBS -lXext -lX11 $X_EXTRA_LIBS $FT2_LIBS $Xrender_LIBS])
    fi
  fi

fi
AC_SUBST(Xft_LIBS)
AC_SUBST(Xft_CFLAGS)

dnl ********* xpm
problem_xpm=": Xpm library or header not found"

$UNSET ac_cv_header_X11_xpm_h
$UNSET ac_cv_lib_Xpm_XpmReadFileToXpmImage
smr_CHECK_LIB(xpm, Xpm, for coloured or shaped icons,
    XpmReadFileToXpmImage, X11/xpm.h,
    [$X_LIBS $X_PRE_LIBS -lX11 $X_EXTRA_LIBS], $X_CFLAGS)

if test x"$xpm_LIBS" != x; then
  dnl Check for proper version of Xpm -- from XEmacs 21.x configure.in
  AC_MSG_CHECKING([for Xpm 3.4g or better])
  my_CPPFLAGS="$CPPFLAGS"
  my_LIBS="$LIBS"
  CPPFLAGS="$CPPFLAGS $xpm_CFLAGS $X_CFLAGS"
  LIBS="$LIBS $xpm_LIBS $X_LIBS $X_PRE_LIBS -lX11 $X_EXTRA_LIBS"
  AC_TRY_RUN([#include <X11/xpm.h>
   int main(int c, char **v) {
   return c == 1 ? 0 :
     XpmIncludeVersion != XpmLibraryVersion() ? 1 :
     XpmIncludeVersion < 30407 ? 2 : 0 ;}],
    [./conftest dummy_arg; xpm_status=$?;
     if test x"$xpm_status" = x0; then
       with_xpm=yes
       problem_xpm=""
     else
       with_xpm=no;
       if test x"$xpm_status" = x1; then
	 problem_xpm=": Xpm library and header versions don't match"
       elif test x"$xpm_status" = x2x; then
	 problem_xpm=": Xpm library version is too old"
       else
	 problem_xpm=": Internal xpm detection logic error"
       fi
     fi],
   [with_xpm=no; problem_xpm=": Xpm test error, see config.log"])
  AC_MSG_RESULT($with_xpm)
  CPPFLAGS="$my_CPPFLAGS"
  LIBS="$my_LIBS"

  if test x"$with_xpm" = xyes; then
    AC_DEFINE(XPM)
    # FVWMBANNER=FvwmBanner AC_SUBST(FVWMBANNER)
    # XPMROOT=xpmroot AC_SUBST(XPMROOT)
    # FVWMSCRIPT=FvwmScript AC_SUBST(FVWMSCRIPT)
  else
    xpm_LIBS=
    xpm_CFLAGS=
  fi
fi
AC_SUBST(xpm_LIBS)
AC_SUBST(xpm_CFLAGS)

dnl ********* png
problem_png=": png library or header not found"

$UNSET ac_cv_header_png_h
$UNSET ac_cv_lib_png_png_read_info
smr_CHECK_LIB(png, png, for coloured or shaped icons,
    png_read_info, png.h, -lz -lm,)

if test x"$png_LIBS" != x; then
  dnl Check for proper version of png
  AC_MSG_CHECKING([for libpng 1.0.4a or better])
  my_CPPFLAGS="$CPPFLAGS"
  my_LIBS="$LIBS"
  CPPFLAGS="$CPPFLAGS $png_CFLAGS"
  LIBS="$LIBS $png_LIBS -lz -lm"
  AC_TRY_RUN([#include <png.h>
   int main(int c, char **v) {
   return c == 1 ? 0 : (PNG_LIBPNG_VER < 10005) ? 2 : 0 ;}],
    [./conftest dummy_arg; png_status=$?;
     if test x"$png_status" = x0; then
       with_png=yes;
     else
       with_png=no;
       if test x"$png_status" = x2; then
	 problem_png=": png library version is too old"
       else
	 problem_png=": Internal png detection logic error"
       fi
     fi],
   [with_png="no"; problem_png=": png test error, see config.log"])
  AC_MSG_RESULT($with_png)
  CPPFLAGS="$my_CPPFLAGS"
  LIBS="$my_LIBS"
fi

if test x"$with_png" = xyes; then
  AC_DEFINE(HAVE_PNG)
  png_LIBS="-lpng -lz"
  problem_png=""
else
  with_png=no
fi
AC_SUBST(png_LIBS)
AC_SUBST(png_CFLAGS)

dnl ** needed by the png support
AC_C_BIGENDIAN

dnl ********* rplay
$UNSET ac_cv_header_rplay_h
$UNSET ac_cv_lib_rplay_rplay_create
dnl Add in X_EXTRA_LIBS here to get things like connect().
smr_CHECK_LIB(rplay, , adds audio capability, rplay_create, rplay.h,
	      $X_EXTRA_LIBS)
test x"$rplay_LIBS" != x && AC_DEFINE(HAVE_RPLAY)
AC_SUBST(rplay_LIBS)
AC_SUBST(rplay_CFLAGS)


dnl ********* stroke
$UNSET ac_cv_header_stroke_h
$UNSET ac_cv_lib_stroke_stroke_init
dnl Add in X_LIBS for MOUSE_DROPPINGS?
dnl As of 23/Mar/2000 the only libstroke RPM has /usr/X11R6/include/stroke.h
smr_CHECK_LIB(stroke, , mouse strokes recognition,
	stroke_init, stroke.h,
	[$X_LIBS -lX11], $X_CFLAGS -I/usr/X11R6/include)
test x"$stroke_LIBS" != x && AC_DEFINE(HAVE_STROKE)
AC_SUBST(stroke_LIBS)
AC_SUBST(stroke_CFLAGS)


dnl ********* readline
with_readline=no
problem_readline=": Both termcap and ncurses disabled"

smr_ARG_WITHLIB(termcap, , to accomplish readline)
if test x"$with_termcap" != xno; then
  dnl Forget cached values, so user can re-run configure
  $UNSET ac_cv_header_readline_history_h
  $UNSET ac_cv_lib_readline_readline
  AC_MSG_CHECKING([with termcap])
  smr_CHECK_LIB(readline, , line editing/history, readline, readline/history.h,
    $termcap_LIBS)
  if test x"$readline_LIBS" != x; then
    with_readline=yes
    readline_LIBS="$readline_LIBS $termcap_LIBS"
    AC_DEFINE(HAVE_READLINE)
  fi
fi
smr_ARG_WITHLIB(ncurses, , to accomplish readline)
if test x"$with_ncurses" != xno -a ! "$readline_LIBS"; then
  # We couldn't use readline with termcap; try with ncurses?
  dnl Doesn't this seem a hacky way to do this??
  dnl unset cached values from last check...
  $UNSET ac_cv_header_readline_history_h
  $UNSET ac_cv_lib_readline_readline
  AC_MSG_CHECKING([with ncurses])
  dnl We can't call smr_CHECK_LIB twice here without having the usage twice...
  dnl old_LIBS=$LIBS
  dnl AC_CHECK_LIB(readline, readline, , , $ncurses_LIBS)
  dnl LIBS=$old_LIBS
  dnl if test x"$ac_cv_lib_readline_readline" = xyes; then
  dnl   AC_CHECK_HEADERS(readline/history.h)
  dnl   if test x"$ac_cv_header_readline_history_h" = xyes; then
  dnl     with_readline=yes
  dnl     readline_LIBS="$readline_LIBS $ncurses_LIBS"
  dnl     AC_DEFINE(HAVE_READLINE)
  dnl   fi
  dnl fi
  smr_CHECK_LIB(readline, , line editing/history, readline, readline/history.h,
    $ncurses_LIBS)
  if test x"$readline_LIBS" != x; then
    with_readline=yes
    readline_LIBS="$readline_LIBS $ncurses_LIBS"
    AC_DEFINE(HAVE_READLINE)
  fi
fi
AC_SUBST(readline_LIBS)
AC_SUBST(readline_CFLAGS)


dnl Check if Xsetlocale() is available or not.
AC_CHECK_LIB(X11, _Xsetlocale, AC_DEFINE(X_LOCALE),, $X_LIBS -lX11)

dnl Check if Xsetlocale() is available or not.
AC_CHECK_LIB(X11, XOpenOM, AC_DEFINE(HAVE_XOUTPUT_METHOD),, $X_LIBS -lX11)

dnl ******** iconv
with_iconv=no
with_iconv_type=no
with_lib_iconv=no
with_sys_iconv=no
problem_iconv=": Explicitly disabled"

AC_ARG_ENABLE(iconv,
  [  --disable-iconv         disable support for iconv character conversion],
  [ac_cv_iconv="$enableval"],
  [ac_cv_iconv="yes"])

if test x"$ac_cv_iconv" != xno; then
  dnl * first check for gnu libiconv
  $UNSET ac_cv_header_libiconv_h
  $UNSET ac_cv_lib_libiconv_libiconv_open
  smr_CHECK_LIB(
  	iconv, , if not found sys iconv is used, libiconv_open, iconv.h)
  if test x"$iconv_LIBS" != x; then
     AC_DEFINE(USE_LIBICONV)
     with_lib_iconv=yes
  fi
  AC_SUBST(iconv_LIBS)
  AC_SUBST(iconv_CFLAGS)

  dnl * check for system iconv

  AC_CHECK_FUNC(iconv_open, with_sys_iconv=yes)

  if test x"$with_lib_iconv" = xyes -a x"$with_sys_iconv" = xyes; then
     AC_MSG_WARN([***  Both system iconv and libiconv found: use libiconv])
     AC_MSG_WARN([***  Use --with-iconv-library=no to use the system iconv])
  fi

  dnl * libiconv found check for libcharset to get the good iconv charset
  if test x"$with_lib_iconv" = xyes; then
     CHECK_LIBCHARSET
  fi

  test x"$with_lib_iconv" = xyes -o x"$with_sys_iconv" = xyes &&
	 with_iconv=yes && problem_iconv=""
  test x"$with_lib_iconv" = xyes && with_iconv_type="yes (libiconv)"
  test x"$with_sys_iconv" = xyes && with_iconv_type="yes (from C library)"

  if test x"$with_iconv" = xno; then
    AC_MSG_WARN([*** ])
    AC_MSG_WARN([*** No iconv() implementation found in C library or libiconv])
    AC_MSG_WARN([*** Please install libiconv ftp://ftp.gnu.org/pub/gnu/libiconv/])
    AC_MSG_WARN([*** ])
  fi

  if test x"$with_iconv" = xyes; then
     AC_DEFINE(HAVE_ICONV)
     ICONV_SECOND_ARG
  fi
fi


dnl ******** nl_langinfo and CODESET
AC_MSG_CHECKING([for nl_langinfo (CODESET)])
AC_TRY_COMPILE([#include <langinfo.h>
#include <locale.h>],
[char *codeset = nl_langinfo(CODESET); setlocale(LC_CTYPE, "");],
   AC_DEFINE(HAVE_CODESET,,[Have nl_langinfo (CODESET)])
   have_codeset=yes,
   have_codeset=no)
AC_MSG_RESULT($have_codeset)


dnl ********* fribidi
AC_ARG_ENABLE(bidi,
	[  --disable-bidi          disable bi-directional text support],
	[ if test x"$enableval" = xyes; then
		with_bidi="yes, check"
	else
		with_bidi="no"
		problem_bidi=": Explicitly disabled"
	fi ],
	[ with_bidi="not specified, check" ]
)

if test x"$with_bidi" != xno; then
	AC_ARG_WITH(fribidi-bindir,
		[  --with-fribidi-bindir=DIR  directory of fribidi-config if not in PATH],
		FRIBIDI_BINDIR="$withval", FRIBIDI_BINDIR=".")
	AC_PATH_PROG(FRIBIDI_CONFIG, fribidi-config,, [$FRIBIDI_BINDIR:$PATH])

	if test x"$FRIBIDI_CONFIG" = x; then
		with_bidi=no
		problem_bidi=": No fribidi-config found in PATH"
	else
		Bidi_CFLAGS=`$FRIBIDI_CONFIG --cflags`
		Bidi_LIBS=`$FRIBIDI_CONFIG --libs`
		AC_CHECK_LIB(fribidi, fribidi_log2vis,
			with_bidi=yes; problem_bidi=,
			with_bidi=no; problem_bidi=": No good libs via fribidi-config",
			[$Bidi_LIBS $Bidi_CFLAGS])
	fi
fi

if test x"$with_bidi" != xno; then
	fribidi_in_path=yes
	ac_save_LIBS="$LIBS"
	LIBS="$LIBS $Bidi_LIBS"
	AC_TRY_RUN([#include <stdlib.h>
#include <fribidi/fribidi.h>
int main()
{
	FriBidiChar *logical_unicode_str =
		(FriBidiChar *)malloc((4 + 1) * sizeof(FriBidiChar));
	fribidi_charset_to_unicode(
		fribidi_parse_charset("iso8859-8"), "test", 4,
		logical_unicode_str);
	return 0;
}
], [:], [fribidi_in_path=no])
	LIBS="$ac_save_LIBS"
	if test x"$fribidi_in_path" != xyes; then
		ac_save_CFLAGS="$CFLAGS"
		ac_save_LIBS="$LIBS"
		CFLAGS="$CFLAGS $Bidi_CFLAGS"
		LIBS="$LIBS $Bidi_LIBS"
	AC_TRY_RUN([#include <stdlib.h>
#include <fribidi/fribidi.h>
int main()
{
	FriBidiChar *logical_unicode_str =
		(FriBidiChar *)malloc((4 + 1) * sizeof(FriBidiChar));
	fribidi_charset_to_unicode(
		fribidi_parse_charset("iso8859-8"), "test", 4,
		logical_unicode_str);
	return 0;
}
], [:], [with_bidi=no; problem_bidi=": Bad fribidi version, see config.log"])
		CFLAGS="$ac_save_CFLAGS"
		LIBS="$ac_save_LIBS"
	fi
	if test x"$fribidi_in_path" != xno; then
		Bidi_CFLAGS=
		Bidi_LIBS=-lfribidi
	fi
fi

if test x"$with_bidi" = xno; then
	Bidi_CFLAGS=
	Bidi_LIBS=
else
	AC_DEFINE(HAVE_BIDI)
fi
AC_SUBST(Bidi_LIBS)
AC_SUBST(Bidi_CFLAGS)


dnl ********* perllib
with_perllib="yes"
problem_perllib=""
FVWM_PERLLIB=perllib
AC_ARG_ENABLE(perllib,
	[  --disable-perllib       disable installing FVWM perl library],
	[ if test x"$enableval" = xno; then
		with_perllib="no"
		problem_perllib=": Explicitly disabled"
		FVWM_PERLLIB=""
	fi ],
)
AC_SUBST(FVWM_PERLLIB)

dnl ******* gettext
ALL_LINGUAS="ar de fr sv_SE"
FVWM_DOMAIN="fvwm"
FVWMTASKBAR_DOMAIN="FvwmTaskBar"
FVWMSCRIPT_DOMAIN="FvwmScript"
ALL_DOMAINS="$FVWM_DOMAIN $FVWMTASKBAR_DOMAIN $FVWMSCRIPT_DOMAIN"

AC_SUBST(ALL_LINGUAS)
AC_SUBST(FVWM_DOMAIN)
AC_SUBST(FVWMTASKBAR_DOMAIN)
AC_SUBST(FVWMSCRIPT_DOMAIN)
AC_SUBST(ALL_DOMAINS)

LOCALEDIR='${datadir}'"/locale"
with_gettext="yes"
problem_gettext=""

AC_ARG_ENABLE(nls,
	[  --disable-nls           do not use Native Language Support],
	[ if test x"$enableval" = xno; then
		with_gettext="no"
		problem_gettext=": Explicitly disabled"
	fi ],
)

if test x"$with_gettext" != xno; then
  AM_GNU_FGETTEXT
  if test x"$USE_NLS" = "xyes"; then
    AC_DEFINE(HAVE_NLS, 1)
  else
    with_gettext="no"
    problem_gettext=": Failed to detected GNU gettext"
  fi
else
  USE_NLS=no
fi

# libs and buil
AC_SUBST(intl_LIBS)
AC_SUBST(intl_CFLAGS)
AC_SUBST(USE_NLS)
AC_SUBST(POSUB)
AC_SUBST(LOCALEDIR)
AC_SUBST(MKINSTALLDIRS)
# programs for devel
AC_SUBST(XGETTEXT)
AC_SUBST(GMSGFMT)
AC_SUBST(MSGMERGE)
AC_SUBST(MSGFMT)
AC_SUBST(MSGUNIQ)
#catalogs
AC_SUBST(INST_LINGUAS)
AC_SUBST(CATALOGS)
AC_SUBST(POFILES)
AC_SUBST(GMOFILES)
AC_SUBST(UPDATEPOFILES)
AC_SUBST(DUMMYPOFILES)
AC_SUBST(CATOBJEXT)

dnl Check for REQUIRED headers and functions before going any
dnl further.

dnl The module interface uses variadic functions for message passing.
AC_CHECK_HEADERS(stdarg.h)
AC_CHECK_FUNCS(vfprintf)
if test x$ac_cv_header_stdarg_h = xno -o \
        $ac_cv_func_vfprintf = no; then
     AC_MSG_ERROR([stdarg.h and vfprintf required])
fi

dnl For reaping children, fvwm needs either waitpid() or wait3()
dnl Some extra modules may need wait4() too
AC_CHECK_FUNCS(waitpid)
if test x$ac_cv_func_waitpid = xno; then
    AC_CHECK_FUNCS(wait3 wait4)
    if test x$ac_cv_func_wait3 = xno; then
        AC_MSG_ERROR([Either waitpid or wait3 function is required])
    fi
fi

dnl Make the C++ compiler optional, for it is only used in
dnl modules, not for the main code.
dnl
dnl Actually, we don't use it at _all_ anymore, since the only module
dnl that used it has been removed.  It causes problems so we'll comment
dnl it out for now.  Hopefully by the time we need it again autoconf
dnl will handle it better :-/

dnl AC_ARG_WITH(cxx,
dnl [  --without-cxx           disable probing for C++ compiler])
dnl
dnl if test x"$with_cxx" != xno; then
dnl     if test x"$with_cxx" != x -a x"$with_cxx" != xyes; then
dnl         CCC=$with_cxx
dnl # disable the cached value before probing
dnl         $UNSET ac_cv_prog_CXX
dnl         AC_CHECK_PROGS(CXX, $CCC)
dnl         test x"$CXX" != x ||
dnl             AC_MSG_ERROR([C++ compiler given by --with-cxx not found])
dnl     else
dnl         AC_CHECK_PROGS(CXX, $CCC c++ g++ gcc CC cxx cc++)
dnl     fi
dnl     if test x"$CXX" != x; then
dnl         AC_MSG_RESULT(Using $CXX to compile C++ programs)
dnl         with_cxx=yes
dnl         AC_PROG_CXX
dnl     fi
dnl fi

dnl Look harder for a C preprocessor for FvwmCpp
AC_PATH_PROG(FVWM_CPP, cpp, no, $PATH:/lib:/usr/lib:/usr/ccs/lib)
if test x"$FVWM_CPP" = xno; then
  FVWM_CPP=
  AC_MSG_WARN([cannot locate a C preprocessor: run FvwmCpp with -cppprog])
fi
dnl FIXME: make sure the cpp we found actually works...

dnl Finish checking for programs.
AC_PROG_INSTALL
AC_PROG_LN_S
AC_PROG_MAKE_SET
AC_PROG_RANLIB
dnl lex+yacc now only needed for FvwmScript developers when syntax is changed
dnl AM_PROG_LEX
dnl AC_PROG_YACC

REQUIRED_PERL_VERSION=5.004
AC_SUBST(REQUIRED_PERL_VERSION)

if test x"$PERL" = x; then
	AC_PATH_PROG(PERL, perl)
fi
if test x"$PERL" != x; then
	AC_MSG_CHECKING([for perl $REQUIRED_PERL_VERSION or better])
	if ("$PERL" -e "require $REQUIRED_PERL_VERSION;") 2>/dev/null; then
		AC_MSG_RESULT(yes)
	else
		AC_MSG_RESULT(no)
		AC_MSG_WARN([$PERL not found or too old])
	fi
else
	AC_MSG_WARN([perl is not found, it is required for some scripts and modules])
	AC_MSG_WARN([It is recommended to install perl $REQUIRED_PERL_VERSION or better later])
	PERL=/usr/bin/perl
fi
AC_MSG_RESULT([assuming $PERL as perl location])
AC_SUBST(PERL)

dnl Checks for header files.
AC_HEADER_STDC
AC_HEADER_SYS_WAIT
AC_CHECK_HEADERS(stdlib.h fcntl.h limits.h malloc.h string.h memory.h unistd.h)
AC_CHECK_HEADERS(getopt.h sys/select.h sys/systeminfo.h sys/time.h)

dnl Checks for typedefs, structures, and compiler characteristics.
AC_C_CONST
AC_C_INLINE
AC_TYPE_OFF_T
AC_TYPE_PID_T
AC_TYPE_SIZE_T
AC_HEADER_TIME
dnl AC_STRUCT_TM

dnl Checks for library functions.
AC_TYPE_SIGNAL
AC_FUNC_ALLOCA
AC_FUNC_STRFTIME
AC_FUNC_SETPGRP
AC_CHECK_FUNCS(gettimeofday mkfifo putenv setvbuf socket waitpid)
AC_CHECK_FUNCS(strdup strstr strtol memmove memcpy strchr sysconf uname div)
AC_CHECK_FUNCS(sigaction siginterrupt getpwuid)
AC_CHECK_FUNCS(setpgrp setpgid)



pds_CHECK_TYPE(sig_atomic_t, int, [#include <signal.h>])

if test x$ac_cv_func_setvbuf = xyes; then
  AC_FUNC_SETVBUF_REVERSED
fi

AC_FUNC_SELECT
if test x$ac_cv_func_select != xyes; then
  AC_MSG_ERROR([select required])
fi

dnl Check for standard functions that we have replacements for.
AC_REPLACE_FUNCS(gethostname strcasecmp strncasecmp strdup strerror usleep atexit)
dnl dv: this is harmful with autoconf 2.53 and is done automatically anyway
dnl AC_SUBST(LIBOBJS)

dnl check for mkstemp, see the discution on this subject on the fvwm workers
dnl list (2001-02-16 and 2001-02-24)
AM_SAFTY_CHECK_MKSTEMP

dnl If we do not have atexit(), then check for on_exit()
if test x$ac_cv_func_atexit = xno; then
  AC_CHECK_FUNCS(on_exit)
fi


dnl ********* GTK, IMLIB, GNOME
dnl Check the availability of gtk
AC_ARG_ENABLE(
	gtk,
	[  --disable-gtk           do not build modules using gtk library],
	enable_gtktest="$enableval", enable_gtktest=yes)
if test x"$enable_gtktest" = xyes; then
	AM_PATH_GTK(1.1.0,[
		FVWMGTK=FvwmGtk AC_SUBST(FVWMGTK)
		MANFVWMGTK=FvwmGtk.1 AC_SUBST(MANFVWMGTK)
	],)
	if test x"$no_gtk" = x; then
		with_gtk=yes
		problem_gtk=""
	else
		with_gtk=no
		problem_gtk=": Failed to detect GTK, see config.log"
	fi
else
	with_gtk=no
	problem_gtk=": Explicitly disabled"
fi

dnl Check the availability of gdk-imlib
AM_PATH_GDK_IMLIB(1.8.0, AC_DEFINE(GDK_IMLIB),)
if test x"$no_imlib" = x; then
  with_gdkimlib=yes
  problem_gdkimlib=""
else
  with_gdkimlib=no
  problem_gdkimlib=": Failed on gdk-imlib, see config.log"
fi

GNOME_INIT_HOOK

dnl Unfortunately we have 2 gnome supports: WM hints and gnome libs.
dnl The $with_gnomehints below refers to the first, not GNOME_INIT_HOOK.
if test x"$enable_gnome_hints" != xno; then
  with_gnomehints=yes
  problem_gnomehints=""
else
  with_gnomehints=no
  problem_gnomehints=": Explicitly disabled"
fi

dnl Define some compatibility macros needed for acconfig.h.
mg_DEFINE_IF_NOT([#include <X11/keysym.h>],
  [defined XK_Page_Up && defined XK_Page_Down],
  [COMPAT_OLD_KEYSYMDEF], [$X_CFLAGS])

if test x"$with_stroke" = xyes; then
  mg_DEFINE_IF_NOT([#include <stroke.h>],
    [defined STROKE_MAX_SEQUENCE],
    [COMPAT_OLD_LIBSTROKE], [$stroke_CFLAGS])
fi


dnl Allow building with dmalloc.  Do this last to avoid screwing up any
dnl other checks above.

case "$ac_cv_dmalloc" in
  yes) AC_CHECK_HEADERS(dmalloc.h)
       AC_CHECK_LIB(dmalloc, dmalloc_shutdown)
       CPPFLAGS="$CPPFLAGS -DDMALLOC_FUNC_CHECK" ;;
esac


dnl Allow building with efence.

case "$ac_cv_efence" in
  yes) AC_CHECK_LIB(efence, malloc) ;;
esac


# mainly for fvwm-config
AC_SUBST(with_bidi)
AC_SUBST(with_gtk)
AC_SUBST(with_gdkimlib)
AC_SUBST(with_gettext)
AC_SUBST(with_gnomelibs)
AC_SUBST(with_iconv)
AC_SUBST(with_perllib)
AC_SUBST(with_png)
AC_SUBST(with_readline)
AC_SUBST(with_rplay)
AC_SUBST(with_shape)
AC_SUBST(with_shm)
AC_SUBST(with_sm)
AC_SUBST(with_stroke)
AC_SUBST(with_xft)
AC_SUBST(with_xinerama)
AC_SUBST(with_xrender)
AC_SUBST(with_xpm)

LOCAL_BUGADDR=${FVWM_BUGADDR-${USER-${LOGNAME-`whoami`}}}
AC_SUBST(LOCAL_BUGADDR)

AC_OUTPUT(
	Makefile
	libs/Makefile
	fvwm/Makefile
	modules/Makefile
dnl
	fvwm/fvwm.1
dnl
	bin/Makefile
	bin/fvwm-config
	bin/fvwm-bug
	bin/fvwm-perllib
	bin/fvwm-menu-xlock
	bin/fvwm-menu-directory
	bin/fvwm-menu-desktop
	bin/fvwm-menu-headlines
	bin/fvwm-convert-2.4
	bin/fvwm-convert-2.6
dnl
	utils/Makefile
	perllib/Makefile
	perllib/General/Makefile
	perllib/FVWM/Makefile
	perllib/FVWM/Module/Makefile
	perllib/FVWM/Tracker/Makefile
	perllib/FVWM/Module.pm
	rpm/Makefile
	rpm/fvwm.spec
	debian/Makefile
	debian/control
	docs/fvwm.lsm
	docs/Makefile
	sample.fvwmrc/Makefile
	tests/Makefile
	tests/hints/Makefile
	po/Makefile
dnl
	modules/FvwmAnimate/Makefile
	modules/FvwmAuto/Makefile
	modules/FvwmBacker/Makefile
	modules/FvwmBanner/Makefile
	modules/FvwmButtons/Makefile
	modules/FvwmCommand/Makefile
	modules/FvwmCommand/scripts/Makefile
	modules/FvwmConsole/Makefile
	modules/FvwmConsole/FvwmConsoleC.pl
	modules/FvwmCpp/Makefile
	modules/FvwmDebug/Makefile
	modules/FvwmDebug/FvwmDebug
	modules/FvwmDebug/FvwmGtkDebug
	modules/FvwmDragWell/Makefile
	modules/FvwmEvent/Makefile
	modules/FvwmForm/Makefile
	modules/FvwmIconBox/Makefile
	modules/FvwmIconMan/Makefile
	modules/FvwmIdent/Makefile
	modules/FvwmM4/Makefile
	modules/FvwmPager/Makefile
	modules/FvwmPerl/Makefile
	modules/FvwmPerl/FvwmPerl
	modules/FvwmProxy/Makefile
	modules/FvwmRearrange/Makefile
	modules/FvwmSave/Makefile
	modules/FvwmSaveDesk/Makefile
	modules/FvwmScript/Makefile
	modules/FvwmScript/Scripts/Makefile
	modules/FvwmScript/Widgets/Makefile
	modules/FvwmScroll/Makefile
	modules/FvwmTaskBar/Makefile
	modules/FvwmTheme/Makefile
	modules/FvwmWharf/Makefile
	modules/FvwmWinList/Makefile
	modules/FvwmWindowMenu/Makefile
	modules/FvwmWindowMenu/FvwmWindowMenu
	modules/FvwmGtk/Makefile
)

# ---------------------------------------------------------------------------
# Original config.status is patched to make generated scripts executable.
sed 's/> $ac_file/> $ac_file; test x"`head -1 $ac_file | cut -c1-2`" = x"#!" \&\& chmod a+rx $ac_file/' <config.status >config.status-t && \
mv config.status-t config.status
chmod +x config.status
# ---------------------------------------------------------------------------

# ---------------------------------------------------------------------------
cat >config.status-t <<EOF
#! /bin/sh

# Original config.status is patched to satisfy processing *.in with 'make -j'.
# This bug seems to be partially fixed in autoconf-2.50 (not in all places).
UNIQUE_POSTFIX=\$\$

EOF
sed 's/conftest/conftest\${UNIQUE_POSTFIX}/g' <config.status >>config.status-t && \
mv config.status-t config.status
chmod +x config.status
# ---------------------------------------------------------------------------

eval my_bindir="`eval echo ${bindir}`"
eval my_mandir="`eval echo ${mandir}`"
eval my_moddir="`eval echo ${FVWM_MODULEDIR}`"; eval my_moddir="$my_moddir"
eval my_datdir="`eval echo ${FVWM_DATADIR}`"
eval my_plldir="`eval echo ${FVWM_PERLLIBDIR}`"
test x"$FVWM_PERLLIB" = x && my_plldir="(Not installed) $my_plldir"
eval my_localedir="`eval echo ${LOCALEDIR}`"
test x"$USE_NLS" = xno && my_localedir="(Not installed) $my_localdir"

case "$with_gtk" in
  yes) fvwmgtk_msg="
  With GDK image support in FvwmGtk?  $with_gdkimlib$problem_gdkimlib
  With GNOME libs support in FvwmGtk? $with_gnomelibs$problem_gnomelibs" ;;
  no) fvwmgtk_msg="" ;;
esac

echo "
FVWM Configuration:

  Version:     $VERSION$VERSIONINFO

  Executables: $my_bindir
  Man pages:   $my_mandir
  Modules:     $my_moddir
  Data files:  $my_datdir
  Perl lib:    $my_plldir
  Locale msg:  $my_localedir $INST_LINGUAS

  With Asian bi-direct. text support? $with_bidi$problem_bidi
  With Gettext Native Lang support?   $with_gettext$problem_gettext
  With GTK+ required for FvwmGtk?     $with_gtk$problem_gtk$fvwmgtk_msg
  With Iconv support?                 $with_iconv_type$problem_iconv
  With Mouse strokes (gestures)?      $with_stroke$problem_stroke
  With PNG image support?             $with_png$problem_png
  With ReadLine sup. in FvwmConsole?  $with_readline$problem_readline
  With RPlay support in FvwmEvent?    $with_rplay$problem_rplay
  With Shaped window support?         $with_shape$problem_shape
  With Shared memory for XImage?      $with_shm$problem_shm
  With Session Management support?    $with_sm$problem_sm
  With Xinerama multi-head support?   $with_xinerama$problem_xinerama
  With Xft anti-alias font support?   $with_xft$problem_xft
  With XPM image support?             $with_xpm$problem_xpm
  With Xrender image support?         $with_xrender$problem_xrender

See INSTALL.fvwm for the description of what this may mean."

case "$with_xinerama_emulation" in
  yes) echo "  Xinerama emulation enabled." ;;
esac
case "$ac_cv_dmalloc" in
  yes) echo "  DMALLOC heap debugging library enabled." ;;
esac
case "$ac_cv_efence" in
  yes) echo "  EFENCE debugging library enabled." ;;
esac
