## Process this file with autoconf to produce configure.
##
##
## Copyright by The HDF Group.
## Copyright by the Board of Trustees of the University of Illinois.
## All rights reserved.
##
## This file is part of HDF.  The full HDF copyright notice, including
## terms governing use, modification, and redistribution, is contained in
## the COPYING file, which can be found at the root of the source code
## distribution tree, or in https://support.hdfgroup.org/ftp/HDF/releases/.
## If you do not have access to either file, you may request a copy from
## help@hdfgroup.org.
##
##
AC_REVISION($Id$)

## ======================================================================
## Initialize configure.
## ======================================================================
## AC_INIT takes the name of the package, the version number, and an
## email address to report bugs. AC_CONFIG_SRCDIR takes a unique file
## as its argument.
##
## NOTE: Do not forget to change the version number here when we do a
## release!!!
##
AC_INIT([HDF], [4.2.14], [help@hdfgroup.org])
AC_CONFIG_SRCDIR([hdf/src/atom.c])
AC_CONFIG_AUX_DIR([bin])
AC_CONFIG_HEADER([hdf/src/h4config.h])
AC_CONFIG_MACRO_DIR([m4])

## AM_INIT_AUTOMAKE takes a list of options that should be applied to
## every Makefile.am when automake is run.
AM_INIT_AUTOMAKE([foreign])

## AM_MAINTAINER_MODE turns off "rebuild rules" that contain dependencies
## for Makefiles, configure, etc.  If AM_MAINTAINER_MODE
## is *not* included here, these files will be rebuilt if out of date.
## This is a problem because if users try to build on a machine with
## the wrong versions of autoconf and automake, these files will be
## rebuilt with the wrong versions and bad things can happen.
## Also, CVS doesn't preserve dependencies between timestamps, so
## Makefiles will often think rebuilding needs to occur when it doesn't.
## Developers should './configure --enable-maintainer-mode' to turn on
## rebuild rules.
AM_MAINTAINER_MODE

## ----------------------------------------------------------------------
## Set prefix default (install directory) to a directory in the build area.
## This allows multiple src-dir builds within one host.
AC_PREFIX_DEFAULT([`pwd`/hdf4])

## Run post processing on files created by configure.
## src/h4config.h:
## libhdf4.settings:
## Remove all lines begun with "#" which are generated by CONDITIONAL's of
## configure.
AC_CONFIG_COMMANDS([h4config], [
  echo "modifying hdf/src/h4config.h"
  sed 's/#define /#define H4_/' < hdf/src/h4config.h |\
    sed 's/#undef /#undef H4_/' > h4config
  cp h4config hdf/src/h4config.h
  rm -f h4config

#if test ! -f hdf/src/h4config.h; then
#    /bin/mv -f h4config hdf/src/h4config.h
#  elif (diff h4config hdf/src/h4config.h >/dev/null); then
#    /bin/rm -f h4config
#    echo "hdf/src/h4config.h is unchanged"
#  else
#    /bin/mv -f h4config hdf/src/h4config.h
#  fi

  echo "Post process libhdf4.settings"
  sed '/^#/d' < libhdf4.settings > libhdf4.settings.TMP
  cp libhdf4.settings.TMP libhdf4.settings
  rm -f libhdf4.settings.TMP
])

## ======================================================================
## Information on the package
## ======================================================================

## Dump all shell variables values.
AC_MSG_CHECKING([shell variables initial values])
set >&AS_MESSAGE_LOG_FD
AC_MSG_RESULT([done])

AC_CANONICAL_HOST

AC_MSG_CHECKING([if basename works])
BASENAME_TEST="`basename /foo/bar/baz/qux/basename_works`"
if test $BASENAME_TEST != "basename_works"; then
  AC_MSG_ERROR([basename program doesn't work])
else
  AC_MSG_RESULT([yes])
fi

AC_MSG_CHECKING([if xargs works])
XARGS_TEST="`echo /foo/bar/baz/qux/xargs_works | xargs basename`"
if test $XARGS_TEST != "xargs_works"; then
  AC_MSG_ERROR([xargs program doesn't work])
else
  AC_MSG_RESULT([yes])
fi

## Source any special files that we need. These files normally aren't
## present but can be used by the maintainers to fine tune things like
## turning on debug or profiling flags for the compiler. The search order
## is:
##
##         CPU-VENDOR-OS
##         VENDOR-OS
##         CPU-OS
##         CPU-VENDOR
##         OS
##         VENDOR
##         CPU
##
## If the `OS' ends with a version number then remove it. For instance,
## `freebsd3.1' would become `freebsd'
##
case "$host_os" in
  aix4.*)       host_os_novers="aix4.x"     ;;
  aix5.*)       host_os_novers="aix5.x"     ;;
  darwin10.*)   host_os_novers="darwin10.x" ;;
  darwin11.*)   host_os_novers="darwin11.x" ;;
  darwin12.*)   host_os_novers="darwin12.x" ;;
  freebsd*)     host_os_novers="freebsd"    ;;
  solaris2.*)   host_os_novers="solaris2.x" ;;
  *)            host_os_novers="$host_os"   ;;
esac

