From 2a3568f502831edf9a40ed52c178d1397b31acfb Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Stefan=20Br=C3=BCns?= <stefan.bruens@rwth-aachen.de>
Date: Fri, 2 Apr 2021 19:53:26 +0200
Subject: [PATCH 1/2] Use reentrant libqhull_r

Actual porting is trivial, as it only requires replacing all occurences
of the "qh" macro with the dereferenced instace "qh->", and passing
the context to all qh_* function calls as first parameter.

Cleanup libqhull include statements - qhull.h has been a proxy for
libqhull.h since 2009.1 and removed in 2011.1, and is irrelevant for
libqhull_r.h. Likewise for the <qhull/*.h> hierarchy, headers are always
below "libqhull_r/".
---
 configure.ac                      |  14 ++--
 libinterp/dldfcn/__delaunayn__.cc |  26 ++++----
 libinterp/dldfcn/__voronoi__.cc   |  41 ++++++------
 libinterp/dldfcn/convhulln.cc     |  53 +++++++--------
 libinterp/dldfcn/oct-qhull.h      |  38 ++++-------
 m4/acinclude.m4                   | 104 +++++++++++-------------------
 6 files changed, 115 insertions(+), 161 deletions(-)

diff --git a/configure.ac b/configure.ac
index 5a07285..4a40ec9 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1336,15 +1336,15 @@ AC_CHECK_DECLS([sys_siglist], [], [],
 
 ### Check for the Qhull library.
 
-OCTAVE_CHECK_LIB(qhull, QHull,
+OCTAVE_CHECK_LIB(qhull_r, QHull,
   [Qhull library not found.  This will result in loss of functionality for some geometry functions.],
-  [libqhull/libqhull.h qhull/libqhull.h libqhull.h qhull/qhull.h qhull.h],
+  [libqhull_r/libqhull_r.h libqhull_r.h],
   [qh_qhull], [], [],
-  [warn_qhull=
+  [warn_qhull_r=
   OCTAVE_CHECK_QHULL_VERSION
   OCTAVE_CHECK_LIB_QHULL_OK(
     [AC_DEFINE(HAVE_QHULL, 1, [Define to 1 if Qhull is available.])],
-    [warn_qhull="Qhull library found, but does not seem to work properly.  This will result in loss of functionality for some geometry functions.  Please try recompiling the library with -fno-strict-aliasing."])])
+    [warn_qhull_r="Qhull library found, but does not seem to work properly.  This will result in loss of functionality for some geometry functions.  Please try recompiling the library with -fno-strict-aliasing."])])
 
 ### Check for PCRE regex library.
 
@@ -3109,9 +3109,9 @@ Octave is now configured for $canonical_host_type
   PortAudio libraries:           $PORTAUDIO_LIBS
   PTHREAD flags:                 $PTHREAD_CFLAGS
   PTHREAD libraries:             $PTHREAD_LIBS
-  QHULL CPPFLAGS:                $QHULL_CPPFLAGS
-  QHULL LDFLAGS:                 $QHULL_LDFLAGS
-  QHULL libraries:               $QHULL_LIBS
+  QHULL CPPFLAGS:                $QHULL_R_CPPFLAGS
+  QHULL LDFLAGS:                 $QHULL_R_LDFLAGS
+  QHULL libraries:               $QHULL_R_LIBS
   QRUPDATE CPPFLAGS:             $QRUPDATE_CPPFLAGS
   QRUPDATE LDFLAGS:              $QRUPDATE_LDFLAGS
   QRUPDATE libraries:            $QRUPDATE_LIBS
diff --git a/libinterp/dldfcn/__delaunayn__.cc b/libinterp/dldfcn/__delaunayn__.cc
index 853eb97..8257db4 100644
--- a/libinterp/dldfcn/__delaunayn__.cc
+++ b/libinterp/dldfcn/__delaunayn__.cc
@@ -65,7 +65,7 @@
 
 #  include "oct-qhull.h"
 
-#  if defined (NEED_QHULL_VERSION)
+#  if defined (NEED_QHULL_R_VERSION)
 char qh_version[] = "__delaunayn__.oct 2007-08-21";
 #  endif
 
@@ -76,12 +76,12 @@
 }

 static void
-free_qhull_memory ()
+free_qhull_memory (qhT *qh)
 {
-  qh_freeqhull (! qh_ALL);
+  qh_freeqhull (qh, ! qh_ALL);

   int curlong, totlong;
-  qh_memfreeshort (&curlong, &totlong);
+  qh_memfreeshort (qh, &curlong, &totlong);

   if (curlong || totlong)
     warning ("__delaunayn__: did not free %d bytes of long memory (%d pieces)",
@@ -161,10 +161,7 @@
       double *pt_array = p.fortran_vec ();
       boolT ismalloc = false;

-      // Qhull flags argument is not const char*
-      OCTAVE_LOCAL_BUFFER (char, flags, 9 + options.length ());
-
-      sprintf (flags, "qhull d %s", options.c_str ());
+      std::string cmd = "qhull d " + options;

       octave::unwind_protect frame;

@@ -181,16 +178,19 @@

       frame.add_fcn (close_fcn, outfile);

-      int exitcode = qh_new_qhull (dim, n, pt_array,
-                                   ismalloc, flags, outfile, errfile);
+      qhT context = { };
+      qhT *qh = &context;
+
+      int exitcode = qh_new_qhull (qh, dim, n, pt_array, ismalloc, &cmd[0],
+                                   outfile, errfile);

-      frame.add_fcn (free_qhull_memory);
+      octave::unwind_action free_memory ([qh] () { free_qhull_memory (qh); });

       if (exitcode)
         error ("__delaunayn__: qhull failed");

       // triangulate non-simplicial facets
-      qh_triangulate ();
+      qh_triangulate (qh);

       facetT *facet;
       vertexT *vertex, **vertexp;
@@ -217,7 +217,7 @@

               FOREACHvertex_ (facet->vertices)
                 {
-                  simpl(i, j++) = 1 + qh_pointid(vertex->point);
+                  simpl(i, j++) = 1 + qh_pointid(qh, vertex->point);
                 }
               i++;
             }
diff --git a/libinterp/dldfcn/__voronoi__.cc b/libinterp/dldfcn/__voronoi__.cc
index 950f46d..14633e2 100644
--- a/libinterp/dldfcn/__voronoi__.cc
+++ b/libinterp/dldfcn/__voronoi__.cc
@@ -60,7 +60,7 @@ qhull command
 
 #  include "oct-qhull.h"
 
-#  if defined (NEED_QHULL_VERSION)
+#  if defined (NEED_QHULL_R_VERSION)
 char qh_version[] = "__voronoi__.oct 2007-07-24";
 #  endif
 
@@ -71,12 +71,12 @@
 }

 static void
-free_qhull_memory ()
+free_qhull_memory (qhT *qh)
 {
-  qh_freeqhull (! qh_ALL);
+  qh_freeqhull (qh, ! qh_ALL);

   int curlong, totlong;
-  qh_memfreeshort (&curlong, &totlong);
+  qh_memfreeshort (qh, &curlong, &totlong);

   if (curlong || totlong)
     warning ("__voronoi__: did not free %d bytes of long memory (%d pieces)",
@@ -173,35 +173,32 @@

   frame.add_fcn (close_fcn, outfile);

-  // qh_new_qhull command and points arguments are not const...
+  qhT context = { };
+  qhT *qh = &context;

   std::string cmd = "qhull v" + options;

-  OCTAVE_LOCAL_BUFFER (char, cmd_str, cmd.length () + 1);
+  int exitcode = qh_new_qhull (qh, dim, num_points, points.fortran_vec (),
+                               ismalloc, &cmd[0], outfile, errfile);

-  strcpy (cmd_str, cmd.c_str ());
-
-  int exitcode = qh_new_qhull (dim, num_points, points.fortran_vec (),
-                               ismalloc, cmd_str, outfile, errfile);
-
-  frame.add_fcn (free_qhull_memory);
+  octave::unwind_action free_memory ([qh] () { free_qhull_memory (qh); });

   if (exitcode)
     error ("%s: qhull failed", caller.c_str ());

   // Calling findgood_all provides the number of Voronoi vertices
-  // (sets qh num_good).
+  // (sets qh->num_good).

-  qh_findgood_all (qh facet_list);
+  qh_findgood_all (qh, qh->facet_list);

   octave_idx_type num_voronoi_regions
-    = qh num_vertices - qh_setsize (qh del_vertices);
+    = qh->num_vertices - qh_setsize (qh, qh->del_vertices);

-  octave_idx_type num_voronoi_vertices = qh num_good;
+  octave_idx_type num_voronoi_vertices = qh->num_good;

   // Find the voronoi centers for all facets.

-  qh_setvoronoi_all ();
+  qh_setvoronoi_all (qh);

   facetT *facet;
   vertexT *vertex;
@@ -224,8 +221,8 @@

   FORALLvertices
     {
-      if (qh hull_dim == 3)
-        qh_order_vertexneighbors (vertex);
+      if (qh->hull_dim == 3)
+        qh_order_vertexneighbors (qh, vertex);

       bool infinity_seen = false;

@@ -289,12 +286,12 @@

   FORALLvertices
     {
-      if (qh hull_dim == 3)
-        qh_order_vertexneighbors (vertex);
+      if (qh->hull_dim == 3)
+        qh_order_vertexneighbors (qh, vertex);

       bool infinity_seen = false;

-      octave_idx_type idx = qh_pointid (vertex->point);
+      octave_idx_type idx = qh_pointid (qh, vertex->point);

       octave_idx_type num_vertices = ni[k++];

diff --git a/libinterp/dldfcn/convhulln.cc b/libinterp/dldfcn/convhulln.cc
index 724cf36..c6caa57 100644
--- a/libinterp/dldfcn/convhulln.cc
+++ b/libinterp/dldfcn/convhulln.cc
@@ -53,7 +53,7 @@
 
 #  include "oct-qhull.h"
 
-#  if defined (NEED_QHULL_VERSION)
+#  if defined (NEED_QHULL_R_VERSION)
 char qh_version[] = "convhulln.oct 2007-07-24";
 #  endif
 
@@ -64,12 +64,12 @@
 }

 static void
-free_qhull_memory ()
+free_qhull_memory (qhT *qh)
 {
-  qh_freeqhull (! qh_ALL);
+  qh_freeqhull (qh, ! qh_ALL);

   int curlong, totlong;
-  qh_memfreeshort (&curlong, &totlong);
+  qh_memfreeshort (qh, &curlong, &totlong);

   if (curlong || totlong)
     warning ("convhulln: did not free %d bytes of long memory (%d pieces)",
@@ -188,25 +188,22 @@

   frame.add_fcn (close_fcn, outfile);

-  // qh_new_qhull command and points arguments are not const...
+  qhT context = { };
+  qhT *qh = &context;

   std::string cmd = "qhull" + options;

-  OCTAVE_LOCAL_BUFFER (char, cmd_str, cmd.length () + 1);
+  int exitcode = qh_new_qhull (qh, dim, num_points, points.fortran_vec (),
+                               ismalloc, &cmd[0], outfile, errfile);

-  strcpy (cmd_str, cmd.c_str ());
-
-  int exitcode = qh_new_qhull (dim, num_points, points.fortran_vec (),
-                               ismalloc, cmd_str, outfile, errfile);
-
-  frame.add_fcn (free_qhull_memory);
+  octave::unwind_action free_memory ([qh] () { free_qhull_memory (qh); });

   if (exitcode)
     error ("convhulln: qhull failed");

   bool nonsimp_seen = false;

-  octave_idx_type nf = qh num_facets;
+  octave_idx_type nf = qh->num_facets;

   Matrix idx (nf, dim + 1);

@@ -218,7 +215,7 @@
     {
       octave_idx_type j = 0;

-      if (! (nonsimp_seen || facet->simplicial || qh hull_dim == 2))
+      if (! (nonsimp_seen || facet->simplicial || qh->hull_dim == 2))
         {
           nonsimp_seen = true;

@@ -229,14 +226,14 @@

       if (dim == 3)
         {
-          setT *vertices = qh_facet3vertex (facet);
+          setT *vertices = qh_facet3vertex (qh, facet);

           vertexT *vertex, **vertexp;

           FOREACHvertex_ (vertices)
-            idx(i, j++) = 1 + qh_pointid(vertex->point);
+            idx(i, j++) = 1 + qh_pointid(qh, vertex->point);

-          qh_settempfree (&vertices);
+          qh_settempfree (qh, &vertices);
         }
       else
         {
@@ -245,14 +242,14 @@
               vertexT *vertex, **vertexp;

               FOREACHvertex_ (facet->vertices)
-                idx(i, j++) = 1 + qh_pointid(vertex->point);
+                idx(i, j++) = 1 + qh_pointid(qh, vertex->point);
             }
           else
             {
               vertexT *vertex, **vertexp;

               FOREACHvertexreverse12_ (facet->vertices)
-                idx(i, j++) = 1 + qh_pointid(vertex->point);
+                idx(i, j++) = 1 + qh_pointid(qh, vertex->point);
             }
         }
       if (j < dim)
@@ -280,26 +277,26 @@
           if (! facet->normal)
             continue;

-          if (facet->upperdelaunay && qh ATinfinity)
+          if (facet->upperdelaunay && qh->ATinfinity)
             continue;

-          facet->f.area = area = qh_facetarea (facet);
+          facet->f.area = area = qh_facetarea (qh, facet);
           facet->isarea = True;

-          if (qh DELAUNAY)
+          if (qh->DELAUNAY)
             {
-              if (facet->upperdelaunay == qh UPPERdelaunay)
-                qh totarea += area;
+              if (facet->upperdelaunay == qh->UPPERdelaunay)
+                qh->totarea += area;
             }
           else
             {
-              qh totarea += area;
-              qh_distplane (qh interior_point, facet, &dist);
-              qh totvol += -dist * area/ qh hull_dim;
+              qh->totarea += area;
+              qh_distplane (qh, qh->interior_point, facet, &dist);
+              qh->totvol += -dist * area / qh->hull_dim;
             }
         }

-      retval(1) = octave_value (qh totvol);
+      retval(1) = octave_value (qh->totvol);
     }

   retval(0) = idx;
diff --git a/libinterp/dldfcn/oct-qhull.h b/libinterp/dldfcn/oct-qhull.h
index d28ba87..2f6323f 100644
--- a/libinterp/dldfcn/oct-qhull.h
+++ b/libinterp/dldfcn/oct-qhull.h
@@ -32,32 +32,18 @@
 
 extern "C" {
 
-#if defined (HAVE_LIBQHULL_LIBQHULL_H)
-#  include <libqhull/libqhull.h>
-#  include <libqhull/qset.h>
-#  include <libqhull/geom.h>
-#  include <libqhull/poly.h>
-#  include <libqhull/io.h>
-#elif defined (HAVE_QHULL_LIBQHULL_H) || defined (HAVE_QHULL_QHULL_H)
-#  if defined (HAVE_QHULL_LIBQHULL_H)
-#    include <qhull/libqhull.h>
-#  else
-#    include <qhull/qhull.h>
-#  endif
-#  include <qhull/qset.h>
-#  include <qhull/geom.h>
-#  include <qhull/poly.h>
-#  include <qhull/io.h>
-#  elif defined (HAVE_LIBQHULL_H) || defined (HAVE_QHULL_H)
-#  if defined (HAVE_LIBQHULL_H)
-#    include <libqhull.h>
-#  else
-#    include <qhull.h>
-#  endif
-#  include <qset.h>
-#  include <geom.h>
-#  include <poly.h>
-#  include <io.h>
+#if defined (HAVE_LIBQHULL_R_LIBQHULL_R_H)
+#  include <libqhull_r/libqhull_r.h>
+#  include <libqhull_r/qset_r.h>
+#  include <libqhull_r/geom_r.h>
+#  include <libqhull_r/poly_r.h>
+#  include <libqhull_r/io_r.h>
+#elif defined (HAVE_LIBQHULL_R_H)
+#  include <libqhull_r.h>
+#  include <qset_r.h>
+#  include <geom_r.h>
+#  include <poly_r.h>
+#  include <io_r.h>
 #endif
 
 }
diff --git a/m4/acinclude.m4 b/m4/acinclude.m4
index a6b8c61..40b4284 100644
--- a/m4/acinclude.m4
+++ b/m4/acinclude.m4
@@ -1793,38 +1793,24 @@ dnl
 dnl Check whether Qhull works (does not crash).
 dnl
 AC_DEFUN([OCTAVE_CHECK_LIB_QHULL_OK], [
-  AC_CACHE_CHECK([whether the qhull library works],
-    [octave_cv_lib_qhull_ok],
+  AC_CACHE_CHECK([whether the qhull_r library works],
+    [octave_cv_lib_qhull_r_ok],
     [AC_RUN_IFELSE([AC_LANG_PROGRAM([[
         #include <stdio.h>
-        #if defined (HAVE_LIBQHULL_LIBQHULL_H)
-        # include <libqhull/libqhull.h>
-        # include <libqhull/qset.h>
-        # include <libqhull/geom.h>
-        # include <libqhull/poly.h>
-        # include <libqhull/io.h>
-        #elif defined (HAVE_QHULL_LIBQHULL_H) || defined (HAVE_QHULL_QHULL_H)
-        # if defined (HAVE_QHULL_LIBQHULL_H)
-        #  include <qhull/libqhull.h>
-        # else
-        #  include <qhull/qhull.h>
-        # endif
-        # include <qhull/qset.h>
-        # include <qhull/geom.h>
-        # include <qhull/poly.h>
-        # include <qhull/io.h>
-        #elif defined (HAVE_LIBQHULL_H) || defined (HAVE_QHULL_H)
-        # if defined (HAVE_LIBQHULL_H)
-        #  include <libqhull.h>
-        # else
-        #  include <qhull.h>
-        # endif
-        # include <qset.h>
-        # include <geom.h>
-        # include <poly.h>
-        # include <io.h>
+        #if defined (HAVE_LIBQHULL_R_LIBQHULL_R_H)
+        # include <libqhull_r/libqhull_r.h>
+        # include <libqhull_r/qset_r.h>
+        # include <libqhull_r/geom_r.h>
+        # include <libqhull_r/poly_r.h>
+        # include <libqhull_r/io_r.h>
+        #elif defined (HAVE_LIBQHULL_R_H)
+        # include <libqhull_r.h>
+        # include <qset_r.h>
+        # include <geom_r.h>
+        # include <poly_r.h>
+        # include <io_r.h>
         #endif
-        #if defined (NEED_QHULL_VERSION)
+        #if defined (NEED_QHULL_R_VERSION)
           char *qh_version = "version";
         #endif
         ]], [[
@@ -1832,13 +1818,15 @@ AC_DEFUN([OCTAVE_CHECK_LIB_QHULL_OK], [
         int n = 4;
         coordT points[8] = { -0.5, -0.5, -0.5, 0.5, 0.5, -0.5, 0.5, 0.5 };
         boolT ismalloc = 0;
-        return qh_new_qhull (dim, n, points, ismalloc, "qhull ", 0, stderr);
+        qhT context = { };
+        qhT* qh = &context;
+        return qh_new_qhull (qh, dim, n, points, ismalloc, "qhull ", 0, stderr);
       ]])],
-      octave_cv_lib_qhull_ok=yes,
-      octave_cv_lib_qhull_ok=no,
-      octave_cv_lib_qhull_ok=yes)
+      octave_cv_lib_qhull_r_ok=yes,
+      octave_cv_lib_qhull_r_ok=no,
+      octave_cv_lib_qhull_r_ok=yes)
   ])
-  if test $octave_cv_lib_qhull_ok = yes; then
+  if test $octave_cv_lib_qhull_r_ok = yes; then
     $1
     :
   else
@@ -2030,44 +2018,30 @@ dnl
 dnl Check for the Qhull version.
 dnl
 AC_DEFUN([OCTAVE_CHECK_QHULL_VERSION], [
-  AC_CACHE_CHECK([for qh_version in $QHULL_LIBS],
-    [octave_cv_lib_qhull_version],
+  AC_CACHE_CHECK([for qh_version in $QHULL_R_LIBS],
+    [octave_cv_lib_qhull_r_version],
     [AC_LINK_IFELSE([AC_LANG_PROGRAM([[
         #include <stdio.h>
-        #if defined (HAVE_LIBQHULL_LIBQHULL_H)
-        # include <libqhull/libqhull.h>
-        # include <libqhull/qset.h>
-        # include <libqhull/geom.h>
-        # include <libqhull/poly.h>
-        # include <libqhull/io.h>
-        #elif defined (HAVE_QHULL_LIBQHULL_H) || defined (HAVE_QHULL_QHULL_H)
-        # if defined (HAVE_QHULL_LIBQHULL_H)
-        #  include <qhull/libqhull.h>
-        # else
-        #  include <qhull/qhull.h>
-        # endif
-        # include <qhull/qset.h>
-        # include <qhull/geom.h>
-        # include <qhull/poly.h>
-        # include <qhull/io.h>
-        #elif defined (HAVE_LIBQHULL_H) || defined (HAVE_QHULL_H)
-        # if defined (HAVE_LIBQHULL_H)
-        #  include <libqhull.h>
-        # else
-        #  include <qhull.h>
-        # endif
-        # include <qset.h>
-        # include <geom.h>
-        # include <poly.h>
-        # include <io.h>
+        #if defined (HAVE_LIBQHULL_R_LIBQHULL_R_H)
+        # include <libqhull_r/libqhull_r.h>
+        # include <libqhull_r/qset_r.h>
+        # include <libqhull_r/geom_r.h>
+        # include <libqhull_r/poly_r.h>
+        # include <libqhull_r/io_r.h>
+        #elif defined (HAVE_LIBQHULL_R_H)
+        # include <libqhull_r.h>
+        # include <qset_r.h>
+        # include <geom_r.h>
+        # include <poly_r.h>
+        # include <io_r.h>
         #endif
         ]], [[
         const char *tmp = qh_version;
       ]])],
-      octave_cv_lib_qhull_version=yes, octave_cv_lib_qhull_version=no)
+      octave_cv_lib_qhull_r_version=yes, octave_cv_lib_qhull_r_version=no)
   ])
-  if test $octave_cv_lib_qhull_version = no; then
-    AC_DEFINE(NEED_QHULL_VERSION, 1,
+  if test $octave_cv_lib_qhull_r_version = no; then
+    AC_DEFINE(NEED_QHULL_R_VERSION, 1,
       [Define to 1 if the Qhull library needs a qh_version variable defined.])
   fi
 ])
-- 
2.30.2

From d34451766b4f8ed2a60733c7fe902bb5f51a2f4f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Stefan=20Br=C3=BCns?= <stefan.bruens@rwth-aachen.de>
Date: Fri, 2 Apr 2021 19:54:00 +0200
Subject: [PATCH 2/2] Use reentrant libqhull_r - update generated files

---
 Makefile.in |  24 ++---
 config.in.h |  19 ++--
 configure   | 252 +++++++++++++++++++++++-----------------------------
 3 files changed, 130 insertions(+), 165 deletions(-)

diff --git a/Makefile.in b/Makefile.in
index 59d9d5e..e7023b4 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -5278,9 +5278,9 @@ QCOLLECTIONGENERATOR_QTVER = @QCOLLECTIONGENERATOR_QTVER@
 QHELPGENERATOR = @QHELPGENERATOR@
 QHELPGENERATORFLAGS = @QHELPGENERATORFLAGS@
 QHELPGENERATOR_QTVER = @QHELPGENERATOR_QTVER@
-QHULL_CPPFLAGS = @QHULL_CPPFLAGS@
-QHULL_LDFLAGS = @QHULL_LDFLAGS@
-QHULL_LIBS = @QHULL_LIBS@
+QHULL_R_CPPFLAGS = @QHULL_R_CPPFLAGS@
+QHULL_R_LDFLAGS = @QHULL_R_LDFLAGS@
+QHULL_R_LIBS = @QHULL_R_LIBS@
 QRUPDATE_CPPFLAGS = @QRUPDATE_CPPFLAGS@
 QRUPDATE_LDFLAGS = @QRUPDATE_LDFLAGS@
 QRUPDATE_LIBS = @QRUPDATE_LIBS@
@@ -8337,9 +8337,9 @@ DLDFCN_SRC = \
 
 DLDFCN_LIBS = $(DLDFCN_SRC:.cc=.la)
 libinterp_dldfcn___delaunayn___la_SOURCES = libinterp/dldfcn/__delaunayn__.cc
-libinterp_dldfcn___delaunayn___la_CPPFLAGS = $(libinterp_liboctinterp_la_CPPFLAGS) $(QHULL_CPPFLAGS)
-libinterp_dldfcn___delaunayn___la_LDFLAGS = -avoid-version -module $(NO_UNDEFINED_LDFLAG) $(QHULL_LDFLAGS) $(OCT_LINK_OPTS) $(WARN_LDFLAGS)
-libinterp_dldfcn___delaunayn___la_LIBADD = $(DLD_LIBOCTINTERP_LIBADD) $(QHULL_LIBS)
+libinterp_dldfcn___delaunayn___la_CPPFLAGS = $(libinterp_liboctinterp_la_CPPFLAGS) $(QHULL_R_CPPFLAGS)
+libinterp_dldfcn___delaunayn___la_LDFLAGS = -avoid-version -module $(NO_UNDEFINED_LDFLAG) $(QHULL_R_LDFLAGS) $(OCT_LINK_OPTS) $(WARN_LDFLAGS)
+libinterp_dldfcn___delaunayn___la_LIBADD = $(DLD_LIBOCTINTERP_LIBADD) $(QHULL_R_LIBS)
 libinterp_dldfcn___delaunayn___la_DEPENDENCIES = $(OCT_LINK_DEPS)
 libinterp_dldfcn___fltk_uigetfile___la_SOURCES = libinterp/dldfcn/__fltk_uigetfile__.cc
 libinterp_dldfcn___fltk_uigetfile___la_CPPFLAGS = $(libinterp_liboctinterp_la_CPPFLAGS) $(FLTK_CPPFLAGS) $(FT2_CPPFLAGS)
@@ -8367,9 +8367,9 @@ libinterp_dldfcn___ode15___la_LDFLAGS = -avoid-version -module $(NO_UNDEFINED_LD
 libinterp_dldfcn___ode15___la_LIBADD = $(DLD_LIBOCTINTERP_LIBADD) $(SUNDIALS_XLIBS)
 libinterp_dldfcn___ode15___la_DEPENDENCIES = $(OCT_LINK_DEPS)
 libinterp_dldfcn___voronoi___la_SOURCES = libinterp/dldfcn/__voronoi__.cc
-libinterp_dldfcn___voronoi___la_CPPFLAGS = $(libinterp_liboctinterp_la_CPPFLAGS) $(QHULL_CPPFLAGS)
-libinterp_dldfcn___voronoi___la_LDFLAGS = -avoid-version -module $(NO_UNDEFINED_LDFLAG) $(QHULL_LDFLAGS) $(OCT_LINK_OPTS) $(WARN_LDFLAGS)
-libinterp_dldfcn___voronoi___la_LIBADD = $(DLD_LIBOCTINTERP_LIBADD) $(QHULL_LIBS)
+libinterp_dldfcn___voronoi___la_CPPFLAGS = $(libinterp_liboctinterp_la_CPPFLAGS) $(QHULL_R_CPPFLAGS)
+libinterp_dldfcn___voronoi___la_LDFLAGS = -avoid-version -module $(NO_UNDEFINED_LDFLAG) $(QHULL_R_LDFLAGS) $(OCT_LINK_OPTS) $(WARN_LDFLAGS)
+libinterp_dldfcn___voronoi___la_LIBADD = $(DLD_LIBOCTINTERP_LIBADD) $(QHULL_R_LIBS)
 libinterp_dldfcn___voronoi___la_DEPENDENCIES = $(OCT_LINK_DEPS)
 libinterp_dldfcn_audiodevinfo_la_SOURCES = libinterp/dldfcn/audiodevinfo.cc
 libinterp_dldfcn_audiodevinfo_la_CPPFLAGS = $(libinterp_liboctinterp_la_CPPFLAGS) $(PORTAUDIO_CPPFLAGS)
@@ -8382,9 +8382,9 @@ libinterp_dldfcn_audioread_la_LDFLAGS = -avoid-version -module $(NO_UNDEFINED_LD
 libinterp_dldfcn_audioread_la_LIBADD = $(DLD_LIBOCTINTERP_LIBADD) $(SNDFILE_LIBS)
 libinterp_dldfcn_audioread_la_DEPENDENCIES = $(OCT_LINK_DEPS)
 libinterp_dldfcn_convhulln_la_SOURCES = libinterp/dldfcn/convhulln.cc
-libinterp_dldfcn_convhulln_la_CPPFLAGS = $(libinterp_liboctinterp_la_CPPFLAGS) $(QHULL_CPPFLAGS)
-libinterp_dldfcn_convhulln_la_LDFLAGS = -avoid-version -module $(NO_UNDEFINED_LDFLAG) $(QHULL_LDFLAGS) $(OCT_LINK_OPTS) $(WARN_LDFLAGS)
-libinterp_dldfcn_convhulln_la_LIBADD = $(DLD_LIBOCTINTERP_LIBADD) $(QHULL_LIBS)
+libinterp_dldfcn_convhulln_la_CPPFLAGS = $(libinterp_liboctinterp_la_CPPFLAGS) $(QHULL_R_CPPFLAGS)
+libinterp_dldfcn_convhulln_la_LDFLAGS = -avoid-version -module $(NO_UNDEFINED_LDFLAG) $(QHULL_R_LDFLAGS) $(OCT_LINK_OPTS) $(WARN_LDFLAGS)
+libinterp_dldfcn_convhulln_la_LIBADD = $(DLD_LIBOCTINTERP_LIBADD) $(QHULL_R_LIBS)
 libinterp_dldfcn_convhulln_la_DEPENDENCIES = $(OCT_LINK_DEPS)
 libinterp_dldfcn_fftw_la_SOURCES = libinterp/dldfcn/fftw.cc
 libinterp_dldfcn_fftw_la_CPPFLAGS = $(libinterp_liboctinterp_la_CPPFLAGS) $(FFTW_XCPPFLAGS)
diff --git a/config.in.h b/config.in.h
index 068af98..c4d9d64 100644
--- a/config.in.h
+++ b/config.in.h
@@ -1153,11 +1153,11 @@
 /* Define to 1 if you have the `m' library (-lm). */
 #undef HAVE_LIBM
 
