1
mirror of https://github.com/jedisct1/libsodium.git synced 2024-12-19 10:05:05 -07:00

Improve readability

This commit is contained in:
Frank Denis 2022-02-05 20:59:16 +01:00
parent 68baef3f03
commit d30251f03e

View File

@ -1,17 +1,18 @@
#!/bin/sh #! /bin/sh
#creates an AAR with libsodium in 4 configurations all combinations of static | shared | minimal | full # Create an AAR with libsodium in all combinations of static | shared | minimal | full.
#the x86 static library will not work due to text relocation rules and so all static x86 versions are just the shared library #
#to simplify linking each version of the library is given a different name sodium, sodium-static, sodium-minimal and sodium-minimal-static # The x86 static library will not work due to text relocation rules, so static x86 versions are limited to shared libraries.
# To simplify linking, library variants have distinct names: sodium, sodium-static, sodium-minimal and sodium-minimal-static.
SODIUM_VERSION="1.0.18.0" SODIUM_VERSION="1.0.18.0"
NDK_VERSION=$(grep "Pkg.Revision = " <"$ANDROID_NDK_HOME/source.properties" | cut -f 2 -d '=' | cut -f 2 -d' ' | cut -f 1 -d'.') NDK_VERSION=$(grep "Pkg.Revision = " <"${ANDROID_NDK_HOME}/source.properties" | cut -f 2 -d '=' | cut -f 2 -d' ' | cut -f 1 -d'.')
DEST_PATH=$(mktemp -d) DEST_PATH=$(mktemp -d)
cd "$(dirname "$0")/../" || exit cd "$(dirname "$0")/../" || exit
make_abi_json() { make_abi_json() {
echo "{\"abi\":\"$NDK_ARCH\",\"api\":$SDK_VERSION,\"ndk\":$NDK_VERSION,\"stl\":\"none\"}" >"$1/abi.json" echo "{\"abi\":\"${NDK_ARCH}\",\"api\":${SDK_VERSION},\"ndk\":${NDK_VERSION},\"stl\":\"none\"}" >"$1/abi.json"
} }
make_prefab_json() { make_prefab_json() {
@ -20,65 +21,68 @@ make_prefab_json() {
make_manifest() { make_manifest() {
echo "<manifest xmlns:android=\"http://schemas.android.com/apk/res/android\" package=\"com.android.ndk.thirdparty.sodium\" android:versionCode=\"1\" android:versionName=\"1.0\"> echo "<manifest xmlns:android=\"http://schemas.android.com/apk/res/android\" package=\"com.android.ndk.thirdparty.sodium\" android:versionCode=\"1\" android:versionName=\"1.0\">
<uses-sdk android:minSdkVersion=\"19\" android:targetSdkVersion=\"21\"/> <uses-sdk android:minSdkVersion=\"19\" android:targetSdkVersion=\"21\"/>
</manifest>" >"$1/AndroidManifest.xml" </manifest>" >"${1}/AndroidManifest.xml"
} }
make_prefab_structure() { make_prefab_structure() {
mkdir "$DEST_PATH" mkdir "$DEST_PATH"
for i in "prefab" "prefab/modules" "META-INF"; do
mkdir "$DEST_PATH/$i" for variant_dirs in "prefab" "prefab/modules" "META-INF"; do
mkdir "${DEST_PATH}/${variant_dirs}"
done done
make_prefab_json "$DEST_PATH/prefab"
make_manifest "$DEST_PATH" make_prefab_json "${DEST_PATH}/prefab"
cp "LICENSE" "$DEST_PATH/META-INF" make_manifest "${DEST_PATH}"
for i in "prefab/modules/sodium" "prefab/modules/sodium-static" "prefab/modules/sodium-minimal" "prefab/modules/sodium-minimal-static"; do cp "LICENSE" "${DEST_PATH}/META-INF"
mkdir "$DEST_PATH/$i"
if [ "$i" = "prefab/modules/sodium-minimal" ]; then for variant in \
echo "{\"library_name\":\"libsodium\"}" >"$DEST_PATH/$i/module.json" "prefab/modules/sodium" "prefab/modules/sodium-static" \
"prefab/modules/sodium-minimal" "prefab/modules/sodium-minimal-static"; do
mkdir "${DEST_PATH}/${variant}"
if [ "$variant" = "prefab/modules/sodium-minimal" ]; then
echo "{\"library_name\":\"libsodium\"}" >"${DEST_PATH}/${variant}/module.json"
else else
echo "{}" >"$DEST_PATH/$i/module.json" echo "{}" >"${DEST_PATH}/${variant}/module.json"
fi fi
mkdir "$DEST_PATH/$i/libs"
for j in "arm64-v8a" "armeabi-v7a" "x86" "x86_64"; do mkdir "${DEST_PATH}/${variant}/libs"
mkdir "$DEST_PATH/$i/libs/android.$j"
mkdir "$DEST_PATH/$i/libs/android.$j/include" for arch in "arm64-v8a" "armeabi-v7a" "x86" "x86_64"; do
NDK_ARCH="$j" mkdir "$DEST_PATH/${variant}/libs/android.${arch}"
if [ $j = "arm64-v8a" ] || [ $j = "x86_64" ]; then mkdir "$DEST_PATH/${variant}/libs/android.${arch}/include"
NDK_ARCH="$arch"
if [ $arch = "arm64-v8a" ] || [ $arch = "x86_64" ]; then
SDK_VERSION="21" SDK_VERSION="21"
else else
SDK_VERSION="19" SDK_VERSION="19"
fi fi
make_abi_json "$DEST_PATH/$i/libs/android.$j" make_abi_json "$DEST_PATH/${variant}/libs/android.${arch}"
done done
done done
} }
copy_libs() { copy_libs() {
SRC_DIR="libsodium-android-$1" SRC_DIR="libsodium-android-${1}"
SHARED_DEST_DIR="$DEST_PATH/prefab/modules/sodium$3/libs/android.$2" SHARED_DEST_DIR="${DEST_PATH}/prefab/modules/sodium${3}/libs/android.${2}"
STATIC_DEST_DIR="$DEST_PATH/prefab/modules/sodium$3-static/libs/android.$2" STATIC_DEST_DIR="${DEST_PATH}/prefab/modules/sodium${3}-static/libs/android.${2}"
cp -r "$SRC_DIR/include" "$SHARED_DEST_DIR" cp -r "${SRC_DIR}/include" "$SHARED_DEST_DIR"
cp -r "$SRC_DIR/include" "$STATIC_DEST_DIR" cp -r "${SRC_DIR}/include" "$STATIC_DEST_DIR"
cp "$SRC_DIR/lib/libsodium.so" "$SHARED_DEST_DIR/libsodium.so" cp "${SRC_DIR}/lib/libsodium.so" "${SHARED_DEST_DIR}/libsodium.so"
cp "$SRC_DIR/lib/libsodium.a" "$STATIC_DEST_DIR/libsodium$3-static.a" cp "${SRC_DIR}/lib/libsodium.a" "${STATIC_DEST_DIR}/libsodium${3}-static.a"
rm -r "$SRC_DIR" rm -r "$SRC_DIR"
} }
build_all() { build_all() {
dist-build/android-armv7-a.sh dist-build/android-armv7-a.sh
dist-build/android-armv8-a.sh dist-build/android-armv8-a.sh
dist-build/android-x86_64.sh dist-build/android-x86_64.sh
dist-build/android-x86.sh dist-build/android-x86.sh
} }
make_prefab_structure make_prefab_structure
@ -100,37 +104,41 @@ copy_libs "armv8-a+crypto" "arm64-v8a"
copy_libs "i686" "x86" copy_libs "i686" "x86"
copy_libs "westmere" "x86_64" copy_libs "westmere" "x86_64"
AAR_PATH="$(pwd)/libsodium-$SODIUM_VERSION.aar" AAR_PATH="$(pwd)/libsodium-${SODIUM_VERSION}.aar"
cd "$DEST_PATH" || exit cd "$DEST_PATH" || exit
rm "$AAR_PATH" rm "$AAR_PATH"
zip -r "$AAR_PATH" META-INF prefab AndroidManifest.xml zip -9 -r "$AAR_PATH" META-INF prefab AndroidManifest.xml
cd .. || exit cd .. || exit
rm -r "$DEST_PATH" rm -r "$DEST_PATH"
clear
echo "congrats you have built an AAR containing libsodium. To use it with
gradle / cmake (defaults for Android Studio projects) simply:
edit the app/build.gradle file to add: echo
echo "Congrats you have built an AAR containing libsodium! To use it with
gradle or cmake (as set by default for Android Studio projects):
- Edit the app/build.gradle file to add:
android { android {
buildFeatures { buildFeatures {
prefab true prefab true
} }
} }
#and and
dependencies { dependencies {
implementation fileTree(dir:'path/to/aar/',include:['libsodium-$SODIUM_VERSION.aar']) implementation fileTree(dir:'path/to/aar/',include:['libsodium-$SODIUM_VERSION.aar'])
} }
#you can optionally store multiple AAR files in the same folder and include '*.aar'
edit your module's CMakeLists.txt file to add: Optionally, store multiple AAR files in the same folder and include '*.aar'
- Edit your module's CMakeLists.txt file to add:
find_package(sodium REQUIRED CONFIG) find_package(sodium REQUIRED CONFIG)
# the specify sodium::sodium as an item in the relevant target_link_libraries statement
# the first value specifies the AAR and is always sodium the second is the library
# name which supports sodium for the full shared library sodium-static
# for the full static library sodium-minimal for the minimal shared library
# or sodium-minimal-static for the minimal static library"
- Then, specify 'sodium::x' as an item in the relevant 'target_link_libraries' statement.
The first part is the AAR name and should be 'sodium'.
The second part ('x', to be replaced) should be set to:
- 'sodium' for the full shared library,
- 'sodium-static' for the full static library
- 'sodium-minimal' for the minimal shared library, or
- 'sodium-minimal-static' for the minimal static library."