blob: 1bdc0702a08d7d67c7ca0c48e8d255f9daeb9e5d [file] [log] [blame]
Jayant Chowdharyea86c042018-01-25 12:07:55 -08001#!/bin/bash -ex
2
Logan Chienee954192018-10-04 10:52:41 +08003# Copyright 2018 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
Logan Chienfd2d41e2018-10-12 15:59:31 +080017export LLVM_BUILD_HOST_TOOLS=true
18export LLVM_PREBUILTS_VERSION=clang-r339409b
19export LLVM_RELEASE_VERSION=8.0.2
20
Jayant Chowdharyea86c042018-01-25 12:07:55 -080021if [ -z "${OUT_DIR}" ]; then
Logan Chien6c5889e2018-10-04 11:18:06 +080022 echo "error: Must set OUT_DIR"
Jayant Chowdharyea86c042018-01-25 12:07:55 -080023 exit 1
24fi
25
Logan Chienf59e2ee2018-10-04 13:43:49 +000026TOP=$(pwd)
Jayant Chowdharyea86c042018-01-25 12:07:55 -080027
28UNAME="$(uname)"
Logan Chien6c5889e2018-10-04 11:18:06 +080029case "${UNAME}" in
Jayant Chowdharyea86c042018-01-25 12:07:55 -080030Linux)
31 OS='linux'
32 ;;
33Darwin)
34 OS='darwin'
35 ;;
36*)
Logan Chien6c5889e2018-10-04 11:18:06 +080037 echo "error: Unknown uname: ${UNAME}"
Jayant Chowdharyea86c042018-01-25 12:07:55 -080038 exit 1
39 ;;
40esac
41
Logan Chien6c5889e2018-10-04 11:18:06 +080042# Setup Soong configuration
43SOONG_OUT="${OUT_DIR}/soong"
44SOONG_HOST_OUT="${OUT_DIR}/soong/host/${OS}-x86"
45rm -rf "${SOONG_OUT}"
46mkdir -p "${SOONG_OUT}"
47cat > "${SOONG_OUT}/soong.variables" << __EOF__
Jayant Chowdharyea86c042018-01-25 12:07:55 -080048{
49 "Allow_missing_dependencies": true,
Logan Chienf59e2ee2018-10-04 13:43:49 +000050 "HostArch":"x86_64"
Jayant Chowdharyea86c042018-01-25 12:07:55 -080051}
Logan Chien6c5889e2018-10-04 11:18:06 +080052__EOF__
53
54# Targets to be built
Jayant Chowdharyea86c042018-01-25 12:07:55 -080055SOONG_BINARIES=(
Logan Chien6c5889e2018-10-04 11:18:06 +080056 "header-abi-linker"
57 "header-abi-dumper"
58 "header-abi-diff"
59 "merge-abi-diff"
Jayant Chowdharyea86c042018-01-25 12:07:55 -080060)
61
Logan Chien6c5889e2018-10-04 11:18:06 +080062binaries=()
63for name in "${SOONG_BINARIES[@]}"; do
64 binaries+=("${SOONG_HOST_OUT}/bin/${name}")
65done
Jayant Chowdharyea86c042018-01-25 12:07:55 -080066
Logan Chienee8038c2018-10-12 15:55:52 +080067libs=()
68if [ "${OS}" = "darwin" ]; then
69 libs+=("${SOONG_HOST_OUT}/lib64/libc++abi_host.dylib")
70fi
71
Logan Chien6c5889e2018-10-04 11:18:06 +080072# Build binaries and shared libs
Logan Chienee8038c2018-10-12 15:55:52 +080073build/soong/soong_ui.bash --make-mode --skip-make "${binaries[@]}" "${libs[@]}"
Jayant Chowdharyea86c042018-01-25 12:07:55 -080074
Logan Chien6c5889e2018-10-04 11:18:06 +080075# Copy binaries and shared libs
76mkdir -p "${SOONG_OUT}/dist/bin"
77cp "${binaries[@]}" "${SOONG_OUT}/dist/bin/"
78cp -R "${SOONG_HOST_OUT}/lib"* "${SOONG_OUT}/dist/"
Jayant Chowdharyea86c042018-01-25 12:07:55 -080079
Logan Chienc3d85932018-10-04 11:24:13 +080080# Copy clang headers
Logan Chienfd2d41e2018-10-12 15:59:31 +080081cp -R "prebuilts/clang/host/${OS}-x86/${LLVM_PREBUILTS_VERSION}/lib64/clang/${LLVM_RELEASE_VERSION}/include" "${SOONG_OUT}/dist/clang-headers"
82
83# Normalize library file names. All library file names must match their soname.
84function extract_soname () {
85 local file="$1"
86
87 case "${OS}" in
88 linux)
89 readelf -d "${file}" | \
90 grep '(SONAME)\s*Library soname: \[.*\]$' -o | \
91 sed 's/(SONAME)\s*Library soname: \[\(.*\)\]$/\1/g'
92 ;;
93 darwin)
94 local install_path="$(otool -D "${file}" | sed -n 2p)"
95 if [ -n "${install_path}" ]; then
96 basename "${install_path}"
97 fi
98 ;;
99 esac
100}
101
102for file in "${SOONG_OUT}/dist/lib"*"/"*; do
103 soname="$(extract_soname "${file}")"
104 if [ -n "${soname}" -a "$(basename "${file}")" != "${soname}" ]; then
105 mv "${file}" "$(dirname "${file}")/${soname}"
106 fi
107done
Logan Chienc3d85932018-10-04 11:24:13 +0800108
Logan Chien6c5889e2018-10-04 11:18:06 +0800109# Package binaries and shared libs
Jayant Chowdharyea86c042018-01-25 12:07:55 -0800110(
Logan Chien6c5889e2018-10-04 11:18:06 +0800111 cd "${SOONG_OUT}/dist"
Jayant Chowdharyea86c042018-01-25 12:07:55 -0800112 zip -qryX build-prebuilts.zip *
113)
114
115if [ -n "${DIST_DIR}" ]; then
Logan Chien6c5889e2018-10-04 11:18:06 +0800116 mkdir -p "${DIST_DIR}" || true
117 cp "${SOONG_OUT}/dist/build-prebuilts.zip" "${DIST_DIR}/"
Jayant Chowdharyea86c042018-01-25 12:07:55 -0800118fi