This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Make compiling with adb work again
[perl5.git] / hints / linux-android.sh
CommitLineData
687e7019
JR
1# set -x
2
02b998ff 3# Install the perl and its libraries anywhere:
0a6fcaf8
BF
4case "$userelocatableinc" in
5'') userelocatableinc='define' ;;
6esac
9b0f5f8a 7
02b998ff
BF
8# The Android linker has some unusual behavior: No matter what
9# path is passed in to dlopen(), it'll only use the path's
10# basename when trying to find a cached library.
11# Unfortunately, this is quite problematic for us, since for example,
12# Hash::Util and List::Util both end up creating a Util.so --
13# So if you load List::Util and then Hash::Util, the dlopen() for
14# the latter will return the handle for the former.
15# See the implementation for details:
16# https://code.google.com/p/android-source-browsing/source/browse/linker/linker.c?repo=platform--bionic&r=9ec0f03a0d0b17bbb94ac0b9fef6add28a133c3a#1231
17# What d_libname_unique does is inform MakeMaker that, rather than
18# creating Hash/Util/Util.so, it needs to make Hash/Util/Perl_Hash_Util.so
19d_libname_unique='define'
20
bbbf0767
JR
21# On Android the shell is /system/bin/sh:
22targetsh='/system/bin/sh'
687e7019 23
19abaf5c
JR
24# Down with locales!
25# https://github.com/android/platform_bionic/blob/master/libc/CAVEATS
26d_locconv='undef'
27d_setlocale='undef'
28d_setlocale_r='undef'
29i_locale='undef'
30
13c14f5c
BF
31# https://code.google.com/p/android-source-browsing/source/browse/libc/netbsd/net/getservent_r.c?repo=platform--bionic&r=ca6fe7bebe3cc6ed7e2db5a3ede2de0fcddf411d#95
32d_getservent_r='undef'
33
76d86663
BF
34# Bionic defines several stubs that just warn and return NULL
35# https://gitorious.org/0xdroid/bionic/blobs/70b2ef0ec89a9c9d4c2d4bcab728a0e72bafb18e/libc/bionic/stubs.c
36# https://android.googlesource.com/platform/bionic/+/master/libc/bionic/stubs.cpp
37
38# If they warn with 'FIX' or 'Android', assume they are the stubs
39# we want to avoid.
40
41# These are all stubs as well, but the core doesn't use them:
42# getusershell setusershell endusershell
43
44# This script UU/archname.cbu will get 'called-back' by Configure.
12120791 45$cat > UU/archname.cbu <<'EOCBU'
76d86663
BF
46# egrep pattern to detect a stub warning on Android.
47# Right now we're checking for:
48# Android 2.x: FIX ME! implement FUNC
49# Android 4.x: FUNC is not implemented on Android
50android_stub='FIX|Android'
51
12120791 52$cat > try.c << 'EOM'
76d86663
BF
53#include <netdb.h>
54int main() { (void) getnetbyname("foo"); return(0); }
55EOM
56$cc $ccflags try.c -o try
57android_warn=`$run ./try 2>&1 | $egrep "$android_stub"`
58if test "X$android_warn" != X; then
59 d_getnbyname="$undef"
60fi
61
12120791 62$cat > try.c << 'EOM'
76d86663
BF
63#include <netdb.h>
64int main() { (void) getnetbyaddr((uint32_t)1, AF_INET); return(0); }
65EOM
66$cc $ccflags try.c -o try
67android_warn=`$run ./try 2>&1 | $egrep "$android_stub"`
68if test "X$android_warn" != X; then
69 d_getnbyaddr="$undef"
70fi
71
12120791 72$cat > try.c << 'EOM'
76d86663
BF
73#include <stdio.h>
74#include <mntent.h>
75#include <unistd.h>
76int main() { (void) getmntent(stdout); return(0); }
77EOM
78$cc $ccflags try.c -o try
79android_warn=`$run ./try 2>&1 | $egrep "$android_stub"`
80if test "X$android_warn" != X; then
81 d_getmntent="$undef"
82fi
83
12120791 84$cat > try.c << 'EOM'
76d86663
BF
85#include <netdb.h>
86int main() { (void) getprotobyname("foo"); return(0); }
87EOM
88$cc $ccflags try.c -o try
89android_warn=`$run ./try 2>&1 | $egrep "$android_stub"`
90if test "X$android_warn" != X; then
91 d_getpbyname="$undef"
92fi
93
12120791 94$cat > try.c << 'EOM'
76d86663
BF
95#include <netdb.h>
96int main() { (void) getprotobynumber(1); return(0); }
97EOM
98$cc $ccflags try.c -o try
99android_warn=`$run ./try 2>&1 | $egrep "$android_stub"`
100if test "X$android_warn" != X; then
101 d_getpbynumber="$undef"
102fi
103
12120791 104$cat > try.c << 'EOM'
76d86663
BF
105#include <sys/types.h>
106#include <pwd.h>
107int main() { endpwent(); return(0); }
108EOM
109$cc $ccflags try.c -o try
110android_warn=`$run ./try 2>&1 | $egrep "$android_stub"`
111if test "X$android_warn" != X; then
112 d_endpwent="$undef"
113fi
114
12120791 115$cat > try.c << 'EOM'
76d86663
BF
116#include <unistd.h>
117int main() { (void) ttyname(STDIN_FILENO); return(0); }
118EOM
119$cc $ccflags try.c -o try
120android_warn=`$run ./try 2>&1 | $egrep "$android_stub"`
121if test "X$android_warn" != X; then
122 d_ttyname="$undef"
123fi
124
125EOCBU
687e7019 126
da8b263a
BF
127if $test "X$targetrun" = "Xadb"; then
128
687e7019
JR
129case "$src" in
130 /*) run=$src/Cross/run
131 targetmkdir=$src/Cross/mkdir
132 to=$src/Cross/to
133 from=$src/Cross/from
134 ;;
135 *) pwd=`test -f ../Configure && cd ..; pwd`
136 run=$pwd/Cross/run
137 targetmkdir=$pwd/Cross/mkdir
138 to=$pwd/Cross/to
139 from=$pwd/Cross/from
140 ;;
141esac
da8b263a 142
687e7019
JR
143targetrun=adb-shell
144targetto=adb-push
145targetfrom=adb-pull
146run=$run-$targetrun
147to=$to-$targetto
148from=$from-$targetfrom
149
12120791 150$cat >$run <<EOF
687e7019 151#!/bin/sh
8995f03f 152doexit="echo \\\$? >$targetdir/output.status"
77e493b5 153env=''
687e7019
JR
154case "\$1" in
155-cwd)
156 shift
157 cwd=\$1
158 shift
159 ;;
160esac
77e493b5
JR
161case "\$1" in
162-env)
163 shift
164 env=\$1
165 shift
166 ;;
167esac
687e7019
JR
168case "\$cwd" in
169'') cwd=$targetdir ;;
170esac
77e493b5
JR
171case "\$env" in
172'') env="echo "
173esac
687e7019
JR
174exe=\$1
175shift
77e493b5 176args=\$@
687e7019
JR
177$to \$exe > /dev/null 2>&1
178
179# send copy results to /dev/null as otherwise it outputs speed stats which gets in our way.
77e493b5 180# sometimes there is no $?, I dunno why? we then get Cross/run-adb-shell: line 39: exit: XX: numeric argument required
8995f03f
BF
181adb -s $targethost shell "sh -c '(cd \$cwd && \$env ; \$exe \$args > $targetdir/output.stdout 2>$targetdir/output.stderr) ; \$doexit '" > /dev/null
182
31b9cdb1 183$from output.stdout
8995f03f
BF
184$from output.stderr
185$from output.status
186
12120791
BF
187result=\`$cat output.stdout\`
188result_err=\`$cat output.stderr\`
189result_status=\`$cat output.status\`
8995f03f
BF
190rm output.stdout output.stderr output.status
191
192# We get back Ok\r\n on android for some reason, grrr:
ca0d4969
BF
193result=\`echo "\$result" | $tr -d '\r'\`
194result_err=\`echo "\$result_err" | $tr -d '\r'\`
195result_status=\`echo \$result_status | $tr -d '\r'\`
8995f03f 196
77e493b5 197echo "\$result"
8995f03f
BF
198if test "X\$result_err" != X; then
199 echo "\$result_err" >&2
200fi
201
202# Also, adb doesn't exit with the commands exit code, like ssh does, double-grr
203exit \$result_status
687e7019
JR
204
205EOF
aec8ce86 206$chmod a+rx $run
687e7019 207
12120791 208$cat >$targetmkdir <<EOF
687e7019
JR
209#!/bin/sh
210adb -s $targethost shell "mkdir -p \$@"
211EOF
aec8ce86 212$chmod a+rx $targetmkdir
687e7019 213
12120791 214$cat >$to <<EOF
687e7019
JR
215#!/bin/sh
216for f in \$@
217do
218 case "\$f" in
219 /*)
687e7019
JR
220 adb -s $targethost push \$f \$f || exit 1
221 ;;
222 *)
687e7019
JR
223 (adb -s $targethost push \$f $targetdir/\$f < /dev/null 2>&1) || exit 1
224 ;;
225 esac
226done
227exit 0
228EOF
aec8ce86 229$chmod a+rx $to
687e7019 230
12120791 231$cat >$from <<EOF
687e7019
JR
232#!/bin/sh
233for f in \$@
234do
235 $rm -f \$f
236 (adb -s $targethost pull $targetdir/\$f . > /dev/null 2>&1) || exit 1
237done
238exit 0
239EOF
aec8ce86 240$chmod a+rx $from
687e7019 241
da8b263a
BF
242fi # Cross-compiling with adb
243
47f59fc1
BF
244if $test "X$hostosname" = "Xdarwin"; then
245 firstmakefile=GNUmakefile;
246fi