Skip to content

Commit 332acd3

Browse files
committed
use strongswan script to build.
1 parent c26e7ab commit 332acd3

File tree

2 files changed

+66
-67
lines changed

2 files changed

+66
-67
lines changed

.gitlab-ci.yml

Lines changed: 6 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -209,34 +209,13 @@ BuildStrongswan:
209209
- export OPENSSL_SRC="$PWD/openssl-OpenSSL_1_1_1t"
210210

211211
script:
212-
- cd $CI_PROJECT_DIR
212+
- cd "$CI_PROJECT_DIR"
213213
- rm -rf strongswan-src
214-
- git clone --branch $SS_BRANCH $SS_REMOTE strongswan-src
215-
# Build Openssl static lib.
216-
- cp -a "$OPENSSL_SRC/." "$CI_PROJECT_DIR/strongswan-src/src/frontends/android/openssl/"
217-
- export OUT_DIR="$PWD/strongswan-src/src/frontends/android/app/src/main/jni/openssl"
218-
- cd $CI_PROJECT_DIR/strongswan-src/src/frontends/android/openssl
219-
- ./compile.sh
220-
- echo "LOCAL_PATH := \$(call my-dir)" >"${OUT_DIR}/Android.mk"
221-
- echo "include \$(CLEAR_VARS)" >>"${OUT_DIR}/Android.mk"
222-
- echo "LOCAL_MODULE := libcrypto_static" >>"${OUT_DIR}/Android.mk"
223-
- echo "LOCAL_SRC_FILES := \$(TARGET_ARCH_ABI)/libcrypto.a" >>"${OUT_DIR}/Android.mk"
224-
- echo "LOCAL_EXPORT_C_INCLUDES := \$(LOCAL_PATH)/include" >>"${OUT_DIR}/Android.mk"
225-
- echo "include \$(PREBUILT_STATIC_LIBRARY)" >>"${OUT_DIR}/Android.mk"
226-
# Build Strongswan.
227-
- cd $CI_PROJECT_DIR/strongswan-src
228-
- ./autogen.sh > config.log
229-
- ./configure --disable-defaults > config.log
230-
- make dist -j $(nproc) > config.log
231-
- rm config.log
232-
# Build App.
233-
- cd $CI_PROJECT_DIR
234-
- cd strongswan-src/src/frontends/android
235-
- sed -i '/arguments '\''-j'\'' \+ Runtime\.runtime\.availableProcessors()/a\ arguments "-DANDROID_SUPPORT_FLEXIBLE_PAGE_SIZES=ON"' app/build.gradle
236-
- ./gradlew assembleRelease
237-
# Copy binaries for download
238-
- mkdir -p $CI_PROJECT_DIR/artifacts
239-
- zip -r $CI_PROJECT_DIR/artifacts/strongswan-libs.zip app/build/intermediates/merged_native_libs/release/mergeReleaseNativeLibs/out/lib
214+
- git clone --branch "$SS_BRANCH" "$SS_REMOTE" strongswan-src
215+
- mkdir -p "$CI_PROJECT_DIR/artifacts"
216+
- ./tools/build_strongswan.sh "$CI_PROJECT_DIR/strongswan-src" "$OPENSSL_SRC" "$CI_PROJECT_DIR/artifacts"
217+
- cd "$CI_PROJECT_DIR/artifacts"
218+
- zip -r strongswan-libs.zip .
240219
artifacts:
241220
paths:
242221
- $CI_PROJECT_DIR/artifacts/strongswan-libs.zip

tools/build_strongswan.sh

