diff -Naur tvheadend/configure tvheadend-android/configure
--- tvheadend/configure	2013-06-30 11:01:45.267707164 +0200
+++ tvheadend-android/configure	2013-06-30 10:48:55.315889179 +0200
@@ -31,6 +31,7 @@
   "dvbcsa:no"
   "epoll:yes"
   "kqueue:no"
+  "android:no"
 )
 
 #
diff -Naur tvheadend/Makefile tvheadend-android/Makefile
--- tvheadend/Makefile	2013-06-30 11:01:45.267707164 +0200
+++ tvheadend-android/Makefile	2013-06-30 11:25:17.450709801 +0200
@@ -32,7 +32,7 @@
 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 -lm -llog
 
 vpath %.c $(ROOTDIR)
 vpath %.h $(ROOTDIR)
diff -Naur tvheadend/README tvheadend-android/README
--- tvheadend/README	2013-06-30 11:01:45.267707164 +0200
+++ tvheadend-android/README	2013-06-30 10:48:04.895639159 +0200
@@ -16,6 +16,16 @@
 
 	$ ./configure
 
+Sample configure for Android:
+
+$ ./configure --disable-avahi \
+              --disable-libav \
+              --enable-bundle \
+              --enable-android \
+              --arch=armeabi-v7a \
+              --cc=/home/jernej/Android/toolchain/android-9/bin/arm-linux-androideabi-gcc \
+              --android_toolchain=/home/jernej/Android/toolchain/android-9
+
 If any dependencies are missing the configure script will complain or attempt
 to disable optional features.
 
diff -Naur tvheadend/src/capmt.c tvheadend-android/src/capmt.c
--- tvheadend/src/capmt.c	2013-06-30 11:01:45.279707223 +0200
+++ tvheadend-android/src/capmt.c	2013-06-30 10:48:04.899639178 +0200
@@ -77,10 +77,12 @@
 
 #ifdef __GNUC__
 #include <features.h>
+#if !ENABLE_ANDROID
 #if __GNUC_PREREQ(4, 3)
 #pragma GCC diagnostic ignored "-Warray-bounds"
 #endif
 #endif
+#endif
 
 #define MAX_CA  4
 #define MAX_INDEX 64
diff -Naur tvheadend/src/cwc.c tvheadend-android/src/cwc.c
--- tvheadend/src/cwc.c	2013-06-30 11:01:45.283707243 +0200
+++ tvheadend-android/src/cwc.c	2013-06-30 10:48:04.899639178 +0200
@@ -48,6 +48,10 @@
 #include "ffdecsa/FFdecsa.h"
 #endif
 
+#if ENABLE_ANDROID
+#include <sys/socket.h>
+#endif
+
 /**
  *
  */
diff -Naur tvheadend/src/dvb/dvb.h tvheadend-android/src/dvb/dvb.h
--- tvheadend/src/dvb/dvb.h	2013-06-30 11:01:45.283707243 +0200
+++ tvheadend-android/src/dvb/dvb.h	2013-06-30 10:48:04.899639178 +0200
@@ -1,6 +1,6 @@
 /*
  *  TV Input - Linux DVB interface
- *  Copyright (C) 2007 Andreas Öman
+ *  Copyright (C) 2007 Andreas ï¿½man
  *
  *  This program is free software: you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
@@ -19,8 +19,10 @@
 #ifndef DVB_H_
 #define DVB_H_
 
+#if ENABLE_LINUXDVB
 #include <linux/dvb/version.h>
 #include <linux/dvb/frontend.h>
+#endif
 #include <pthread.h>
 #include "htsmsg.h"
 #include "psi.h"
@@ -81,7 +83,9 @@
  *
  */
 typedef struct dvb_mux_conf {
+#if ENABLE_LINUXDVB
   dvb_frontend_parameters_t dmc_fe_params;
+#endif
   int dmc_polarisation;
   dvb_satconf_t *dmc_satconf;
 #if DVB_API_VERSION >= 5
diff -Naur tvheadend/src/epggrab/module/eit.c tvheadend-android/src/epggrab/module/eit.c
--- tvheadend/src/epggrab/module/eit.c	2013-06-30 11:01:45.291707283 +0200
+++ tvheadend-android/src/epggrab/module/eit.c	2013-06-30 10:48:04.903639198 +0200
@@ -19,6 +19,8 @@
 #include <string.h>
 
 #include "tvheadend.h"
+
+#if ENABLE_LINUXDVB
 #include "channels.h"
 #include "dvb/dvb.h"
 #include "dvb/dvb_support.h"
@@ -900,3 +902,5 @@
 void eit_load ( void )
 {
 }
+
+#endif
diff -Naur tvheadend/src/epggrab/module/opentv.c tvheadend-android/src/epggrab/module/opentv.c
--- tvheadend/src/epggrab/module/opentv.c	2013-06-30 11:01:45.291707283 +0200
+++ tvheadend-android/src/epggrab/module/opentv.c	2013-06-30 10:48:04.903639198 +0200
@@ -20,8 +20,9 @@
 #include <assert.h>
 #include <unistd.h>
 #include <regex.h>
-#include <linux/dvb/dmx.h>
 #include "tvheadend.h"
+#if ENABLE_LINUXDVB
+#include <linux/dvb/dmx.h>
 #include "dvb/dvb.h"
 #include "channels.h"
 #include "huffman.h"
@@ -934,3 +935,4 @@
 {
   // TODO: do we want to keep a list of channels stored?
 }
+#endif
diff -Naur tvheadend/src/epggrab/otamux.c tvheadend-android/src/epggrab/otamux.c
--- tvheadend/src/epggrab/otamux.c	2013-06-30 11:01:45.291707283 +0200
+++ tvheadend-android/src/epggrab/otamux.c	2013-06-30 10:48:13.711682875 +0200
@@ -252,6 +252,7 @@
   ( epggrab_module_ota_t *mod, int onid, int tsid, int period, int interval, 
     const char *networkname )
 {
+#if ENABLE_LINUXDVB
   th_dvb_adapter_t *tda;
   th_dvb_mux_instance_t *tdmi;
   epggrab_ota_mux_t *ota;
@@ -264,6 +265,7 @@
       epggrab_ota_register(ota, period, interval);
     }
   }
