--- octave.cmake_orig	2006-10-18 18:21:30.000000000 +0200
+++ octave.cmake	2006-10-18 19:02:35.000000000 +0200
@@ -57,16 +57,21 @@
 endif(ENABLE_octave)
 
 if(ENABLE_octave)
+  find_program(OCTAVECONFIG octave-config)
+  if(OCTAVECONFIG)
+    message(STATUS "OCTAVECONFIG = ${OCTAVECONFIG}")
+  else(OCTAVECONFIG)
+    message(STATUS "WARNING: "
+    "octave-config not found. Disabling octave bindings")
+    set(ENABLE_octave OFF CACHE BOOL "Enable Octave bindings" FORCE)
+  endif(OCTAVECONFIG)
+endif(ENABLE_octave)
+
+if(ENABLE_octave)
   #OCTAVE_VERSION is the (dotted triplet) octave version.
   execute_process(
-  COMMAND ${OCTAVE} --version
-  OUTPUT_VARIABLE _OCTAVE_VERSION
-  )
-  string(REGEX REPLACE
-  "^.*version ([0-9]\\.[0-9]\\.[0-9][0-9]).*$" 
-  "\\1"
-  OCTAVE_VERSION
-  ${_OCTAVE_VERSION}
+  COMMAND ${OCTAVECONFIG} -p VERSION
+  OUTPUT_VARIABLE OCTAVE_VERSION
   )
   message(STATUS "OCTAVE_VERSION = ${OCTAVE_VERSION}")
 
@@ -78,48 +83,72 @@
   # if OCTAVE_INCLUDE_PATH is defined from the previous cmake run should be
   # fine.
   if(NOT DEFINED OCTAVE_INCLUDE_PATH)
