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: track.c
===================================================================
--- track.c	(revision 516)
+++ track.c	(working copy)
@@ -13,6 +13,11 @@
 #include "pwc-ioctl.h"
 #endif
 
+#if defined(HAVE_SYS_VIDEOIO_H) && defined(MOTION_V4L2)
+#include <sys/types.h>
+#include <sys/ioctl.h>
+#include <sys/videoio.h>
+#endif
 
 struct trackoptions track_template = {
     dev:            -1,             /* dev open */
Index: conf.c
===================================================================
--- conf.c	(revision 516)
+++ conf.c	(working copy)
@@ -34,9 +34,13 @@
 #ifndef HAVE_GET_CURRENT_DIR_NAME
 char *get_current_dir_name(void)
 {
+#ifdef HAVE_GETCWD
+    return getcwd(NULL, MAXPATHLEN);
+#else
     char *buf = mymalloc(MAXPATHLEN);
     getwd(buf);
     return buf;
+#endif
 }
 #endif
 
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,36 @@
 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
+
+# Checks for language and library features
+AC_HEADER_STDC
+AC_CHECK_FUNCS(get_current_dir_name getcwd)
+
+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
+
 AC_MSG_CHECKING(for Darwin)
 Darwin=`uname -a | grep "Darwin"`
 
@@ -37,7 +66,6 @@
 	FreeBSD=`uname -a | grep "BSD"`
 	if test "${FreeBSD}" = ""; then
 		AC_MSG_RESULT(no)
-		VIDEO="video.o video2.o video_common.o"
 	else
 		AC_MSG_RESULT(yes)
 		if test "${LINUXTHREADS}" = "no"; then
@@ -50,7 +78,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 +91,31 @@
 
 	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)
-fi
 
+	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_SUBST(VIDEO)
+	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
 