Lines changed: 60 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,62 @@
1-
strongswanLibsSrc="$PWD/../strongswan-src/src/frontends/android/app/src/main/libs/*"
2-
strongswanLibsDst="$PWD/../strongswan/libs"
3-
mkdir -p $strongswanLibsDst
4-
strongswanRoot="$PWD/../strongswan-src"
5-
cd $strongswanRoot
6-
lib="$PWD/src/frontends/android/app/src/main/jni/openssl"
7-
PATH=$ANDROID_NDK/toolchains/llvm/prebuilt/linux-x86_64/bin:$PATH
8-
pushd $OpenSSL
9-
CC=armv7a-linux-androideabi16-clang ./Configure android-arm no-shared no-ssl3 no-engine no-dso no-asm no-hw no-comp no-stdio -fPIC -DOPENSSL_PIC -D__ANDROID_API__=16 -ffast-math -O3 -funroll-loops
10-
make -j $(nproc) > config.log
11-
mkdir -p "${lib}/armeabi-v7a"
12-
cp libcrypto.a ${lib}/armeabi-v7a/
13-
make distclean
14-
CC=aarch64-linux-android21-clang ./Configure android-arm64 no-shared no-ssl3 no-engine no-dso no-asm no-hw no-comp no-stdio -fPIC -DOPENSSL_PIC -D__ANDROID_API__=21 -ffast-math -O3 -funroll-loops
15-
make -j $(nproc) > config.log
16-
mkdir -p "${lib}/arm64-v8a"
17-
cp libcrypto.a ${lib}/arm64-v8a/
18-
make distclean
19-
CC=i686-linux-android16-clang ./Configure android-x86 no-shared no-ssl3 no-engine no-dso no-asm no-hw no-comp no-stdio -fPIC -DOPENSSL_PIC -D__ANDROID_API__=16 -ffast-math -O3 -funroll-loops
20-
make -j $(nproc) > config.log
21-
mkdir -p "${lib}/x86"
22-
cp libcrypto.a ${lib}/x86/
23-
make distclean
24-
CC=x86_64-linux-android21-clang ./Configure android-x86_64 no-shared no-ssl3 no-engine no-dso no-asm no-hw no-comp no-stdio -fPIC -DOPENSSL_PIC -D__ANDROID_API__=21 -ffast-math -O3 -funroll-loops
25-
make -j $(nproc) > config.log
26-
mkdir -p "${lib}/x86_64"
27-
cp libcrypto.a ${lib}/x86_64/
28-
cp -R include/ ${lib}/
29-
make distclean
30-
rm config.log
31-
popd
32-
echo "LOCAL_PATH := \$(call my-dir)" >"${lib}/Android.mk"
33-
echo "include \$(CLEAR_VARS)" >>"${lib}/Android.mk"
34-
echo "LOCAL_MODULE := libcrypto_static" >>"${lib}/Android.mk"
35-
echo "LOCAL_SRC_FILES := \$(TARGET_ARCH_ABI)/libcrypto.a" >>"${lib}/Android.mk"
36-
echo "LOCAL_EXPORT_C_INCLUDES := \$(LOCAL_PATH)/include" >>"${lib}/Android.mk"
37-
echo "include \$(PREBUILT_STATIC_LIBRARY)" >>"${lib}/Android.mk"
38-
cd $strongswanRoot
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
5+
# === Usage ===
6+
# ./build_strongswan.sh /path/to/strongswan-src /path/to/openssl /path/to/output-libs
7+
# ================================
8+
9+
if [ "$#" -ne 3 ]; then
10+
echo "Usage: $0 <strongswan-dir> <openssl-dir> <strongswan-libs-dst>"
11+
exit 1
12+
fi
13+
14+
# === Parameters ===
15+
STRONGSWAN_DIR="$1"
16+
OPENSSL_SRC="$2"
17+
STRONGSWAN_LIBS_DST="$3"
18+
19+
# === Derived Paths ===
20+
ANDROID_OPENSSL_DIR="$STRONGSWAN_DIR/src/frontends/android/openssl"
21+
OUT_DIR="$STRONGSWAN_DIR/src/frontends/android/app/src/main/jni/openssl"
22+
APP_DIR="$STRONGSWAN_DIR/src/frontends/android/app"
23+
24+
echo "===> Copying OpenSSL sources..."
25+
rm -rf "$ANDROID_OPENSSL_DIR"
26+
mkdir -p "$ANDROID_OPENSSL_DIR"
27+
cp -a "$OPENSSL_SRC/." "$ANDROID_OPENSSL_DIR/"
28+
29+
echo "===> Compiling OpenSSL..."
30+
cd "$ANDROID_OPENSSL_DIR"
31+
./compile.sh
32+
33+
echo "===> Generating Android.mk for libcrypto_static..."
34+
mkdir -p "$OUT_DIR"
35+
cat <<EOF > "${OUT_DIR}/Android.mk"
36+
LOCAL_PATH := \$(call my-dir)
37+
include \$(CLEAR_VARS)
38+
LOCAL_MODULE := libcrypto_static
39+
LOCAL_SRC_FILES := \$(TARGET_ARCH_ABI)/libcrypto.a
40+
LOCAL_EXPORT_C_INCLUDES := \$(LOCAL_PATH)/include
41+
include \$(PREBUILT_STATIC_LIBRARY)
42+
EOF
43+
44+
echo "===> Building Strongswan..."
45+
cd "$STRONGSWAN_DIR"
3946
./autogen.sh > config.log
40-
./configure --disable-defaults > config.log
41-
make dist -j $(nproc) > config.log
47+
./configure --disable-defaults >> config.log
48+
make dist -j "$(nproc)" >> config.log
4249
rm config.log
50+
51+
echo "===> Updating Gradle build config..."
52+
cd "$APP_DIR"
53+
sed -i '/arguments '\''-j'\'' \+ Runtime\.runtime\.availableProcessors()/a\ arguments "-DANDROID_SUPPORT_FLEXIBLE_PAGE_SIZES=ON"' build.gradle
54+
55+
echo "===> Building release APK..."
56+
gradle assembleRelease
57+
58+
echo "===> Copying output libs to: $STRONGSWAN_LIBS_DST"
59+
mkdir -p "$STRONGSWAN_LIBS_DST"
60+
cp -r "$ANDROID_OPENSSL_DIR"/lib/* "$STRONGSWAN_LIBS_DST/"
61+
62+
echo "✅ Build completed successfully."

0 commit comments

Comments
 (0)