Char/HChar fixups for m_debuginfo and m_gdbserver.
[ambi/valgrind.git] / README.android
1
2 How to cross-compile for Android.  These notes were last updated on 
3 17 Feb 2012, for Valgrind SVN revision 12390/2257.
4
5 This is known to work at least for :
6 ARM:
7   Android 4.0.3 running on a (rooted, AOSP build) Nexus S.
8   Android 4.0.3 running on Motorola Xoom.
9   Android 4.0.3 running on android arm emulator.
10   Android 4.1   running on android emulator.
11   Android 2.3.4 on Nexus S worked at some time in the past.
12
13 x86:
14   Android 4.0.3 running on android x86 emulator.
15
16 On android-arm, GDBserver might insert breaks at wrong addresses.
17 Feedback on this welcome.
18
19 Other configurations and toolchains might work, but haven't been tested.
20 Feedback is welcome.
21
22
23 You need the android-ndk-r6 native development kit.  r6b and r7
24 give a non-completely-working build; see
25 http://code.google.com/p/android/issues/detail?id=23203
26 For the android emulator, the versions needed and how to
27 install them are described in README.android_emulator.
28
29 Install it somewhere.  Doesn't matter where.  Then do this:
30
31
32 # Modify this (obviously).  Note, this "export" command is only done
33 # so as to reduce the amount of typing required.  None of the commands
34 # below read it as part of their operation.
35 #
36 export NDKROOT=/path/to/android-ndk-r6
37
38
39 # Modify this too.  Tell the build system which Android hardware you
40 # are building for.  It needs to know this so it can compile in
41 # support for the right Android-hw-specific ioctls.  (sigh.)  As with
42 # NDKROOT above, this is merely to avoid repeated typing; none of the
43 # commands read it.
44 #
45 # Currently the supported values are:  nexus_s pandaboard
46 # So choose one of the below:
47 #
48 export HWKIND=nexus_s         # Samsung Nexus S; also Xoom (for now)
49 export HWKIND=generic         # A generic Android device. eg, Pandaboard
50 export HWKIND=emulator        # Android emulator
51
52 # Then cd to the root of your Valgrind source tree.
53 #
54 cd /path/to/valgrind/source/tree
55
56
57 # After this point, you don't need to modify anything; just copy and
58 # paste the commands below.
59
60
61 # Set up toolchain paths.
62 #
63 # For ARM
64 export AR=$NDKROOT/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/arm-linux-androideabi-ar
65 export LD=$NDKROOT/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/arm-linux-androideabi-ld
66 export CC=$NDKROOT/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/arm-linux-androideabi-gcc
67
68 # For x86
69 export AR=$NDKROOT/toolchains/x86-4.4.3/prebuilt/linux-x86/bin/i686-android-linux-ar
70 export LD=$NDKROOT/toolchains/x86-4.4.3/prebuilt/linux-x86/bin/i686-android-linux-ld
71 export CC=$NDKROOT/toolchains/x86-4.4.3/prebuilt/linux-x86/bin/i686-android-linux-gcc
72
73
74 # Do configuration stuff.  Don't mess with the --prefix in the
75 # configure command below, even if you think it's wrong.
76 # You may need to set the --with-tmpdir path to something
77 # different if /sdcard doesn't work on the device -- this is
78 # a known cause of difficulties.
79
80 # The below re-generates configure, Makefiles, ...
81 # This is not needed if you start from a release tarball.
82 ./autogen.sh
83
84 # for ARM
85 CPPFLAGS="--sysroot=$NDKROOT/platforms/android-3/arch-arm -DANDROID_HARDWARE_$HWKIND" \
86    CFLAGS="--sysroot=$NDKROOT/platforms/android-3/arch-arm" \
87    ./configure --prefix=/data/local/Inst \
88    --host=armv7-unknown-linux --target=armv7-unknown-linux \
89    --with-tmpdir=/sdcard
90 # note: on android emulator, android-14 platform was also tested and works.
91 # It is not clear what this platform nr really is.
92
93 # for x86
94 CPPFLAGS="--sysroot=$NDKROOT/platforms/android-9/arch-x86 -DANDROID_HARDWARE_$HWKIND" \
95    CFLAGS="--sysroot=$NDKROOT/platforms/android-9/arch-x86 -fno-pic" \
96    ./configure --prefix=/data/local/Inst \
97    --host=i686-android-linux --target=i686-android-linux \
98    --with-tmpdir=/sdcard
99
100 # At the end of the configure run, a few lines of details
101 # are printed.  Make sure that you see these two lines:
102 #
103 # For ARM:
104 #          Platform variant: android
105 #     Primary -DVGPV string: -DVGPV_arm_linux_android=1
106 #
107 # For x86:
108 #          Platform variant: android
109 #     Primary -DVGPV string: -DVGPV_x86_linux_android=1
110 #
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
117 #
118 make -j2
119 make -j2 install DESTDIR=`pwd`/Inst
120
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 #
126 adb push Inst /
127
128 # To run (on the device)
129 /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 #
135 mq -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.