+#endif
 }
 
 /*
@@ -381,11 +383,13 @@
       if (ota->is_reg && ota->state == EPGGRAB_OTA_MUX_RUNNING) break;
     }
 
+#if ENABLE_LINUXDVB
     /* All complete (bring timer forward) */
     if (!ota) {
       gtimer_arm(&tdmi->tdmi_adapter->tda_mux_scanner_timer,
                  dvb_adapter_mux_scanner, tdmi->tdmi_adapter, 20);
     }
+#endif
   }
 }
 
diff -Naur tvheadend/src/epggrab.c tvheadend-android/src/epggrab.c
--- tvheadend/src/epggrab.c	2013-06-30 11:01:45.291707283 +0200
+++ tvheadend-android/src/epggrab.c	2013-06-30 10:48:13.711682875 +0200
@@ -22,7 +22,6 @@
 #include <assert.h>
 #include <unistd.h>
 #include <sys/types.h>
-#include <sys/un.h>
 #include <sys/socket.h>
 #include "htsmsg.h"
 #include "settings.h"
diff -Naur tvheadend/src/htsp_server.c tvheadend-android/src/htsp_server.c
--- tvheadend/src/htsp_server.c	2013-06-30 11:01:45.299707323 +0200
+++ tvheadend-android/src/htsp_server.c	2013-06-30 10:52:57.273088980 +0200
@@ -51,7 +51,7 @@
 #if ENABLE_LIBAV
 #include "plumbing/transcoding.h"
 #endif
-#include <sys/statvfs.h>
+#include <sys/vfs.h>
 #include "settings.h"
 #include <sys/time.h>
 
@@ -823,10 +823,10 @@
 htsp_method_getDiskSpace(htsp_connection_t *htsp, htsmsg_t *in)
 {
   htsmsg_t *out;
-  struct statvfs diskdata;
+  struct statfs diskdata;
   dvr_config_t *cfg = dvr_config_find_by_name_default("");
 
-  if(statvfs(cfg->dvr_storage,&diskdata) == -1)
+  if(statfs(cfg->dvr_storage,&diskdata) == -1)
     return htsp_error("Unable to stat path");
   
   out = htsmsg_create_map();
diff -Naur tvheadend/src/main.c tvheadend-android/src/main.c
--- tvheadend/src/main.c	2013-06-30 11:01:45.303707342 +0200
+++ tvheadend-android/src/main.c	2013-06-30 10:48:13.711682875 +0200
@@ -41,7 +41,9 @@
 #include "access.h"
 #include "http.h"
 #include "webui/webui.h"
+#if ENABLE_LINUXDVB
 #include "dvb/dvb.h"
+#endif
 #include "epggrab.h"
 #include "spawn.h"
 #include "subscriptions.h"
@@ -171,6 +173,9 @@
 get_user_groups (const struct passwd *pw, gid_t* glist, size_t gmax)
 {
   int num = 0;
+#if ENABLE_ANDROID
+  return num;
+#else
   struct group *gr;
   char **mem;
   glist[num++] = pw->pw_gid;
@@ -181,6 +186,7 @@
     }
   }
   return num;
