dnl
dnl template file to create configure script for DCL
dnl

configure.in:
AC_INIT
AC_CONFIG_SRCDIR([INSTALL])

AC_CONFIG_HEADERS([config.h])

DCLVERSION=7.5.3
DCLVERNUM=753
dnl #if FORTRAN
DCLLANG=f77
dnl #elif C
dnl DCLLANG=c
dnl #endif

DCLNWS=2

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
DCL_PROG_FC
dnl #elif C
dnl DCL_PROG_FC_for_C
dnl #endif

dnl Check LaTeX program
DCL_PROG_JLATEX
DCL_PROG_DVIPDF


dnl shared library
dnl #if FORTRAN
TODO_SHARED_LIBRARY=
LINKOPT=
EXTSHLIB=dummy
AC_SUBST(TODO_SHARED_LIBRARY)
AC_SUBST(LINKOPT)
AC_SUBST(EXTSHLIB)
dnl #elif C
dnl 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
DCL_CHECK_OSLIB_OPTIONS
dnl #elif C
dnl OSGARG_OPT=getarg
dnl OSQARN_OPT=iargc
dnl AC_SUBST(OSGARG_OPT)
dnl AC_SUBST(OSQARN_OPT)
dnl #endif

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

dnl DCLDIR
DCL_SET_DCLDIR

dnl bitlib
dnl #if FORTRAN
DCL_FORTRAN_TYPES
dnl #endif

DCL_CHECK_VALUES
DCL_CHECK_CLOCK_VALUES

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

AC_SUBST(DCLNWS)

# Checks for libraries.
#PKG_PROG_PKG_CONFIG
AC_ARG_WITH([gtk4], AS_HELP_STRING([--with-gtk4], [Build using GTK+ 4.0 (not yet)]), [with_gtk4=yes], [with_gtk4=no])
AC_ARG_WITH([gtk3], AS_HELP_STRING([--with-gtk3], [Build using GTK+ 3.0 (default)]), [with_gtk3=yes], [with_gtk3=no])
AC_ARG_WITH([gtk2], AS_HELP_STRING([--with-gtk2], [Build using GTK+ 2.0]), [with_gtk2=yes], [with_gtk2=no])
AC_ARG_WITH([socket], AS_HELP_STRING([--with-socket], [Build without GTK+ (Using Socket)]), [with_socket=yes], [with_socket=no])

AS_IF([test "x$with_socket" = "xyes"],[
    GTK_CFLAGS=""
    GTK_LIBS=""
    GTKVERSION=""
    DRV_EXT="socket"
    ],
    [
        AS_IF([test "x$with_gtk2" = "xyes"], [
            PKG_CHECK_MODULES([GTK2], [gtk+-2.0],[AC_DEFINE([HAVE_GTK2], [1], [Define if using GTK+2])
            GTK_CFLAGS=${GTK2_CFLAGS}
            GTK_LIBS=${GTK2_LIBS}
            GTKVERSION=2
            DRV_EXT="gtk"])
        ],
            [
            AS_IF([test "x$with_gtk3" = "xyes"], [
                PKG_CHECK_MODULES([GTK3], [gtk+-3.0],[AC_DEFINE([HAVE_GTK3], [1], [Define if using GTK+3])
                GTK_CFLAGS=${GTK3_CFLAGS}
                GTK_LIBS=${GTK3_LIBS}
                GTKVERSION=3
                DRV_EXT="gtk"])
                ],
                  [
            AS_IF([test "x$with_gtk4" = "xyes"], [
                PKG_CHECK_MODULES([GTK4], [gtk4],[AC_DEFINE([HAVE_GTK4], [1], [Define if using GTK+4])
                GTK_CFLAGS=${GTK4_CFLAGS}
                GTK_LIBS=${GTK4_LIBS}
                GTKVERSION=4
                DRV_EXT="gtk"])
                ],
                  [
                  PKG_CHECK_MODULES([GTK3], [gtk+-3.0])
                  GTK_CFLAGS=${GTK3_CFLAGS}
                  GTK_LIBS=${GTK3_LIBS}
                  GTKVERSION=3
                  DRV_EXT="gtk"
                  ]
            )
                  ]
            )
         ])
])

AC_SUBST(GTK_CFLAGS)
AC_SUBST(GTK_LIBS)
AC_SUBST(GTKVERSION)
AC_SUBST(DRV_EXT)

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}
}

AC_CONFIG_FILES([Mkinclude Makefile])
AC_OUTPUT
