blob: ea040767a0ec11fc06518204db11283b00e1c745 [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
Dan Willemsen2b32bc32022-03-22 21:53:15 -070027export CLANG_VERSION=$(cd $ANDROID_BUILD_TOP; build/soong/scripts/get_clang_version.py)
28
Dan Willemsenb3614d22019-10-07 16:06:34 -070029if [ $DIR == "linux_x86_64" ]; then
Dan Willemsen2b32bc32022-03-22 21:53:15 -070030 export CC="$ANDROID_BUILD_TOP/prebuilts/clang/host/linux-x86/$CLANG_VERSION/bin/clang"
Dan Willemsenb3614d22019-10-07 16:06:34 -070031 export CFLAGS="--sysroot=$ANDROID_BUILD_TOP/prebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.17-4.8/sysroot"
32 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"
33fi
34
35#
36# Generate pyconfig.h
37#
38rm -rf tmp
39mkdir tmp
40cd tmp
41../../../configure
42
43if [ $DIR == "darwin_x86_64" ]; then
Dan Willemsenf4dc1922020-12-23 19:03:46 -080044 # preadv and pwritev are not safe on <11, which we still target
45 sed -ibak "s%#define HAVE_PREADV 1%/* #undef HAVE_PREADV */%" pyconfig.h
46 sed -ibak "s%#define HAVE_PWRITEV 1%/* #undef HAVE_PWRITEV */%" pyconfig.h
Dan Willemsenb3614d22019-10-07 16:06:34 -070047fi
48
Dan Willemsenb3614d22019-10-07 16:06:34 -070049if [ $DIR == "linux_x86_64" ]; then
50 mkdir -p ../../bionic/pyconfig
51 cp pyconfig.h ../../bionic/pyconfig/
52 # Changes to support bionic
53 bionic_pyconfig=../../bionic/pyconfig/pyconfig.h
54 sed -i 's%#define HAVE_CONFSTR 1%/* #undef HAVE_CONFSTR */%' $bionic_pyconfig
55 sed -i 's%#define HAVE_CRYPT_H 1%/* #undef HAVE_CRYPT_H */%' $bionic_pyconfig
56 sed -i 's%#define HAVE_CRYPT_R 1%/* #undef HAVE_CRYPT_R */%' $bionic_pyconfig
57 sed -i 's%#define HAVE_DECL_RTLD_DEEPBIND 1%/* #undef HAVE_DECL_RTLD_DEEPBIND */%' $bionic_pyconfig
58 sed -i "s%#define HAVE_GCC_ASM_FOR_X87 1%#ifdef __i386__\n#define HAVE_GCC_ASM_FOR_X87 1\n#endif%" $bionic_pyconfig
59 sed -i 's%#define HAVE_LIBINTL_H 1%/* #undef HAVE_LIBINTL_H */%' $bionic_pyconfig
60 sed -i 's%#define HAVE_STROPTS_H 1%/* #undef HAVE_STROPTS_H */%' $bionic_pyconfig
61 sed -i 's%#define HAVE_WAIT3 1%/* #undef HAVE_WAIT3 */%' $bionic_pyconfig
62
63 sed -i 's%#define SIZEOF_FPOS_T .*%#define SIZEOF_FPOS_T 8%' $bionic_pyconfig
64 sed -i 's%#define SIZEOF_LONG .*%#ifdef __LP64__\n#define SIZEOF_LONG 8\n#else\n#define SIZEOF_LONG 4\n#endif%' $bionic_pyconfig
65 sed -i 's%#define SIZEOF_LONG_DOUBLE .*%#define SIZEOF_LONG_DOUBLE (SIZEOF_LONG * 2)%' $bionic_pyconfig
66 sed -i 's%#define SIZEOF_PTHREAD_T .*%#define SIZEOF_PTHREAD_T SIZEOF_LONG%' $bionic_pyconfig
67 sed -i 's%#define SIZEOF_SIZE_T .*%#define SIZEOF_SIZE_T SIZEOF_LONG%' $bionic_pyconfig
68 sed -i 's%#define SIZEOF_TIME_T .*%#define SIZEOF_TIME_T SIZEOF_LONG%' $bionic_pyconfig
69 sed -i 's%#define SIZEOF_UINTPTR_T .*%#define SIZEOF_UINTPTR_T SIZEOF_LONG%' $bionic_pyconfig
70 sed -i 's%#define SIZEOF_VOID_P .*%#define SIZEOF_VOID_P SIZEOF_LONG%' $bionic_pyconfig
Dan Willemsen2b32bc32022-03-22 21:53:15 -070071
72 # Changes to support musl
73 sed -i "s%#define HAVE_DECL_RTLD_DEEPBIND 1%#ifdef __GLIBC__\n#define HAVE_DECL_RTLD_DEEPBIND 1\n#endif%" pyconfig.h
Dan Willemsenb3614d22019-10-07 16:06:34 -070074fi
75
Dan Willemsen2b32bc32022-03-22 21:53:15 -070076cp pyconfig.h ../pyconfig/
77
Dan Willemsenb3614d22019-10-07 16:06:34 -070078function generate_srcs() {
79 #
80 # Generate config.c
81 #
82 echo >Makefile.pre
83 ../../../Modules/makesetup -c ../../../Modules/config.c.in -s Modules -m Makefile.pre ../Setup.local ../../Setup.local ../../../Modules/Setup
84 cp config.c ../
85
86 #
87 # Generate module file list
88 #
89 grep '$(CC)' Makefile | sed 's/;.*//' | sed 's/.*: //' | sed 's#$(srcdir)/##' | sort -u >srcs
90 (
91 echo '// Generated by android/regen.sh'
92 echo 'filegroup {'
93 echo " name: \"py3-c-modules-$1\","
94 echo " srcs: ["
95 for src in $(cat srcs); do
96 echo " \"${src}\","
97 done
98 echo " ],"
99 echo '}'
100 ) >../../../Android-$1.bp
101}
102
103generate_srcs $DIR
104
105cd ..
106rm -rf tmp
107
108if [ $DIR == "linux_x86_64" ]; then
109 mkdir ../bionic/tmp
110 pushd ../bionic/tmp
111 generate_srcs bionic
112 popd
113 rm -rf ../bionic/tmp
114fi