dnl# -*- sh -*-
dnl# Process this file with autoconf to produce a configure script.
dnl#
dnl#Copyright (c) 1998 Michal Vitecek <fuf@fuf.sh.cvut.cz>
dnl#Copyright (c) 1998 Sasha Vasko <sashav@sprintmail.com>
dnl#Copyright (c) 1998 Juergen Sawinski <Juergen.Sawinski@urz.uni-heidelberg.de>
dnl#Copyright (c) 1997 1998 Guylhem AZNAR <guylhem@oeil.qc.ca>

AC_INIT(afterstep/autoexec.in)
AC_CONFIG_AUX_DIR(autoconf)
AC_CONFIG_HEADER(config.h:autoconf/config.h.in)

version="1.7.25"

dnl# Setup command-line options

dnl# we need the standard prefixes defined early
test "x$prefix" = xNONE && prefix=$ac_default_prefix
test "x$exec_prefix" = xNONE && exec_prefix="$prefix"
eval "bindir=$bindir"
eval "datadir=$datadir"
eval "mandir=$mandir"
eval "libdir=$libdir"

dnl# directories
AC_ARG_WITH(gnustep_dir,	[  --with-gnustep-dir=DIR  GNUstep directory [~/GNUstep] ],with_gnustep_dir=$withval, with_gnustep_dir="~/GNUstep")
AC_ARG_WITH(gnustep_lib,	[  --with-gnustep-lib=DIR  GNUstep/Library directory [Library] ],with_gnustep_lib=$withval, with_gnustep_lib="Library")
AC_ARG_WITH(afterdir,		[  --with-afterdir=DIR     user AfterStep dir [AfterStep] ],with_afterdir=$withval, with_afterdir="AfterStep")

dnl# helper apps
AC_ARG_WITH(imageloader,	[  --with-imageloader=APP  used to display non-XPMs [xli -onroot -quiet] ],with_imageloader=$withval, with_imageloader="xli -onroot -quiet -colors 20")
AC_ARG_WITH(helpcommand,	[  --with-helpcommand=APP  display manpage for window [xiterm -e man] ],with_helpcommand=$withval, with_helpcommand="xiterm -e man")

dnl# look defaults
AC_ARG_WITH(startsort,		[  --with-startsort=METHOD start menu sorting method [SORTBYALPHA] ],with_startsort=$withval, with_startsort="SORTBYALPHA")
AC_ARG_ENABLE(different_looknfeels, [  --enable-different-looknfeels 
                          different look&feel for each desktop [no] ],enable_different_looknfeels=$enableval,enable_different_looknfeels="no")
AC_ARG_WITH(desktops,		[  --with-desktops=DESKS   default desktops in pager [4] ],with_desktops=$withval, with_desktops="4")
AC_ARG_WITH(deskgeometry,	[  --with-deskgeometry=GEOM desktop views as COLUMNSxROWS [2x2] ],with_deskgeometry=$withval, with_deskgeometry="2x2")
with_desktops_1=`expr ${with_desktops} - 1`

