2020-01-06 04:21:44 -08:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
2020-10-19 10:07:25 +02:00
|
|
|
install_modules()
|
|
|
|
|
{
|
|
|
|
|
printf "\e[0;32mStart installing go modules and their dependencies \033[0m\n\n"
|
|
|
|
|
GO111MODULE=on
|
|
|
|
|
go mod download
|
|
|
|
|
printf "\e[0;32mDone \033[0m\n\n"
|
|
|
|
|
}
|
2020-01-06 04:21:44 -08:00
|
|
|
|
2020-10-19 10:07:25 +02:00
|
|
|
install_gomobile()
|
2020-01-06 04:21:44 -08:00
|
|
|
{
|
2020-10-19 10:07:25 +02:00
|
|
|
printf "\e[0;32mInstalling gomobile fork\033[0m\n\n"
|
|
|
|
|
go build golang.org/x/mobile/cmd/gomobile
|
|
|
|
|
go build golang.org/x/mobile/cmd/gobind
|
|
|
|
|
printf "\e[0;32mDone \033[0m\n\n"
|
|
|
|
|
PATH=$(pwd):$PATH
|
2020-01-06 04:21:44 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# import function, add internal package in the build
|
|
|
|
|
import()
|
|
|
|
|
{
|
2020-10-19 10:07:25 +02:00
|
|
|
PACKAGES="${PACKAGES} $1"
|
2020-01-06 04:21:44 -08:00
|
|
|
}
|
|
|
|
|
|
2020-10-19 10:07:25 +02:00
|
|
|
build()
|
2020-01-06 04:21:44 -08:00
|
|
|
{
|
2020-10-19 10:07:25 +02:00
|
|
|
TARGET=$1
|
2020-12-09 01:03:39 -08:00
|
|
|
JAVA_PKG=$2
|
2020-10-19 10:07:25 +02:00
|
|
|
if [ $TARGET = "android" ]; then
|
|
|
|
|
OUT_EXTENSION="aar"
|
2020-12-09 01:03:39 -08:00
|
|
|
if [ -z "$JAVA_PKG" ]; then
|
|
|
|
|
JAVAPKG_FLAG="-javapkg=$JAVA_PKG"
|
|
|
|
|
else
|
|
|
|
|
JAVAPKG_FLAG=""
|
|
|
|
|
fi
|
2020-10-19 10:07:25 +02:00
|
|
|
else
|
|
|
|
|
OUT_EXTENSION="framework"
|
2020-12-09 01:03:39 -08:00
|
|
|
JAVAPKG_FLAG=""
|
2020-10-19 10:07:25 +02:00
|
|
|
fi
|
|
|
|
|
TARGET_DIR=${BUILD_DIR}/${TARGET}
|
|
|
|
|
TARGET_OUT_FILE=${TARGET_DIR}/${BUILD_NAME}.${OUT_EXTENSION}
|
|
|
|
|
mkdir -p $TARGET_DIR
|
|
|
|
|
printf "\e[0;32mStart Building ${TARGET} .. Location: ${TARGET_DIR} \033[0m\n\n"
|
2020-12-09 01:03:39 -08:00
|
|
|
gomobile bind -tags mobile -target $TARGET $JAVAPKG_FLAG -x -o ${TARGET_OUT_FILE} -ldflags="${LDFLAGS}" ${PACKAGES}
|
2020-01-06 04:21:44 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2020-10-19 10:07:25 +02:00
|
|
|
## ======== Config ===============
|
|
|
|
|
|
|
|
|
|
# ==== Generic parameters ======
|
|
|
|
|
|
|
|
|
|
# output directory
|
2020-12-09 01:03:39 -08:00
|
|
|
BUILD_DIR="./dist"
|
2020-10-19 10:07:25 +02:00
|
|
|
|
|
|
|
|
# linkage flags
|
|
|
|
|
LDFLAGS="'all=-s -w'"
|
|
|
|
|
|
|
|
|
|
# name of the build output
|
|
|
|
|
BUILD_NAME="Gopenpgp"
|
2020-01-06 04:21:44 -08:00
|
|
|
|
2020-10-19 10:07:25 +02:00
|
|
|
# ==== Packages to include =====
|
2020-01-06 04:21:44 -08:00
|
|
|
PACKAGES=""
|
|
|
|
|
|
2020-10-19 10:07:25 +02:00
|
|
|
## crypto must be the first one, and the framework name better same with the first package name
|
|
|
|
|
import github.com/ProtonMail/gopenpgp/v2/crypto
|
|
|
|
|
import github.com/ProtonMail/gopenpgp/v2/armor
|
|
|
|
|
import github.com/ProtonMail/gopenpgp/v2/constants
|
|
|
|
|
import github.com/ProtonMail/gopenpgp/v2/models
|
|
|
|
|
import github.com/ProtonMail/gopenpgp/v2/subtle
|
|
|
|
|
import github.com/ProtonMail/gopenpgp/v2/helper
|
|
|
|
|
|
|
|
|
|
######## ======== Main ===========
|
|
|
|
|
|
|
|
|
|
# We get the needed go modules stated in the go.mod file
|
|
|
|
|
install_modules
|
|
|
|
|
install_gomobile
|
|
|
|
|
go env
|
|
|
|
|
echo "gomobile: $(which gomobile)"
|
|
|
|
|
echo "gobind: $(which gobind)"
|
|
|
|
|
printf "Packages included : ${PACKAGES}\n"
|
2020-01-06 04:21:44 -08:00
|
|
|
## start building
|
2020-10-19 10:07:25 +02:00
|
|
|
# ================= Apple Builds ======================
|
|
|
|
|
if [ "$#" -ne 1 ] || [ $1 = apple ]; then
|
|
|
|
|
# ========== iOS and Simulator =========
|
|
|
|
|
|
|
|
|
|
# we build the framework for the ios devices
|
|
|
|
|
build ios
|
|
|
|
|
|
|
|
|
|
# we make a copy of the framework for the simulator
|
|
|
|
|
IOSSIM_OUT=${BUILD_DIR}/"ios-simulator"
|
|
|
|
|
mkdir -p $IOSSIM_OUT
|
|
|
|
|
IOS_OUT_FILE=${BUILD_DIR}/ios/${BUILD_NAME}.framework
|
|
|
|
|
IOSSIM_OUT_FILE=${IOSSIM_OUT}/${BUILD_NAME}.framework
|
|
|
|
|
|
|
|
|
|
cp -R $IOS_OUT_FILE $IOSSIM_OUT_FILE;
|
|
|
|
|
|
|
|
|
|
# we remove the unwanted archs for ios and simulator
|
|
|
|
|
lipo $IOSSIM_OUT_FILE/Versions/A/${BUILD_NAME} -remove arm64 -output $IOSSIM_OUT_FILE/Versions/A/${BUILD_NAME};
|
|
|
|
|
lipo $IOS_OUT_FILE/Versions/A/${BUILD_NAME} -remove x86_64 -output $IOS_OUT_FILE/Versions/A/${BUILD_NAME};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# ========== macOs ====================
|
2020-01-06 04:21:44 -08:00
|
|
|
|
2020-10-19 10:07:25 +02:00
|
|
|
# we build the framework for the macos devices
|
2020-01-06 04:21:44 -08:00
|
|
|
|
2020-10-19 10:07:25 +02:00
|
|
|
build macos
|
2020-01-06 04:21:44 -08:00
|
|
|
|
2020-10-19 10:07:25 +02:00
|
|
|
# ======== macOSUI ===============
|
2020-01-06 04:21:44 -08:00
|
|
|
|
2020-10-19 10:07:25 +02:00
|
|
|
# we build the framework for the macos-ui target
|
|
|
|
|
|
|
|
|
|
build macos-ui
|
|
|
|
|
|
|
|
|
|
# we join all platform's framework in a xcframework
|
|
|
|
|
XCFRAMEWORK_OUT_FILE=$BUILD_DIR/$BUILD_NAME.xcframework
|
|
|
|
|
|
|
|
|
|
xcodebuild -create-xcframework -framework $BUILD_DIR/ios/$BUILD_NAME.framework -framework $BUILD_DIR/macos/$BUILD_NAME.framework -framework $BUILD_DIR/macos-ui/$BUILD_NAME.framework -framework $BUILD_DIR/ios-simulator/$BUILD_NAME.framework -output $XCFRAMEWORK_OUT_FILE
|
|
|
|
|
|
|
|
|
|
fi
|
|
|
|
|
# ================ Android Build =====================
|
|
|
|
|
if [ "$#" -ne 1 ] || [ $1 = android ]; then
|
2020-12-09 01:03:39 -08:00
|
|
|
ANDROID_JAVA_PAG="com.proton.${BUILD_NAME}"
|
|
|
|
|
build android $ANDROID_JAVA_PAG
|
2020-10-19 10:07:25 +02:00
|
|
|
|
|
|
|
|
printf "\e[0;32mAll Done. \033[0m\n\n"
|
|
|
|
|
fi
|