enhanced m4 files

Patrice Dumas pertusus at FREE.FR
Tue Oct 25 17:37:27 EDT 2005


Hello,

The attached m4 files are enhanced versions of the files I
allready sent. These autoconf macros now search for the libraries and
header files for netcdf and hdf4 in many places, moreover it should
be easy to add other places to search in.
The configure.ac patch is also updated to take advantage of those new
macros.
There is a new file libnc-dap_header.m4. It is the same file than
netcdf_header.m4 with different macro names, to avoid clashes with
netcdf_header.m4 while still being able to provide it independently.

With these files and the other patches I sent, a simple
   ./configure --enable-dyn-supplibs
allows to build grads on fedora core 4.

--
Pat
-------------- next part --------------
--- grads-1.9b4-orig/configure.in       2005-05-23 17:04:40.000000000 +0200
+++ grads-1.9b4/configure.in    2005-10-25 23:25:02.000000000 +0200
@@ -66,6 +66,8 @@
     [Use pre-1.9 non-canonical names for supplib directories]),
     [old_supplibs="yes"])

+ga_dyn_supplibs=no
+
 AC_ARG_ENABLE(dyn-supplibs, AC_HELP_STRING([--enable-dyn-supplibs],
     [Use dynamic (shared object) system libraries, if present, for optional features. This will produce smaller, but possibly less portable, binaries. By default, only static libraries from a GrADS supplibs distribution will be used for optional feature support to maximize binary portability.]),
     [ GA_ENABLE_DYNAMIC() ])
@@ -258,11 +260,21 @@
 use_readline=no
 if test "$with_readline" != "no" ; then
   echo "Check GrADS command line editing support..."
-  GA_CHECK_READLINE([use_readline=yes])
+  if test "$ga_dyn_supplibs" = "yes" ; then
+  # GA_LIB_READLINE adds the required -l to LIBS
+    GA_LIB_READLINE([
+      use_readline=yes
+      readline_libs=""
+    ])
+  else
+    GA_CHECK_READLINE([use_readline=yes])
+  fi
 fi
 if test $use_readline = "yes" ; then
   echo "+ Command line editing enabled"
-  GA_SET_LIB_VAR(readline_libs, readline)
+  if test "$ga_dyn_supplibs" = "no" ; then
+    GA_SET_LIB_VAR(readline_libs, readline)
+  fi
   AC_SUBST(readline_libs)
   AC_DEFINE(READLINE, 1, [Enable command line editing])
   AC_DEFINE(MM_READLINE,,[Enhanced readline with history])
@@ -274,15 +286,29 @@


 use_gui=no
+use_freq=yes
 if test "$with_gui" != "no" ; then
    echo "Check GrADS GUI support..."
-   GA_CHECK_GUI([use_gui=yes])
+   if test "$ga_dyn_supplibs" = "yes" ; then
+     GA_CHECK_LIBSX([use_gui=yes;use_freq=yes],[use_gui=yes;use_freq=no])
+   else
+     GA_CHECK_GUI([use_gui=yes])
+   fi
 fi
 if test $use_gui = "yes" ; then
   AC_DEFINE(USEGUI, 1, [Enable GUI widgets])
   echo "+ GUI enabled"
-  GA_SET_LIB_VAR(gui_libs, [sx freq])
-  gui_libs="$gui_libs -lXaw -lXmu -lXt $guilibadd"
+  if test "$ga_dyn_supplibs" = "yes" ; then
+    gui_libs="$GA_LIBSX_LIBS $guilibadd"
+  else
+    GA_SET_LIB_VAR(gui_libs, [sx freq])
+    gui_libs="$gui_libs -lXaw -lXmu -lXt $guilibadd"
+  fi
+  if test $use_freq = yes; then
+     AC_DEFINE(USEFREQ, 1, [Use GetFile from freq])
+  else
+     AC_DEFINE(USEFREQ, 0, [Use GetFile from freq])
+  fi
   AC_SUBST(gui_libs)
 else
   AC_DEFINE(USEGUI, 0, [Enable GUI widgets])
@@ -294,13 +320,24 @@
 use_printim=no
 if test "$with_printim" != "no" ; then
   echo "Check GrADS printim support..."
