dnl Process this file with autoconf to produce a configure script.

dnl Define the reference directory checking if the file exist there
dnl Any file argument can be passed to AC_INIT but, on the same time, 
dnl changing all the relative path for all the files involved in the code!
dnl this will be called in the all the other MAKEFILEs as "@top_srcdir@"
AC_INIT(event/PamelaRun.h)

dnl Adds several standard checks. It takes the program name and version number as arguments.
AM_INIT_AUTOMAKE([yoda],[4.0.0])

dnl Indicates that you will be using a config.h file
dnl config.h will be generated by AUTOCONF using a confing.h.in file
dnl config.h.in can be generated automatically using AUTOHEADER
dnl However, you need a stamp-h file in your project to ensure that 
dnl AUTOMAKE regenerates config.h from config.h.in. 
dnl Type 'touch stamp-h' to add this file to your project 
AM_CONFIG_HEADER(config.h)

AC_LIBTOOL_DLOPEN

dnl The following macros make the system type available to configure scripts
AC_CANONICAL_HOST

dnl Indicates that the source code may be in C
AC_PROG_CC

dnl ------------------Fortran support----------------------------------
dnl Determine a Fortran 77 compiler to use. If F77 is not already set in the environment, 
dnl then check for g77 and f77, and then some other names. 
dnl Set the output variable F77 to the name of the compiler found
 AC_PROG_F77(f77 fort77 g77)

