Last active
November 10, 2019 10:27
-
-
Save drrost/3081a0c7183aba3589559a0a99e44812 to your computer and use it in GitHub Desktop.
Bash script to build a universal library from Xcode
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Created by: Rostyslav Druzhchenko | |
# | |
# 1: Declare variables | |
RESULT_DIR="libUniversal" | |
BUILD_DIR_SIMULATOR="Debug-iphonesimulator" | |
BUILD_DIR_DEVICE="Debug-iphoneos" | |
LIB_NAME="Networking" | |
LIB_BINARY_NAME="lib$LIB_NAME.a" | |
LIB_BINARY_NAME_SIMULATOR="lib$LIB_NAME-simulator.a" | |
LIB_BINARY_NAME_DEVICE="lib$LIB_NAME-device.a" | |
SWIFTMODULE_DIR=$LIB_NAME".swiftmodule" | |
# 2: BUILD | |
# | |
# Build for simulator | |
xcodebuild -target $LIB_NAME -configuration ${CONFIGURATION} -sdk iphonesimulator -arch x86_64 BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}" | |
# Build for device | |
xcodebuild -target $LIB_NAME ONLY_ACTIVE_ARCH=NO -configuration ${CONFIGURATION} -sdk iphoneos BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}" | |
# 3: OPERATE THE BINARIES | |
# | |
# Move to the build directory | |
cd $BUILD_DIR | |
# Completely delete the result of the previous build if any | |
# Suppress the error to avoid unnecessary logs | |
rm -rf $BUILD_DIR/$RESULT_DIR 2> /dev/null | |
# Create a new result directory | |
mkdir $RESULT_DIR | |
# Copy simulator's binary file to the result dir and rename it | |
cp ./$BUILD_DIR_SIMULATOR/$LIB_BINARY_NAME ./$RESULT_DIR/$LIB_BINARY_NAME_SIMULATOR | |
# Copy devices's binary file to the result dir and rename it | |
cp ./$BUILD_DIR_DEVICE/$LIB_BINARY_NAME ./$RESULT_DIR/$LIB_BINARY_NAME_DEVICE | |
# Make the library "fat", means "universal" | |
lipo -create ./$RESULT_DIR/$LIB_BINARY_NAME_SIMULATOR ./$RESULT_DIR/$LIB_BINARY_NAME_DEVICE -output ./$RESULT_DIR/$LIB_BINARY_NAME | |
# Delete simulator's binary file | |
rm ./$RESULT_DIR/$LIB_BINARY_NAME_SIMULATOR | |
# Delete device's binary file | |
rm ./$RESULT_DIR/$LIB_BINARY_NAME_DEVICE | |
# 4: OPERATE SIWFTMODULE | |
# | |
# Create ".siwftmodule" directory in the result directory | |
mkdir $RESULT_DIR/$SWIFTMODULE_DIR | |
# Copy 'swiftmodule' related to simulator | |
cp -r $BUILD_DIR_SIMULATOR/$SWIFTMODULE_DIR $RESULT_DIR | |
# Copy 'swiftmodule' related to mobile divice | |
cp -r $BUILD_DIR_DEVICE/$SWIFTMODULE_DIR/* $RESULT_DIR/$SWIFTMODULE_DIR | |
# Delete build directory | |
rm -rf $PROJECT_DIR/build |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment