+# check for octave
+if test x"$with_octave" = "xyes"; then
+ AC_MSG_NOTICE([Checking for necessary tools to build octave wrappers])
+
+ # find octave and mkoctfile
+ AC_PATH_PROG(OCTAVE,octave)
+ AC_PATH_PROG(MKOCTFILE,mkoctfile)
+
+ if test -z "$OCTAVE"; then
+ AC_MSG_WARN([octave not found, disabling octave wrappers])
+ with_octave=no
+ fi
+ if test -z "$MKOCTFILE"; then
+ AC_MSG_WARN([mkoctfile not found, disabling octave wrappers])
+ with_octave=no
+ fi
+ OCTAVE_INCFLAGS=`$MKOCTFILE -p INCFLAGS`
+ AC_SUBST(OCTAVE_INCFLAGS,[$OCTAVE_INCFLAGS])
+fi
+if test x"$with_octave" = "xyes"; then
+ # check that octave version is at least 2.9.12
+ cat > conftest.m <<'EOF'
+[[a,b,c]]=sscanf([[version()," "]],"%i.%i.%i","C");
+exit(sum([[a,b,c]].*[[1e5,1e3,1]])<209012)
+EOF
+ $OCTAVE --no-init-file conftest.m >& /dev/null || with_octave="no";
+ rm -f conftest.m
+
+ if test x"$with_octave" = "xno"; then
+ AC_MSG_WARN([Octave version < 2.9.12, disabling octave wrappers])
+ fi
+fi
+if test x"$with_octave" = "xyes"; then
+ # if not explicitly forbidden, check for swig also
+ if test x"$with_swig" = "xauto"; then
+ with_swig=yes
+ fi
+
+ # check that we have octave headers
+ OLD_CPPFLAGS=$CPPFLAGS
+ CPPFLAGS="$CPPFLAGS -x c++ $OCTAVE_INCFLAGS"
+ AC_CHECK_HEADER(octave/oct.h,
+ [have_octave=yes],
+ [
+ AC_MSG_WARN([Octave headers not found, disabling octave wrappers])
+ have_octave=no
+ ])
+
+ # restore the old CPPFLAGS
+ CPPFLAGS=$OLD_CPPFLAGS
+
+ # find Octave arch
+ AC_MSG_CHECKING([for Octave arch])
+ OCTAVE_ARCH=`$OCTAVE -q --eval 'strcat(octave_config_info("canonical_host_type"), "-", octave_config_info("api_version"))'|sed -e 's/ans = //'`
+ AC_MSG_RESULT([$OCTAVE_ARCH])
+ AC_SUBST(OCTAVE_ARCH,[$OCTAVE_ARCH])
+
+else
+ # check if ./configure arguments are valid
+ if test x"$with_octave" = "xno"; then
+ have_octave=no
+ else
+ # if we get here then --with-octave was not called with 'yes','no' or 'auto'
+ AC_MSG_WARN([unexpected arguments for option --with-octave, continuing assuming 'no'])
+ have_octave=no
+ fi
+fi
+AM_CONDITIONAL([BUILD_OCTAVE_WRAPPERS], [test x"$have_octave" = "xyes"])
+