--- motion-3.2.12/configure.in	2013-01-13 17:09:49.000000000 +0100
+++ motion-new/configure.in	2013-01-13 17:11:12.000000000 +0100
@@ -505,25 +505,8 @@
 	# ******* Search mysql headers *******
 
 	if test "${MYSQL_HEADERS}" = "yes"; then
-		AC_MSG_CHECKING(autodect mysql headers)
-		# Autodetect
-		for w in /usr/include /usr/local/include /usr/mysql /usr/local/mysql /usr/local/mysql/include /opt /opt/mysql; do
-			# check for plain setups
-			if test -f $w/mysql.h; then
-				MYSQL_INCDIR=$w
-				break
-			fi
-			# check for "/usr/include/<packagename>" type setups
-			if test -f $w/mysql/mysql.h; then
-				MYSQL_INCDIR=$w/mysql
-				break
-			fi
-			# check for "/usr/<packagename>/include" type setups
-			if test -f $w/mysql/include/mysql.h; then
-				MYSQL_INCDIR=$w/mysql/include
-				break
-			fi
-		done
+		AC_CHECK_HEADER([mysql.h], , [MYSQL_HEADERS=no])
+		AC_MSG_CHECKING(for mysql headers)
 	elif test "${MYSQL_HEADERS}" = "no"; then
 		AC_MSG_CHECKING(for mysql headers)	
 		AC_MSG_RESULT(skipped)
@@ -532,26 +515,29 @@
 		# Manual detection for <withval>
         	if test -f $MYSQL_HEADERS/mysql.h; then
                 	MYSQL_INCDIR=$MYSQL_HEADERS
+		else
+			MYSQL_HEADERS="no"
 	        fi
 	fi
 
-	if test -z "$MYSQL_INCDIR" ; then
-		MYSQL_HEADERS="no"
+	if test "$MYSQL_HEADERS" = "no" ; then
 		AC_MSG_RESULT(not found)
 		echo "Invalid MySQL directory - unable to find mysql.h."
 	else
 		AC_MSG_RESULT(yes)
-		MYSQL_HEADERS="yes"
 	fi
 
 
 	if test "${MYSQL_HEADERS}" = "yes"; then
 
 	# ******* Search mysql libs *********
-	if test "${MYSQL_LIBS}" = "yes"; then
+	if test "${MYSQL_LIBS}" = "no"; then
+        	AC_MSG_CHECKING(for mysql libs)
+	        AC_MSG_RESULT(skipped)
+	elif test "${MYSQL_LIBS}" = "yes"; then
 		AC_MSG_CHECKING(autodect mysql libs)
         	# Autodetect
-		for w in /usr/lib64 /usr/lib /usr/local/lib /usr/mysql /usr/local/mysql /usr/local/mysql/lib /opt /opt/mysql; do
+		for w in /usr/mysql /usr/local/mysql /usr/local/mysql/lib /opt /opt/mysql; do
 			# check for plain setups
 			if test -f $w/libmysqlclient.a -o -f $w/libmysqlclient.so; then
 				MYSQL_LIBDIR=$w
@@ -568,9 +554,6 @@
 				break
 			fi
 		done
-	elif test "${MYSQL_LIBS}" = "no"; then
-        	AC_MSG_CHECKING(for mysql libs)
-	        AC_MSG_RESULT(skipped)
 	else
 		AC_MSG_CHECKING(for mysql libs in $MYSQL_LIBS)
 		# Manual detection for <withval>
@@ -580,7 +563,7 @@
 	fi
 
 
-	if test -z "$MYSQL_LIBDIR" ; then
+	if test "$MYSQL_LIBS" = "no" ; then
 		AC_MSG_RESULT(not found)
 		echo "Invalid MySQL directory - unable to find libmysqlclient.a or libmysqlclient.so."
 	else
@@ -588,11 +571,17 @@
 		#LDFLAGS="-L$MYSQL_LIBDIR"
 		saved_CFLAGS=$CFLAGS
 		saved_LIBS=$LIBS
-		CFLAGS="-I$MYSQL_INCDIR"
-		LIBS="-L$MYSQL_LIBDIR"
+		if test -z "$MYSQL_INCDIR"; then
+			CFLAGS=""
+		else
+			CFLAGS="-I$MYSQL_INCDIR"
+		fi
+		if test -z "$MYSQL_LIBDIR"; then
+			LIBS=""
+		else
+			LIBS="-L$MYSQL_LIBDIR"
+		fi
 		AC_CHECK_LIB(mysqlclient,mysql_init,[	
-					TEMP_LIBS="$TEMP_LIBS -L$MYSQL_LIBDIR -lmysqlclient -lz"
-					TEMP_CFLAGS="$TEMP_CFLAGS -I$MYSQL_INCDIR"
 					MYSQL_SUPPORT="yes"
 					AC_DEFINE([HAVE_MYSQL],1,[Define to 1 if you have MySQL support])
 					],
