This repository has been archived by the owner on May 17, 2021. It is now read-only.
forked from passepartoutvpn/openssl-apple
-
Notifications
You must be signed in to change notification settings - Fork 7
/
create-openssl-framework.sh
executable file
·156 lines (131 loc) · 4.41 KB
/
create-openssl-framework.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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#!/bin/bash
set -euo pipefail
# Determine script directory
SCRIPTDIR=$(cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd)
# System types we support. Note the matching directories in assets, and that these are
# used as prefixes for many operations of this script.
ALL_SYSTEMS=("iPhone" "AppleTV" "MacOSX" "Watch" "Catalyst")
# Bring in libraries.
source "${SCRIPTDIR}/scripts/lib-min-sdk-versions.sh"
source "${SCRIPTDIR}/scripts/lib-frameworks.sh"
source "${SCRIPTDIR}/scripts/lib-spinner.sh"
#
# main
#
# Defaults, some of which will be overridden by CLI args.
BUILD_DIR="$SCRIPTDIR" # Where the built libraries are.
FWROOT="frameworks" # Containing directory within the build directory.
FWNAME="openssl" # Name of the finished framework.
COMMAND="" # Command specified on CLI.
FWXC=NO # building an XCFramework?
FWTYPE="" # Static or Dynamic?
# Process command line arguments
for i in "$@"; do
case $i in
--directory=*)
BUILD_DIR="${i#*=}"
BUILD_DIR="${BUILD_DIR/#\~/$HOME}"
shift
;;
--frameworks=*)
FWROOT="${i#*=}"
FWROOT="${FWROOT/#\~/$HOME}"
shift
;;
carthage)
(carthage build --configuration Release --no-use-binaries --no-skip-current --project-directory .) & spinner
(carthage archive) & spinner
exit
;;
static|xcstatic|dynamic|xcdynamic)
if [[ ! -z $COMMAND ]]; then
echo "Only one command can be specified, and you've already provided '$COMMAND'."
echo "Therefore ignoring '$i' and any subsequent commands you might have provided."
else
COMMAND=$i
FWTYPE=$i
if [[ $FWTYPE == xc* ]]; then
FWXC=YES
FWTYPE=${FWTYPE:2}
fi
fi
;;
-h|--help)
echo_help
exit
;;
*)
echo "Unknown argument: ${i}"
;;
esac
done
# A command is required.
if [[ -z $COMMAND ]]; then
echo_help
exit
fi
# Make sure the library was built first.
if [ ! -d "${BUILD_DIR}/lib" ]; then
echo "Please run build-libssl.sh first!"
exit 1
fi
# Clean up previous
if [ -d "${BUILD_DIR}/${FWROOT}" ]; then
echo "Removing previous $FWNAME.framework copies"
rm -rf "${BUILD_DIR}/${FWROOT}"
fi
# Perform the build.
cd $BUILD_DIR
build_libraries
if [ $FWTYPE == "dynamic" ]; then
if [[ $FWXC == NO ]]; then
# create per platform frameworks, which might be all a developer needs.
for SYS in ${ALL_SYSTEMS[@]}; do
FWDIR="$BUILD_DIR/$FWROOT/$SYS/$FWNAME.framework"
FILES=($BUILD_DIR/bin/${SYS}*/$FWNAME.dylib)
build_dynamic_framework $FWDIR $SYS "${FILES[*]}"
done
else
# Create per destination frameworks, which will be combined into a single XCFramework.
# xcodebuild -create-xcframework only works with per destination frameworks, e.g.,
# iOS devices, tvOS simulator, etc., which must already have fat libraries for the
# architectures.
for SYS in ${ALL_SYSTEMS[@]}; do
cd $BUILD_DIR/bin
ALL_TARGETS=(${SYS}*)
TARGETS=$(for TARGET in ${ALL_TARGETS[@]}; do echo "${TARGET%-*}"; done | sort -u)
cd ..
for TARGET in ${TARGETS[@]}; do
FWDIR="$BUILD_DIR/$FWROOT/$TARGET/$FWNAME.framework"
FILES=($BUILD_DIR/bin/${TARGET}*/$FWNAME.dylib)
build_dynamic_framework $FWDIR $SYS "${FILES[*]}"
done
done
build_xcframework
fi
else
if [[ $FWXC == NO ]]; then
# create per platform frameworks, which might be all a developer needs.
for SYS in ${ALL_SYSTEMS[@]}; do
FWDIR="$BUILD_DIR/$FWROOT/$SYS/$FWNAME.framework"
FILES=($BUILD_DIR/bin/${SYS}*/${FWNAME}.a)
build_static_framework $FWDIR $SYS "${FILES[*]}"
done
else
# Create per destination frameworks, which will be combined into a single XCFramework.
for SYS in ${ALL_SYSTEMS[@]}; do
cd $BUILD_DIR/bin
ALL_TARGETS=(${SYS}*)
TARGETS=$(for TARGET in ${ALL_TARGETS[@]}; do echo "${TARGET%-*}"; done | sort -u)
cd ..
for TARGET in ${TARGETS[@]}; do
FWDIR="$BUILD_DIR/$FWROOT/$TARGET/$FWNAME.framework"
FILES=($BUILD_DIR/bin/${TARGET}*/${FWNAME}.a)
build_static_framework $FWDIR $SYS "${FILES[*]}"
done
done
build_xcframework
fi
fi
# The built libraries aren't required any longer.
rm $BUILD_DIR/bin/*/$FWNAME.{dylib,a}