aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore3
-rwxr-xr-xMakefile.in10
-rwxr-xr-xconfigure.in52
-rw-r--r--lib/cximage-6.0/raw/dcr.c2
-rw-r--r--lib/timidity/interface/w32g.h6
-rw-r--r--lib/timidity/timidity/gogo_a.c3
-rw-r--r--tools/TexturePacker/XBTFWriter.cpp4
-rw-r--r--xbmc/addons/Addon.cpp3
-rw-r--r--xbmc/cores/DllLoader/exports/emu_msvcrt.cpp32
-rw-r--r--xbmc/cores/DllLoader/exports/emu_msvcrt.h4
-rw-r--r--xbmc/filesystem/SAPDirectory.cpp3
-rw-r--r--xbmc/freebsd/FreeBSDGNUReplacements.c252
-rw-r--r--xbmc/freebsd/FreeBSDGNUReplacements.h25
-rw-r--r--xbmc/freebsd/Makefile.in10
-rw-r--r--xbmc/interfaces/python/XBPython.cpp2
-rw-r--r--xbmc/linux/LinuxTimezone.cpp19
-rw-r--r--xbmc/linux/PlatformDefs.h15
-rw-r--r--xbmc/linux/XFileUtils.cpp2
-rw-r--r--xbmc/network/Network.cpp1
-rw-r--r--xbmc/network/Socket.h3
-rw-r--r--xbmc/network/linux/NetworkLinux.cpp53
-rw-r--r--xbmc/peripherals/bus/PeripheralBusUSB.h3
-rw-r--r--xbmc/peripherals/bus/linux/PeripheralBusUSBLibUSB.cpp5
-rw-r--r--xbmc/storage/IoSupport.cpp9
-rw-r--r--xbmc/system.h2
-rw-r--r--xbmc/system_gl.h3
-rw-r--r--xbmc/threads/platform/pthreads/ThreadImpl.cpp20
-rw-r--r--xbmc/utils/StdString.h4
-rw-r--r--xbmc/visualizations/XBMCProjectM/libprojectM/fftsg.cpp11
-rw-r--r--xbmc/windowing/WinEvents.h4
-rw-r--r--xbmc/windowing/WindowingFactory.h9
-rw-r--r--xbmc/windowing/X11/XRandR.cpp5
32 files changed, 545 insertions, 34 deletions
diff --git a/.gitignore b/.gitignore
index 3748323009..9ba9e2af6d 100644
--- a/.gitignore
+++ b/.gitignore
@@ -507,6 +507,9 @@ lib/cmyth/Makefile
# /xbmc/linux/
/xbmc/linux/Makefile
+# /xbmc/freebsd/
+/xbmc/freebsd/Makefile
+
# /xbmc/cdrip/
/xbmc/cdrip/Makefile
diff --git a/Makefile.in b/Makefile.in
index 2596c67a27..4500b2c7a5 100755
--- a/Makefile.in
+++ b/Makefile.in
@@ -112,6 +112,10 @@ DIRECTORY_ARCHIVES += xbmc/storage/linux/storage_linux.a
DIRECTORY_ARCHIVES += xbmc/windowing/X11/windowing_X11.a
endif
+ifeq ($(findstring freebsd,@ARCH@),freebsd)
+DIRECTORY_ARCHIVES += xbmc/freebsd/freebsd.a
+endif
+
ifeq (@HAVE_XBMC_NONFREE@,1)
DIRECTORY_ARCHIVES += lib/UnrarXLib/UnrarXLib.a
endif
@@ -291,7 +295,7 @@ ifeq (@USE_ASAP_CODEC@,1)
endif
endif
$(MAKE) -C lib/stsound/StSoundLibrary
-ifeq ($(or $(findstring powerpc,@ARCH@),$(findstring x86_64-linux,@ARCH@),$(findstring arm, @ARCH@)),)
+ifeq ($(or $(findstring powerpc,@ARCH@),$(findstring x86_64-linux,@ARCH@),$(findstring arm, @ARCH@),$(findstring freebsd,@ARCH@)),)
$(MAKE) -C lib/snesapu/SNES/SNESAPU
endif
imagelib: dllloader
@@ -323,6 +327,10 @@ DYNOBJSXBMC= \
xbmc/video/video.a \
xbmc/guilib/guilib.a # must be dynamic to avoid linker errors
+ifeq ($(findstring freebsd,@ARCH@),freebsd)
+DYNOBJSXBMC+= xbmc/freebsd/freebsd.a
+endif
+
OBJSXBMC:=$(filter-out $(DYNOBJSXBMC), $(OBJSXBMC))
LIBS += @PYTHON_LDFLAGS@
diff --git a/configure.in b/configure.in
index 85e5d1016b..a92119d680 100755
--- a/configure.in
+++ b/configure.in
@@ -18,7 +18,13 @@ tolower(){
# check for library basenames
AC_DEFUN([XB_FIND_SONAME],
[
- if [[ "$host_vendor" != "apple" ]]; then
+ if echo "$host" | grep -q freebsd ; then
+ AC_MSG_CHECKING([for lib$2 soname])
+ $1_SONAME=[`ldconfig -r | sed -n "s;.* \(/.*lib$2\.so.*\)$;\1;p" | head -n 1`]
+ if test x$$1_SONAME != x ; then
+ $1_SONAME=[`basename $$1_SONAME`]
+ fi
+ elif [[ "$host_vendor" != "apple" ]]; then
AC_MSG_CHECKING([for lib$2 soname])
$1_FILENAME=$($CC -nostdlib -o /dev/null $LDFLAGS -l$2 -Wl,-M 2>/dev/null | grep "^LOAD.*$2" | awk '{V=2; print $V}')
if [[ ! -z $$1_FILENAME ]]; then
@@ -472,6 +478,18 @@ case $host in
ARCH="x86_64-linux"
AC_SUBST(ARCH_DEFINES, "-DTARGET_POSIX -DTARGET_LINUX -D_LINUX")
;;
+ i386-*-freebsd*)
+ ARCH="x86-freebsd"
+ MAKE="gmake"
+ use_external_ffmpeg="yes"
+ AC_SUBST(ARCH_DEFINES, "-DTARGET_POSIX -DTARGET_FREEBSD -D_LINUX")
+ ;;
+ amd64-*-freebsd*)
+ ARCH="x86_64-freebsd"
+ MAKE="gmake"
+ use_external_ffmpeg="yes"
+ AC_SUBST(ARCH_DEFINES, "-DTARGET_POSIX -DTARGET_FREEBSD -D_LINUX")
+ ;;
arm-apple-darwin*)
use_joystick=no
use_neon=yes
@@ -569,6 +587,13 @@ fi
# platform specific flags
+if echo "$ARCH" | grep -q "freebsd" ; then
+ LOCALBASE="${LOCALBASE:-/usr/local}"
+ CFLAGS="$CFLAGS -I$LOCALBASE/include"
+ CXXFLAGS="$CXXFLAGS -I$LOCALBASE/include"
+ CPPFLAGS="$CPPFLAGS -I$LOCALBASE/include"
+ LDFLAGS="$LDFLAGS -L$LOCALBASE/lib"
+fi
if test "$host_vendor" = "apple" ; then
# standard xbmc paths
INCLUDES="$INCLUDES -I\$(abs_top_srcdir)/xbmc/osx"
@@ -727,7 +752,11 @@ fi
AC_CHECK_LIB([bz2], [main],, AC_MSG_ERROR($missing_library))
AC_CHECK_LIB([jpeg], [main],, AC_MSG_ERROR($missing_library)) # check for cximage
AC_CHECK_LIB([tiff], [main],, AC_MSG_ERROR($missing_library))
+if echo "$ARCH" | grep -q freebsd; then
+AC_CHECK_LIB([pthread], [main],LIBS="-pthread $LIBS", AC_MSG_ERROR($missing_library))
+else
AC_CHECK_LIB([pthread], [main],, AC_MSG_ERROR($missing_library))
+fi
AC_CHECK_LIB([lzo2], [main],, AC_MSG_ERROR($missing_library))
AC_CHECK_LIB([z], [main],, AC_MSG_ERROR($missing_library))
AC_CHECK_LIB([crypto], [main],, AC_MSG_ERROR($missing_library))
@@ -798,8 +827,12 @@ if test "$host_vendor" = "apple" ; then
else
case $host_os in
linux*) AC_CHECK_LIB([dl], [main],, AC_MSG_ERROR($missing_library)) ;;
+ freebsd*) AC_CHECK_LIB([iconv], [main],, AC_MSG_ERROR($missing_library)) ;;
+ esac
+ case $host_os in
+ freebsd*) ;;
+ *) AC_CHECK_LIB([resolv], [main],, AC_MSG_ERROR($missing_library)) ;;
esac
- AC_CHECK_LIB([resolv], [main],, AC_MSG_ERROR($missing_library))
AC_CHECK_LIB([jasper], [main],, AC_MSG_ERROR($missing_library)) # check for cximage
AC_CHECK_LIB([rt], [clock_gettime],, AC_MSG_ERROR($missing_library))
@@ -1172,7 +1205,11 @@ else
use_libusb="no"
AC_MSG_NOTICE($libusb_disabled)
else
- if test "$use_libusb" = "auto"; then
+ if echo "$ARCH" | grep -q freebsd ; then
+ AC_CHECK_LIB([usb],[main],
+ [use_libusb="yes";USB_LIBS="-lusb"],
+ [use_libusb="no";AC_MSG_RESULT($libusb_not_found)])
+ elif test "$use_libusb" = "auto"; then
PKG_CHECK_MODULES([USB],[libusb],,[use_libusb="no";AC_MSG_RESULT($libusb_not_found)])
elif test "$use_libusb" = "yes"; then
PKG_CHECK_MODULES([USB],[libusb],,[use_libusb="no";AC_MSG_ERROR($libusb_not_found)])
@@ -1938,6 +1975,7 @@ OUTPUT_FILES="Makefile \
xbmc/interfaces/python/xbmcmodule/Makefile \
lib/libUPnP/Makefile \
xbmc/DllPaths_generated.h \
+ xbmc/freebsd/Makefile \
xbmc/linux/Makefile \
xbmc/filesystem/Makefile \
xbmc/screensavers/rsxs-0.9/xbmc/Makefile \
@@ -2212,7 +2250,8 @@ XB_CONFIG_MODULE([lib/libid3tag/libid3tag],[
XB_CONFIG_MODULE([xbmc/visualizations/XBMCProjectM/libprojectM],[
set -x
- rm -f CMakeCache.txt && CC="$ORIGCC" CXX="$ORIGCXX" cmake \
+ rm -f CMakeCache.txt && \
+ CC="$ORIGCC" CXX="$ORIGCXX" LDFLAGS="$LDFLAGS" cmake \
-DCMAKE_BUILD_TYPE=None -DUSE_FTGL:BOOL=OFF \
-DCMAKE_C_FLAGS:STRING="${CPPFLAGS} ${CFLAGS}" \
-DCMAKE_CXX_FLAGS:STRING="${CPPFLAGS} ${CXXFLAGS}" \
@@ -2265,6 +2304,9 @@ XB_CONFIG_MODULE([xbmc/screensavers/rsxs-0.9/], [
--disable-hyperspace \
--disable-lattice \
--disable-skyrocket
+ if echo "$ARCH" | grep -q freebsd ; then
+ sed -i.back "s;\(STDBOOL_H = \)stdbool.h;\1;" lib/Makefile
+ fi
], [$DISABLE_RSXS])
XB_CONFIG_MODULE([lib/libapetag], [
@@ -2281,7 +2323,7 @@ XB_CONFIG_MODULE([lib/cpluff], [
--prefix="${prefix}" --includedir="${includedir}" --libdir="${libdir}" --datadir="${datadir}" \
--host=$host_alias \
--build=$build_alias \
- --target=$target_alias CFLAGS="$CFLAGS" CC="$CC" CXX="$CXX"
+ --target=$target_alias CFLAGS="$CFLAGS" CC="$CC" CXX="$CXX" LDFLAGS="$LDFLAGS"
#LDFLAGS="$LDFLAGS -Wl,-read_only_relocs,suppress"
], [0])
diff --git a/lib/cximage-6.0/raw/dcr.c b/lib/cximage-6.0/raw/dcr.c
index 9a85dc783d..1668dd0122 100644
--- a/lib/cximage-6.0/raw/dcr.c
+++ b/lib/cximage-6.0/raw/dcr.c
@@ -144,7 +144,9 @@ int DCR_CLASS main (int argc, char **argv)
//!!! set return point for error handling
if (setjmp (dcr.failure)) {
+#if !defined(__FreeBSD__)
if (fileno(dcr.obj_) > 2) (*dcr.ops_->close_)(dcr.obj_);
+#endif
if (fileno(ofp) > 2) fclose(ofp);
status = 1;
goto cleanup;
diff --git a/lib/timidity/interface/w32g.h b/lib/timidity/interface/w32g.h
index c68592cae1..e0960afa8c 100644
--- a/lib/timidity/interface/w32g.h
+++ b/lib/timidity/interface/w32g.h
@@ -64,6 +64,9 @@ typedef LPTHREAD_START_ROUTINE BCC_BEGINTHREAD_START_ADDRESS;
#elif defined(_BORLANDC_)
#define crt_beginthread(start_address,stack_size,arglist) \
(HANDLE)_beginthread((BCC_BEGINTHREAD_START_ADDRESS)start_address,(unsigned)stack_size,(void *)arglist)
+#elif defined(__FreeBSD__)
+#define crt_beginthread(start_address,stack_size,arglist) \
+(HANDLE)CreateThread(NULL,(DWORD)stack_size,(LPTHREAD_START_ROUTINE)start_address,(LPVOID)arglist,0,NULL)
#else
#define crt_beginthread(start_address,stack_size,arglist) \
(HANDLE)CreateThread(NULL,(DWORD)stack_size,(LPTHREAD_START_ROUTINE)start_address,(LPVOID)arglist,0,&dwTmp)
@@ -76,6 +79,9 @@ typedef LPTHREAD_START_ROUTINE BCC_BEGINTHREAD_START_ADDRESS;
#elif defined(_BORLANDC_)
#define crt_beginthreadex(security,stack_size,start_address,arglist,initflag,thrdaddr ) \
(HANDLE)_beginthreadNT((BCC_BEGINTHREAD_START_ADDRESS)start_address,(unsigned)stack_size,(void *)arglist,(void *)security_attrib,(unsigned long)create_flags,(unsigned long *)thread_id)
+#elif defined(__FreeBSD__)
+#define crt_beginthreadex(security,stack_size,start_address,arglist,initflag,thrdaddr ) \
+(HANDLE)CreateThread((LPSECURITY_ATTRIBUTES)security,(DWORD)stack_size,(LPTHREAD_START_ROUTINE)start_address,(LPVOID)arglist,(DWORD)initflag,(LPLONG)thrdaddr)
#else
#define crt_beginthreadex(security,stack_size,start_address,arglist,initflag,thrdaddr ) \
(HANDLE)CreateThread((LPSECURITY_ATTRIBUTES)security,(DWORD)stack_size,(LPTHREAD_START_ROUTINE)start_address,(LPVOID)arglist,(DWORD)initflag,(LPDWORD)thrdaddr)
diff --git a/lib/timidity/timidity/gogo_a.c b/lib/timidity/timidity/gogo_a.c
index 68eff48585..71ae65c71f 100644
--- a/lib/timidity/timidity/gogo_a.c
+++ b/lib/timidity/timidity/gogo_a.c
@@ -108,6 +108,9 @@ typedef LPTHREAD_START_ROUTINE BCC_BEGINTHREAD_START_ADDRESS;
#elif defined(_BORLANDC_)
#define crt_beginthreadex(security,stack_size,start_address,arglist,initflag,thrdaddr ) \
(HANDLE)_beginthreadNT((BCC_BEGINTHREAD_START_ADDRESS)start_address,(unsigned)stack_size,(void *)arglist,(void *)security_attrib,(unsigned long)create_flags,(unsigned long *)thread_id)
+#elif defined(__FreeBSD__)
+#define crt_beginthreadex(security,stack_size,start_address,arglist,initflag,thrdaddr ) \
+(HANDLE)CreateThread((LPSECURITY_ATTRIBUTES)security,(DWORD)stack_size,(LPTHREAD_START_ROUTINE)start_address,(LPVOID)arglist,(DWORD)initflag,(LPLONG)thrdaddr)
#else
#define crt_beginthreadex(security,stack_size,start_address,arglist,initflag,thrdaddr ) \
(HANDLE)CreateThread((LPSECURITY_ATTRIBUTES)security,(DWORD)stack_size,(LPTHREAD_START_ROUTINE)start_address,(LPVOID)arglist,(DWORD)initflag,(LPDWORD)thrdaddr)
diff --git a/tools/TexturePacker/XBTFWriter.cpp b/tools/TexturePacker/XBTFWriter.cpp
index 78b47fe810..7999a7e83f 100644
--- a/tools/TexturePacker/XBTFWriter.cpp
+++ b/tools/TexturePacker/XBTFWriter.cpp
@@ -24,7 +24,9 @@
#include <inttypes.h>
#include "guilib/XBTF.h"
#include "utils/EndianSwap.h"
-#if !defined(__APPLE__) && !defined(__FreeBSD__)
+#if defined(__FreeBSD__)
+#include <stdlib.h>
+#elif !defined(__APPLE__)
#include <malloc.h>
#endif
#include <memory.h>
diff --git a/xbmc/addons/Addon.cpp b/xbmc/addons/Addon.cpp
index 5c77aba0e4..30c035469b 100644
--- a/xbmc/addons/Addon.cpp
+++ b/xbmc/addons/Addon.cpp
@@ -29,6 +29,9 @@
#ifdef __APPLE__
#include "../osx/OSXGNUReplacements.h"
#endif
+#ifdef __FreeBSD__
+#include "freebsd/FreeBSDGNUReplacements.h"
+#endif
#include "utils/log.h"
#include "utils/URIUtils.h"
#include <vector>
diff --git a/xbmc/cores/DllLoader/exports/emu_msvcrt.cpp b/xbmc/cores/DllLoader/exports/emu_msvcrt.cpp
index 076862d5b5..ded46e71e9 100644
--- a/xbmc/cores/DllLoader/exports/emu_msvcrt.cpp
+++ b/xbmc/cores/DllLoader/exports/emu_msvcrt.cpp
@@ -27,21 +27,23 @@
#include <direct.h>
#include <process.h>
#else
-#ifndef __APPLE__
+#if !defined(__APPLE__) && !defined(__FreeBSD__)
#include <mntent.h>
#endif
#endif
#include <sys/stat.h>
#include <sys/types.h>
+#if !defined(__FreeBSD__)
#include <sys/timeb.h>
+#endif
#include "system.h" // for HAS_DVD_DRIVE
#ifdef HAS_DVD_DRIVE
#ifdef _LINUX
#include <sys/ioctl.h>
- #ifndef __APPLE__
- #include <linux/cdrom.h>
- #else
+ #ifdef __APPLE__
#include <IOKit/storage/IODVDMediaBSDClient.h>
+ #elif !defined(__FreeBSD__)
+ #include <linux/cdrom.h>
#endif
#endif
#endif
@@ -1167,7 +1169,7 @@ extern "C"
FILE* dll_fopen(const char* filename, const char* mode)
{
FILE* file = NULL;
-#if defined(_LINUX) && !defined(__APPLE__)
+#if defined(_LINUX) && !defined(__APPLE__) && !defined(__FreeBSD__)
if (strcmp(filename, MOUNTED) == 0
|| strcmp(filename, MNTTAB) == 0)
{
@@ -1275,7 +1277,7 @@ extern "C"
{
// it might be something else than a file, or the file is not emulated
// let the operating system handle it
-#if defined(__APPLE__)
+#if defined(__APPLE__) || defined(__FreeBSD__)
return fseek(stream, offset, origin);
#else
return fseeko64(stream, offset, origin);
@@ -1340,7 +1342,7 @@ extern "C"
{
// it might be something else than a file, or the file is not emulated
// let the operating system handle it
-#if defined(__APPLE__)
+#if defined(__APPLE__) || defined(__FreeBSD__)
return ftello(stream);
#else
return ftello64(stream);
@@ -1386,7 +1388,7 @@ extern "C"
CLog::Log(LOGWARNING, "msvcrt.dll: dll_telli64 called, TODO: add 'int64 -> long' type checking"); //warning
#ifndef _LINUX
return (__int64)tell(fd);
-#elif defined(__APPLE__)
+#elif defined(__APPLE__) || defined(__FreeBSD__)
return lseek(fd, 0, SEEK_CUR);
#else
return lseek64(fd, 0, SEEK_CUR);
@@ -1563,7 +1565,7 @@ extern "C"
int ret;
ret = dll_fgetpos64(stream, &tmpPos);
-#if !defined(_LINUX) || defined(__APPLE__)
+#if !defined(_LINUX) || defined(__APPLE__) || defined(__FreeBSD__)
*pos = (fpos_t)tmpPos;
#else
pos->__pos = (off_t)tmpPos.__pos;
@@ -1576,7 +1578,7 @@ extern "C"
CFile* pFile = g_emuFileWrapper.GetFileXbmcByStream(stream);
if (pFile != NULL)
{
-#if !defined(_LINUX) || defined(__APPLE__)
+#if !defined(_LINUX) || defined(__APPLE__) || defined(__FreeBSD__)
*pos = pFile->GetPosition();
#else
pos->__pos = pFile->GetPosition();
@@ -1598,7 +1600,7 @@ extern "C"
int fd = g_emuFileWrapper.GetDescriptorByStream(stream);
if (fd >= 0)
{
-#if !defined(_LINUX) || defined(__APPLE__)
+#if !defined(_LINUX) || defined(__APPLE__) || defined(__FreeBSD__)
if (dll_lseeki64(fd, *pos, SEEK_SET) >= 0)
#else
if (dll_lseeki64(fd, (__off64_t)pos->__pos, SEEK_SET) >= 0)
@@ -1615,7 +1617,7 @@ extern "C"
{
// it might be something else than a file, or the file is not emulated
// let the operating system handle it
-#if !defined(_LINUX) || defined(__APPLE__)
+#if !defined(_LINUX) || defined(__APPLE__) || defined(__FreeBSD__)
return fsetpos(stream, pos);
#else
return fsetpos64(stream, pos);
@@ -1631,7 +1633,7 @@ extern "C"
if (fd >= 0)
{
fpos64_t tmpPos;
-#if !defined(_LINUX) || defined(__APPLE__)
+#if !defined(_LINUX) || defined(__APPLE__) || defined(__FreeBSD__)
tmpPos= *pos;
#else
tmpPos.__pos = (off64_t)(pos->__pos);
@@ -2095,7 +2097,7 @@ extern "C"
if (!pFile)
return -1;
-#ifdef HAS_DVD_DRIVE
+#if defined(HAS_DVD_DRIVE) && !defined(__FreeBSD__)
#ifndef __APPLE__
if(request == DVD_READ_STRUCT || request == DVD_AUTH)
#else
@@ -2138,7 +2140,7 @@ extern "C"
CLog::Log(LOGERROR, "%s - getmntent is not implemented for our virtual filesystem", __FUNCTION__);
return NULL;
}
-#if defined(_LINUX) && !defined(__APPLE__)
+#if defined(_LINUX) && !defined(__APPLE__) && !defined(__FreeBSD__)
return getmntent(fp);
#else
CLog::Log(LOGWARNING, "%s - unimplemented function called", __FUNCTION__);
diff --git a/xbmc/cores/DllLoader/exports/emu_msvcrt.h b/xbmc/cores/DllLoader/exports/emu_msvcrt.h
index 601a9eea39..2ff7e30d5e 100644
--- a/xbmc/cores/DllLoader/exports/emu_msvcrt.h
+++ b/xbmc/cores/DllLoader/exports/emu_msvcrt.h
@@ -132,7 +132,11 @@ extern "C"
uintptr_t dll_beginthread(void( *start_address )( void * ),unsigned stack_size,void *arglist);
HANDLE dll_beginthreadex(LPSECURITY_ATTRIBUTES lpThreadAttributes, DWORD dwStackSize,
LPTHREAD_START_ROUTINE lpStartAddress, LPVOID lpParameter, DWORD dwCreationFlags,
+#ifdef __FreeBSD__
+ LPLONG lpThreadId);
+#else
LPDWORD lpThreadId);
+#endif
int dll_stati64(const char *path, struct _stati64 *buffer);
int dll_stat64(const char *path, struct __stat64 *buffer);
#ifdef _WIN32
diff --git a/xbmc/filesystem/SAPDirectory.cpp b/xbmc/filesystem/SAPDirectory.cpp
index b997c12270..7129abe678 100644
--- a/xbmc/filesystem/SAPDirectory.cpp
+++ b/xbmc/filesystem/SAPDirectory.cpp
@@ -31,6 +31,9 @@
#ifdef __APPLE__
#include "OSXGNUReplacements.h" // strnlen
#endif
+#ifdef __FreeBSD__
+#include "freebsd/FreeBSDGNUReplacements.h"
+#endif
#include <sys/socket.h>
#include <netinet/in.h>
diff --git a/xbmc/freebsd/FreeBSDGNUReplacements.c b/xbmc/freebsd/FreeBSDGNUReplacements.c
new file mode 100644
index 0000000000..5d9ab356c8
--- /dev/null
+++ b/xbmc/freebsd/FreeBSDGNUReplacements.c
@@ -0,0 +1,252 @@
+
+#include "FreeBSDGNUReplacements.h"
+
+#if __FreeBSD_version < 800067
+
+/*-
+ * Copyright (c) 2009 David Schultz <das@FreeBSD.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+size_t
+strnlen(const char *s, size_t maxlen)
+{
+ size_t len;
+
+ for (len = 0; len < maxlen; len++, s++) {
+ if (!*s)
+ break;
+ }
+ return (len);
+}
+
+/* Copyright (C) 1991, 1992, 1995, 1996, 1997 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <limits.h>
+#include <errno.h>
+
+/* Read up to (and including) a TERMINATOR from STREAM into *LINEPTR
+ (and null-terminate it). *LINEPTR is a pointer returned from malloc (or
+ NULL), pointing to *N characters of space. It is realloc'd as
+ necessary. Returns the number of characters read (not including the
+ null terminator), or -1 on error or EOF. */
+
+ssize_t
+getdelim(char **lineptr, size_t *n, int terminator, FILE *stream)
+{
+ char *line, *p;
+ size_t size, copy;
+
+ if (stream == NULL || lineptr == NULL || n == NULL)
+ {
+ errno = EINVAL;
+ return -1;
+ }
+
+ if (ferror (stream))
+ return -1;
+
+ /* Make sure we have a line buffer to start with. */
+ if (*lineptr == NULL || *n < 2) /* !seen and no buf yet need 2 chars. */
+ {
+#ifndef MAX_CANON
+#define MAX_CANON 256
+#endif
+ line = (char *)realloc (*lineptr, MAX_CANON);
+ if (line == NULL)
+ return -1;
+ *lineptr = line;
+ *n = MAX_CANON;
+ }
+
+ line = *lineptr;
+ size = *n;
+
+ copy = size;
+ p = line;
+
+ while (1)
+ {
+ size_t len;
+
+ while (--copy > 0)
+ {
+ register int c = getc (stream);
+ if (c == EOF)
+ goto lose;
+ else if ((*p++ = c) == terminator)
+ goto win;
+ }
+
+ /* Need to enlarge the line buffer. */
+ len = p - line;
+ size *= 2;
+ line = (char *)realloc (line, size);
+ if (line == NULL)
+ goto lose;
+ *lineptr = line;
+ *n = size;
+ p = line + len;
+ copy = size - len;
+ }
+
+ lose:
+ if (p == *lineptr)
+ return -1;
+ /* Return a partial line since we got an error in the middle. */
+ win:
+ *p = '\0';
+ return p - *lineptr;
+}
+
+#endif
+
+/* Compare strings while treating digits characters numerically.
+ Copyright (C) 1997, 2002, 2005 Free Software Foundation, Inc.
+ This file is part of the libiberty library.
+ Contributed by Jean-François Bignolles <bignolle@ecoledoc.ibp.fr>, 1997.
+
+ Libiberty is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ Libiberty is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ 02110-1301 USA. */
+
+#include <ctype.h>
+
+#define ISASCII(c) isascii(c)
+#define ISDIGIT(c) (ISASCII (c) && isdigit (c))
+/* states: S_N: normal, S_I: comparing integral part, S_F: comparing
+ fractional parts, S_Z: idem but with leading Zeroes only */
+#define S_N 0x0
+#define S_I 0x4
+#define S_F 0x8
+#define S_Z 0xC
+
+/* result_type: CMP: return diff; LEN: compare using len_diff/diff */
+#define CMP 2
+#define LEN 3
+
+
+/* Compare S1 and S2 as strings holding indices/version numbers,
+ returning less than, equal to or greater than zero if S1 is less than,
+ equal to or greater than S2 (for more info, see the Glibc texinfo doc). */
+
+int
+strverscmp (const char *s1, const char *s2)
+{
+ const unsigned char *p1 = (const unsigned char *) s1;
+ const unsigned char *p2 = (const unsigned char *) s2;
+ unsigned char c1, c2;
+ int state;
+ int diff;
+
+ /* Symbol(s) 0 [1-9] others (padding)
+ Transition (10) 0 (01) d (00) x (11) - */
+ static const unsigned int next_state[] =
+ {
+ /* state x d 0 - */
+ /* S_N */ S_N, S_I, S_Z, S_N,
+ /* S_I */ S_N, S_I, S_I, S_I,
+ /* S_F */ S_N, S_F, S_F, S_F,
+ /* S_Z */ S_N, S_F, S_Z, S_Z
+ };
+
+ static const int result_type[] =
+ {
+ /* state x/x x/d x/0 x/- d/x d/d d/0 d/-
+ 0/x 0/d 0/0 0/- -/x -/d -/0 -/- */
+
+ /* S_N */ CMP, CMP, CMP, CMP, CMP, LEN, CMP, CMP,
+ CMP, CMP, CMP, CMP, CMP, CMP, CMP, CMP,
+ /* S_I */ CMP, -1, -1, CMP, +1, LEN, LEN, CMP,
+ +1, LEN, LEN, CMP, CMP, CMP, CMP, CMP,
+ /* S_F */ CMP, CMP, CMP, CMP, CMP, LEN, CMP, CMP,
+ CMP, CMP, CMP, CMP, CMP, CMP, CMP, CMP,
+ /* S_Z */ CMP, +1, +1, CMP, -1, CMP, CMP, CMP,
+ -1, CMP, CMP, CMP
+ };
+
+ if (p1 == p2)
+ return 0;
+
+ c1 = *p1++;
+ c2 = *p2++;
+ /* Hint: '0' is a digit too. */
+ state = S_N | ((c1 == '0') + (ISDIGIT (c1) != 0));
+
+ while ((diff = c1 - c2) == 0 && c1 != '\0')
+ {
+ state = next_state[state];
+ c1 = *p1++;
+ c2 = *p2++;
+ state |= (c1 == '0') + (ISDIGIT (c1) != 0);
+ }
+
+ state = result_type[state << 2 | (((c2 == '0') + (ISDIGIT (c2) != 0)))];
+
+ switch (state)
+ {
+ case CMP:
+ return diff;
+
+ case LEN:
+ while (ISDIGIT (*p1++))
+ if (!ISDIGIT (*p2++))
+ return 1;
+
+ return ISDIGIT (*p2) ? -1 : diff;
+
+ default:
+ return state;
+ }
+}
diff --git a/xbmc/freebsd/FreeBSDGNUReplacements.h b/xbmc/freebsd/FreeBSDGNUReplacements.h
new file mode 100644
index 0000000000..9713b62b7e
--- /dev/null
+++ b/xbmc/freebsd/FreeBSDGNUReplacements.h
@@ -0,0 +1,25 @@
+#ifndef __FREEBSDGNUREPLACEMENTS_H__
+#define __FREEBSDGNUREPLACEMENTS_H__
+
+#include <sys/param.h>
+#include <string.h>
+#include <stdio.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+#if __FreeBSD_version < 800067
+
+size_t strnlen(const char *s, size_t n);
+ssize_t getdelim(char **lineptr, size_t *n, int delimiter, FILE *stream);
+
+#endif
+
+int strverscmp(const char *s1, const char *s2);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif
diff --git a/xbmc/freebsd/Makefile.in b/xbmc/freebsd/Makefile.in
new file mode 100644
index 0000000000..33da958dd9
--- /dev/null
+++ b/xbmc/freebsd/Makefile.in
@@ -0,0 +1,10 @@
+ARCH=@ARCH@
+
+CXXFLAGS+=-fPIC
+
+SRCS=FreeBSDGNUReplacements.c
+
+LIB=freebsd.a
+
+include @abs_top_srcdir@/Makefile.include
+
diff --git a/xbmc/interfaces/python/XBPython.cpp b/xbmc/interfaces/python/XBPython.cpp
index 2a1d9fb172..4ed38128e1 100644
--- a/xbmc/interfaces/python/XBPython.cpp
+++ b/xbmc/interfaces/python/XBPython.cpp
@@ -532,7 +532,7 @@ void XBPython::Finalize()
#if !(defined(__APPLE__) || defined(_WIN32))
DllLoaderContainer::UnloadPythonDlls();
#endif
-#if defined(_LINUX) && !defined(__APPLE__)
+#if defined(_LINUX) && !defined(__APPLE__) && !defined(__FreeBSD__)
// we can't release it on windows, as this is done in UnloadPythonDlls() for win32 (see above).
// The implementation for linux needs looking at - UnloadPythonDlls() currently only searches for "python24.dll"
// The implementation for osx can never unload the python dylib.
diff --git a/xbmc/linux/LinuxTimezone.cpp b/xbmc/linux/LinuxTimezone.cpp
index 8e2bf2b4b4..8ca969c6e7 100644
--- a/xbmc/linux/LinuxTimezone.cpp
+++ b/xbmc/linux/LinuxTimezone.cpp
@@ -27,6 +27,9 @@
#ifdef __APPLE__
#include "OSXGNUReplacements.h"
#endif
+#ifdef __FreeBSD__
+#include "freebsd/FreeBSDGNUReplacements.h"
+#endif
#include "Util.h"
@@ -36,6 +39,7 @@ CLinuxTimezone::CLinuxTimezone() : m_IsDST(0)
{
char* line = NULL;
size_t linelen = 0;
+ int nameonfourthfield = 0;
CStdString s;
vector<CStdString> tokens;
@@ -91,6 +95,11 @@ CLinuxTimezone::CLinuxTimezone() : m_IsDST(0)
// Load countries
fp = fopen("/usr/share/zoneinfo/iso3166.tab", "r");
+ if (!fp)
+ {
+ fp = fopen("/usr/share/misc/iso3166", "r");
+ nameonfourthfield = 1;
+ }
if (fp)
{
CStdString countryCode;
@@ -111,6 +120,16 @@ CLinuxTimezone::CLinuxTimezone() : m_IsDST(0)
int i = 2;
while (s[i] == ' ' || s[i] == '\t') i++;
+ if (nameonfourthfield)
+ {
+ // skip three letter
+ while (s[i] != ' ' && s[i] != '\t') i++;
+ while (s[i] == ' ' || s[i] == '\t') i++;
+ // skip number
+ while (s[i] != ' ' && s[i] != '\t') i++;
+ while (s[i] == ' ' || s[i] == '\t') i++;
+ }
+
countryCode = s.Left(2);
countryName = s.Mid(i);
diff --git a/xbmc/linux/PlatformDefs.h b/xbmc/linux/PlatformDefs.h
index de3a00b96d..fdfac62146 100644
--- a/xbmc/linux/PlatformDefs.h
+++ b/xbmc/linux/PlatformDefs.h
@@ -43,6 +43,10 @@
#include <stdio.h>
#include <sys/sysctl.h>
#include <mach/mach.h>
+#elif defined(__FreeBSD__)
+#include <stdio.h>
+#include <sys/sysctl.h>
+#include <sys/types.h>
#else
#include <sys/sysinfo.h>
#endif
@@ -166,7 +170,7 @@
#define CALLBACK __stdcall
#define WINAPI __stdcall
#define WINAPIV __cdecl
-#ifndef __APPLE__
+#if !defined(__APPLE__) && !defined(__FreeBSD__)
#define APIENTRY WINAPI
#else
#define APIENTRY
@@ -355,6 +359,15 @@ typedef int (*LPTHREAD_START_ROUTINE)(void *);
#define statfs64 statfs
#endif
#define fstat64 fstat
+#elif defined(__FreeBSD__)
+ typedef int64_t off64_t;
+ typedef off_t __off_t;
+ typedef off64_t __off64_t;
+ typedef fpos_t fpos64_t;
+ #define __stat64 stat
+ #define stat64 stat
+ #define statfs64 statfs
+ #define fstat64 fstat
#else
#define __stat64 stat64
#endif
diff --git a/xbmc/linux/XFileUtils.cpp b/xbmc/linux/XFileUtils.cpp
index 2f69500483..779112ee19 100644
--- a/xbmc/linux/XFileUtils.cpp
+++ b/xbmc/linux/XFileUtils.cpp
@@ -275,7 +275,7 @@ if (errno == 20)
HANDLE result = new CXHandle(CXHandle::HND_FILE);
result->fd = fd;
-#if defined(TARGET_LINUX) && defined(HAS_DVD_DRIVE)
+#if (defined(TARGET_LINUX) || defined(TARGET_FREEBSD)) && defined(HAS_DVD_DRIVE)
// special case for opening the cdrom device
if (strcmp(lpFileName, MEDIA_DETECT::CLibcdio::GetInstance()->GetDeviceFileName())==0)
result->m_bCDROM = true;
diff --git a/xbmc/network/Network.cpp b/xbmc/network/Network.cpp
index 9e344f6fdd..b9e6227ec2 100644
--- a/xbmc/network/Network.cpp
+++ b/xbmc/network/Network.cpp
@@ -30,6 +30,7 @@
#include "dialogs/GUIDialogKaiToast.h"
#include <netinet/in.h>
+#include <sys/socket.h>
#include <arpa/inet.h>
using namespace std;
diff --git a/xbmc/network/Socket.h b/xbmc/network/Socket.h
index bf45ff0e8f..8de583d95f 100644
--- a/xbmc/network/Socket.h
+++ b/xbmc/network/Socket.h
@@ -30,6 +30,9 @@
#include <sys/time.h>
#include <sys/types.h>
#include <unistd.h>
+#ifdef __FreeBSD__
+#include <netinet/in.h>
+#endif
#ifdef _LINUX
typedef int SOCKET;
#endif
diff --git a/xbmc/network/linux/NetworkLinux.cpp b/xbmc/network/linux/NetworkLinux.cpp
index 75c84384d2..f133ce2422 100644
--- a/xbmc/network/linux/NetworkLinux.cpp
+++ b/xbmc/network/linux/NetworkLinux.cpp
@@ -35,6 +35,12 @@
#include <net/if.h>
#include <net/if_dl.h>
#include <ifaddrs.h>
+#elif defined(TARGET_FREEBSD)
+ #include <sys/sockio.h>
+ #include <net/if.h>
+ #include <net/if_dl.h>
+ #include <ifaddrs.h>
+ #include <net/route.h>
#else
#include <net/if_arp.h>
#endif
@@ -64,7 +70,7 @@ CStdString& CNetworkInterfaceLinux::GetName(void)
bool CNetworkInterfaceLinux::IsWireless()
{
-#if defined(TARGET_DARWIN)
+#if defined(TARGET_DARWIN) || defined(TARGET_FREEBSD)
return false;
#else
struct iwreq wrq;
@@ -183,6 +189,47 @@ CStdString CNetworkInterfaceLinux::GetCurrentDefaultGateway(void)
}
pclose(pipe);
}
+#elif defined(TARGET_FREEBSD)
+ size_t needed;
+ int mib[6];
+ char *buf, *next, *lim;
+ char line[16];
+ struct rt_msghdr *rtm;
+ struct sockaddr *sa;
+ struct sockaddr_in *sockin;
+
+ mib[0] = CTL_NET;
+ mib[1] = PF_ROUTE;
+ mib[2] = 0;
+ mib[3] = 0;
+ mib[4] = NET_RT_DUMP;
+ mib[5] = 0;
+ if (sysctl(mib, 6, NULL, &needed, NULL, 0) < 0)
+ return result;
+
+ if ((buf = (char *)malloc(needed)) == NULL)
+ return result;
+
+ if (sysctl(mib, 6, buf, &needed, NULL, 0) < 0) {
+ free(buf);
+ return result;
+ }
+
+ lim = buf + needed;
+ for (next = buf; next < lim; next += rtm->rtm_msglen) {
+ rtm = (struct rt_msghdr *)next;
+ sa = (struct sockaddr *)(rtm + 1);
+ sa = (struct sockaddr *)(SA_SIZE(sa) + (char *)sa);
+ sockin = (struct sockaddr_in *)sa;
+ if (inet_ntop(AF_INET, &sockin->sin_addr.s_addr,
+ line, sizeof(line)) == NULL) {
+ free(buf);
+ return result;
+ }
+ result = line;
+ break;
+ }
+ free(buf);
#else
FILE* fp = fopen("/proc/net/route", "r");
if (!fp)
@@ -284,7 +331,7 @@ CNetworkInterface* CNetworkLinux::GetFirstConnectedInterface(void)
CStdString CNetworkLinux::GetMacAddress(CStdString interfaceName)
{
CStdString result = "00:00:00:00:00:00";
-#if defined(TARGET_DARWIN)
+#if defined(TARGET_DARWIN) || defined(TARGET_FREEBSD)
#if !defined(IFT_ETHER)
#define IFT_ETHER 0x6/* Ethernet CSMACD */
@@ -350,7 +397,7 @@ void CNetworkLinux::queryInterfaceList()
CStdString macAddr = "";
m_interfaces.clear();
-#if defined(TARGET_DARWIN)
+#if defined(TARGET_DARWIN) || defined(TARGET_FREEBSD)
// Query the list of interfaces.
struct ifaddrs *list;
diff --git a/xbmc/peripherals/bus/PeripheralBusUSB.h b/xbmc/peripherals/bus/PeripheralBusUSB.h
index 5aa7bb6df6..f8c30b05d7 100644
--- a/xbmc/peripherals/bus/PeripheralBusUSB.h
+++ b/xbmc/peripherals/bus/PeripheralBusUSB.h
@@ -29,6 +29,9 @@
#elif defined(TARGET_LINUX) && defined(HAVE_LIBUSB)
#define HAVE_PERIPHERAL_BUS_USB 1
#include "linux/PeripheralBusUSBLibUSB.h"
+#elif defined(TARGET_FREEBSD) && defined(HAVE_LIBUSB)
+#define HAVE_PERIPHERAL_BUS_USB 1
+#include "linux/PeripheralBusUSBLibUSB.h"
#elif defined(TARGET_DARWIN)
#define HAVE_PERIPHERAL_BUS_USB 1
#include "osx/PeripheralBusUSB.h"
diff --git a/xbmc/peripherals/bus/linux/PeripheralBusUSBLibUSB.cpp b/xbmc/peripherals/bus/linux/PeripheralBusUSBLibUSB.cpp
index 196f26781e..3f477b3dc3 100644
--- a/xbmc/peripherals/bus/linux/PeripheralBusUSBLibUSB.cpp
+++ b/xbmc/peripherals/bus/linux/PeripheralBusUSBLibUSB.cpp
@@ -51,8 +51,11 @@ bool CPeripheralBusUSB::PerformDeviceScan(PeripheralScanResults &results)
dev->config[0].bNumInterfaces > 0 && dev->config[0].interface[0].num_altsetting > 0) ?
GetType(dev->config[0].interface[0].altsetting[0].bInterfaceClass) :
GetType(dev->descriptor.bDeviceClass);
+#ifdef __FreeBSD__
+ result.m_strLocation.Format("%s", dev->filename);
+#else
result.m_strLocation.Format("/bus%s/dev%s", bus->dirname, dev->filename);
-
+#endif
if (!results.ContainsResult(result))
results.m_results.push_back(result);
}
diff --git a/xbmc/storage/IoSupport.cpp b/xbmc/storage/IoSupport.cpp
index 67847afce0..b95919f73e 100644
--- a/xbmc/storage/IoSupport.cpp
+++ b/xbmc/storage/IoSupport.cpp
@@ -30,7 +30,7 @@
#include "WIN32Util.h"
#include "utils/CharsetConverter.h"
#endif
-#if defined (_LINUX) && !defined(__APPLE__)
+#if defined (_LINUX) && !defined(__APPLE__) && !defined(__FreeBSD__)
#include <linux/limits.h>
#include <sys/types.h>
#include <sys/ioctl.h>
@@ -54,6 +54,9 @@
#include <IOKit/storage/IOStorageDeviceCharacteristics.h>
#endif
#endif
+#ifdef __FreeBSD__
+#include <sys/syslimits.h>
+#endif
#include "cdioSupport.h"
#include "filesystem/iso9660.h"
#include "MediaManager.h"
@@ -95,6 +98,8 @@ HRESULT CIoSupport::CloseTray()
#ifdef HAS_DVD_DRIVE
#ifdef __APPLE__
// FIXME...
+#elif defined(__FreeBSD__)
+ // NYI
#elif defined(_LINUX)
char* dvdDevice = CLibcdio::GetInstance()->GetDeviceFileName();
if (strlen(dvdDevice) != 0)
@@ -264,6 +269,8 @@ INT CIoSupport::ReadSectorMode2(HANDLE hDevice, DWORD dwSector, LPSTR lpczBuffer
return -1;
}
return MODE2_DATA_SIZE;
+#elif defined(__FreeBSD__)
+ // NYI
#elif defined(_LINUX)
if (hDevice->m_bCDROM)
{
diff --git a/xbmc/system.h b/xbmc/system.h
index db525f7ac9..f35bf1387c 100644
--- a/xbmc/system.h
+++ b/xbmc/system.h
@@ -141,7 +141,7 @@
* Linux Specific
*****************/
-#if defined(TARGET_LINUX)
+#if defined(TARGET_LINUX) || defined(TARGET_FREEBSD)
#if defined(HAVE_LIBAVAHI_COMMON) && defined(HAVE_LIBAVAHI_CLIENT)
#define HAS_ZEROCONF
#define HAS_AVAHI
diff --git a/xbmc/system_gl.h b/xbmc/system_gl.h
index 18de193b79..987aa6a7f1 100644
--- a/xbmc/system_gl.h
+++ b/xbmc/system_gl.h
@@ -36,6 +36,9 @@
#include <GL/glew.h>
#include <GL/gl.h>
#include <GL/glext.h>
+ #elif defined(TARGET_FREEBSD)
+ #include <GL/glew.h>
+ #include <GL/gl.h>
#elif defined(TARGET_DARWIN)
#include <GL/glew.h>
#include <OpenGL/gl.h>
diff --git a/xbmc/threads/platform/pthreads/ThreadImpl.cpp b/xbmc/threads/platform/pthreads/ThreadImpl.cpp
index 9d875ec07d..71b209964d 100644
--- a/xbmc/threads/platform/pthreads/ThreadImpl.cpp
+++ b/xbmc/threads/platform/pthreads/ThreadImpl.cpp
@@ -23,6 +23,14 @@
#include <sys/syscall.h>
#include <sys/resource.h>
#include <string.h>
+#ifdef __FreeBSD__
+#include <sys/param.h>
+#if __FreeBSD_version < 900031
+#include <sys/thr.h>
+#else
+#include <pthread_np.h>
+#endif
+#endif
void CThread::Create(bool bAutoDelete, unsigned stacksize)
{
@@ -59,7 +67,17 @@ void CThread::TermHandler()
void CThread::SetThreadInfo()
{
+#ifdef __FreeBSD__
+#if __FreeBSD_version < 900031
+ long lwpid;
+ thr_self(&lwpid);
+ m_ThreadOpaque.LwpId = lwpid;
+#else
+ m_ThreadOpaque.LwpId = pthread_getthreadid_np();
+#endif
+#else
m_ThreadOpaque.LwpId = syscall(SYS_gettid);
+#endif
// start thread with nice level of appication
int appNice = getpriority(PRIO_PROCESS, getpid());
@@ -111,7 +129,7 @@ bool CThread::SetPriority(const int iPriority)
bReturn = false;
else if (iPriority >= minRR)
bReturn = SetPrioritySched_RR(iPriority);
-#ifndef TARGET_DARWIN
+#ifdef RLIMIT_NICE
else
{
// get user max prio
diff --git a/xbmc/utils/StdString.h b/xbmc/utils/StdString.h
index daf55d88e2..1c870b38dd 100644
--- a/xbmc/utils/StdString.h
+++ b/xbmc/utils/StdString.h
@@ -864,7 +864,7 @@ inline const Type& SSMAX(const Type& arg1, const Type& arg2)
PWSTR pNextDstW = pDstW;
SSCodeCvt::result res = SSCodeCvt::ok;
const SSCodeCvt& conv = SS_USE_FACET(loc, SSCodeCvt);
-#if defined(TARGET_DARWIN)
+#if defined(TARGET_DARWIN) || defined(__FreeBSD__)
SSCodeCvt::state_type st= { { 0 } };
#else
SSCodeCvt::state_type st= { 0 };
@@ -911,7 +911,7 @@ inline const Type& SSMAX(const Type& arg1, const Type& arg2)
PCWSTR pNextSrcW = pSrcW;
SSCodeCvt::result res = SSCodeCvt::ok;
const SSCodeCvt& conv = SS_USE_FACET(loc, SSCodeCvt);
-#if defined(TARGET_DARWIN)
+#if defined(TARGET_DARWIN) || defined(__FreeBSD__)
SSCodeCvt::state_type st= { { 0 } };
#else
SSCodeCvt::state_type st= { 0 };
diff --git a/xbmc/visualizations/XBMCProjectM/libprojectM/fftsg.cpp b/xbmc/visualizations/XBMCProjectM/libprojectM/fftsg.cpp
index 43d7534480..39a3341e66 100644
--- a/xbmc/visualizations/XBMCProjectM/libprojectM/fftsg.cpp
+++ b/xbmc/visualizations/XBMCProjectM/libprojectM/fftsg.cpp
@@ -782,6 +782,16 @@ void makect(int nc, int *ip, double *c)
#include <stdio.h>
#include <stdlib.h>
#define cdft_thread_t HANDLE
+#ifdef __FreeBSD__
+#define cdft_thread_create(thp,func,argp) { \
+ LONG thid; \
+ *(thp) = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) func, (LPVOID) argp, 0, &thid); \
+ if (*(thp) == 0) { \
+ fprintf(stderr, "cdft thread error\n"); \
+ exit(1); \
+ } \
+}
+#else
#define cdft_thread_create(thp,func,argp) { \
DWORD thid; \
*(thp) = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) func, (LPVOID) argp, 0, &thid); \
@@ -790,6 +800,7 @@ void makect(int nc, int *ip, double *c)
exit(1); \
} \
}
+#endif
#define cdft_thread_wait(th) { \
WaitForSingleObject(th, INFINITE); \
CloseHandle(th); \
diff --git a/xbmc/windowing/WinEvents.h b/xbmc/windowing/WinEvents.h
index 65faedbf84..09a36f027c 100644
--- a/xbmc/windowing/WinEvents.h
+++ b/xbmc/windowing/WinEvents.h
@@ -47,6 +47,10 @@ public:
#include "osx/WinEventsIOS.h"
#define CWinEvents CWinEventsIOS
+#elif defined(TARGET_FREEBSD) && defined(HAS_SDL_WIN_EVENTS)
+#include "WinEventsSDL.h"
+#define CWinEvents CWinEventsSDL
+
#elif defined(TARGET_LINUX) && defined(HAS_SDL_WIN_EVENTS)
#include "WinEventsSDL.h"
#define CWinEvents CWinEventsSDL
diff --git a/xbmc/windowing/WindowingFactory.h b/xbmc/windowing/WindowingFactory.h
index f1800e5929..d36f683ab1 100644
--- a/xbmc/windowing/WindowingFactory.h
+++ b/xbmc/windowing/WindowingFactory.h
@@ -39,6 +39,15 @@
#elif defined(TARGET_LINUX) && defined(HAS_GLES) && defined(HAS_EGL)
#include "egl/WinSystemGLES.h"
+#elif defined(TARGET_FREEBSD) && defined(HAS_GL) && defined(HAVE_X11)
+#include "X11/WinSystemX11GL.h"
+
+#elif defined(TARGET_FREEBSD) && defined(HAS_GLES) && defined(HAVE_X11)
+#include "X11/WinSystemX11GLES.h"
+
+#elif defined(TARGET_FREEBSD) && defined(HAS_GLES) && defined(HAS_EGL)
+#include "egl/WinSystemGLES.h"
+
#elif defined(TARGET_DARWIN_OSX)
#include "osx/WinSystemOSXGL.h"
diff --git a/xbmc/windowing/X11/XRandR.cpp b/xbmc/windowing/X11/XRandR.cpp
index 350acee5f9..69d19467c3 100644
--- a/xbmc/windowing/X11/XRandR.cpp
+++ b/xbmc/windowing/X11/XRandR.cpp
@@ -30,6 +30,11 @@
#include "utils/XBMCTinyXML.h"
#include "../xbmc/utils/log.h"
+#if defined(__FreeBSD__)
+#include <sys/types.h>
+#include <sys/wait.h>
+#endif
+
using namespace std;
CXRandR::CXRandR(bool query)