blob: 3c2eba09a70242317aab2c6053dc39d7a3d7706d [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
sewardj0a64a7a2012-02-17 15:13:55 +0000317 Feb 2012, for Valgrind SVN revision 12390/2257.
sewardj37ed97b2011-07-12 13:34:31 +00004
sewardj0a64a7a2012-02-17 15:13:55 +00005This is known to work at least for Android 4.0.3 running on a (rooted,
6AOSP build) Nexus S and also on the same on Motorola Xoom. Android
72.3.4 on Nexus S worked at some time in the past. Other
8configurations and toolchains might work, but haven't been tested.
9Feedback is welcome.
sewardj37ed97b2011-07-12 13:34:31 +000010
sewardj0a64a7a2012-02-17 15:13:55 +000011You need the android-ndk-r6 native development kit. r6b and r7
12give a non-completely-working build; see
13http://code.google.com/p/android/issues/detail?id=23203
14
15Install it somewhere. Doesn't matter where. Then do this:
sewardj37ed97b2011-07-12 13:34:31 +000016
sewardj37ed97b2011-07-12 13:34:31 +000017
sewardjfb9c9622011-09-27 11:54:01 +000018# Modify this (obviously). Note, this "export" command is only done
19# so as to reduce the amount of typing required. None of the commands
20# below read it as part of their operation.
sewardj37ed97b2011-07-12 13:34:31 +000021#
sewardja0b4dbc2011-09-10 11:28:51 +000022export NDKROOT=/path/to/android-ndk-r6
sewardj37ed97b2011-07-12 13:34:31 +000023
sewardja0b4dbc2011-09-10 11:28:51 +000024
sewardjfb9c9622011-09-27 11:54:01 +000025# Modify this too. Tell the build system which Android hardware you
26# are building for. It needs to know this so it can compile in
27# support for the right Android-hw-specific ioctls. (sigh.) As with
28# NDKROOT above, this is merely to avoid repeated typing; none of the
29# commands read it.
sewardja0b4dbc2011-09-10 11:28:51 +000030#
sewardj1b3a7a42011-10-26 15:10:49 +000031# Currently the supported values are: nexus_s pandaboard
32# So choose one of the below:
sewardjfb9c9622011-09-27 11:54:01 +000033#
sewardj0a64a7a2012-02-17 15:13:55 +000034export HWKIND=nexus_s # Samsung Nexus S; also Xoom (for now)
sewardj1b3a7a42011-10-26 15:10:49 +000035export HWKIND=pandaboard # Pandaboard running Linaro Android
sewardja0b4dbc2011-09-10 11:28:51 +000036
37# Then cd to the root of your Valgrind source tree.
38#
39cd /path/to/valgrind/source/tree
40
41
sewardjfb9c9622011-09-27 11:54:01 +000042# After this point, you don't need to modify anything; just copy and
43# paste the commands below.
44
45
46# Set up toolchain paths.
47#
48export AR=$NDKROOT/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/arm-linux-androideabi-ar
49export LD=$NDKROOT/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/arm-linux-androideabi-ld
50export CC=$NDKROOT/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/arm-linux-androideabi-gcc
51
52
sewardja0b4dbc2011-09-10 11:28:51 +000053# Do configuration stuff. Don't mess with the --prefix in the
54# configure command below, even if you think it's wrong.
sewardjfb9c9622011-09-27 11:54:01 +000055# You may need to set the --with-tmpdir path to something
sewardj1b3a7a42011-10-26 15:10:49 +000056# different if /sdcard doesn't work on the device -- this is
sewardjfb9c9622011-09-27 11:54:01 +000057# a known cause of difficulties.
sewardja0b4dbc2011-09-10 11:28:51 +000058
sewardj37ed97b2011-07-12 13:34:31 +000059./autogen.sh
60
sewardjfb9c9622011-09-27 11:54:01 +000061CPPFLAGS="--sysroot=$NDKROOT/platforms/android-3/arch-arm -DANDROID_HARDWARE_$HWKIND" \
sewardja0b4dbc2011-09-10 11:28:51 +000062 CFLAGS="--sysroot=$NDKROOT/platforms/android-3/arch-arm" \
sewardj37ed97b2011-07-12 13:34:31 +000063 ./configure --prefix=/data/local/Inst \
64 --host=armv7-unknown-linux --target=armv7-unknown-linux \
sewardja0b4dbc2011-09-10 11:28:51 +000065 --with-tmpdir=/sdcard
sewardj37ed97b2011-07-12 13:34:31 +000066
67
68# At the end of the configure run, a few lines of details
69# are printed. Make sure that you see these two lines:
70#
71# Platform variant: android
72# Primary -DVGPV string: -DVGPV_arm_linux_android=1
73#
74# If you see anything else at this point, something is wrong, and
75# either the build will fail, or will succeed but you'll get something
76# which won't work.
77
78
79# Build, and park the install tree in `pwd`/Inst
sewardja0b4dbc2011-09-10 11:28:51 +000080#
81make -j2
82make -j2 install DESTDIR=`pwd`/Inst
sewardj37ed97b2011-07-12 13:34:31 +000083
84
85# To get the install tree onto the device:
86# (I don't know why it's not "adb push Inst /data/local", but this
87# formulation does appear to put the result in /data/local/Inst.)
88#
89adb push Inst /
90
91# To run (on the device)
sewardja0b4dbc2011-09-10 11:28:51 +000092/data/local/Inst/bin/valgrind [the usual args etc]
93
94
95# Once you're up and running, a handy modify-V-rebuild-reinstall
96# command line (on the host, of course) is
97#
98mq -j2 && mq -j2 install DESTDIR=`pwd`/Inst && adb push Inst /
99#
100# where 'mq' is an alias for 'make --quiet'.
101
102
103# One common cause of runs failing at startup is the inability of
104# Valgrind to find a suitable temporary directory. On the device,
105# there doesn't seem to be any one location which we always have
106# permission to write to. The instructions above use /sdcard. If
107# that doesn't work for you, and you're Valgrinding one specific
108# application which is already installed, you could try using its
109# temporary directory, in /data/data, for example
110# /data/data/org.mozilla.firefox_beta.
111#
112# Using /system/bin/logcat on the device is helpful for diagnosing
113# these kinds of problems.