-/* Define to 1 if you have the <libqhull.h> header file. */
-#undef HAVE_LIBQHULL_H
+/* Define to 1 if you have the <libqhull_r.h> header file. */
+#undef HAVE_LIBQHULL_R_H
 
-/* Define to 1 if you have the <libqhull/libqhull.h> header file. */
-#undef HAVE_LIBQHULL_LIBQHULL_H
+/* Define to 1 if you have the <libqhull_r/libqhull_r.h> header file. */
+#undef HAVE_LIBQHULL_R_LIBQHULL_R_H
 
 /* Define to 1 if you have the `sun' library (-lsun). */
 #undef HAVE_LIBSUN
@@ -1493,15 +1493,6 @@
 /* Define to 1 if Qhull is available. */
 #undef HAVE_QHULL
 
-/* Define to 1 if you have the <qhull.h> header file. */
-#undef HAVE_QHULL_H
-
-/* Define to 1 if you have the <qhull/libqhull.h> header file. */
-#undef HAVE_QHULL_LIBQHULL_H
-
-/* Define to 1 if you have the <qhull/qhull.h> header file. */
-#undef HAVE_QHULL_QHULL_H
-
 /* Define to 1 if you have the `qInstallMessageHandler' function. */
 #undef HAVE_QINSTALLMESSAGEHANDLER
 
