#-------------------------------------------------------------------
#
# Process this file with autoconf to produce a configure script.
#
#-------------------------------------------------------------------

AC_INIT()
AC_PREREQ(2.4)

AC_CONFIG_HEADER(include/FVWMconfig.h)

CFLAGS=-O

#-------------------------------------------------------------------
#
# Remove the ./config.cache file and rerun configure if
# the cache file belong to a different architecture
#
#-------------------------------------------------------------------

AC_CHECK_PROG(UNAME, uname -a, [uname -a], "")
if test "$UNAME" = ""; then
    AC_CHECK_PROG(UNAME, uname, [uname], "")
fi

if test "$UNAME" != ""; then
    uname=`$UNAME`
    AC_MSG_CHECKING('checking cached value of \$uname')
    AC_CACHE_VAL(ac_cv_prog_uname, [nocached=1 ac_cv_prog_uname=`$UNAME`])
    if test "$nocached" = "1"; then
        AC_MSG_RESULT(no)
    else
        AC_MSG_RESULT(yes)
    fi

    if test "$uname" != "$ac_cv_prog_uname"; then
        echo "Running on a different architecture. Can't use cached values"
        echo "Removing config.cache and running configure again"
        rm -f config.cache
        exec $CMDLINE
    fi
fi


#-------------------------------------------------------------------
#
# Checks for programs.
#
#-------------------------------------------------------------------

AC_CHECK_PROG(AR, ar, ar cr, ar cr)
AC_CHECK_PROG(MAKEDEPEND, makedepend, makedepend, makedepend)
AC_CHECK_PROG(RM, rm, rm -f, rm -f)
AC_CHECK_PROG(XCLASS, xc-config, `xc-config --version`, no)
if test "$XCLASS" != "no"; then
	XC_CONFIG=xc-config
	AC_DEFINE(HAVE_XCLASS)
fi
AC_PROG_RANLIB
AC_PROG_MAKE_SET
AC_PROG_CC


#-------------------------------------------------------------------
#
# Check for OS specific
#
#-------------------------------------------------------------------

AC_AIX


#-------------------------------------------------------------------
#
# Checks for standard programs.
#
#-------------------------------------------------------------------

AC_PROG_CPP
AC_PROG_YACC
AC_PROG_LEX
AC_PROG_INSTALL
AC_PROG_LN_S


#-------------------------------------------------------------------
#
# Check for the existence of various libraries.  The order here
# is important, so that then end up in the right order in the
# command line generated by make.  The -lsocket and -lnsl libraries
# require a couple of special tricks:
#
#   1. Use "connect" and "accept" to check for -lsocket, and
#      "gethostbyname" to check for -lnsl.
#   2. Use each function name only once:  can't redo a check because
#      autoconf caches the results of the last check and won't redo it.
#   3. Use -lnsl and -lsocket only if they supply procedures that
#      aren't already present in the normal libraries.  This is because
#      IRIX 5.2 has libraries, but they aren't needed and they're
#      bogus:  they goof up name resolution if used.
#   4. On some SVR4 systems, can't use -lsocket without -lnsl too.
#      To get around this problem, check for both libraries together
#      if -lsocket doesn't work by itself.
#
# Need to check for Xpm and rplay
#
#-------------------------------------------------------------------

AC_CHECK_LIB(Xbsd, main, [LIBS="$LIBS -lXbsd"])

fvwm95_checkBoth=0
AC_CHECK_FUNC(connect, fvwm95_checkSocket=0, fvwm95_checkSocket=1)
if test "$fvwm95_checkSocket" = 1; then
    AC_CHECK_LIB(socket, main, LIBS="$LIBS -lsocket", fvwm95_checkBoth=1)
fi
if test "$fvwm95_checkBoth" = 1; then
    fvwm95_oldLibs=$LIBS
    LIBS="$LIBS -lsocket -lnsl"
    AC_CHECK_FUNC(accept, fvwm95_checkNsl=0, [LIBS=$fvwm95_oldLibs])
fi
AC_CHECK_FUNC(gethostbyname, , AC_CHECK_LIB(nsl, main, [LIBS="$LIBS -lnsl"]))


#-------------------------------------------------------------------
#
# Checks for header files.
#
#-------------------------------------------------------------------

AC_HEADER_STDC


#-------------------------------------------------------------------
#
# Checks for typedefs, structures, and compiler characteristics.
#
#-------------------------------------------------------------------

AC_C_CONST
AC_C_INLINE


#-------------------------------------------------------------------
#
# Checks for library functions.
#
#-------------------------------------------------------------------

# AC_CHECK_FUNCS(select)
AC_CHECK_FUNCS(gethostname waitpid sysconf uname)
AC_CHECK_FUNCS(strerror strcasecmp strncasecmp)


#===================================================================

#-------------------------------------------------------------------
# 
# Check for X11
#
#-------------------------------------------------------------------

AC_PATH_X


#-------------------------------------------------------------------
#
# Hard coded fvwm config stuff
#
#-------------------------------------------------------------------

fvwm_name="fvwm95"
fvwm_rc=".fvwm95rc"
fvwm_icons="$x_includes/X11/bitmaps:$x_includes/X11/pixmaps:$prefix/icons"

if test "x$x_libraries" != x ; then
  x_libraries="-L$x_libraries"
fi
if test "x$x_includes" != x ; then
  x_includes="-I$x_includes"
fi


#-------------------------------------------------------------------
#
# export variables
#
#-------------------------------------------------------------------

AC_SUBST(LIBS)
AC_SUBST(x_libraries)
AC_SUBST(x_includes)
AC_SUBST(fvwm_icons)
AC_SUBST(fvwm_name)
AC_SUBST(fvwm_rc)


#-------------------------------------------------------------------
#
# always build Makefiles in examples subdir
# so user can manually build programs when needed.
#
#-------------------------------------------------------------------

AC_OUTPUT(Makefile \
          docs/Makefile \
          fvwm/Makefile \
          libs/Makefile \
          mini-icons/Makefile \
          pixmaps/Makefile \
          utils/Makefile \
          xpmroot/Makefile \
          sample.fvwmrc/Makefile \
          sample.fvwmrc/system.fvwm95rc \
          modules/Makefile \
          modules/FvwmAudio/Makefile \
          modules/FvwmAuto/Makefile \
          modules/FvwmBacker/Makefile \
          modules/FvwmBanner/Makefile \
          modules/FvwmButtons/Makefile \
          modules/FvwmConsole/Makefile \
          modules/FvwmCpp/Makefile \
          modules/FvwmDebug/Makefile \
          modules/FvwmForm/Makefile \
          modules/FvwmIconBox/Makefile \
          modules/FvwmIconMan/Makefile \
          modules/FvwmIdent/Makefile \
          modules/FvwmM4/Makefile \
          modules/FvwmPager/Makefile \
          modules/FvwmSave/Makefile \
          modules/FvwmSaveDesk/Makefile \
          modules/FvwmScript/Makefile \
          modules/FvwmScript/Widgets/Makefile \
          modules/FvwmScript/Scripts/Makefile \
          modules/FvwmScroll/Makefile \
          modules/FvwmTalk/Makefile \
          modules/FvwmTaskBar/Makefile \
          modules/FvwmWharf/Makefile \
          modules/FvwmWinList/Makefile)


#-------------------------------------------------------------------
#
# Hasta la vista!
#
#-------------------------------------------------------------------

