From: Sergio Costa Fortier Date: Sat, 2 Aug 2014 01:17:51 +0000 (-0300) Subject: Corrected build for android. X-Git-Tag: v4.1~1537 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d91375de0af65eeaddcdc52a63499b12f0bb39b8;p=thirdparty%2Ftvheadend.git Corrected build for android. Included --enable-android on configure script. Build with that sample script: #!/bin/sh # Make sure you have TOOLCHAIN defined in .bashrc or .bash_profile and have linux/dvb headers in include dir. SRC_DIR="`pwd`/tvheadend" INCLUDE_DIR="`pwd`/out/include" cd $SRC_DIR export SYS_ROOT="$TOOLCHAIN/sysroot" export CC="arm-linux-androideabi-gcc --sysroot=$SYS_ROOT -I$INCLUDE_DIR" export CXX="arm-linux-androideabi-g++ --sysroot=$SYS_ROOT -I$INCLUDE_DIR" export CPP="arm-linux-androideabi-cpp" export LD="arm-linux-androideabi-ld" export AR="arm-linux-androideabi-ar" export RANLIB="arm-linux-androideabi-ranlib" export STRIP="arm-linux-androideabi-strip" export CROSSCOMPILE="arm-linux-androideabi-" export CFLAGS="--sysroot=$SYS_ROOT -I$INCLUDE_DIR" export CXXFLAGS="--sysroot=$SYS_ROOT -I$INCLUDE_DIR" export LIBS="-lc -lgcc" ./configure --prefix=$SYS_ROOT/usr --arch=armv7 --platform=linux --disable-avahi --enable-bundle --python=/usr/bin/python --enable-android make TODO: change shm code to ashmem on tvhtime.c --- diff --git a/Makefile b/Makefile index 3ed7cb3f9..9aa4c9460 100644 --- a/Makefile +++ b/Makefile @@ -33,15 +33,21 @@ CFLAGS += -Wmissing-prototypes CFLAGS += -fms-extensions -funsigned-char -fno-strict-aliasing CFLAGS += -D_FILE_OFFSET_BITS=64 CFLAGS += -I${BUILDDIR} -I${ROOTDIR}/src -I${ROOTDIR} +ifeq ($(CONFIG_ANDROID),yes) +LDFLAGS += -ldl -lm +else LDFLAGS += -ldl -lpthread -lm +endif ifeq ($(CONFIG_LIBICONV),yes) LDFLAGS += -liconv endif ifeq ($(PLATFORM), darwin) LDFLAGS += -framework CoreServices else +ifeq ($(CONFIG_ANDROID),no) LDFLAGS += -lrt endif +endif ifeq ($(COMPILER), clang) CFLAGS += -Wno-microsoft -Qunused-arguments -Wno-unused-function diff --git a/configure b/configure index 225662999..96839f6e7 100755 --- a/configure +++ b/configure @@ -39,6 +39,7 @@ OPTIONS=( "dvbcsa:no" "kqueue:no" "dbus_1:auto" + "android:no" ) # @@ -166,6 +167,8 @@ if [ ${PLATFORM} = "freebsd" ]; then enable ssl elif check_pkg openssl || check_pkg libssl; then enable ssl +elif check_cc_header 'openssl/ssl' ssl; then + enable ssl else die "SSL development support not found" fi diff --git a/src/descrambler/capmt.c b/src/descrambler/capmt.c index 40a21c9a8..e9a62aced 100644 --- a/src/descrambler/capmt.c +++ b/src/descrambler/capmt.c @@ -627,7 +627,7 @@ capmt_write_msg(capmt_t *capmt, int adapter, int sid, const uint8_t *buf, size_t res = send(fd, buf, len, MSG_DONTWAIT); if (res < len) { - tvhlog(LOG_DEBUG, "capmt", "Message send failed to socket %i (%zi)", fd, res); + tvhlog(LOG_DEBUG, "capmt", "Message send failed to socket %i (%li)", fd, res); if (capmt->capmt_oscam != CAPMT_OSCAM_SO_WRAPPER) { capmt_socket_close_lock(capmt, i); return -1; diff --git a/src/htsp_server.c b/src/htsp_server.c index 94e91e16a..e84c22b88 100644 --- a/src/htsp_server.c +++ b/src/htsp_server.c @@ -54,7 +54,13 @@ #include #include #include +#if ENABLE_ANDROID +#include +#define statvfs statfs +#define fstatvfs fstatfs +#else #include +#endif #include "settings.h" #include #include diff --git a/src/httpc.c b/src/httpc.c index ac88ba3c4..8f64ef743 100644 --- a/src/httpc.c +++ b/src/httpc.c @@ -40,6 +40,10 @@ #define SSL_OP_NO_COMPRESSION 0 #endif +#if ENABLE_ANDROID +#include +#endif + struct http_client_ssl { int connected; int shutdown; diff --git a/src/input/mpegts/satip/satip.c b/src/input/mpegts/satip/satip.c index 333244750..901a00923 100644 --- a/src/input/mpegts/satip/satip.c +++ b/src/input/mpegts/satip/satip.c @@ -34,6 +34,10 @@ #include #endif +#if ENABLE_ANDROID +#include +#endif + static void satip_device_discovery_start( void ); /* diff --git a/src/input/mpegts/satip/satip_frontend.c b/src/input/mpegts/satip/satip_frontend.c index a0c7eb250..a735e504e 100644 --- a/src/input/mpegts/satip/satip_frontend.c +++ b/src/input/mpegts/satip/satip_frontend.c @@ -29,6 +29,10 @@ #include #endif +#if ENABLE_ANDROID +#include +#endif + static int satip_frontend_tune1 ( satip_frontend_t *lfe, mpegts_mux_instance_t *mmi ); diff --git a/src/input/mpegts/satip/satip_rtsp.c b/src/input/mpegts/satip/satip_rtsp.c index cf6ed2a22..ae0b265cd 100644 --- a/src/input/mpegts/satip/satip_rtsp.c +++ b/src/input/mpegts/satip/satip_rtsp.c @@ -226,7 +226,7 @@ satip_rtsp_pids_strip( const char *s, int maxlen ) while (*s == ',') s++; while (strlen(s) > maxlen) { - ptr = rindex(s, ','); + ptr = strrchr(s, ','); if (ptr == NULL) abort(); *ptr = '\0'; diff --git a/src/main.c b/src/main.c index 16fb19ebd..3628ec8df 100644 --- a/src/main.c +++ b/src/main.c @@ -196,6 +196,7 @@ static int get_user_groups (const struct passwd *pw, gid_t* glist, size_t gmax) { int num = 0; +#if !ENABLE_ANDROID struct group *gr; char **mem; glist[num++] = pw->pw_gid; @@ -205,6 +206,7 @@ get_user_groups (const struct passwd *pw, gid_t* glist, size_t gmax) if(!strcmp(*mem, pw->pw_name)) glist[num++] = gr->gr_gid; } } +#endif return num; } diff --git a/src/muxer.c b/src/muxer.c index a359c7484..bf78b1e85 100644 --- a/src/muxer.c +++ b/src/muxer.c @@ -460,7 +460,7 @@ muxer_cache_update(muxer_t *m, int fd, off_t pos, size_t size) case MC_CACHE_DONTKEEP: #if defined(PLATFORM_DARWIN) fcntl(fd, F_NOCACHE, 1); -#else +#elseif !ENABLE_ANDROID posix_fadvise(fd, pos, size, POSIX_FADV_DONTNEED); #endif break; diff --git a/src/spawn.c b/src/spawn.c index 534e5af7e..b1bdacbf8 100644 --- a/src/spawn.c +++ b/src/spawn.c @@ -33,6 +33,10 @@ #include "file.h" #include "spawn.h" +#if ENABLE_ANDROID +#define WIFCONTINUED(s) ((s) == 0xffff) +#endif + extern char **environ; pthread_mutex_t spawn_mutex = PTHREAD_MUTEX_INITIALIZER; diff --git a/src/timeshift/timeshift_reader.c b/src/timeshift/timeshift_reader.c index a73d2df71..fb94957db 100644 --- a/src/timeshift/timeshift_reader.c +++ b/src/timeshift/timeshift_reader.c @@ -336,7 +336,7 @@ static int _timeshift_read tvhlog(LOG_ERR, "timeshift", "ts %d could not read buffer", ts->id); return -1; } - tvhtrace("timeshift", "ts %d read msg %p (%zd)", + tvhtrace("timeshift", "ts %d read msg %p (%ld)", ts->id, *sm, r); /* Incomplete */ diff --git a/src/tvheadend.h b/src/tvheadend.h index 020812b74..81c92c407 100644 --- a/src/tvheadend.h +++ b/src/tvheadend.h @@ -32,7 +32,7 @@ #include #include #include -#if ENABLE_LOCKOWNER +#if ENABLE_LOCKOWNER || ENABLE_ANDROID #include #endif @@ -46,6 +46,23 @@ #define ERRNO_AGAIN(e) ((e) == EAGAIN || (e) == EINTR || (e) == EWOULDBLOCK) +#if ENABLE_ANDROID +#define S_IEXEC S_IXUSR +#include +// 32-bit Android has only timegm64() and not timegm(). +// We replicate the behaviour of timegm() when the result overflows time_t. +static inline time_t timegm(struct tm* const t); +time_t timegm(struct tm* const t) { + // time_t is signed on Android. + static const time_t kTimeMax = ~(1L << (sizeof(time_t) * CHAR_BIT - 1)); + static const time_t kTimeMin = (1L << (sizeof(time_t) * CHAR_BIT - 1)); + time64_t result = timegm64(t); + if (result < kTimeMin || result > kTimeMax) + return -1; + return result; +} +#endif + typedef struct { const char *name; const uint32_t *enabled; diff --git a/src/tvhlog.h b/src/tvhlog.h index 06bb47326..f9c2d3256 100644 --- a/src/tvhlog.h +++ b/src/tvhlog.h @@ -19,7 +19,12 @@ #define __TVH_LOGGING_H__ #include +#include "build.h" +#if ENABLE_ANDROID +#include +#else #include +#endif #include #include diff --git a/src/tvhtime.c b/src/tvhtime.c index 589840af5..9bee7609f 100644 --- a/src/tvhtime.c +++ b/src/tvhtime.c @@ -2,7 +2,6 @@ #include #include -#include #include #include #include @@ -14,6 +13,10 @@ #include "tvheadend.h" #include "settings.h" +#if !ENABLE_ANDROID +#include +#endif + uint32_t tvhtime_update_enabled; uint32_t tvhtime_ntp_enabled; uint32_t tvhtime_tolerance; @@ -24,6 +27,7 @@ uint32_t tvhtime_tolerance; #define NTPD_BASE 0x4e545030 /* "NTP0" */ #define NTPD_UNIT 2 +#if !ENABLE_ANDROID typedef struct { int mode; /* 0 - if valid set @@ -72,6 +76,7 @@ ntp_shm_init ( void ) return shmptr; } +#endif /* * Update time @@ -79,6 +84,7 @@ ntp_shm_init ( void ) void tvhtime_update ( struct tm *tm ) { +#if !ENABLE_ANDROID time_t now; struct timeval tv; ntp_shm_t *ntp_shm; @@ -122,6 +128,7 @@ tvhtime_update ( struct tm *tm ) ntp_shm->count++; ntp_shm->valid = 1; } +#endif } /* Initialise */ diff --git a/src/upnp.c b/src/upnp.c index cdbf3533c..25713d099 100644 --- a/src/upnp.c +++ b/src/upnp.c @@ -39,6 +39,10 @@ #include #endif +#if ENABLE_ANDROID +#include +#endif + int upnp_running; static pthread_t upnp_tid; pthread_mutex_t upnp_lock; diff --git a/src/webui/webui.c b/src/webui/webui.c index 7e57ba473..071ac7504 100644 --- a/src/webui/webui.c +++ b/src/webui/webui.c @@ -55,6 +55,10 @@ #include #endif +#if ENABLE_ANDROID +#include +#endif + static int webui_xspf; /**