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 |
| 18 | export LLVM_PREBUILTS_VERSION=clang-r339409b |
| 19 | export LLVM_RELEASE_VERSION=8.0.2 |
| 20 | |
Jayant Chowdhary | ea86c04 | 2018-01-25 12:07:55 -0800 | [diff] [blame] | 21 | if [ -z "${OUT_DIR}" ]; then |
Logan Chien | 6c5889e | 2018-10-04 11:18:06 +0800 | [diff] [blame] | 22 | echo "error: Must set OUT_DIR" |
Jayant Chowdhary | ea86c04 | 2018-01-25 12:07:55 -0800 | [diff] [blame] | 23 | exit 1 |
| 24 | fi |
| 25 | |
Logan Chien | f59e2ee | 2018-10-04 13:43:49 +0000 | [diff] [blame] | 26 | TOP=$(pwd) |
Jayant Chowdhary | ea86c04 | 2018-01-25 12:07:55 -0800 | [diff] [blame] | 27 | |
| 28 | UNAME="$(uname)" |
Logan Chien | 6c5889e | 2018-10-04 11:18:06 +0800 | [diff] [blame] | 29 | case "${UNAME}" in |
Jayant Chowdhary | ea86c04 | 2018-01-25 12:07:55 -0800 | [diff] [blame] | 30 | Linux) |
| 31 | OS='linux' |
| 32 | ;; |
| 33 | Darwin) |
| 34 | OS='darwin' |
| 35 | ;; |
| 36 | *) |
Logan Chien | 6c5889e | 2018-10-04 11:18:06 +0800 | [diff] [blame] | 37 | echo "error: Unknown uname: ${UNAME}" |
Jayant Chowdhary | ea86c04 | 2018-01-25 12:07:55 -0800 | [diff] [blame] | 38 | exit 1 |
| 39 | ;; |
| 40 | esac |
| 41 | |
Logan Chien | 6c5889e | 2018-10-04 11:18:06 +0800 | [diff] [blame] | 42 | # Setup Soong configuration |
| 43 | SOONG_OUT="${OUT_DIR}/soong" |
| 44 | SOONG_HOST_OUT="${OUT_DIR}/soong/host/${OS}-x86" |
| 45 | rm -rf "${SOONG_OUT}" |
| 46 | mkdir -p "${SOONG_OUT}" |
| 47 | cat > "${SOONG_OUT}/soong.variables" << __EOF__ |
Jayant Chowdhary | ea86c04 | 2018-01-25 12:07:55 -0800 | [diff] [blame] | 48 | { |
| 49 | "Allow_missing_dependencies": true, |
Logan Chien | f59e2ee | 2018-10-04 13:43:49 +0000 | [diff] [blame] | 50 | "HostArch":"x86_64" |
Jayant Chowdhary | ea86c04 | 2018-01-25 12:07:55 -0800 | [diff] [blame] | 51 | } |
Logan Chien | 6c5889e | 2018-10-04 11:18:06 +0800 | [diff] [blame] | 52 | __EOF__ |
| 53 | |
| 54 | # Targets to be built |
Jayant Chowdhary | ea86c04 | 2018-01-25 12:07:55 -0800 | [diff] [blame] | 55 | SOONG_BINARIES=( |
Logan Chien | 6c5889e | 2018-10-04 11:18:06 +0800 | [diff] [blame] | 56 | "header-abi-linker" |
| 57 | "header-abi-dumper" |
| 58 | "header-abi-diff" |
| 59 | "merge-abi-diff" |
Jayant Chowdhary | ea86c04 | 2018-01-25 12:07:55 -0800 | [diff] [blame] | 60 | ) |
| 61 | |
Logan Chien | 6c5889e | 2018-10-04 11:18:06 +0800 | [diff] [blame] | 62 | binaries=() |
| 63 | for name in "${SOONG_BINARIES[@]}"; do |
| 64 | binaries+=("${SOONG_HOST_OUT}/bin/${name}") |
| 65 | done |
Jayant Chowdhary | ea86c04 | 2018-01-25 12:07:55 -0800 | [diff] [blame] | 66 | |
Logan Chien | ee8038c | 2018-10-12 15:55:52 +0800 | [diff] [blame] | 67 | libs=() |
| 68 | if [ "${OS}" = "darwin" ]; then |
| 69 | libs+=("${SOONG_HOST_OUT}/lib64/libc++abi_host.dylib") |
| 70 | fi |
| 71 | |
Logan Chien | 6c5889e | 2018-10-04 11:18:06 +0800 | [diff] [blame] | 72 | # Build binaries and shared libs |
Logan Chien | ee8038c | 2018-10-12 15:55:52 +0800 | [diff] [blame] | 73 | build/soong/soong_ui.bash --make-mode --skip-make "${binaries[@]}" "${libs[@]}" |
Jayant Chowdhary | ea86c04 | 2018-01-25 12:07:55 -0800 | [diff] [blame] | 74 | |
Logan Chien | 6c5889e | 2018-10-04 11:18:06 +0800 | [diff] [blame] | 75 | # Copy binaries and shared libs |
| 76 | mkdir -p "${SOONG_OUT}/dist/bin" |
| 77 | cp "${binaries[@]}" "${SOONG_OUT}/dist/bin/" |
| 78 | cp -R "${SOONG_HOST_OUT}/lib"* "${SOONG_OUT}/dist/" |
Jayant Chowdhary | ea86c04 | 2018-01-25 12:07:55 -0800 | [diff] [blame] | 79 | |
Logan Chien | c3d8593 | 2018-10-04 11:24:13 +0800 | [diff] [blame] | 80 | # Copy clang headers |
Logan Chien | fd2d41e | 2018-10-12 15:59:31 +0800 | [diff] [blame^] | 81 | cp -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. |
| 84 | function 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 | |
| 102 | for 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 |
| 107 | done |
Logan Chien | c3d8593 | 2018-10-04 11:24:13 +0800 | [diff] [blame] | 108 | |
Logan Chien | 6c5889e | 2018-10-04 11:18:06 +0800 | [diff] [blame] | 109 | # Package binaries and shared libs |
Jayant Chowdhary | ea86c04 | 2018-01-25 12:07:55 -0800 | [diff] [blame] | 110 | ( |
Logan Chien | 6c5889e | 2018-10-04 11:18:06 +0800 | [diff] [blame] | 111 | cd "${SOONG_OUT}/dist" |
Jayant Chowdhary | ea86c04 | 2018-01-25 12:07:55 -0800 | [diff] [blame] | 112 | zip -qryX build-prebuilts.zip * |
| 113 | ) |
| 114 | |
| 115 | if [ -n "${DIST_DIR}" ]; then |
Logan Chien | 6c5889e | 2018-10-04 11:18:06 +0800 | [diff] [blame] | 116 | mkdir -p "${DIST_DIR}" || true |
| 117 | cp "${SOONG_OUT}/dist/build-prebuilts.zip" "${DIST_DIR}/" |
Jayant Chowdhary | ea86c04 | 2018-01-25 12:07:55 -0800 | [diff] [blame] | 118 | fi |