]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
osx: initial support for OS X 397/head
authorDamjan Marion <damjan.marion@gmail.com>
Fri, 16 May 2014 21:18:53 +0000 (23:18 +0200)
committerDamjan Marion <damjan.marion@gmail.com>
Mon, 26 May 2014 15:59:33 +0000 (17:59 +0200)
Makefile
configure
src/httpc.c
src/muxer.c
src/trap.c
src/tvheadend.h
src/upnp.c
src/webui/webui.c
src/wrappers.c
support/configure.inc

index dee8c41222b57d19998c39928bcdfe0dcfea3df9..1bf97c332b78da9ea87ede9b21611c4b486cb9a2 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -32,7 +32,16 @@ CFLAGS  += -Wmissing-prototypes -fms-extensions
 CFLAGS  += -g -funsigned-char -O2
 CFLAGS  += -D_FILE_OFFSET_BITS=64
 CFLAGS  += -I${BUILDDIR} -I${ROOTDIR}/src -I${ROOTDIR}
-LDFLAGS += -lrt -ldl -lpthread -lm
+LDFLAGS += -ldl -lpthread -lm
+ifneq ($(PLATFORM), darwin)
+LDFLAGS += -lrt
+endif
+
+ifeq ($(COMPILER), clang)
+CFLAGS  += -Wno-microsoft -Qunused-arguments -Wno-unused-function
+CFLAGS  += -Wno-unused-value -Wno-tautological-constant-out-of-range-compare
+CFLAGS  += -Wno-parentheses-equality -Wno-incompatible-pointer-types
+endif
 
 vpath %.c $(ROOTDIR)
 vpath %.h $(ROOTDIR)
index cdcd469dcde36198eb41ed4b04811d2954c5c6e6..0fbe95d08a262453a4c8929fd9be5d2a81c8e1c1 100755 (executable)
--- a/configure
+++ b/configure
@@ -72,6 +72,16 @@ check_cc_header execinfo
 check_cc_option mmx
 check_cc_option sse2
 
+if check_cc '
+#if !defined(__clang__)
+#error this is not clang
+#endif
+'; then
+  COMPILER=clang
+else
+  COMPILER=gcc
+fi
+
 check_cc_snippet getloadavg '#include <stdlib.h> 
 void test() { getloadavg(NULL,0); }'
 
@@ -147,6 +157,13 @@ else
   die "SSL development support not found"
 fi
 
+#
+# OS X
+#
+if [ ${PLATFORM} = "darwin" ]; then
+  disable linuxdvb
+fi
+
 #
 # DVB API
 #
@@ -296,7 +313,7 @@ fi
 #
 # kqueue
 #
-if [ ${PLATFORM} = "freebsd" ]; then
+if [ ${PLATFORM} = "freebsd" ] || [ ${PLATFORM} = "darwin" ]; then
   enable kqueue
 fi
 
index 4efa047de7c696b822cefb3a29322f9c5facc1e2..21cb6771c6731eec290ea1a52c126667f0390762 100644 (file)
@@ -766,9 +766,9 @@ http_client_data_received( http_client_t *hc, char *buf, ssize_t len, int hdr )
     return 0;
   }  
 
-  csize = hc->hc_csize < 0 ? 0 : hc->hc_csize;
+  csize = hc->hc_csize == (size_t) -1 ? 0 : hc->hc_csize;
   l = len;
