blob: 653c833c2bc0210da9a3e43ffcfd384ff0fdc3ef [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
Logan Chieneb644b92019-06-20 14:25:42 -070018export LLVM_PREBUILTS_VERSION=clang-r353983d
19export LLVM_RELEASE_VERSION=9.0.4
Logan Chienfd2d41e2018-10-12 15:59:31 +080020
Logan Chien72dc0302018-10-18 10:56:26 +080021# FIXME: Workaround to build bionic versioner in the aosp/clang-tools branch.
22export FORCE_BUILD_LLVM_COMPONENTS=true
23
Jayant Chowdharyea86c042018-01-25 12:07:55 -080024if [ -z "${OUT_DIR}" ]; then
Logan Chien6c5889e2018-10-04 11:18:06 +080025 echo "error: Must set OUT_DIR"
Jayant Chowdharyea86c042018-01-25 12:07:55 -080026 exit 1
27fi
28
Logan Chienf59e2ee2018-10-04 13:43:49 +000029TOP=$(pwd)
Jayant Chowdharyea86c042018-01-25 12:07:55 -080030
31UNAME="$(uname)"
Logan Chien6c5889e2018-10-04 11:18:06 +080032case "${UNAME}" in
Jayant Chowdharyea86c042018-01-25 12:07:55 -080033Linux)
34 OS='linux'
35 ;;
36Darwin)
37 OS='darwin'
38 ;;
39*)
Logan Chien6c5889e2018-10-04 11:18:06 +080040 echo "error: Unknown uname: ${UNAME}"
Jayant Chowdharyea86c042018-01-25 12:07:55 -080041 exit 1
42 ;;
43esac
44
Logan Chien6c5889e2018-10-04 11:18:06 +080045# Setup Soong configuration
46SOONG_OUT="${OUT_DIR}/soong"
47SOONG_HOST_OUT="${OUT_DIR}/soong/host/${OS}-x86"
48rm -rf "${SOONG_OUT}"
49mkdir -p "${SOONG_OUT}"
50cat > "${SOONG_OUT}/soong.variables" << __EOF__
Jayant Chowdharyea86c042018-01-25 12:07:55 -080051{
52 "Allow_missing_dependencies": true,
Logan Chienf59e2ee2018-10-04 13:43:49 +000053 "HostArch":"x86_64"
Jayant Chowdharyea86c042018-01-25 12:07:55 -080054}
Logan Chien6c5889e2018-10-04 11:18:06 +080055__EOF__
56
57# Targets to be built
Jayant Chowdharyea86c042018-01-25 12:07:55 -080058SOONG_BINARIES=(
Logan Chien6c5889e2018-10-04 11:18:06 +080059 "header-abi-linker"
60 "header-abi-dumper"
61 "header-abi-diff"
62 "merge-abi-diff"
Logan Chien72dc0302018-10-18 10:56:26 +080063 "versioner"
Jayant Chowdharyea86c042018-01-25 12:07:55 -080064)
65
Logan Chien6c5889e2018-10-04 11:18:06 +080066binaries=()
67for name in "${SOONG_BINARIES[@]}"; do
68 binaries+=("${SOONG_HOST_OUT}/bin/${name}")
69done
Jayant Chowdharyea86c042018-01-25 12:07:55 -080070
Logan Chienee8038c2018-10-12 15:55:52 +080071libs=()
72if [ "${OS}" = "darwin" ]; then
73 libs+=("${SOONG_HOST_OUT}/lib64/libc++abi_host.dylib")
74fi
75
Logan Chien6c5889e2018-10-04 11:18:06 +080076# Build binaries and shared libs
Logan Chienee8038c2018-10-12 15:55:52 +080077build/soong/soong_ui.bash --make-mode --skip-make "${binaries[@]}" "${libs[@]}"
Jayant Chowdharyea86c042018-01-25 12:07:55 -080078
Logan Chien6c5889e2018-10-04 11:18:06 +080079# Copy binaries and shared libs
Logan Chien5bc46b82018-11-08 14:40:07 +080080SOONG_DIST="${SOONG_OUT}/dist"
81mkdir -p "${SOONG_DIST}/bin"
82cp "${binaries[@]}" "${SOONG_DIST}/bin"
83cp -R "${SOONG_HOST_OUT}/lib"* "${SOONG_DIST}"
Jayant Chowdharyea86c042018-01-25 12:07:55 -080084
Logan Chien5bc46b82018-11-08 14:40:07 +080085# Copy clang header and share files
86CLANG_DIR="prebuilts/clang/host/${OS}-x86/${LLVM_PREBUILTS_VERSION}"
87CLANG_LIB_DIR="${CLANG_DIR}/lib64/clang/${LLVM_RELEASE_VERSION}"
88CLANG_LIB_DIR_OUT="${SOONG_DIST}/lib64/clang/${LLVM_RELEASE_VERSION}"
89mkdir -p "${CLANG_LIB_DIR_OUT}"
90cp -R "${CLANG_LIB_DIR}/share" "${CLANG_LIB_DIR_OUT}/share"
91cp -R "${CLANG_LIB_DIR}/include" "${CLANG_LIB_DIR_OUT}/include"
92ln -s "lib64/clang/${LLVM_RELEASE_VERSION}/include" "${SOONG_DIST}/clang-headers"
Logan Chienfd2d41e2018-10-12 15:59:31 +080093
94# Normalize library file names. All library file names must match their soname.
95function extract_soname () {
96 local file="$1"
97
98 case "${OS}" in
99 linux)
100 readelf -d "${file}" | \
101 grep '(SONAME)\s*Library soname: \[.*\]$' -o | \
102 sed 's/(SONAME)\s*Library soname: \[\(.*\)\]$/\1/g'
103 ;;
104 darwin)
105 local install_path="$(otool -D "${file}" | sed -n 2p)"
106 if [ -n "${install_path}" ]; then
107 basename "${install_path}"
108 fi
109 ;;
110 esac
111}
112
113for file in "${SOONG_OUT}/dist/lib"*"/"*; do
114 soname="$(extract_soname "${file}")"
115 if [ -n "${soname}" -a "$(basename "${file}")" != "${soname}" ]; then
116 mv "${file}" "$(dirname "${file}")/${soname}"
117 fi
118done
Logan Chienc3d85932018-10-04 11:24:13 +0800119
Logan Chien6c5889e2018-10-04 11:18:06 +0800120# Package binaries and shared libs
Jayant Chowdharyea86c042018-01-25 12:07:55 -0800121(
Logan Chien6c5889e2018-10-04 11:18:06 +0800122 cd "${SOONG_OUT}/dist"
Jayant Chowdharyea86c042018-01-25 12:07:55 -0800123 zip -qryX build-prebuilts.zip *
124)
125
126if [ -n "${DIST_DIR}" ]; then
Logan Chien6c5889e2018-10-04 11:18:06 +0800127 mkdir -p "${DIST_DIR}" || true
128 cp "${SOONG_OUT}/dist/build-prebuilts.zip" "${DIST_DIR}/"
Jayant Chowdharyea86c042018-01-25 12:07:55 -0800129fi