host_config="none"
for f in $host_cpu-$host_vendor-$host_os        \
         $host_cpu-$host_vendor-$host_os_novers \
         $host_vendor-$host_os                  \
         $host_vendor-$host_os_novers           \
         $host_cpu-$host_os                     \
         $host_cpu-$host_os_novers              \
         $host_cpu-$host_vendor                 \
         $host_os                               \
         $host_os_novers                        \
         $host_vendor                           \
         $host_cpu ; do
  AC_MSG_CHECKING([for config $f])
  if test -f "$srcdir/config/$f"; then
    host_config=$srcdir/config/$f
    AC_MSG_RESULT([found])
    break
  fi
  AC_MSG_RESULT([no])
done
if test "X$host_config" != "Xnone"; then
  CC_BASENAME="`echo $CC | cut -f1 -d' ' | xargs basename 2>/dev/null`"
  F77_BASENAME="`echo $F77 | cut -f1 -d' ' | xargs basename 2>/dev/null`"
  CXX_BASENAME="`echo $CXX | cut -f1 -d' ' | xargs basename 2>/dev/null`"
  . $host_config
fi

## ======================================================================
## Checks for NetCDF-2.3.2 support
## ======================================================================

# We disable Fortran netCDF APIs and their testing when --disable-netcdf is used.
# Let's define a proper variable to be used in mfhdf/testfortran.sh.in to run
# the netCDF Fortran APIs test program "ftest".
AC_SUBST(TEST_FORTRAN_NETCDF) TEST_FORTRAN_NETCDF="yes"

AC_ARG_ENABLE([netcdf],
              [AS_HELP_STRING([--enable-netcdf],
                              [Build HDF4 versions of NetCDF APIs (version 2.3.2) [default=yes]])],,
              [enableval="yes"])

case "$enableval" in
  yes)
    BUILD_NETCDF="yes"
    AC_DEFINE([HAVE_NETCDF], [1], [Define if we support HDF NetCDF APIs version 2.3.2])
    ;;
  no)
    BUILD_NETCDF="no"
    TEST_FORTRAN_NETCDF="no"
    ;;
esac
AM_CONDITIONAL([HDF_BUILD_NETCDF], [test "X$BUILD_NETCDF" = "Xyes"])
AC_SUBST([BUILD_NETCDF])

## ======================================================================
## Checks for programs
## ======================================================================

AC_PROG_MAKE_SET

AC_PROG_CC
AC_PROG_CPP
AC_PROG_CXX

AC_ARG_ENABLE([fortran],
              [AS_HELP_STRING([--enable-fortran],
                              [Build Fortran into library [default=yes]])],,
              [enableval="yes"])

case "$enableval" in
  yes)
    BUILD_FORTRAN="yes"
    AC_PROG_F77
    AC_F77_WRAPPERS

    if test "X$F77" = "X"; then
      BUILD_FORTRAN="no"
    fi
    ;;
  no)
    BUILD_FORTRAN="no"
    F77="no"
    ;;
esac
AM_CONDITIONAL([HDF_BUILD_FORTRAN], [test "X$BUILD_FORTRAN" = "Xyes"])
AC_SUBST([BUILD_FORTRAN])

## ----------------------------------------------------------------------
## Check if they would like the Java native interface (JNI) compiled
##
AC_SUBST([JNIFLAGS])
AC_SUBST([H4_JAVACFLAGS])
AC_SUBST([H4_JAVAFLAGS])

## This needs to be exposed for the library info file even if Java is disabled.
AC_SUBST([HDF_JAVA])

## Default is no Java
HDF_JAVA=no

AC_SUBST([H4_CLASSPATH]) H4_CLASSPATH=""
AC_MSG_CHECKING([if Java JNI interface enabled])

AC_ARG_ENABLE([java],
              [AS_HELP_STRING([--enable-java],
                              [Compile the Java JNI interface [default=no]])],
              [HDF_JAVA=$enableval])

if test "X$HDF_JAVA" = "Xyes"; then
  if test "X${enable_shared}" != "Xno"; then
    echo "yes"
    if test "X$CLASSPATH" = "X"; then
      H4_CLASSPATH=".:$srcdir/java/lib"
    else
      H4_CLASSPATH=".:$CLASSPATH:$srcdir/java/lib"
    fi
    ## Checks for programs.
    AX_JAVA_OPTIONS
    H4_JAVACFLAGS=$JAVACFLAGS
    H4_JAVAFLAGS=$JAVAFLAGS
    AX_PROG_JAVAC
    AX_PROG_JAVA
    AX_PROG_JAR
    AX_PROG_JAVADOC
    ## Find the include directories needed for building JNI code
    AX_JNI_INCLUDE_DIR()
    for JNI_INCLUDE_DIR in $JNI_INCLUDE_DIRS
    do
      JNIFLAGS="$JNIFLAGS -I$JNI_INCLUDE_DIR"
    done
    ## Find junit for testing the JNI code
    AX_CHECK_CLASSPATH()
    CLASSPATH_ENV=$H4_CLASSPATH
    AX_CHECK_JUNIT()
    AX_CHECK_JAVA_HOME

    AC_MSG_RESULT([yes])
  else
    AC_MSG_ERROR([Java requires shared libraries to be built])
    HDF_JAVA="no"
    AC_MSG_RESULT([no])
  fi
else
  AC_MSG_RESULT([no])
fi

