blob: 0ae52e4032618f0d4757c70191519217ea9aa85d [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
42 # utimensat and futimens are not safe on <10.13, which we still target
43 sed -ibak "s%#define HAVE_UTIMENSAT 1%/* #undef HAVE_UTIMENSAT */%" pyconfig.h
44 sed -ibak "s%#define HAVE_FUTIMENS 1%/* #undef HAVE_FUTIMENS */%" pyconfig.h
Dan Willemsenf4dc1922020-12-23 19:03:46 -080045 # preadv and pwritev are not safe on <11, which we still target
46 sed -ibak "s%#define HAVE_PREADV 1%/* #undef HAVE_PREADV */%" pyconfig.h
47 sed -ibak "s%#define HAVE_PWRITEV 1%/* #undef HAVE_PWRITEV */%" pyconfig.h
Dan Willemsenb3614d22019-10-07 16:06:34 -070048fi
49
50cp pyconfig.h ../pyconfig/
51
52if [ $DIR == "linux_x86_64" ]; then
53 mkdir -p ../../bionic/pyconfig
54 cp pyconfig.h ../../bionic/pyconfig/
55 # Changes to support bionic
56 bionic_pyconfig=../../bionic/pyconfig/pyconfig.h
57 sed -i 's%#define HAVE_CONFSTR 1%/* #undef HAVE_CONFSTR */%' $bionic_pyconfig
58 sed -i 's%#define HAVE_CRYPT_H 1%/* #undef HAVE_CRYPT_H */%' $bionic_pyconfig
59 sed -i 's%#define HAVE_CRYPT_R 1%/* #undef HAVE_CRYPT_R */%' $bionic_pyconfig
60 sed -i 's%#define HAVE_DECL_RTLD_DEEPBIND 1%/* #undef HAVE_DECL_RTLD_DEEPBIND */%' $bionic_pyconfig
61 sed -i "s%#define HAVE_GCC_ASM_FOR_X87 1%#ifdef __i386__\n#define HAVE_GCC_ASM_FOR_X87 1\n#endif%" $bionic_pyconfig
62 sed -i 's%#define HAVE_LIBINTL_H 1%/* #undef HAVE_LIBINTL_H */%' $bionic_pyconfig
63 sed -i 's%#define HAVE_STROPTS_H 1%/* #undef HAVE_STROPTS_H */%' $bionic_pyconfig
64 sed -i 's%#define HAVE_WAIT3 1%/* #undef HAVE_WAIT3 */%' $bionic_pyconfig
65
66 sed -i 's%#define SIZEOF_FPOS_T .*%#define SIZEOF_FPOS_T 8%' $bionic_pyconfig
67 sed -i 's%#define SIZEOF_LONG .*%#ifdef __LP64__\n#define SIZEOF_LONG 8\n#else\n#define SIZEOF_LONG 4\n#endif%' $bionic_pyconfig
68 sed -i 's%#define SIZEOF_LONG_DOUBLE .*%#define SIZEOF_LONG_DOUBLE (SIZEOF_LONG * 2)%' $bionic_pyconfig
69 sed -i 's%#define SIZEOF_PTHREAD_T .*%#define SIZEOF_PTHREAD_T SIZEOF_LONG%' $bionic_pyconfig
70 sed -i 's%#define SIZEOF_SIZE_T .*%#define SIZEOF_SIZE_T SIZEOF_LONG%' $bionic_pyconfig
71 sed -i 's%#define SIZEOF_TIME_T .*%#define SIZEOF_TIME_T SIZEOF_LONG%' $bionic_pyconfig
72 sed -i 's%#define SIZEOF_UINTPTR_T .*%#define SIZEOF_UINTPTR_T SIZEOF_LONG%' $bionic_pyconfig
73 sed -i 's%#define SIZEOF_VOID_P .*%#define SIZEOF_VOID_P SIZEOF_LONG%' $bionic_pyconfig
74fi
75
76function generate_srcs() {
77 #
78 # Generate config.c
79 #
80 echo >Makefile.pre
81 ../../../Modules/makesetup -c ../../../Modules/config.c.in -s Modules -m Makefile.pre ../Setup.local ../../Setup.local ../../../Modules/Setup
82 cp config.c ../
83
84 #
85 # Generate module file list
86 #
87 grep '$(CC)' Makefile | sed 's/;.*//' | sed 's/.*: //' | sed 's#$(srcdir)/##' | sort -u >srcs
88 (
89 echo '// Generated by android/regen.sh'
90 echo 'filegroup {'
91 echo " name: \"py3-c-modules-$1\","
92 echo " srcs: ["
93 for src in $(cat srcs); do
94 echo " \"${src}\","
95 done
96 echo " ],"
97 echo '}'
98 ) >../../../Android-$1.bp
99}
100
101generate_srcs $DIR
102
103cd ..
104rm -rf tmp
105
106if [ $DIR == "linux_x86_64" ]; then
107 mkdir ../bionic/tmp
108 pushd ../bionic/tmp
109 generate_srcs bionic
110 popd
111 rm -rf ../bionic/tmp
112fi