forked from tpot/libssh2-for-iOS
-
Notifications
You must be signed in to change notification settings - Fork 7
/
build-libssh2.sh
executable file
·119 lines (104 loc) · 4.69 KB
/
build-libssh2.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#!/bin/bash
# Automatic build script for libssh2
# for iPhoneOS and iPhoneSimulator
#
# Created by Felix Schulze on 02.02.11.
# Copyright 2010-2015 Felix Schulze. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
###########################################################################
# Change values here
#
VERSION="1.8.0"
#
###########################################################################
#
# Don't change anything here
SDKVERSION=`xcrun -sdk iphoneos --show-sdk-version`
CURRENTPATH=`pwd`
ARCHS="i386 x86_64 armv7 armv7s arm64"
DEVELOPER=`xcode-select -print-path`
##########
set -e
if [ ! -e libssh2-${VERSION}.tar.gz ]; then
echo "Downloading libssh2-${VERSION}.tar.gz"
curl -O https://www.libssh2.org/download/libssh2-${VERSION}.tar.gz
else
echo "Using libssh2-${VERSION}.tar.gz"
fi
echo "Checking file: libssh2-${VERSION}.tar.gz"
md5=`md5 -q libssh2-${VERSION}.tar.gz`
if [ $md5 != "3d1147cae66e2959ea5441b183de1b1c" ]
then
echo "File corrupt, please download again."
exit 1
else
echo "Checksum verified."
fi
mkdir -p bin
mkdir -p lib
mkdir -p src
for ARCH in ${ARCHS}
do
if [[ "${ARCH}" == "i386" || "${ARCH}" == "x86_64" ]];
then
PLATFORM="iPhoneSimulator"
else
PLATFORM="iPhoneOS"
fi
echo "Building libssh2 for ${PLATFORM} ${SDKVERSION} ${ARCH}"
echo "Please stand by..."
tar zxf libssh2-${VERSION}.tar.gz -C src
cd src/libssh2-${VERSION}
PATCHFILE=`find ../.. | grep with-libgcrypt-prefix.patch`
patch -p2 < $PATCHFILE
export M4="${DEVELOPER}/Toolchains/XcodeDefault.xctoolchain/usr/bin/gm4"
export DEVROOT="${DEVELOPER}/Platforms/${PLATFORM}.platform/Developer"
export SDKROOT="${DEVROOT}/SDKs/${PLATFORM}${SDKVERSION}.sdk"
export LD=${DEVROOT}/usr/bin/ld
export CC=${DEVELOPER}/usr/bin/gcc
export CXX=${DEVELOPER}/usr/bin/g++
export AR=${DEVELOPER}/Toolchains/XcodeDefault.xctoolchain/usr/bin/ar
export AS=${DEVELOPER}/Toolchains/XcodeDefault.xctoolchain/usr/bin/as
export NM=${DEVELOPER}/Toolchains/XcodeDefault.xctoolchain/usr/bin/nm
export RANLIB=${DEVELOPER}/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib
export LDFLAGS="-dynamic -arch ${ARCH} -fembed-bitcode -pipe -no-cpp-precomp -isysroot ${SDKROOT} -L${CURRENTPATH}/bin/${PLATFORM}${SDKVERSION}-${ARCH}.sdk/lib -miphoneos-version-min=7.0"
export CFLAGS="-arch ${ARCH} -fembed-bitcode -pipe -no-cpp-precomp -isysroot ${SDKROOT} -I${CURRENTPATH}/bin/${PLATFORM}${SDKVERSION}-${ARCH}.sdk/include -miphoneos-version-min=7.0"
export CPPFLAGS="-arch ${ARCH} -fembed-bitcode -pipe -no-cpp-precomp -isysroot ${SDKROOT} -I${CURRENTPATH}/bin/${PLATFORM}${SDKVERSION}-${ARCH}.sdk/include -miphoneos-version-min=7.0"
mkdir -p "${CURRENTPATH}/bin/${PLATFORM}${SDKVERSION}-${ARCH}.sdk"
LOG="${CURRENTPATH}/bin/${PLATFORM}${SDKVERSION}-${ARCH}.sdk/build-libssh2-${VERSION}.log"
echo ${CURRENTPATH}/bin/${PLATFORM}${SDKVERSION}-${ARCH}.sdk
HOST="${ARCH}"
if [ "${ARCH}" == "arm64" ];
then
HOST="aarch64"
fi
autoconf
if [ "$1" == "openssl" ];
then
./configure --host=${HOST}-apple-darwin --prefix="${CURRENTPATH}/bin/${PLATFORM}${SDKVERSION}-${ARCH}.sdk" --with-openssl --with-libssl-prefix=${CURRENTPATH}/bin/${PLATFORM}${SDKVERSION}-${ARCH}.sdk --disable-shared --enable-static >> "${LOG}" 2>&1
else
./configure --host=${HOST}-apple-darwin --prefix="${CURRENTPATH}/bin/${PLATFORM}${SDKVERSION}-${ARCH}.sdk" --with-libgcrypt --with-libgcrypt-prefix=${CURRENTPATH}/bin/${PLATFORM}${SDKVERSION}-${ARCH}.sdk --disable-shared --enable-static >> "${LOG}" 2>&1
fi
make >> "${LOG}" 2>&1
make install >> "${LOG}" 2>&1
cd ${CURRENTPATH}
rm -rf src/libssh2-${VERSION}
done
echo "Build library..."
#
lipo -create ${CURRENTPATH}/bin/iPhoneSimulator${SDKVERSION}-i386.sdk/lib/libssh2.a ${CURRENTPATH}/bin/iPhoneSimulator${SDKVERSION}-x86_64.sdk/lib/libssh2.a ${CURRENTPATH}/bin/iPhoneOS${SDKVERSION}-armv7s.sdk/lib/libssh2.a ${CURRENTPATH}/bin/iPhoneOS${SDKVERSION}-armv7.sdk/lib/libssh2.a ${CURRENTPATH}/bin/iPhoneOS${SDKVERSION}-arm64.sdk/lib/libssh2.a -output ${CURRENTPATH}/lib/libssh2.a
mkdir -p ${CURRENTPATH}/include/libssh2
cp -R ${CURRENTPATH}/bin/iPhoneSimulator${SDKVERSION}-i386.sdk/include/libssh2* ${CURRENTPATH}/include/libssh2/
echo "Building done."