Index: Makefile.in
===================================================================
--- Makefile.in	(revision 516)
+++ Makefile.in	(working copy)
@@ -30,7 +30,8 @@
 # These variables contain compiler flags, object files to build and files to   #
 # install.                                                                     #
 ################################################################################
-CFLAGS       = @CFLAGS@ -Wall -DVERSION=\"@PACKAGE_VERSION@\" -Dsysconfdir=\"$(sysconfdir)\" 
+CPPFLAGS     = @CPPFLAGS@ @DEFS@ -DVERSION=\"@PACKAGE_VERSION@\" -Dsysconfdir=\"$(sysconfdir)\" 
+CFLAGS       = @CFLAGS@ -Wall
 LDFLAGS      = @LDFLAGS@
 LIBS         = @LIBS@ 
 VIDEO_OBJ    = @VIDEO@
@@ -48,11 +49,7 @@
 # ALL and PROGS build Motion and, possibly, Motion-control.                    #
 ################################################################################
 all: progs
-ifneq (,$(findstring freebsd,$(VIDEO_OBJ)))
-	@echo "Build complete, run \"gmake install\" to install Motion!"
-else
-	@echo "Build complete, run \"make install\" to install Motion!"
-endif
+	@echo "Build complete, run \"$(MAKE) install\" to install Motion!"
 	@echo
 
 progs: pre-build-info $(PROGS)
@@ -64,7 +61,7 @@
 	@echo "Welcome to the setup procedure for Motion, the motion detection daemon! If you get"
 	@echo "error messages during this procedure, please report them to the mailing list. The"
 	@echo "Motion Guide contains all information you should need to get Motion up and running."
-	@echo "Run \"make updateguide\" to download the latest version of the Motion Guide."
+	@echo "Run \"$(MAKE) updateguide\" to download the latest version of the Motion Guide."
 	@echo
 	@echo "Version: @PACKAGE_VERSION@"
 ifneq (,$(findstring freebsd,$(VIDEO_OBJ)))
@@ -118,7 +115,7 @@
 ################################################################################
 $(DEPEND_FILE): *.h $(SRC)
 	@echo "Generating dependencies, please wait..."
-	@$(CC) $(CFLAGS) -M $(SRC) > .tmp
+	@$(CC) $(CPPFLAGS) $(CFLAGS) -M $(SRC) > .tmp
 	@mv -f .tmp $(DEPEND_FILE)
 	@echo
 
Index: rotate.c
===================================================================
--- rotate.c	(revision 516)
+++ rotate.c	(working copy)
@@ -36,8 +36,8 @@
  * We don't have a 32-bit unsigned integer type, so define it, given
  * a 32-bit type was found by configure.
  */
-#    ifdef TYPE_32BIT
-typedef unsigned TYPE_32BIT __uint32;
+#    ifdef TYPE_U32BIT
+typedef TYPE_U32BIT __uint32;
 #    else
 #        error "Failed to find a 32-bit integer type."
 #    endif
Index: motion.c
===================================================================
--- motion.c	(revision 516)
+++ motion.c	(working copy)
@@ -2291,11 +2291,11 @@
         MOTION_LOG(ERR, TYPE_ALL, SHOW_ERRNO, "%s: Could not change directory");
     
 
-#if (defined(BSD))
+#ifdef SETPGRP_TAKES_ARGS
     setpgrp(0, getpid());
 #else
     setpgrp();
-#endif /* BSD */
+#endif /* SETPGRP_TAKES_ARGS, for BSD */
 
     
     if ((i = open("/dev/tty", O_RDWR)) >= 0) {
Index: configure.in
===================================================================
--- configure.in	(revision 516)
+++ configure.in	(working copy)
@@ -26,7 +26,20 @@
 PWCBSD="$withval"
 )
 
+#
+# Check to Exclude V4L
+#
+AC_ARG_WITH(v4l,
+[  --without-v4l           Exclude using v4l (video4linux) subsystem.
+                          Makes Motion so it only supports network cameras.
+                          ],
+V4L="$withval"
+)
+dnl $V4L may be 'yes', 'no', or unset at this point.
 