@@ -2246,7 +2237,7 @@
 #undef NEED_MKTIME_WORKING
 
 /* Define to 1 if the Qhull library needs a qh_version variable defined. */
-#undef NEED_QHULL_VERSION
+#undef NEED_QHULL_R_VERSION
 
 /* Define to 1 to enable general improvements of setlocale. */
 #undef NEED_SETLOCALE_IMPROVED
diff --git a/configure b/configure
index d3bf4af..b8b7305 100755
--- a/configure
+++ b/configure
@@ -850,9 +850,9 @@ TERM_LIBS
 PCRE_LIBS
 PCRE_LDFLAGS
 PCRE_CPPFLAGS
-QHULL_LIBS
-QHULL_LDFLAGS
-QHULL_CPPFLAGS
+QHULL_R_LIBS
+QHULL_R_LDFLAGS
+QHULL_R_CPPFLAGS
 gltests_WITNESS
 REPLACE_TOWLOWER
 REPLACE_ISWCNTRL
@@ -2451,9 +2451,9 @@ with_linux_crypto
 with_openssl
 enable_rpath
 with_libiconv_prefix
-with_qhull_includedir
-with_qhull_libdir
-with_qhull
+with_qhull_r_includedir
+with_qhull_r_libdir
+with_qhull_r
 with_pcre_includedir
 with_pcre_libdir
 with_pcre