-  if (hc->hc_csize && hc->hc_csize != -1 && hc->hc_rpos > csize) {
+  if (hc->hc_csize && hc->hc_csize != (size_t) -1 && hc->hc_rpos > csize) {
     l2 = hc->hc_rpos - csize;
     if (l2 < l)
       l = l2;
@@ -801,7 +801,7 @@ int
 http_client_run( http_client_t *hc )
 {
   char *buf, *saveptr, *argv[3], *d, *p;
-  http_ver_t ver;
+  int ver;
   ssize_t r;
   size_t len;
   int res;
index d8d76e6bc56a7a8046ab76a321090c7c7ebc8674..03150d39e621ce8aaf8545cc623bb322be1831b4 100644 (file)
 #include "muxer/muxer_libav.h"
 #endif
 
+#if defined(PLATFORM_DARWIN)
+#define fdatasync(fd)       fcntl(fd, F_FULLFSYNC)
+#endif
+
 /**
  * Mime type for containers containing only audio
  */
@@ -458,7 +462,11 @@ muxer_cache_update(muxer_t *m, int fd, off_t pos, size_t size)
     fdatasync(fd);
     /* fall through */
   case MC_CACHE_DONTKEEP:
+#if defined(PLATFORM_DARWIN)
+    fcntl(fd, F_NOCACHE, 1);
+#else
     posix_fadvise(fd, pos, size, POSIX_FADV_DONTNEED);
+#endif
     break;
   default:
     abort();
index 5481792d7feeea7bf1d09940f19a0500fb192eef..2bb99c27e76838b9db12de6a43ad8134a58d58d9 100644 (file)
@@ -20,7 +20,7 @@
 
 char tvh_binshasum[20];
 
-#if defined(__i386__) || defined(__x86_64__)
+#if (defined(__i386__) || defined(__x86_64__)) && !defined(PLATFORM_DARWIN)
 
 // Only do this on x86 for now
 
@@ -315,6 +315,26 @@ trap_init(const char *ver)
   sigprocmask(SIG_UNBLOCK, &m, NULL);
 }
 
+#elif defined(PLATFORM_DARWIN)
+
+#include <string.h>
+#include <signal.h>
+
+void
+trap_init(const char *ver)
+{
+  sigset_t m;
+
+  sigemptyset(&m);
+  sigaddset(&m, SIGSEGV);
+  sigaddset(&m, SIGBUS);
+  sigaddset(&m, SIGILL);
+  sigaddset(&m, SIGABRT);
+  sigaddset(&m, SIGFPE);
+
+  sigprocmask(SIG_UNBLOCK, &m, NULL);
+}
+
 #else
 
 void
index 91b0d831b2a317ffb750941d13a3dfc112228fe2..e5910f8ddec819e255da1c7b3560efc78f61717a 100644 (file)
@@ -500,6 +500,20 @@ int tvh_str_update(char **strp, const char *src);
 #define CLOCK_MONOTONIC_COARSE CLOCK_MONOTONIC
 #endif
 
+#ifdef PLATFORM_DARWIN
+#define CLOCK_MONOTONIC 0 
+#define CLOCK_REALTIME 0
+
+static inline int clock_gettime(int clk_id, struct timespec* t) {
+    struct timeval now;
+    int rv = gettimeofday(&now, NULL);
+    if (rv) return rv;
+    t->tv_sec  = now.tv_sec;
+    t->tv_nsec = now.tv_usec * 1000;
+    return 0;
+}
+#endif
+
 static inline int64_t 
 getmonoclock(void)
 {
@@ -677,8 +691,13 @@ void tvh_qsort_r(void *base, size_t nmemb, size_t size, int (*compar)(const void
 #endif
 #define PRIslongword_t  "ld"
 #define PRIulongword_t  "lu"
+#if defined(PLATFORM_DARWIN)
+#define PRIsize_t       PRIulongword_t
+#define PRIssize_t      PRIslongword_t
+#else
 #define PRIsize_t       PRIuword_t
 #define PRIssize_t      PRIsword_t
+#endif
 #if __WORDSIZE == 32 && defined(PLATFORM_FREEBSD)
 #define PRItime_t       PRIsword_t
 #else
index 4c9435c47c848a3bfd8c5f7bac53a006373e2c3f..0c6f5ee873994b45f585ed4edf0fc56d13510be1 100644 (file)
@@ -147,7 +147,7 @@ upnp_thread( void *aux )
           inet_ntop(ip.ss_family, IP_IN_ADDR(ip), tbuf, sizeof(tbuf));
           tvhtrace("upnp", "%s - received data from %s:%hu [size=%zi]",
                    conn == multicast ? "multicast" : "unicast",
-                   tbuf, IP_PORT(ip), size);
+                   tbuf, (unsigned short) IP_PORT(ip), size);
           tvhlog_hexdump("upnp", buf, size);
         }
 #endif
index d56c79cfb289942cf619a76f99b854a525d333f6..7929ad29ad5c80d63e45e954aebf78fc18822598 100644 (file)
@@ -930,7 +930,7 @@ page_dvrfile(http_connection_t *hc, const char *remain, void *opaque)
   off_t content_len, file_start, file_end, chunk;
 #if defined(PLATFORM_LINUX)
   ssize_t r;
-#elif defined(PLATFORM_FREEBSD)
+#elif defined(PLATFORM_FREEBSD) || defined(PLATFORM_DARWIN)
   off_t r;
 #endif
   
@@ -1017,6 +1017,9 @@ page_dvrfile(http_connection_t *hc, const char *remain, void *opaque)
       r = sendfile(hc->hc_fd, fd, NULL, chunk);
 #elif defined(PLATFORM_FREEBSD)
       sendfile(fd, hc->hc_fd, 0, chunk, NULL, &r, 0);
+#elif defined(PLATFORM_DARWIN)
+      r = chunk;
+      sendfile(fd, hc->hc_fd, 0, NULL, &r, 0);
 #endif
       if(r == -1) {
   close(fd);
index 82535abf666fc35f2cefc26a4de456e94f46edf3..db3b5a16852735ff1ddefa03583bf13eb5871835 100644 (file)
@@ -109,6 +109,8 @@ thread_wrapper ( void *p )
 #elif defined(PLATFORM_FREEBSD)
   /* Set name of thread */
   pthread_set_name_np(pthread_self(), ts->name);
+#elif defined(PLATFORM_DARWIN)
+  pthread_setname_np(ts->name);
 #endif
 
   sigemptyset(&set);
index 8ddae9820cc7f71647e06d0d7b852b88274143f5..96f1d68dd06122d07c70c8d052d095b290689991 100755 (executable)
@@ -470,9 +470,11 @@ function write_config
 CONFIGURE_ARGS = ${CONFIGURE_ARGS}
 ROOTDIR  ?= ${ROOTDIR}
 BUILDDIR ?= ${BUILDDIR}
+PLATFORM ?= ${PLATFORM}
 OSENV    ?= ${OSENV}
 ARCH     ?= ${ARCH}
 CPU      ?= ${CPU}
+COMPILER ?= ${COMPILER}
 ifeq (\$(origin CC),default)
 CC        = ${CC}
 endif