set -e
set +u
# Avoid recursively calling this script.if[[$SF_MASTER_SCRIPT_RUNNING]]thenexit 0
fiset -u
export SF_MASTER_SCRIPT_RUNNING=1
SF_TARGET_NAME=${PROJECT_NAME}SF_EXECUTABLE_PATH=${PROJECT_NAME}SF_WRAPPER_NAME="${SF_TARGET_NAME}.framework"# The following conditionals come from# https://github.com/kstenerud/iOS-Universal-Frameworkif[["$SDK_NAME"=~ ([A-Za-z]+)]]thenSF_SDK_PLATFORM=${BASH_REMATCH[1]}elseecho"Could not find platform name from SDK_NAME: $SDK_NAME"exit 1
fiif[["$SDK_NAME"=~ ([0-9]+.*$)]]thenSF_SDK_VERSION=${BASH_REMATCH[1]}elseecho"Could not find sdk version from SDK_NAME: $SDK_NAME"exit 1
fiif[["$SF_SDK_PLATFORM"="iphoneos"]]thenSF_OTHER_PLATFORM=iphonesimulator
elseSF_OTHER_PLATFORM=iphoneos
fiif[["$BUILT_PRODUCTS_DIR"=~ (.*)$SF_SDK_PLATFORM$ ]]thenSF_OTHER_BUILT_PRODUCTS_DIR="${BASH_REMATCH[1]}${SF_OTHER_PLATFORM}"elseecho"Could not find platform name from build products directory: $BUILT_PRODUCTS_DIR"exit 1
firm -r "${BUILT_PRODUCTS_DIR}/${SF_WRAPPER_NAME}/_CodeSignature"# Build the other platform.xcrun xcodebuild -project "${PROJECT_FILE_PATH}" -target "${TARGET_NAME}" -configuration "${CONFIGURATION}" -sdk ${SF_OTHER_PLATFORM}${SF_SDK_VERSION}BUILD_DIR="${BUILD_DIR}"OBJROOT="${OBJROOT}"BUILD_ROOT="${BUILD_ROOT}"SYMROOT="${SYMROOT}"$ACTION# Smash the two static libraries into one fat binary and store it in the .frameworkxcrun lipo -create "${BUILT_PRODUCTS_DIR}/${SF_WRAPPER_NAME}/${SF_EXECUTABLE_PATH}""${SF_OTHER_BUILT_PRODUCTS_DIR}/${SF_WRAPPER_NAME}/${SF_EXECUTABLE_PATH}" -output "${BUILT_PRODUCTS_DIR}/${SF_WRAPPER_NAME}/${SF_TARGET_NAME}"# Copy the binary to the other architecture folder to have a complete framework in both.cp -a "${BUILT_PRODUCTS_DIR}/${SF_WRAPPER_NAME}/${SF_TARGET_NAME}""${SF_OTHER_BUILT_PRODUCTS_DIR}/${SF_WRAPPER_NAME}/${SF_TARGET_NAME}"