@@ -3313,10 +3313,10 @@ Optional Packages:
   --with-gnu-ld           assume the C compiler uses GNU ld [default=no]
   --with-libiconv-prefix[=DIR]  search for libiconv in DIR/include and DIR/lib
   --without-libiconv-prefix     don't search for libiconv in includedir and libdir
-  --with-qhull-includedir=DIR
+  --with-qhull_r-includedir=DIR
                           look for QHull include files in DIR
-  --with-qhull-libdir=DIR look for QHull libraries in DIR
-  --without-qhull         don't use QHull library
+  --with-qhull_r-libdir=DIR look for QHull libraries in DIR
+  --without-qhull_r         don't use QHull library
   --with-pcre-includedir=DIR
                           look for PCRE include files in DIR
   --with-pcre-libdir=DIR  look for PCRE libraries in DIR
@@ -70826,79 +70826,79 @@ _ACEOF
 
 
 
-# Check whether --with-qhull-includedir was given.
-if test "${with_qhull_includedir+set}" = set; then :
-  withval=$with_qhull_includedir; QHULL_CPPFLAGS="-I$withval"
+# Check whether --with-qhull_r-includedir was given.
+if test "${with_qhull_r_includedir+set}" = set; then :
+  withval=$with_qhull_r_includedir; QHULL_R_CPPFLAGS="-I$withval"
 fi
 
 
 
 
