弁財天

ゴフマン「専門家を信じるのではなく、自分自身で考えて判断せよ」

Android NDKでprivoxyをビルド

Fwd: Getting parental controls working on Android using NDK (dansguardian + privoxy)

Be interested if anyone else can get it working on some other device
<<
Download and install NDK from http://developer.android.com/sdk/ndk/index.html

**Create toolchain
cd to where NDK in installed and run
./build/tools/make-standalone-toolchain.sh --platform=android-8 --
install-dir=android-8-toolchain
Add #NDK_PATH#/android-8-toolchain/bin to your PATH

cd ..
mkdir projects/external
cd projects/external

**Build privoxy
wget http://sourceforge.net/projects/ijbswa/files/Sources/3.0.12%20%28stable%29/privoxy-3.0.12-stable-src.tar.gz
tar xzvf privoxy-3.0.12-stable-src.tar.gz
cd privoxy-3.0.12-stable
autoheader
autoconf
edit configure and comment out
   #PTHREAD_LIB=-lpthread
./configure CC=arm-linux-androideabi-gcc LD=arm-linux-androideabi-ld
ac_cv_func_setpgrp_void=yes --host=arm-linux
make
upload privoxy and config to your android device


AndroidのバージョンとAPIレベルの対応関係

Androidのプラットフォームのバージョンと、それに対応するAPIレベルについて、下表にまとめます。

プラットフォーム APIレベル コードネーム 公開日
Android 1.0 1 Base 2008/09/23
Android 1.1 2 Base 1_1 2009/02/09
Android 1.5 3 Cupcake 2009/04/30
Android 1.6 4 Donut 2009/09/15
Android 2.0 5 Eclair 2009/10/26
Android 2.0.1 6 Eclair 0_1 2009/12/03
Android 2.1.x 7 Eclair MR1 2010/01/12
Android 2.2.x 8 Froyo 2010/05/20
Android 2.3 9 Gingerbread 2010/12/06
Android 2.3.1
Android 2.3.2
Android 2.3.3 10 Gingerbread MR1 2011/02/09
Android 2.3.4
Android 3.0.x 11 Honeycomb 2011/02/22
Android 3.1.x 12 Honeycomb MR1 2011/05/10
Android 3.2 13 Honeycomb MR2 2011/07/15
Android 4.0 14 Ice Cream Sandwich 2011/10/19
Android 4.0.1
Android 4.0.2
Android 4.0.3 15 Ice Cream Sandwich MR1 2011/12/16
Android 4.1 16 Jelly Bean 2012/07/09
Android 4.1.1
Android 4.2 17 Jelly Bean MR1 2012/12/13
Android 4.2.2
Android 4.3 18 Jelly Bean MR2 2013/07/24
Android 4.4 19 KitKat 2013/10/31
Android 5.0 21 Lollipop 2014/11/12
Android version history - Wikipedia, the free encyclopedia

# uname -a
Linux localhost 3.10.20-x86_64_moor-gea7d143 #1 SMP PREEMPT Wed May 6 17:35:47 CST 2015 x86_64 GNU/Linux
ふーん。じゃぁZenPhone2はAndroid5.0だからandroid-21だな。

$ cat create_sysroot.sh
#!/bin/sh

ANDROID_NDK=/somewhere/android-ndk-r10d
TARGETARCH=x86
#TARGET_TOOLCHAIN=x86_64-4.9 # x86_64はダメだったw
TARGET_TOOLCHAIN=x86-4.9

ANDROID_TOOLCHAIN=/somewhere/ZenPhone2-toolchain-$TARGETARCH
SYSROOT=$ANDROID_TOOLCHAIN/sysroot

$ANDROID_NDK/build/tools/make-standalone-toolchain.sh \
 --platform=android-21 \
 --install-dir=$ANDROID_TOOLCHAIN \
 --system=linux-x86_64 \
 --toolchain=$TARGET_TOOLCHAIN
$ 
--system=linux-x86_64はクロスコンパイルシステムを指定?
Fedora21のx86_64なので--system=linux-x86_64かなみたいなw
同じx86_64環境なのにクロスコンパイルするとゆー。
$ sh create_sysroot.sh
Copying prebuilt binaries...
Copying sysroot headers and libraries...
Copying c++ runtime headers and libraries...
Copying files to: /somewhere/ZenPhone2-toolchain-x86
Cleaning up...
Done.
$ 

configure

