Jayant Chowdhary | ea86c04 | 2018-01-25 12:07:55 -0800 | [diff] [blame] | 1 | #!/bin/bash -ex |
| 2 | |
Logan Chien | ee95419 | 2018-10-04 10:52:41 +0800 | [diff] [blame] | 3 | # 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 Chien | fd2d41e | 2018-10-12 15:59:31 +0800 | [diff] [blame] | 17 | export LLVM_BUILD_HOST_TOOLS=true |
Logan Chien | eb644b9 | 2019-06-20 14:25:42 -0700 | [diff] [blame] | 18 | export LLVM_PREBUILTS_VERSION=clang-r353983d |
| 19 | export LLVM_RELEASE_VERSION=9.0.4 |
Logan Chien | fd2d41e | 2018-10-12 15:59:31 +0800 | [diff] [blame] | 20 | |
Logan Chien | 72dc030 | 2018-10-18 10:56:26 +0800 | [diff] [blame] | 21 | # FIXME: Workaround to build bionic versioner in the aosp/clang-tools branch. |
| 22 | export FORCE_BUILD_LLVM_COMPONENTS=true |
| 23 | |
Jayant Chowdhary | ea86c04 | 2018-01-25 12:07:55 -0800 | [diff] [blame] | 24 | if [ -z "${OUT_DIR}" ]; then |
Logan Chien | 6c5889e | 2018-10-04 11:18:06 +0800 | [diff] [blame] | 25 | echo "error: Must set OUT_DIR" |
Jayant Chowdhary | ea86c04 | 2018-01-25 12:07:55 -0800 | [diff] [blame] | 26 | exit 1 |
| 27 | fi |
| 28 | |
Logan Chien | f59e2ee | 2018-10-04 13:43:49 +0000 | [diff] [blame] | 29 | TOP=$(pwd) |
Jayant Chowdhary | ea86c04 | 2018-01-25 12:07:55 -0800 | [diff] [blame] | 30 | |
| 31 | UNAME="$(uname)" |
Logan Chien | 6c5889e | 2018-10-04 11:18:06 +0800 | [diff] [blame] | 32 | case "${UNAME}" in |
Jayant Chowdhary | ea86c04 | 2018-01-25 12:07:55 -0800 | [diff] [blame] | 33 | Linux) |
| 34 | OS='linux' |
| 35 | ;; |
| 36 | Darwin) |
| 37 | OS='darwin' |
| 38 | ;; |
| 39 | *) |
Logan Chien | 6c5889e | 2018-10-04 11:18:06 +0800 | [diff] [blame] | 40 | echo "error: Unknown uname: ${UNAME}" |
Jayant Chowdhary | ea86c04 | 2018-01-25 12:07:55 -0800 | [diff] [blame] | 41 | exit 1 |
| 42 | ;; |
| 43 | esac |
| 44 | |
Logan Chien | 6c5889e | 2018-10-04 11:18:06 +0800 | [diff] [blame] | 45 | # Setup Soong configuration |
| 46 | SOONG_OUT="${OUT_DIR}/soong" |
| 47 | SOONG_HOST_OUT="${OUT_DIR}/soong/host/${OS}-x86" |
| 48 | rm -rf "${SOONG_OUT}" |
| 49 | mkdir -p "${SOONG_OUT}" |
| 50 | cat > "${SOONG_OUT}/soong.variables" << __EOF__ |
Jayant Chowdhary | ea86c04 | 2018-01-25 12:07:55 -0800 | [diff] [blame] | 51 | { |
| 52 | "Allow_missing_dependencies": true, |
Logan Chien | f59e2ee | 2018-10-04 13:43:49 +0000 | [diff] [blame] | 53 | "HostArch":"x86_64" |
Jayant Chowdhary | ea86c04 | 2018-01-25 12:07:55 -0800 | [diff] [blame] | 54 | } |
Logan Chien | 6c5889e | 2018-10-04 11:18:06 +0800 | [diff] [blame] | 55 | __EOF__ |
| 56 | |
| 57 | # Targets to be built |
Jayant Chowdhary | ea86c04 | 2018-01-25 12:07:55 -0800 | [diff] [blame] | 58 | SOONG_BINARIES=( |
Logan Chien | 6c5889e | 2018-10-04 11:18:06 +0800 | [diff] [blame] | 59 | "header-abi-linker" |
| 60 | "header-abi-dumper" |
| 61 | "header-abi-diff" |
| 62 | "merge-abi-diff" |
Logan Chien | 72dc030 | 2018-10-18 10:56:26 +0800 | [diff] [blame] | 63 | "versioner" |
Jayant Chowdhary | ea86c04 | 2018-01-25 12:07:55 -0800 | [diff] [blame] | 64 | ) |
| 65 | |
Logan Chien | 6c5889e | 2018-10-04 11:18:06 +0800 | [diff] [blame] | 66 | binaries=() |
| 67 | for name in "${SOONG_BINARIES[@]}"; do |
| 68 | binaries+=("${SOONG_HOST_OUT}/bin/${name}") |
| 69 | done |
Jayant Chowdhary | ea86c04 | 2018-01-25 12:07:55 -0800 | [diff] [blame] | 70 | |
Logan Chien | ee8038c | 2018-10-12 15:55:52 +0800 | [diff] [blame] | 71 | libs=() |
| 72 | if [ "${OS}" = "darwin" ]; then |
| 73 | libs+=("${SOONG_HOST_OUT}/lib64/libc++abi_host.dylib") |
| 74 | fi |
| 75 | |
Logan Chien | 6c5889e | 2018-10-04 11:18:06 +0800 | [diff] [blame] | 76 | # Build binaries and shared libs |
Logan Chien | ee8038c | 2018-10-12 15:55:52 +0800 | [diff] [blame] | 77 | build/soong/soong_ui.bash --make-mode --skip-make "${binaries[@]}" "${libs[@]}" |
Jayant Chowdhary | ea86c04 | 2018-01-25 12:07:55 -0800 | [diff] [blame] | 78 | |
Logan Chien | 6c5889e | 2018-10-04 11:18:06 +0800 | [diff] [blame] | 79 | # Copy binaries and shared libs |
Logan Chien | 5bc46b8 | 2018-11-08 14:40:07 +0800 | [diff] [blame] | 80 | SOONG_DIST="${SOONG_OUT}/dist" |
| 81 | mkdir -p "${SOONG_DIST}/bin" |
| 82 | cp "${binaries[@]}" "${SOONG_DIST}/bin" |
| 83 | cp -R "${SOONG_HOST_OUT}/lib"* "${SOONG_DIST}" |
Jayant Chowdhary | ea86c04 | 2018-01-25 12:07:55 -0800 | [diff] [blame] | 84 | |
Logan Chien | 5bc46b8 | 2018-11-08 14:40:07 +0800 | [diff] [blame] | 85 | # Copy clang header and share files |
| 86 | CLANG_DIR="prebuilts/clang/host/${OS}-x86/${LLVM_PREBUILTS_VERSION}" |
| 87 | CLANG_LIB_DIR="${CLANG_DIR}/lib64/clang/${LLVM_RELEASE_VERSION}" |
| 88 | CLANG_LIB_DIR_OUT="${SOONG_DIST}/lib64/clang/${LLVM_RELEASE_VERSION}" |
| 89 | mkdir -p "${CLANG_LIB_DIR_OUT}" |
| 90 | cp -R "${CLANG_LIB_DIR}/share" "${CLANG_LIB_DIR_OUT}/share" |
| 91 | cp -R "${CLANG_LIB_DIR}/include" "${CLANG_LIB_DIR_OUT}/include" |
| 92 | ln -s "lib64/clang/${LLVM_RELEASE_VERSION}/include" "${SOONG_DIST}/clang-headers" |
Logan Chien | fd2d41e | 2018-10-12 15:59:31 +0800 | [diff] [blame] | 93 | |
| 94 | # Normalize library file names. All library file names must match their soname. |
| 95 | function 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 | |
| 113 | for 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 |
| 118 | done |
Logan Chien | c3d8593 | 2018-10-04 11:24:13 +0800 | [diff] [blame] | 119 | |
Logan Chien | 6c5889e | 2018-10-04 11:18:06 +0800 | [diff] [blame] | 120 | # Package binaries and shared libs |
Jayant Chowdhary | ea86c04 | 2018-01-25 12:07:55 -0800 | [diff] [blame] | 121 | ( |
Logan Chien | 6c5889e | 2018-10-04 11:18:06 +0800 | [diff] [blame] | 122 | cd "${SOONG_OUT}/dist" |
Jayant Chowdhary | ea86c04 | 2018-01-25 12:07:55 -0800 | [diff] [blame] | 123 | zip -qryX build-prebuilts.zip * |
| 124 | ) |
| 125 | |
| 126 | if [ -n "${DIST_DIR}" ]; then |
Logan Chien | 6c5889e | 2018-10-04 11:18:06 +0800 | [diff] [blame] | 127 | mkdir -p "${DIST_DIR}" || true |
| 128 | cp "${SOONG_OUT}/dist/build-prebuilts.zip" "${DIST_DIR}/" |
Jayant Chowdhary | ea86c04 | 2018-01-25 12:07:55 -0800 | [diff] [blame] | 129 | fi |