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 |
sewardj | 0a64a7a | 2012-02-17 15:13:55 +0000 | [diff] [blame] | 3 | 17 Feb 2012, for Valgrind SVN revision 12390/2257. |
sewardj | 37ed97b | 2011-07-12 13:34:31 +0000 | [diff] [blame] | 4 | |
philippe | eeb0733 | 2012-07-04 21:59:29 +0000 | [diff] [blame] | 5 | This is known to work at least for : |
philippe | 5d5dd8e | 2012-08-05 00:08:25 +0000 | [diff] [blame] | 6 | ARM: |
philippe | eeb0733 | 2012-07-04 21:59:29 +0000 | [diff] [blame] | 7 | Android 4.0.3 running on a (rooted, AOSP build) Nexus S. |
| 8 | Android 4.0.3 running on Motorola Xoom. |
philippe | 5d5dd8e | 2012-08-05 00:08:25 +0000 | [diff] [blame] | 9 | Android 4.0.3 running on android arm emulator. |
philippe | 77c1185 | 2012-07-18 23:01:02 +0000 | [diff] [blame] | 10 | Android 4.1 running on android emulator. |
sewardj | ca456c7 | 2012-08-05 13:44:15 +0000 | [diff] [blame] | 11 | Android 2.3.4 on Nexus S worked at some time in the past. |
philippe | 77c1185 | 2012-07-18 23:01:02 +0000 | [diff] [blame] | 12 | |
philippe | 5d5dd8e | 2012-08-05 00:08:25 +0000 | [diff] [blame] | 13 | x86: |
philippe | 5d5dd8e | 2012-08-05 00:08:25 +0000 | [diff] [blame] | 14 | Android 4.0.3 running on android x86 emulator. |
| 15 | |
dejanj | 9c6b05d | 2013-12-27 09:06:55 +0000 | [diff] [blame] | 16 | mips32: |
| 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 | |
sewardj | ca456c7 | 2012-08-05 13:44:15 +0000 | [diff] [blame] | 22 | On android-arm, GDBserver might insert breaks at wrong addresses. |
philippe | 77c1185 | 2012-07-18 23:01:02 +0000 | [diff] [blame] | 23 | Feedback on this welcome. |
philippe | eeb0733 | 2012-07-04 21:59:29 +0000 | [diff] [blame] | 24 | |
| 25 | Other configurations and toolchains might work, but haven't been tested. |
sewardj | 0a64a7a | 2012-02-17 15:13:55 +0000 | [diff] [blame] | 26 | Feedback is welcome. |
sewardj | 37ed97b | 2011-07-12 13:34:31 +0000 | [diff] [blame] | 27 | |
philippe | eeb0733 | 2012-07-04 21:59:29 +0000 | [diff] [blame] | 28 | |
sewardj | 0a64a7a | 2012-02-17 15:13:55 +0000 | [diff] [blame] | 29 | You need the android-ndk-r6 native development kit. r6b and r7 |
| 30 | give a non-completely-working build; see |
| 31 | http://code.google.com/p/android/issues/detail?id=23203 |
philippe | eeb0733 | 2012-07-04 21:59:29 +0000 | [diff] [blame] | 32 | For the android emulator, the versions needed and how to |
| 33 | install them are described in README.android_emulator. |
sewardj | 0a64a7a | 2012-02-17 15:13:55 +0000 | [diff] [blame] | 34 | |
| 35 | Install it somewhere. Doesn't matter where. Then do this: |
sewardj | 37ed97b | 2011-07-12 13:34:31 +0000 | [diff] [blame] | 36 | |
sewardj | 37ed97b | 2011-07-12 13:34:31 +0000 | [diff] [blame] | 37 | |
sewardj | fb9c962 | 2011-09-27 11:54:01 +0000 | [diff] [blame] | 38 | # 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. |
sewardj | 37ed97b | 2011-07-12 13:34:31 +0000 | [diff] [blame] | 41 | # |
sewardj | a0b4dbc | 2011-09-10 11:28:51 +0000 | [diff] [blame] | 42 | export NDKROOT=/path/to/android-ndk-r6 |
sewardj | 37ed97b | 2011-07-12 13:34:31 +0000 | [diff] [blame] | 43 | |
sewardj | a0b4dbc | 2011-09-10 11:28:51 +0000 | [diff] [blame] | 44 | |
sewardj | fb9c962 | 2011-09-27 11:54:01 +0000 | [diff] [blame] | 45 | # 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. |
sewardj | a0b4dbc | 2011-09-10 11:28:51 +0000 | [diff] [blame] | 50 | # |
sewardj | 1b3a7a4 | 2011-10-26 15:10:49 +0000 | [diff] [blame] | 51 | # Currently the supported values are: nexus_s pandaboard |
| 52 | # So choose one of the below: |
sewardj | fb9c962 | 2011-09-27 11:54:01 +0000 | [diff] [blame] | 53 | # |
sewardj | 0a64a7a | 2012-02-17 15:13:55 +0000 | [diff] [blame] | 54 | export HWKIND=nexus_s # Samsung Nexus S; also Xoom (for now) |
philippe | 5d5dd8e | 2012-08-05 00:08:25 +0000 | [diff] [blame] | 55 | export HWKIND=generic # A generic Android device. eg, Pandaboard |
philippe | eeb0733 | 2012-07-04 21:59:29 +0000 | [diff] [blame] | 56 | export HWKIND=emulator # Android emulator |
sewardj | a0b4dbc | 2011-09-10 11:28:51 +0000 | [diff] [blame] | 57 | |
| 58 | # Then cd to the root of your Valgrind source tree. |
| 59 | # |
| 60 | cd /path/to/valgrind/source/tree |
| 61 | |
| 62 | |
sewardj | fb9c962 | 2011-09-27 11:54:01 +0000 | [diff] [blame] | 63 | # 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 | # |
sewardj | ca456c7 | 2012-08-05 13:44:15 +0000 | [diff] [blame] | 69 | # For ARM |
sewardj | fb9c962 | 2011-09-27 11:54:01 +0000 | [diff] [blame] | 70 | export AR=$NDKROOT/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/arm-linux-androideabi-ar |
| 71 | export LD=$NDKROOT/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/arm-linux-androideabi-ld |
| 72 | export CC=$NDKROOT/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/arm-linux-androideabi-gcc |
| 73 | |
sewardj | ca456c7 | 2012-08-05 13:44:15 +0000 | [diff] [blame] | 74 | # For x86 |
philippe | 5d5dd8e | 2012-08-05 00:08:25 +0000 | [diff] [blame] | 75 | export AR=$NDKROOT/toolchains/x86-4.4.3/prebuilt/linux-x86/bin/i686-android-linux-ar |
| 76 | export LD=$NDKROOT/toolchains/x86-4.4.3/prebuilt/linux-x86/bin/i686-android-linux-ld |
| 77 | export CC=$NDKROOT/toolchains/x86-4.4.3/prebuilt/linux-x86/bin/i686-android-linux-gcc |
| 78 | |
dejanj | 9c6b05d | 2013-12-27 09:06:55 +0000 | [diff] [blame] | 79 | # For MIPS32 |
| 80 | export AR=$NDKROOT/toolchains/mipsel-linux-android-4.8/prebuilt/linux-x86_64/bin/mipsel-linux-android-ar |
| 81 | export LD=$NDKROOT/toolchains/mipsel-linux-android-4.8/prebuilt/linux-x86_64/bin/mipsel-linux-android-ld |
| 82 | export CC=$NDKROOT/toolchains/mipsel-linux-android-4.8/prebuilt/linux-x86_64/bin/mipsel-linux-android-gcc |
sewardj | fb9c962 | 2011-09-27 11:54:01 +0000 | [diff] [blame] | 83 | |
sewardj | a0b4dbc | 2011-09-10 11:28:51 +0000 | [diff] [blame] | 84 | # Do configuration stuff. Don't mess with the --prefix in the |
| 85 | # configure command below, even if you think it's wrong. |
sewardj | fb9c962 | 2011-09-27 11:54:01 +0000 | [diff] [blame] | 86 | # You may need to set the --with-tmpdir path to something |
sewardj | 1b3a7a4 | 2011-10-26 15:10:49 +0000 | [diff] [blame] | 87 | # different if /sdcard doesn't work on the device -- this is |
sewardj | fb9c962 | 2011-09-27 11:54:01 +0000 | [diff] [blame] | 88 | # a known cause of difficulties. |
sewardj | a0b4dbc | 2011-09-10 11:28:51 +0000 | [diff] [blame] | 89 | |
philippe | 7d9b41b | 2012-09-11 19:53:01 +0000 | [diff] [blame] | 90 | # The below re-generates configure, Makefiles, ... |
| 91 | # This is not needed if you start from a release tarball. |
sewardj | 37ed97b | 2011-07-12 13:34:31 +0000 | [diff] [blame] | 92 | ./autogen.sh |
| 93 | |
philippe | 5d5dd8e | 2012-08-05 00:08:25 +0000 | [diff] [blame] | 94 | # for ARM |
sewardj | fb9c962 | 2011-09-27 11:54:01 +0000 | [diff] [blame] | 95 | CPPFLAGS="--sysroot=$NDKROOT/platforms/android-3/arch-arm -DANDROID_HARDWARE_$HWKIND" \ |
sewardj | a0b4dbc | 2011-09-10 11:28:51 +0000 | [diff] [blame] | 96 | CFLAGS="--sysroot=$NDKROOT/platforms/android-3/arch-arm" \ |
sewardj | 37ed97b | 2011-07-12 13:34:31 +0000 | [diff] [blame] | 97 | ./configure --prefix=/data/local/Inst \ |
| 98 | --host=armv7-unknown-linux --target=armv7-unknown-linux \ |
sewardj | a0b4dbc | 2011-09-10 11:28:51 +0000 | [diff] [blame] | 99 | --with-tmpdir=/sdcard |
philippe | eeb0733 | 2012-07-04 21:59:29 +0000 | [diff] [blame] | 100 | # note: on android emulator, android-14 platform was also tested and works. |
| 101 | # It is not clear what this platform nr really is. |
sewardj | 37ed97b | 2011-07-12 13:34:31 +0000 | [diff] [blame] | 102 | |
philippe | 5d5dd8e | 2012-08-05 00:08:25 +0000 | [diff] [blame] | 103 | # for x86 |
| 104 | CPPFLAGS="--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 | |
dejanj | 9c6b05d | 2013-12-27 09:06:55 +0000 | [diff] [blame] | 110 | # for MIPS32 |
| 111 | CPPFLAGS="--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 | |
sewardj | 37ed97b | 2011-07-12 13:34:31 +0000 | [diff] [blame] | 117 | # At the end of the configure run, a few lines of details |
| 118 | # are printed. Make sure that you see these two lines: |
sewardj | ca456c7 | 2012-08-05 13:44:15 +0000 | [diff] [blame] | 119 | # |
philippe | 5d5dd8e | 2012-08-05 00:08:25 +0000 | [diff] [blame] | 120 | # For ARM: |
sewardj | 37ed97b | 2011-07-12 13:34:31 +0000 | [diff] [blame] | 121 | # Platform variant: android |
| 122 | # Primary -DVGPV string: -DVGPV_arm_linux_android=1 |
sewardj | ca456c7 | 2012-08-05 13:44:15 +0000 | [diff] [blame] | 123 | # |
philippe | 5d5dd8e | 2012-08-05 00:08:25 +0000 | [diff] [blame] | 124 | # For x86: |
| 125 | # Platform variant: android |
| 126 | # Primary -DVGPV string: -DVGPV_x86_linux_android=1 |
sewardj | 37ed97b | 2011-07-12 13:34:31 +0000 | [diff] [blame] | 127 | # |
dejanj | 9c6b05d | 2013-12-27 09:06:55 +0000 | [diff] [blame] | 128 | # For mips32: |
| 129 | # Platform variant: android |
| 130 | # Primary -DVGPV string: -DVGPV_mips32_linux_android=1 |
| 131 | # |
sewardj | 37ed97b | 2011-07-12 13:34:31 +0000 | [diff] [blame] | 132 | # 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 |
sewardj | a0b4dbc | 2011-09-10 11:28:51 +0000 | [diff] [blame] | 138 | # |
| 139 | make -j2 |
| 140 | make -j2 install DESTDIR=`pwd`/Inst |
sewardj | 37ed97b | 2011-07-12 13:34:31 +0000 | [diff] [blame] | 141 | |
| 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 | # |
| 147 | adb push Inst / |
| 148 | |
| 149 | # To run (on the device) |
sewardj | a0b4dbc | 2011-09-10 11:28:51 +0000 | [diff] [blame] | 150 | /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 | # |
| 156 | mq -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. |