-# Check whether --with-qhull-libdir was given.
-if test "${with_qhull_libdir+set}" = set; then :
-  withval=$with_qhull_libdir; QHULL_LDFLAGS="-L$withval"
+# Check whether --with-qhull_r-libdir was given.
+if test "${with_qhull_r_libdir+set}" = set; then :
+  withval=$with_qhull_r_libdir; QHULL_R_LDFLAGS="-L$withval"
 fi
 
 
 
 
-# Check whether --with-qhull was given.
-if test "${with_qhull+set}" = set; then :
-  withval=$with_qhull; with_qhull=$withval
+# Check whether --with-qhull_r was given.
+if test "${with_qhull_r+set}" = set; then :
+  withval=$with_qhull_r; with_qhull_r=$withval
 else
-  with_qhull=yes
+  with_qhull_r=yes
 fi
 
 
-  ac_octave_qhull_pkg_check=no
-  QHULL_LIBS=
-  warn_qhull="Qhull library not found.  This will result in loss of functionality for some geometry functions."
-  case $with_qhull in
+  ac_octave_qhull_r_pkg_check=no
+  QHULL_R_LIBS=
+  warn_qhull_r="Qhull library not found.  This will result in loss of functionality for some geometry functions."
+  case $with_qhull_r in
     no)
