| 1 | AC_DEFUN([ACX_NETCDF], [ |
|---|
| 2 | acx_netcdf_ok=no |
|---|
| 3 | |
|---|
| 4 | dnl Check if the library was given in the command line |
|---|
| 5 | AC_ARG_WITH(netcdf-prefix, [AS_HELP_STRING([--with-netcdf-prefix=DIR], [Directory where netcdf was installed.])]) |
|---|
| 6 | case $with_netcdf_prefix in |
|---|
| 7 | no ) acx_netcdf_ok=disabled ;; |
|---|
| 8 | "") if test x$FCFLAGS_NETCDF == x; then |
|---|
| 9 | FCFLAGS_NETCDF="-I/usr/include" |
|---|
| 10 | fi;; |
|---|
| 11 | *) LIBS_NETCDF="-L$with_netcdf_prefix/lib"; FCFLAGS_NETCDF="$ax_cv_f90_modflag$with_netcdf_prefix/include" ;; |
|---|
| 12 | esac |
|---|
| 13 | |
|---|
| 14 | AC_ARG_WITH(netcdf-include, [AS_HELP_STRING([--with-netcdf-include=DIR], [Directory where netcdf Fortran headers were installed.])]) |
|---|
| 15 | case $with_netcdf_include in |
|---|
| 16 | "") ;; |
|---|
| 17 | *) FCFLAGS_NETCDF="$ax_cv_f90_modflag$with_netcdf_include" ;; |
|---|
| 18 | esac |
|---|
| 19 | |
|---|
| 20 | dnl Backup LIBS and FCFLAGS |
|---|
| 21 | acx_netcdf_save_LIBS="$LIBS" |
|---|
| 22 | acx_netcdf_save_FCFLAGS="$FCFLAGS" |
|---|
| 23 | |
|---|
| 24 | dnl The tests |
|---|
| 25 | AC_MSG_CHECKING([for netcdf]) |
|---|
| 26 | if test "$acx_netcdf_ok" != disabled; then |
|---|
| 27 | netcdf_fcflags="$FCFLAGS_NETCDF" |
|---|
| 28 | FCFLAGS="$netcdf_fcflags $acx_netcdf_save_FCFLAGS" |
|---|
| 29 | for netcdf_libsl in "" -lnetcdf "-lnetcdff -lnetcdf"; do |
|---|
| 30 | netcdf_libs="$LIBS_NETCDF $netcdf_libsl" |
|---|
| 31 | LIBS="$netcdf_libs $acx_netcdf_save_LIBS" |
|---|
| 32 | AC_LINK_IFELSE(AC_LANG_PROGRAM([],[ |
|---|
| 33 | use netcdf |
|---|
| 34 | integer :: ncid |
|---|
| 35 | integer :: status |
|---|
| 36 | status = nf90_close(ncid) |
|---|
| 37 | ]), [acx_netcdf_ok=yes; FCFLAGS_NETCDF="$netcdf_fcflags"; LIBS_NETCDF="$netcdf_libs"], []) |
|---|
| 38 | if test $acx_netcdf_ok == yes; then |
|---|
| 39 | LIBS_NETCDF=$netcdf_libs |
|---|
| 40 | break |
|---|
| 41 | fi |
|---|
| 42 | done |
|---|
| 43 | fi |
|---|
| 44 | AC_MSG_RESULT([$acx_netcdf_ok ($FCFLAGS_NETCDF $LIBS_NETCDF)]) |
|---|
| 45 | |
|---|
| 46 | dnl Finally, execute ACTION-IF-FOUND/ACTION-IF-NOT-FOUND: |
|---|
| 47 | if test x"$acx_netcdf_ok" = xyes; then |
|---|
| 48 | AC_DEFINE(HAVE_NETCDF,1,[Defined if you have NETCDF library.]) |
|---|
| 49 | $1 |
|---|
| 50 | else |
|---|
| 51 | AC_MSG_WARN([Could not find NetCDF library. |
|---|
| 52 | *** Will compile without NetCDF and ETSF I/O support]) |
|---|
| 53 | FCFLAGS_NETCDF="" |
|---|
| 54 | LIBS_NETCDF="" |
|---|
| 55 | $2 |
|---|
| 56 | fi |
|---|
| 57 | |
|---|
| 58 | AC_SUBST(FCFLAGS_NETCDF) |
|---|
| 59 | AC_SUBST(LIBS_NETCDF) |
|---|
| 60 | FCFLAGS="$acx_netcdf_save_FCFLAGS" |
|---|
| 61 | LIBS="$acx_netcdf_save_LIBS" |
|---|
| 62 | ])dnl ACX_NETCDF |
|---|