diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 0000000..ed5ce83 --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1 @@ +custom: ['https://www.buymeacoffee.com/frugghi'] diff --git a/.gitignore b/.gitignore index 2fd4e3d..d24c6be 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,5 @@ tmp -openssl -libssh2 -libressl +openssl* +libssh2* +libressl* .DS_Store diff --git a/README.md b/README.md index ed1f5fb..aa10b79 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,6 @@ # iSSH2 -iSSH2 is a bash script for compiling Libssh2 (and OpenSSL) for iOS, iPhone Simulator and OSX. - -The current version supports armv7, armv7s, arm64, x86_64 architectures. +iSSH2 is a bash script for compiling Libssh2 (and OpenSSL) for iOS, macOS, watchOS and tvOS. - Libssh2: [Website](http://www.libssh2.org) | [Documentation](http://www.libssh2.org/docs.html) | [Changelog](http://www.libssh2.org/changes.html) - OpenSSL: [Website](http://www.openssl.org) | [Documentation](http://www.openssl.org/docs/) | [Changelog](http://www.openssl.org/news/) @@ -11,7 +9,6 @@ The current version supports armv7, armv7s, arm64, x86_64 architectures. - Xcode - Xcode Command Line Tools -- iOS SDK or MacOS SDK #### Optional Requirements @@ -19,17 +16,16 @@ The current version supports armv7, armv7s, arm64, x86_64 architectures. ## Tested with -- Xcode: 9.2.0 -- iOS SDK: 11.2 -- MacOS SDK: 10.12 -- Libssh2: 1.8.0 -- OpenSSL: 1.1.0g -- Architectures: armv7, armv7s, arm64, x86_64 +- Xcode: 10.2.1 +- iOS SDK: 12.2 +- Libssh2: 1.9.0 +- OpenSSL: 1.1.1c +- Architectures: arm64 arm64e armv7 armv7s i386 x86_64 ## How to use 1. Download the script -2. Run `iSSH2.sh` in Terminal +2. Run `iSSH2.sh` passing `--platform=PLATFORM --min-version=VERS` or `--xcodeproj=PATH --target=TARGET` as options (for example: `./iSSH2.sh --platform=iphoneos --min-version=8.0`) 3. Take a cup of coffee while waiting ## Script help @@ -41,15 +37,21 @@ This script download and build OpenSSL and Libssh2 libraries. Options: -a, --archs=[ARCHS] build for [ARCHS] architectures - -v, --min-version=VERS set iPhone or Mac OS minimum version to VERS + -p, --platform=PLATFORM build for PLATFORM platform + -v, --min-version=VERS set platform minimum version to VERS -s, --sdk-version=VERS use SDK version VERS -l, --libssh2=VERS download and build Libssh2 version VERS -o, --openssl=VERS download and build OpenSSL version VERS + -x, --xcodeproj=PATH get info from the project (requires TARGET) + -t, --target=TARGET get info from the target (requires XCODEPROJ) --build-only-openssl build OpenSSL and skip Libssh2 --no-clean do not clean build folder - --osx build only for OSX --no-bitcode don't embed bitcode -h, --help display this help and exit + +Valid platforms: iphoneos, macosx, appletvos, watchos + +Xcodeproj and target or platform and min version must be set. ``` ## License diff --git a/iSSH2-commons b/iSSH2-commons index d9d9c64..28819e7 100755 --- a/iSSH2-commons +++ b/iSSH2-commons @@ -70,3 +70,29 @@ importHeaders () { mkdir -p "$output" cp -RL "$input" "$output" } + +platformName () { + case "$1" in + macosx) echo "MacOSX" ;; + iphoneos) + if [[ "$2" == "i386" ]] || [[ "$2" == "x86_64" ]]; then + echo "iPhoneSimulator" + else + echo "iPhoneOS" + fi ;; + appletvos) + if [[ "$2" == "i386" ]] || [[ "$2" == "x86_64" ]]; then + echo "AppleTVSimulator" + else + echo "AppleTVOS" + fi ;; + watchos) + if [[ "$2" == "i386" ]] || [[ "$2" == "x86_64" ]]; then + echo "WatchSimulator" + else + echo "WatchOS" + fi ;; + *) echo "Unknown platform $1" + exit 1 ;; + esac +} diff --git a/iSSH2-libssh2.sh b/iSSH2-libssh2.sh index 53ec878..8a72b4e 100755 --- a/iSSH2-libssh2.sh +++ b/iSSH2-libssh2.sh @@ -45,17 +45,8 @@ echo "Building Libssh2 $LIBSSH_VERSION:" for ARCH in $ARCHS do - if [[ "$SDK_PLATFORM" == "macosx" ]]; then - PLATFORM="MacOSX" - else - if [[ "$ARCH" == "i386" ]] || [[ "$ARCH" == "x86_64" ]]; then - PLATFORM="iPhoneSimulator" - else - PLATFORM="iPhoneOS" - fi - fi - - OPENSSLDIR="$BASEPATH/openssl/" + PLATFORM="$(platformName "$SDK_PLATFORM" "$ARCH")" + OPENSSLDIR="$BASEPATH/openssl_$SDK_PLATFORM/" PLATFORM_SRC="$LIBSSHDIR/${PLATFORM}_$SDK_VERSION-$ARCH/src" PLATFORM_OUT="$LIBSSHDIR/${PLATFORM}_$SDK_VERSION-$ARCH/install" LIPO_SSH2="$LIPO_SSH2 $PLATFORM_OUT/lib/libssh2.a" @@ -72,7 +63,7 @@ do LOG="$PLATFORM_OUT/build-libssh2.log" touch $LOG - if [[ "$ARCH" == "arm64" ]]; then + if [[ "$ARCH" == arm64* ]]; then HOST="aarch64-apple-darwin" else HOST="$ARCH-apple-darwin" @@ -94,8 +85,8 @@ do fi done -lipoFatLibrary "$LIPO_SSH2" "$BASEPATH/libssh2/lib/libssh2.a" +lipoFatLibrary "$LIPO_SSH2" "$BASEPATH/libssh2_$SDK_PLATFORM/lib/libssh2.a" -importHeaders "$LIBSSHSRC/include/" "$BASEPATH/libssh2/include" +importHeaders "$LIBSSHSRC/include/" "$BASEPATH/libssh2_$SDK_PLATFORM/include" echo "Building done." diff --git a/iSSH2-openssl.sh b/iSSH2-openssl.sh index f3225da..25fe2d7 100755 --- a/iSSH2-openssl.sh +++ b/iSSH2-openssl.sh @@ -46,17 +46,12 @@ echo "Building OpenSSL $LIBSSL_VERSION, please wait..." for ARCH in $ARCHS do if [[ "$SDK_PLATFORM" == "macosx" ]]; then - PLATFORM="MacOSX" CONF="no-shared" else CONF="no-asm no-hw no-shared no-async" - if [[ "$ARCH" == "i386" ]] || [[ "$ARCH" == "x86_64" ]]; then - PLATFORM="iPhoneSimulator" - else - PLATFORM="iPhoneOS" - fi fi + PLATFORM="$(platformName "$SDK_PLATFORM" "$ARCH")" OPENSSLDIR="$LIBSSLDIR/${PLATFORM}_$SDK_VERSION-$ARCH" LIPO_LIBSSL="$LIPO_LIBSSL $OPENSSLDIR/libssl.a" LIPO_LIBCRYPTO="$LIPO_LIBCRYPTO $OPENSSLDIR/libcrypto.a" @@ -79,7 +74,7 @@ do fi else HOST="iphoneos-cross" - if [[ "${ARCH}" == *64 ]]; then + if [[ "${ARCH}" == *64 ]] || [[ "${ARCH}" == arm64* ]]; then CONF="$CONF enable-ec_nistp_64_gcc_128" fi fi @@ -104,9 +99,9 @@ do fi done -lipoFatLibrary "$LIPO_LIBSSL" "$BASEPATH/openssl/lib/libssl.a" -lipoFatLibrary "$LIPO_LIBCRYPTO" "$BASEPATH/openssl/lib/libcrypto.a" +lipoFatLibrary "$LIPO_LIBSSL" "$BASEPATH/openssl_$SDK_PLATFORM/lib/libssl.a" +lipoFatLibrary "$LIPO_LIBCRYPTO" "$BASEPATH/openssl_$SDK_PLATFORM/lib/libcrypto.a" -importHeaders "$OPENSSLDIR/include/" "$BASEPATH/openssl/include" +importHeaders "$OPENSSLDIR/include/" "$BASEPATH/openssl_$SDK_PLATFORM/include" echo "Building done." diff --git a/iSSH2.sh b/iSSH2.sh index c1c33ae..16d6564 100755 --- a/iSSH2.sh +++ b/iSSH2.sh @@ -68,6 +68,14 @@ getOpensslVersion () { fi } +getBuildSetting () { + echo "${1}" | grep -i "^\s*${2}\s*=\s*" | cut -d= -f2 | xargs echo -n +} + +version () { + printf "%02d%02d%02d" ${1//./ } +} + usageHelp () { echo echo "Usage: $SCRIPTNAME.sh [options]" @@ -76,16 +84,22 @@ usageHelp () { echo echo "Options:" echo " -a, --archs=[ARCHS] build for [ARCHS] architectures" - echo " -v, --min-version=VERS set iPhone or Mac OS minimum version to VERS" + echo " -p, --platform=PLATFORM build for PLATFORM platform" + echo " -v, --min-version=VERS set platform minimum version to VERS" echo " -s, --sdk-version=VERS use SDK version VERS" echo " -l, --libssh2=VERS download and build Libssh2 version VERS" echo " -o, --openssl=VERS download and build OpenSSL version VERS" + echo " -x, --xcodeproj=PATH get info from the project (requires TARGET)" + echo " -t, --target=TARGET get info from the target (requires XCODEPROJ)" echo " --build-only-openssl build OpenSSL and skip Libssh2" echo " --no-clean do not clean build folder" - echo " --osx build only for OSX" echo " --no-bitcode don't embed bitcode" echo " -h, --help display this help and exit" echo + echo "Valid platforms: iphoneos, macosx, appletvos, watchos" + echo + echo "Xcodeproj and target or platform and min version must be set." + echo exit 1 } @@ -99,69 +113,118 @@ export ARCHS= export SDK_PLATFORM= export EMBED_BITCODE="-fembed-bitcode" -OSX_ARCHS="x86_64" -IOS_ARCHS="armv7 armv7s arm64" - BUILD_OSX=false BUILD_SSL=true BUILD_SSH=true CLEAN_BUILD=true -while getopts ':a:l:o:v:s:h-' OPTION ; do +XCODE_PROJECT= +TARGET_NAME= + +while getopts 'a:p:l:o:v:s:x:t:h-' OPTION ; do case "$OPTION" in a) ARCHS="$OPTARG" ;; + p) SDK_PLATFORM="$OPTARG" ;; v) MIN_VERSION="$OPTARG" ;; s) SDK_VERSION="$OPTARG" ;; l) LIBSSH_VERSION="$OPTARG" ;; o) LIBSSL_VERSION="$OPTARG" ;; + x) XCODE_PROJECT="$OPTARG" ;; + t) TARGET_NAME="$OPTARG" ;; h) usageHelp ;; - -) [[ $OPTIND -ge 1 ]] && optind=$(expr $OPTIND - 1 ) || optind=$OPTIND - eval FULL_OPTION="\$$optind" - OPTARG=$(echo $FULL_OPTION | cut -d'=' -f2) - OPTION=$(echo $FULL_OPTION | cut -d'=' -f1) - case "$OPTION" in - --archs) ARCHS="$OPTARG" ;; - --openssl) LIBSSL_VERSION="$OPTARG" ;; - --libssh2) LIBSSH_VERSION="$OPTARG" ;; - --sdk-version) SDK_VERSION="$OPTARG" ;; - --min-version) MIN_VERSION="$OPTARG" ;; - --build-only-openssl) BUILD_SSH=false ;; - --only-print-env) BUILD_SSL=false; BUILD_SSH=false ;; - --osx) BUILD_OSX=true ;; - --no-bitcode) EMBED_BITCODE="" ;; - --no-clean) CLEAN_BUILD=false ;; - --help) usageHelp ;; - * ) echo "$SCRIPTNAME: Invalid option '$FULL_OPTION'" - echo "Try '$SCRIPTNAME --help' for more information." - exit 1 ;; - esac - OPTIND=1 + -) eval FULL_OPTION="\$$OPTIND" + OPTARG=$(echo $FULL_OPTION | cut -d'=' -f2) + OPTION=$(echo $FULL_OPTION | cut -d'=' -f1) + case "$OPTION" in + --archs) ARCHS="$OPTARG" ;; + --platform) SDK_PLATFORM="$OPTARG" ;; + --openssl) LIBSSL_VERSION="$OPTARG" ;; + --libssh2) LIBSSH_VERSION="$OPTARG" ;; + --sdk-version) SDK_VERSION="$OPTARG" ;; + --min-version) MIN_VERSION="$OPTARG" ;; + --xcodeproj) XCODE_PROJECT="$OPTARG" ;; + --target) TARGET_NAME="$OPTARG" ;; + --build-only-openssl) BUILD_SSH=false ;; + --only-print-env) BUILD_SSL=false; BUILD_SSH=false ;; + --osx) BUILD_OSX=true ;; + --no-bitcode) EMBED_BITCODE="" ;; + --no-clean) CLEAN_BUILD=false ;; + --help) usageHelp ;; + * ) echo "$SCRIPTNAME: Invalid option '$FULL_OPTION'" + echo "Run '$SCRIPTNAME --help' for more information." + exit 1 ;; + esac shift ;; \?) echo "$SCRIPTNAME: Invalid option -- $OPTION" - echo "Try '$SCRIPTNAME --help' for more information." + echo "Run '$SCRIPTNAME --help' for more information." exit 1 ;; esac + shift $((OPTIND - 1)) + OPTIND=1 done echo "Initializing..." +XCODE_VERSION=`xcodebuild -version | grep Xcode | cut -d' ' -f2` + +if [[ ! -z "$XCODE_PROJECT" ]] && [[ ! -z "$TARGET_NAME" ]]; then + BUILD_SETTINGS=`xcodebuild -project "$XCODE_PROJECT" -target "$TARGET_NAME" -showBuildSettings` + SDK_PLATFORM=`getBuildSetting "$BUILD_SETTINGS" "PLATFORM_NAME"` + MIN_VERSION=`getBuildSetting "$BUILD_SETTINGS" "${SDK_PLATFORM}_DEPLOYMENT_TARGET"` + TARGET_ARCHS=`getBuildSetting "$BUILD_SETTINGS" "VALID_ARCHS"` +fi + if [[ -z "$MIN_VERSION" ]]; then - if [[ $BUILD_OSX == true ]]; then - MIN_VERSION="10.10" - else - MIN_VERSION="8.0" - fi + echo "$SCRIPTNAME: Minimum platform version must be specified." + echo "Run '$SCRIPTNAME --help' for more information." + exit 1 fi -if [[ -z "$ARCHS" ]]; then - if [[ $BUILD_OSX == true ]]; then - ARCHS="$OSX_ARCHS" - else - ARCHS="$IOS_ARCHS $OSX_ARCHS" +if [[ "$SDK_PLATFORM" == "macosx" ]] || [[ "$SDK_PLATFORM" == "iphoneos" ]] || [[ "$SDK_PLATFORM" == "appletvos" ]] || [[ "$SDK_PLATFORM" == "watchos" ]]; then + if [[ -z "$ARCHS" ]]; then + ARCHS="$TARGET_ARCHS" + + if [[ "$SDK_PLATFORM" == "macosx" ]]; then + if [[ -z "$ARCHS" ]]; then + ARCHS="i386 x86_64" + fi + elif [[ "$SDK_PLATFORM" == "iphoneos" ]]; then + if [[ -z "$ARCHS" ]]; then + ARCHS="arm64" + + if [[ $(version "$XCODE_VERSION") == $(version "10.1") ]] || [[ $(version "$XCODE_VERSION") > $(version "10.1") ]]; then + ARCHS="$ARCHS arm64e" + fi + + if [[ $(version "$MIN_VERSION") < $(version "10.0") ]]; then + ARCHS="$ARCHS armv7 armv7s" + fi + fi + + ARCHS="$ARCHS x86_64" + + if [[ $(version "$MIN_VERSION") < $(version "10.0") ]]; then + ARCHS="$ARCHS i386" + fi + elif [[ "$SDK_PLATFORM" == "appletvos" ]]; then + ARCHS="$ARCHS arm64 x86_64" + elif [[ "$SDK_PLATFORM" == "watchos" ]]; then + ARCHS="$ARCHS i386 armv7k" + + if [[ $(version "$XCODE_VERSION") == $(version "10.0") ]] || [[ $(version "$XCODE_VERSION") > $(version "10.0") ]]; then + ARCHS="$ARCHS arm64_32" + fi + fi fi +else + echo "$SCRIPTNAME: Unknown platform '$SDK_PLATFORM'" + echo "Run '$SCRIPTNAME --help' for more information." + exit 1 fi +ARCHS="$(echo "$ARCHS" | tr ' ' '\n' | sort -u | tr '\n' ' ')" + LIBSSH_AUTO=false if [[ -z "$LIBSSH_VERSION" ]]; then getLibssh2Version @@ -172,12 +235,6 @@ if [[ -z "$LIBSSL_VERSION" ]]; then getOpensslVersion fi -if [[ $BUILD_OSX == true ]]; then - SDK_PLATFORM="macosx" -else - SDK_PLATFORM="iphoneos" -fi - SDK_AUTO=false if [[ -z "$SDK_VERSION" ]]; then SDK_VERSION=`xcrun --sdk $SDK_PLATFORM --show-sdk-version` @@ -217,7 +274,8 @@ else fi echo "Architectures: $ARCHS" -echo "OS min version: $MIN_VERSION" +echo "Platform: $SDK_PLATFORM" +echo "Platform min version: $MIN_VERSION" echo #Build