libgocrypfs: OpenSSL as git submodule

This commit is contained in:
Matéo Duparc 2024-07-18 21:50:26 +02:00
parent 4f32853ae5
commit b221d4cf3c
Signed by: hardcoresushi
GPG Key ID: AFE384344A45E13A
5 changed files with 23 additions and 20 deletions

1
.gitignore vendored
View File

@ -1,7 +1,6 @@
/build /build
/include /include
/lib /lib
/openssl*
# temporary files created by the tests # temporary files created by the tests
/tmp /tmp

3
.gitmodules vendored Normal file
View File

@ -0,0 +1,3 @@
[submodule "openssl"]
path = openssl
url = https://github.com/openssl/openssl.git

View File

@ -1,9 +1,12 @@
#!/bin/bash #!/bin/bash
set -e
if [ -z ${ANDROID_NDK_HOME+x} ]; then if [ -z ${ANDROID_NDK_HOME+x} ]; then
echo "Error: \$ANDROID_NDK_HOME is not defined." >&2 echo "Error: \$ANDROID_NDK_HOME is not defined." >&2
exit 1 exit 1
else else
OPENSSL_PATH="openssl"
NDK_BIN_PATH="$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/linux-x86_64/bin" NDK_BIN_PATH="$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/linux-x86_64/bin"
declare -a ABIs=("x86_64" "x86" "arm64-v8a" "armeabi-v7a") declare -a ABIs=("x86_64" "x86" "arm64-v8a" "armeabi-v7a")
@ -23,31 +26,28 @@ else
elif [ "$1" = "armeabi-v7a" ]; then elif [ "$1" = "armeabi-v7a" ]; then
OPENSSL_ARCH="android-arm" OPENSSL_ARCH="android-arm"
else else
invalid_abi $1 invalid_abi "$1"
fi
if [ -z ${OPENSSL_PATH+x} ]; then
echo "Error: \$OPENSSL_PATH is not defined." >&2
exit 1
fi fi
export CFLAGS=-D__ANDROID_API__=21 export CFLAGS=-D__ANDROID_API__=21
export PATH=$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/linux-x86_64/bin:$ANDROID_NDK_HOME/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin:$PATH export PATH=$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/linux-x86_64/bin:$ANDROID_NDK_HOME/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin:$PATH
( (
cd "$OPENSSL_PATH" cd "$OPENSSL_PATH"
export ANDROID_NDK_ROOT="$ANDROID_NDK_HOME"
if [ -f "Makefile" ]; then if [ -f "Makefile" ]; then
make clean make clean
fi fi
./Configure $OPENSSL_ARCH -D__ANDROID_API__=21 && ./Configure $OPENSSL_ARCH -D__ANDROID_API__=21
make -j $(nproc --all) build_libs make -j "$(nproc --all)" build_libs
) && )
mkdir -p "./lib/$1" "./include/$1" && mkdir -p "./lib/$1" "./include/$1"
cp "$OPENSSL_PATH/libcrypto.a" "$OPENSSL_PATH/libssl.a" "./lib/$1" && cp "$OPENSSL_PATH/libcrypto.a" "$OPENSSL_PATH/libssl.a" "./lib/$1"
cp -r "$OPENSSL_PATH"/include/* "./include/$1/" || exit 1 cp -r "$OPENSSL_PATH"/include/* "./include/$1/"
fi fi
} }
compile_for_arch() { compile_for_arch() {
compile_openssl $1 compile_openssl "$1"
if [ "$1" = "x86_64" ]; then if [ "$1" = "x86_64" ]; then
CFN="x86_64-linux-android21-clang" CFN="x86_64-linux-android21-clang"
elif [ "$1" = "x86" ]; then elif [ "$1" = "x86" ]; then
@ -62,7 +62,7 @@ else
export GOARCH=arm export GOARCH=arm
export GOARM=7 export GOARM=7
else else
invalid_abi $1 invalid_abi "$1"
fi fi
export CC="$NDK_BIN_PATH/$CFN" export CC="$NDK_BIN_PATH/$CFN"
@ -71,16 +71,16 @@ else
export GOOS=android export GOOS=android
export CGO_CFLAGS="-I ${PWD}/include/$1" export CGO_CFLAGS="-I ${PWD}/include/$1"
export CGO_LDFLAGS="-Wl,-soname=libgocryptfs.so -L${PWD}/lib/$1" export CGO_LDFLAGS="-Wl,-soname=libgocryptfs.so -L${PWD}/lib/$1"
go build -o build/$1/libgocryptfs.so -buildmode=c-shared || exit 1 go build -o "build/$1/libgocryptfs.so" -buildmode=c-shared
} }
cd $(dirname $0) || exit 1 cd "$(dirname "$0")"
if [ "$#" -eq 1 ]; then if [ "$#" -eq 1 ]; then
compile_for_arch $1 compile_for_arch "$1"
else else
for abi in ${ABIs[@]}; do for abi in "${ABIs[@]}"; do
echo "Compiling for $abi..." echo "Compiling for $abi..."
compile_for_arch $abi compile_for_arch "$abi"
done done
fi fi
fi fi

2
go.mod
View File

@ -1,6 +1,6 @@
module libgocryptfs/v2 module libgocryptfs/v2
go 1.19 go 1.22
require ( require (
github.com/aperturerobotics/jacobsa-crypto v1.0.1 github.com/aperturerobotics/jacobsa-crypto v1.0.1

1
openssl Submodule

@ -0,0 +1 @@
Subproject commit db2ac4f6ebd8f3d7b2a60882992fbea1269114e2