Forked from xuzepei/gist:ac868003f11a7526c6198a8c2156bb5a
Created
October 3, 2019 16:15
-
-
Save vukcevich/cfa96bf841f92bae3f5f544829b6c032 to your computer and use it in GitHub Desktop.
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
# Building FAT librares for XCode 10 | |
set -e | |
# If we're already inside this script then die | |
if [ -n "$MULTIPLATFORM_BUILD_IN_PROGRESS" ]; then | |
exit 0 | |
fi | |
export MULTIPLATFORM_BUILD_IN_PROGRESS=1 | |
############################################ | |
# Options | |
############################################ | |
REVEAL_ARCHIVE_IN_FINDER=true | |
OUTPUT_DIR_NAME="Generated-Frameworks" | |
FRAMEWORK_NAME="${PROJECT_NAME}" | |
OUTPUT_DIR="${PROJECT_DIR}/${OUTPUT_DIR_NAME}/${FRAMEWORK_NAME}-${CONFIGURATION}-framework/" | |
SIMULATOR_LIBRARY_OUT_DIR="${OUTPUT_DIR}/Simulator/" | |
GENERATED_LIBRARY_DIR="${BUILD_DIR}/${CONFIGURATION}-iphoneuniversal" | |
SIMULATOR_FRAMEWORK_OUT_DIR="${GENERATED_LIBRARY_DIR}/Simulator" | |
FRAMEWORK="${SIMULATOR_FRAMEWORK_OUT_DIR}/${FRAMEWORK_NAME}.framework" | |
######################################################################## | |
# Build Frameworks | |
######################################################################## | |
if [ -f "${PROJECT_NAME}.xcworkspace" ] | |
then | |
xcodebuild -workspace ${PROJECT_NAME}.xcworkspace -scheme ${PROJECT_NAME} -sdk iphonesimulator ONLY_ACTIVE_ARCH=NO -configuration ${CONFIGURATION} clean build CONFIGURATION_BUILD_DIR=${BUILD_DIR}/${CONFIGURATION}-iphonesimulator OBJROOT="${OBJROOT}/DependantBuilds" | |
else | |
echo "${PROJECT_NAME}.xcworkspace not found." | |
fi | |
######################################################################## | |
# Create directory for general | |
######################################################################## | |
rm -rf "${GENERATED_LIBRARY_DIR}" | |
mkdir "${GENERATED_LIBRARY_DIR}" | |
mkdir "${SIMULATOR_FRAMEWORK_OUT_DIR}" | |
mkdir "${FRAMEWORK}" | |
######################################################################## | |
# Copy files Framework | |
######################################################################## | |
SIMULATOR_LIBRARY_PATH="${BUILD_DIR}/${CONFIGURATION}-iphonesimulator/${FRAMEWORK_NAME}.framework" | |
######################################################################## | |
# Make a binary for simulaotr ie. x86_64 ot i386 file system | |
######################################################################## | |
# For Swift framework, Swiftmodule needs to be copied in the universal framework | |
if [ -d "${SIMULATOR_LIBRARY_PATH}/Modules/${FRAMEWORK_NAME}.swiftmodule/" ]; then | |
cp -f "${SIMULATOR_LIBRARY_PATH}/Modules/${FRAMEWORK_NAME}.swiftmodule/"* "${FRAMEWORK}/Modules/${FRAMEWORK_NAME}.swiftmodule/" | echo | |
fi | |
cp -r "${SIMULATOR_LIBRARY_PATH}/." "${FRAMEWORK}" | |
######################################################################## | |
# Copy simulator build library in output folder | |
######################################################################## | |
rm -rf "$OUTPUT_DIR" | |
mkdir -p "$OUTPUT_DIR" | |
mkdir -p ${SIMULATOR_LIBRARY_OUT_DIR} | |
cp -r "${FRAMEWORK}" "$SIMULATOR_LIBRARY_OUT_DIR" | |
######################################################################### | |
echo "Simulator Lib Path ---->" "${SIMULATOR_LIBRARY_PATH}" "<----" | |
#if [ ${REVEAL_ARCHIVE_IN_FINDER} = true ]; then | |
#open "${SIMULATOR_LIBRARY_OUT_DIR}/" | |
#fi | |
########################################################################## | |
# Now lets build for device; shall we? | |
########################################################################## | |
DEVICE_LIBRARY_OUT_DIR="${OUTPUT_DIR}/Device/" | |
DEVICE_FRAMEWORK_OUT_DIR="${GENERATED_LIBRARY_DIR}/Device" | |
FRAMEWORK="${DEVICE_FRAMEWORK_OUT_DIR}/${FRAMEWORK_NAME}.framework" | |
######################################################################## | |
# Build Device Frameworks | |
######################################################################## | |
if [ -f "${PROJECT_NAME}.xcworkspace" ] | |
then | |
xcodebuild -workspace ${PROJECT_NAME}.xcworkspace -scheme ${PROJECT_NAME} -sdk iphoneos ONLY_ACTIVE_ARCH=NO -configuration ${CONFIGURATION} clean build CONFIGURATION_BUILD_DIR=${BUILD_DIR}/${CONFIGURATION}-iphoneos OBJROOT="${OBJROOT}/DependantBuilds" | |
else | |
echo "${PROJECT_NAME}.xcworkspace not found." | |
fi | |
######################################################################## | |
# Create directory for general | |
######################################################################## | |
rm -rf "${GENERATED_LIBRARY_DIR}" | |
mkdir "${GENERATED_LIBRARY_DIR}" | |
mkdir "${DEVICE_FRAMEWORK_OUT_DIR}" | |
mkdir "${FRAMEWORK}" | |
######################################################################## | |
# Copy files Framework | |
######################################################################## | |
DEVICE_LIBRARY_PATH="${BUILD_DIR}/${CONFIGURATION}-iphoneos/${FRAMEWORK_NAME}.framework" | |
######################################################################## | |
# Make a binary for device ie. arm7, arm7v, arm8 file system | |
######################################################################## | |
# For Swift framework, Swiftmodule needs to be copied in the universal framework | |
if [ -d "${DEVICE_LIBRARY_PATH}/Modules/${FRAMEWORK_NAME}.swiftmodule/" ]; then | |
cp -f "${DEVICE_LIBRARY_PATH}/Modules/${FRAMEWORK_NAME}.swiftmodule/"* "${FRAMEWORK}/Modules/${FRAMEWORK_NAME}.swiftmodule/" | echo | |
fi | |
cp -r "${DEVICE_LIBRARY_PATH}/." "${FRAMEWORK}" | |
######################################################################## | |
# Copy device build library in output folder | |
######################################################################## | |
mkdir -p ${DEVICE_LIBRARY_OUT_DIR} | |
cp -r "${FRAMEWORK}" "$DEVICE_LIBRARY_OUT_DIR" | |
echo "${DEVICE_LIBRARY_OUT_DIR}/${FRAMEWORK_NAME}.framework/${FRAMEWORK_NAME}" | |
echo "${SIMULATOR_LIBRARY_OUT_DIR}/${FRAMEWORK_NAME}.framework/${FRAMEWORK_NAME}" | |
#if [ ${REVEAL_ARCHIVE_IN_FINDER} = true ]; then | |
#open "${DEVICE_LIBRARY_OUT_DIR}/" | |
#fi | |
#Create fat framework and put it to UNIVERSAL_OUTPUT_DIR | |
UNIVERSAL_OUTPUT_DIR="${OUTPUT_DIR}/Universal/" | |
rm -rf "${UNIVERSAL_OUTPUT_DIR}" | |
mkdir "${UNIVERSAL_OUTPUT_DIR}" | |
cp -r "${FRAMEWORK}" "${UNIVERSAL_OUTPUT_DIR}" | |
# Smash them together to combine all architectures | |
lipo -create "${DEVICE_LIBRARY_OUT_DIR}/${FRAMEWORK_NAME}.framework/${FRAMEWORK_NAME}" "${SIMULATOR_LIBRARY_OUT_DIR}/${FRAMEWORK_NAME}.framework/${FRAMEWORK_NAME}" -output "${UNIVERSAL_OUTPUT_DIR}/${FRAMEWORK_NAME}.framework/${TARGET_NAME}" | |
open "${UNIVERSAL_OUTPUT_DIR}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment