blob: 2feb42b9a5bb01c74914b80ac13b642871a5729b [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
dejanj9c6b05d2013-12-27 09:06:55 +000016mips32:
17 Android 4.1.2 running on android mips emulator.
18 Android 4.2.2 running on android mips emulator.
19 Android 4.3 running on android mips emulator.
20 Android 4.0.4 running on BROADCOM bcm7425
21
sewardjca456c72012-08-05 13:44:15 +000022On android-arm, GDBserver might insert breaks at wrong addresses.
philippe77c11852012-07-18 23:01:02 +000023Feedback on this welcome.
philippeeeb07332012-07-04 21:59:29 +000024
25Other configurations and toolchains might work, but haven't been tested.
sewardj0a64a7a2012-02-17 15:13:55 +000026Feedback is welcome.
sewardj37ed97b2011-07-12 13:34:31 +000027
philippeeeb07332012-07-04 21:59:29 +000028
sewardj0a64a7a2012-02-17 15:13:55 +000029You need the android-ndk-r6 native development kit. r6b and r7
30give a non-completely-working build; see
31http://code.google.com/p/android/issues/detail?id=23203
philippeeeb07332012-07-04 21:59:29 +000032For the android emulator, the versions needed and how to
33install them are described in README.android_emulator.
sewardj0a64a7a2012-02-17 15:13:55 +000034
35Install it somewhere. Doesn't matter where. Then do this:
sewardj37ed97b2011-07-12 13:34:31 +000036
sewardj37ed97b2011-07-12 13:34:31 +000037
sewardjfb9c9622011-09-27 11:54:01 +000038# Modify this (obviously). Note, this "export" command is only done
39# so as to reduce the amount of typing required. None of the commands
40# below read it as part of their operation.
sewardj37ed97b2011-07-12 13:34:31 +000041#
sewardja0b4dbc2011-09-10 11:28:51 +000042export NDKROOT=/path/to/android-ndk-r6
sewardj37ed97b2011-07-12 13:34:31 +000043
sewardja0b4dbc2011-09-10 11:28:51 +000044
sewardjfb9c9622011-09-27 11:54:01 +000045# Modify this too. Tell the build system which Android hardware you
46# are building for. It needs to know this so it can compile in
47# support for the right Android-hw-specific ioctls. (sigh.) As with
48# NDKROOT above, this is merely to avoid repeated typing; none of the
49# commands read it.
sewardja0b4dbc2011-09-10 11:28:51 +000050#
sewardj1b3a7a42011-10-26 15:10:49 +000051# Currently the supported values are: nexus_s pandaboard
52# So choose one of the below:
sewardjfb9c9622011-09-27 11:54:01 +000053#
sewardj0a64a7a2012-02-17 15:13:55 +000054export HWKIND=nexus_s # Samsung Nexus S; also Xoom (for now)
philippe5d5dd8e2012-08-05 00:08:25 +000055export HWKIND=generic # A generic Android device. eg, Pandaboard
philippeeeb07332012-07-04 21:59:29 +000056export HWKIND=emulator # Android emulator
sewardja0b4dbc2011-09-10 11:28:51 +000057
58# Then cd to the root of your Valgrind source tree.
59#
60cd /path/to/valgrind/source/tree
61
62
sewardjfb9c9622011-09-27 11:54:01 +000063# After this point, you don't need to modify anything; just copy and
64# paste the commands below.
65
66
67# Set up toolchain paths.
68#
sewardjca456c72012-08-05 13:44:15 +000069# For ARM
sewardjfb9c9622011-09-27 11:54:01 +000070export AR=$NDKROOT/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/arm-linux-androideabi-ar
71export LD=$NDKROOT/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/arm-linux-androideabi-ld
72export CC=$NDKROOT/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/arm-linux-androideabi-gcc
73
sewardjca456c72012-08-05 13:44:15 +000074# For x86
philippe5d5dd8e2012-08-05 00:08:25 +000075export AR=$NDKROOT/toolchains/x86-4.4.3/prebuilt/linux-x86/bin/i686-android-linux-ar
76export LD=$NDKROOT/toolchains/x86-4.4.3/prebuilt/linux-x86/bin/i686-android-linux-ld
77export CC=$NDKROOT/toolchains/x86-4.4.3/prebuilt/linux-x86/bin/i686-android-linux-gcc
78
dejanj9c6b05d2013-12-27 09:06:55 +000079# For MIPS32
80export AR=$NDKROOT/toolchains/mipsel-linux-android-4.8/prebuilt/linux-x86_64/bin/mipsel-linux-android-ar
81export LD=$NDKROOT/toolchains/mipsel-linux-android-4.8/prebuilt/linux-x86_64/bin/mipsel-linux-android-ld
82export CC=$NDKROOT/toolchains/mipsel-linux-android-4.8/prebuilt/linux-x86_64/bin/mipsel-linux-android-gcc
sewardjfb9c9622011-09-27 11:54:01 +000083
sewardja0b4dbc2011-09-10 11:28:51 +000084# Do configuration stuff. Don't mess with the --prefix in the
85# configure command below, even if you think it's wrong.
sewardjfb9c9622011-09-27 11:54:01 +000086# You may need to set the --with-tmpdir path to something
sewardj1b3a7a42011-10-26 15:10:49 +000087# different if /sdcard doesn't work on the device -- this is
sewardjfb9c9622011-09-27 11:54:01 +000088# a known cause of difficulties.
sewardja0b4dbc2011-09-10 11:28:51 +000089
philippe7d9b41b2012-09-11 19:53:01 +000090# The below re-generates configure, Makefiles, ...
91# This is not needed if you start from a release tarball.
sewardj37ed97b2011-07-12 13:34:31 +000092./autogen.sh
93
philippe5d5dd8e2012-08-05 00:08:25 +000094# for ARM
sewardjfb9c9622011-09-27 11:54:01 +000095CPPFLAGS="--sysroot=$NDKROOT/platforms/android-3/arch-arm -DANDROID_HARDWARE_$HWKIND" \
sewardja0b4dbc2011-09-10 11:28:51 +000096 CFLAGS="--sysroot=$NDKROOT/platforms/android-3/arch-arm" \
sewardj37ed97b2011-07-12 13:34:31 +000097 ./configure --prefix=/data/local/Inst \
98 --host=armv7-unknown-linux --target=armv7-unknown-linux \
sewardja0b4dbc2011-09-10 11:28:51 +000099 --with-tmpdir=/sdcard
philippeeeb07332012-07-04 21:59:29 +0000100# note: on android emulator, android-14 platform was also tested and works.
101# It is not clear what this platform nr really is.
sewardj37ed97b2011-07-12 13:34:31 +0000102
philippe5d5dd8e2012-08-05 00:08:25 +0000103# for x86
104CPPFLAGS="--sysroot=$NDKROOT/platforms/android-9/arch-x86 -DANDROID_HARDWARE_$HWKIND" \
105 CFLAGS="--sysroot=$NDKROOT/platforms/android-9/arch-x86 -fno-pic" \
106 ./configure --prefix=/data/local/Inst \
107 --host=i686-android-linux --target=i686-android-linux \
108 --with-tmpdir=/sdcard
109
dejanj9c6b05d2013-12-27 09:06:55 +0000110# for MIPS32
111CPPFLAGS="--sysroot=$NDKROOT/platforms/android-18/arch-mips -DANDROID_HARDWARE_$HWKIND" \
112 CFLAGS="--sysroot=$NDKROOT/platforms/android-18/arch-mips" \
113 ./configure --prefix=/data/local/Inst \
114 --host=mipsel-linux-android --target=mipsel-linux-android \
115 --with-tmpdir=/sdcard
116
sewardj37ed97b2011-07-12 13:34:31 +0000117# At the end of the configure run, a few lines of details
118# are printed. Make sure that you see these two lines:
sewardjca456c72012-08-05 13:44:15 +0000119#
philippe5d5dd8e2012-08-05 00:08:25 +0000120# For ARM:
sewardj37ed97b2011-07-12 13:34:31 +0000121# Platform variant: android
122# Primary -DVGPV string: -DVGPV_arm_linux_android=1
sewardjca456c72012-08-05 13:44:15 +0000123#
philippe5d5dd8e2012-08-05 00:08:25 +0000124# For x86:
125# Platform variant: android
126# Primary -DVGPV string: -DVGPV_x86_linux_android=1
sewardj37ed97b2011-07-12 13:34:31 +0000127#
dejanj9c6b05d2013-12-27 09:06:55 +0000128# For mips32:
129# Platform variant: android
130# Primary -DVGPV string: -DVGPV_mips32_linux_android=1
131#
sewardj37ed97b2011-07-12 13:34:31 +0000132# If you see anything else at this point, something is wrong, and
133# either the build will fail, or will succeed but you'll get something
134# which won't work.
135
136
137# Build, and park the install tree in `pwd`/Inst
sewardja0b4dbc2011-09-10 11:28:51 +0000138#
139make -j2
140make -j2 install DESTDIR=`pwd`/Inst
sewardj37ed97b2011-07-12 13:34:31 +0000141
142
143# To get the install tree onto the device:
144# (I don't know why it's not "adb push Inst /data/local", but this
145# formulation does appear to put the result in /data/local/Inst.)
146#
147adb push Inst /
148
149# To run (on the device)
sewardja0b4dbc2011-09-10 11:28:51 +0000150/data/local/Inst/bin/valgrind [the usual args etc]
151
152
153# Once you're up and running, a handy modify-V-rebuild-reinstall
154# command line (on the host, of course) is
155#
156mq -j2 && mq -j2 install DESTDIR=`pwd`/Inst && adb push Inst /
157#
158# where 'mq' is an alias for 'make --quiet'.
159
160
161# One common cause of runs failing at startup is the inability of
162# Valgrind to find a suitable temporary directory. On the device,
163# there doesn't seem to be any one location which we always have
164# permission to write to. The instructions above use /sdcard. If
165# that doesn't work for you, and you're Valgrinding one specific
166# application which is already installed, you could try using its
167# temporary directory, in /data/data, for example
168# /data/data/org.mozilla.firefox_beta.
169#
170# Using /system/bin/logcat on the device is helpful for diagnosing
171# these kinds of problems.