Index: configure.in =================================================================== --- configure.in (revision 23757) +++ configure.in (working copy) @@ -1410,6 +1410,10 @@ NETCDF_ROOT= NETCDF_HAS_NC4= NETCDF_HAS_HDF4= +NETCDF_VERSION= +NETCDF_VERSION_MAJOR= +NETCDF_NCDUMP= +NETCDF_NCCONFIG= AC_ARG_WITH([netcdf],[ --with-netcdf[=ARG] Include netCDF support (ARG=no or netCDF tree prefix)],,) @@ -1419,6 +1423,62 @@ echo "netCDF support disabled." +dnl use ncdump and nc-config to find version and linking information +else + + dnl find ncdump location + if test "$with_netcdf" = "yes" -o "$with_netcdf" = "" ; then + NETCDF_NCDUMP=`which ncdump` + else + NETCDF_NCDUMP="$with_netcdf/bin/ncdump" + if ! test -x "$NETCDF_NCDUMP" ; then + NETCDF_NCDUMP="$with_netcdf/ncdump" + fi + fi + + if test -x "$NETCDF_NCDUMP" ; then + + dnl find libnetcdf version with ncdump + AC_MSG_CHECKING([libnetcdf version with $NETCDF_NCDUMP]) + NETCDF_VERSION=`$NETCDF_NCDUMP 2>&1 | grep "netcdf library version" | awk '{gsub(/"/,"");print $4}'` + AC_MSG_RESULT([got $NETCDF_VERSION]) + if test "$NETCDF_VERSION" != "" -a "${NETCDF_VERSION:0:1}" != "" ; then + NETCDF_VERSION_MAJOR=${NETCDF_VERSION:0:1} + fi + + dnl find nc-config location + NETCDF_NCCONFIG=`dirname $NETCDF_NCDUMP`/nc-config + if ! test -x "$NETCDF_NCCONFIG" ; then + echo "did not find nc-config, some features may be missing" + NETCDF_NCCONFIG= + fi + + else + echo "did not find ncdump, some features may be missing" + NETCDF_NCDUMP= + fi + +fi + +dnl test linking using information from nc-config +if test "$NETCDF_NCCONFIG" != "" ; then + + AC_MSG_CHECKING([libnetcdf compiler and linker flags with $NETCDF_NCCONFIG]) + NETCDF_PREFIX=`nc-config --prefix` + NETCDF_INCLUDEDIR=`nc-config --includedir` + NETCDF_LIBS=`nc-config --libs` + echo "" + AC_MSG_RESULT([ got prefix="$NETCDF_PREFIX" libs="$NETCDF_LIBS"] includedir="$NETCDF_INCLUDEDIR") + + AC_CHECK_LIB([netcdf], [nc_open], [NETCDF_SETTING=yes], [NETCDF_SETTING=no], $NETCDF_LIBS) + + if test "$NETCDF_SETTING" = "yes" ; then + EXTRA_INCLUDES="-I$NETCDF_INCLUDEDIR $EXTRA_INCLUDES" + NETCDF_ROOT=$NETCDF_PREFIX + LIBS="$NETCDF_LIBS $LIBS" + fi + +dnl test linking using default settings elif test "$with_netcdf" = "yes" -o "$with_netcdf" = "" ; then AC_CHECK_LIB([netcdf], [nc_open], [NETCDF_SETTING=yes], [NETCDF_SETTING=no],) @@ -1455,6 +1515,7 @@ echo "libnetcdf not found - netCDF support disabled" fi +dnl test linking using --with_netcdf dir else AC_CHECK_LIB([netcdf], [nc_open], [NETCDF_SETTING=yes], [NETCDF_SETTING=no],-L$with_netcdf -L$with_netcdf/lib) @@ -1480,30 +1541,13 @@ fi -dnl start new test - -dnl test for NC4 and HDF4 support +dnl test for NC4 and HDF4 support with nc-config if test "$NETCDF_SETTING" = "yes" ; then - ncdump=$NETCDF_ROOT"/bin/ncdump" - nc_config="" + if test "$NETCDF_NCCONFIG" != "" ; then - dnl test for libnetcdf v4 - if { test -x "$ncdump"; }; then - AC_MSG_CHECKING([libnetcdf version with $ncdump]) - netcdf_version=`$ncdump 2>&1 | grep "netcdf library version" | awk '{gsub(/"/,"");print $4}'` - AC_MSG_RESULT([got $netcdf_version]) - if test "$netcdf_version" != "" -a "${netcdf_version:0:1}" == "4" ; then - nc_config=$NETCDF_ROOT"/bin/nc-config" - fi - fi - - dnl if nc-config is found (only for libnetcdf-4), test for netcdf-4 and HDF4 support - if { test -x "$nc_config"; }; then - echo "checking libnetcdf config with $nc_config" - AC_MSG_CHECKING([for netcdf-4 (and HDF5) support in libnetcdf]) - if test "x$($nc_config --has-nc4)" = "xyes"; then : + if test "x$($NETCDF_NCCONFIG --has-nc4)" = "xyes"; then : AC_MSG_RESULT([yes]) NETCDF_HAS_NC4=yes else @@ -1512,7 +1556,7 @@ fi AC_MSG_CHECKING([for HDF4 support in libnetcdf]) - if test "x$($nc_config --has-hdf4)" = "xyes"; then : + if test "x$($NETCDF_NCCONFIG --has-hdf4)" = "xyes"; then : AC_MSG_RESULT([yes]) NETCDF_HAS_HDF4=yes else @@ -1527,15 +1571,18 @@ fi fi -dnl end new test +dnl export results AC_SUBST([NETCDF_SETTING], [$NETCDF_SETTING]) -AC_SUBST([NETCDF_ROOT], [$NETCDF_ROOT]) -AC_SUBST([NETCDF_HAS_NC4], [$NETCDF_HAS_NC4]) -AC_SUBST([NETCDF_HAS_HDF4], [$NETCDF_HAS_HDF4]) if test "$NETCDF_SETTING" != "no" ; then - OPT_GDAL_FORMATS="netcdf $OPT_GDAL_FORMATS" + + AC_SUBST([NETCDF_ROOT], [$NETCDF_ROOT]) + AC_SUBST([NETCDF_HAS_NC4], [$NETCDF_HAS_NC4]) + AC_SUBST([NETCDF_HAS_HDF4], [$NETCDF_HAS_HDF4]) + + OPT_GDAL_FORMATS="netcdf $OPT_GDAL_FORMATS" + fi