Skip to content

Commit

Permalink
Refactor script to support all platforms
Browse files Browse the repository at this point in the history
  • Loading branch information
Frugghi committed Aug 12, 2019
1 parent 5f38b8d commit f958fb1
Show file tree
Hide file tree
Showing 7 changed files with 158 additions and 85 deletions.
1 change: 1 addition & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
custom: ['https://www.buymeacoffee.com/frugghi']
6 changes: 3 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
tmp
openssl
libssh2
libressl
openssl*
libssh2*
libressl*
.DS_Store
28 changes: 15 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -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/)
Expand All @@ -11,25 +9,23 @@ The current version supports armv7, armv7s, arm64, x86_64 architectures.

- Xcode
- Xcode Command Line Tools
- iOS SDK or MacOS SDK

#### Optional Requirements

- git (required for automatically detection of latest version of Libssh2/OpenSSL)

## 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
Expand All @@ -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
Expand Down
26 changes: 26 additions & 0 deletions iSSH2-commons
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
19 changes: 5 additions & 14 deletions iSSH2-libssh2.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand All @@ -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."
15 changes: 5 additions & 10 deletions iSSH2-openssl.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand All @@ -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."
Loading

0 comments on commit f958fb1

Please sign in to comment.