dnl# compile-time switches
AC_ARG_ENABLE(newlook,		[  --enable-newlook        support new look options (MyStyles) [yes] ],enable_newlook=$enableval,enable_newlook="yes")
AC_ARG_ENABLE(pagerbackground,	[  --enable-pagerbackground provide background support with the Pager [yes] ],enable_pagerbackground=$enableval,enable_pagerbackground="yes")
AC_ARG_ENABLE(iconbackground,	[  --enable-iconbackground icon backgrounds, limits icons to 64x64 [no] ],enable_iconbackground=$enableval,enable_iconbackground="no")
AC_ARG_ENABLE(i18n,		[  --enable-i18n           support I18N [no] ],enable_i18n=$enableval,enable_i18n="no")
AC_ARG_ENABLE(xlocale,		[  --enable-xlocale        using X_LOCALE [no] ],enable_xlocale=$enableval,enable_xlocale="no")
AC_ARG_ENABLE(menuwarp,		[  --enable-menuwarp       warp mouse pointer to menus [no] ],enable_menuwarp=$enableval,enable_menuwarp="no")
AC_ARG_ENABLE(savewindows,	[  --enable-savewindows    save windows and re-open next session [yes] ],enable_savewindows=$enableval,enable_savewindows="yes")
AC_ARG_ENABLE(makemenus,	[  --enable-makemenus      make the start menu from the start/ tree [yes] ],enable_makemenus=$enableval,enable_makemenus="yes")
AC_ARG_ENABLE(makemenusonboot,	[  --enable-makemenusonboot always make the start menu when starting AS [no] ],enable_makemenusonboot=$enableval,enable_makemenusonboot="no")
AC_ARG_ENABLE(texture,		[  --enable-texture        support gradient, XPM, and JPEG textures [yes] ],enable_texure=$enableval,enable_texture="yes")
AC_ARG_ENABLE(shade,		[  --enable-shade          support shaded windows [yes] ],enable_shade=$enableval,enable_shade="yes")
AC_ARG_ENABLE(virtual,		[  --enable-virtual        support virtual desktops [yes] ],enable_virtual=$enableval,enable_virtual="yes")
AC_ARG_ENABLE(saveunders,	[  --enable-saveunders     request saveunders for menus [yes] ],enable_saveunders=$enableval,enable_saveunders="yes")
AC_ARG_ENABLE(windowlist,	[  --enable-windowlist     compile built-in window-list [yes] ],enable_windowlist=$enableval,enable_windowlist="yes")
AC_ARG_ENABLE(availability,	[  --enable-availability   check for unavailable binaries [yes] ],enable_availability=$enableval,enable_availability="yes")
AC_ARG_ENABLE(fixeditems,	[  --enable-fixeditems     enable fixed menu entries [no] ], enable_fixeditems=$enableval,enable_fixeditems="no")

AC_ARG_WITH(locale,		[  --with-locale=LOCALE    locale name you want to use ],with_locale=$withval,with_locale="")
AC_ARG_ENABLE(shaping,		[  --enable-shaping        support shaped windows [yes] ],enable_shaping=$enableval,enable_shaping="yes")
AC_ARG_ENABLE(staticlibs,       [  --enable-staticlibs     enable linking to libafterstep statically [yes] ],enable_staticlibs=$enableval,enable_staticlibs="yes")

AC_ARG_ENABLE(gdb,		[  --enable-gdb            add gdb symbols to binaries (-g) [no] ],enable_gdb=$enableval,enable_gdb="yes")
AC_ARG_ENABLE(gprof,		[  --enable-gprof          add gprof symbols to binaries (-pg) [no] ],enable_gprof=$enableval,enable_gprof="yes")

AC_ARG_ENABLE(script,		[  --enable-script         compile Script module [yes] ], enable_script=$enableval,enable_script="yes")


dnl# Check for compiler tools

AC_PROG_CC
AC_PROG_INSTALL
dnl# if the path to the install program is relative, make it absolute
currdir=`pwd`
INSTALL=`echo $INSTALL|sed -e "s@\^\.\.@${currdir}@" -e "s@^autoconf@${currdir}/autoconf@"`
INSTALL_PROGRAM=`echo $INSTALL_PROGRAM|sed -e "s@\^\.\.@${currdir}@" -e "s@^autoconf@${currdir}/autoconf@"`
INSTALL_DATA=`echo $INSTALL_DATA|sed -e "s@\^\.\.@${currdir}@" -e "s@^autoconf@${currdir}/autoconf@"`
INSTALL_LIB=`echo $INSTALL_LIB|sed -e "s@\^\.\.@${currdir}@" -e "s@^autoconf@${currdir}/autoconf@"`

AC_PROG_RANLIB
AC_PATH_PROG(RM, rm, rm)
AC_PATH_PROG(MV, mv, mv)
AC_PATH_PROG(CP, cp, cp)
AC_PATH_PROG(MKDIR, mkdir, mkdir)