+# Checks for programs.
+AC_PROG_CC
+
 AC_MSG_CHECKING(for Darwin)
 Darwin=`uname -a | grep "Darwin"`
 
@@ -50,7 +63,8 @@
 
 		if test "${PWCBSD}" != "no"; then
 			VIDEO="video.o video2.o video_common.o"
-			TEMP_CFLAGS="${CFLAGS} -I/usr/local/include -DPWCBSD"
+			TEMP_CFLAGS="${CFLAGS} -I/usr/local/include"
+			AC_DEFINE(PWCBSD, 1, [Philips webcam for BSD support])
 		else 
 			VIDEO="video_freebsd.o"
 			TEMP_CFLAGS="${CFLAGS} -I/usr/local/include"	
@@ -62,23 +76,33 @@
 
 	fi
 else
-	TEMP_CFLAGS="${CFLAGS} -I/sw/include"
-	TEMP_LDFLAGS="${LDFLAGS} -L/sw/lib"
-	TEMP_LIBS="-L/sw/lib"
 	VIDEO="video_freebsd.o"
-	FINK_LIB="-L/sw/lib"
 	Darwin="yes"
 	V4L="no"
 	AC_MSG_RESULT($Darwin)
+
+	AC_MSG_CHECKING(for Fink)
+	if test -d /sw/include -a -d /sw/lib ; then
+	    AC_MSG_RESULT(yes)
+   	    CPPFLAGS="${CFLAGS} -I/sw/include"
+	    LDFLAGS="${LDFLAGS} -L/sw/lib"
+	else
+	    AC_MSG_RESULT(no)
+	fi
+
+	AC_MSG_CHECKING(for macports)
+	if test -d /opt/local/include -a -d /opt/local/lib ; then
+	    AC_MSG_RESULT(yes)
+   	    CPPFLAGS="${CFLAGS} -I/opt/local/include"
+	    LDFLAGS="${LDFLAGS} -L/opt/local/lib"
+	else
+	    AC_MSG_RESULT(no)
+	fi
 fi
 
-
 AC_SUBST(VIDEO)
 
-# Checks for programs.
-AC_PROG_CC
-
-TEMP_LIBS="-lm ${TEMP_LIBS}"
+TEMP_LIBS="-lm ${TEMP_LIBS} ${LIBS}"
 TEMP_CFLAGS="${TEMP_CFLAGS} ${CFLAGS}"
 TEMP_LDFLAGS="${TEMP_LDFLAGS} ${LDFLAGS}"
 
@@ -106,30 +130,31 @@
 
 
 	if test "${BKTR}" = "no"; then
-        	TEMP_CFLAGS="${TEMP_CFLAGS} -DWITHOUT_V4L"
+		V4L=no
 	fi
+fi
 
+AC_MSG_CHECKING(for video4linux)
+if test "x${V4L}" = "xno"; then
+    AC_MSG_RESULT(disabled)
+elif test "x${V4L}" = "xyes"; then
+    AC_MSG_RESULT(explicitly enabled)
 else
-
-#
-# Check to Exclude V4L
-#
-V4L="yes"
-AC_ARG_WITH(v4l,
-[  --without-v4l           Exclude using v4l (video4linux) subsystem.
-                          Makes Motion so it only supports network cameras.
-                          ],
-V4L="$withval"
-)
-
+    # If Video4Linux hasn't been explicitly enabled or disabled,
+    # then test for its existence.
+    AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <linux/videodev.h>]],
+                                       [[
+struct video_capability cap;
+ioctl(dev, VIDIOCGCAP, &cap);
+printf("%d", cap.channels);]])],
+                      [V4L=yes], [V4L=no])
+    AC_MSG_RESULT($V4L)
 fi
 
-
 if test "${V4L}" = "no"; then
