Skip to content

Instantly share code, notes, and snippets.

@danylokos
Created October 12, 2016 08:17
Show Gist options
  • Save danylokos/27c4b190c9e61233259f26c37a3a1b02 to your computer and use it in GitHub Desktop.
Save danylokos/27c4b190c9e61233259f26c37a3a1b02 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
# OpenSSL
# https://github.com/x2on/OpenSSL-for-iPhone
# boost
# https://gist.github.com/faithfracture/c629ae4c7168216a9856
echo "Cleaning up..."
rm -rf bin/
BIN_NAME="libtorrent.a"
IOS_VERSION_MIN=8.0
: ${SRC_ROOT:=`pwd`}
: ${XCODE_ROOT:=`xcode-select -print-path`}
SDK_ROOT_OS=${XCODE_ROOT}/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk
SDK_ROOT_SIMULATOR=${XCODE_ROOT}/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk
echo "Symlink route.h from simulator SDK"
sudo ln -s ${SDK_ROOT_SIMULATOR}/usr/include/net/route.h ${SDK_ROOT_OS}/usr/include/net/
ARCHS="i386 x86_64 armv7 armv7s arm64"
LIBTORRENT_DIR="${SRC_ROOT}/libtorrent-rasterbar"
INPUT=`find ${LIBTORRENT_DIR}/src ${LIBTORRENT_DIR}/ed25519/src -type f -name "*.cpp" -o -name "*.c"`
TORRENT_INCLUDE="${LIBTORRENT_DIR}/include/"
OPENSSL_INCLUDE="${SRC_ROOT}/../OpenSSL-for-iPhone/include/"
OPENSSL_LIBS="${SRC_ROOT}/../OpenSSL-for-iPhone/lib/"
BOOST_FRAMEWORK="${SRC_ROOT}/../boost/ios/framework/"
for ARCH in ${ARCHS}
do
OUTPUT_DIR="${SRC_ROOT}/bin/${ARCH}/"
mkdir -p ${OUTPUT_DIR}
echo "Building for ${ARCH}..."
if [[ "${ARCH}" == "i386" || "${ARCH}" == "x86_64" ]];
then
SDK_ROOT=${SDK_ROOT_SIMULATOR}
IOS_VERSION_MIN_FLAG=-mios-simulator-version-min
else
SDK_ROOT=${SDK_ROOT_OS}
IOS_VERSION_MIN_FLAG=-mios-version-min
fi
FRAMEWORKS=${SDK_ROOT}/System/Library/Frameworks/
INCLUDES=${SDK_ROOT}/usr/include/
OBJ_DIR="${OUTPUT_DIR}/obj"
mkdir -p ${OBJ_DIR}
cd ${OBJ_DIR}
DEFINES="-DBOOST_ASIO_SEPARATE_COMPILATION -DWITH_SHIPPED_GEOIP_H -DTORRENT_USE_TOMMATH -DTORRENT_BUILDING_STATIC"
clang -Os -I${INCLUDES} -I${TORRENT_INCLUDE} -I${OPENSSL_INCLUDE} -F${BOOST_FRAMEWORK} -isysroot ${SDK_ROOT} -arch ${ARCH} ${IOS_VERSION_MIN_FLAG}=${IOS_VERSION_MIN} -stdlib=libc++ ${DEFINES} -c ${INPUT}
libtool -static -o ${BIN_NAME} *.o
mv ${BIN_NAME} ${OUTPUT_DIR}
done
cd ${SRC_ROOT}
echo "Creating universal binary..."
FAT_BIN_DIR="${SRC_ROOT}/bin/universal"
mkdir -p ${FAT_BIN_DIR}
lipo -create bin/**/${BIN_NAME} -output ${FAT_BIN_DIR}/${BIN_NAME}
echo "Done."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment