blob: d15072e0f3c9611a964ca96e4482c8054046ce43 [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)
clang_version=$(cd $ANDROID_BUILD_TOP; build/soong/scripts/get_clang_version.py)
UNAME=$(uname | tr 'A-Z' 'a-z')
DIR=linux_glibc
TARGET=glibc
if [ $UNAME == "darwin" ]; then
DIR=darwin
TARGET=darwin
elif [ "$1" = "--musl" ]; then
DIR=linux_musl
TARGET=musl
fi
if [ $UNAME == "linux" ]; then
CC="$ANDROID_BUILD_TOP/prebuilts/clang/host/linux-x86/$clang_version/bin/clang"
fi
CFLAGS=""
LDLFAGS=""
config_opts=()
if [ $DIR = "linux_glibc" ]; then
glibc="${ANDROID_BUILD_TOP}/prebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.17-4.8"
CFLAGS="--sysroot=${glibc}/sysroot"
LDFLAGS="--sysroot=${glibc}/sysroot -B${glibc}/lib/gcc/x86_64-linux/4.8.3 -L${glibc}lib/gcc/x86_64-linux/4.8.3 -L${glibc}/x86_64-linux/lib64 --rtlib=compiler-rt"
elif [ $DIR = "linux_musl" ]; then
sysroot="${ANDROID_BUILD_TOP}/prebuilts/build-tools/sysroots/x86_64-linux-musl"
CFLAGS="--sysroot=${sysroot} -target x86_64-linux-musl"
LDFLAGS="--rtlib=compiler-rt -fuse-ld=lld"
elif [ $DIR = "darwin" ]; then
# 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")
fi
rm -rf $DIR
mkdir -p $DIR $DIR/sys
cd $DIR
# Generate headers
rm -rf tmp
mkdir tmp
cd tmp
../../../configure CC=$CC CXX=$CC CFLAGS="${CFLAGS}" LDFLAGS="${LDFLAGS}" "${config_opts[@]}"
# Don't try to use various tools to update the source tree:
# aclocal/automake/etc
touch ../../../aclocal.m4
touch ../../../configure
touch ../../../Makefile.in
# autoheader
touch ../../../lib/config.hin
# doc/...
touch ../../../doc/stamp-vti
touch ../../../doc/m4.info
touch ../../../doc/m4.1
make
cat >../Android.bp <<END
// Autogenerated by android_regen.sh
cc_defaults {
name: "m4_${TARGET}_defaults",
target: {
$TARGET: {
srcs: [
$(find lib src -name '*.o' | sed -E "s/(.*)\.o/\"\1\.c\",/" | LC_ALL=C sort)
],
},
},
}
END
${ANDROID_BUILD_TOP}/prebuilts/build-tools/$UNAME-x86/bin/bpfmt -w ../Android.bp
sed -ibak 's%#define __x86_64__ 1%/* compiler-set */%' lib/config.h
cd lib
find . -name '*.h' | xargs -IX cp X ../../X
cd ../..
rm -rf tmp