This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Test-Harness: don't assume symlink succeeds
[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'
78ada538
BF
23case "$usecrosscompile" in
24define) ;;
25 # If we aren't cross-compiling, then sh should also point
26 # to /system/bin/sh.
27*) sh=$targetsh ;;
28esac
687e7019 29
1db8b1b9 30# Make sure that we look for libm
136a1aff 31libswanted="$libswanted m log"
1db8b1b9 32
734a50c7
RL
33# Older Androids lack locale support and may need the following undefs
34# uncommenting. This isn't necessary from at least Android 8.1 (Oreo)
19abaf5c 35# https://github.com/android/platform_bionic/blob/master/libc/CAVEATS
734a50c7
RL
36#d_locconv='undef'
37#d_setlocale='undef'
38#d_setlocale_r='undef'
39#d_lc_monetary_2008='undef'
40#i_locale='undef'
41#d_newlocale='undef'
19abaf5c 42
13c14f5c
BF
43# https://code.google.com/p/android-source-browsing/source/browse/libc/netbsd/net/getservent_r.c?repo=platform--bionic&r=ca6fe7bebe3cc6ed7e2db5a3ede2de0fcddf411d#95
44d_getservent_r='undef'
45
f1d63d3c 46# Bionic defines several stubs that warn (in older releases) and return NULL
76d86663
BF
47# https://gitorious.org/0xdroid/bionic/blobs/70b2ef0ec89a9c9d4c2d4bcab728a0e72bafb18e/libc/bionic/stubs.c
48# https://android.googlesource.com/platform/bionic/+/master/libc/bionic/stubs.cpp
49
f1d63d3c
RL
50# These tests originally looked for 'FIX' or 'Android' warnings, as they
51# indicated stubs to avoid. At some point, Android stopped emitting
52# those warnings; the tests were adapted to check function return values
53# and hopefully now detect stubs on both older and newer Androids.
76d86663
BF
54
55# These are all stubs as well, but the core doesn't use them:
56# getusershell setusershell endusershell
57
58# This script UU/archname.cbu will get 'called-back' by Configure.
12120791 59$cat > UU/archname.cbu <<'EOCBU'
f1d63d3c 60# original egrep pattern to detect a stub warning on Android.
76d86663
BF
61# Right now we're checking for:
62# Android 2.x: FIX ME! implement FUNC
63# Android 4.x: FUNC is not implemented on Android
f1d63d3c 64# Android 8.x: <no warnings; tests now printf a compatible warning>
76d86663
BF
65android_stub='FIX|Android'
66
12120791 67$cat > try.c << 'EOM'
76d86663 68#include <netdb.h>
f1d63d3c
RL
69#include <stdio.h>
70int main() {
71 struct netent* test = getnetbyname("loopback");
72 if (test == NULL) {
73 printf("getnetbyname is still a stub function on Android");
74 }
75 return(0);
76}
76d86663
BF
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_getnbyname="$undef"
82fi
83
12120791 84$cat > try.c << 'EOM'
76d86663 85#include <netdb.h>
f1d63d3c
RL
86#include <stdio.h>
87int main() {
88 struct netent* test = getnetbyaddr(127, AF_INET);
89 if (test == NULL) {
90 printf("getnetbyaddr is still a stub function on Android");
91 }
92 return(0);
93}
76d86663
BF
94EOM
95$cc $ccflags try.c -o try
96android_warn=`$run ./try 2>&1 | $egrep "$android_stub"`
97if test "X$android_warn" != X; then
98 d_getnbyaddr="$undef"
99fi
100
12120791 101$cat > try.c << 'EOM'
ea442100
JH
102#include <stdio.h>
103#include <mntent.h>
104#include <unistd.h>
105int main() { (void) getmntent(stdout); return(0); }
106EOM
107$cc $ccflags try.c -o try
108android_warn=`$run ./try 2>&1 | $egrep "$android_stub"`
109if test "X$android_warn" != X; then
110 d_getmntent="$undef"
111fi
112
113$cat > try.c << 'EOM'
76d86663 114#include <netdb.h>
f1d63d3c
RL
115#include <stdio.h>
116int main() {
117 struct protoent* test = getprotobyname("tcp");
118 if (test == NULL) {
119 printf("getprotobyname is still a stub function on Android");
120 }
121 return(0);
122}
76d86663
BF
123EOM
124$cc $ccflags try.c -o try
125android_warn=`$run ./try 2>&1 | $egrep "$android_stub"`
126if test "X$android_warn" != X; then
127 d_getpbyname="$undef"
128fi
129
12120791 130$cat > try.c << 'EOM'
76d86663 131#include <netdb.h>
f1d63d3c
RL
132#include <stdio.h>
133int main() {
134 struct protoent* test = getprotobynumber(1);
135 if (test == NULL) {
136 printf("getprotobynumber is still a stub function on Android");
137 }
138 return(0);
139}
76d86663
BF
140EOM
141$cc $ccflags try.c -o try
142android_warn=`$run ./try 2>&1 | $egrep "$android_stub"`
143if test "X$android_warn" != X; then
144 d_getpbynumber="$undef"
145fi
146
12120791 147$cat > try.c << 'EOM'
76d86663
BF
148#include <sys/types.h>
149#include <pwd.h>
150int main() { endpwent(); return(0); }
151EOM
152$cc $ccflags try.c -o try
153android_warn=`$run ./try 2>&1 | $egrep "$android_stub"`
154if test "X$android_warn" != X; then
155 d_endpwent="$undef"
156fi
157
12120791 158$cat > try.c << 'EOM'
76d86663 159#include <unistd.h>
f1d63d3c
RL
160#include <stdio.h>
161int main() {
162 char *tty = ttyname(STDIN_FILENO);
163 if (tty == NULL) {
164 printf("ttyname is still a stub function on Android");
165 }
166 return(0);
167}
76d86663
BF
168EOM
169$cc $ccflags try.c -o try
170android_warn=`$run ./try 2>&1 | $egrep "$android_stub"`
171if test "X$android_warn" != X; then
172 d_ttyname="$undef"
173fi
174
175EOCBU
687e7019 176
da8b263a
BF
177if $test "X$targetrun" = "Xadb"; then
178
f4ca4add
BF
179$rm $run $to $from $targetmkdir
180
687e7019
JR
181case "$src" in
182 /*) run=$src/Cross/run
183 targetmkdir=$src/Cross/mkdir
184 to=$src/Cross/to
185 from=$src/Cross/from
186 ;;
187 *) pwd=`test -f ../Configure && cd ..; pwd`
188 run=$pwd/Cross/run
189 targetmkdir=$pwd/Cross/mkdir
190 to=$pwd/Cross/to
191 from=$pwd/Cross/from
192 ;;
193esac
da8b263a 194
687e7019
JR
195targetrun=adb-shell
196targetto=adb-push
197targetfrom=adb-pull
198run=$run-$targetrun
199to=$to-$targetto
200from=$from-$targetfrom
201
12120791 202$cat >$run <<EOF
687e7019 203#!/bin/sh
8995f03f 204doexit="echo \\\$? >$targetdir/output.status"
77e493b5 205env=''
687e7019
JR
206case "\$1" in
207-cwd)
208 shift
209 cwd=\$1
210 shift
211 ;;
212esac
77e493b5
JR
213case "\$1" in
214-env)
215 shift
216 env=\$1
217 shift
218 ;;
219esac
687e7019
JR
220case "\$cwd" in
221'') cwd=$targetdir ;;
222esac
77e493b5
JR
223case "\$env" in
224'') env="echo "
225esac
687e7019
JR
226exe=\$1
227shift
77e493b5 228args=\$@
687e7019
JR
229$to \$exe > /dev/null 2>&1
230
231# send copy results to /dev/null as otherwise it outputs speed stats which gets in our way.
77e493b5 232# sometimes there is no $?, I dunno why? we then get Cross/run-adb-shell: line 39: exit: XX: numeric argument required
8995f03f
BF
233adb -s $targethost shell "sh -c '(cd \$cwd && \$env ; \$exe \$args > $targetdir/output.stdout 2>$targetdir/output.stderr) ; \$doexit '" > /dev/null
234
bb34e29a
BF
235rm output.stdout output.stderr output.status 2>/dev/null
236
31b9cdb1 237$from output.stdout
8995f03f
BF
238$from output.stderr
239$from output.status
240
8995f03f 241# We get back Ok\r\n on android for some reason, grrr:
bb34e29a
BF
242$cat output.stdout | $tr -d '\r'
243if test -s output.stderr; then
244 $cat output.stderr | $tr -d '\r' >&2
8995f03f
BF
245fi
246
bb34e29a
BF
247result_status=\`$cat output.status | $tr -d '\r'\`
248
249rm output.stdout output.stderr output.status
250
8995f03f
BF
251# Also, adb doesn't exit with the commands exit code, like ssh does, double-grr
252exit \$result_status
687e7019
JR
253
254EOF
aec8ce86 255$chmod a+rx $run
687e7019 256
12120791 257$cat >$targetmkdir <<EOF
687e7019
JR
258#!/bin/sh
259adb -s $targethost shell "mkdir -p \$@"
260EOF
aec8ce86 261$chmod a+rx $targetmkdir
687e7019 262
12120791 263$cat >$to <<EOF
687e7019
JR
264#!/bin/sh
265for f in \$@
266do
267 case "\$f" in
268 /*)
687e7019
JR
269 adb -s $targethost push \$f \$f || exit 1
270 ;;
271 *)
687e7019
JR
272 (adb -s $targethost push \$f $targetdir/\$f < /dev/null 2>&1) || exit 1
273 ;;
274 esac
275done
276exit 0
277EOF
aec8ce86 278$chmod a+rx $to
687e7019 279
12120791 280$cat >$from <<EOF
687e7019
JR
281#!/bin/sh
282for f in \$@
283do
284 $rm -f \$f
285 (adb -s $targethost pull $targetdir/\$f . > /dev/null 2>&1) || exit 1
286done
287exit 0
288EOF
aec8ce86 289$chmod a+rx $from
687e7019 290
da8b263a
BF
291fi # Cross-compiling with adb
292
78ada538
BF
293case "$usecrosscompile" in
294define)
ff44ff0c
BF
295# The tests for this in Configure doesn't play nicely with
296# cross-compiling
297d_procselfexe="define"
47f59fc1
BF
298if $test "X$hostosname" = "Xdarwin"; then
299 firstmakefile=GNUmakefile;
300fi
081c3f50
BF
301
302# When cross-compiling, full_csh and d_csh will get the
303# host's values, which is all sorts of wrong. So unless
304# full_csh has been set on the command line, set d_csh to
305# undef.
306case "$full_csh" in
307'') d_csh="$undef"
308;;
309esac
310
78ada538 311;;
567e4090
BF
312*)
313ldflags="$ldflags -L/system/lib"
314;;
78ada538 315esac
d600e720
BF
316
317osvers="`$run getprop ro.build.version.release`"
055e6a96
BF
318
319# We want osname to be linux-android during Configure,
320# but plain 'android' afterwards.
321case "$src" in
322 /*) pwd="$src";;
323 *) pwd=`test -f ../Configure && cd ..; pwd`
324 ;;
325esac
326
ff44ff0c 327$cat <<'EOO' >> $pwd/config.arch
055e6a96
BF
328
329osname='android'
42b5146c 330eval "libpth='$libpth /system/lib /vendor/lib'"
ff44ff0c
BF
331
332if $test "X$procselfexe" = X; then
333 case "$d_procselfexe" in
334 define) procselfexe='"/proc/self/exe"';;
335 esac
336fi
055e6a96 337EOO
ac0b53aa
BF
338
339# Android is a linux variant, so run those hints.
340. ./hints/linux.sh