-# 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 +143,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([
+AC_INCLUDES_DEFAULT
+#include <sys/ioctl.h>
+#include <linux/videodev.h>
+],[[
+    extern int fd;
+    struct video_capability cap;
+    ioctl(fd, 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"
-fi
-
-
 if test "${FreeBSD}" != "" && test "${LINUXTHREADS}" != "no" ; then
 
 AC_MSG_CHECKING(for linuxthreads)
@@ -175,19 +213,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 +225,29 @@
 		TEMP_CFLAGS="${TEMP_CFLAGS} -D_REENTRANT"
 	fi
 	PTHREAD_SUPPORT="yes"
+
 fi
-	AC_MSG_RESULT($PTHREAD_SUPPORT)                        
 
-else
+
+AC_MSG_CHECKING(for pthreads)
+AC_LINK_IFELSE([AC_LANG_PROGRAM(
+[[#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 +452,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 +476,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
@@ -766,48 +808,84 @@
 
 
 #Checks for header files.
-AC_HEADER_STDC
-AC_CHECK_HEADERS(stdio.h unistd.h stdint.h fcntl.h time.h signal.h sys/ioctl.h sys/mman.h linux/videodev.h linux/videodev2.h sys/param.h sys/types.h)
+AC_CHECK_HEADERS(stdio.h unistd.h stdint.h fcntl.h time.h signal.h sys/ioctl.h sys/mman.h asm/types.h linux/videodev.h linux/videodev2.h sys/param.h sys/types.h sys/videoio.h)
 
-AC_CHECK_FUNCS(get_current_dir_name)
-
 # Check if v4l2 is available
 SUPPORTED_V4L2=false
 SUPPORTED_V4L2_old=false
 
-if test "${V4L}" = "no"; then
-	AC_MSG_CHECKING(for V42L support)
-	AC_MSG_RESULT(skipping)
-else
-	AC_CHECK_TYPE([struct v4l2_buffer], 
-        	      [SUPPORTED_V4L2=true],
-             	 [SUPPORTED_V4L2=false],
-	       	 [#include <sys/time.h>
-			#include <linux/videodev.h>])
+if test "x$ac_cv_header_linux_videodev_h" = "xyes"; then
+# video4linux2 headers
+        v4l2_headers='#include <sys/time.h>
+                      #include <sys/ioctl.h>
+                      #include <linux/videodev.h>'
+elif test "x$ac_cv_header_sys_videoio_h" = "xyes"; then
+# openbsd supports the v4l2 types and ioctls, with a different set of headers
+        v4l2_headers='#include <sys/ioctl.h>
+                      #include <sys/videoio.h>'
+fi
 
-	AC_MSG_CHECKING(for V42L support)
-	if test x$SUPPORTED_V4L2 = xtrue; then
-		AC_MSG_RESULT(yes)
-		TEMP_CFLAGS="${TEMP_CFLAGS} -DMOTION_V4L2"
-	else	
-		AC_MSG_RESULT(no)
-	fi
 
-	# linux/videodev.h doesn't include videodev2.h
-	if test x$SUPPORTED_V4L2 = xfalse; then
-		AC_MSG_CHECKING(for V42L *old* support)
-		AC_MSG_RESULT(testing)
-		AC_CHECK_HEADERS(linux/videodev2.h,[SUPPORTED_V4L2_old=true],[], [#include <asm/types.h>])
-	fi
+dnl This is the same check that AC_CHECK_TYPE uses. But we want to
+dnl be able to test again with a different set of headers, so we need
+dnl to avoid the caching behavior that AC_CHECK_TYPE gives us.
+AC_MSG_CHECKING(for struct v4l2_buffer)
+AC_COMPILE_IFELSE([AC_LANG_PROGRAM([
+AC_INCLUDES_DEFAULT
+$v4l2_headers
+typedef struct v4l2_buffer ac_type;],
+[if ((ac_type *) 0)
+  return 0;
+if (sizeof (ac_type))
+  return 0;])],
+[V4L2_HEADERS="$v4l2_headers"
+SUPPORTED_V4L2=true
+AC_MSG_RESULT(yes)
+], [
+   if test "x$ac_cv_header_linux_videodev_h" = "xyes"; then
+       # linux/videodev.h doesn't include videodev2.h ?
+       v4l2_headers='#include <sys/time.h>
+                     #include <sys/ioctl.h>
+		     #include <asm/types.h>
+		     #include <linux/videodev2.h>'
+       AC_COMPILE_IFELSE([AC_LANG_PROGRAM([
+       AC_INCLUDES_DEFAULT
+       $v4l2_headers
+       typedef struct v4l2_buffer ac_type;],
+       [if ((ac_type *) 0)
+	 return 0;
+       if (sizeof (ac_type))
+	 return 0;])],
+       [V4L2_HEADERS="$v4l2_headers"
+	SUPPORTED_V4L2=true
+	SUPPORTED_V4L2_old=true
+        AC_MSG_RESULT(yes, old-style)
+       ], [AC_MSG_RESULT(no)])
+   else
+       AC_MSG_RESULT(no)
+   fi
+])
 
+if test x$SUPPORTED_V4L2 = xtrue; then
+   AC_DEFINE(MOTION_V4L2, 1, [Define to use the video4linux2 interface])
+   if test x$SUPPORTED_V4L2_old = xtrue; then
+       AC_DEFINE(MOTION_V4L2_OLD, 1, [Define to use old includes for v4l2])
+   fi
+fi
 
-	if test x$SUPPORTED_V4L2_old = xtrue; then
-		TEMP_CFLAGS="${TEMP_CFLAGS} -DMOTION_V4L2 -DMOTION_V4L2_OLD"
-		SUPPORTED_V4L2=true
-	fi
+if test "x${V4L}${SUPPORTED_V4L2}" = "xnofalse"; then
+    AC_DEFINE(WITHOUT_V4L, 1, [Define to disable video4linux support])
+else
+    if test "x$VIDEO" = "x" ; then
+        VIDEO="video.o video2.o video_common.o"
+    fi
+fi
 
+if test "x${V4L}" = "xyes"; then
+    AC_DEFINE(MOTION_V4L1, 1, [Define to use the video4linux1 interface])
 fi
 
+AC_SUBST(VIDEO)
 
 # Check sizes of integer types
 AC_CHECK_SIZEOF(short)
@@ -817,19 +895,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 +1164,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 +1176,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}"
@@ -1181,21 +1264,16 @@
 	else
         echo "PWCBSD include:      No"
 	fi
+fi
 
-else
-	if test "${V4L}" = "yes"; then
-        echo "V4L support:         Yes"
-	else
-        echo "V4L support:         No"
-	fi
+echo $ECHO_N "Video4Linux:         $ECHO_C"
+case ".${V4L}.${SUPPORTED_V4L2}." in
+        .no.false.)   echo "No"            ;;
+	.yes.false.)  echo "V4L1 only"     ;;
+	.no.true.)    echo "V4L2 only"     ;;
+	.yes.true.)   echo "V4L1 and V4L2" ;;
+esac
 
-	if test x$SUPPORTED_V4L2 = xtrue; then
-        echo "V4L2 support:        Yes"	
-	else
-        echo "V4L2 support:        No"
-	fi
-fi
-
 if test "${FFMPEG_OK}" = "found"; then
     echo "FFmpeg support:      Yes"
 else
@@ -1220,7 +1298,7 @@
     echo "PostgreSQL support:  No"
 fi
 echo 
-echo "CFLAGS: $CFLAGS"
+echo "CFLAGS: $CFLAGS $DEFS"
 echo "LIBS: $LIBS"
 echo "LDFLAGS: $LDFLAGS"
 echo
Index: video.h
===================================================================
--- video.h	(revision 516)
+++ video.h	(working copy)
@@ -10,10 +10,20 @@
 #ifndef _INCLUDE_VIDEO_H
 #define _INCLUDE_VIDEO_H
 
+#ifndef WITHOUT_V4L
+
+#if HAVE_LINUX_VIDEODEV_H
 #define _LINUX_TIME_H 1
-#ifndef WITHOUT_V4L
 #include <linux/videodev.h>
 #include <sys/mman.h>
+#endif
+
+#if defined(HAVE_SYS_VIDEOIO_H) && defined(MOTION_V4L2)
+#include <sys/types.h>
+#include <sys/ioctl.h>
+#include <sys/videoio.h>
+#endif
+
 #include "vloopback_motion.h"
 #include "pwc-ioctl.h"
 #endif
Index: video2.c
===================================================================
--- video2.c	(revision 516)
+++ video2.c	(working copy)
@@ -68,22 +68,38 @@
  let's go :)
 */
 
+#include "motion.h"
+
 #if !defined(WITHOUT_V4L) && defined(MOTION_V4L2)
 
-#include "motion.h"
 #include "video.h"
 
+#include <sys/mman.h>
+
 #ifdef MOTION_V4L2_OLD
 // Seems that is needed for some system
 #include <linux/time.h>
 #include <linux/videodev2.h>
 #endif
 
+#ifdef HAVE_STDINT_H
+
+#include <stdint.h>
+
+#define u8 unt8_t
+#define u16 uint16_t
+#define u32 uint32_t
+#define s32 int32_t
+
+#else /* STDINT_H */
+
 #define u8 unsigned char
 #define u16 unsigned short
 #define u32 unsigned int
 #define s32 signed int
 
+#endif /* STDINT_H */
+
 #define MMAP_BUFFERS 4
 #define MIN_MMAP_BUFFERS 2
 
Index: ffmpeg.c
===================================================================
--- ffmpeg.c	(revision 516)
+++ ffmpeg.c	(working copy)
@@ -10,9 +10,10 @@
  *
  */
 
+#include "ffmpeg.h"
+
 #ifdef HAVE_FFMPEG
 
-#include "ffmpeg.h"
 #include "motion.h"
 
 #if LIBAVCODEC_BUILD > 4680
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>
 
@@ -8,7 +12,7 @@
 #include <libavformat/avformat.h>
 #else
 #include <avformat.h>
-#endif
+#endif /* defined(FFMPEG_NEW_INCLUDES) */
 
 #ifndef AVERROR /* 0.4.8 & 0.4.9-pre1 */
 
Index: video_common.c
===================================================================
--- video_common.c	(revision 516)
+++ video_common.c	(working copy)
@@ -14,10 +14,16 @@
 #include "video.h"
 #include "jpegutils.h"
 
+#ifdef HAVE_STDINT_H
+#include <stdint.h>
+#else
 typedef unsigned char uint8_t;
 typedef unsigned short int uint16_t;
 typedef unsigned int uint32_t;
+#endif
 
+#include <sys/mman.h>
+
 #define CLAMP(x)  ((x) < 0 ? 0 : ((x) > 255) ? 255 : (x))
 
 typedef struct {
@@ -777,6 +783,7 @@
         dev->height = height;
 #endif
 
+#ifdef MOTION_V4L1
         if (!v4l_start(dev, width, height, input, norm, frequency, tuner_number)) {
             close(dev->fd);
             pthread_mutexattr_destroy(&dev->attr);
@@ -786,6 +793,10 @@
             pthread_mutex_unlock(&vid_mutex);
             return -1;
         }
+#else
+	return -1;
+#endif
+
 #ifdef MOTION_V4L2
         dev->v4l2 = 0;
     }
@@ -940,8 +951,12 @@
             ret = v4l2_next(cnt, dev, map, width, height);
         } else {
 #endif
+#ifdef MOTION_V4L1
             v4l_set_input(cnt, dev, map, width, height, conf);
             ret = v4l_next(dev, map, width, height);
+#else
+            ret = -1;
+#endif
 #ifdef MOTION_V4L2
         }
 #endif