## -------------------------------------------------------------------------
## Build static libraries by default. Furthermore, fortran shared libraries
## are unsupported. Disallow a user from enabling both shared libraries and
## fortran.
if test "X${enable_shared}" != "Xyes"; then
    enable_shared="no"
fi

if test "X${enable_shared}" = "Xyes"; then
    if test "X${BUILD_FORTRAN}" = "Xyes"; then
        AC_MSG_ERROR([Cannot build shared fortran libraries. Please configure with --disable-fortran flag.])
    fi
fi

AC_PROG_INSTALL
AC_PROG_LN_S

AC_CHECK_PROGS([AR], [ar xar], [:], [$PATH])

AC_CHECK_PROGS([YACC], ['bison -y' byacc yacc], [none], [])

if test "$YACC" = "none"; then
  AC_MSG_ERROR([cannot find yacc utility])
fi

AC_CHECK_PROGS([LEX], [flex lex], [none], [])

if test "$LEX" = "none"; then
  AC_MSG_ERROR([cannot find lex utility])
fi

AC_CHECK_PROG([DIFF],     [diff],     [diff -w])
AC_CHECK_PROG([MAKEINFO], [makeinfo], [makeinfo])
AC_CHECK_PROG([NEQN],     [neqn],     [neqn])
AC_CHECK_PROG([TBL],      [tbl],      [tbl])

AC_SUBST([AR])
AC_SUBST([DIFF])
AC_SUBST([STATIC_SHARED])
AC_SUBST([SHARED_EXTENSION])
AC_SUBST([enable_shared])
AC_SUBST([enable_static])
AC_SUBST([UNAME_INFO]) UNAME_INFO=`uname -a`
AC_SUBST([STATIC_EXEC]) STATIC_EXEC=no
AC_SUBST([LT_STATIC_EXEC])

## ======================================================================
## Libtool initialization
## ======================================================================
LT_INIT([dlopen disable-shared])
LT_OUTPUT

## ----------------------------------------------------------------------
## Check if we should install only statically linked executables.
##   This check needs to occur after libtool is initialized because
##   we check a libtool cache value and may issue a warning based
##   on its result.
AC_MSG_CHECKING([if we should install only statically linked executables])
AC_ARG_ENABLE([static_exec],
              [AS_HELP_STRING([--enable-static-exec],
                              [Install only statically linked executables
                               [default=no]])],
              [STATIC_EXEC=$enableval])

if test "X$STATIC_EXEC" = "Xyes"; then
  echo "yes"
  ## Issue a warning if -static flag is not supported.
  if test "X$lt_cv_prog_compiler_static_works" = "Xno"; then
      echo "    warning: -static flag not supported on this system; executable won't statically link shared system libraries."
  fi
  LT_STATIC_EXEC="-all-static"
else
  echo "no"
  LT_STATIC_EXEC=""
fi

AC_SUBST([LT_STATIC_EXEC])

## ======================================================================
## Checks for libraries
## ======================================================================

## ----------------------------------------------------------------------
## Fake --with-xxx option to allow us to create a help message for the
## following --with-xxx options which can take either a =DIR or =INC,LIB
## specifier.
##
AC_ARG_WITH([fnord],
  [
 For the following --with-xxx options, you can specify where the header
 files and libraries are in two different ways:

    --with-xxx=INC,LIB - Specify individually the include directory and
                         library directory separated by a comma
    --with-xxx=DIR     - Specify only the directory which contains the
                         include/ and lib/ subdirectories
  ])

## ----------------------------------------------------------------------
## Is the GNU zlib present? It has a header file `zlib.h' and a library
## `-lz' and their locations might be specified with the `--with-zlib'
## command-line switch. The value is an include path and/or a library path.
## If the library path is specified then it must be preceded by a comma.
AC_ARG_WITH([zlib],
            [AS_HELP_STRING([--with-zlib=DIR],
                            [Use zlib library [default=yes]])],,
            [withval=yes])