+#endif
 }
 
 /**
@@ -754,7 +760,11 @@
   signal(SIGTERM, doexit);
   signal(SIGINT, doexit);
 
+#if ENABLE_ANDROID
+  sigprocmask(SIG_UNBLOCK, &set, NULL);
+#else
   pthread_sigmask(SIG_UNBLOCK, &set, NULL);
+#endif
 
   tvhlog(LOG_NOTICE, "START", "HTS Tvheadend version %s started, "
 	 "running as PID:%d UID:%d GID:%d, settings located in '%s'",
diff -Naur tvheadend/src/muxer/tvh/mkmux.c tvheadend-android/src/muxer/tvh/mkmux.c
--- tvheadend/src/muxer/tvh/mkmux.c	2013-06-30 11:01:45.303707342 +0200
+++ tvheadend-android/src/muxer/tvh/mkmux.c	2013-06-30 10:48:13.711682875 +0200
@@ -32,6 +32,10 @@
 #include "mkmux.h"
 #include "ebml.h"
 
+#if ENABLE_ANDROID
+#include <sys/uio.h>
+#endif
+
 extern int dvr_iov_max;
 
 TAILQ_HEAD(mk_cue_queue, mk_cue);
diff -Naur tvheadend/src/muxes.c tvheadend-android/src/muxes.c
--- tvheadend/src/muxes.c	2013-06-30 11:01:45.303707342 +0200
+++ tvheadend-android/src/muxes.c	2013-06-30 10:48:13.711682875 +0200
@@ -15,7 +15,6 @@
  *  You should have received a copy of the GNU General Public License
  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
-
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <unistd.h>
@@ -29,6 +28,8 @@
 #include <ctype.h>
 
 #include "tvheadend.h"
+
+#if ENABLE_LINUXDVB
 #include "dvb/dvb.h"
 #include "muxes.h"
 #include "filebundle.h"
@@ -379,3 +380,4 @@
 #endif
   _muxes_load_dir(path, NULL, 0);
 } 
+#endif
diff -Naur tvheadend/src/rawtsinput.c tvheadend-android/src/rawtsinput.c
--- tvheadend/src/rawtsinput.c	2013-06-30 11:01:45.307707362 +0200
+++ tvheadend-android/src/rawtsinput.c	2013-06-30 10:48:13.711682875 +0200
@@ -47,6 +47,9 @@
 
 } rawts_t;
 
+#if ENABLE_ANDROID
+extern int clock_nanosleep(clockid_t, int, const struct timespec *, struct timespec *);
+#endif
 
 /**
  *
diff -Naur tvheadend/src/spawn.c tvheadend-android/src/spawn.c
--- tvheadend/src/spawn.c	2013-06-30 11:01:45.307707362 +0200
+++ tvheadend-android/src/spawn.c	2013-06-30 10:48:13.711682875 +0200
@@ -33,6 +33,10 @@
 #include "file.h"
 #include "spawn.h"
 
+#ifndef WIFCONTINUED
+#define WIFCONTINUED(s) ((s) == 0xffff)
+#endif
+
 extern char **environ;
 
 pthread_mutex_t spawn_mutex = PTHREAD_MUTEX_INITIALIZER;
diff -Naur tvheadend/src/timeshift/timeshift_reader.c tvheadend-android/src/timeshift/timeshift_reader.c
--- tvheadend/src/timeshift/timeshift_reader.c	2013-06-30 11:01:45.311707382 +0200
+++ tvheadend-android/src/timeshift/timeshift_reader.c	2013-06-30 11:44:40.428476697 +0200
@@ -325,7 +325,7 @@
                ts->id, (*cur_file)->path);
       *fd = open((*cur_file)->path, O_RDONLY);
     }
-    tvhtrace("timeshift", "ts %d seek to %"PRIoff_t, ts->id, *cur_off);
+    tvhtrace("timeshift", "ts %d seek to %"PRIoff_t, ts->id, (long long int)*cur_off);
     lseek(*fd, *cur_off, SEEK_SET);
 
     /* Read msg */