-  GA_CHECK_GD([use_printim=yes], [])
+  if test "$ga_dyn_supplibs" = "yes" ; then
+    GA_SUPP_CHECK_GD([
+      use_printim=yes
+      printim_libs="$GA_GD_LIBS"
+      LDFLAGS="$LDFLAGS $GA_GD_LDFLAGS"
+      CPPFLAGS="$CPPFLAGS $GA_GD_CPPFLAGS"
+    ])
+  else
+    GA_CHECK_GD([use_printim=yes], [])
+  fi
 fi

 if test $use_printim = "yes" ; then
   AC_DEFINE(GXPNG, 1, [Enable printim using GD library \
                        (http://www.boutell.com/gd) for PNG/GIF images])
-  GA_SET_LIB_VAR(printim_libs, [gd png z])
+  if test "$ga_dyn_supplibs" = "no" ; then
+    GA_SET_LIB_VAR(printim_libs, [gd png z])
+  fi
   AC_SUBST(printim_libs)
   extra_utils="$extra_utils gxtran"
   echo "+ printim enabled"
@@ -354,10 +391,31 @@

 use_nc=no
 if test "$with_nc" != "no" ; then
-     GA_CHECK_NC([use_nc=yes])
+  if test "$ga_dyn_supplibs" = "yes" ; then
+dnl check for netcdf 3 and, if not found, for netcdf 2
+    GA_CHECK_UDUNITS([
+      AC_CHECK_NETCDF([
+        LDFLAGS="$LDFLAGS $NC_LDFLAGS"
+        CPPFLAGS="$CPPFLAGS $NC_CPPFLAGS"
+        use_nc=yes
+        nc_libs="$NC_LIBS $GA_UDUNITS_LIBS"],
+      [
+        AC_CHECK_NETCDF([
+          LDFLAGS="$LDFLAGS $NC_LDFLAGS"
+          CPPFLAGS="$CPPFLAGS $NC_CPPFLAGS"
+          use_nc=yes
+          nc_libs="$NC_LIBS $GA_UDUNITS_LIBS"])
+      ],
+      [3])
+    ])
+  else
+    GA_CHECK_NC([use_nc=yes])
+  fi
 fi
 if test $use_nc = "yes" ; then
-  GA_SET_LIB_VAR(nc_libs, [netcdf udunits])
+  if test "$ga_dyn_supplibs" = "no" ; then
+    GA_SET_LIB_VAR(nc_libs, [netcdf udunits])
+  fi
   AC_SUBST(nc_libs)
   extra_bins="$extra_bins gradsnc"
   echo "+ gradsnc (plain netCDF) build enabled"
@@ -369,13 +427,26 @@

 use_hdf=no
 if test "$with_hdf" != "no" ; then
-  GA_CHECK_HDF([use_hdf=yes])
+  if test "$ga_dyn_supplibs" = "yes" ; then
+    GA_CHECK_UDUNITS([
+      AC_CHECK_HDF4_NETCDF([
+        LDFLAGS="$LDFLAGS $HDF4_LDFLAGS"
+        CPPFLAGS="$CPPFLAGS $HDF4_CPPFLAGS"
+        use_hdf=yes
+        hdf_libs="$HDF4_LIBS $GA_UDUNITS_LIBS"
+      ])
+    ])
+  else
+    GA_CHECK_HDF([use_hdf=yes])
+  fi
 fi
 if test $use_hdf = "yes" ; then
+  if test "$ga_dyn_supplibs" = "no" ; then
     GA_SET_LIB_VAR(hdf_libs, [mfhdf df jpeg udunits z])
-    AC_SUBST(hdf_libs)
-    extra_bins="$extra_bins gradshdf"
-    echo "+ gradshdf (HDF-SDS/netCDF) build enabled"
+  fi
+  AC_SUBST(hdf_libs)
+  extra_bins="$extra_bins gradshdf"
+  echo "+ gradshdf (HDF-SDS/netCDF) build enabled"
 else
   echo "- gradshdf (HDF-SDS/netCDF) build disabled"
 fi
@@ -384,22 +455,38 @@

 use_dods=no
 if test "$with_dods" != "no" ; then
-  GA_CHECK_DODS([use_dods=yes])
+  if test "$ga_dyn_supplibs" = "yes" ; then
+    GA_CHECK_UDUNITS([
+      AC_CHECK_NC_DODS([
+        CPPFLAGS="$CPPFLAGS $NC_DAP_CFLAGS"
+        dods_libs="$GA_UDUNITS_LIBS $NC_DAP_LIBS"
+        use_dods=yes
+      ])
+    ])
+  else
+    GA_CHECK_DODS([use_dods=yes])
+  fi
 fi

 if test $use_dods = "yes" ; then
-
     extra_bins="$extra_bins gradsdods"
-    GA_SET_LIB_VAR(dods_libs, [udunits www rx z])
-
+    if test "$ga_dyn_supplibs" = "no" ; then
+      GA_SET_LIB_VAR(dods_libs, [udunits www rx z])
+    fi

     GA_CHECK_LIB(gadods, main, [use_gadods=yes], [use_gadods=no])
     if test $use_gadods = "yes" ; then
-       dods_rep_libs="-lgadods -lnc-dods -ldap++"
+       if test "$ga_dyn_supplibs" = "no" ; then
+         dods_rep_libs="-lgadods -lnc-dods -ldap++"
+       else
+         dods_rep_libs="-lgadods"
+       fi
        gadods_def="-DUSEGADODS=1"
        echo "+ gradsdods (OPeNDAP/netCDF) build enabled - gridded and station interfaces"
     else
-       dods_rep_libs="-lnc-dods -ldap++"
+       if test "$ga_dyn_supplibs" = "no" ; then
+         dods_rep_libs="-lnc-dods -ldap++"
+       fi
        gadods_def="-DUSEGADODS=0"
        echo "+ gradsdods (OPeNDAP/netCDF) build enabled - gridded interface only"
     fi
-------------- next part --------------
# -*- mode: autoconf -*-
# Configure macro for Libnc-dap
#
# Code for version detection and comparison comes from freetype2.m4
# Marcelo Magallon 2001-10-26, based on gtk.m4 by Owen Taylor
#
# Copyright 2001, 2003 by
# David Turner, Robert Wilhelm, and Werner Lemberg.
#
# This file is part of the FreeType project, and may only be used, modified,
# and distributed under the terms of the FreeType project license,
# LICENSE.TXT.  By continuing to use, modify, or distribute this file you
# indicate that you have read the license and understand and accept it
# fully.
#
# As a special exception to the FreeType project license, this file may be
# distributed as part of a program that contains a configuration script
# generated by Autoconf, under the same distribution terms as the rest of
# that program.
#
# Patrice Dumas 2005 Libnc-dap specific code

# AC_CHECK_LIBNC_DAP([MINIMUM-VERSION [, ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]]])
# Test for Libnc-dap and define NC_DAP_CFLAGS and NC_DAP_LIBS.
# Check that the version is above MINIMUM-VERSION
# Check for the inclusion of a netcdf.h header file with netcdf 3 interface
AC_DEFUN([AC_CHECK_LIBNC_DAP],
[
  ncdap_header_ok='no'
  ncdap_lib_ok='no'
  AC_CHECK_LIBNC_DAP_LIB([$1],[ncdap_lib_ok='yes'],
     [ncdap_lib_ok='no'])
  ncdap_save_CPPFLAGS=$CPPFLAGS
  CPPFLAGS="$CPPFLAGS $NC_DAP_CFLAGS"
  AC_CHECK_NETCDF_DAP_HEADER([],[ncdap_header_ok='yes'],
    [ncdap_header_ok='no'],[3])
  CPPFLAGS=$ncdap_save_CPPFLAGS

  if test "$ncdap_lib_ok" = 'yes' -a "$ncdap_header_ok" = 'yes' ; then
    m4_if([$2], [], [:], [$2])
  else
    m4_if([$3], [], [:], [$3])
  fi
])

# AC_CHECK_LIBNC_DAP_LIB([MINIMUM-VERSION [, ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]]])
# Test for Libnc-dap and define NC_DAP_CFLAGS and NC_DAP_LIBS.
# Check that the version is above MINIMUM-VERSION
AC_DEFUN([AC_CHECK_LIBNC_DAP_LIB],
[
  AC_PATH_PROG([NC_DAP_CONFIG], [ncdap-config], [no])
  ncdap_min_version=m4_if([$1], [], [3.5.0], [$1])
  AC_MSG_CHECKING([for libnc-dap version >= $ncdap_min_version])
  ncdap_ok='no'
  if test "$NC_DAP_CONFIG" = "no" ; then
     ncdap_ok='no'
  else
     ncdap_config_major_version=`$NC_DAP_CONFIG --version | sed 's/^libnc-dap \([[0-9]]\)*\.\([[0-9]]*\)\.\([[0-9]]*\)$/\1/'`
     ncdap_config_minor_version=`$NC_DAP_CONFIG --version | sed 's/^libnc-dap \([[0-9]]\)*\.\([[0-9]]*\)\.\([[0-9]]*\)$/\2/'`
     ncdap_config_micro_version=`$NC_DAP_CONFIG --version | sed 's/^libnc-dap \([[0-9]]\)*\.\([[0-9]]*\)\.\([[0-9]]*\)$/\2/'`
     ncdap_min_major_version=`echo $ncdap_min_version | sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\1/'`
     ncdap_min_minor_version=`echo $ncdap_min_version | sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\2/'`
     ncdap_min_micro_version=`echo $ncdap_min_version | sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\3/'`

     ncdap_config_is_lt='no'
     if test $ncdap_config_major_version -lt $ncdap_min_major_version ; then
       ncdap_config_is_lt='yes'
     else
       if test $ncdap_config_major_version -eq $ncdap_min_major_version ; then
         if test $ncdap_config_minor_version -lt $ncdap_min_minor_version ; then
           ncdap_config_is_lt='yes'
         else
           if test $ncdap_config_minor_version -eq $ncdap_min_minor_version ; then
             if test $ncdap_config_micro_version -lt $ncdap_min_micro_version ; then
               ncdap_config_is_lt='yes'
             fi
           fi
         fi
       fi
     fi
     if test "x$ncdap_config_is_lt" = "xyes" ; then
       ncdap_ok='no'
     else
       NC_DAP_LIBS="`$NC_DAP_CONFIG --libs`"
       NC_DAP_CFLAGS="`$NC_DAP_CONFIG --cflags`"
     fi
   fi
   if test "x$ncdap_ok" = 'xyes' ; then
     AC_MSG_RESULT([yes])
     m4_if([$2], [], [:], [$2])
   else
     AC_MSG_RESULT([no])
     if test "$NC_DAP_CONFIG" = "no" ; then
     AC_MSG_NOTICE([The ncdap-config script could not be found.])
     else
       if test x$ncdap_config_is_lt = xyes ; then
         AC_MSG_NOTICE([The installed libnc-dap library is too old.])
       fi
     fi
     NC_DAP_LIBS=""
     NC_DAP_CFLAGS=""
     m4_if([$3], [], [:], [$3])

   fi
   AC_SUBST([NC_DAP_CFLAGS])
   AC_SUBST([NC_DAP_LIBS])
])


# AC_FC_CHECK_LIBNC_DAP([MINIMUM-VERSION [, ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]]])
# Test for Libnc-dap and define NC_DAP_FFLAGS and NC_DAP_FLIBS with flags
# for fortran.
# Check that the version is above MINIMUM-VERSION

AC_DEFUN([AC_FC_CHECK_LIBNC_DAP],
[
  libnc_fc_dap_ok="no"
  AC_CHECK_LIBNC_DAP_LIB([$1],[libnc_fc_dap_ok="yes"],[libnc_fc_dap_ok="no"])
  if test $libnc_fc_dap_ok = "yes"; then
     NC_DAP_FLIBS="`$NC_DAP_CONFIG --flibs`"
     NC_DAP_FFLAGS="$NC_DAP_CFLAGS"
     m4_if([$2], [], [:], [$2])
  else
     m4_if([$3], [], [:], [$3])
     NC_DAP_FLIBS=""
     NC_DAP_FFLAGS=""
  fi
  AC_SUBST([NC_DAP_FFLAGS])
  AC_SUBST([NC_DAP_FLIBS])
])

# AC_CHECK_NC_DODS([ ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]]])
# Test for Libnc-dap or older versions. Define NC_DAP_CFLAGS and NC_DAP_LIBS.
# check for the netcdf.h file inclusion
AC_DEFUN([AC_CHECK_NC_DODS],
[
  ncdods_header_ok='no'
  ncdods_lib_ok='no'
  AC_CHECK_NC_DODS_LIB([ncdods_lib_ok='yes'],
     [ncdods_lib_ok='no'])
  ncdods_save_CPPFLAGS=$CPPFLAGS
  CPPFLAGS="$CPPFLAGS $NC_DAP_CFLAGS"
  AC_CHECK_NETCDF_DAP_HEADER([],[ncdods_header_ok='yes'],
    [ncdods_header_ok='no'])
  CPPFLAGS=$ncdods_save_CPPFLAGS

  if test "$ncdods_lib_ok" = 'yes' -a "$ncdods_header_ok" = 'yes' ; then
    m4_if([$1], [], [:], [$1])
  else
    m4_if([$2], [], [:], [$2])
  fi
])

# AC_CHECK_NC_DODS_LIB([ ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]]])
# Test for Libnc-dap or older versions. Define NC_DAP_CFLAGS and NC_DAP_LIBS.
# use AC_CHECK_DODS first
AC_DEFUN([AC_CHECK_NC_DODS_LIB],
[
  ac_ncdods_ok='no'
  ac_ncdods_dap_ok='no'
  NC_DAP_LIBS=
  NC_DAP_CFLAGS=
  dnl it may happen that the cflags are not the ones associated
  dnl with -L and -l flags, however even in that case the most recent
  dnl netcdf.h should be picked up and things should go smoothly
  AC_PATH_PROG([OPENNC_DAP_CONFIG], [opendap-config], [no])
  if test "$OPENNC_DAP_CONFIG" != "no" ; then
     NC_DAP_CFLAGS="`$OPENNC_DAP_CONFIG --cflags`"
  fi
  AC_PATH_PROG([NC_DAP_CONFIG], [ncdap-config], [no])
  if test "$NC_DAP_CONFIG" != "no" ; then
     NC_DAP_CFLAGS="`$NC_DAP_CONFIG --cflags`"
  fi
  AC_CHECK_DODS([ac_ncdods_dap_ok='yes'],[ac_ncdods_dap_ok='no'])
  if test "z$ac_ncdods_dap_ok" = 'zyes'; then
     if test "z$DAP_ROOT" != "z" ; then
        NC_DAP_CFLAGS=$DAP_ROOT/include
     fi
     dnl We check that linking is succesfull
     dnl instead of using a C++ compiler we add -lstdc++
     dnl AC_LANG_PUSH([C++])
     NC_DAP_LIBS="-lnc-dap $DAP_LIBS -ldap"
     ac_save_LIBS=$LIBS
     LIBS="$LIBS $NC_DAP_LIBS -lstdc++"
     AC_MSG_CHECKING([for nc_open with -lnc-dap -ldap])
     AC_LINK_IFELSE([AC_LANG_CALL([],[nc_open])],
       [ ac_ncdods_ok='yes'
         AC_MSG_RESULT([yes])
       ],[ ac_ncdods_ok='no'
         AC_MSG_RESULT([no])
       ])
     LIBS=$ac_save_LIBS
     if test $ac_ncdods_ok = 'no' ; then
       NC_DAP_LIBS="-lnc-dods $DAP_LIBS -ldap++"
       LIBS="$LIBS $NC_DAP_LIBS -lstdc++"
       AC_MSG_CHECKING([for nc_open with -lnc-dods -ldap++])
       AC_LINK_IFELSE([AC_LANG_CALL([],[nc_open])],
         [ ac_ncdods_ok='yes'
           AC_MSG_RESULT([yes])
         ],[ ac_ncdods_ok='no'
           AC_MSG_RESULT([no])
         ])
       LIBS=$ac_save_LIBS
     fi
     dnl AC_LANG_POP
  fi
  if test $ac_ncdods_ok = no ; then
    AC_CHECK_LIBNC_DAP_LIB([],[ac_ncdods_ok='yes'],[ac_ncdods_ok='no'])
    if test "z$ac_ncdods_ok" = "zno" ; then
      AC_MSG_CHECKING([for libnc-dap with opendap-config])
      if test "$OPENNC_DAP_CONFIG" = "no" ; then
        ac_ncdods_ok='no'
        AC_MSG_RESULT([no])
      else
        NC_DAP_LIBS="`$OPENNC_DAP_CONFIG --libs-nc`"
        ac_ncdods_ok='yes'
        AC_MSG_RESULT([yes])
      fi
    fi
  fi
  if test "x$ac_ncdods_ok" = "xyes" ; then
     m4_if([$1], [], [:], [$1])
  else
     m4_if([$2], [], [:], [$2])
  fi
  AC_SUBST([NC_DAP_CFLAGS])
  AC_SUBST([NC_DAP_LIBS])
])
-------------- next part --------------
# Check for the netcdf header.
# AC_CHECK_NETCDF_DAP_HEADER([INCLUDE-DIR],[ACTION-IF-FOUND],
# [ACTION-IF-NOT-FOUND],[INTERFACE-NR])
# if interface number is given, check for a specific interface
# sets NC_CPPFLAGS and maybe NC_NETCDF_3_CPPFLAG
AC_DEFUN([AC_CHECK_NETCDF_DAP_HEADER],
[
  NC_CPPFLAGS=
  ac_netcdf_h='no'
  ac_netcdf_h_compile='no'
  ac_netcdf_h_preproc='no'
  ac_nc_include_dir=
  ac_nc_header_interface=

  ac_nc_save_CPPFLAGS=$CPPFLAGS
  m4_if([$1],[],[:],[
    ac_nc_include_dir="$1"
    AS_IF([test "z$ac_nc_include_dir" != "z"],
       [CPPFLAGS="$CPPFLAGS -I$ac_nc_include_dir"])
  ])
  m4_if([$4],[],[:],[ac_nc_header_interface=$4])
dnl dont use AC_CHECK_HEADERS to avoid autoconf internal caching
  AC_MSG_CHECKING([for netcdf.h with compiler])
  AC_COMPILE_IFELSE([AC_LANG_SOURCE([[#include <netcdf.h>]])],
    [
      AC_MSG_RESULT([yes])
      ac_netcdf_h_compile='yes'
    ],
    [
      AC_MSG_RESULT([no])
      ac_netcdf_h_compile='no'
    ])
    AC_MSG_CHECKING([for netcdf.h with preprocessor])
    AC_PREPROC_IFELSE([AC_LANG_SOURCE([[#include <netcdf.h>]])],
    [
      AC_MSG_RESULT([yes])
      ac_netcdf_h_preproc='yes'
    ],
    [
      AC_MSG_RESULT([no])
      ac_netcdf_h_preproc='no'
    ])
  CPPFLAGS="$ac_nc_save_CPPFLAGS"
  AS_IF([test $ac_netcdf_h_compile = 'yes'],
    [ac_netcdf_h='yes'
    AS_IF([test "z$ac_nc_header_interface" = 'z3'],
      [AC_CHECK_NETCDF_3_DAP_HEADER([$1],
         [ac_netcdf_h='yes'],[ac_netcdf_h='no'])])
    ])

  AS_IF([test "$ac_netcdf_h" = 'yes'],
    [
      AS_IF([test "z$ac_nc_include_dir" != "z"],
        [NC_CPPFLAGS="-I$ac_nc_include_dir"])
      m4_if([$2], [], [:], [$2])
    ],
    [m4_if([$3], [], [:], [$3])])

  AC_SUBST([NC_CPPFLAGS])
])

AC_DEFUN([AC_CHECK_NETCDF_3_DAP_HEADER],
[
  NC_NETCDF_3_CPPFLAG=
  ac_check_netcdf_3_include=
  ac_check_netcdf_3_header='no'
  ac_nc_save_CPPFLAGS=$CPPFLAGS
  AC_MSG_CHECKING([for netcdf 3 interface])
  m4_if([$1],[],[:],[
    ac_check_netcdf_3_include="$1"
  ])
  AS_IF([test "z$ac_check_netcdf_3_include" != "z"],
    [CPPFLAGS="$CPPFLAGS -I$ac_check_netcdf_3_include"])
  AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <netcdf.h>]],
    [[int status;
int ncid;
status = nc_open("foo.nc", 0, &ncid);
char vernum;
vernum = *nc_inq_libvers();]])],
    [
      AS_IF([test "z$ac_check_netcdf_3_include" != "z"],
        [NC_NETCDF_3_CPPFLAG="-I$ac_check_netcdf_3_include"])
      ac_check_netcdf_3_header='yes'
    ],[ac_check_netcdf_3_header='no'])
  CPPFLAGS=$ac_nc_save_CPPFLAGS
  AS_IF([test "$ac_check_netcdf_3_header" = 'yes'],
    [
      AC_MSG_RESULT([yes])
      m4_if([$2], [], [:], [$2])
    ],
    [
      AC_MSG_RESULT([no])
      m4_if([$3], [], [:], [$3])
    ])

  AC_SUBST([NC_NETCDF_3_CPPFLAG])
])
-------------- next part --------------
dnl example of use
dnl AC_CHECK_NETCDF(
dnl   [
dnl       LIBS="$LIBS $NC_LIBS"
dnl       LDFLAGS="$LDFLAGS $NC_LDFLAGS"
dnl       CPPFLAGS="$CPPFLAGS $NC_CPPFLAGS"
dnl   ],
dnl   [
dnl       echo "*** Use --with-netcdf for the root netcdf directory."
dnl       echo "*** Otherwise use --with-netcdf-include switch for includes directory"
dnl       echo "*** and --with-netcdf-libdir switch for libraries directory."
dnl       AC_MSG_ERROR([netcdf library and netcdf headers are required.])
dnl   ]
dnl )

# Check for the netcdf library.
# AC_CHECK_NETCDF([ACTION-IF-FOUND],[ACTION-IF-NOT-FOUND],[INTERFACE-NR])
# if interface number is given, check for a specific interface
# sets NC_LDFLAGS, NC_LIBS, and, by calling other macros
# NC_CPPFLAGS and maybe NC_NETCDF_3_CPPFLAG
AC_DEFUN([AC_CHECK_NETCDF],
[
  AC_ARG_WITH([netcdf],
            [AS_HELP_STRING([--with-netcdf=ARG],[netcdf directory])],
            [NC_PATH=$withval],
            [NC_PATH=""])

  AC_ARG_WITH([netcdf_include],
            [AS_HELP_STRING([--with-netcdf-include=ARG],[netcdf include directory])],
            [NC_PATH_INC=$withval],
            [NC_PATH_INC=""])

  AC_ARG_WITH([netcdf_libdir],
            [AS_HELP_STRING([--with-netcdf-libdir=ARG],[netcdf library directory])],
            [NC_PATH_LIBDIR=$withval],
            [NC_PATH_LIBDIR=""])

  AS_IF([test "z$NC_PATH" != "z"],
  [
    AS_IF([test "z$NC_PATH_LIBDIR" = "z"],[NC_PATH_LIBDIR="$NC_PATH/lib"])
    AS_IF([test "z$NC_PATH_INC" = "z"],[NC_PATH_INC="$NC_PATH/include"])
  ])

  ac_netcdf_ok='no'
  NC_LIBS=
  NC_LDFLAGS=
  ac_nc_save_LDFLAGS=$LDFLAGS
  ac_nc_save_LIBS=$LIBS
  ac_check_nc_func_checked='ncopen'
  ac_check_nc_interface=
dnl the interface number isn't quoted with "" otherwise a newline
dnl following the number isn't stripped.
  m4_if([$3],[],[ac_check_nc_interface=2],[ac_check_nc_interface=$3])
  AS_IF([test "z$ac_check_nc_interface" = 'z3'],
    [ac_check_nc_func_checked='nc_open'])
  AS_IF([test "z$NC_PATH_LIBDIR" != "z"],
    [
      NC_LDFLAGS="-L$NC_PATH_LIBDIR"
      LDFLAGS="$LDFLAGS $NC_LDFLAGS"
dnl the autoconf internal cache isn't avoided because we really check for
dnl libnetcdf, other libraries that implement the same api have other names
dnl  AC_LINK_IFELSE([AC_LANG_CALL([],[$ac_check_func_checked])],
      AC_CHECK_LIB([netcdf],[$ac_check_nc_func_checked],
        [
          NC_LIBS='-lnetcdf'
          ac_netcdf_ok='yes'
        ])
    ],
    [
      for ac_netcdf_libdir in "" \
       /usr/local/netcdf-${ac_check_nc_interface}/lib \
       /opt/netcdf-${ac_check_nc_interface}/lib \
       /usr/netcdf-${ac_check_nc_interface}/lib \
       /usr/local/lib/netcdf-${ac_check_nc_interface} \
       /opt/lib/netcdf-${ac_check_nc_interface} \
       /usr/lib/netcdf-${ac_check_nc_interface} \
       /usr/local/netcdf/lib /opt/netcdf/lib \
       /usr/netcdf/lib /usr/local/lib/netcdf /opt/lib/netcdf \
       /usr/lib/netcdf ; do
        AS_IF([test "z$ac_netcdf_libdir" = 'z'],
          [NC_LDFLAGS=],
          [
            AC_MSG_CHECKING([for netcdf libraries in $ac_netcdf_libdir])
            NC_LDFLAGS="-L$ac_netcdf_libdir"
          ])
        LDFLAGS="$LDFLAGS $NC_LDFLAGS"
        LIBS="$LIBS -lnetcdf"
dnl we have to avoid the autoconf internal cache in that case
        AC_LINK_IFELSE([AC_LANG_CALL([],[$ac_check_nc_func_checked])],
          [
            NC_LIBS='-lnetcdf'
            ac_netcdf_ok='yes'
            AS_IF([test "z$ac_netcdf_libdir" != 'z'],[AC_MSG_RESULT([yes])])
          ],
          [
            AS_IF([test "z$ac_netcdf_libdir" != 'z'],[AC_MSG_RESULT([no])])
          ])
        AS_IF([test $ac_netcdf_ok = 'yes'],[break])
        LDFLAGS=$ac_nc_save_LDFLAGS
        LIBS=$ac_nc_save_LIBS
      done
    ])
  LDFLAGS=$ac_nc_save_LDFLAGS
  LIBS=$ac_nc_save_LIBS

  AC_SUBST([NC_LDFLAGS])
  AC_SUBST([NC_LIBS])
  ac_netcdf_header='no'

  AS_IF([test "z$NC_PATH_INC" != "z"],
    [
      AC_CHECK_NETCDF_HEADER([$NC_PATH_INC],
        [ac_netcdf_header='yes'],
        [ac_netcdf_header='no'],
        [$ac_check_nc_interface])
    ],
    [
      for ac_netcdf_incdir in "" \
       /usr/local/netcdf-${ac_check_nc_interface}/include \
       /opt/netcdf-${ac_check_nc_interface}/include \
       /usr/netcdf-${ac_check_nc_interface}/include \
       /usr/local/include/netcdf-${ac_check_nc_interface} \
       /opt/include/netcdf-${ac_check_nc_interface} \
       /usr/include/netcdf-${ac_check_nc_interface} \
       /usr/local/netcdf/include \
       /opt/netcdf/include /usr/netcdf/include /usr/local/include/netcdf \
       /opt/include/netcdf /usr/include/netcdf ; do
        AC_MSG_NOTICE([searching netcdf includes in $ac_netcdf_incdir])
        AC_CHECK_NETCDF_HEADER([$ac_netcdf_incdir],[ac_netcdf_header='yes'],
          [ac_netcdf_header='no'],[$ac_check_nc_interface])
        AS_IF([test $ac_netcdf_header = 'yes'],[break])
      done
    ])

  AS_IF([test "$ac_netcdf_ok" = 'no' -o "$ac_netcdf_header" = 'no'],
    [m4_if([$2], [], [:], [$2])],
    [m4_if([$1], [], [:], [$1])])
])
-------------- next part --------------
# Check for the netcdf header.
# AC_CHECK_NETCDF_HEADER([INCLUDE-DIR],[ACTION-IF-FOUND],
# [ACTION-IF-NOT-FOUND],[INTERFACE-NR])
# if interface number is given, check for a specific interface
# sets NC_CPPFLAGS and maybe NC_NETCDF_3_CPPFLAG
AC_DEFUN([AC_CHECK_NETCDF_HEADER],
[
  NC_CPPFLAGS=
  ac_netcdf_h='no'
  ac_netcdf_h_compile='no'
  ac_netcdf_h_preproc='no'
  ac_nc_include_dir=
  ac_nc_header_interface=

  ac_nc_save_CPPFLAGS=$CPPFLAGS
  m4_if([$1],[],[:],[
    ac_nc_include_dir="$1"
    AS_IF([test "z$ac_nc_include_dir" != "z"],
       [CPPFLAGS="$CPPFLAGS -I$ac_nc_include_dir"])
  ])
  m4_if([$4],[],[:],[ac_nc_header_interface=$4])
dnl dont use AC_CHECK_HEADERS to avoid autoconf internal caching
  AC_MSG_CHECKING([for netcdf.h with compiler])
  AC_COMPILE_IFELSE([AC_LANG_SOURCE([[#include <netcdf.h>]])],
    [
      AC_MSG_RESULT([yes])
      ac_netcdf_h_compile='yes'
    ],
    [
      AC_MSG_RESULT([no])
      ac_netcdf_h_compile='no'
    ])
    AC_MSG_CHECKING([for netcdf.h with preprocessor])
    AC_PREPROC_IFELSE([AC_LANG_SOURCE([[#include <netcdf.h>]])],
    [
      AC_MSG_RESULT([yes])
      ac_netcdf_h_preproc='yes'
    ],
    [
      AC_MSG_RESULT([no])
      ac_netcdf_h_preproc='no'
    ])
  CPPFLAGS="$ac_nc_save_CPPFLAGS"
  AS_IF([test $ac_netcdf_h_compile = 'yes'],
    [ac_netcdf_h='yes'
    AS_IF([test "z$ac_nc_header_interface" = 'z3'],
      [AC_CHECK_NETCDF_3_HEADER([$1],
         [ac_netcdf_h='yes'],[ac_netcdf_h='no'])])
    ])

  AS_IF([test "$ac_netcdf_h" = 'yes'],
    [
      AS_IF([test "z$ac_nc_include_dir" != "z"],
        [NC_CPPFLAGS="-I$ac_nc_include_dir"])
      m4_if([$2], [], [:], [$2])
    ],
    [m4_if([$3], [], [:], [$3])])

  AC_SUBST([NC_CPPFLAGS])
])

AC_DEFUN([AC_CHECK_NETCDF_3_HEADER],
[
  NC_NETCDF_3_CPPFLAG=
  ac_check_netcdf_3_include=
  ac_check_netcdf_3_header='no'
  ac_nc_save_CPPFLAGS=$CPPFLAGS
  AC_MSG_CHECKING([for netcdf 3 interface])
  m4_if([$1],[],[:],[
    ac_check_netcdf_3_include="$1"
  ])
  AS_IF([test "z$ac_check_netcdf_3_include" != "z"],
    [CPPFLAGS="$CPPFLAGS -I$ac_check_netcdf_3_include"])
  AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <netcdf.h>]],
    [[int status;
int ncid;
status = nc_open("foo.nc", 0, &ncid);
char vernum;
vernum = *nc_inq_libvers();]])],
    [
      AS_IF([test "z$ac_check_netcdf_3_include" != "z"],
        [NC_NETCDF_3_CPPFLAG="-I$ac_check_netcdf_3_include"])
      ac_check_netcdf_3_header='yes'
    ],[ac_check_netcdf_3_header='no'])
  CPPFLAGS=$ac_nc_save_CPPFLAGS
  AS_IF([test "$ac_check_netcdf_3_header" = 'yes'],
    [
      AC_MSG_RESULT([yes])
      m4_if([$2], [], [:], [$2])
    ],
    [
      AC_MSG_RESULT([no])
      m4_if([$3], [], [:], [$3])
    ])

  AC_SUBST([NC_NETCDF_3_CPPFLAG])
])
-------------- next part --------------
dnl AC_CHECK_HDF : Check for hdf4
dnl args :             action-if-yes, action-if-no

AC_DEFUN([AC_CHECK_HDF4],
[
  AC_ARG_WITH([hdf4],
            [AS_HELP_STRING([--with-hdf4=ARG],[hdf4 directory])],
            [HDF4_PATH=$withval],
            [HDF4_PATH=""])

  AC_ARG_WITH([hdf4_include],
            [AS_HELP_STRING([--with-hdf4-include=ARG],[hdf 4 include directory])],
            [HDF4_PATH_INC=$withval],
            [HDF4_PATH_INC=""])

  AC_ARG_WITH([hdf4_libdir],
            [AS_HELP_STRING([--with-hdf4-libdir=ARG],[hdf 4 library directory])],
            [HDF4_PATH_LIBDIR=$withval],
            [HDF4_PATH_LIBDIR=""])

  dnl This is a very common location for the hdf4 code. jhrg 10/11/05
  AS_IF([test -d /usr/local/hdf], [HDF4_PATH="/usr/local/hdf"])

  AS_IF([test "z$HDF4_PATH" != "z"],
  [
    AS_IF([test "z$HDF4_PATH_LIBDIR" = "z"],
      [HDF4_PATH_LIBDIR="$HDF4_PATH/lib"])
    AS_IF([test "z$HDF4_PATH_INC" = "z"],
      [HDF4_PATH_INC="$HDF4_PATH/include"])
  ])


  ac_hdf4_lib_ok='no'
  ac_hdf4_save_LDFLAGS=$LDFLAGS
  HDF4_LIBS=
  AS_IF([test "z$HDF4_PATH_LIBDIR" != "z"],
    [
      HDF4_LDFLAGS="-L$HDF4_PATH_LIBDIR"
      LDFLAGS="$LDFLAGS $HDF4_LDFLAGS"
      AC_CHECK_HDF4_LIB([ac_hdf4_lib_ok='yes'])
    ],
    [
      for ac_hdf4_libdir in "" /usr/local/hdf4.2r1/lib /opt/hdf4.2r1/lib \
       /usr/hdf4.2r1/lib /usr/local/lib/hdf4.2r1 /opt/lib/hdf4.2r1 \
       /usr/lib/hdf4.2r1 /usr/local/hdf/lib/ /opt/hdf/lib /usr/hdf/lib \
       /usr/local/lib/hdf /opt/lib/hdf /usr/lib/hdf ; do
        AS_IF([test "z$ac_hdf4_libdir" = 'z'],
           [HDF4_LDFLAGS=],
           [
             AC_MSG_NOTICE([searching hdf libraries in $ac_hdf4_libdir])
             HDF4_LDFLAGS="-L$ac_hdf4_libdir"
           ])
        LDFLAGS="$LDFLAGS $HDF4_LDFLAGS"
        AC_CHECK_HDF4_LIB([ac_hdf4_lib_ok='yes'])
        AS_IF([test $ac_hdf4_lib_ok = 'yes'],[break])
        LDFLAGS=$ac_hdf4_save_LDFLAGS
      done
    ])
  LDFLAGS=$ac_hdf4_save_LDFLAGS

  ac_hdf4_h='no'
  HDF4_CPPFLAGS=
  ac_hdf4_save_CPPFLAGS=$CPPFLAGS
  AS_IF([test "z$HDF4_PATH_INC" != "z"],
    [
       HDF4_CPPFLAGS="-I$HDF4_PATH_INC"
       CPPFLAGS="$CPPFLAGS $HDF4_CPPFLAGS"
       AC_CHECK_HEADER_NOCACHE_HDF4([mfhdf.h],[ac_hdf4_h='yes'])
    ],
    [
      for ac_hdf4_incdir in "" /usr/local/hdf4.2r1/include /opt/hdf4.2r1/include \
       /usr/hdf4.2r1/include /usr/local/include/hdf4.2r1 \
       /opt/include/hdf4.2r1 /usr/include/hdf4.2r1 /usr/local/hdf/include \
       /opt/hdf/include /usr/hdf/include /usr/local/include/hdf \
       /opt/include/hdf /usr/include/hdf ; do
        AS_IF([test "z$ac_hdf4_incdir" = 'z'],
           [HDF4_CPPFLAGS=],
           [
             AC_MSG_NOTICE([searching hdf includes in $ac_hdf4_incdir])
             HDF4_CPPFLAGS="-I$ac_hdf4_incdir"
           ])
        CPPFLAGS="$CPPFLAGS $HDF4_CPPFLAGS"
        AC_CHECK_HEADER_NOCACHE_HDF4([mfhdf.h],[ac_hdf4_h='yes'])
        AS_IF([test $ac_hdf4_h = 'yes'],[break])
        CPPFLAGS=$ac_hdf4_save_CPPFLAGS
      done
    ])
  CPPFLAGS=$ac_hdf4_save_CPPFLAGS

  AS_IF([test "$ac_hdf4_h" = 'yes' -a "$ac_hdf4_lib_ok" = 'yes'],
  [m4_if([$1], [], [:], [$1])],
  [m4_if([$2], [], [:], [$2])])

  AC_SUBST([HDF4_LIBS])
  AC_SUBST([HDF4_CPPFLAGS])
  AC_SUBST([HDF4_LDFLAGS])
])

dnl check for the netcdf 2 interface provided by hdf
AC_DEFUN([AC_CHECK_HDF4_NETCDF],
[
  ac_hdf4_netcdf_lib='no'
  ac_hdf4_netcdf_h='no'
  AC_CHECK_HDF4([
    ac_hdf4_netcdf_save_LDFLAGS=$LDFLAGS
    ac_hdf4_netcdf_save_LIBS=$LIBS
    LIBS="$LIBS $HDF4_LIBS"
    LDFLAGS="$LDFLAGS $HDF4_LDFLAGS"
    AC_MSG_CHECKING([for ncopen with hdf link flags])
    AC_LINK_IFELSE([AC_LANG_CALL([],[ncopen])],
      [
        AC_MSG_RESULT([yes])
        ac_hdf4_netcdf_lib='yes'
      ],
      [
        AC_MSG_RESULT([no])
        ac_hdf4_netcdf_lib='no'
      ])
    LDFLAGS=$ac_hdf4_netcdf_save_LDFLAGS
    LIBS=$ac_hdf4_netcdf_save_LIBS

    ac_hdf4_netcdf_save_CPPFLAGS=$CPPFLAGS
    CPPFLAGS="$CPPFLAGS $HDF4_CPPFLAGS"
    AC_CHECK_NETCDF_HEADER([],[ac_hdf4_netcdf_h='yes'])
    CPPFLAGS=$ac_hdf4_netcdf_save_CPPFLAGS
  ])

  AS_IF([test $ac_hdf4_netcdf_lib = 'yes' -a $ac_hdf4_netcdf_h = 'yes'],
  [m4_if([$1], [], [:], [$1])],
  [m4_if([$2], [], [:], [$2])])

])

AC_DEFUN([AC_CHECK_HDF4_LIB],
[
  HDF4_LIBS=
  ac_hdf4_save_LIBS=$LIBS
  AC_CHECK_LIB_NOCACHE_HDF4([sz], [SZ_BufftoBuffCompress],
  [
      LIBS="$LIBS -lsz"
      HDF4_LIBS='-lsz'
  ])

dnl -lsz is not required because due to licencing it may not be present
dnl nor required everywhere
  ac_hdf4_lib='no'
  AC_CHECK_LIB_NOCACHE_HDF4([z],[deflate],
  [ AC_CHECK_LIB_NOCACHE_HDF4([jpeg],[jpeg_start_compress],
    [ AC_CHECK_LIB_NOCACHE_HDF4([df],[Hopen],
      [ AC_CHECK_LIB_NOCACHE_HDF4([mfhdf],[SDstart],
        [ ac_hdf4_lib="yes"
          HDF4_LIBS="-lmfhdf -ldf -ljpeg -lz $HDF4_LIBS"
        ],[],[-ldf -ljpeg -lz])
      ],[],[-ljpeg -lz])
    ])
  ])
  LIBS=$ac_hdf4_save_LIBS

  AS_IF([test "$ac_hdf4_lib" = 'yes'],
  [m4_if([$1], [], [:], [$1])],
  [m4_if([$2], [], [:], [$2])])
])

AC_DEFUN([AC_CHECK_LIB_NOCACHE_HDF4],
[
  AS_TR_SH([ac_check_lib_nocache_ok_$1_$2])='no'
  AS_TR_SH([ac_check_lib_nocache_$1_$2_LIBS])=$LIBS
  LIBS="-l$1 $5 $LIBS"
  AC_MSG_CHECKING([for $2 in -l$1])
  AC_LINK_IFELSE([AC_LANG_CALL([], [$2])],
  [
    AS_TR_SH([ac_check_lib_nocache_ok_$1_$2])='yes'
    AC_MSG_RESULT([yes])
  ],[
    AC_MSG_RESULT([no])
  ])
  LIBS=$AS_TR_SH([ac_check_lib_nocache_$1_$2_LIBS])
  AS_IF([test $AS_TR_SH([ac_check_lib_nocache_ok_$1_$2]) = 'yes'],
  [m4_if([$3], [], [:], [$3])],
  [m4_if([$4], [], [:], [$4])])
])

AC_DEFUN([AC_CHECK_HEADER_NOCACHE_HDF4],
[
  AS_TR_SH([ac_check_header_nocache_compile_$1])='no'
  AS_TR_SH([ac_check_header_nocache_preproc_$1])='no'
  AC_MSG_CHECKING([for $1 with compiler])
  AC_COMPILE_IFELSE([AC_LANG_SOURCE([[#include <$1>]])],
    [
      AC_MSG_RESULT([yes])
      AS_TR_SH([ac_check_header_nocache_compile_$1])='yes'
    ],
    [
      AC_MSG_RESULT([no])
    ])
  AC_MSG_CHECKING([for $1 with preprocessor])
  AC_PREPROC_IFELSE([AC_LANG_SOURCE([[#include <$1>]])],
    [
      AC_MSG_RESULT([yes])
      AS_TR_SH([ac_check_header_nocache_preproc_$1])='yes'
    ],
    [
      AC_MSG_RESULT([no])
      AS_IF([test "$AS_TR_SH([ac_check_header_nocache_compile_$1])" = 'yes'],
        [AC_MSG_WARN([trusting compiler result, ignoring preprocessor error])])
    ])
  AS_IF([test "$AS_TR_SH([ac_check_header_nocache_compile_$1])" = 'yes'],
  [m4_if([$2], [], [:], [$2])],
  [m4_if([$3], [], [:], [$3])])
])


More information about the gradsusr mailing list