diff --git a/configure b/configure
index 75c79c05f54a4111124bed90268c8be2f97fbc64..1aa49cd43ead7de2a6f515dd06b5c29f90c50bcf 100755
--- a/configure
+++ b/configure
@@ -839,6 +839,7 @@ Optional Packages:
   --without-PACKAGE       do not use PACKAGE (same as --with-PACKAGE=no)
   --with-gsl-prefix=PFX   prefix where GSL is installed
   --with-fltk-prefix=PFX  prefix where FLTK is installed
+  --with-jpeg-prefix=PFX  prefix where the JPEG code is installed
 
 Some influential environment variables:
   CC          C compiler command
@@ -1217,6 +1218,14 @@ else
   FLTK_PREFIX="$FLTK_DIR"
 fi;
 
+# Check whether --with-jpeg-prefix or --without-jpeg-prefix was given.
+if test "${with_jpeg_prefix+set}" = set; then
+  withval="$with_jpeg_prefix"
+  JPEG_PREFIX=$withval
+else
+  JPEG_PREFIX="$JPEG_DIR"
+fi;
+
 # Check whether --enable-gui or --disable-gui was given.
 if test "${enable_gui+set}" = set; then
   enableval="$enable_gui"
@@ -2752,6 +2761,7 @@ echo "$as_me: error: Could not find fltk-config. Try --with-fltk-prefix?" >&2;}
   GUI_LIBS="${GUI_LIBS} `$FLTKCONFIG --use-gl --use-images --ldflags`"
   GUI_INCLUDE="${GUI_INCLUDE} `$FLTKCONFIG --use-gl --use-images --cxxflags`"
 
+    if test "x${JPEG_PREFIX}" = "x"; then
 
 echo "$as_me:$LINENO: checking for ANSI C header files" >&5
 echo $ECHO_N "checking for ANSI C header files... $ECHO_C" >&6
@@ -3109,12 +3119,76 @@ fi
 echo "$as_me:$LINENO: result: $ac_cv_lib_jpeg_jpeg_destroy_decompress" >&5
 echo "${ECHO_T}$ac_cv_lib_jpeg_jpeg_destroy_decompress" >&6
 if test $ac_cv_lib_jpeg_jpeg_destroy_decompress = yes; then
-  VERSION_FLAGS="${VERSION_FLAGS} -DHAVE_LIBJPEG" GUI_LIBS="${GUI_LIBS} -ljpeg"
+  VERSION_FLAGS="${VERSION_FLAGS} -DHAVE_LIBJPEG"
+                   GUI_LIBS="${GUI_LIBS} -ljpeg"
 fi
 
 fi
 
 