@@ -337,7 +337,7 @@
       return -1;
     }
     tvhtrace("timeshift", "ts %d read msg %p (%"PRIssize_t")",
-             ts->id, *sm, r);
+             ts->id, *sm, (int)r);
 
     /* Incomplete */
     if (r == 0) {
diff -Naur tvheadend/src/tvheadend.h tvheadend-android/src/tvheadend.h
--- tvheadend/src/tvheadend.h	2013-06-30 11:01:45.311707382 +0200
+++ tvheadend-android/src/tvheadend.h	2013-06-30 10:48:13.715682895 +0200
@@ -1,6 +1,6 @@
 /*
  *  Tvheadend - structures
- *  Copyright (C) 2007 Andreas Öman
+ *  Copyright (C) 2007 Andreas ï¿½man
  *
  *  This program is free software: you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
@@ -36,6 +36,10 @@
 
 #include "redblack.h"
 
+#if ENABLE_ANDROID
+#define S_IEXEC S_IXUSR
+#endif
+
 typedef struct {
   const char     *name;
   const uint32_t *enabled;
@@ -456,6 +460,29 @@
   return tp.tv_sec * 1000000ULL + (tp.tv_nsec / 1000);
 }
 
+#if ENABLE_ANDROID
+static inline time_t timegm(struct tm *tm);
+
+time_t
+timegm(struct tm *tm)
+{
+    time_t ret;
+    char *tz;
+
+   tz = getenv("TZ");
+    setenv("TZ", "", 1);
+    tzset();
+    ret = mktime(tm);
+    if (tz)
+        setenv("TZ", tz, 1);
+    else
+        unsetenv("TZ");
+    tzset();
+    return ret;
+}
+
+#endif
+
 int sri_to_rate(int sri);
 int rate_to_sri(int rate);
 
diff -Naur tvheadend/src/tvhlog.c tvheadend-android/src/tvhlog.c
--- tvheadend/src/tvhlog.c	2013-06-30 11:01:45.311707382 +0200
+++ tvheadend-android/src/tvhlog.c	2013-06-30 11:39:01.082793972 +0200
@@ -51,7 +51,9 @@
   tvhlog_options = options;
   tvhlog_path    = path ? strdup(path) : NULL;
   tvhlog_subsys  = NULL;
+#if !ENABLE_ANDROID
   openlog("tvheadend", LOG_PID, LOG_DAEMON);
+#endif
   pthread_mutex_init(&tvhlog_mutex, NULL);
 }
 
@@ -174,7 +176,11 @@
   /* Syslog */
   if (options & TVHLOG_OPT_SYSLOG) {
     if (options & TVHLOG_OPT_DBG_SYSLOG || severity < LOG_DEBUG) {
+#if ENABLE_ANDROID
+      __android_log_print(ANDROID_LOG_DEBUG, "tvheadend", "%s", buf);
+#else
       syslog(s, "%s", buf);
+#endif
     }
   } 
 
diff -Naur tvheadend/src/tvhlog.h tvheadend-android/src/tvhlog.h
--- tvheadend/src/tvhlog.h	2013-06-30 11:01:45.311707382 +0200
+++ tvheadend-android/src/tvhlog.h	2013-06-30 11:38:18.462582630 +0200
@@ -18,8 +18,24 @@
 #ifndef __TVH_LOGGING_H__
 #define __TVH_LOGGING_H__
 
+#include "config.h"
+
 #include <sys/types.h>
+#if ENABLE_ANDROID
+#include <android/log.h>
+
+#define	LOG_EMERG	0	/* system is unusable */
+#define	LOG_ALERT	1	/* action must be taken immediately */
+#define	LOG_CRIT	2	/* critical conditions */
+#define	LOG_ERR		3	/* error conditions */
+#define	LOG_WARNING	4	/* warning conditions */
+#define	LOG_NOTICE	5	/* normal but significant condition */
+#define	LOG_INFO	6	/* informational */
+#define	LOG_DEBUG	7	/* debug-level messages */
+
+#else
 #include <sys/syslog.h>
+#endif
 #include <pthread.h>
 #include <stdarg.h>
 
diff -Naur tvheadend/src/tvhtime.c tvheadend-android/src/tvhtime.c
--- tvheadend/src/tvhtime.c	2013-06-30 11:01:45.311707382 +0200
+++ tvheadend-android/src/tvhtime.c	2013-06-30 10:55:11.201753096 +0200
@@ -1,8 +1,11 @@
 #define _ISOC9X_SOURCE
 
+#include "tvheadend.h"
 #include <time.h>
 #include <sys/ipc.h>
+#if !ENABLE_ANDROID
 #include <sys/shm.h>
+#endif
 #include <sys/time.h>
 #include <stdio.h>
 #include <string.h>
@@ -11,7 +14,6 @@
 #include <stdlib.h>
 
 #include "tvhtime.h"
-#include "tvheadend.h"
 #include "settings.h"
 
 uint32_t tvhtime_update_enabled;
@@ -46,6 +48,7 @@
   int    pad[10];
 } ntp_shm_t;
 
