blob: 138f64487220019bffeb752972c410ffd26d1370 [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 :
philippe5d5dd8e2012-08-05 00:08:25 +00006ARM:
philippeeeb07332012-07-04 21:59:29 +00007 Android 4.0.3 running on a (rooted, AOSP build) Nexus S.
8 Android 4.0.3 running on Motorola Xoom.
philippe5d5dd8e2012-08-05 00:08:25 +00009 Android 4.0.3 running on android arm emulator.
philippe77c11852012-07-18 23:01:02 +000010 Android 4.1 running on android emulator.
sewardjca456c72012-08-05 13:44:15 +000011 Android 2.3.4 on Nexus S worked at some time in the past.
philippe77c11852012-07-18 23:01:02 +000012
philippe5d5dd8e2012-08-05 00:08:25 +000013x86:
philippe5d5dd8e2012-08-05 00:08:25 +000014 Android 4.0.3 running on android x86 emulator.
15
sewardjca456c72012-08-05 13:44:15 +000016On android-arm, GDBserver might insert breaks at wrong addresses.
philippe77c11852012-07-18 23:01:02 +000017Feedback on this welcome.
philippeeeb07332012-07-04 21:59:29 +000018
19Other configurations and toolchains might work, but haven't been tested.
sewardj0a64a7a2012-02-17 15:13:55 +000020Feedback is welcome.
sewardj37ed97b2011-07-12 13:34:31 +000021
philippeeeb07332012-07-04 21:59:29 +000022
sewardj0a64a7a2012-02-17 15:13:55 +000023You need the android-ndk-r6 native development kit. r6b and r7
24give a non-completely-working build; see
25http://code.google.com/p/android/issues/detail?id=23203
philippeeeb07332012-07-04 21:59:29 +000026For the android emulator, the versions needed and how to
27install them are described in README.android_emulator.
sewardj0a64a7a2012-02-17 15:13:55 +000028
29Install it somewhere. Doesn't matter where. Then do this:
sewardj37ed97b2011-07-12 13:34:31 +000030
sewardj37ed97b2011-07-12 13:34:31 +000031
sewardjfb9c9622011-09-27 11:54:01 +000032# Modify this (obviously). Note, this "export" command is only done
33# so as to reduce the amount of typing required. None of the commands
34# below read it as part of their operation.
sewardj37ed97b2011-07-12 13:34:31 +000035#
sewardja0b4dbc2011-09-10 11:28:51 +000036export NDKROOT=/path/to/android-ndk-r6
sewardj37ed97b2011-07-12 13:34:31 +000037
sewardja0b4dbc2011-09-10 11:28:51 +000038
sewardjfb9c9622011-09-27 11:54:01 +000039# Modify this too. Tell the build system which Android hardware you
40# are building for. It needs to know this so it can compile in
41# support for the right Android-hw-specific ioctls. (sigh.) As with
42# NDKROOT above, this is merely to avoid repeated typing; none of the
43# commands read it.
sewardja0b4dbc2011-09-10 11:28:51 +000044#
sewardj1b3a7a42011-10-26 15:10:49 +000045# Currently the supported values are: nexus_s pandaboard
46# So choose one of the below:
sewardjfb9c9622011-09-27 11:54:01 +000047#
sewardj0a64a7a2012-02-17 15:13:55 +000048export HWKIND=nexus_s # Samsung Nexus S; also Xoom (for now)
philippe5d5dd8e2012-08-05 00:08:25 +000049export HWKIND=generic # A generic Android device. eg, Pandaboard
philippeeeb07332012-07-04 21:59:29 +000050export HWKIND=emulator # Android emulator
sewardja0b4dbc2011-09-10 11:28:51 +000051
52# Then cd to the root of your Valgrind source tree.
53#
54cd /path/to/valgrind/source/tree
55
56
sewardjfb9c9622011-09-27 11:54:01 +000057# After this point, you don't need to modify anything; just copy and
58# paste the commands below.
59
60
61# Set up toolchain paths.
62#
sewardjca456c72012-08-05 13:44:15 +000063# For ARM
sewardjfb9c9622011-09-27 11:54:01 +000064export AR=$NDKROOT/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/arm-linux-androideabi-ar
65export LD=$NDKROOT/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/arm-linux-androideabi-ld
66export CC=$NDKROOT/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/arm-linux-androideabi-gcc
67
sewardjca456c72012-08-05 13:44:15 +000068# For x86
philippe5d5dd8e2012-08-05 00:08:25 +000069export AR=$NDKROOT/toolchains/x86-4.4.3/prebuilt/linux-x86/bin/i686-android-linux-ar
70export LD=$NDKROOT/toolchains/x86-4.4.3/prebuilt/linux-x86/bin/i686-android-linux-ld
71export CC=$NDKROOT/toolchains/x86-4.4.3/prebuilt/linux-x86/bin/i686-android-linux-gcc
72
sewardjfb9c9622011-09-27 11:54:01 +000073
sewardja0b4dbc2011-09-10 11:28:51 +000074# Do configuration stuff. Don't mess with the --prefix in the
75# configure command below, even if you think it's wrong.
sewardjfb9c9622011-09-27 11:54:01 +000076# You may need to set the --with-tmpdir path to something
sewardj1b3a7a42011-10-26 15:10:49 +000077# different if /sdcard doesn't work on the device -- this is
sewardjfb9c9622011-09-27 11:54:01 +000078# a known cause of difficulties.
sewardja0b4dbc2011-09-10 11:28:51 +000079
sewardj37ed97b2011-07-12 13:34:31 +000080./autogen.sh
81
philippe5d5dd8e2012-08-05 00:08:25 +000082# for ARM
sewardjfb9c9622011-09-27 11:54:01 +000083CPPFLAGS="--sysroot=$NDKROOT/platforms/android-3/arch-arm -DANDROID_HARDWARE_$HWKIND" \
sewardja0b4dbc2011-09-10 11:28:51 +000084 CFLAGS="--sysroot=$NDKROOT/platforms/android-3/arch-arm" \
sewardj37ed97b2011-07-12 13:34:31 +000085 ./configure --prefix=/data/local/Inst \
86 --host=armv7-unknown-linux --target=armv7-unknown-linux \
sewardja0b4dbc2011-09-10 11:28:51 +000087 --with-tmpdir=/sdcard
philippeeeb07332012-07-04 21:59:29 +000088# note: on android emulator, android-14 platform was also tested and works.
89# It is not clear what this platform nr really is.
sewardj37ed97b2011-07-12 13:34:31 +000090
philippe5d5dd8e2012-08-05 00:08:25 +000091# for x86
92CPPFLAGS="--sysroot=$NDKROOT/platforms/android-9/arch-x86 -DANDROID_HARDWARE_$HWKIND" \
93 CFLAGS="--sysroot=$NDKROOT/platforms/android-9/arch-x86 -fno-pic" \
94 ./configure --prefix=/data/local/Inst \
95 --host=i686-android-linux --target=i686-android-linux \
96 --with-tmpdir=/sdcard
97
sewardj37ed97b2011-07-12 13:34:31 +000098# At the end of the configure run, a few lines of details
99# are printed. Make sure that you see these two lines:
sewardjca456c72012-08-05 13:44:15 +0000100#
philippe5d5dd8e2012-08-05 00:08:25 +0000101# For ARM:
sewardj37ed97b2011-07-12 13:34:31 +0000102# Platform variant: android
103# Primary -DVGPV string: -DVGPV_arm_linux_android=1
sewardjca456c72012-08-05 13:44:15 +0000104#
philippe5d5dd8e2012-08-05 00:08:25 +0000105# For x86:
106# Platform variant: android
107# Primary -DVGPV string: -DVGPV_x86_linux_android=1
sewardj37ed97b2011-07-12 13:34:31 +0000108#
109# If you see anything else at this point, something is wrong, and
110# either the build will fail, or will succeed but you'll get something
111# which won't work.
112
113
114# Build, and park the install tree in `pwd`/Inst
sewardja0b4dbc2011-09-10 11:28:51 +0000115#
116make -j2
117make -j2 install DESTDIR=`pwd`/Inst
sewardj37ed97b2011-07-12 13:34:31 +0000118
119
120# To get the install tree onto the device:
121# (I don't know why it's not "adb push Inst /data/local", but this
122# formulation does appear to put the result in /data/local/Inst.)
123#
124adb push Inst /
125
126# To run (on the device)
sewardja0b4dbc2011-09-10 11:28:51 +0000127/data/local/Inst/bin/valgrind [the usual args etc]
128
129
130# Once you're up and running, a handy modify-V-rebuild-reinstall
131# command line (on the host, of course) is
132#
133mq -j2 && mq -j2 install DESTDIR=`pwd`/Inst && adb push Inst /
134#
135# where 'mq' is an alias for 'make --quiet'.
136
137
138# One common cause of runs failing at startup is the inability of
139# Valgrind to find a suitable temporary directory. On the device,
140# there doesn't seem to be any one location which we always have
141# permission to write to. The instructions above use /sdcard. If
142# that doesn't work for you, and you're Valgrinding one specific
143# application which is already installed, you could try using its
144# temporary directory, in /data/data, for example
145# /data/data/org.mozilla.firefox_beta.
146#
147# Using /system/bin/logcat on the device is helpful for diagnosing
148# these kinds of problems.