dnl Determine the linker flags (e.g., `-L' and `-l') for the Fortran 77 
dnl intrinsic and run-time libraries that are required to successfully 
dnl link a Fortran 77 program or shared library. 
dnl The output variable FLIBS is set to these flags
 AC_F77_LIBRARY_LDFLAGS
dnl ------------------Fortran support----------------------------------


dnl Indicates that the source code may be in C++
AC_PROG_CXX
AC_PROG_LIBTOOL

dnl Will generate an install target so that users may just type 'make install' to install the software
dnl Set output variable INSTALL to the path of a BSD compatible install program, 
dnl if one is found in the current PATH. 
dnl Otherwise, set INSTALL to `dir/install-sh -c', checking the directories specified to 
dnl AC_CONFIG_AUX_DIR (or its default directories) to determine dir
AC_PROG_INSTALL

dnl This will allow you to build code in sub-directories into temporary libraries, 
dnl which MAKE will then link in with the rest of the code
dnl AC_PROG_RANLIB


AC_PROG_MAKE_SET
AC_CHECK_PROG(HAS_DOXYFILE, doxygen, yes)

missing_dir=`cd $ac_aux_dir && pwd`
AM_MISSING_PROG(ACLOCAL, aclocal, $missing_dir)
AM_MISSING_PROG(AUTOCONF, autoconf, $missing_dir)
AM_MISSING_PROG(AUTOMAKE, automake, $missing_dir)
AM_MISSING_PROG(AUTOHEADER, autoheader, $missing_dir)
AM_MISSING_PROG(MAKEINFO, makeinfo, $missing_dir)


dnl Process the different options
AC_ARG_WITH(root,
  [--with-root=path    Use the specified ROOT directory],
  ROOTSYS=$with_root,)

ROOT_LIBRARY="${ROOTSYS}/lib"

ROOT_LDFLAGS="                                                          \
${ROOT_LIBRARY}/libCint.so          ${ROOT_LIBRARY}/libCore.so          \
${ROOT_LIBRARY}/libMatrix.so        ${ROOT_LIBRARY}/libHist.so          \
${ROOT_LIBRARY}/libTree.so          ${ROOT_LIBRARY}/libGraf.so          \
${ROOT_LIBRARY}/libGraf3d.so        ${ROOT_LIBRARY}/libGpad.so          \
${ROOT_LIBRARY}/libGui.so           ${ROOT_LIBRARY}/libMinuit.so        \
${ROOT_LIBRARY}/libHistPainter.so   ${ROOT_LIBRARY}/libTreePlayer.so    \
${ROOT_LIBRARY}/libTreeViewer.so    ${ROOT_LIBRARY}/libProof.so         \
${ROOT_LIBRARY}/libProofGui.so      ${ROOT_LIBRARY}/libPhysics.so       \
${ROOT_LIBRARY}/libRint.so          ${ROOT_LIBRARY}/libHtml.so          \
${ROOT_LIBRARY}/libEG.so            ${ROOT_LIBRARY}/libGeom.so          \
${ROOT_LIBRARY}/libGeomPainter.so   ${ROOT_LIBRARY}/libVMC.so           \
${ROOT_LIBRARY}/libFumili.so        ${ROOT_LIBRARY}/libMLP.so           \
${ROOT_LIBRARY}/libGedOld.so        ${ROOT_LIBRARY}/libGed.so           \
${ROOT_LIBRARY}/libQuadp.so                 \
${ROOT_LIBRARY}/libGX11.so          ${ROOT_LIBRARY}/libGX11TTF.so       \
${ROOT_LIBRARY}/libX3d.so                  \
${ROOT_LIBRARY}/libASImage.so       \
${ROOT_LIBRARY}/libThread.so        ${ROOT_LIBRARY}/libRXML.so          \
 -ldl"


ROOT_INCLUDES="-I${ROOTSYS}/include"
AC_SUBST(ROOT_INCLUDES)
AC_SUBST(ROOT_LDFLAGS)
ROOTCINT=${ROOTSYS}/bin/rootcint
AC_SUBST(ROOTCINT)

AC_MSG_CHECKING(for gprof)
AC_ARG_ENABLE(gprof,
[--enable-gprof          enable memory profiling with gprof],
gprof=$enableval,gprof=no)
if test "$gprof" != no
then
    CXXFLAGS="-pg $CXXFLAGS"
    AC_MSG_RESULT(enabled)
else
    AC_MSG_RESULT(no)
fi

AC_ARG_WITH(log4cxx,
  [--with-log4cxx=path Use the specified directroy for log4cxx],
  LOG4CXX=$with_log4cxx,)
LOG4CXX_INCLUDES="-I${LOG4CXX}/include"

dnl Checks for header files.
AC_HEADER_STDC


dnl Indicates the name of the Makefile which will be generated
dnl and the various subDirs where it will be generated one
dnl Add your own Makefiles to create here.
AC_OUTPUT(Makefile Doxyfile             \
 event/Makefile                         \

dnl ------------------makes for Packets and SubPackets----------------
 event/mcmd/Makefile                    \
 event/tmtc/Makefile                    \
 event/log/Makefile                     \
 event/arrDump/Makefile                 \
 event/tabDump/Makefile                 \
 event/varDump/Makefile                 \
 event/tsbt/Makefile                    \
 event/tsbb/Makefile                    \
 event/endrun/Makefile                  \
 event/physics/Makefile                 \
 event/physics/tracker/Makefile         \
 event/physics/anticounter/Makefile     \
 event/physics/calorimeter/Makefile     \
 event/physics/neutronDetector/Makefile \
 event/physics/trigger/Makefile         \
 event/physics/tof/Makefile             \
 event/physics/S4/Makefile              \
dnl ------------------makes for Packets and SubPackets----------------


dnl ------------------makes for Techmodel Data----------------
 techmodel/Makefile                             \
 techmodel/forroutines/tracker/Makefile         \
 techmodel/forroutines/tracker/readraw/Makefile \
 techmodel/forroutines/anticounter/Makefile     \
 techmodel/forroutines/calorimeter/Makefile     \
 techmodel/forroutines/tof/Makefile             \
 techmodel/forroutines/trigger/Makefile         \
 techmodel/forroutines/Makefile                 \
 techmodel/physics/Makefile                     \
dnl ------------------makes for Techmodel Data----------------
  )


