diff --git a/CommonPEPDependencies/CommonPEPDependencies.xcodeproj/project.pbxproj b/CommonPEPDependencies/CommonPEPDependencies.xcodeproj/project.pbxproj index 4142e44..3921586 100644 --- a/CommonPEPDependencies/CommonPEPDependencies.xcodeproj/project.pbxproj +++ b/CommonPEPDependencies/CommonPEPDependencies.xcodeproj/project.pbxproj @@ -18,6 +18,17 @@ name = CLEAN_ALL_iOS; productName = "libetpan-dependencies_macOS"; }; + 152E498D26A9B252009BD3CE /* build_gmp_iOS */ = { + isa = PBXAggregateTarget; + buildConfigurationList = 152E498F26A9B252009BD3CE /* Build configuration list for PBXAggregateTarget "build_gmp_iOS" */; + buildPhases = ( + 152E498E26A9B252009BD3CE /* Build */, + ); + dependencies = ( + ); + name = build_gmp_iOS; + productName = "libetpan-dependencies_macOS"; + }; 1585EE16269DCEA600B822E1 /* build-pEpMIME-dependencies_macOS */ = { isa = PBXAggregateTarget; buildConfigurationList = 1585EE17269DCEA600B822E1 /* Build configuration list for PBXAggregateTarget "build-pEpMIME-dependencies_macOS" */; @@ -402,6 +413,7 @@ 1585F04A26A1D2BE00B822E1 /* build-pEp4ThunderbirdInstaller-dependencies_macOS */, 1585EEFC26A0432A00B822E1 /* CLEAN_ALL_macOS */, 1585F04126A1C14C00B822E1 /* CLEAN_PEP */, + 152E498D26A9B252009BD3CE /* build_gmp_iOS */, 1585EF0526A0479800B822E1 /* build_sequoia_iOS */, 152E47C626A5B7C2009BD3CE /* CLEAN_ALL_iOS */, ); @@ -428,6 +440,25 @@ shellScript = "SCRIPTS_DIR=\"${PROJECT_DIR}/..\"\nPREFIX=\"${PROJECT_DIR}/$(${SCRIPTS_DIR}/get-config-prefix.sh)\"\nBUILD_SCRIPT=\"${SCRIPTS_DIR}/clean_all_iOS.sh\" \nsh \"${BUILD_SCRIPT}\" \"${PREFIX}\"\n"; showEnvVarsInLog = 0; }; + 152E498E26A9B252009BD3CE /* Build */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputFileListPaths = ( + ); + inputPaths = ( + ); + name = Build; + outputFileListPaths = ( + ); + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = "/bin/sh -l"; + shellScript = "LIB_NAME=\"gmp\"\n\nSCRIPTS_DIR=\"${PROJECT_DIR}/..\"\nPREFIX=\"${PROJECT_DIR}/$(${SCRIPTS_DIR}/get-config-prefix.sh)\"\n\nBUILD_SCRIPT=\"${SCRIPTS_DIR}/generate_and_run_ios_dependency_build_script.sh\" \nsh \"${BUILD_SCRIPT}\" $LIB_NAME \"${PREFIX}\"\n"; + showEnvVarsInLog = 0; + }; 1585EE28269DD87700B822E1 /* Build */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; @@ -803,6 +834,24 @@ }; name = Release; }; + 152E499026A9B252009BD3CE /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + CODE_SIGN_STYLE = Automatic; + DEVELOPMENT_TEAM = NQLYU6MGPN; + PRODUCT_NAME = "$(TARGET_NAME)"; + }; + name = Debug; + }; + 152E499126A9B252009BD3CE /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + CODE_SIGN_STYLE = Automatic; + DEVELOPMENT_TEAM = NQLYU6MGPN; + PRODUCT_NAME = "$(TARGET_NAME)"; + }; + name = Release; + }; 1585EE0F269DC6DD00B822E1 /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { @@ -1151,6 +1200,15 @@ defaultConfigurationIsVisible = 0; defaultConfigurationName = Release; }; + 152E498F26A9B252009BD3CE /* Build configuration list for PBXAggregateTarget "build_gmp_iOS" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 152E499026A9B252009BD3CE /* Debug */, + 152E499126A9B252009BD3CE /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; 1585EE0E269DC6DD00B822E1 /* Build configuration list for PBXProject "CommonPEPDependencies" */ = { isa = XCConfigurationList; buildConfigurations = ( diff --git a/CommonPEPDependencies/CommonPEPDependencies.xcodeproj/xcshareddata/xcschemes/build_gmp_iOS.xcscheme b/CommonPEPDependencies/CommonPEPDependencies.xcodeproj/xcshareddata/xcschemes/build_gmp_iOS.xcscheme new file mode 100644 index 0000000..966b546 --- /dev/null +++ b/CommonPEPDependencies/CommonPEPDependencies.xcodeproj/xcshareddata/xcschemes/build_gmp_iOS.xcscheme @@ -0,0 +1,67 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/CommonPEPDependencies/config.plist b/CommonPEPDependencies/config.plist index 8d9bac4..207fd53 100644 --- a/CommonPEPDependencies/config.plist +++ b/CommonPEPDependencies/config.plist @@ -2,6 +2,8 @@ + IOS_DEPLOYMENT + 12.0 MACOSX_DEPLOYMENT_x86_64 10.10 MACOSX_DEPLOYMENT_M1 diff --git a/_config/pEp_versions.plist b/_config/pEp_versions.plist index 028b32e..5e48b0b 100644 --- a/_config/pEp_versions.plist +++ b/_config/pEp_versions.plist @@ -2,6 +2,8 @@ + GMP_VERSION + 6.2.1 SEQUOIA_4_iOS_VERSION v2.1.6 SEQUOIA_4_MAC_OS_VERSION diff --git a/build-ios_dependency.template b/build-ios_dependency.template new file mode 100644 index 0000000..0bb42fa --- /dev/null +++ b/build-ios_dependency.template @@ -0,0 +1,85 @@ +# Builds fat lib for macOS (ARM64 & x86_64). +# Pass PREFIX as argument. If not passed, "local/" is used as deafult. + +# Exit on errors +set -e + +SCRIPT_DIR=$(dirname "$0") +PREFIX=$1 + +# Get Absolute Paths & Setup + +SCRIPT_DIR=$(dirname "$0") +pushd "${SCRIPT_DIR}" + SCRIPT_DIR=$(pwd) +popd +if [ "${PREFIX}" = "" ]; then + PREFIX="${SCRIPT_DIR}/local" +fi +mkdir -p "${PREFIX}" +pushd "${PREFIX}" + PREFIX=$(pwd) +popd + +TMP_DIR="${SCRIPT_DIR}/tmp" +INCLUDE_DIR="${PREFIX}/include" +LIB_DIR="${PREFIX}/lib" +BIN_DIR="${PREFIX}/bin" + +mkdir -p "${INCLUDE_DIR}" +mkdir -p "${LIB_DIR}" +mkdir -p "${TMP_DIR}" + + +IOS_DEPLOYMENT_TARGET=$(sh "${SCRIPT_DIR}"/get-config-ios-deployment-target.sh) + +# Funcs + +buildLib() +{ + ARCH=$1 + TARGET=$2 + HOST=$3 + SDK=$4 + SDK_PATH=`xcrun -sdk ${SDK} --show-sdk-path` + + CURRENT_LIB_DIR="${TMP_DIR}/${ARCH}" + mkdir -p "${CURRENT_LIB_DIR}/lib" + mkdir -p "${CURRENT_LIB_DIR}/include" + mkdir -p "${CURRENT_LIB_DIR}/bin" + + # START: Lib Specific Code + + BUILD_CODE + + # END: Lib Specific Code +} + +cleanup() +{ + rm -rf "${TMP_DIR}/x86_64" + rm -rf "${TMP_DIR}/arm64" +} + +# Setup + +cleanup + +mkdir -p "${TMP_DIR}" +mkdir -p "${PREFIX}" + +# Build +pushd "${TMP_DIR}" + buildLib "arm64" "aarch64-apple-ios" "aarch64-apple-darwin" "iphoneos" + buildLib "x86_64" "x86_64-apple-ios" "x86_64-apple-darwin" "iphonesimulator" +popd + +# Make Fat Lib +sh "${SCRIPT_DIR}/build-fat-libs.sh" "${TMP_DIR}/arm64/lib" "${TMP_DIR}/x86_64/lib" "${LIB_DIR}" + +# Copy Headers If Currently Building Lib +ARM64_INCLUDE_DIR="${TMP_DIR}/arm64/include" +cp -r "${ARM64_INCLUDE_DIR}"/* "${INCLUDE_DIR}" 2>/dev/null || : + +# Cleanup +cleanup diff --git a/buildcode/gmp.code b/buildcode/gmp.code new file mode 100644 index 0000000..96a2ab2 --- /dev/null +++ b/buildcode/gmp.code @@ -0,0 +1,30 @@ +GMP_VERSION=$(sh "${SCRIPT_DIR}"/get-pEp-version.sh "GMP_VERSION") +GMP_NAME="gmp-${GMP_VERSION}" + +OUTPUT_DIR=${SCRIPT_DIR}/build + +# Exit on errors +set -e + +if [ -f "${LIB_DIR}/libgmp.a" ]; then + echo "lib exists already in ${LIB_DIR}. If you want to rebuild it, delete the existing one." + exit 0 +fi + +GMP_DIR="${TMP_DIR}/${GMP_NAME}" +if [ ! -d "${GMP_DIR}" ]; then + # GMP snapshot must be used until released + wget -nc https://gmplib.org/download/gmp/$GMP_NAME.tar.bz2 + tar xvf ${GMP_NAME}.tar.bz2 +fi + +export CFLAGS="-arch ${ARCH} -isysroot ${SDK_PATH} -miphoneos-version-min=${IOS_DEPLOYMENT_TARGET} -std=c99" +export LDFLAGS="-arch ${ARCH}" +export CC="$(xcrun --sdk ${SDK} -f clang) -arch ${ARCH} -isysroot ${SDK_PATH}" + +pushd gmp-$GMP_VERSION + PKG_CONFIG_ALLOW_CROSS=1 PKG_CONFIG_PATH=${CURRENT_LIB_DIR}/lib/pkgconfig ./configure --host=${HOST} --prefix=${CURRENT_LIB_DIR} --disable-assembly + make clean + make -j4 + make install +popd diff --git a/generate_and_run_ios_dependency_build_script.sh b/generate_and_run_ios_dependency_build_script.sh new file mode 100644 index 0000000..45aaf11 --- /dev/null +++ b/generate_and_run_ios_dependency_build_script.sh @@ -0,0 +1,46 @@ +# Builds fat lib for macOS (ARM64 & x86_64). +# Pass PREFIX as argument. If not passed, "local/" is used as deafult. + +# Exit on errors +set -e + +SCRIPT_DIR=$(dirname "$0") +LIB_NAME=$1 +PREFIX=$2 + +# Get Absolute Paths +pushd "${SCRIPT_DIR}" + SCRIPT_DIR=$(pwd) +popd +mkdir -p "${PREFIX}" +pushd "${PREFIX}" + PREFIX=$(pwd) +popd +GENERATED_SCRIPT="${SCRIPT_DIR}/generated.sh" + +exitAndPrintHelp() +{ + echo "Must be called passing \`LIB_NAME`\` (mandatory). \`PREFIX\` can also be passed (optional).\nSample:\n\`generate_and_run_ios_dependency_build_script \$LIB_NAME\`\n`generate_and_run_ios_dependency_build_script \$LIB_NAME \$PREFIX\`" + exit 1 +} + +if [ "${LIB_NAME}" = "" ]; then + exitAndPrintHelp +fi + +# Say Hello +echo "#####################################################" +echo "#Generating buildscript for ${LIB_NAME}" +echo "#####################################################" + +# Generate Actual Script + +BUILD_CODE_FILE="${SCRIPT_DIR}/buildcode/${LIB_NAME}.code" +BUILD_SCRIPT_TEMPLATE_FILE="${SCRIPT_DIR}/build-ios_dependency.template" +SEARCH_STRING="BUILD_CODE" +#Replaces ${SEARCH_STRING} in file ${BUILD_SCRIPT_TEMPLATE_FILE} with content of ${BUILD_CODE_FILE} +/opt/local/bin/gsed -e "/${SEARCH_STRING}/r ${BUILD_CODE_FILE}" -e "/${SEARCH_STRING}/d" ${BUILD_SCRIPT_TEMPLATE_FILE} > "${GENERATED_SCRIPT}" +sh ${GENERATED_SCRIPT} ${PREFIX} + +# Cleanup +rm -rf "${TMP_DIR}" diff --git a/get-config-ios-deployment-target.sh b/get-config-ios-deployment-target.sh new file mode 100755 index 0000000..ab24792 --- /dev/null +++ b/get-config-ios-deployment-target.sh @@ -0,0 +1,12 @@ +# returns the default IOS_DEPLOYMENT TARGET +SCRIPT_DIR=$(dirname $0) + +# Get Absolute Paths +pushd "${SCRIPT_DIR}" >/dev/null + SCRIPT_DIR=$(pwd) +popd >/dev/null + +CONFIG_PLIST="${SCRIPT_DIR}/CommonPEPDependencies/config.plist" +RESULT=$(/usr/libexec/PlistBuddy -c "Print IOS_DEPLOYMENT" "${CONFIG_PLIST}") + +echo ${RESULT}