aboutsummaryrefslogtreecommitdiff
path: root/soong/regen.sh
blob: 1089fd90a176c75bde2936773ff9d1b1f53c6b65 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/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

cd lib
find . -name '*.h' | xargs -IX cp X ../../X
cd ../..
rm -rf tmp