case "$withval" in
  yes)
    HAVE_ZLIB="yes"
    AC_CHECK_HEADERS([zlib.h], [HAVE_ZLIB_H="yes"], [unset HAVE_ZLIB])
    if test "x$HAVE_ZLIB" = "xyes" -a "x$HAVE_ZLIB_H" = "xyes"; then
      AC_CHECK_LIB([z], [compress2],, [unset HAVE_ZLIB])
    fi
    if test -z "$HAVE_ZLIB"; then
      if test -n "$HDF4_CONFIG_ABORT"; then
        AC_MSG_ERROR([couldn't find zlib library])
      fi
    else
      AC_CHECK_FUNC([compress2], [HAVE_COMPRESS2="yes"])
    fi
    ;;
  no)
    HAVE_ZLIB="no"
    AC_MSG_ERROR([zlib library required to build HDF4])
    ;;
  *)
    HAVE_ZLIB="yes"
    case "$withval" in
      *,*)
        zlib_inc="`echo $withval | cut -f1 -d,`"
        zlib_lib="`echo $withval | cut -f2 -d, -s`"
        ;;
      *)
        if test -n "$withval"; then
          zlib_inc="$withval/include"
          zlib_lib="$withval/lib"
        fi
        ;;
    esac

    ## Trying to include -I/usr/include and -L/usr/lib is redundant and
    ## can mess some compilers up.
    if test "X$zlib_inc" = "X/usr/include"; then
      zlib_inc=""
    fi
    if test "X$zlib_lib" = "X/usr/lib"; then
      zlib_lib=""
    fi

    if test -n "$zlib_inc"; then
      CPPFLAGS="$CPPFLAGS -I$zlib_inc"
    fi

    AC_CHECK_HEADERS([zlib.h], [HAVE_ZLIB_H="yes"], [unset HAVE_ZLIB])

    if test -n "$zlib_lib"; then
      LDFLAGS="$LDFLAGS -L$zlib_lib"
    fi

    if test "x$HAVE_ZLIB" = "xyes" -a "x$HAVE_ZLIB_H" = "xyes"; then
      AC_CHECK_LIB([z], [compress2],, [unset HAVE_ZLIB])
    fi

    if test -z "$HAVE_ZLIB"; then
      AC_MSG_ERROR([couldn't find zlib library])
    else
      AC_CHECK_FUNC([compress2], [HAVE_COMPRESS2="yes"])
    fi
    ;;
esac

## ----------------------------------------------------------------------
## Is the JPEG library present?
AC_ARG_WITH([jpeg],
            [AS_HELP_STRING([--with-jpeg=DIR],
                            [Use jpeg library [default=yes]])],,
            [withval=yes])

case "$withval" in
  yes)
    HAVE_JPEG="yes"
    AC_CHECK_HEADERS([jpeglib.h], [HAVE_JPEG_H="yes"], [unset HAVE_JPEG])
    if test "x$HAVE_JPEG" = "xyes" -a "x$HAVE_JPEG_H" = "xyes"; then
      AC_CHECK_LIB([jpeg], [jpeg_start_decompress],, [unset HAVE_JPEG])
    fi

    if test -z "$HAVE_JPEG"; then
      AC_MSG_ERROR([couldn't find jpeg library])
    fi
    ;;
  no)
    HAVE_JPEG="no"
    AC_MSG_ERROR([jpeg library required to build HDF4])
    ;;
  *)
    HAVE_JPEG="yes"
    case "$withval" in
      *,*)
        jpeg_inc="`echo $withval | cut -f1 -d,`"
        jpeg_lib="`echo $withval | cut -f2 -d, -s`"
        ;;
      *)
        if test -n "$withval"; then
          jpeg_inc="$withval/include"
          jpeg_lib="$withval/lib"
        fi
        ;;
    esac

    ## Trying to include -I/usr/include and -L/usr/lib is redundant and
    ## can mess some compilers up.
    if test "X$jpeg_inc" = "X/usr/include"; then
      jpeg_inc=""
    fi
    if test "X$jpeg_lib" = "X/usr/lib"; then
      jpeg_lib=""
    fi

    if test -n "$jpeg_inc"; then
      CPPFLAGS="$CPPFLAGS -I$jpeg_inc"
    fi

    AC_CHECK_HEADERS([jpeglib.h], [HAVE_JPEG_H="yes"], [unset HAVE_JPEG])

    if test -n "$jpeg_lib"; then
      LDFLAGS="$LDFLAGS -L$jpeg_lib"
    fi

    if test "x$HAVE_JPEG" = "xyes" -a "x$HAVE_JPEG_H" = "xyes"; then
      AC_CHECK_LIB([jpeg], [jpeg_start_decompress],, [unset HAVE_JPEG])
    fi

    if test -z "$HAVE_JPEG"; then
      AC_MSG_ERROR([couldn't find jpeg library])
    fi
    ;;
esac

## ----------------------------------------------------------------------
## Is the szip library present?
AC_SUBST(USE_COMP_SZIP) USE_COMP_SZIP="no"
AC_SUBST(SZIP_HAS_ENCODER) SZIP_HAS_ENCODER="no"
AC_ARG_WITH([szlib],
            [AS_HELP_STRING([--with-szlib=DIR],
                            [Use szlib library [default=no]])],,
            [withval=no])

case "$withval" in
  yes)
    HAVE_SZIP="yes"
    AC_CHECK_HEADERS([szlib.h], [HAVE_SZLIB_H="yes"], [unset HAVE_SZIP])
    if test "x$HAVE_SZLIB" = "xyes" -a "x$HAVE_SZLIB_H" = "xyes"; then
      AC_CHECK_LIB([sz], [SZ_BufftoBuffCompress],, [unset HAVE_SZIP])
    fi

    if test -z "$HAVE_SZIP"; then
      AC_MSG_ERROR([couldn't find szlib library])
    fi
    ;;
  no)
    HAVE_SZIP="no"
    AC_MSG_CHECKING([for szlib])
    AC_MSG_RESULT([suppressed])
    SZIP_INFO="${SZIP_INFO}disabled"
    ;;
  *)
    HAVE_SZIP="yes"
    case "$withval" in
      *,*)
        szip_inc="`echo $withval | cut -f1 -d,`"
        szip_lib="`echo $withval | cut -f2 -d, -s`"
        ;;
      *)
        if test -n "$withval"; then
          szip_inc="$withval/include"
          szip_lib="$withval/lib"
        fi
        ;;
    esac

    ## Trying to include -I/usr/include and -L/usr/lib is redundant and
    ## can mess some compilers up.
    if test "X$szip_inc" = "X/usr/include"; then
      szip_inc=""
    fi
    if test "X$szip_lib" = "X/usr/lib"; then
      szip_lib=""
    fi

    if test -n "$szip_inc"; then
      CPPFLAGS="$CPPFLAGS -I$szip_inc"
    fi

    AC_CHECK_HEADERS([szlib.h], [HAVE_SZLIB_H="yes"], [unset HAVE_SZIP])

    if test -n "$szip_lib"; then
      LDFLAGS="$LDFLAGS -L$szip_lib"
    fi

    if test "x$HAVE_SZIP" = "xyes" -a "x$HAVE_SZLIB_H" = "xyes"; then
      AC_CHECK_LIB([sz], [SZ_BufftoBuffCompress],, [unset HAVE_SZIP])
    fi

    if test -z "$HAVE_SZIP"; then
      AC_MSG_ERROR([couldn't find szlib library])
    else
      USE_COMP_SZIP="yes"
    fi
    ;;
esac

## Check to see if SZIP has encoder
if test "X$HAVE_SZIP" = "Xyes" -a "x$HAVE_SZLIB_H" = "xyes"; then
    ## SZLIB library is available. Check if it can encode.
    AC_MSG_CHECKING([for szlib encoder])

    ## Set LD_LIBRARY_PATH so encoder test can find the library and run.
    if test -z "$LD_LIBRARY_PATH"; then
        export LD_LIBRARY_PATH="$szip_lib"
    else
        export LD_LIBRARY_PATH="${szip_lib}:$LD_LIBRARY_PATH"
    fi

    AC_SUBST([LL_PATH]) LL_PATH="$LD_LIBRARY_PATH"

    AC_TRY_RUN([
    #include <stdlib.h>
    #include <szlib.h>

    int main(void)
    {
        /* SZ_encoder_enabled returns 1 if encoder is present */
        if (SZ_encoder_enabled() == 1)
            exit(0);
        else
            exit(1);
    }
    ], [CAN_ENCODE="yes"], [CAN_ENCODE="no"],)

    ## Report szip encoder test results
    if test "X$CAN_ENCODE" = "Xyes"; then
        AC_MSG_RESULT([yes])
    fi
    if test "X$CAN_ENCODE" = "Xno"; then
        AC_MSG_RESULT([no])
    fi

    ## Add "szip" to external filter list
    if test "X$CAN_ENCODE" = "Xyes"; then
        if test "X$SZIP_INFO" != "X"; then
            SZIP_INFO="${SZIP_INFO}"
        fi
        SZIP_INFO="${SZIP_INFO}enabled with encoder"
    fi

    if test "X$CAN_ENCODE" = "Xno"; then
        if test "X$SZIP_INFO" != "X"; then
            SZIP_INFO="${SZIP_INFO}"
        fi
        SZIP_INFO="${SZIP_INFO}enabled with decoder only"
    fi

    ## Create macro to specify if encoder is present
    if test "X$CAN_ENCODE" = "Xyes"; then
        AC_DEFINE([HAVE_SZIP_ENCODER], [1],
                [Define if szip has encoder])
        SZIP_HAS_ENCODER="yes"
    fi
fi
AC_SUBST([SZIP_INFO])
AC_SUBST([SZIP_HAS_ENCODER])

AM_CONDITIONAL([BUILD_SHARED_SZIP_CONDITIONAL], [test "X$USE_COMP_SZIP" = "Xyes" && test "X$LL_PATH" != "X"])

## ----------------------------------------------------------------------
## Is XDR support present? The TRY_LINK info was gotten from the
## mfhdf/libsrc/local_nc.c file.
AC_MSG_CHECKING([for xdr library support])

AC_ARG_ENABLE([hdf4-xdr],
              [AS_HELP_STRING([--enable-hdf4-xdr],
                              [Build xdr library from code in HDF4 source.
                               Not supported for 64 bit mode. [default="no"]])],
              [enableval="yes"],[enableval="no"])

case "$enableval" in
  yes)
    BUILD_XDR="yes"
    AC_MSG_RESULT([using HDF4 XDR]);
    ;;
  no)
    BUILD_XDR="no"
    ;;
