Dan Willemsen | b3614d2 | 2019-10-07 16:06:34 -0700 | [diff] [blame] | 1 | #!/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 | |
| 19 | cd `dirname ${BASH_SOURCE[0]}` |
| 20 | |
| 21 | ANDROID_BUILD_TOP=$(cd ../../../..; pwd) |
| 22 | |
| 23 | DIR=`uname | tr 'A-Z' 'a-z'`_x86_64 |
| 24 | mkdir -p $DIR/pyconfig |
| 25 | cd $DIR |
| 26 | |
| 27 | if [ $DIR == "linux_x86_64" ]; then |
Haibo Huang | 5bb95e9 | 2021-01-14 11:35:14 -0800 | [diff] [blame] | 28 | export CC="$ANDROID_BUILD_TOP/prebuilts/clang/host/linux-x86/clang-r399163b/bin/clang" |
Dan Willemsen | b3614d2 | 2019-10-07 16:06:34 -0700 | [diff] [blame] | 29 | 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" |
| 31 | fi |
| 32 | |
| 33 | # |
| 34 | # Generate pyconfig.h |
| 35 | # |
| 36 | rm -rf tmp |
| 37 | mkdir tmp |
| 38 | cd tmp |
| 39 | ../../../configure |
| 40 | |
| 41 | if [ $DIR == "darwin_x86_64" ]; then |
Dan Willemsen | d948d44 | 2021-02-16 21:10:24 -0800 | [diff] [blame] | 42 | # 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 Willemsen | b3614d2 | 2019-10-07 16:06:34 -0700 | [diff] [blame] | 44 | # 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 Willemsen | f4dc192 | 2020-12-23 19:03:46 -0800 | [diff] [blame] | 47 | # 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 Willemsen | 2c451f8 | 2021-01-25 17:43:33 -0800 | [diff] [blame] | 50 | # _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 Willemsen | b3614d2 | 2019-10-07 16:06:34 -0700 | [diff] [blame] | 52 | fi |
| 53 | |
| 54 | cp pyconfig.h ../pyconfig/ |
| 55 | |
| 56 | if [ $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 |
| 78 | fi |
| 79 | |
| 80 | function 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 | |
| 105 | generate_srcs $DIR |
| 106 | |
| 107 | cd .. |
| 108 | rm -rf tmp |
| 109 | |
| 110 | if [ $DIR == "linux_x86_64" ]; then |
| 111 | mkdir ../bionic/tmp |
| 112 | pushd ../bionic/tmp |
| 113 | generate_srcs bionic |
| 114 | popd |
| 115 | rm -rf ../bionic/tmp |
| 116 | fi |