dnl Process this file with autoconf to produce a configure script.
AC_INIT(elmerpost, 5.0.1, jpr@csc.fi)

AC_CONFIG_SRCDIR([src/ElmerPost.c])
AC_CONFIG_HEADER([config.h])

AC_CANONICAL_HOST
AC_CANONICAL_TARGET

sinclude(acx_elmer.m4)
ACX_DEBUG
ACX_HOST
ACX_PLATFORM_DEFS

AM_INIT_AUTOMAKE
AM_MAINTAINER_MODE

# Checks for programs.

AC_PROG_CC([xlc pathcc icc cc gcc])
AC_PROG_CXX([xlC pathCC icc CC g++])
AC_PROG_CPP
AC_PROG_FC([xlf90 pathf90 ifort ifc f90 g95])

AC_PROG_RANLIB

ACX_CHECK_B64FLAGS

AC_FC_WRAPPERS
ACX_FC_CHAR_MANGLING

LIBS="-L. $LIBS -L$prefix/lib"
LDFLAGS="-L. $LDFLAGS -L$prefix/lib"
CFLAGS="$CFLAGS -I$prefix/include"
FCFLAGS="$FCFLAGS -I. -I$prefix/include"
FFFLAGS="$FCFLAGS -I. -I$prefix/include"

ACX_MATC([],[AC_MSG_ERROR([Couldn't link to MATC, make sure that libmatc is available and it works with your compiler.])])

# Checks for libraries.
# MATC

# Checks for header files.
AC_PATH_X
AC_HEADER_STDC
AC_CHECK_HEADERS([malloc.h stdlib.h string.h strings.h sys/param.h sys/time.h termio.h])

sinclude(acx_gl.m4)
ACX_CHECK_GL
ACX_CHECK_GLU
ACX_TCLTK([],[AC_MSG_ERROR([Tcl/tk not found, use TCLTK_LIBS environment variable or --with-tcltk="-L/path/to/ -ltcl8.4 -ltk8.4" to point to it's location.])])
CPPFLAGS="$CPPFLAGS $TCLTK_INCLUDE"

# Checks for typedefs, structures, and compiler characteristics.
AC_TYPE_SIZE_T
AC_HEADER_TIME
AC_HEADER_STDBOOL

# Checks for library functions.
AC_FUNC_ERROR_AT_LINE
AC_FUNC_MALLOC
AC_FUNC_REALLOC
AC_TYPE_SIGNAL
AC_FUNC_STAT
AC_CHECK_FUNCS([floor gettimeofday memset sqrt strerror])

ACX_SHLIB_STUFF
AC_SUBST(SH_LDFLAGS)
AC_SUBST(SH_LD)

AC_DEFINE_UNQUOTED(ELMER_POST_HOME,"${prefix}/share/elmerpost", [Elmer post default install directory])

AM_CONDITIONAL(NOTWINDOWS, test "$acx_platform_def" != "WIN32")

LIBS="$LIBS $GL_LIBS $GLU_LIBS $MATC_LIBS $TCLTK_LIBS"
CFLAGS="$CFLAGS $GL_CFLAGS $GLU_CFLAGS"
CXXFLAGS="$CXXFLAGS $GL_CFLAGS $GLU_CFLAGS"

AC_CONFIG_FILES([Makefile
                 src/Makefile
                 src/camera/Makefile
                 src/elements/Makefile
                 src/graphics/Makefile
                 src/modules/Makefile
                 src/objects/Makefile
                 src/sico2elmer/Makefile
                 src/glaux/Makefile
                 src/tk/Makefile
                 src/tcl/Makefile
                 src/visuals/Makefile])
AC_OUTPUT

AC_MSG_RESULT([
ElmerPost build options:
  Version                   $VERSION
  Install prefix            $prefix
  CFLAGS                    $CFLAGS
  CXXFLAGS                  $CXXFLAGS
  FCFLAGS                   $FCFLAGS

  LDFLAGS                   $LDFLAGS
  LIBS                      $LIBS

Compilers:
  Fortran 90 compiler       $FC
  CC                        $CC
  C++                       $CXX

Libs:  
  OpenGL                    $GL_LIBS $GLU_LIBS
  MATC			    $MATC_LIBS
  Tcl/Tk		    $TCLTK_LIBS

])

