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 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 28 export CC="$ANDROID_BUILD_TOP/prebuilts/clang/host/linux-x86/clang-r365631c/bin/clang" 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" 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 45fi 46 47cp pyconfig.h ../pyconfig/ 48 49if [ $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 71fi 72 73function generate_srcs() { 74 # 75 # Generate config.c 76 # 77 echo >Makefile.pre 78 ../../../Modules/makesetup -c ../../../Modules/config.c.in -s Modules -m Makefile.pre ../Setup.local ../../Setup.local ../../../Modules/Setup 79 cp config.c ../ 80 81 # 82 # Generate module file list 83 # 84 grep '$(CC)' Makefile | sed 's/;.*//' | sed 's/.*: //' | sed 's#$(srcdir)/##' | sort -u >srcs 85 ( 86 echo '// Generated by android/regen.sh' 87 echo 'filegroup {' 88 echo " name: \"py3-c-modules-$1\"," 89 echo " srcs: [" 90 for src in $(cat srcs); do 91 echo " \"${src}\"," 92 done 93 echo " ]," 94 echo '}' 95 ) >../../../Android-$1.bp 96} 97 98generate_srcs $DIR 99 100cd .. 101rm -rf tmp 102 103if [ $DIR == "linux_x86_64" ]; then 104 mkdir ../bionic/tmp 105 pushd ../bionic/tmp 106 generate_srcs bionic 107 popd 108 rm -rf ../bionic/tmp 109fi 110