-      warn_qhull="--without-qhull specified.  Functions or features that depend on QHull will be disabled."
-         QHULL_LIBS=
+      warn_qhull_r="--without-qhull_r specified.  Functions or features that depend on QHull will be disabled."
+         QHULL_R_LIBS=
     ;;
     yes | "")
-      ac_octave_qhull_pkg_check=yes
-      QHULL_LIBS="-lqhull"
+      ac_octave_qhull_r_pkg_check=yes
+      QHULL_R_LIBS="-lqhull_r"
     ;;
     -* | */* | *.a | *.so | *.so.* | *.o)
-      QHULL_LIBS="$with_qhull"
+      QHULL_R_LIBS="$with_qhull_r"
     ;;
     *)
-      QHULL_LIBS="-l$with_qhull"
+      QHULL_R_LIBS="-l$with_qhull_r"
     ;;
   esac
 
-  if test $ac_octave_qhull_pkg_check = yes; then
+  if test $ac_octave_qhull_r_pkg_check = yes; then
     if test -n "$PKG_CONFIG" && \
-    { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"qhull\""; } >&5
-  ($PKG_CONFIG --exists --print-errors "qhull") 2>&5
+    { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"qhull_r\""; } >&5
+  ($PKG_CONFIG --exists --print-errors "qhull_r") 2>&5
   ac_status=$?
   $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
   test $ac_status = 0; }; then
 
-      if test -z "$QHULL_CPPFLAGS"; then
-        QHULL_CPPFLAGS="$($PKG_CONFIG --cflags-only-I qhull | $SED -e 's/^ *$//')"
+      if test -z "$QHULL_R_CPPFLAGS"; then
+        QHULL_R_CPPFLAGS="$($PKG_CONFIG --cflags-only-I qhull_r | $SED -e 's/^ *$//')"
       fi
-      if test -z "$QHULL_LDFLAGS"; then
-        QHULL_LDFLAGS="$($PKG_CONFIG --libs-only-L qhull | $SED -e 's/^ *$//')"
+      if test -z "$QHULL_R_LDFLAGS"; then
+        QHULL_R_LDFLAGS="$($PKG_CONFIG --libs-only-L qhull_r | $SED -e 's/^ *$//')"
       fi
-      QHULL_LIBS="$($PKG_CONFIG --libs-only-l qhull | $SED -e 's/^ *$//')"
+      QHULL_R_LIBS="$($PKG_CONFIG --libs-only-l qhull_r | $SED -e 's/^ *$//')"
 
 fi
   fi
 
-  if test -n "$QHULL_LIBS"; then
+  if test -n "$QHULL_R_LIBS"; then
     ac_octave_save_CPPFLAGS="$CPPFLAGS"
     ac_octave_save_LDFLAGS="$LDFLAGS"
     ac_octave_save_LIBS="$LIBS"
-    CPPFLAGS="$QHULL_CPPFLAGS $CPPFLAGS"
-    LDFLAGS="$QHULL_LDFLAGS $LDFLAGS"
-    LIBS="$QHULL_LIBS $LIBS"
+    CPPFLAGS="$QHULL_R_CPPFLAGS $CPPFLAGS"
+    LDFLAGS="$QHULL_R_LDFLAGS $LDFLAGS"
+    LIBS="$QHULL_R_LIBS $LIBS"
 
-    ac_octave_qhull_check_for_lib=no
-    for ac_header in libqhull/libqhull.h qhull/libqhull.h libqhull.h qhull/qhull.h qhull.h
+    ac_octave_qhull_r_check_for_lib=no
+    for ac_header in libqhull_r/libqhull_r.h libqhull_r.h
 do :
   as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh`
 ac_fn_c_check_header_mongrel "$LINENO" "$ac_header" "$as_ac_Header" "$ac_includes_default"
@@ -70906,15 +70906,15 @@ if eval test \"x\$"$as_ac_Header"\" = x"yes"; then :
   cat >>confdefs.h <<_ACEOF
 #define `$as_echo "HAVE_$ac_header" | $as_tr_cpp` 1
 _ACEOF
- ac_octave_qhull_check_for_lib=yes; break
+ ac_octave_qhull_r_check_for_lib=yes; break
 fi
 
 done
 
-    if test $ac_octave_qhull_check_for_lib = yes; then
-      { $as_echo "$as_me:${as_lineno-$LINENO}: checking for qh_qhull in $QHULL_LIBS" >&5
-$as_echo_n "checking for qh_qhull in $QHULL_LIBS... " >&6; }
-if ${octave_cv_lib_qhull+:} false; then :
+    if test $ac_octave_qhull_r_check_for_lib = yes; then
+      { $as_echo "$as_me:${as_lineno-$LINENO}: checking for qh_qhull in $QHULL_R_LIBS" >&5
+$as_echo_n "checking for qh_qhull in $QHULL_R_LIBS... " >&6; }
+if ${octave_cv_lib_qhull_r+:} false; then :
   $as_echo_n "(cached) " >&6
 else
   cat confdefs.h - <<_ACEOF >conftest.$ac_ext
@@ -70944,54 +70944,40 @@ return qh_qhull ();
 }
 _ACEOF
 if ac_fn_c_try_link "$LINENO"; then :
-  octave_cv_lib_qhull=yes
+  octave_cv_lib_qhull_r=yes
 else
-  octave_cv_lib_qhull=no
+  octave_cv_lib_qhull_r=no
 fi
 rm -f core conftest.err conftest.$ac_objext \
     conftest$ac_exeext conftest.$ac_ext
 
 fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $octave_cv_lib_qhull" >&5
-$as_echo "$octave_cv_lib_qhull" >&6; }
-      if test "$octave_cv_lib_qhull" = yes; then
-        warn_qhull=
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $octave_cv_lib_qhull_r" >&5
+$as_echo "$octave_cv_lib_qhull_r" >&6; }
+      if test "$octave_cv_lib_qhull_r" = yes; then
+        warn_qhull_r=
 
-  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for qh_version in $QHULL_LIBS" >&5
-$as_echo_n "checking for qh_version in $QHULL_LIBS... " >&6; }
-if ${octave_cv_lib_qhull_version+:} false; then :
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for qh_version in $QHULL_R_LIBS" >&5
+$as_echo_n "checking for qh_version in $QHULL_R_LIBS... " >&6; }
+if ${octave_cv_lib_qhull_r_version+:} false; then :
   $as_echo_n "(cached) " >&6
 else
   cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 /* end confdefs.h.  */
 
         #include <stdio.h>