esac

## For Solaris systems, add the -nsl for XDR support
##
## The SunRPC of the glibc has been replaced by a TI-RPC (Transport Independent RPC) library for IPv6 support
case "$host" in
  *-solaris*)
    LIBS="$LIBS -lnsl"  ;;
  *-pc-cygwin*)
    LIBS="$LIBS -ltirpc"
    CPPFLAGS="$CPPFLAGS -I/usr/include/tirpc"  ;;
  *) ;;
esac

if test "X$BUILD_XDR" != "Xyes"; then
    AC_TRY_LINK([
    #include <rpc/types.h>
    #include <rpc/xdr.h>], [xdr_int],
                [AC_MSG_RESULT([yes]); BUILD_XDR="no"],
                [AC_MSG_RESULT([no]); BUILD_XDR="yes"])
fi

AM_CONDITIONAL([HDF_BUILD_XDR], [test "X$BUILD_XDR" = "Xyes"])


## Check headers and add libraries for XDR if the HDF4 XDR library is not used.
if test "X$BUILD_XDR" != "Xyes"; then

  ## ======================================================================
  ## Checks for header files
  ## ======================================================================

  ## ----------------------------------------------------------------------
  ## We're trying to link against the rpc library when building on Cygwin,
  ## but we need to make sure that it is present on the system. Do that here,
  ## The SunRPC of the glibc has been replaced by a TI-RPC (Transport Independent RPC) library for IPv6 support
  case "$host" in
    *-pc-cygwin*)
      HAVE_RPC="yes"
      AC_CHECK_HEADER([rpc.h],[:], [unset HAVE_RPC])
      AC_CHECK_LIB([tirpc], [xdr_opaque],[:], [unset HAVE_RPC])
      if test -z "$HAVE_RPC"; then
        AC_MSG_ERROR([couldn't find tirpc library])
      fi
      ;;
  esac
fi

AC_HEADER_STDC

## ======================================================================
## Checks for types
## ======================================================================

## ======================================================================
## Checks for structures
## ======================================================================

## ======================================================================
## Checks for compiler characteristics
## ======================================================================

AC_PROG_CC_C_O
AC_PROG_CXXCPP

if test "X$BUILD_FORTRAN" = "Xyes"; then
  AC_PROG_F77_C_O
fi

## This is a bit of a hack. The AC_CHECK_SIZEOF macro is supposed to
## #define a value in a header file. However, we don't use a generated
## header file. So I check the value left over from autoconf's test  is
## >= 8.
AC_CHECK_SIZEOF([int*])

if test $ac_cv_sizeof_intp -ge 8; then
  CPPFLAGS="$CPPFLAGS -DBIG_LONGS"

  ## Define super secret special flag for AIX machines in 64-bit mode.
  case "${host}" in
    *-ibm-aix*) CPPFLAGS="$CPPFLAGS -DAIX5L64" ;;
    *)          ;;
  esac
  if test "X$BUILD_XDR" = "Xyes"; then
    AC_MSG_ERROR([--enable-hdf4-xdr is not supported for 64 bit mode.])
  fi