-    find_path(
-    OCTAVE_INCLUDE_PATH
-    oct.h
-    PATH_SUFFIXES octave-${OCTAVE_VERSION}/octave
-    )
-
-    find_library(
-    OCTAVE_LIBRARIES
-    octave
-    PATH_SUFFIXES octave-${OCTAVE_VERSION}
-    )
-    
-    find_library(
-    OCTINTERP_LIBRARIES
-    octinterp
-    PATH_SUFFIXES octave-${OCTAVE_VERSION}
-    )
-
-    if(OCTAVE_INCLUDE_PATH AND OCTAVE_LIBRARIES AND OCTINTERP_LIBRARIES)
-      # If first octave include path has trailing /octave, then must have
-      # second include path without that trailing /octave.
-      string(REGEX REPLACE "/octave$" ""
-      OCTAVE_INCLUDE_PATH_TRIMMED
-      ${OCTAVE_INCLUDE_PATH}
+    execute_process(
+	COMMAND ${OCTAVECONFIG} -p OCTINCLUDEDIR
+	OUTPUT_VARIABLE OCTAVE_INCLUDE_PATH
       )
-      if(NOT OCTAVE_INCLUDE_PATH_TRIMMED STREQUAL "${OCTAVE_INCLUDE_PATH}")
         set(OCTAVE_INCLUDE_PATH 
-	${OCTAVE_INCLUDE_PATH_TRIMMED} ${OCTAVE_INCLUDE_PATH}
+	${OCTAVE_INCLUDE_PATH} 
 	CACHE INTERNAL ""
 	)
-      endif(NOT OCTAVE_INCLUDE_PATH_TRIMMED STREQUAL "${OCTAVE_INCLUDE_PATH}")
-    else(OCTAVE_INCLUDE_PATH AND OCTAVE_LIBRARIES AND OCTINTERP_LIBRARIES)
-      message(STATUS "WARNING: "
-      "octave headers and/or library not found. Disabling octave bindings")
-      set(ENABLE_octave OFF CACHE BOOL "Enable Octave bindings" FORCE)
-    endif(OCTAVE_INCLUDE_PATH AND OCTAVE_LIBRARIES AND OCTINTERP_LIBRARIES) 
-  endif(NOT DEFINED OCTAVE_INCLUDE_PATH)
+    message(STATUS "OCTAVE_INCLUDE_PATH = ${OCTAVE_INCLUDE_PATH}")
+    execute_process(
+	COMMAND ${OCTAVECONFIG} -p OCTLIBDIR
+	OUTPUT_VARIABLE OCTAVE_LIBRARIES
+    )
   message(STATUS "OCTAVE_LIBRARIES = ${OCTAVE_LIBRARIES}")
+    # Redundant?
+    execute_process(
+	COMMAND ${OCTAVECONFIG} -p OCTINCLUDEDIR
+	OUTPUT_VARIABLE OCTINTERP_LIBRARIES
+    )
   message(STATUS "OCTINTERP_LIBRARIES = ${OCTINTERP_LIBRARIES}")
-  message(STATUS "OCTAVE_INCLUDE_PATH = ${OCTAVE_INCLUDE_PATH}")
+  endif(NOT DEFINED OCTAVE_INCLUDE_PATH)
 endif(ENABLE_octave)
 
+#   if(NOT DEFINED OCTAVE_INCLUDE_PATH)
+#     find_path(
+#     OCTAVE_INCLUDE_PATH
+#     oct.h
+#     PATH_SUFFIXES octave-${OCTAVE_VERSION}/octave
+#     )
+
+#     find_library(
+#     OCTAVE_LIBRARIES
+#     octave
+#     PATH_SUFFIXES octave-${OCTAVE_VERSION}
+#     )
+    
+#     find_library(
+#     OCTINTERP_LIBRARIES
+#     octinterp
+#     PATH_SUFFIXES octave-${OCTAVE_VERSION}
+#     )
+
+#     if(OCTAVE_INCLUDE_PATH AND OCTAVE_LIBRARIES AND OCTINTERP_LIBRARIES)
+#       # If first octave include path has trailing /octave, then must have
+#       # second include path without that trailing /octave.
+#       string(REGEX REPLACE "/octave$" ""
+#       OCTAVE_INCLUDE_PATH_TRIMMED
+#       ${OCTAVE_INCLUDE_PATH}
+#       )
+#       if(NOT OCTAVE_INCLUDE_PATH_TRIMMED STREQUAL "${OCTAVE_INCLUDE_PATH}")
+#         set(OCTAVE_INCLUDE_PATH 
+# 	${OCTAVE_INCLUDE_PATH_TRIMMED} ${OCTAVE_INCLUDE_PATH}
+# 	CACHE INTERNAL ""
+# 	)
+#       endif(NOT OCTAVE_INCLUDE_PATH_TRIMMED STREQUAL "${OCTAVE_INCLUDE_PATH}")
+#     else(OCTAVE_INCLUDE_PATH AND OCTAVE_LIBRARIES AND OCTINTERP_LIBRARIES)
+#       message(STATUS "WARNING: "
+#       "octave headers and/or library not found. Disabling octave bindings")
+#       set(ENABLE_octave OFF CACHE BOOL "Enable Octave bindings" FORCE)
+#     endif(OCTAVE_INCLUDE_PATH AND OCTAVE_LIBRARIES AND OCTINTERP_LIBRARIES) 
+#   endif(NOT DEFINED OCTAVE_INCLUDE_PATH)
+#   message(STATUS "OCTAVE_LIBRARIES = ${OCTAVE_LIBRARIES}")
+#   message(STATUS "OCTINTERP_LIBRARIES = ${OCTINTERP_LIBRARIES}")
+#   message(STATUS "OCTAVE_INCLUDE_PATH = ${OCTAVE_INCLUDE_PATH}")
+# endif(ENABLE_octave)
+
 if(ENABLE_octave)
   check_perl_modules(PERL_XML_PARSER XML::Parser)
   check_perl_modules(PERL_XML_DOM XML::DOM)
