android编译avahi
1、下载android的ndk与sdk。自己网上找下。
我用的NDK为android-ndk-r15c
2、生成工具链
$NDK/build/tools/make-standalone-toolchain.sh --arch=arm --platform=android-21 --install-dir=/home/suka
arch、install-dir与platform根据实际选。$NDK为NDK的目录
3、下载xbmc并切换到avahi分支
git clone https://github.com/theuni/xbmc.git
git checkout remotes/origin/android-avahi
git checkout -b android-avahi
cd xbmc/tools/android/depends
4、修改configure.in,找到zipalign,修成对应sdk的zipalign路径如:
if [ ! test -f $use_sdk/build-tools/27.0.3/zipalign ]; then
5、修改Makefile.in的SUBDIRS ,只编译我们需要的:
SUBDIRS = \
expat libcap dbus libcap libdaemon avahi
6、修改Makefile.include.in ,修改gcc与g++
export CC=$(CROSSTOOLS)clang
export CXX=$(CROSSTOOLS)clang++
7、autoconf版本换高的。修改autoconf/Makefile
VERSION=2.69
8、automake版本换高的。修改 automake/Makefile
VERSION=1.15
SOURCE=$(LIBNAME)-$(VERSION)
ARCHIVE=$(SOURCE).tar.gz
BASE_URL=https://ftp.gnu.org/gnu/automake/
9、修改avahi/glob.patch,加减反一下,如下
+ sd-daemon.h sd-daemon.c glob.c \
- sd-daemon.h sd-daemon.c \
10、修改avahi/0001-Add-Android-support.patch,注释掉in6_pktinfo
+#if 0 //def __BIONIC__
+struct in6_pktinfo {
+ struct in6_addr ipi6_addr;
+ int ipi6_ifindex;
+};
+#endif
修改avahi/0001-Add-Android-support.patch, sys/_types.h改<sys/types.h>
+#include <sys/types.h>
修改avahi/0001-Add-Android-support.patch,注释掉size_t
+#if 0//ndef _SIZE_T_DECLARED
+typedef __size_t size_t;
+#define _SIZE_T_DECLARED
+#endif
修改avahi/0001-Add-Android-support.patch,释放GLOB_ERR定义
+#if 1//__POSIX_VISIBLE >= 199209
+/* Believed to have been introduced in 1003.2-1992 */
+#define GLOB_APPEND 0x0001 /* Append to output from previous call. */
+#define GLOB_DOOFFS 0x0002 /* Use gl_offs. */
修改avahi/0001-Add-Android-support.patch,释放GLOB_LIMIT定义
+#if 1// __BSD_VISIBLE
+#define GLOB_ALTDIRFUNC 0x0040 /* Use alternately specified directory funcs. */
+#define GLOB_BRACE 0x0080 /* Expand braces ala csh. */
修改avahi/0001-Add-Android-support.patch,将ARG_MAX替换为
limit = sysconf(_SC_ARG_MAX);
删除掉issetugid的调用
issetugid() != 0 ||
11、修改avahi/Makefile,增加版本
VERSION=0.6.32
CONFIGURE增加
--disable-glib \
--disable-gobject \
--enable-compat-libdns_sd \
LIBS="-llog -lc" \
CFLAGS="-pie -fPIE" \
同时删除--disable-shared
12、修改dbus/Makefile,换高版本,如下
include ../Makefile.include
DEPS= ../Makefile.include Makefile
# lib name, version
LIBNAME=dbus
VERSION=1.13.4
SOURCE=$(LIBNAME)-$(VERSION)
ARCHIVE=$(SOURCE).tar.gz
BASE_URL=http://dbus.freedesktop.org/releases/dbus
# configuration settings
CONFIGURE=cp -f $(CONFIG_SUB) $(CONFIG_GUESS) .; \
./configure --prefix=$(PREFIX) --host=$(HOST) \
--without-x --disable-xml-docs --disable-doxygen-docs \
--with-dbus-user=root CFLAGS="-pie -fPIE" \
LIBDYLIB=$(PLATFORM)/$(LIBNAME)/.libs/libdbus-1.a
CLEAN_FILES=$(ARCHIVE) $(PLATFORM)
all: .installed-$(PLATFORM)
$(TARBALLS_LOCATION)/$(ARCHIVE):
$(RETRIEVE_TOOL) $(RETRIEVE_TOOL_FLAGS) $(BASE_URL)/$(ARCHIVE)
$(PLATFORM): $(TARBALLS_LOCATION)/$(ARCHIVE) $(DEPS)
rm -rf $(PLATFORM)/*; mkdir -p $(PLATFORM)
$(ARCHIVE_TOOL) $(ARCHIVE_TOOL_FLAGS) $(TARBALLS_LOCATION)/$(ARCHIVE)
#cd $(PLATFORM); patch -p1 < ../android-upstream.patch
#cd $(PLATFORM); patch -p1 < ../android.patch
cd $(PLATFORM); $(CONFIGURE)
$(LIBDYLIB): $(PLATFORM)
sed -i "/^#define HAVE_POSIX_GETPWNAM_R/d" $(PLATFORM)/config.h
$(MAKE) -C $(PLATFORM)/
.installed-$(PLATFORM): $(LIBDYLIB)
$(MAKE) -C $(PLATFORM)/ install
cp $(PLATFORM)/dbus-1.pc $(PKG_CONFIG_PATH)
touch $@
clean:
$(MAKE) -C $(PLATFORM) clean
rm -f .installed-$(PLATFORM)
distclean::
rm -rf $(PLATFORM) .installed-$(PLATFORM)
13、修改expat/Makefile,增加版本
VERSION=2.2.5
SOURCE=$(LIBNAME)-$(VERSION)
ARCHIVE=$(SOURCE).tar.bz2
BASE_URL=https://jaist.dl.sourceforge.net/project/expat/expat/2.2.5
14、生成configure 并执行
./bootstrap
./configure --prefix=/etc/android --host=arm-linux-androideabi \
--with-ndk=/home/suka/android-ndk-r15c --with-sdk=/home/suka/android-sdk-linux \
--with-sdk-platform=android-21 --with-tarballs=pack --with-toolchain=/home/suka/arm-linux-androideabi --with-staging=/etc/android \
CC=/home/suka/arm-linux-androideabi/bin/clang CFLAGS="-pie -fPIE"
其中,prefix与with-staging要和安卓的目录一致。with-sdk-platform为要用的sdk版本
15、创建libcap目录,里面增加Makefile,内容如下
include ../Makefile.include
DEPS= ../Makefile.include
# lib name, version
LIBNAME=libcap
VERSION=2.25
SOURCE=$(LIBNAME)-$(VERSION)
ARCHIVE=$(SOURCE).tar.gz
BASE_URL=https://mirrors.edge.kernel.org/pub/linux/libs/security/linux-privs/libcap2
# configuration settings
CONFIGURE=cp -f $(CONFIG_SUB) $(CONFIG_GUESS) .; \
./configure --prefix=$(PREFIX) --host=$(HOST) --without-cd-drive --without-cd-info --without-cd-paranoia \
--without-cdda-player --without-cd-read --without-iso-info --without-iso-read --disable-example-progs \
--disable-cpp-progs --without-cd-drive --without-cd-info --without-cd-paranoia --without-cdda-player \
--without-cd-read --without-iso-info --without-iso-read --disable-shared
LIBDYLIB=$(PLATFORM)/lib/driver/.libs/$(LIBNAME).a
CLEAN_FILES=$(ARCHIVE) $(PLATFORM)
all: .installed-$(PLATFORM)
$(TARBALLS_LOCATION)/$(ARCHIVE):
$(RETRIEVE_TOOL) $(RETRIEVE_TOOL_FLAGS) $(BASE_URL)/$(ARCHIVE)
$(PLATFORM): $(TARBALLS_LOCATION)/$(ARCHIVE) $(DEPS)
rm -rf $(PLATFORM)/*; mkdir -p $(PLATFORM)
$(ARCHIVE_TOOL) $(ARCHIVE_TOOL_FLAGS) $(TARBALLS_LOCATION)/$(ARCHIVE)
sed -i "s/-\/sbin\/ldconfig//" $(PLATFORM)/libcap/Makefile
$(LIBDYLIB): $(PLATFORM)
$(MAKE) -C $(PLATFORM)/libcap lib=lib prefix=$(PREFIX) CC=$(CC)
.installed-$(PLATFORM): $(LIBDYLIB)
$(MAKE) -C $(PLATFORM)/libcap install lib=lib prefix=$(PREFIX) CC=$(CC)
touch $@
clean:
$(MAKE) -C $(PLATFORM)/libcap clean
rm -f .installed-$(PLATFORM)
进入libcap,执行make.
如出现下面错误
./_makenames: 1: ./_makenames: Syntax error: word unexpected (expecting ")")
修改armeabi-v7a/libcap/Makefile
把
_makenames: _makenames.c cap_names.list.h
$(BUILD_CC) $(BUILD_CFLAGS) $< -o $@
改成
_makenames: _makenames.c cap_names.list.h
gcc $(BUILD_CFLAGS) $< -o $@
16、退到depends执行make
make
17、生成的/etc/android/armeabi-v7a,都上传到系统中。
在安卓上,运行
mkdir -p /etc/android/armeabi-v7a/var/run/dbus
dbus-daemon --system &
avahi-daemon --no-chroot &