fi

## ----------------------------------------------------------------------
## Set some variables for general configuration information to be saved
## and installed with the libraries.
##

## HDF4 version from the first line of the README.txt file.
H4_VERSION="`cut -d' ' -f3 $srcdir/README.txt | head -1`"
AC_SUBST([H4_VERSION])

## Configuration date
AC_SUBST([CONFIG_DATE]) CONFIG_DATE="`date`"

## User doing the configuration
AC_SUBST([CONFIG_USER]) CONFIG_USER="`whoami`@`hostname`"

## Configuration mode (production, development, etc)
AC_SUBST([CONFIG_MODE])

AC_C_BIGENDIAN([], [CPPFLAGS="$CPPFLAGS -DSWAP"])

## Are we building this in debug or production mode? (Remove the -g flag
## in production mode.)
AC_MSG_CHECKING([for build mode])
AC_ARG_ENABLE([production],
              [AS_HELP_STRING([--enable-production],
                              [Determines how to run the compiler.])])

case "X-$enable_production" in
  X-|X-yes)
    AC_MSG_RESULT([production])
    CONFIG_MODE=production
    ## Remove the "-g" flag from compile line if it's in there.
    CFLAGS_temp=""
    if test -n "$CFLAGS"; then
      for d in $CFLAGS ; do
        if test "X$d" != "X-g"; then
          CFLAGS_temp="$CFLAGS_temp $d"
        fi
      done
      CFLAGS=$CFLAGS_temp
    fi

    FFLAGS_temp=""
    if test -n "$FFLAGS"; then
      for d in $FFLAGS ; do
        if test "X$d" != "X-g"; then
          FFLAGS_temp="$FFLAGS_temp $d"
        fi
      done
      FFLAGS=$FFLAGS_temp
    fi

    CXXFLAGS_temp=""
    if test -n "$CXXFLAGS"; then
      for d in $CXXFLAGS ; do
        if test "X$d" != "X-g"; then
          CXXFLAGS_temp="$CXXFLAGS_temp $d"
        fi
      done
      CXXFLAGS=$CXXFLAGS_temp
    fi

    CFLAGS="$CFLAGS $PROD_CFLAGS"
    CXXFLAGS="$CXXFLAGS $PROD_CXXFLAGS"
    FFLAGS="$FFLAGS $PROD_FFLAGS"
    CPPFLAGS="$CPPFLAGS $PROD_CPPFLAGS"
    ;;
  X-no)
    AC_MSG_RESULT([development])
    CONFIG_MODE=development
    CFLAGS="$CFLAGS $DEBUG_CFLAGS"
    FFLAGS="$FFLAGS $DEBUG_FFLAGS"
    CXXFLAGS="$CXXFLAGS $DEBUG_CXXFLAGS"
    CPPFLAGS="$CPPFLAGS $DEBUG_CPPFLAGS"
    ;;
  *)
    AC_MSG_RESULT([user-defined])
    ;;
esac

## ======================================================================
## Checks for library functions
## ======================================================================

