blob: 9c43d7ee7946d8ab2e524587578ffc55b98bd524 [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
philippeeeb07332012-07-04 21:59:29 +00005This is known to work at least for :
6 Android 4.0.3 running on a (rooted, AOSP build) Nexus S.
7 Android 4.0.3 running on Motorola Xoom.
8 Android 4.0.3 running on android emulator.
9
10Android 2.3.4 on Nexus S worked at some time in the past.
11It is known not to work on Android 4.1 running on android emulator.
12
13Other configurations and toolchains might work, but haven't been tested.
sewardj0a64a7a2012-02-17 15:13:55 +000014Feedback is welcome.
sewardj37ed97b2011-07-12 13:34:31 +000015
philippeeeb07332012-07-04 21:59:29 +000016
sewardj0a64a7a2012-02-17 15:13:55 +000017You need the android-ndk-r6 native development kit. r6b and r7
18give a non-completely-working build; see
19http://code.google.com/p/android/issues/detail?id=23203
philippeeeb07332012-07-04 21:59:29 +000020For the android emulator, the versions needed and how to
21install them are described in README.android_emulator.
sewardj0a64a7a2012-02-17 15:13:55 +000022
23Install it somewhere. Doesn't matter where. Then do this:
sewardj37ed97b2011-07-12 13:34:31 +000024
sewardj37ed97b2011-07-12 13:34:31 +000025
sewardjfb9c9622011-09-27 11:54:01 +000026# Modify this (obviously). Note, this "export" command is only done
27# so as to reduce the amount of typing required. None of the commands
28# below read it as part of their operation.
sewardj37ed97b2011-07-12 13:34:31 +000029#
sewardja0b4dbc2011-09-10 11:28:51 +000030export NDKROOT=/path/to/android-ndk-r6
sewardj37ed97b2011-07-12 13:34:31 +000031
sewardja0b4dbc2011-09-10 11:28:51 +000032
sewardjfb9c9622011-09-27 11:54:01 +000033# Modify this too. Tell the build system which Android hardware you
34# are building for. It needs to know this so it can compile in
35# support for the right Android-hw-specific ioctls. (sigh.) As with
36# NDKROOT above, this is merely to avoid repeated typing; none of the
37# commands read it.
sewardja0b4dbc2011-09-10 11:28:51 +000038#
sewardj1b3a7a42011-10-26 15:10:49 +000039# Currently the supported values are: nexus_s pandaboard
40# So choose one of the below:
sewardjfb9c9622011-09-27 11:54:01 +000041#
sewardj0a64a7a2012-02-17 15:13:55 +000042export HWKIND=nexus_s # Samsung Nexus S; also Xoom (for now)
sewardj1b3a7a42011-10-26 15:10:49 +000043export HWKIND=pandaboard # Pandaboard running Linaro Android
philippeeeb07332012-07-04 21:59:29 +000044export HWKIND=emulator # Android emulator
sewardja0b4dbc2011-09-10 11:28:51 +000045
46# Then cd to the root of your Valgrind source tree.
47#
48cd /path/to/valgrind/source/tree
49
50
sewardjfb9c9622011-09-27 11:54:01 +000051# After this point, you don't need to modify anything; just copy and
52# paste the commands below.
53
54
55# Set up toolchain paths.
56#
57export AR=$NDKROOT/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/arm-linux-androideabi-ar
58export LD=$NDKROOT/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/arm-linux-androideabi-ld
59export CC=$NDKROOT/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/arm-linux-androideabi-gcc
60
61
sewardja0b4dbc2011-09-10 11:28:51 +000062# Do configuration stuff. Don't mess with the --prefix in the
63# configure command below, even if you think it's wrong.
sewardjfb9c9622011-09-27 11:54:01 +000064# You may need to set the --with-tmpdir path to something
sewardj1b3a7a42011-10-26 15:10:49 +000065# different if /sdcard doesn't work on the device -- this is
sewardjfb9c9622011-09-27 11:54:01 +000066# a known cause of difficulties.
sewardja0b4dbc2011-09-10 11:28:51 +000067
sewardj37ed97b2011-07-12 13:34:31 +000068./autogen.sh
69
sewardjfb9c9622011-09-27 11:54:01 +000070CPPFLAGS="--sysroot=$NDKROOT/platforms/android-3/arch-arm -DANDROID_HARDWARE_$HWKIND" \
sewardja0b4dbc2011-09-10 11:28:51 +000071 CFLAGS="--sysroot=$NDKROOT/platforms/android-3/arch-arm" \
sewardj37ed97b2011-07-12 13:34:31 +000072 ./configure --prefix=/data/local/Inst \
73 --host=armv7-unknown-linux --target=armv7-unknown-linux \
sewardja0b4dbc2011-09-10 11:28:51 +000074 --with-tmpdir=/sdcard
philippeeeb07332012-07-04 21:59:29 +000075# note: on android emulator, android-14 platform was also tested and works.
76# It is not clear what this platform nr really is.
sewardj37ed97b2011-07-12 13:34:31 +000077
78# At the end of the configure run, a few lines of details
79# are printed. Make sure that you see these two lines:
80#
81# Platform variant: android
82# Primary -DVGPV string: -DVGPV_arm_linux_android=1
83#
84# If you see anything else at this point, something is wrong, and
85# either the build will fail, or will succeed but you'll get something
86# which won't work.
87
88
89# Build, and park the install tree in `pwd`/Inst
sewardja0b4dbc2011-09-10 11:28:51 +000090#
91make -j2
92make -j2 install DESTDIR=`pwd`/Inst
sewardj37ed97b2011-07-12 13:34:31 +000093
94
95# To get the install tree onto the device:
96# (I don't know why it's not "adb push Inst /data/local", but this
97# formulation does appear to put the result in /data/local/Inst.)
98#
99adb push Inst /
100
101# To run (on the device)
sewardja0b4dbc2011-09-10 11:28:51 +0000102/data/local/Inst/bin/valgrind [the usual args etc]
103
104
105# Once you're up and running, a handy modify-V-rebuild-reinstall
106# command line (on the host, of course) is
107#
108mq -j2 && mq -j2 install DESTDIR=`pwd`/Inst && adb push Inst /
109#
110# where 'mq' is an alias for 'make --quiet'.
111
112
113# One common cause of runs failing at startup is the inability of
114# Valgrind to find a suitable temporary directory. On the device,
115# there doesn't seem to be any one location which we always have
116# permission to write to. The instructions above use /sdcard. If
117# that doesn't work for you, and you're Valgrinding one specific
118# application which is already installed, you could try using its
119# temporary directory, in /data/data, for example
120# /data/data/org.mozilla.firefox_beta.
121#
122# Using /system/bin/logcat on the device is helpful for diagnosing
123# these kinds of problems.