-        #if defined (HAVE_LIBQHULL_LIBQHULL_H)
-        # include <libqhull/libqhull.h>
-        # include <libqhull/qset.h>
-        # include <libqhull/geom.h>
-        # include <libqhull/poly.h>
-        # include <libqhull/io.h>
-        #elif defined (HAVE_QHULL_LIBQHULL_H) || defined (HAVE_QHULL_QHULL_H)
-        # if defined (HAVE_QHULL_LIBQHULL_H)
-        #  include <qhull/libqhull.h>
-        # else
-        #  include <qhull/qhull.h>
-        # endif
-        # include <qhull/qset.h>
-        # include <qhull/geom.h>
-        # include <qhull/poly.h>
-        # include <qhull/io.h>
-        #elif defined (HAVE_LIBQHULL_H) || defined (HAVE_QHULL_H)
-        # if defined (HAVE_LIBQHULL_H)
-        #  include <libqhull.h>
-        # else
-        #  include <qhull.h>
-        # endif
-        # include <qset.h>
-        # include <geom.h>
-        # include <poly.h>
-        # include <io.h>
+        #if defined (HAVE_LIBQHULL_R_LIBQHULL_R_H)
+        # include <libqhull_r/libqhull_r.h>
+        # include <libqhull_r/qset_r.h>
+        # include <libqhull_r/geom_r.h>
+        # include <libqhull_r/poly_r.h>
+        # include <libqhull_r/io_r.h>
+        #elif defined (HAVE_LIBQHULL_R_H)
+        # include <libqhull_r.h>
+        # include <qset_r.h>
+        # include <geom_r.h>
+        # include <poly_r.h>
+        # include <io_r.h>
         #endif
 
 #ifdef F77_DUMMY_MAIN
@@ -71013,63 +70999,49 @@ main ()
 }
 _ACEOF
 if ac_fn_c_try_link "$LINENO"; then :
-  octave_cv_lib_qhull_version=yes
+  octave_cv_lib_qhull_r_version=yes
 else
-  octave_cv_lib_qhull_version=no
+  octave_cv_lib_qhull_r_version=no
 fi
 rm -f core conftest.err conftest.$ac_objext \
     conftest$ac_exeext conftest.$ac_ext
 
 fi
 { $as_echo "$as_me:${as_lineno-$LINENO}: result: $octave_cv_lib_qhull_version" >&5
-$as_echo "$octave_cv_lib_qhull_version" >&6; }
-  if test $octave_cv_lib_qhull_version = no; then
+$as_echo "$octave_cv_lib_qhull_r_version" >&6; }
+  if test $octave_cv_lib_qhull_r_version = no; then
 
-$as_echo "#define NEED_QHULL_VERSION 1" >>confdefs.h
+$as_echo "#define NEED_QHULL_R_VERSION 1" >>confdefs.h
 
   fi
 
 
-  { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the qhull library works" >&5
-$as_echo_n "checking whether the qhull library works... " >&6; }
-if ${octave_cv_lib_qhull_ok+:} false; then :
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the qhull_r library works" >&5
+$as_echo_n "checking whether the qhull_r library works... " >&6; }
+if ${octave_cv_lib_qhull_r_ok+:} false; then :
   $as_echo_n "(cached) " >&6
 else
   if test "$cross_compiling" = yes; then :
