Index: libs/libmythtv/videodev_myth.h
===================================================================
--- libs/libmythtv/videodev_myth.h	(revision 12793)
+++ libs/libmythtv/videodev_myth.h	(working copy)
@@ -5,12 +5,12 @@
 
 #if defined(__FreeBSD__) || defined(CONFIG_DARWIN)
 #include <sys/types.h>
-typedef unsigned long __u32;
-typedef unsigned short __u16;
-typedef int  __s32;
-typedef unsigned char __u8;
-typedef unsigned long long __u64;
-typedef long long __s64;
+typedef uint32_t __u32;
+typedef uint16_t __u16;
+typedef int32_t  __s32;
+typedef uint8_t  __u8;
+typedef uint32_t __u64;
+typedef int32_t __s64;
 #else
 #include <linux/types.h>
 #include <linux/version.h>
Index: libs/libmythtv/mpegrecorder.cpp
===================================================================
--- libs/libmythtv/mpegrecorder.cpp	(revision 12793)
+++ libs/libmythtv/mpegrecorder.cpp	(working copy)
@@ -828,6 +828,7 @@
         FD_ZERO(&rdset);
         FD_SET(readfd, &rdset);
 
+#if !defined(__FreeBSD__) 
         switch (select(readfd + 1, &rdset, NULL, NULL, &tv))
         {
             case -1:
@@ -851,6 +852,7 @@
 
            default: break;
         }
+#endif
 
         ret = read(readfd, buffer, bufferSize);
 
Index: programs/mythbackend/mainserver.cpp
===================================================================
--- programs/mythbackend/mainserver.cpp	(revision 12793)
+++ programs/mythbackend/mainserver.cpp	(working copy)
@@ -240,9 +240,11 @@
         return;
     }
 
+#if !defined(__FreeBSD__)
     readReadyLock.lock();
 
     sock->Lock();
+#endif
 
     //if (socket->IsInProcess())
     //{
@@ -287,9 +289,15 @@
         threadPoolLock.unlock();
     }
 
+#if defined(__FreeBSD__)
+    sock->Lock();
     prt->setup(sock);
+    sock->Unlock();
+#else
+    prt->setup(sock);
 
     readReadyLock.unlock();
+#endif
 }
 
 void MainServer::ProcessRequest(MythSocket *sock)
@@ -303,7 +311,9 @@
         ProcessRequestWork(sock);
     }
 
+#if !defined(__FreeBSD__)
     sock->Unlock();
+#endif
     //sock->SetInProcess(false);
 }
 
Index: libs/libmythtv/videoout_xv.cpp
===================================================================
--- libs/libmythtv/videoout_xv.cpp	(revision 12793)
+++ libs/libmythtv/videoout_xv.cpp	(working copy)
@@ -7,7 +7,9 @@
 #include <ctime>
 #include <cerrno>
 
+#ifdef _linux_
 #include <malloc.h>
+#endif
 #include <fcntl.h>
 #include <unistd.h>
 #include <sys/time.h>
Index: libs/libmythupnp/httprequest.cpp
===================================================================
--- libs/libmythupnp/httprequest.cpp	(revision 12793)
+++ libs/libmythupnp/httprequest.cpp	(working copy)
@@ -18,7 +18,7 @@
 #include <qfileinfo.h>
 
 #include "mythconfig.h"
-#if defined CONFIG_DARWIN || defined CONFIG_CYGWIN
+#if defined CONFIG_DARWIN || defined CONFIG_CYGWIN || defined(__FreeBSD__)
 #include "darwin-sendfile.h"
 #else
 #include <sys/sendfile.h>
@@ -220,7 +220,7 @@
     // Make it so the header is sent with the data
     // ----------------------------------------------------------------------
 
-#if !defined(CONFIG_DARWIN) && !defined(CONFIG_CYGWIN)
+#if !defined(CONFIG_DARWIN) && !defined(CONFIG_CYGWIN) && !defined(__FreeBSD__)
     // Never send out partially complete segments
     setsockopt( getSocketHandle(), SOL_TCP, TCP_CORK, &g_on, sizeof( g_on ));
 #endif
@@ -248,7 +248,7 @@
     // Turn off the option so any small remaining packets will be sent
     // ----------------------------------------------------------------------
 
-#if !defined(CONFIG_DARWIN) && !defined(CONFIG_CYGWIN)
+#if !defined(CONFIG_DARWIN) && !defined(CONFIG_CYGWIN) && !defined(__FreeBSD__)
     setsockopt( getSocketHandle(), SOL_TCP, TCP_CORK, &g_off, sizeof( g_off ));
 #endif
 
