1*333d2b36SAndroid Build Coastguard Worker#!/bin/bash -e 2*333d2b36SAndroid Build Coastguard Worker 3*333d2b36SAndroid Build Coastguard Worker# Copyright 2020 Google Inc. All rights reserved. 4*333d2b36SAndroid Build Coastguard Worker# 5*333d2b36SAndroid Build Coastguard Worker# Licensed under the Apache License, Version 2.0 (the "License"); 6*333d2b36SAndroid Build Coastguard Worker# you may not use this file except in compliance with the License. 7*333d2b36SAndroid Build Coastguard Worker# You may obtain a copy of the License at 8*333d2b36SAndroid Build Coastguard Worker# 9*333d2b36SAndroid Build Coastguard Worker# http://www.apache.org/licenses/LICENSE-2.0 10*333d2b36SAndroid Build Coastguard Worker# 11*333d2b36SAndroid Build Coastguard Worker# Unless required by applicable law or agreed to in writing, software 12*333d2b36SAndroid Build Coastguard Worker# distributed under the License is distributed on an "AS IS" BASIS, 13*333d2b36SAndroid Build Coastguard Worker# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14*333d2b36SAndroid Build Coastguard Worker# See the License for the specific language governing permissions and 15*333d2b36SAndroid Build Coastguard Worker# limitations under the License. 16*333d2b36SAndroid Build Coastguard Worker 17*333d2b36SAndroid Build Coastguard Worker# Generates NDK API txt file used by Mainline modules. NDK APIs would have value 18*333d2b36SAndroid Build Coastguard Worker# "UND" in Ndx column and have suffix "@LIB_NAME" in Name column. 19*333d2b36SAndroid Build Coastguard Worker# For example, current line llvm-readelf output is: 20*333d2b36SAndroid Build Coastguard Worker# 1: 00000000 0 FUNC GLOBAL DEFAULT UND dlopen@LIBC 21*333d2b36SAndroid Build Coastguard Worker# After the parse function below "dlopen" would be write to the output file. 22*333d2b36SAndroid Build Coastguard WorkerprintHelp() { 23*333d2b36SAndroid Build Coastguard Worker echo "**************************** Usage Instructions ****************************" 24*333d2b36SAndroid Build Coastguard Worker echo "This script is used to generate the native libraries backed by Mainline modules." 25*333d2b36SAndroid Build Coastguard Worker echo "" 26*333d2b36SAndroid Build Coastguard Worker echo "To run this script use: ./gen_ndk_backed_by_apex.sh \$OUTPUT_FILE_PATH \$MODULE_LIB1 \$MODULE_LIB2..." 27*333d2b36SAndroid Build Coastguard Worker echo "For example: If output write to /backedby.txt then the command would be:" 28*333d2b36SAndroid Build Coastguard Worker echo "./gen_ndk_backed_by_apex.sh /backedby.txt lib1.so lib2.so" 29*333d2b36SAndroid Build Coastguard Worker echo "If the module1 is backing lib1 then the backedby.txt would contains: " 30*333d2b36SAndroid Build Coastguard Worker echo "lib1.so lib2.so" 31*333d2b36SAndroid Build Coastguard Worker} 32*333d2b36SAndroid Build Coastguard Worker 33*333d2b36SAndroid Build Coastguard WorkergenAllBackedByList() { 34*333d2b36SAndroid Build Coastguard Worker out="$1" 35*333d2b36SAndroid Build Coastguard Worker shift 36*333d2b36SAndroid Build Coastguard Worker rm -f "$out" 37*333d2b36SAndroid Build Coastguard Worker touch "$out" 38*333d2b36SAndroid Build Coastguard Worker echo "$@" >> "$out" 39*333d2b36SAndroid Build Coastguard Worker} 40*333d2b36SAndroid Build Coastguard Worker 41*333d2b36SAndroid Build Coastguard Workerif [[ "$1" == "help" ]] 42*333d2b36SAndroid Build Coastguard Workerthen 43*333d2b36SAndroid Build Coastguard Worker printHelp 44*333d2b36SAndroid Build Coastguard Workerelif [[ "$#" -lt 1 ]] 45*333d2b36SAndroid Build Coastguard Workerthen 46*333d2b36SAndroid Build Coastguard Worker echo "Wrong argument length. Expecting at least 1 argument representing output path, followed by a list of libraries in the Mainline module." 47*333d2b36SAndroid Build Coastguard Workerelse 48*333d2b36SAndroid Build Coastguard Worker genAllBackedByList "$@" 49*333d2b36SAndroid Build Coastguard Workerfi 50