AC_MSG_CHECKING([for math library support])
AC_TRY_LINK([#include <math.h>], [sinh(37.927)],
            [AC_MSG_RESULT([yes])],
            [AC_MSG_RESULT([no]); LIBS="$LIBS -lm"])

AC_CHECK_FUNCS([fork system vfork wait])


## ======================================================================
## Checks for system services
## ======================================================================

## Copy NetCDF header files.
#
## FIXME: This is code stolen^Wborrowed from the old HDF4 configure.
## These header files should probably be generated by autoconf instead
## of being copied depending upon the host.
case "$host" in
  *-linux*)             BAR="linux"       ;;
  *-freebsd*)           BAR="fbsd"        ;;
  *-ibm-aix*)           BAR="aix"         ;;
  sparc64-*-solaris2*)  BAR="solaris64"   ;;
  *-*-solaris2*)        BAR="solaris"     ;;
  *-apple*)             BAR="apple"       ;;
  *-pc-cygwin*)         BAR="linux"       ;;
  *)                    echo "*** unknown host $host!"; exit 1 ;;
esac
src_files=""
src_files="`echo $src_files | sed -e s/FOO/${BAR}/g`"

for config_file in $src_files; do
  src_file="${srcdir}/`echo $config_file | sed -e s/:.*$//`"
  target_file="`echo $config_file | sed -e s/^[[^:]]*://g`"

  if test ! -r ${src_file}; then
    echo '***' "${progname}: cannot copy file \"${target_file}\"," 1>&2
    echo '***' "since the file \"${src_file}\" does not exist." 1>&2
    exit 1
  fi

  ## this sed command emulates the dirname command
  dstdir=`echo "$target_file" | sed -e 's,[[^/]]*$,,;s,/$,,;s,^$,.,'`

  ## Create directory for the target_file if it's not there.
  if test ! -d $dstdir; then
    ${srcdir}/bin/mkinstalldirs $dstdir
  fi

  echo "Copying \"${src_file}\" to \"${target_file}\" ."
  cp ${src_file} ${target_file}

  if test ! -r ${target_file}; then
    echo '***' "${progname}: cannot copy file \"${target_file}\"," 1>&2
    exit 1
  fi
done

## ------------------------------------------------------------------------
## Check to see if libtool has enabled shared libraries. Set a conditional
## as some Makefiles will build based on availability of shared libraries.
if (./libtool --features | grep '^enable shared libraries' > /dev/null); then
  enable_shared=yes
else
  enable_shared=no
fi

## ------------------------------------------------------------------------
## Specify shared library extension the host machine should recognize.
case "$host_os" in
  darwin*)
      SHARED_EXTENSION="dylib"
      ;;
  *)
      SHARED_EXTENSION="so"
      ;;
esac

## We don't need to say when we're entering directories if we're using
## GNU make because make does it for us.
if test "X$GMAKE" = "Xyes"; then
  AC_SUBST([SETX]) SETX=":"
else
  AC_SUBST([SETX]) SETX="set -x"
fi

AM_CONDITIONAL([HDF_BUILD_SHARED], [test "X$enable_shared" = "Xyes"])

## Compiler with version information. This consists of the full path
## name of the compiler and the reported version number.
AC_SUBST([CC_VERSION])
## Strip anything that looks like a flag off of $CC
CC_NOFLAGS=`echo $CC | sed 's/ -.*//'`

if `echo $CC_NOFLAGS | grep ^/ >/dev/null 2>&1`; then
  CC_VERSION="$CC"
else
  CC_VERSION="$CC";
  for x in `echo $PATH | sed -e 's/:/ /g'`; do
    if test -x $x/$CC_NOFLAGS; then
      CC_VERSION="$x/$CC"
      break
    fi
  done
fi


## ----------------------------------------------------------------------
##
## If --enable-static-exec and are specified together, there will be ld failures for
## "attempted static link of dynamic object" when the tools are built.  This check
## will prevent that error during configure instead.  It could go with the other
## --enable-static-exec checks, but since enable_static is set by default later in
## the configure process this check has to be delayed.
if test "X$STATIC_EXEC" = "Xyes"; then
  if test "X${enable_static}" != "Xyes"; then
    AC_MSG_ERROR([--enable-static-exec flag to build static executables requires static libraries.  Please configure with --enable-static flag.])
  fi
fi

## This part doesn't work yet since HDF4 config files do not contain
## information for cc_vendor and cc_version as HDF4 similar files do.
## Needs to be fixed EIP 2010-01-21
## if test -n "$cc_vendor" && test -n "$cc_version"; then
##  CC_VERSION="$CC_VERSION ($cc_vendor-$cc_version)"
## fi

if test -n "$cc_version_info"; then
  CC_VERSION="$CC_VERSION ( $cc_version_info)"
fi

## Fortran compiler with version information. This consists of the full path
## name of the compiler and the reported version number.
AC_SUBST([F77_VERSION])
## Strip anything that looks like a flag off of $F77
F77_NOFLAGS=`echo $F77 | sed 's/ -.*//'`

if `echo $F77_NOFLAGS | grep ^/ >/dev/null 2>&1`; then
  F77_VERSION="$F77"
else
  F77_VERSION="$F77";
  for x in `echo $PATH | sed -e 's/:/ /g'`; do
    if test -x $x/$F77_NOFLAGS; then
      F77_VERSION="$x/$F77"
      break
    fi
  done
fi
if test -n "$fc_version_info"; then
  F77_VERSION="$F77_VERSION ( $fc_version_info)"