$ ./configure CC=i686-linux-android-gcc LD=i686-linux-android-ld LDFLAGS="-pie -fPIE" ac_cv_func_setpgrp_void=yes --host=i686-linux
checking build system type... x86_64-unknown-linux-gnu
checking host system type... i686-pc-linux-gnu
checking for i686-linux-gcc... i686-linux-android-gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... yes
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether i686-linux-android-gcc accepts -g... yes
checking for i686-linux-android-gcc option to accept ISO C89... none needed
checking how to run the C preprocessor... i686-linux-android-gcc -E
checking for a BSD-compatible install... /usr/bin/install -c
checking whether ln -s works... yes
checking whether make sets $(MAKE)... yes
checking for gawk... gawk
略
checking for pcre_compile in -lpcre... no
checking for regcomp in -lpcreposix... no
checking for zlibVersion in -lz... yes
configure: WARNING: You are using the static PCRE code which is out of date and scheduled for removal, for details see:
    http://sourceforge.net/mailarchive/forum.php?thread_name=20080511195555.2dc6cfdc%40fabiankeil.de&forum_name=ijbswa-developers
Enabling connection-sharing support.
configure: creating ./config.status
config.status: creating GNUmakefile
config.status: creating doc/source/ldp.dsl
config.status: creating config.h
config.status: config.h is unchanged
$ 
x86_64-linux-android-gcc -c -pipe -O2   -pthread -Wall -Ipcre  filters.c -o filters.o
In file included from /somewhere/ZenPhone2-toolchain-x86_64/sysroot/usr/include/netinet/in.h:32:0,
                 from filters.c:49:
Cross-compiling a MPICH library for Android NDK
The Android NDK does not define or use in_port_t, but instead uses unsigned short int. To compile code using the Android NDK, either typedef in_port_t or replace it with unsigned short int.
project.h
/* Need for struct sockaddr_storage */
#ifdef HAVE_RFC2553
#  ifndef _WIN32
#    include 
#    include 
#  else
#    include 
#    include 
#    include 
     typedef unsigned short in_port_t;
#  endif
#endif

typedef unsigned short int in_port_t; /* ここにアグリーパッチw */

make
$ make
i686-linux-android-gcc -c -pipe -O2   -pthread -Wall -Ipcre  actions.c -o actions.o
i686-linux-android-gcc -c -pipe -O2   -pthread -Wall -Ipcre  cgi.c -o cgi.o
i686-linux-android-gcc -c -pipe -O2   -pthread -Wall -Ipcre  cgiedit.c -o cgiedit.o
i686-linux-android-gcc -c -pipe -O2   -pthread -Wall -Ipcre  cgisimple.c -o cgisimple.o
i686-linux-android-gcc -c -pipe -O2   -pthread -Wall -Ipcre  deanimate.c -o deanimate.o
i686-linux-android-gcc -c -pipe -O2   -pthread -Wall -Ipcre  encode.c -o encode.o
i686-linux-android-gcc -c -pipe -O2   -pthread -Wall -Ipcre  errlog.c -o errlog.o
i686-linux-android-gcc -c -pipe -O2   -pthread -Wall -Ipcre  filters.c -o filters.o
In file included from /somewhere/ZenPhone2-toolchain-x86/sysroot/usr/include/netinet/in.h:32:0,
                 from filters.c:49:
filters.c: In function 'match_sockaddr':
filters.c:190:39: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
       && IN6_IS_ADDR_V4MAPPED((struct in6_addr *)address_addr))
                                       ^
filters.c:190:39: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
       && IN6_IS_ADDR_V4MAPPED((struct in6_addr *)address_addr))
                                       ^
filters.c:190:39: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
       && IN6_IS_ADDR_V4MAPPED((struct in6_addr *)address_addr))
                                       ^
filters.c:197:39: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
       && IN6_IS_ADDR_V4MAPPED((struct in6_addr *)network_addr))
                                       ^
filters.c:197:39: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
       && IN6_IS_ADDR_V4MAPPED((struct in6_addr *)network_addr))
                                       ^
filters.c:197:39: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
       && IN6_IS_ADDR_V4MAPPED((struct in6_addr *)network_addr))
                                       ^
filters.c:206:42: warning: 'address_port' may be used uninitialized in this function [-Wmaybe-uninitialized]
    if (*netmask_port && *network_port != *address_port)
                                          ^
filters.c:215:24: warning: 'address_addr' may be used uninitialized in this function [-Wmaybe-uninitialized]
           (address_addr[i] & netmask_addr[i]))
                        ^
