Yo Chiang | 4770456 | 2020-03-24 19:31:42 +0800 | [diff] [blame^] | 1 | #!/bin/bash |
| 2 | # |
| 3 | # Copyright 2020 The Android Open Source Project |
| 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 | # |
| 17 | # Generate Android.bp for AOSP blob self-extractors. |
| 18 | # |
| 19 | # For example, a blob package may contain: |
| 20 | # ./vendor |
| 21 | # └── qcom |
| 22 | # └── coral |
| 23 | # └── proprietary |
| 24 | # ├── lib64 |
| 25 | # | ├── libfoo.so |
| 26 | # | └── libbar.so |
| 27 | # ├── libfoo.so |
| 28 | # └── libbar.so |
| 29 | # |
| 30 | # Generate prebuilt modules for these blobs: |
| 31 | # $ export SYSTEM_EXT_SPECIFIC=true # If installing prebuilts to system_ext/ partition |
| 32 | # $ ./generate-android-bp-for-blobs.sh ./vendor/qcom/coral/proprietary > Android.bp.txt |
| 33 | # $ mv Android.bp.txt ${ANDROID_BUILD_TOP}/device/google/coral/self-extractors/qcom/staging/ |
| 34 | # |
| 35 | # You may need to review the contents of Android.bp.txt as some of the blobs may |
| 36 | # have unsatisfied dependencies. Add `check_elf_files: false` to bypass this |
| 37 | # kind of build errors. |
| 38 | |
| 39 | set -e |
| 40 | |
| 41 | readonly PREBUILT_DIR="$1" |
| 42 | |
| 43 | readonly elf_files=$( |
| 44 | for file in $(find "$PREBUILT_DIR" -type f); do |
| 45 | if readelf -h "$file" 2>/dev/null 1>&2; then |
| 46 | basename "$file" |
| 47 | fi |
| 48 | done | sort | uniq | xargs |
| 49 | ) |
| 50 | |
| 51 | echo "// Copyright (C) $(date +%Y) The Android Open Source Project" |
| 52 | echo "//" |
| 53 | echo "// Licensed under the Apache License, Version 2.0 (the \"License\");" |
| 54 | echo "// you may not use this file except in compliance with the License." |
| 55 | echo "// You may obtain a copy of the License at" |
| 56 | echo "//" |
| 57 | echo "// http://www.apache.org/licenses/LICENSE-2.0" |
| 58 | echo "//" |
| 59 | echo "// Unless required by applicable law or agreed to in writing, software" |
| 60 | echo "// distributed under the License is distributed on an \"AS IS\" BASIS," |
| 61 | echo "// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied." |
| 62 | echo "// See the License for the specific language governing permissions and" |
| 63 | echo "// limitations under the License." |
| 64 | echo "" |
| 65 | echo "soong_namespace {" |
| 66 | echo "}" |
| 67 | |
| 68 | for file in $elf_files; do |
| 69 | file32=$(find "$PREBUILT_DIR" -type f -name "$file" | grep -v 'lib64' | head) |
| 70 | file64=$(find "$PREBUILT_DIR" -type f -name "$file" | grep 'lib64' | head) |
| 71 | if [[ -n "$file32" ]] && [[ -n "$file64" ]]; then |
| 72 | multilib="both" |
| 73 | elif [[ -n "$file32" ]]; then |
| 74 | multilib="32" |
| 75 | else |
| 76 | multilib="64" |
| 77 | fi |
| 78 | |
| 79 | echo "" |
| 80 | echo "cc_prebuilt_library_shared {" |
| 81 | echo " name: \"${file%.so}\"," |
| 82 | echo " arch: {" |
| 83 | |
| 84 | if [[ -f "$file32" ]]; then |
| 85 | NEEDED=$(readelf -d "$file32" | sed -n -E 's/^.*\(NEEDED\).*\[(.+)\]$/\1/p' | xargs) |
| 86 | echo " arm: {" |
| 87 | echo " srcs: [\"$(realpath --relative-to="$PREBUILT_DIR" "$file32")\"]," |
| 88 | if [[ -n "$NEEDED" ]]; then |
| 89 | echo " shared_libs: [" |
| 90 | for entry in $NEEDED; do |
| 91 | echo " \"${entry%.so}\"," |
| 92 | done |
| 93 | echo " ]," |
| 94 | fi |
| 95 | echo " }," |
| 96 | fi |
| 97 | |
| 98 | if [[ -f "$file64" ]]; then |
| 99 | NEEDED=$(readelf -d "$file64" | sed -n -E 's/^.*\(NEEDED\).*\[(.+)\]$/\1/p' | xargs) |
| 100 | echo " arm64: {" |
| 101 | echo " srcs: [\"$(realpath --relative-to="$PREBUILT_DIR" "$file64")\"]," |
| 102 | if [[ -n "$NEEDED" ]]; then |
| 103 | echo " shared_libs: [" |
| 104 | for entry in $NEEDED; do |
| 105 | echo " \"${entry%.so}\"," |
| 106 | done |
| 107 | echo " ]," |
| 108 | fi |
| 109 | echo " }," |
| 110 | fi |
| 111 | |
| 112 | echo " }," |
| 113 | echo " compile_multilib: \"$multilib\"," |
| 114 | if [[ -n "$SYSTEM_EXT_SPECIFIC" ]]; then |
| 115 | echo " system_ext_specific: true," |
| 116 | fi |
| 117 | echo " strip: {" |
| 118 | echo " none: true," |
| 119 | echo " }," |
| 120 | echo "}" |
| 121 | |
| 122 | done |