sewardj | 37ed97b | 2011-07-12 13:34:31 +0000 | [diff] [blame] | 1 | |
| 2 | How to cross-compile for Android. |
| 3 | |
sewardj | a0b4dbc | 2011-09-10 11:28:51 +0000 | [diff] [blame] | 4 | This is known to work at least for Android 2.3.4 running on a (rooted, |
| 5 | AOSP build) Nexus S. It has also worked in the past on a |
| 6 | un-messed-with Motorola Xoom, although I haven't tested it recently. |
| 7 | Other configurations and toolchains might work, but haven't been |
| 8 | tested. Feedback is welcome. |
sewardj | 37ed97b | 2011-07-12 13:34:31 +0000 | [diff] [blame] | 9 | |
sewardj | a0b4dbc | 2011-09-10 11:28:51 +0000 | [diff] [blame] | 10 | You need the android-ndk-r6 native development kit. Install it |
sewardj | 37ed97b | 2011-07-12 13:34:31 +0000 | [diff] [blame] | 11 | somewhere. Then do this: |
| 12 | |
sewardj | 37ed97b | 2011-07-12 13:34:31 +0000 | [diff] [blame] | 13 | |
sewardj | a0b4dbc | 2011-09-10 11:28:51 +0000 | [diff] [blame] | 14 | # Modify this (obviously). |
sewardj | 37ed97b | 2011-07-12 13:34:31 +0000 | [diff] [blame] | 15 | # |
sewardj | a0b4dbc | 2011-09-10 11:28:51 +0000 | [diff] [blame] | 16 | export NDKROOT=/path/to/android-ndk-r6 |
sewardj | 37ed97b | 2011-07-12 13:34:31 +0000 | [diff] [blame] | 17 | |
sewardj | a0b4dbc | 2011-09-10 11:28:51 +0000 | [diff] [blame] | 18 | |
| 19 | # And then (unmodified) |
| 20 | # |
| 21 | export AR=$NDKROOT/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/arm-linux-androideabi-ar |
| 22 | export CPP=$NDKROOT/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/arm-linux-androideabi-cpp |
| 23 | export LD=$NDKROOT/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/arm-linux-androideabi-ld |
| 24 | export CXX=$NDKROOT/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/arm-linux-androideabi-g++ |
| 25 | export CC=$NDKROOT/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/arm-linux-androideabi-gcc |
| 26 | |
| 27 | |
| 28 | # Then cd to the root of your Valgrind source tree. |
| 29 | # |
| 30 | cd /path/to/valgrind/source/tree |
| 31 | |
| 32 | |
| 33 | # Do configuration stuff. Don't mess with the --prefix in the |
| 34 | # configure command below, even if you think it's wrong. |
| 35 | |
sewardj | 37ed97b | 2011-07-12 13:34:31 +0000 | [diff] [blame] | 36 | ./autogen.sh |
| 37 | |
sewardj | a0b4dbc | 2011-09-10 11:28:51 +0000 | [diff] [blame] | 38 | CPPFLAGS="--sysroot=$NDKROOT/platforms/android-3/arch-arm" \ |
| 39 | CFLAGS="--sysroot=$NDKROOT/platforms/android-3/arch-arm" \ |
sewardj | 37ed97b | 2011-07-12 13:34:31 +0000 | [diff] [blame] | 40 | ./configure --prefix=/data/local/Inst \ |
| 41 | --host=armv7-unknown-linux --target=armv7-unknown-linux \ |
sewardj | a0b4dbc | 2011-09-10 11:28:51 +0000 | [diff] [blame] | 42 | --with-tmpdir=/sdcard |
sewardj | 37ed97b | 2011-07-12 13:34:31 +0000 | [diff] [blame] | 43 | |
| 44 | |
| 45 | # At the end of the configure run, a few lines of details |
| 46 | # are printed. Make sure that you see these two lines: |
| 47 | # |
| 48 | # Platform variant: android |
| 49 | # Primary -DVGPV string: -DVGPV_arm_linux_android=1 |
| 50 | # |
| 51 | # If you see anything else at this point, something is wrong, and |
| 52 | # either the build will fail, or will succeed but you'll get something |
| 53 | # which won't work. |
| 54 | |
| 55 | |
| 56 | # Build, and park the install tree in `pwd`/Inst |
sewardj | a0b4dbc | 2011-09-10 11:28:51 +0000 | [diff] [blame] | 57 | # |
| 58 | make -j2 |
| 59 | make -j2 install DESTDIR=`pwd`/Inst |
sewardj | 37ed97b | 2011-07-12 13:34:31 +0000 | [diff] [blame] | 60 | |
| 61 | |
| 62 | # To get the install tree onto the device: |
| 63 | # (I don't know why it's not "adb push Inst /data/local", but this |
| 64 | # formulation does appear to put the result in /data/local/Inst.) |
| 65 | # |
| 66 | adb push Inst / |
| 67 | |
| 68 | # To run (on the device) |
sewardj | a0b4dbc | 2011-09-10 11:28:51 +0000 | [diff] [blame] | 69 | /data/local/Inst/bin/valgrind [the usual args etc] |
| 70 | |
| 71 | |
| 72 | # Once you're up and running, a handy modify-V-rebuild-reinstall |
| 73 | # command line (on the host, of course) is |
| 74 | # |
| 75 | mq -j2 && mq -j2 install DESTDIR=`pwd`/Inst && adb push Inst / |
| 76 | # |
| 77 | # where 'mq' is an alias for 'make --quiet'. |
| 78 | |
| 79 | |
| 80 | # One common cause of runs failing at startup is the inability of |
| 81 | # Valgrind to find a suitable temporary directory. On the device, |
| 82 | # there doesn't seem to be any one location which we always have |
| 83 | # permission to write to. The instructions above use /sdcard. If |
| 84 | # that doesn't work for you, and you're Valgrinding one specific |
| 85 | # application which is already installed, you could try using its |
| 86 | # temporary directory, in /data/data, for example |
| 87 | # /data/data/org.mozilla.firefox_beta. |
| 88 | # |
| 89 | # Using /system/bin/logcat on the device is helpful for diagnosing |
| 90 | # these kinds of problems. |