+#if !ENABLE_ANDROID
 static ntp_shm_t *
 ntp_shm_init ( void )
 {
@@ -72,6 +75,7 @@
 
   return shmptr;
 }
+#endif
 
 /*
  * Update time
@@ -79,6 +83,7 @@
 void
 tvhtime_update ( struct tm *tm )
 {
+#if !ENABLE_ANDROID
   time_t now;
   struct timeval tv;
   ntp_shm_t *ntp_shm;
@@ -122,6 +127,7 @@
     ntp_shm->count++;
     ntp_shm->valid = 1;
   }
+#endif
 }
 
 /* Initialise */
diff -Naur tvheadend/src/version.c tvheadend-android/src/version.c
--- tvheadend/src/version.c	1970-01-01 01:00:00.000000000 +0100
+++ tvheadend-android/src/version.c	2013-06-30 11:06:00.512972857 +0200
@@ -0,0 +1 @@
+const char *tvheadend_version = "";
diff -Naur tvheadend/src/webui/webui.c tvheadend-android/src/webui/webui.c
--- tvheadend/src/webui/webui.c	2013-06-30 11:01:45.411707878 +0200
+++ tvheadend-android/src/webui/webui.c	2013-06-30 11:00:09.595232750 +0200
@@ -1,6 +1,6 @@
 /*
  *  tvheadend, WEBUI / HTML user interface
- *  Copyright (C) 2008 Andreas Öman
+ *  Copyright (C) 2008 Andreas ï¿½man
  *
  *  This program is free software: you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
@@ -55,6 +55,10 @@
 #include <sys/uio.h>
 #endif
 
+#if ENABLE_ANDROID
+#include <sys/socket.h>
+#endif
+
 /**
  *
  */
@@ -894,8 +898,14 @@
   file_end = st.st_size-1;
   
   range = http_arg_get(&hc->hc_args, "Range");
+
+#if ENABLE_ANDROID
+  if(range != NULL)
+    sscanf(range, "bytes=%"PRId64"-%"PRId64"", (long long int *)&file_start, (long long int *)&file_end);
+#else
   if(range != NULL)
     sscanf(range, "bytes=%"PRId64"-%"PRId64"", &file_start, &file_end);
+#endif
 
   //Sanity checks
   if(file_start < 0 || file_start >= st.st_size) {
@@ -913,9 +923,14 @@
   }
 
   content_len = file_end - file_start+1;
-  
+
+#if ENABLE_ANDROID
+  sprintf(range_buf, "bytes %"PRId64"-%"PRId64"/%"PRId64"",
+	  (long long int)file_start, (long long int)file_end, st.st_size);
+#else
   sprintf(range_buf, "bytes %"PRId64"-%"PRId64"/%"PRId64"",
     file_start, file_end, st.st_size);
+#endif
 
   if(file_start > 0)
     lseek(fd, file_start, SEEK_SET);
diff -Naur tvheadend/support/configure.inc tvheadend-android/support/configure.inc
--- tvheadend/support/configure.inc	2013-06-30 11:01:45.411707878 +0200
+++ tvheadend-android/support/configure.inc	2013-06-30 10:48:13.715682895 +0200
@@ -201,7 +201,7 @@
       *dir|prefix)
         eval "$opt=$val"
         ;;
-      cc|cflags|arch|cpu|platform|python)
+      cc|cflags|arch|cpu|platform|python|android_toolchain)
         eval "`toupper $opt`=$val"
         ;;
       enable-*)
@@ -493,6 +493,19 @@
 #define PLATFORM_$(toupper ${PLATFORM}) 1
 EOF
 
+if enabled android; then
+cat >>${CONFIG_MK} <<EOF
+CFLAGS += -I${ANDROID_TOOLCHAIN}/staging/armeabi-v7a/include	
+CFLAGS += -I${ANDROID_TOOLCHAIN}/sysroot/usr/include/
+LDFLAGS += -L${ANDROID_TOOLCHAIN}/staging/armeabi-v7a/lib
+LDFLAGS += -L${ANDROID_TOOLCHAIN}/lib
+EOF
+else
+cat >>${CONFIG_MK} <<EOF
+LDFLAGS += -lrt -lpthread
+EOF
+fi
+
   # Add package config
   for pkg in ${PACKAGES[*]}; do
     cat >>"${CONFIG_MK}" <<EOF