+  else
+        echo "$as_me:$LINENO: checking for jpeg_destroy_decompress in -ljpeg" >&5
+echo $ECHO_N "checking for jpeg_destroy_decompress in -ljpeg... $ECHO_C" >&6
+if test "${ac_cv_lib_jpeg_jpeg_destroy_decompress+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  ac_check_lib_save_LIBS=$LIBS
+LIBS="-ljpeg  $LIBS"
+cat >conftest.$ac_ext <<_ACEOF
+#line $LINENO "configure"
+#include "confdefs.h"
+
+/* Override any gcc2 internal prototype to avoid an error.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+/* We use char because int might match the return type of a gcc2
+   builtin and then its argument prototype would still apply.  */
+char jpeg_destroy_decompress ();
+#ifdef F77_DUMMY_MAIN
+#  ifdef __cplusplus
+     extern "C"
+#  endif
+   int F77_DUMMY_MAIN() { return 1; }
+#endif
+int
+main ()
+{
+jpeg_destroy_decompress ();
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext conftest$ac_exeext
+if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
+  (eval $ac_link) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+         { ac_try='test -s conftest$ac_exeext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  ac_cv_lib_jpeg_jpeg_destroy_decompress=yes
+else
+  echo "$as_me: failed program was:" >&5
+cat conftest.$ac_ext >&5
+ac_cv_lib_jpeg_jpeg_destroy_decompress=no
+fi
+rm -f conftest.$ac_objext conftest$ac_exeext conftest.$ac_ext
+LIBS=$ac_check_lib_save_LIBS
+fi
+echo "$as_me:$LINENO: result: $ac_cv_lib_jpeg_jpeg_destroy_decompress" >&5
+echo "${ECHO_T}$ac_cv_lib_jpeg_jpeg_destroy_decompress" >&6
+if test $ac_cv_lib_jpeg_jpeg_destroy_decompress = yes; then
+  VERSION_FLAGS="${VERSION_FLAGS} -DHAVE_LIBJPEG"
+                 GUI_INCLUDE="${GUI_INCLUDE} -I${JPEG_PREFIX} -I${JPEG_PREFIX}/include"
+                 GUI_LIBS="${GUI_LIBS} -L${JPEG_PREFIX} -L${JPEG_PREFIX}/lib -ljpeg"
+fi
+
+  fi
 
 else
 
diff --git a/configure.in b/configure.in
index 2de5387434f4eebeeff2c681de8ace9784e9f71c..536cf94aba3da031e5fa1af91a75ff662048eda4 100644
--- a/configure.in
+++ b/configure.in
@@ -1,4 +1,4 @@
-dnl "$Id: configure.in,v 1.17 2003-02-15 23:22:17 geuzaine Exp $"
+dnl "$Id: configure.in,v 1.18 2003-02-17 01:43:21 geuzaine Exp $"
 dnl
 dnl Copyright (C) 1997 - 2003 C. Geuzaine, J.-F. Remacle
 dnl
@@ -33,6 +33,10 @@ AC_ARG_WITH(fltk-prefix,
             AC_HELP_STRING([--with-fltk-prefix=PFX],
                            [prefix where FLTK is installed]),
             [FLTK_PREFIX=$withval],[FLTK_PREFIX="$FLTK_DIR"])
+AC_ARG_WITH(jpeg-prefix,
+            AC_HELP_STRING([--with-jpeg-prefix=PFX],
+                           [prefix where the JPEG code is installed]),
+            [JPEG_PREFIX=$withval],[JPEG_PREFIX="$JPEG_DIR"])
 
 dnl Parse '--enable' command line options
 AC_ARG_ENABLE(gui,
@@ -96,9 +100,18 @@ if test "x$enable_gui" != "xno"; then
   GUI_INCLUDE="${GUI_INCLUDE} `$FLTKCONFIG --use-gl --use-images --cxxflags`"
 
   dnl Check if libjpeg is available (in case fltk didn't find it) to enable/disable gl2jpg
-  AC_CHECK_HEADER(jpeglib.h,
+  if test "x${JPEG_PREFIX}" = "x"; then
+    AC_CHECK_HEADER(jpeglib.h,
+      AC_CHECK_LIB(jpeg, jpeg_destroy_decompress,
+                   VERSION_FLAGS="${VERSION_FLAGS} -DHAVE_LIBJPEG"
+                   GUI_LIBS="${GUI_LIBS} -ljpeg"))
+  else
+    dnl Find the libs/includes even if jpeg is _not_ properly installed (ugly hack!)
     AC_CHECK_LIB(jpeg, jpeg_destroy_decompress,
-      VERSION_FLAGS="${VERSION_FLAGS} -DHAVE_LIBJPEG" GUI_LIBS="${GUI_LIBS} -ljpeg"))
+                 VERSION_FLAGS="${VERSION_FLAGS} -DHAVE_LIBJPEG"
+                 GUI_INCLUDE="${GUI_INCLUDE} -I${JPEG_PREFIX} -I${JPEG_PREFIX}/include"
+                 GUI_LIBS="${GUI_LIBS} -L${JPEG_PREFIX} -L${JPEG_PREFIX}/lib -ljpeg")
+  fi 
 
 else