dnl# Construct Gnu/AfterStep path from pieces
with_gnustep_lib=${with_gnustep_dir}/${with_gnustep_lib}
with_afterdir=${with_gnustep_lib}/${with_afterdir} 

dnl# Remove -g

if test -n "`echo $CFLAGS' ' | grep '\-g ' 2> /dev/null`" ; then
  CFLAGS=`echo "$CFLAGS " | sed "s/-g / /"`
fi

dnl# Add -Wall

if test "x$GCC" = "xyes"; then
  if test -z "`echo $CFLAGS | grep '\-Wall' 2> /dev/null`" ; then
    CFLAGS="$CFLAGS -Wall"
  fi
fi

dnl# Add -g

if test "x$enable-gdb" = "xyes"; then
  CFLAGS="$CFLAGS -g"
  LDFLAGS="$LDFLAGS -g"
fi

dnl# Add -pg

if test "x$enable-gprof" = "xyes"; then
  CFLAGS="$CFLAGS -pg"
  LDFLAGS="$LDFLAGS -pg"
fi

dnl# Check for headers

AC_PATH_XTRA
AC_HEADER_DIRENT
AC_HEADER_TIME
AC_CHECK_HEADERS(sys/wait.h sys/time.h)

dnl# Checks for optional programs

AC_PROG_LEX
AC_PROG_YACC
AC_CHECK_PROG(sgmltools, sgmltools, HAVE_SGMLTOOLS, NO_SGMLTOOLS)

dnl# Checks for functions

AC_FUNC_WAIT3
AC_CHECK_FUNCS(uname gethostname)

dnl# Check for X

saved_cflags="$CFLAGS"
saved_ldflags="$LDFLAGS"

CFLAGS="$CFLAGS $X_CFLAGS"
LDFLAGS="$LDFLAGS $X_LDFLAGS $X_LIBS"

x_libs="$LDFLAGS $X_EXTRA_LIBS $X_PRE_LIBS"
AC_CHECK_LIB(X11, XOpenDisplay, [x_libs="-lX11 $x_libs"],,$x_libs)

dnl# Check for XPM library

VT_FIND_LIBXPM
HAVEXPM="NOXPM"
if test "x$have_xpm" = "xyes"; then
  HAVEXPM="XPM"
  x_libs="$x_libs $XPM_LIBS"
  AC_CHECK_LIB(Xpm, XpmWriteFileFromPixmap, [have_xpm_write="1"],[have_xpm_write="0"],$x_libs)
fi
for x in $X_CFLAGS; do
  XPM_CFLAGS=`echo " $XPM_CFLAGS " | sed "s@ $x @ @"`
done

dnl# Check for X shaped window extension

HAVESHAPE="NOSHAPE"
if test "x$enable_shaping" = "xyes"; then
  AC_CHECK_LIB(Xext, XShapeCombineMask, [x_libs="$x_libs -lXext" HAVESHAPE="SHAPE"],,$x_libs)
fi

CFLAGS="$saved_cflags"
LDFLAGS="$saved_ldflags"
saved_LIBS=$LIBS
LIBS=""

dnl# Check for libjpeg

VT_FIND_LIBJPEG
HAVEJPEG="NOJPEG"
if test "x$have_jpeg" = "xyes"; then
  HAVEJPEG="JPEG"
else
  echo "You need the libJPEG v 6.0 or later, in order to use JPEG support in AfterStep";  
fi
for x in $X_CFLAGS; do
  JPEG_CFLAGS=`echo " $JPEG_CFLAGS " | sed "s@ $x @ @"`
done

CFLAGS="$saved_cflags"
LDFLAGS="$saved_ldflags"
LIBS=""

dnl# Check for libpng

VT_FIND_LIBPNG
HAVEPNG="NOPNG"
if test "x$have_png" = "xyes"; then
  HAVEPNG="PNG"
