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