blob: 6cad17f81fde71bee0bdc1dbb6ba4f23023bbffa [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
if [ $UNAME == "darwin" ]; then
NAME=darwin
TARGET=darwin
fi
if [ "$1" = "--musl_sysroot" ]; then
NAME=linux_musl
TARGET=musl
sysroot=$2
export CC="${sysroot}/bin/musl-clang"
export LDFLAGS="--rtlib=compiler-rt"
fi
if [ $NAME == "linux_glibc" ]; then
export CC="$ANDROID_BUILD_TOP/prebuilts/clang/host/linux-x86/$(cd $ANDROID_BUILD_TOP; build/soong/scripts/get_clang_version.py)/bin/clang"
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
echo 'gensrcs: $(BUILT_SOURCES)' >>Makefile
make -fMakefile gensrcs
make -fMakefile src/bison
mv lib/*.h ../
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