Port of gwyddion-2.62-automagic.patch (from ::gentoo) to 2.70/2.71.
Same content changes, refreshed line numbers so `patch` applies cleanly.

Upstream's configure.ac unconditionally probes OpenEXR/CFITSIO via
pkg-config; wrap both in GWY_WITH toggles so USE=-openexr / USE=-fits
actually disable them instead of just hoping pkg-config won't find them.

--- a/configure.ac
+++ b/configure.ac
@@ -735,11 +735,13 @@
 #############################################################################
 # OpenEXR 2.x+
 # Optional.  Used for HDR greyscale OpenEXR pixmap import/export.
-enable_exr=$have_cxx
-PKG_CHECK_MODULES(EXR, [OpenEXR >= 2.0],
-                  [AC_DEFINE(HAVE_EXR,1,
-                            [Define if we have the OpenEXR 2.x+ package.])],
-                  [enable_exr=no])
+GWY_WITH([exr],,[build with OpenEXR support])
+if test "x$enable_exr" != "xno"; then
+  PKG_CHECK_MODULES(EXR, [OpenEXR],
+                    [AC_DEFINE(HAVE_EXR,1,
+                              [Define if we have the OpenEXR 2.x+ package.])],
+                    [enable_exr=no])
+fi
 AM_CONDITIONAL([HAVE_EXR],[test "x$enable_exr" != xno])

 #############################################################################
@@ -754,10 +756,13 @@
 #############################################################################
 # CFITSIO
 # Optional.  Used for FITS image import.
-PKG_CHECK_MODULES(CFITSIO, [cfitsio],
-                  [AC_DEFINE(HAVE_CFITSIO,1,
-                            [Define if we have the cfitsio package.])],
-                  [enable_cfitsio=no])
+GWY_WITH([cfitsio],,[build with cfitsio support])
+if test "x$enable_cfitsio" != "xno"; then
+  PKG_CHECK_MODULES(CFITSIO, [cfitsio],
+                    [AC_DEFINE(HAVE_CFITSIO,1,
+                              [Define if we have the cfitsio package.])],
+                    [enable_cfitsio=no])
+fi
 AM_CONDITIONAL([HAVE_CFITSIO],[test "x$enable_cfitsio" != xno])

 #############################################################################
