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)

VERSION=0.85
PACKAGE=gem
AC_SUBST(VERSION)
AC_SUBST(PACKAGE)


dnl 
dnl We will use the sam Makefiles for any subdir .. so build the Makefile.in
dnl 

./makesource


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_SUBST(CXX)
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 ../Particles ../MarkEx ../Gige"
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)
dnl add -shared to the libraries, so X will be shared
LIBS="-Wl,-Bdynamic $LIBS"

AC_ARG_WITH(static,"  ",LIBS="/usr/lib/gcc-lib/i486-linux/egcs-2.91.57/libstdc++.a $LIBS")

AC_CHECK_LIB(m,sin)


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 
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 ttf
dnl

     AC_CHECK_LIB_TWICE(ttf,$search_libs)

dnl
dnl Check for gltt
dnl

     AC_CHECK_LIB_TWICE(gltt,$search_libs)

dnl
dnl Check for td 
dnl 

     AC_CHECK_LIB_TWICE(td,$search_libs)

dnl
dnl CHeck for orbit
dnl

    AC_CHECK_LIB_TWICE(orb,$search_libs)

dnl
dnl Chech for particle
dnl

    AC_CHECK_LIB_TWICE(particle,$search_libs)


dnl
dnl Chech mpeg
dnl

    AC_CHECK_LIB_TWICE(mpeg,$search_libs)

dnl
dnl Check for imagemagick 
dnl

      AC_CHECK_LIB_TWICE(Magick,$search_libs)


dnl
dnl Check for aa
dnl

      AC_CHECK_LIB_TWICE(aa,$search_libs)



dnl Check for sgi vl library


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

AC_CHECK_LIB(z,main)

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


ggstatic="-Wl,-Bstatic"
AC_ARG_WITH(static,"  ",LIBS="$ggstatic $LIBS")





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



dnl look for pd

INCLUDES="-I.. -I/usr/include/gltt $INCLUDES"

AC_PATH_INCLUDE(m_pd.h,"../..")
AC_PATH_INCLUDE(td.h,$search_libs)
AC_PATH_INCLUDE(orb.h,$search_libs)
AC_PATH_INCLUDE(papi.h,$search_libs)


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)

CXXFLAGS="-fPIC"
AC_SUBST(CXXFLAGS)

dnl gemsrc=/slink/home/geiger/PD/gem-0.79/src
gemsrc=./..

AC_OUTPUT(Makefile  
$gemsrc/Manips/Makefile
$gemsrc/Particles/Makefile
$gemsrc/Base/Makefile
$gemsrc/MarkEx/Makefile 
$gemsrc/Pixes/Makefile 
$gemsrc/Controls/Makefile 
$gemsrc/Nongeos/Makefile 
$gemsrc/Geos/Makefile
$gemsrc/Gige/Makefile
)