filters.c:214:24: warning: 'network_addr' may be used uninitialized in this function [-Wmaybe-uninitialized]
       if ((network_addr[i] & netmask_addr[i]) !=
                        ^
filters.c:212:46: warning: 'netmask_addr' may be used uninitialized in this function [-Wmaybe-uninitialized]
    for (i = 0; (i < addr_len) && netmask_addr[i]; i++)
                                              ^
filters.c:173:17: warning: 'addr_len' may be used uninitialized in this function [-Wmaybe-uninitialized]
    unsigned int addr_len;
                 ^
filters.c:206:25: warning: 'network_port' may be used uninitialized in this function [-Wmaybe-uninitialized]
    if (*netmask_port && *network_port != *address_port)
                         ^
filters.c:206:8: warning: 'netmask_port' may be used uninitialized in this function [-Wmaybe-uninitialized]
    if (*netmask_port && *network_port != *address_port)
        ^
i686-linux-android-gcc -c -pipe -O2   -pthread -Wall -Ipcre  gateway.c -o gateway.o
i686-linux-android-gcc -c -pipe -O2   -pthread -Wall -Ipcre  jbsockets.c -o jbsockets.o
i686-linux-android-gcc -c -pipe -O2   -pthread -Wall -Ipcre  jcc.c -o jcc.o
i686-linux-android-gcc -c -pipe -O2   -pthread -Wall -Ipcre  list.c -o list.o
i686-linux-android-gcc -c -pipe -O2   -pthread -Wall -Ipcre  loadcfg.c -o loadcfg.o
i686-linux-android-gcc -c -pipe -O2   -pthread -Wall -Ipcre  loaders.c -o loaders.o
i686-linux-android-gcc -c -pipe -O2   -pthread -Wall -Ipcre  miscutil.c -o miscutil.o
i686-linux-android-gcc -c -pipe -O2   -pthread -Wall -Ipcre  parsers.c -o parsers.o
i686-linux-android-gcc -c -pipe -O2   -pthread -Wall -Ipcre  ssplit.c -o ssplit.o
i686-linux-android-gcc -c -pipe -O2   -pthread -Wall -Ipcre  urlmatch.c -o urlmatch.o
i686-linux-android-gcc -c -pipe -O2   -pthread -Wall -Ipcre  pcrs.c -o pcrs.o
i686-linux-android-gcc -c -pipe -O2   -pthread -Wall -Ipcre  pcre/get.c -o pcre/get.o
i686-linux-android-gcc -c -pipe -O2   -pthread -Wall -Ipcre  pcre/maketables.c -o pcre/maketables.o
i686-linux-android-gcc -c -pipe -O2   -pthread -Wall -Ipcre  pcre/study.c -o pcre/study.o
pcre/study.c: In function 'set_start_bits':
pcre/study.c:98:14: warning: variable 'dummy' set but not used [-Wunused-but-set-variable]
 volatile int dummy;
              ^
i686-linux-android-gcc -c -pipe -O2   -pthread -Wall -Ipcre  pcre/pcre.c -o pcre/pcre.o
i686-linux-android-gcc -c -pipe -O2   -pthread -Wall -Ipcre  pcre/pcreposix.c -o pcre/pcreposix.o
i686-linux-android-gcc -pie -fPIE  -pthread -o privoxy actions.o cgi.o cgiedit.o cgisimple.o deanimate.o encode.o errlog.o filters.o gateway.o jbsockets.o jcc.o list.o loadcfg.o loaders.o miscutil.o parsers.o ssplit.o urlmatch.o  pcrs.o pcre/get.o pcre/maketables.o pcre/study.o pcre/pcre.o pcre/pcreposix.o -lz   
grep -v '^#MASTER#' default.action.master > default.action
$ 
あ、でけた。

error: only position independent executables (PIE) are supported.
[参考]Android 5.0 Lollipopで32bit ARMバイナリが動かない
LDFLAGS="-pie -fPIE"がいるみたいだ。

export PATH=/somewhere/ZenPhone2-toolchain-x86/bin:$PATH
./configure CC=i686-linux-android-gcc LD=i686-linux-android-ld LDFLAGS="-pie -fPIE" ac_cv_func_setpgrp_void=yes --host=i686-linux

adbで適当な場所にpush

$ adb push privoxy /mnt/sdcard/somewhere/privoxy
7079 KB/s (414468 bytes in 0.057s)
$ 
でけとーな場所にコピー。
root@Z00A:/somewhere # cp /mnt/sdcard/somewhere/privoxy /data/loca/bin/privoxy
root@Z00A:/somewhere # chmod755 /data/loca/bin/privoxy
root@Z00A:/somewhere # cd /data/local/bin
root@Z00A:/data/local/bin # ./privoxy
tmp-mksh: ./privoxy: No such file or directory
1|root@Z00A:/data/local/bin #
あ?x86_64のバイナリて動かないw
しょーがねーなー。やっぱi686にクロスコンパイルしないとダメなんだろ。
i686でリビルド。
$ ./configure CC=i686-linux-android-gcc LD=i686-linux-android-ld LDFLAGS="-pie -fPIE" ac_cv_func_setpgrp_void=yes --host=i686-linux
上と同じ作業。
/data/local/bin/privoxy --no-daemon /storage/MicroSD/gscript/privoxy/config
2015-05-14 08:40:30.624 f771e160 Info: Privoxy version 3.0.23
2015-05-14 08:40:30.626 f771e160 Info: Program name: /data/local/bin/privoxy
あ、ふつうに動いた。

投稿されたコメント:

コメント
コメントは無効になっています。