-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·143 lines (115 loc) · 4.41 KB
/
build.sh
File metadata and controls
executable file
·143 lines (115 loc) · 4.41 KB
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#!/usr/bin/env bash
# Copyright 2022 Michael F. Collins, III
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restrictions, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.
# build.sh
#
# This program automated building libssh2 to be linked into an iOS or macOS
# application, or to be used by other libraries that may be linked into
# applications.
#
# Usage: build.sh
ROOT_PATH=$PWD
PLATFORMS="MAC MAC_ARM64 OS64 SIMULATOR64 SIMULATORARM64 MAC_CATALYST MAC_CATALYST_ARM64"
for PLATFORM in $PLATFORMS; do
echo "Building libssh2 for $PLATFORM"
rm -rf /tmp/libssh2
cp -r External/libssh2 /tmp/
pushd /tmp/libssh2 > /dev/null
LOG=/tmp/libssh2-$PLATFORM.log
rm -rf $LOG
OUTPUT_PATH=$ROOT_PATH/build/$PLATFORM
rm -rf $OUTPUT_PATH
case $PLATFORM in
"MAC" )
OPENSSL_ROOT_DIR=$ROOT_PATH/../openssl-apple/build/darwin64-x86_64
;;
"MAC_ARM64" )
OPENSSL_ROOT_DIR=$ROOT_PATH/../openssl-apple/build/darwin64-arm64
;;
"OS64" )
OPENSSL_ROOT_DIR=$ROOT_PATH/../openssl-apple/build/openssl-ios64
;;
"SIMULATOR64" )
OPENSSL_ROOT_DIR=$ROOT_PATH/../openssl-apple/build/openssl-iossimulator
;;
"SIMULATORARM64" )
OPENSSL_ROOT_DIR=$ROOT_PATH/../openssl-apple/build/openssl-iossimulator-arm
;;
"MAC_CATALYST" )
OPENSSL_ROOT_DIR=$ROOT_PATH/../openssl-apple/build/openssl-catalyst
;;
"MAC_CATALYST_ARM64" )
OPENSSL_ROOT_DIR=$ROOT_PATH/../openssl-apple/build/openssl-catalyst-arm
;;
esac
mkdir bin
cd bin
cmake \
-DCMAKE_TOOLCHAIN_FILE=$ROOT_PATH/External/ios-cmake/ios.toolchain.cmake \
-DPLATFORM=$PLATFORM \
-DCMAKE_INSTALL_PREFIX=$OUTPUT_PATH \
-DCRYPTO_BACKEND=OpenSSL \
-DOPENSSL_ROOT_DIR=$OPENSSL_ROOT_DIR \
-DENABLE_BITCODE=FALSE \
.. >> $LOG 2>&1
cmake --build . --target install >> $LOG 2>&1
popd > /dev/null
done
echo "Creating the universal library for macOS"
OUTPUT_PATH=$ROOT_PATH/build/macos
rm -rf $OUTPUT_PATH
mkdir -p $OUTPUT_PATH
lipo -create \
$ROOT_PATH/build/MAC/lib/libssh2.a \
$ROOT_PATH/build/MAC_ARM64/lib/libssh2.a \
-output $OUTPUT_PATH/libssh2.a
echo "Creating the universal library for iOS Simulator"
OUTPUT_PATH=$ROOT_PATH/build/iossimulator
rm -rf $OUTPUT_PATH
mkdir -p $OUTPUT_PATH
lipo -create \
$ROOT_PATH/build/SIMULATOR64/lib/libssh2.a \
$ROOT_PATH/build/SIMULATORARM64/lib/libssh2.a \
-output $OUTPUT_PATH/libssh2.a
echo "Creating the universal library for Catalyst"
OUTPUT_PATH=$ROOT_PATH/build/catalyst
rm -rf $OUTPUT_PATH
mkdir -p $OUTPUT_PATH
lipo -create \
$ROOT_PATH/build/MAC_CATALYST/lib/libssh2.a \
$ROOT_PATH/build/MAC_CATALYST_ARM64/lib/libssh2.a \
-output $OUTPUT_PATH/libssh2.a
echo "Creating the libssh2 XCFramework"
LIB_PATH=$ROOT_PATH
LIBSSH2_PATH=$LIB_PATH/libssh2.xcframework
rm -rf $LIBSSH2_PATH
xcodebuild -create-xcframework \
-library $ROOT_PATH/build/macos/libssh2.a \
-headers $ROOT_PATH/build/MAC/include \
-library $ROOT_PATH/build/OS64/lib/libssh2.a \
-headers $ROOT_PATH/build/OS64/include \
-library $ROOT_PATH/build/iossimulator/libssh2.a \
-headers $ROOT_PATH/build/SIMULATOR64/include \
-library $ROOT_PATH/build/catalyst/libssh2.a \
-headers $ROOT_PATH/build/MAC_CATALYST/include \
-output $LIBSSH2_PATH
zip -r libssh2.zip libssh2.xcframework
echo "Done; cleaning up"
rm -rf $TEMP_PATH