blob: 1c0e235c3349197c97b1655a5d2ca3c5f60350b4 [file] [log] [blame]
Dan Willemsenb3614d22019-10-07 16:06:34 -07001#!/bin/bash -ex
2#
3# Copyright 2019 Google Inc. All rights reserved.
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16#
17# Regenerate host configuration files for the current host
18
19cd `dirname ${BASH_SOURCE[0]}`
20
21ANDROID_BUILD_TOP=$(cd ../../../..; pwd)
22
23DIR=`uname | tr 'A-Z' 'a-z'`_x86_64
24mkdir -p $DIR/pyconfig
25cd $DIR
26
27if [ $DIR == "linux_x86_64" ]; then
Haibo Huang5bb95e92021-01-14 11:35:14 -080028 export CC="$ANDROID_BUILD_TOP/prebuilts/clang/host/linux-x86/clang-r399163b/bin/clang"
Dan Willemsenb3614d22019-10-07 16:06:34 -070029 export CFLAGS="--sysroot=$ANDROID_BUILD_TOP/prebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.17-4.8/sysroot"
30 export LDFLAGS="--sysroot=$ANDROID_BUILD_TOP/prebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.17-4.8/sysroot -B$ANDROID_BUILD_TOP/prebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.17-4.8/lib/gcc/x86_64-linux/4.8.3 -L$ANDROID_BUILD_TOP/prebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.17-4.8/lib/gcc/x86_64-linux/4.8.3 -L$ANDROID_BUILD_TOP/prebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.17-4.8/x86_64-linux/lib64"
31fi
32
33#
34# Generate pyconfig.h
35#
36rm -rf tmp
37mkdir tmp
38cd tmp
39../../../configure
40
41if [ $DIR == "darwin_x86_64" ]; then
Dan Willemsend948d442021-02-16 21:10:24 -080042 # getentropy is not safe on <10.12, which we still target
43 sed -ibak "s%#define HAVE_GETENTROPY 1%/* #undef HAVE_GETENTROPY */%" pyconfig.h
Dan Willemsenb3614d22019-10-07 16:06:34 -070044 # utimensat and futimens are not safe on <10.13, which we still target
45 sed -ibak "s%#define HAVE_UTIMENSAT 1%/* #undef HAVE_UTIMENSAT */%" pyconfig.h
46 sed -ibak "s%#define HAVE_FUTIMENS 1%/* #undef HAVE_FUTIMENS */%" pyconfig.h
Dan Willemsenf4dc1922020-12-23 19:03:46 -080047 # preadv and pwritev are not safe on <11, which we still target
48 sed -ibak "s%#define HAVE_PREADV 1%/* #undef HAVE_PREADV */%" pyconfig.h
49 sed -ibak "s%#define HAVE_PWRITEV 1%/* #undef HAVE_PWRITEV */%" pyconfig.h
Dan Willemsen2c451f82021-01-25 17:43:33 -080050 # _dyld_shared_cache_contains_path is not safe on <11, which we still target
51 sed -ibak "s%#define HAVE_DYLD_SHARED_CACHE_CONTAINS_PATH 1%/* #undef HAVE_DYLD_SHARED_CACHE_CONTAINS_PATH */%" pyconfig.h
Dan Willemsenb3614d22019-10-07 16:06:34 -070052fi
53
54cp pyconfig.h ../pyconfig/
55
56if [ $DIR == "linux_x86_64" ]; then
57 mkdir -p ../../bionic/pyconfig
58 cp pyconfig.h ../../bionic/pyconfig/
59 # Changes to support bionic
60 bionic_pyconfig=../../bionic/pyconfig/pyconfig.h
61 sed -i 's%#define HAVE_CONFSTR 1%/* #undef HAVE_CONFSTR */%' $bionic_pyconfig
62 sed -i 's%#define HAVE_CRYPT_H 1%/* #undef HAVE_CRYPT_H */%' $bionic_pyconfig
63 sed -i 's%#define HAVE_CRYPT_R 1%/* #undef HAVE_CRYPT_R */%' $bionic_pyconfig
64 sed -i 's%#define HAVE_DECL_RTLD_DEEPBIND 1%/* #undef HAVE_DECL_RTLD_DEEPBIND */%' $bionic_pyconfig
65 sed -i "s%#define HAVE_GCC_ASM_FOR_X87 1%#ifdef __i386__\n#define HAVE_GCC_ASM_FOR_X87 1\n#endif%" $bionic_pyconfig
66 sed -i 's%#define HAVE_LIBINTL_H 1%/* #undef HAVE_LIBINTL_H */%' $bionic_pyconfig
67 sed -i 's%#define HAVE_STROPTS_H 1%/* #undef HAVE_STROPTS_H */%' $bionic_pyconfig
68 sed -i 's%#define HAVE_WAIT3 1%/* #undef HAVE_WAIT3 */%' $bionic_pyconfig
69
70 sed -i 's%#define SIZEOF_FPOS_T .*%#define SIZEOF_FPOS_T 8%' $bionic_pyconfig
71 sed -i 's%#define SIZEOF_LONG .*%#ifdef __LP64__\n#define SIZEOF_LONG 8\n#else\n#define SIZEOF_LONG 4\n#endif%' $bionic_pyconfig
72 sed -i 's%#define SIZEOF_LONG_DOUBLE .*%#define SIZEOF_LONG_DOUBLE (SIZEOF_LONG * 2)%' $bionic_pyconfig
73 sed -i 's%#define SIZEOF_PTHREAD_T .*%#define SIZEOF_PTHREAD_T SIZEOF_LONG%' $bionic_pyconfig
74 sed -i 's%#define SIZEOF_SIZE_T .*%#define SIZEOF_SIZE_T SIZEOF_LONG%' $bionic_pyconfig
75 sed -i 's%#define SIZEOF_TIME_T .*%#define SIZEOF_TIME_T SIZEOF_LONG%' $bionic_pyconfig
76 sed -i 's%#define SIZEOF_UINTPTR_T .*%#define SIZEOF_UINTPTR_T SIZEOF_LONG%' $bionic_pyconfig
77 sed -i 's%#define SIZEOF_VOID_P .*%#define SIZEOF_VOID_P SIZEOF_LONG%' $bionic_pyconfig
78fi
79
80function generate_srcs() {
81 #
82 # Generate config.c
83 #
84 echo >Makefile.pre
85 ../../../Modules/makesetup -c ../../../Modules/config.c.in -s Modules -m Makefile.pre ../Setup.local ../../Setup.local ../../../Modules/Setup
86 cp config.c ../
87
88 #
89 # Generate module file list
90 #
91 grep '$(CC)' Makefile | sed 's/;.*//' | sed 's/.*: //' | sed 's#$(srcdir)/##' | sort -u >srcs
92 (
93 echo '// Generated by android/regen.sh'
94 echo 'filegroup {'
95 echo " name: \"py3-c-modules-$1\","
96 echo " srcs: ["
97 for src in $(cat srcs); do
98 echo " \"${src}\","
99 done
100 echo " ],"
101 echo '}'
102 ) >../../../Android-$1.bp
103}
104
105generate_srcs $DIR
106
107cd ..
108rm -rf tmp
109
110if [ $DIR == "linux_x86_64" ]; then
111 mkdir ../bionic/tmp
112 pushd ../bionic/tmp
113 generate_srcs bionic
114 popd
115 rm -rf ../bionic/tmp
116fi