AC_PREREQ(2.59)
AC_INIT(configure.in)

dnl
dnl Set the directory that contains support scripts such as install-sh and
dnl config.guess
dnl
AC_CONFIG_AUX_DIR(../../../../../confdb)

dnl
dnl Definitions will be placed in this file rather than in the DEFS variable
dnl
AC_CONFIG_HEADER(include/mpidi_ch3i_sock_conf.h)
AH_TOP([/* -*- Mode: C; c-basic-offset:4 ; -*- */
/*  
 *  (C) 2001 by Argonne National Laboratory.
 *      See COPYRIGHT in top-level directory.
 */
#ifndef MPIDI_CH3I_SOCK_CONF_H_INCLUDED
#define MPIDI_CH3I_SOCK_CONF_H_INCLUDED
])
AH_BOTTOM([#endif])

echo "RUNNING CONFIGURE FOR THE SOCK CHANNEL"

dnl
dnl First check that we have a clean build if we are doing a VPATH build
PAC_VPATH_CHECK()

PAC_LOAD_BASE_CACHE

PAC_PROG_MAKE

dnl AC_CHECK_HEADER(net/if.h) fails on Solaris; extra header files needed
AC_TRY_COMPILE([
#include <sys/types.h>
#include <sys/socket.h>
#include <net/if.h>
],,lac_cv_header_net_if_h=yes,lac_cv_header_net_if_h=no)

echo "checking for net/if.h... $lac_cv_header_net_if_h"

if test "$lac_cv_header_net_if_h" = "yes" ; then
    AC_DEFINE(HAVE_NET_IF_H, 1, [Define if you have the <net/if.h> header file.])
fi

AC_CHECK_HEADERS(				\
	netdb.h					\
	sys/ioctl.h				\
	sys/socket.h				\
	sys/sockio.h				\
	sys/types.h				\
	errno.h)

# netinet/in.h often requires sys/types.h first.  With AC 2.57, check_headers
# does the right thing, which is to test whether the header is found 
# by the compiler, but this can cause problems when the header needs 
# other headers.  2.57 changes the syntax (!) of check_headers to allow 
# additional headers.
AC_CACHE_CHECK([for netinet/in.h],ac_cv_header_netinet_in_h,[
AC_TRY_COMPILE([#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
#include <netinet/in.h>],[int a=0;],
    ac_cv_header_netinet_in_h=yes,
    ac_cv_header_netinet_in_h=no)])
if test "$ac_cv_header_netinet_in_h" = yes ; then
    AC_DEFINE(HAVE_NETINET_IN_H,1,[Define if netinet/in.h exists])
fi

# We need the util/sock/ch3usock.h header file
CPPFLAGS="${CPPFLAGS} -I${master_top_srcdir}/src/mpid/ch3/util/sock"

AC_SUBST(device_name)
AC_SUBST(channel_name)

AC_SUBST(AR)
AC_SUBST(RANLIB)
AC_SUBST(MPILIBNAME)
AC_SUBST(CC)
AC_SUBST(CFLAGS)
AC_SUBST(CPPFLAGS)
PAC_CC_SUBDIR_SHLIBS
AC_SUBST(master_top_srcdir)
# Master_top_builddir is imported from the top; use it for the "top"
# (used for things like libtool)
if test -z "$master_top_builddir" ; then
    if test -s ../../../../../.mpich2 ; then
        master_top_builddir=../../../../..
    fi
fi
AC_SUBST(master_top_builddir)
dnl
dnl Dependency handling
AC_SUBST(MAKE_DEPEND_C)
dnl
dnl Etags
AC_SUBST(ETAGS)
AC_SUBST(ETAGSADD)
export ETAGS
export ETAGSADD

PAC_UPDATE_BASE_CACHE

AC_OUTPUT(Makefile src/Makefile localdefs)
