Skip to content

Instantly share code, notes, and snippets.

@ss-abramchuk
Last active November 9, 2019 10:14
Show Gist options
  • Save ss-abramchuk/e637536143ab4491d85b40841f5f8c4f to your computer and use it in GitHub Desktop.
Save ss-abramchuk/e637536143ab4491d85b40841f5f8c4f to your computer and use it in GitHub Desktop.
Misc build scripts
- mbedTLS: General, OpenVPN
- lz4: OpenVPN
#!/usr/bin/env bash
set -e
export BUILD_TOOLS="${DEVELOPER_DIR:-`xcode-select -p`}"
export CC="${BUILD_TOOLS}/usr/bin/gcc"
mkdir -p ./binaries
TARGETS="ios ios-sim macosx"
for TARGET in $TARGETS
do
echo "*********** Build Target: ${TARGET} ***********"
mkdir -p ./binaries/${TARGET}
rm -rf ./binaries/${TARGET}/*
case $TARGET in
"ios")
PLATFORM="iPhoneOS"
SDKVERSION=`xcrun -sdk iphoneos --show-sdk-version`
ARCHS="-arch armv7 -arch armv7s -arch arm64"
MIN_DEPLOY_TARGET="-miphoneos-version-min=9.0"
;;
"ios-sim")
PLATFORM="iPhoneSimulator"
SDKVERSION=`xcrun -sdk iphoneos --show-sdk-version`
ARCHS="-arch x86_64 -arch i386"
MIN_DEPLOY_TARGET="-miphoneos-version-min=9.0"
;;
"macosx")
PLATFORM="MacOSX"
SDKVERSION=`xcrun -sdk macosx --show-sdk-version`
ARCHS="-arch x86_64 -arch i386"
MIN_DEPLOY_TARGET="-mmacosx-version-min=10.11"
;;
esac
export DEVROOT="${BUILD_TOOLS}/Platforms/${PLATFORM}.platform/Developer"
export SDKROOT="${DEVROOT}/SDKs/${PLATFORM}${SDKVERSION}.sdk"
export CFLAGS="${ARCHS} ${MIN_DEPLOY_TARGET} -O2 -fembed-bitcode -isysroot ${SDKROOT}"
make lib
mv ./library/libmbedcrypto.a ./binaries/${TARGET}/libmbedcrypto.a && \
mv ./library/libmbedtls.a ./binaries/${TARGET}/libmbedtls.a && \
mv ./library/libmbedx509.a ./binaries/${TARGET}/libmbedx509.a
make clean
echo "*********** Finished ***********"
done
#!/usr/bin/env bash
set -e
export BUILD_TOOLS="${DEVELOPER_DIR:-`xcode-select -p`}"
export CC="${BUILD_TOOLS}/usr/bin/gcc"
mkdir -p ./binaries
IOS_TARGET="ios"
SIMULATOR_TARGET="ios-sim"
MACOS_TARGET="macosx"
TARGETS="${IOS_TARGET} ${SIMULATOR_TARGET} ${MACOS_TARGET}"
for TARGET in $TARGETS
do
echo "*********** Build Target: ${TARGET} ***********"
mkdir -p ./binaries/${TARGET} && \
rm -rf ./binaries/${TARGET}/*
case $TARGET in
"ios")
PLATFORM="iPhoneOS"
SDKVERSION=`xcrun -sdk iphoneos --show-sdk-version`
ARCHS="-arch armv7 -arch armv7s -arch arm64"
MIN_DEPLOY_TARGET="-miphoneos-version-min=9.0"
;;
"ios-sim")
PLATFORM="iPhoneSimulator"
SDKVERSION=`xcrun -sdk iphoneos --show-sdk-version`
ARCHS="-arch x86_64 -arch i386"
MIN_DEPLOY_TARGET="-miphoneos-version-min=9.0"
;;
"macosx")
PLATFORM="MacOSX"
SDKVERSION=`xcrun -sdk macosx --show-sdk-version`
ARCHS="-arch x86_64"
MIN_DEPLOY_TARGET="-mmacosx-version-min=10.11"
;;
esac
export DEVROOT="${BUILD_TOOLS}/Platforms/${PLATFORM}.platform/Developer"
export SDKROOT="${DEVROOT}/SDKs/${PLATFORM}${SDKVERSION}.sdk"
export MOREFLAGS="${ARCHS} ${MIN_DEPLOY_TARGET} -fembed-bitcode -isysroot ${SDKROOT}"
make lib && \
mv ./lib/liblz4.a ./binaries/${TARGET}/liblz4.a && \
make clean
echo "*********** Finished ***********"
done
mkdir -p ./binaries/ios-fat
rm -rf ./binaries/ios-fat/*
lipo -create -output ./binaries/ios-fat/liblz4.a ./binaries/${IOS_TARGET}/liblz4.a ./binaries/${SIMULATOR_TARGET}/liblz4.a
#!/usr/bin/env bash
set -e
# enable MD4 (needed for NTLM auth)
perl -pi -e 's/^\/\/// if /#define MBEDTLS_MD4_C/' include/mbedtls/config.h
MBEDTLS_DIR=$(pwd)
# change directory since git apply got confused when
# applying patches to files which are not found in index
pushd ${MBEDTLS_DIR}
cd /tmp
# apply pre-generated patches
for file in ${MBEDTLS_DIR}/patches/*.patch; do
echo Applying patch: $file
git apply --directory ${MBEDTLS_DIR} --unsafe-path $file
done
popd
export BUILD_TOOLS="${DEVELOPER_DIR:-`xcode-select -p`}"
export CC="${BUILD_TOOLS}/usr/bin/gcc"
mkdir -p ./binaries
IOS_TARGET="ios"
SIMULATOR_TARGET="ios-sim"
MACOS_TARGET="macosx"
TARGETS="${IOS_TARGET} ${SIMULATOR_TARGET} ${MACOS_TARGET}"
for TARGET in $TARGETS
do
echo "*********** Build Target: ${TARGET} ***********"
mkdir -p ./binaries/${TARGET}
rm -rf ./binaries/${TARGET}/*
case $TARGET in
"ios")
PLATFORM="iPhoneOS"
SDKVERSION=`xcrun -sdk iphoneos --show-sdk-version`
ARCHS="-arch armv7 -arch armv7s -arch arm64"
MIN_DEPLOY_TARGET="-miphoneos-version-min=9.0"
;;
"ios-sim")
PLATFORM="iPhoneSimulator"
SDKVERSION=`xcrun -sdk iphoneos --show-sdk-version`
ARCHS="-arch x86_64 -arch i386"
MIN_DEPLOY_TARGET="-miphoneos-version-min=9.0"
;;
"macosx")
PLATFORM="MacOSX"
SDKVERSION=`xcrun -sdk macosx --show-sdk-version`
ARCHS="-arch x86_64 -arch i386"
MIN_DEPLOY_TARGET="-mmacosx-version-min=10.11"
;;
esac
export DEVROOT="${BUILD_TOOLS}/Platforms/${PLATFORM}.platform/Developer"
export SDKROOT="${DEVROOT}/SDKs/${PLATFORM}${SDKVERSION}.sdk"
export CFLAGS="${ARCHS} ${MIN_DEPLOY_TARGET} -O2 -fembed-bitcode -isysroot ${SDKROOT}"
make lib
mv ./library/libmbedcrypto.a ./binaries/${TARGET}/libmbedcrypto.a && \
mv ./library/libmbedtls.a ./binaries/${TARGET}/libmbedtls.a && \
mv ./library/libmbedx509.a ./binaries/${TARGET}/libmbedx509.a
make clean
echo "*********** Finished ***********"
done
# Create fat librarieas for iOS
mkdir -p ./binaries/ios-fat
rm -rf ./binaries/ios-fat/*
lipo -create -output ./binaries/ios-fat/libmbedcrypto.a ./binaries/${IOS_TARGET}/libmbedcrypto.a ./binaries/${SIMULATOR_TARGET}/libmbedcrypto.a && \
lipo -create -output ./binaries/ios-fat/libmbedtls.a ./binaries/${IOS_TARGET}/libmbedtls.a ./binaries/${SIMULATOR_TARGET}/libmbedtls.a && \
lipo -create -output ./binaries/ios-fat/libmbedx509.a ./binaries/${IOS_TARGET}/libmbedx509.a ./binaries/${SIMULATOR_TARGET}/libmbedx509.a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment