twice_lib=`dirname $(find $2 -name "lib$1.a" | sed 1q)dnl Process this file with autoconf to produce a configure script.

AC_INIT(../Base/CPPExtern.h)
AM_INIT_AUTOMAKE(gem, 0.73)
dnl VERSION=0.73
dnl PACKAGE=gem
AC_SUBST(VERSION)
AC_SUBST(PACKAGE)


dnl check for architecture
dnl ***********************************************************************


AC_CANONICAL_HOST

ttarget=pd_`echo $host_os | sed /.*/s/-.*//`
target=`echo $ttarget | sed -e 's/\[.].*//'`

echo Configuring for Gem.$target
AC_SUBST(target)



dnl Check for make version


AC_SUBST_FILE(build_rules)


echo $ac_n "checking for gnu make""... $ac_c"  1>&6

ac_make_gnu=`make -v | sed /GNU/p`
if test "$ac_make_gnu" != ""; then
  ac_make_gnu="yes";
  build_rules="Config.gnumake"
  echo $ac_t "yes";
else 
  ac_make_gnu="no";
  build_rules="Config.make"
  echo $ac_t "no";
fi



dnl Checks for programs.
dnl ***********************************************************************

AC_PROG_CXX
#case $target in 
#pd_irix*)
#    echo $ac_n "checking for irix C++ compiler""... $ac_c" 1>&6

#    if test "${GXX+set}" = set; then 
#      echo $ac_t yes;
#      echo "adding flags for irix CC compiler";
#      CXXFLAGS="$CXXFLAGS -o32 -mips2 -xansi -woff 3157,3173";
#    else
#      echo $ac_t no;
#    fi;;
#esac


AC_PROG_CC
AC_SUBST(CC)
AC_PROG_INSTALL
AC_PROG_MAKE_SET
AC_CHECK_PROGS(shell_prog,sh)

AC_PATH_XTRA



dnl Checks for libraries.
dnl ***********************************************************************



source_dirs="../Base ../Geos ../Nongeos ../Controls ../Manips ../Pixes"
AC_SUBST(source_dirs)

LIBTOOL=""
AC_SUBST(LIBTOOL)


arch_ld_flags="-shared"
AC_SUBST(arch_ld_flags)

if test "$x_libraries" != ""; then
LDFLAGS="$LDFLAGS -L$x_libraries";
fi

AC_CHECK_LIB(X11,main)
AC_CHECK_LIB(Xext,main)

AC_CHECK_LIB(m,sin)

dnl 
dnl  The following libraries are not that common, so they are looked for
dnl  in two different places
dnl  1) in the system
dnl  2) in the gem distribution
dnl

search_libs="../../.."

dnl
dnl Check for tiff
dnl

      AC_CHECK_LIB_TWICE(tiff,$search_libs)

dnl
dnl Check for Jpeg
dnl

     AC_CHECK_LIB_TWICE(jpeg,$search_libs)

dnl
dnl Check for gltt
dnl

     AC_CHECK_LIB_TWICE(gltt,$search_libs)

dnl
dnl Check for ttf
dnl

     AC_CHECK_LIB_TWICE(ttf,$search_libs)

dnl
dnl Check for td 
dnl 

     AC_CHECK_LIB_TWICE(td,$search_libs)


dnl
dnl
dnl Check for Open GL (Original or Mesa)
dnl
dnl

AC_CHECK_LIB(GL,
	     glInitNames,
             ,
             AC_CHECK_LIB(MesaGL,glInitNames,,
                          echo "OpenGL is mandatory";exit 1)
            )
                                                
AC_CHECK_LIB(GLU,
             gluLookAt,
             ,
             AC_CHECK_LIB(MesaGLU,gluLookAt,,
                          echo "incomplete OpenGL (no GLU)";exit 1)
             )                                                 


dnl Check for sgi vl library


AC_CHECK_LIB(vl,main,
             SGI_SPECIFIC="pix_videoSGI.o pix_indycam.o")

AC_SUBST(SGI_SPECIFIC)


dnl check for dl , stdc++ 

if test "${GXX+set}" != set; then
AC_CHECK_LIB(dl,dlopen)
AC_CHECK_LIB(stdc++,main)
fi








dnl Checks for header files.
dnl ***********************************************************************



dnl look for pd


pd_path=`dirname \`find ../../../ -name "m_pd.h" | sed 1q\``

echo $ac_n "Checking for pd path""... $ac_c"  1>&6
echo $ac_t $pd_path

INCLUDES="$INCLUDES -I`pwd`/$pd_path -I.."

if [test "$INCLUDES" = ""]; then
  echo Error can\'t find pd directory;exit 1;
fi

AC_SUBST(INCLUDES)



AC_HEADER_STDC



dnl Checks for typedefs, structures, and compiler characteristics.
AC_C_CONST
dnl AC_C_INLINE
AC_TYPE_SIZE_T

dnl Checks for library functions.
AC_FUNC_VPRINTF
AC_CHECK_FUNCS(strdup strstr)

AC_SUBST(arch_ld_flags)
AC_SUBST(LIBS)

RANLIB=gcc 
AC_SUBST(RANLIB)


AC_OUTPUT(Makefile)

