blob: e41a74926c040d5c6bb21d8e655f1b4e3a1eb4f9 [file] [log] [blame]
#!/bin/bash -ex
#
# Copyright 2019 Google Inc. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Regenerate host configuration files for the current host
cd `dirname ${BASH_SOURCE[0]}`
ANDROID_BUILD_TOP=$(cd ../..; pwd)
UNAME=$(uname | tr 'A-Z' 'a-z')
NAME=linux_glibc
TARGET=glibc
config_opts=()
if [ $UNAME == "darwin" ]; then
NAME=darwin
TARGET=darwin
# vfork is deprecated on Mac, so always fallback to fork
config_opts+=("ac_cv_func_vfork=no")
# we'd need to link to libiconv
config_opts+=("am_cv_func_iconv=no")
else
export CC="$ANDROID_BUILD_TOP/prebuilts/clang/host/linux-x86/$(cd $ANDROID_BUILD_TOP; build/soong/scripts/get_clang_version.py)/bin/clang"
fi
if [ "$1" = "--musl" ]; then
NAME=linux_musl
TARGET=musl
sysroot="${ANDROID_BUILD_TOP}/prebuilts/build-tools/sysroots/x86_64-linux-musl"
export CFLAGS="--sysroot=${sysroot} -target x86_64-linux-musl -fuse-ld=lld"
export LDFLAGS="--rtlib=compiler-rt"
fi
if [ $NAME == "linux_glibc" ]; then
export CFLAGS="--sysroot=$ANDROID_BUILD_TOP/prebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.17-4.8/sysroot"
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"
fi
DIR=$NAME-lib
mkdir -p $DIR
cd $DIR
rm -rf tmp
mkdir tmp
cd tmp
../../configure \
--disable-nls \
--enable-relocatable \
--prefix=/nonexistent \
--exec-prefix=/nonexistent/$NAME-x86 \
--datarootdir=/nonexistent/common \
"${config_opts[@]}"
# Don't try to use aclocal/automake/etc
touch ../../aclocal.m4
touch ../../configure
touch ../../Makefile.in
# Don't attempt to update source timestamps
touch ../../doc/stamp-vti
make -fMakefile Makefile
echo 'gensrcs: $(BUILT_SOURCES)' >>Makefile
make -fMakefile gensrcs
make -fMakefile src/bison
mkdir -p ../malloc
rm -rf ../*.h ../malloc/*.h
mv lib/*.h ../
mv lib/malloc/*.h ../malloc/
GENBP=../Android.bp
rm -f $GENBP
cat >$GENBP <<END
// Autogenerated by android_regen.sh
cc_defaults {
name: "libbison_${NAME}_defaults",
target: {
$TARGET: {
srcs: [
$(find lib -name '*.o' | sed "s/libbison_a-//" | sed -E "s/(.*)\.o/\"\1\.c\",/" | LC_ALL=C sort)
],
},
},
}
cc_defaults {
name: "bison_${NAME}_defaults",
target: {
$TARGET: {
srcs: [
$(find src -name '*.o' | sed "s/bison-//" | sed -E "s/(.*)\.o/\"\1\.c\",/" | LC_ALL=C sort)
],
},
},
}
END
${ANDROID_BUILD_TOP}/prebuilts/build-tools/$UNAME-x86/bin/bpfmt -w $GENBP
cd ../
rm -rf tmp