Index: /trunk/psphot/configure.ac
===================================================================
--- /trunk/psphot/configure.ac	(revision 7425)
+++ /trunk/psphot/configure.ac	(revision 7426)
@@ -31,20 +31,35 @@
 )
 
-dnl ------------------------------------------------------------
-dnl Find libjpeg. The library may not be in a well-known place,
-dnl and AC_CHECK_LIB has no way of adding a library to the
-dnl search path for the duration of the test
-dnl
+dnl ------------------ libjpeg options ---------------------
 
-AC_ARG_WITH(libjpeg,
-	    [AS_HELP_STRING(--with-libjpeg=DIR, Specify location of libjpg library)],
-	    [JPEG_LIB="-L$withval"])
-SAVE_LIBS="${LIBS}"
-LIBS="${LIBS=} $JPEG_LIB"
+AC_ARG_WITH(jpeg,
+[AS_HELP_STRING(--with-jpeg=DIR,Specify location of libjpeg.)],
+[JPEG_CFLAGS="-I$withval/include"
+ JPEG_LDFLAGS="-L$withval/lib"])
+AC_ARG_WITH(jpeg-include,
+[AS_HELP_STRING(--with-jpeg-include=DIR,Specify libjpeg include directory.)],
+[JPEG_CFLAGS="-I$withval"])
+AC_ARG_WITH(fftw3-lib,
+[AS_HELP_STRING(--with-jpeg-lib=DIR,Specify libjpeg library directory.)],
+[JPEG_LDFLAGS="-L$withval"])
 
-AC_CHECK_LIB(jpeg,jpeg_CreateCompress,
-	[LIBS="${SAVE_LIBS} $JPEG_LIB -ljpeg"],
-	[LIBS="${SAVE_LIBS}"
-	 AC_MSG_ERROR([jpeg library not found.])])
+dnl Store off CFLAGS/LDFLAGS so that they can be restored after tests
+TMP_CFLAGS=${CFLAGS}
+TMP_LDFLAGS=${LDFLAGS}
+
+CFLAGS="${TMP_CFLAGS} ${JPEG_CFLAGS}"
+LDFLAGS="${TMP_LDFLAGS} ${JPEG_LDFLAGS}"
+
+AC_CHECK_HEADERS([jpeglib.h],[TMP_CFLAGS="$CFLAGS" # keep the change],
+  [AC_MSG_ERROR([libjpeg headers not found.  Obtain libjpeg from http://www.ijg.org/ or use --with-jpeg to specify location.])]
+)
+
+AC_CHECK_LIB(jpeg,jpeg_CreateCompress,[TMP_LDFLAGS="$LDFLAGS" # keep the change],
+  [AC_MSG_ERROR([libjpeg library not found.  Obtain libjpeg from http://www.ijg.org/ or use --with-jpeg to specify location.])]
+)
+
+dnl restore the CFLAGS/LDFLAGS in case we decide to make missing libjpeg only a warning
+CFLAGS=${TMP_CFLAGS}
+LDFLAGS=${TMP_LDFLAGS}
 
 dnl ------------------------------------------------------------
