blob: f2a41dc771ad199d270673fceae9ee02c1c122fc [file] [log] [blame]
sewardj37ed97b2011-07-12 13:34:31 +00001
sewardjfb9c9622011-09-27 11:54:01 +00002How to cross-compile for Android. These notes were last updated on
327 Sept 2011, for Valgrind SVN revision 12060/2209.
sewardj37ed97b2011-07-12 13:34:31 +00004
sewardja0b4dbc2011-09-10 11:28:51 +00005This is known to work at least for Android 2.3.4 running on a (rooted,
6AOSP build) Nexus S. It has also worked in the past on a
7un-messed-with Motorola Xoom, although I haven't tested it recently.
8Other configurations and toolchains might work, but haven't been
9tested. Feedback is welcome.
sewardj37ed97b2011-07-12 13:34:31 +000010
sewardja0b4dbc2011-09-10 11:28:51 +000011You need the android-ndk-r6 native development kit. Install it
sewardjfb9c9622011-09-27 11:54:01 +000012somewhere. Doesn't matter where. Then do this:
sewardj37ed97b2011-07-12 13:34:31 +000013
sewardj37ed97b2011-07-12 13:34:31 +000014
sewardjfb9c9622011-09-27 11:54:01 +000015# Modify this (obviously). Note, this "export" command is only done
16# so as to reduce the amount of typing required. None of the commands
17# below read it as part of their operation.
sewardj37ed97b2011-07-12 13:34:31 +000018#
sewardja0b4dbc2011-09-10 11:28:51 +000019export NDKROOT=/path/to/android-ndk-r6
sewardj37ed97b2011-07-12 13:34:31 +000020
sewardja0b4dbc2011-09-10 11:28:51 +000021
sewardjfb9c9622011-09-27 11:54:01 +000022# Modify this too. Tell the build system which Android hardware you
23# are building for. It needs to know this so it can compile in
24# support for the right Android-hw-specific ioctls. (sigh.) As with
25# NDKROOT above, this is merely to avoid repeated typing; none of the
26# commands read it.
sewardja0b4dbc2011-09-10 11:28:51 +000027#
sewardjfb9c9622011-09-27 11:54:01 +000028# Currently the only supported value is: nexus_s
29#
30export HWKIND=nexus_t # Samsung Nexus S
sewardja0b4dbc2011-09-10 11:28:51 +000031
32
33# Then cd to the root of your Valgrind source tree.
34#
35cd /path/to/valgrind/source/tree
36
37
sewardjfb9c9622011-09-27 11:54:01 +000038# After this point, you don't need to modify anything; just copy and
39# paste the commands below.
40
41
42# Set up toolchain paths.
43#
44export AR=$NDKROOT/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/arm-linux-androideabi-ar
45export LD=$NDKROOT/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/arm-linux-androideabi-ld
46export CC=$NDKROOT/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/arm-linux-androideabi-gcc
47
48
sewardja0b4dbc2011-09-10 11:28:51 +000049# Do configuration stuff. Don't mess with the --prefix in the
50# configure command below, even if you think it's wrong.
sewardjfb9c9622011-09-27 11:54:01 +000051# You may need to set the --with-tmpdir path to something
52# different if /sdcard doesn't works on the device -- this is
53# a known cause of difficulties.
sewardja0b4dbc2011-09-10 11:28:51 +000054
sewardj37ed97b2011-07-12 13:34:31 +000055./autogen.sh
56
sewardjfb9c9622011-09-27 11:54:01 +000057CPPFLAGS="--sysroot=$NDKROOT/platforms/android-3/arch-arm -DANDROID_HARDWARE_$HWKIND" \
sewardja0b4dbc2011-09-10 11:28:51 +000058 CFLAGS="--sysroot=$NDKROOT/platforms/android-3/arch-arm" \
sewardj37ed97b2011-07-12 13:34:31 +000059 ./configure --prefix=/data/local/Inst \
60 --host=armv7-unknown-linux --target=armv7-unknown-linux \
sewardja0b4dbc2011-09-10 11:28:51 +000061 --with-tmpdir=/sdcard
sewardj37ed97b2011-07-12 13:34:31 +000062
63
64# At the end of the configure run, a few lines of details
65# are printed. Make sure that you see these two lines:
66#
67# Platform variant: android
68# Primary -DVGPV string: -DVGPV_arm_linux_android=1
69#
70# If you see anything else at this point, something is wrong, and
71# either the build will fail, or will succeed but you'll get something
72# which won't work.
73
74
75# Build, and park the install tree in `pwd`/Inst
sewardja0b4dbc2011-09-10 11:28:51 +000076#
77make -j2
78make -j2 install DESTDIR=`pwd`/Inst
sewardj37ed97b2011-07-12 13:34:31 +000079
80
81# To get the install tree onto the device:
82# (I don't know why it's not "adb push Inst /data/local", but this
83# formulation does appear to put the result in /data/local/Inst.)
84#
85adb push Inst /
86
87# To run (on the device)
sewardja0b4dbc2011-09-10 11:28:51 +000088/data/local/Inst/bin/valgrind [the usual args etc]
89
90
91# Once you're up and running, a handy modify-V-rebuild-reinstall
92# command line (on the host, of course) is
93#
94mq -j2 && mq -j2 install DESTDIR=`pwd`/Inst && adb push Inst /
95#
96# where 'mq' is an alias for 'make --quiet'.
97
98
99# One common cause of runs failing at startup is the inability of
100# Valgrind to find a suitable temporary directory. On the device,
101# there doesn't seem to be any one location which we always have
102# permission to write to. The instructions above use /sdcard. If
103# that doesn't work for you, and you're Valgrinding one specific
104# application which is already installed, you could try using its
105# temporary directory, in /data/data, for example
106# /data/data/org.mozilla.firefox_beta.
107#
108# Using /system/bin/logcat on the device is helpful for diagnosing
109# these kinds of problems.