dnl 
dnl template file to create configure script for DCL
dnl

configure.in:
AC_INIT(INSTALL)

AC_CONFIG_HEADER(config.h)

DCLVERSION=5.4.8
DCLVERNUM=548
dnl #if FORTRAN
dnl DCLLANG=f77
dnl #elif C
DCLLANG=c
dnl #endif

DCLNWS=3

CFLAGS=${CFLAGS--O}
FFLAGS=${FFLAGS--O}

DCL_PROG_CC
AC_PROG_CPP
DCL_PROG_AWK
DCL_PROG_SED
AC_PROG_RANLIB

dnl Check Fortran Compiler
dnl #if FORTRAN
dnl DCL_PROG_FC
dnl #elif C
DCL_PROG_FC_for_C
dnl #endif

dnl Check LaTeX program
dnl DCL_PROG_JLATEX
dnl DCL_PROG_DVIPS

dnl X Window System files.
AC_SUBST(X_INCLUDES)
AC_SUBST(X_LIBRARIES)
AC_PATH_X
if test "$no_x" = yes; then
  X_INCLUDES= X_LIBRARIES= 
else
  if test -n "$x_includes"; then
    X_INCLUDES="-I$x_includes"
  fi
  X_LIBRARIES="-lX11"
  AC_DEFINE(X11)
fi
AC_PATH_XTRA

dnl shared library
dnl #if FORTRAN
dnl TODO_SHARED_LIBRARY=
dnl LINKOPT=
dnl EXTSHLIB=dummy
dnl AC_SUBST(TODO_SHARED_LIBRARY)
dnl AC_SUBST(LINKOPT)
dnl AC_SUBST(EXTSHLIB)
dnl #elif C
DCL_SHARED
dnl #endif

AC_SUBST(CFLAGS)

dnl old src
AC_SUBST(OLDSRC)
AC_ARG_WITH(oldsrc,dnl
[  --with-oldsrc           compile dcl source codes older than ver.5],
if test "$withval" = yes; then OLDSRC=oldsrc; \
else OLDSRC=; fi, OLDSRC=
)dnl

dnl OSLIB
dnl #if FORTRAN
dnl DCL_CHECK_OSLIB_OPTIONS
dnl #elif C
OSGARG_OPT=getarg
OSQARN_OPT=iargc
AC_SUBST(OSGARG_OPT)
AC_SUBST(OSQARN_OPT)
dnl #endif

dnl CSGI
dnl #if FORTRAN
dnl DCL_CHECK_CSGI
dnl #elif C
DCL_CHECK_CSGI_C
dnl #endif

dnl DCLDIR
DCL_SET_DCLDIR

dnl bitlib
dnl #if FORTRAN
dnl DCL_FORTRAN_TYPES
dnl #endif

DCL_CHECK_VALUES
DCL_CHECK_CLOCK_VALUES

AC_SUBST(DCLVERSION)
AC_SUBST(DCLVERNUM)
AC_SUBST(DCLLANG)

AC_SUBST(DCLNWS)

dnl GTK2
GTKVERSION="no"
AC_SUBST(GTKVERSION)
AC_ARG_ENABLE(gtk2, [  --disable-gtk2   Do not try to compile with GTK2],
		    , enable_gtk2=yes)

expunge () {
  list=$1

  list=`reverse_list ${list}`

  newlist=""
  for arg in ${list}
  do
    return=`echo ${newlist} | grep -- ${arg}`
    if test -z "${return}" ; then
      newlist="${arg} ${newlist}"
    fi
  done

  echo ${newlist}
}

reverse_list () {
  newlist=""
  for arg in $*
  do
    newlist="${arg} ${newlist}"
  done
  echo ${newlist}
}

if test "$enable_gtk2" = "yes" ; then
   AM_PATH_GTK_2_0
   if test x"$no_gtk" = x ; then
      ac_save_CPPFLAGS="$CPPFLAGS"
      CPPFLAGS="$GTK_CFLAGS"
      AC_CHECK_HEADER(gtk/gtk.h, AC_DEFINE(HAVE_GTK_H),
                      AC_MSG_WARN(gtk/gtk.h is not found.))
      CPPFLAGS="$ac_save_CPPFLAGS"
      GTKVERSION="2"
      DCLNWS="4"

      dnl check gdk-pixbuf
      AM_PATH_GDK_PIXBUF_2_0
      if test x"$no_gdk_pixbuf" = x ; then
	 ac_save_CPPFLAGS="$CPPFLAGS"
	 CPPFLAGS="$GDK_PIXBUF_CFLAGS"
	 AC_CHECK_HEADER(gdk-pixbuf/gdk-pixbuf.h, AC_DEFINE(HAVE_GDK_PIXBUF_H),
                         AC_MSG_WARN(gdk-pixbuf/gdk-pixbuf.h is not found.))
	 CPPFLAGS="$ac_save_CPPFLAGS"
	 GTK_CFLAGS="$GTK_CFLAGS $GDK_PIXBUF_CFLAGS"
	 GTK_LIBS="$GTK_LIBS $GDK_PIXBUF_LIBS"
       fi
   fi
fi

if test "$GTKVERSION" = "no"; then
   AC_ARG_ENABLE(gtk, [  --disable-gtk   Do not try to compile with GTK],
		   , enable_gtk=yes)
   if test "$enable_gtk" = "yes" ; then
      AM_PATH_GTK
      if test x"$no_gtk" = x ; then
	 ac_save_CPPFLAGS="$CPPFLAGS"
	 CPPFLAGS="$GTK_CFLAGS"
	 AC_CHECK_HEADER(gtk/gtk.h, AC_DEFINE(HAVE_GTK_H),
	                 AC_MSG_WARN(gtk/gtk.h is not found.))
	 CPPFLAGS="$ac_save_CPPFLAGS"
	 GTKVERSION="1"
         DCLNWS="4"

         dnl check gdk-imlib
	 AM_PATH_GDK_IMLIB
	 if test x"$no_imlib" = x ; then
	    GTK_CFLAGS="$GTK_CFLAGS $GDK_IMLIB_CFLAGS"
	    GTK_LIBS="$GTK_LIBS $GDK_IMLIB_LIBS"
	    ac_save_CPPFLAGS="$CPPFLAGS"
	    CPPFLAGS="$GDK_IMLIB_CFLAGS"
	    AC_CHECK_HEADER(gdk_imlib.h, AC_DEFINE(HAVE_GDK_IMLIB_H),
                            AC_MSG_WARN(gdk_imlib.h is not found.))
	    CPPFLAGS="$ac_save_CPPFLAGS"
         fi
      fi
   fi
fi

GTK_CFLAGS=`expunge "${GTK_CFLAGS}"`
GTK_LIBS=`expunge "${GTK_LIBS}"`

if test "$GTKVERSION" = "no"; then
   GTK_CFLAGS=""
   GTK_LIBS=""
fi


AC_OUTPUT(Mkinclude Makefile)
