This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Modern Androids do support locales
[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
BF
30# Make sure that we look for libm
31libswanted="$libswanted m"
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
76d86663
BF
46# Bionic defines several stubs that just warn and return NULL
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
50# If they warn with 'FIX' or 'Android', assume they are the stubs
51# we want to avoid.
52
53# These are all stubs as well, but the core doesn't use them:
54# getusershell setusershell endusershell
55
56# This script UU/archname.cbu will get 'called-back' by Configure.
12120791 57$cat > UU/archname.cbu <<'EOCBU'
76d86663
BF
58# egrep pattern to detect a stub warning on Android.
59# Right now we're checking for:
60# Android 2.x: FIX ME! implement FUNC
61# Android 4.x: FUNC is not implemented on Android
62android_stub='FIX|Android'
63
12120791 64$cat > try.c << 'EOM'
76d86663
BF
65#include <netdb.h>
66int main() { (void) getnetbyname("foo"); return(0); }
67EOM
68$cc $ccflags try.c -o try
69android_warn=`$run ./try 2>&1 | $egrep "$android_stub"`
70if test "X$android_warn" != X; then
71 d_getnbyname="$undef"
72fi
73
12120791 74$cat > try.c << 'EOM'
76d86663
BF
75#include <netdb.h>
76int main() { (void) getnetbyaddr((uint32_t)1, AF_INET); 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_getnbyaddr="$undef"
82fi
83
12120791 84$cat > try.c << 'EOM'
ea442100
JH
85#include <stdio.h>
86#include <mntent.h>
87#include <unistd.h>
88int main() { (void) getmntent(stdout); return(0); }
89EOM
90$cc $ccflags try.c -o try
91android_warn=`$run ./try 2>&1 | $egrep "$android_stub"`
92if test "X$android_warn" != X; then
93 d_getmntent="$undef"
94fi
95
96$cat > try.c << 'EOM'
76d86663
BF
97#include <netdb.h>
98int main() { (void) getprotobyname("foo"); return(0); }
99EOM
100$cc $ccflags try.c -o try
101android_warn=`$run ./try 2>&1 | $egrep "$android_stub"`
102if test "X$android_warn" != X; then
103 d_getpbyname="$undef"
104fi
105
12120791 106$cat > try.c << 'EOM'
76d86663
BF
107#include <netdb.h>
108int main() { (void) getprotobynumber(1); return(0); }
109EOM
110$cc $ccflags try.c -o try
111android_warn=`$run ./try 2>&1 | $egrep "$android_stub"`
112if test "X$android_warn" != X; then
113 d_getpbynumber="$undef"
114fi
115
12120791 116$cat > try.c << 'EOM'
76d86663
BF
117#include <sys/types.h>
118#include <pwd.h>
119int main() { endpwent(); return(0); }
120EOM
121$cc $ccflags try.c -o try
122android_warn=`$run ./try 2>&1 | $egrep "$android_stub"`
123if test "X$android_warn" != X; then
124 d_endpwent="$undef"
125fi
126
12120791 127$cat > try.c << 'EOM'
76d86663
BF
128#include <unistd.h>
129int main() { (void) ttyname(STDIN_FILENO); return(0); }
130EOM
131$cc $ccflags try.c -o try
132android_warn=`$run ./try 2>&1 | $egrep "$android_stub"`
133if test "X$android_warn" != X; then
134 d_ttyname="$undef"
135fi
136
137EOCBU
687e7019 138
da8b263a
BF
139if $test "X$targetrun" = "Xadb"; then
140
f4ca4add
BF
141$rm $run $to $from $targetmkdir
142
687e7019
JR
143case "$src" in
144 /*) run=$src/Cross/run
145 targetmkdir=$src/Cross/mkdir
146 to=$src/Cross/to
147 from=$src/Cross/from
148 ;;
149 *) pwd=`test -f ../Configure && cd ..; pwd`
150 run=$pwd/Cross/run
151 targetmkdir=$pwd/Cross/mkdir
152 to=$pwd/Cross/to
153 from=$pwd/Cross/from
154 ;;
155esac
da8b263a 156
687e7019
JR
157targetrun=adb-shell
158targetto=adb-push
159targetfrom=adb-pull
160run=$run-$targetrun
161to=$to-$targetto
162from=$from-$targetfrom
163
12120791 164$cat >$run <<EOF
687e7019 165#!/bin/sh
8995f03f 166doexit="echo \\\$? >$targetdir/output.status"
77e493b5 167env=''
687e7019
JR
168case "\$1" in
169-cwd)
170 shift
171 cwd=\$1
172 shift
173 ;;
174esac
77e493b5
JR
175case "\$1" in
176-env)
177 shift
178 env=\$1
179 shift
180 ;;
181esac
687e7019
JR
182case "\$cwd" in
183'') cwd=$targetdir ;;
184esac
77e493b5
JR
185case "\$env" in
186'') env="echo "
187esac
687e7019
JR
188exe=\$1
189shift
77e493b5 190args=\$@
687e7019
JR
191$to \$exe > /dev/null 2>&1
192
193# send copy results to /dev/null as otherwise it outputs speed stats which gets in our way.
77e493b5 194# sometimes there is no $?, I dunno why? we then get Cross/run-adb-shell: line 39: exit: XX: numeric argument required
8995f03f
BF
195adb -s $targethost shell "sh -c '(cd \$cwd && \$env ; \$exe \$args > $targetdir/output.stdout 2>$targetdir/output.stderr) ; \$doexit '" > /dev/null
196
bb34e29a
BF
197rm output.stdout output.stderr output.status 2>/dev/null
198
31b9cdb1 199$from output.stdout
8995f03f
BF
200$from output.stderr
201$from output.status
202
8995f03f 203# We get back Ok\r\n on android for some reason, grrr:
bb34e29a
BF
204$cat output.stdout | $tr -d '\r'
205if test -s output.stderr; then
206 $cat output.stderr | $tr -d '\r' >&2
8995f03f
BF
207fi
208
bb34e29a
BF
209result_status=\`$cat output.status | $tr -d '\r'\`
210
211rm output.stdout output.stderr output.status
212
8995f03f
BF
213# Also, adb doesn't exit with the commands exit code, like ssh does, double-grr
214exit \$result_status
687e7019
JR
215
216EOF
aec8ce86 217$chmod a+rx $run
687e7019 218
12120791 219$cat >$targetmkdir <<EOF
687e7019
JR
220#!/bin/sh
221adb -s $targethost shell "mkdir -p \$@"
222EOF
aec8ce86 223$chmod a+rx $targetmkdir
687e7019 224
12120791 225$cat >$to <<EOF
687e7019
JR
226#!/bin/sh
227for f in \$@
228do
229 case "\$f" in
230 /*)
687e7019
JR
231 adb -s $targethost push \$f \$f || exit 1
232 ;;
233 *)
687e7019
JR
234 (adb -s $targethost push \$f $targetdir/\$f < /dev/null 2>&1) || exit 1
235 ;;
236 esac
237done
238exit 0
239EOF
aec8ce86 240$chmod a+rx $to
687e7019 241
12120791 242$cat >$from <<EOF
687e7019
JR
243#!/bin/sh
244for f in \$@
245do
246 $rm -f \$f
247 (adb -s $targethost pull $targetdir/\$f . > /dev/null 2>&1) || exit 1
248done
249exit 0
250EOF
aec8ce86 251$chmod a+rx $from
687e7019 252
da8b263a
BF
253fi # Cross-compiling with adb
254
78ada538
BF
255case "$usecrosscompile" in
256define)
ff44ff0c
BF
257# The tests for this in Configure doesn't play nicely with
258# cross-compiling
259d_procselfexe="define"
47f59fc1
BF
260if $test "X$hostosname" = "Xdarwin"; then
261 firstmakefile=GNUmakefile;
262fi
081c3f50
BF
263
264# When cross-compiling, full_csh and d_csh will get the
265# host's values, which is all sorts of wrong. So unless
266# full_csh has been set on the command line, set d_csh to
267# undef.
268case "$full_csh" in
269'') d_csh="$undef"
270;;
271esac
272
78ada538 273;;
567e4090
BF
274*)
275ldflags="$ldflags -L/system/lib"
276;;
78ada538 277esac
d600e720
BF
278
279osvers="`$run getprop ro.build.version.release`"
055e6a96
BF
280
281# We want osname to be linux-android during Configure,
282# but plain 'android' afterwards.
283case "$src" in
284 /*) pwd="$src";;
285 *) pwd=`test -f ../Configure && cd ..; pwd`
286 ;;
287esac
288
ff44ff0c 289$cat <<'EOO' >> $pwd/config.arch
055e6a96
BF
290
291osname='android'
42b5146c 292eval "libpth='$libpth /system/lib /vendor/lib'"
ff44ff0c
BF
293
294if $test "X$procselfexe" = X; then
295 case "$d_procselfexe" in
296 define) procselfexe='"/proc/self/exe"';;
297 esac
298fi
055e6a96 299EOO
ac0b53aa
BF
300
301# Android is a linux variant, so run those hints.
302. ./hints/linux.sh