else
  echo "You need the libPNG v 1.0.2 or later, in order to use PNG support in AfterStep";  
fi
for x in $X_CFLAGS; do
  PNG_CFLAGS=`echo " $PNG_CFLAGS " | sed "s@ $x @ @"`
done

dnl# remove the same include directories for png and jpeg
if test "x$have_jpeg$have_png" = "xyesyes"; then
  if test "x$PNG_CFLAGS" = "x$JPEG_CFLAGS"; then
    PNG_CFLAGS=""
  fi
fi

LIBS=$saved_LIBS

dnl# AFTERSTEP_LIB="-lafterstep" 
dnl# ASIMAGE_LIB="-lasimage"
dnl# WIDGETS_LIB="-lWidgets"
if test "x$enable_staticlibs" = "xyes"; then
   AFTERSTEP_LIB="../../lib/libafterstep.a" 
   ASIMAGE_LIB="../../asimagelib/libasimage.a"
   WIDGETS_LIB="../Script/Widgets/libWidgets.a"
   LIBPROG='$(PROG)'
   LIBINSTALL=""
else
   AFTERSTEP_LIB="../../lib/libafterstep.so" 
   ASIMAGE_LIB="../../asimagelib/libasimage.so"
   WIDGETS_LIB="../Script/Widgets/libWidgets.so"
   LIBPROG='$(DYNPROG)'
   LIBINSTALL="install.dyn"
fi

dnl# define X_LOCALE.  need Linux, NetBSD and etc.

if test "x$enable_xlocale" = "xyes"; then
  DEFINE_XLOCALE="-DX_LOCALE"
fi

dnl# Translate enable_* from "yes/no" to "1/0" (for configure.h)

if test "x$enable_different_looknfeels" = "xyes"; then enable_different_looknfeels="1"; else enable_different_looknfeels="0";fi
if test "x$enable_newlook" = "xyes"; then enable_newlook="1"; else enable_newlook="0"; fi
if test "x$enable_pagerbackground" = "xyes"; then enable_pagerbackground="1"; else enable_pagerbackground="0"; fi
if test "x$enable_iconbackground" = "xyes"; then enable_iconbackground="1"; else enable_iconbackground="0"; fi
if test "x$enable_i18n" = "xyes"; then enable_i18n="1"; else enable_i18n="0"; fi
if test "x$enable_menuwarp" = "xyes"; then enable_menuwarp="1"; else enable_menuwarp="0"; fi
if test "x$enable_savewindows" = "xyes"; then enable_savewindows="1"; else enable_savewindows="0"; fi
if test "x$enable_makemenus" = "xyes"; then enable_makemenus="1"; else enable_makemenus="0"; fi
if test "x$enable_makemenusonboot" = "xyes"; then enable_makemenusonboot="1"; else enable_makemenusonboot="0"; fi
if test "x$enable_texture" = "xyes"; then enable_texture="1"; else enable_texture="0"; fi
if test "x$enable_shade" = "xyes"; then enable_shade="1"; else enable_shade="0"; fi
if test "x$enable_virtual" = "xyes"; then enable_virtual="1"; else enable_virtual="0"; fi
if test "x$enable_saveunders" = "xyes"; then enable_saveunders="1"; else enable_saveunders="0"; fi
if test "x$enable_windowlist" = "xyes"; then enable_windowlist="1"; else enable_windowlist="0"; fi
if test "x$enable_availability" = "xyes"; then enable_availability="1"; else enable_availability="0"; fi
if test "x$enable_fixeditems" = "xyes"; then enable_fixeditems="1"; else enable_fixeditems="0"; fi
if test "x$enable_script" = "xyes"; then enable_script="1"; else enable_script="0"; fi

dnl# Variable strings declaration

dnl# don't process Script and its subdirs if it wasn't asked
SCRIPT_DIR=""
if test "x$enable_script" = "x1"; then
    SCRIPT_DIR="src/Script/Widgets src/Script"
fi

