#!/bin/bash

BASE_DIR=$(readlink -f $0 | xargs dirname)

declare -A sysroots
sysroots=(
 [arm]=$BASE_DIR/armeabi-v7a
 [arm64]=$BASE_DIR/arm64-v8a
 [x86]=$BASE_DIR/x86
 [x86_64]=$BASE_DIR/x86_64
)

srt_version=1.3.1
jni_dir=$BASE_DIR/jniLibs

declare -A jnilibs
jnilibs=(
 [arm]=$jni_dir/armeabi-v7a
 [arm64]=$jni_dir/arm64-v8a
 [x86]=$jni_dir/x86
 [x86_64]=$jni_dir/x86_64
)

jni_dir=$BASE_DIR/jniLibs

# Android < 6.0 has an issue with loading versioned libraries
# The issue is because of library so-name libsrt.so.1

for arch in arm arm64 x86 x86_64; do
 mkdir -p ${jnilibs[$arch]}
 cp ${sysroots[$arch]}/lib/libsrt.so.${srt_version} ${jnilibs[$arch]}/libsrt.so
 /usr/local/bin/patchelf --set-soname libsrt.so ${jnilibs[$arch]}/libsrt.so
 objdump -p ${jnilibs[$arch]}/libsrt.so | grep libsrt.so 
done

zip -r libsrt_$(date +%Y-%m-%d).zip jniLibs