-	TEMP_CFLAGS="${TEMP_CFLAGS} -DWITHOUT_V4L"
+    AC_DEFINE(WITHOUT_V4L, 1, [Define to disable video4linux support])
 fi
 
-
 if test "${FreeBSD}" != "" && test "${LINUXTHREADS}" != "no" ; then
 
 AC_MSG_CHECKING(for linuxthreads)
@@ -175,19 +200,10 @@
                 echo "You do not have linuxthread installed"
                 echo
         fi
+fi
 
-elif test -f "${THREAD_CHECK}"; then
+if test -f "${THREAD_CHECK}" -a  "x$PTHREAD_LIB" != "xyes"; then
 
-
-AC_MSG_CHECKING(threads)
-AC_TRY_LINK([#include <pthread.h>],
-[pthread_t th; pthread_join(th, 0);
- pthread_attr_init(0); pthread_cleanup_push(0, 0);
- pthread_create(0,0,0,0); pthread_cleanup_pop(0); ],
- [PTHREAD_LIB=yes])
-
-if test x$PTHREAD_LIB != xyes; then
-
 	if test "${FreeBSD}" != ""; then
 		TEMP_LIBS="$TEMP_LIBS -pthread"
 		TEMP_CFLAGS="${TEMP_CFLAGS} -D_REENTRANT -D_THREAD_SAFE"
@@ -196,17 +212,25 @@
 		TEMP_CFLAGS="${TEMP_CFLAGS} -D_REENTRANT"
 	fi
 	PTHREAD_SUPPORT="yes"
+
 fi
-	AC_MSG_RESULT($PTHREAD_SUPPORT)                        
 
-else
+
+AC_MSG_CHECKING(for pthreads)
+AC_TRY_LINK([#include <pthread.h>],
+[pthread_t th; pthread_join(th, 0);
+ pthread_attr_init(0); pthread_cleanup_push(0, 0);
+ pthread_create(0,0,0,0); pthread_cleanup_pop(0); ],
+ [PTHREAD_LIB=yes
+PTHREAD_SUPPORT=yes
+AC_MSG_RESULT(yes)], [AC_MSG_RESULT(no)])
+
+if test "x$PTHREAD_SUPPORT" != "xyes"; then
 	echo 
 	echo "You do not have threads support"
 	echo	
 fi
 
-
-
 #
 # Check for the special mmx accelerated jpeg library
 #
@@ -411,7 +435,8 @@
 	if  test "${FFMPEG_OK}" = "found"; then	
 		TEMP_LIBS="$TEMP_LIBS -L${FFMPEG_LIB} -lavformat -lavcodec -lavutil -lm -lz"
 		TEMP_LDFLAGS="${TEMP_LDFLAGS} -L${FFMPEG_LIB}"
-		TEMP_CFLAGS="${TEMP_CFLAGS} -DHAVE_FFMPEG ${FFMPEG_CFLAGS}"
+		TEMP_CFLAGS="${TEMP_CFLAGS} ${FFMPEG_CFLAGS}"
+		AC_DEFINE(HAVE_FFMPEG, 1, [Define if ffmpeg is available])
 
 		FFMPEG_OBJ="ffmpeg.o"
 		AC_SUBST(FFMPEG_OBJ)
@@ -434,7 +459,7 @@
 			[AC_MSG_RESULT(yes)],
 			[
 				AC_MSG_RESULT(no)
-				TEMP_CFLAGS="${TEMP_CFLAGS} -DHAVE_FFMPEG_NEW"
+				AC_DEFINE(HAVE_FFMPEG_NEW, 1, [ffmpeg headers in new location])
 			]
 		)
 		CFLAGS=$saved_CFLAGS
@@ -771,6 +796,18 @@
 
 AC_CHECK_FUNCS(get_current_dir_name)
 
+AC_CACHE_CHECK([whether setpgrp() accepts arguments],
+ ac_cv_func_setpgrp_args,
+[AC_COMPILE_IFELSE([AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT
+#include <unistd.h>], [setpgrp (0, 1);])],
+                  [ac_cv_func_setpgrp_args=yes],
+                  [ac_cv_func_setpgrp_args=no])
+])
+if test $ac_cv_func_setpgrp_args = yes; then
+  AC_DEFINE(SETPGRP_TAKES_ARGS, 1,
+            [Define to 1 if the `setpgrp' function accepts arguments.])
+fi
+
 # Check if v4l2 is available
 SUPPORTED_V4L2=false
 SUPPORTED_V4L2_old=false
@@ -817,19 +854,24 @@
 AC_CHECK_SIZEOF(int *)
 AC_CHECK_SIZEOF(void *)
 
-if test "$ac_cv_sizeof_short" = "4"; then
-	TEMP_CFLAGS="${TEMP_CFLAGS} -DTYPE_32BIT=\"short\""
+AC_MSG_CHECKING(for a 32-bit integer type)
+
+if test "x$ac_cv_header_stdint_h" = "xyes"; then
+        type_32bit=uint32_t
+elif test "$ac_cv_sizeof_short" = "4"; then
+        type_32bit='unsigned short'
+elif test "$ac_cv_sizeof_int" = "4"; then
+        type_32bit='unsigned int'
+elif test "$ac_cv_sizeof_long_int" = "4"; then
+        type_32bit='unsigned long int'
 else
-	if test "$ac_cv_sizeof_int" = "4"; then
-		TEMP_CFLAGS="${TEMP_CFLAGS} -DTYPE_32BIT=\"int\""
-	else
-		if test "$ac_cv_sizeof_long_int" = "4"; then
-			TEMP_CFLAGS="${TEMP_CFLAGS} -DTYPE_32BIT=\"long int\""
-		fi
-	fi
+	AC_MSG_ERROR(Unable to find a 32-bit integer type)
 fi
+AC_MSG_RESULT($type_32bit)
+AC_DEFINE_UNQUOTED(TYPE_U32BIT,
+          $type_32bit,
+          [Define to a 32-bit unsigned integer type.])
 
-
 OPTIMIZECPU="yes"
 
 AC_ARG_WITH(optimizecpu,
@@ -1081,7 +1123,7 @@
 		__asm("bswap %0" : "=r" (__v) : "0" (__x));])
 	],
 	[
-		TEMP_CFLAGS="${TEMP_CFLAGS} -DHAVE_BSWAP"
+		AC_DEFINE(HAVE_BSWAP, 1, [i386 bswap instruction])
 		AC_MSG_RESULT(yes)
 	],
 	[ 
@@ -1093,7 +1135,7 @@
 	TEMP_CFLAGS="${TEMP_CFLAGS} -W -Wshadow -Wpointer-arith -Wcast-align -Wwrite-strings -Waggregate-return -Wstrict-prototypes -Wmissing-prototypes -Wnested-externs -Winline -Wredundant-decls -Wno-long-long -ggdb -g3"
 fi
 
-CFLAGS="${TEMP_CFLAGS} $UNAME_DEFS  $CPU_OPTIONS"
+CFLAGS="${TEMP_CFLAGS} $CPU_OPTIONS"
 
 LIBS="${TEMP_LIBS}"
 LDFLAGS="${TEMP_LDFLAGS}"
@@ -1220,7 +1262,7 @@
     echo "PostgreSQL support:  No"
 fi
 echo 
-echo "CFLAGS: $CFLAGS"
+echo "CFLAGS: $CFLAGS $DEFS"
 echo "LIBS: $LIBS"
 echo "LDFLAGS: $LDFLAGS"
 echo
Index: ffmpeg.h
===================================================================
--- ffmpeg.h	(revision 516)
+++ ffmpeg.h	(working copy)
@@ -1,6 +1,10 @@
 #ifndef _INCLUDE_FFMPEG_H_
 #define _INCLUDE_FFMPEG_H_
 
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
 #ifdef HAVE_FFMPEG
 #include <errno.h>
 
