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