-  octave_cv_lib_qhull_ok=yes
+  octave_cv_lib_qhull_r_ok=yes
 else
   cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 /* end confdefs.h.  */
 
         #include <stdio.h>
-        #if defined (HAVE_LIBQHULL_LIBQHULL_H)
-        # include <libqhull/libqhull.h>
-        # include <libqhull/qset.h>
-        # include <libqhull/geom.h>
-        # include <libqhull/poly.h>
-        # include <libqhull/io.h>
-        #elif defined (HAVE_QHULL_LIBQHULL_H) || defined (HAVE_QHULL_QHULL_H)
-        # if defined (HAVE_QHULL_LIBQHULL_H)
-        #  include <qhull/libqhull.h>
-        # else
-        #  include <qhull/qhull.h>
-        # endif
-        # include <qhull/qset.h>
-        # include <qhull/geom.h>
-        # include <qhull/poly.h>
-        # include <qhull/io.h>
-        #elif defined (HAVE_LIBQHULL_H) || defined (HAVE_QHULL_H)
-        # if defined (HAVE_LIBQHULL_H)
-        #  include <libqhull.h>
-        # else
-        #  include <qhull.h>
-        # endif
-        # include <qset.h>
-        # include <geom.h>
-        # include <poly.h>
-        # include <io.h>
+        #if defined (HAVE_LIBQHULL_R_LIBQHULL_R_H)
+        # include <libqhull_r/libqhull_r.h>
+        # include <libqhull_r/qset_r.h>
+        # include <libqhull_r/geom_r.h>
+        # include <libqhull_r/poly_r.h>
+        # include <libqhull_r/io_r.h>
+        #elif defined (HAVE_LIBQHULL_R_H)
+        # include <libqhull_r.h>
+        # include <qset_r.h>
+        # include <geom_r.h>
+        # include <poly_r.h>
+        # include <io_r.h>
         #endif
-        #if defined (NEED_QHULL_VERSION)
+        #if defined (NEED_QHULL_R_VERSION)
           char *qh_version = "version";
         #endif
 
@@ -71089,16 +71061,18 @@ main ()
         int n = 4;
         coordT points[8] = { -0.5, -0.5, -0.5, 0.5, 0.5, -0.5, 0.5, 0.5 };
         boolT ismalloc = 0;
-        return qh_new_qhull (dim, n, points, ismalloc, "qhull ", 0, stderr);
+        qhT context = { };
+        qhT* qh = &context;
+        return qh_new_qhull (qh, dim, n, points, ismalloc, "qhull ", 0, stderr);
 
   ;
   return 0;
 }
 _ACEOF
 if ac_fn_c_try_run "$LINENO"; then :
-  octave_cv_lib_qhull_ok=yes
+  octave_cv_lib_qhull_r_ok=yes
 else
-  octave_cv_lib_qhull_ok=no
+  octave_cv_lib_qhull_r_ok=no
 fi
 rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \
   conftest.$ac_objext conftest.beam conftest.$ac_ext
@@ -71106,39 +71080,39 @@ fi
 
 
 fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $octave_cv_lib_qhull_ok" >&5
-$as_echo "$octave_cv_lib_qhull_ok" >&6; }
-  if test $octave_cv_lib_qhull_ok = yes; then
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $octave_cv_lib_qhull_r_ok" >&5
+$as_echo "$octave_cv_lib_qhull_r_ok" >&6; }
+  if test $octave_cv_lib_qhull_r_ok = yes; then
 
 $as_echo "#define HAVE_QHULL 1" >>confdefs.h
 
     :
   else
-    warn_qhull="Qhull library found, but does not seem to work properly.  This will result in loss of functionality for some geometry functions.  Please try recompiling the library with -fno-strict-aliasing."
+    warn_qhull_r="Qhull library found, but does not seem to work properly.  This will result in loss of functionality for some geometry functions.  Please try recompiling the library with -fno-strict-aliasing."
     :
   fi
 
       else
-        QHULL_LIBS=
+        QHULL_R_LIBS=
       fi
     else
-      octave_cv_lib_qhull=no
-      QHULL_LIBS=
+      octave_cv_lib_qhull_r=no
+      QHULL_R_LIBS=
     fi
 
     CPPFLAGS="$ac_octave_save_CPPFLAGS"
     LDFLAGS="$ac_octave_save_LDFLAGS"
     LIBS="$ac_octave_save_LIBS"
   else
-    octave_cv_lib_qhull=no
+    octave_cv_lib_qhull_r=no
   fi
 
 
 
-  if test -n "$warn_qhull"; then
+  if test -n "$warn_qhull_r"; then
 
-  { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $warn_qhull" >&5
-$as_echo "$as_me: WARNING: $warn_qhull" >&2;}
+  { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $warn_qhull_r" >&5
+$as_echo "$as_me: WARNING: $warn_qhull_r" >&2;}
 
 
   fi
@@ -88392,9 +88366,9 @@ Octave is now configured for $canonical_host_type
   PortAudio libraries:           $PORTAUDIO_LIBS
   PTHREAD flags:                 $PTHREAD_CFLAGS
   PTHREAD libraries:             $PTHREAD_LIBS
-  QHULL CPPFLAGS:                $QHULL_CPPFLAGS
-  QHULL LDFLAGS:                 $QHULL_LDFLAGS
-  QHULL libraries:               $QHULL_LIBS
+  QHULL CPPFLAGS:                $QHULL_R_CPPFLAGS
+  QHULL LDFLAGS:                 $QHULL_R_LDFLAGS
+  QHULL libraries:               $QHULL_R_LIBS
   QRUPDATE CPPFLAGS:             $QRUPDATE_CPPFLAGS
   QRUPDATE LDFLAGS:              $QRUPDATE_LDFLAGS
   QRUPDATE libraries:            $QRUPDATE_LIBS
@@ -88685,9 +88659,9 @@ $as_echo "$as_me: WARNING: $warn_64_bit" >&2;}
 $as_echo "$as_me: WARNING: $warn_bounds_check" >&2;}
       warn_msg_printed=true
     fi
-    if test -n "$warn_qhull"; then
-      { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $warn_qhull" >&5
-$as_echo "$as_me: WARNING: $warn_qhull" >&2;}
+    if test -n "$warn_qhull_r"; then
+      { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $warn_qhull_r" >&5
+$as_echo "$as_me: WARNING: $warn_qhull_r" >&2;}
       warn_msg_printed=true
     fi
     if test -n "$warn_pcre"; then
-- 
2.30.2