fi

## This part doesn't work yet since HDF4 config files do not contain
## information for fortran_vendor and fortran_version.
## Needs to be fixed EIP 2010-01-21
## if test -n "$fortran_vendor" && test -n "$fortran_version"; then
##   F77_VERSION="$F77_VERSION ($fortran_vendor-$fortran_version)"
## fi

AC_SUBST([JAVA_VERSION])
## Strip anything that looks like a flag off of $JAVA
JAVA_NOFLAGS=`echo $JAVA | sed 's/ -.*//'`

if `echo $JAVA_NOFLAGS | grep ^/ >/dev/null 2>&1`; then
  JAVA_VERSION="$JAVA"
else
  JAVA_VERSION="$JAVA";
  for x in `echo $PATH | sed -e 's/:/ /g'`; do
    if test -x $x/$JAVA_NOFLAGS; then
      JAVA_VERSION="$x/$JAVA"
      break
    fi
  done
fi
java_version_info=`$JAVA -version 2>&1 |\
  grep 'version' | sed -e 's/version "//' | sed -e 's/"//'`
if test -n "$java_version_info"; then
  JAVA_VERSION="$JAVA_VERSION ($java_version_info)"
fi
AM_CONDITIONAL([BUILD_JAVA_CONDITIONAL], [test "X$HDF_JAVA" = "Xyes"])

## ----------------------------------------------------------------------
## Enable deprecated public API symbols
##
AC_SUBST([DEPRECATED_SYMBOLS])
AC_MSG_CHECKING([if deprecated public symbols are available]);
AC_ARG_ENABLE([deprecated-symbols],
              [AS_HELP_STRING([--enable-deprecated-symbols],
                     [Enable deprecated public API symbols [default=yes]])],
             [DEPREC_SYMBOLS=$enableval],
             [DEPREC_SYMBOLS=yes])

case "X-$DEPREC_SYMBOLS" in
  X-yes)
    AC_MSG_RESULT([yes])
    DEPRECATED_SYMBOLS=yes
    ;;
  X-no|*)
    AC_MSG_RESULT([no])
    DEPRECATED_SYMBOLS=no
    AC_DEFINE([NO_DEPRECATED_SYMBOLS], [1],
              [Define if deprecated public API symbols are disabled])
    ;;
esac

AC_CONFIG_FILES([Makefile
                 libhdf4.settings
                 hdf/Makefile
                 hdf/examples/Makefile
                 hdf/fortran/Makefile
                 hdf/fortran/examples/Makefile
                 hdf/src/Makefile
                 hdf/test/Makefile
                 hdf/util/Makefile
                 hdf/util/h4cc
                 hdf/util/h4fc
                 hdf/util/h4redeploy
                 hdf/util/testutil.sh
                 man/Makefile
        mfhdf/fortran/ftest.f
        mfhdf/fortran/jackets.c
        mfhdf/fortran/netcdf.inc
        mfhdf/libsrc/netcdf.h
                 mfhdf/Makefile
                 mfhdf/dumper/Makefile
                 mfhdf/dumper/testhdp.sh
                 mfhdf/examples/Makefile
                 mfhdf/examples/testexamples.sh
                 mfhdf/fortran/Makefile
                 mfhdf/fortran/examples/Makefile
                 mfhdf/fortran/testfortran.sh
                 mfhdf/hdfimport/Makefile
                 mfhdf/hdfimport/testutil.sh
                 mfhdf/hdiff/Makefile
                 mfhdf/hdiff/testhdiff.sh
                 mfhdf/hrepack/Makefile
                 mfhdf/hrepack/hrepack.sh
                 mfhdf/hrepack/hrepack_all.sh
                 mfhdf/libsrc/Makefile
                 mfhdf/ncdump/Makefile
                 mfhdf/ncdump/testncdump.sh
                 mfhdf/ncgen/Makefile
                 mfhdf/ncgen/testncgen.sh
                 mfhdf/nctest/Makefile
                 mfhdf/test/Makefile
                 mfhdf/test/testmfhdf.sh
                 mfhdf/xdr/Makefile
                 java/Makefile
                 java/src/Makefile
                 java/src/jni/Makefile
                 java/test/Makefile
                 java/test/junit.sh
                 java/examples/Makefile])

AC_CONFIG_COMMANDS([.classes], [], [$MKDIR_P java/src/.classes;
                $MKDIR_P java/test/.classes;
                $MKDIR_P java/examples/.classes])

AC_OUTPUT

## A temporary patch. These code were after where it did
## cp config/netcdf-XXX.h netcdf.h before.
## Moved it here after AC_CONFIG_FILES(... mfhdf/libsrc/netcdf.h ).
## Need a better and correct solution.
##
if test "X$BUILD_NETCDF" != "Xyes"; then
    echo "Renaming \"mfhdf/libsrc/netcdf.h\" to \"mfhdf/libsrc/hdf4_netcdf.h\" ."
    mv mfhdf/libsrc/netcdf.h mfhdf/libsrc/hdf4_netcdf.h
fi

chmod 755 hdf/util/h4cc hdf/util/h4redeploy

if test "X$BUILD_FORTRAN" = "Xyes"; then
  chmod 755 hdf/util/h4fc
fi

## show the configure settings
cat libhdf4.settings