@@ -284,7 +284,7 @@
     // Make it so the header is sent with the data
     // ----------------------------------------------------------------------
 
-#if !defined(CONFIG_DARWIN) && !defined(CONFIG_CYGWIN)
+#if !defined(CONFIG_DARWIN) && !defined(CONFIG_CYGWIN) && !defined(__FreeBSD__)
     // Never send out partially complete segments
     setsockopt( getSocketHandle(), SOL_TCP, TCP_CORK, &g_on, sizeof( g_on ));
 #endif
@@ -393,7 +393,7 @@
     // Turn off the option so any small remaining packets will be sent
     // ----------------------------------------------------------------------
     
-#if !defined(CONFIG_DARWIN) && !defined(CONFIG_CYGWIN)
+#if !defined(CONFIG_DARWIN) && !defined(CONFIG_CYGWIN) && !defined(__FreeBSD__)
     setsockopt( getSocketHandle(), SOL_TCP, TCP_CORK, &g_off, sizeof( g_off ));
 #endif
 
Index: programs/mythcommflag/FrameAnalyzer.h
===================================================================
--- programs/mythcommflag/FrameAnalyzer.h	(revision 12793)
+++ programs/mythcommflag/FrameAnalyzer.h	(working copy)
@@ -7,6 +7,14 @@
 #ifndef __FRAMEANALYZER_H__
 #define __FRAMEANALYZER_H__
 
+/* 
+ * At least FreeBSD doesn't define LONG_LONG_MAX, but it does define 
+ * __LONG_LONG_MAX__.  Who knows what other systems do the same? 
+ */ 
+#ifndef LONG_LONG_MAX 
+#define LONG_LONG_MAX  __LONG_LONG_MAX__ 
+#endif 
+
 /* Base class for commercial flagging frame analyzers. */
 
 #include <limits.h>
Index: libs/libmythupnp/upnputil.h
===================================================================
--- libs/libmythupnp/upnputil.h	(revision 12793)
+++ libs/libmythupnp/upnputil.h	(working copy)
@@ -14,6 +14,9 @@
 #include "mythcontext.h"
 
 // __suseconds_t doesn't exist on some older Unixes. e.g. Darwin/Mac OS X
+#if defined(__FreeBSD__)
+#define __suseconds_t_defined
+#endif
 
 #ifndef __suseconds_t_defined
 #define __suseconds_t_defined
Index: programs/mythbackend/backendutil.cpp
===================================================================
--- programs/mythbackend/backendutil.cpp	(revision 12793)
+++ programs/mythbackend/backendutil.cpp	(working copy)
@@ -1,7 +1,7 @@
 #include <cstdlib> // for llabs
 
 #include "mythconfig.h"
-#ifdef CONFIG_DARWIN
+#if defined(CONFIG_DARWIN) || defined(__FreeBSD__)
 #include <sys/param.h>
 #include <sys/mount.h>
 static inline long long int abs(long long int v) { return llabs(v); }
Index: libs/libmythupnp/libmythupnp.pro
===================================================================
--- libs/libmythupnp/libmythupnp.pro	(revision 12793)
+++ libs/libmythupnp/libmythupnp.pro	(working copy)
@@ -78,3 +78,9 @@
     LIBS += -L../libmythui -lmythui-$$LIBVERSION
     #QMAKE_LFLAGS_SHLIB += -flat_namespace -undefined warning
 }
+
+freebsd {
+    HEADERS += darwin-sendfile.h
+    SOURCES += darwin-sendfile.c
+}
+
Index: version.pro
===================================================================
--- version.pro	(revision 12793)
+++ version.pro	(working copy)
@@ -10,11 +10,11 @@
 SOURCES += version.cpp
 
 version.target = version.cpp 
-version.commands = echo 'const char *myth_source_version =' \
-'"'`(svnversion $${SVNTREEDIR} 2>/dev/null) || echo Unknown`'";' > .vers.new ; \
+version.commands = sh -c "echo 'const char *myth_source_version =' \
+'\"'`(svnversion $${SVNTREEDIR} 2>/dev/null) || echo Unknown`'\";' > .vers.new ; \
 diff .vers.new version.cpp > .vers.diff 2>&1 ; \
 if test -s .vers.diff ; then mv -f .vers.new version.cpp ; fi ; \
-rm -f .vers.new .vers.diff
+rm -f .vers.new .vers.diff"
 version.depends = FORCE 
 
 QMAKE_EXTRA_UNIX_TARGETS += version