AC_SUBST(version)
AC_SUBST(with_locale)
AC_SUBST(HAVEXPM)
AC_SUBST(HAVESHAPE)
AC_SUBST(HAVEJPEG)
AC_SUBST(HAVEPNG)
AC_SUBST(XPM_LIBS)
AC_SUBST(have_xpm_write)
AC_SUBST(x_libs)
AC_SUBST(x_includes)
AC_SUBST(XEXT_LIB)
AC_SUBST(JPEG_LIBS)
AC_SUBST(PNG_LIBS)
AC_SUBST(AFTERSTEP_LIB)
AC_SUBST(ASIMAGE_LIB)
AC_SUBST(WIDGETS_LIB)
AC_SUBST(LIBPROG)
AC_SUBST(LIBINSTALL)
AC_SUBST(DEFINE_XLOCALE)
AC_SUBST(sgmltools)
AC_SUBST(with_gnustep_dir)
AC_SUBST(with_gnustep_lib)
AC_SUBST(with_afterdir)
AC_SUBST(with_imageloader)
AC_SUBST(with_helpcommand)
AC_SUBST(with_startsort)
AC_SUBST(with_desktops)
AC_SUBST(with_desktops_1)
AC_SUBST(with_deskgeometry)
AC_SUBST(enable_different_looknfeels)
AC_SUBST(enable_newlook)
AC_SUBST(enable_pagerbackground)
AC_SUBST(enable_iconbackground)
AC_SUBST(enable_i18n)
AC_SUBST(enable_menuwarp)
AC_SUBST(enable_savewindows)
AC_SUBST(enable_makemenus)
AC_SUBST(enable_makemenusonboot)
AC_SUBST(enable_texture)
AC_SUBST(enable_shade)
AC_SUBST(enable_virtual)
AC_SUBST(enable_saveunders)
AC_SUBST(enable_windowlist)
AC_SUBST(enable_availability)
AC_SUBST(enable_fixeditems)
AC_SUBST(SCRIPT_DIR)

dnl# Write results

AC_CONFIG_HEADER(config.h)

dnl# Common parts of the Makefile
MAKEFILEDEFINES=./autoconf/Makefile.defines
MAKEFILECOMMON=./autoconf/Makefile.common
MAKEFILECOMMONLIB=./autoconf/Makefile.common.lib

AC_SUBST_FILE(MAKEFILEDEFINES)
AC_SUBST_FILE(MAKEFILECOMMON)
AC_SUBST_FILE(MAKEFILECOMMONLIB)

AC_OUTPUT(\
autoconf/Makefile.defines \
autoconf/Makefile.common \
autoconf/Makefile.common.lib \
configure.h \
Makefile \
\
doc/Makefile \
doc/afterstepdoc \
\
lib/Makefile \
asimagelib/Makefile \
\
src/afterstep/Makefile \
src/Animate/Makefile \
src/Audio/Makefile \
src/Auto/Makefile \
src/Banner/Makefile \
src/Cascade/Makefile \
src/Clean/Makefile \
src/Form/Makefile \
src/Ident/Makefile \
src/Pager/Makefile \
src/Save/Makefile \
src/Script/Widgets/Makefile \
src/Script/Makefile \
src/Scroll/Makefile \
src/Sound/Makefile \
src/Tile/Makefile \
src/Wharf/Makefile \
src/WinList/Makefile \
src/Zharf/Makefile \
\
afterstep/base.8bpp \
afterstep/base.15bpp \
afterstep/base.16bpp \
afterstep/base.24bpp \
afterstep/base.32bpp \
afterstep/asmail \
afterstep/audio \
afterstep/autoexec \
afterstep/compatibility \
afterstep/pager \
afterstep/wharf \
afterstep/zharf \
afterstep/start/Desktop/Feel/.include \
afterstep/start/Desktop/Look/.include \
afterstep/start/Desktop/Pictures/.include \
afterstep/non-configurable/startmenu \
)

echo "


AfterStep $version is now hopefully configured:
Just run : make ; make install
"
