blob: cf45bf71f3b5e8e3772a710ec998bd17e9daa934 [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#
sewardj1b3a7a42011-10-26 15:10:49 +000028# Currently the supported values are: nexus_s pandaboard
29# So choose one of the below:
sewardjfb9c9622011-09-27 11:54:01 +000030#
sewardjd13016b2011-10-13 16:11:58 +000031export HWKIND=nexus_s # Samsung Nexus S
sewardj1b3a7a42011-10-26 15:10:49 +000032export HWKIND=pandaboard # Pandaboard running Linaro Android
sewardja0b4dbc2011-09-10 11:28:51 +000033
34# Then cd to the root of your Valgrind source tree.
35#
36cd /path/to/valgrind/source/tree
37
38
sewardjfb9c9622011-09-27 11:54:01 +000039# After this point, you don't need to modify anything; just copy and
40# paste the commands below.
41
42
43# Set up toolchain paths.
44#
45export AR=$NDKROOT/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/arm-linux-androideabi-ar
46export LD=$NDKROOT/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/arm-linux-androideabi-ld
47export CC=$NDKROOT/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/arm-linux-androideabi-gcc
48
49
sewardja0b4dbc2011-09-10 11:28:51 +000050# Do configuration stuff. Don't mess with the --prefix in the
51# configure command below, even if you think it's wrong.
sewardjfb9c9622011-09-27 11:54:01 +000052# You may need to set the --with-tmpdir path to something
sewardj1b3a7a42011-10-26 15:10:49 +000053# different if /sdcard doesn't work on the device -- this is
sewardjfb9c9622011-09-27 11:54:01 +000054# a known cause of difficulties.
sewardja0b4dbc2011-09-10 11:28:51 +000055
sewardj37ed97b2011-07-12 13:34:31 +000056./autogen.sh
57
sewardjfb9c9622011-09-27 11:54:01 +000058CPPFLAGS="--sysroot=$NDKROOT/platforms/android-3/arch-arm -DANDROID_HARDWARE_$HWKIND" \
sewardja0b4dbc2011-09-10 11:28:51 +000059 CFLAGS="--sysroot=$NDKROOT/platforms/android-3/arch-arm" \
sewardj37ed97b2011-07-12 13:34:31 +000060 ./configure --prefix=/data/local/Inst \
61 --host=armv7-unknown-linux --target=armv7-unknown-linux \
sewardja0b4dbc2011-09-10 11:28:51 +000062 --with-tmpdir=/sdcard
sewardj37ed97b2011-07-12 13:34:31 +000063
64
65# At the end of the configure run, a few lines of details
66# are printed. Make sure that you see these two lines:
67#
68# Platform variant: android
69# Primary -DVGPV string: -DVGPV_arm_linux_android=1
70#
71# If you see anything else at this point, something is wrong, and
72# either the build will fail, or will succeed but you'll get something
73# which won't work.
74
75
76# Build, and park the install tree in `pwd`/Inst
sewardja0b4dbc2011-09-10 11:28:51 +000077#
78make -j2
79make -j2 install DESTDIR=`pwd`/Inst
sewardj37ed97b2011-07-12 13:34:31 +000080
81
82# To get the install tree onto the device:
83# (I don't know why it's not "adb push Inst /data/local", but this
84# formulation does appear to put the result in /data/local/Inst.)
85#
86adb push Inst /
87
88# To run (on the device)
sewardja0b4dbc2011-09-10 11:28:51 +000089/data/local/Inst/bin/valgrind [the usual args etc]
90
91
92# Once you're up and running, a handy modify-V-rebuild-reinstall
93# command line (on the host, of course) is
94#
95mq -j2 && mq -j2 install DESTDIR=`pwd`/Inst && adb push Inst /
96#
97# where 'mq' is an alias for 'make --quiet'.
98
99
100# One common cause of runs failing at startup is the inability of
101# Valgrind to find a suitable temporary directory. On the device,
102# there doesn't seem to be any one location which we always have
103# permission to write to. The instructions above use /sdcard. If
104# that doesn't work for you, and you're Valgrinding one specific
105# application which is already installed, you could try using its
106# temporary directory, in /data/data, for example
107# /data/data/org.mozilla.firefox_beta.
108#
109# Using /system/bin/logcat on the device is helpful for diagnosing
110# these kinds of problems.