-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.sh
executable file
·152 lines (117 loc) · 3.66 KB
/
build.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
#!/bin/sh
# Warning: pipefail is not a POSIX compatible option, but on OS X it works just fine.
# OS X uses a POSIX complain version of bash as /bin/sh, but apparently it does
# not strip away this feature. Also, this will fail if somebody forces the script
# to be run with zsh.
set -o pipefail
set -e
source_root="$(dirname "$0")"
# You can override the xcmode used
: ${XCMODE:=xcodebuild} # must be one of: xcodebuild (default), xcpretty, xctool
# Provide a fallback value for TMPDIR, relevant for Xcode Bots
: ${TMPDIR:=$(getconf DARWIN_USER_TEMP_DIR)}
PATH=/usr/libexec:$PATH
usage() {
cat <<EOF
Usage: sh $0 command [argument]
command:
clean: clean up/remove all generated files
build: builds iOS framework
environment variables:
CONFIGURATION: Debug or Release (default)
EOF
}
######################################
# Xcode Helpers
######################################
xcode() {
mkdir -p build/DerivedData
CMD="xcodebuild -IDECustomDerivedDataLocation=build/DerivedData BITCODE_GENERATION_MODE=bitcode $@"
echo "Building with command:" $CMD
eval "$CMD"
}
build_framework() {
local target="$1"
local os="$2"
local framework_path="$3"
local config="$CONFIGURATION"
# Archive for each platform
eval "xcodebuild -target $target -configuration $config -sdk $os ONLY_ACTIVE_ARCH=NO BUILD_DIR=$framework_path"
}
######################################
# Variables
######################################
COMMAND="$1"
# Use Debug config if command ends with -debug, otherwise default to Release
case "$COMMAND" in
*-debug)
COMMAND="${COMMAND%-debug}"
CONFIGURATION="Debug"
;;
*) CONFIGURATION=${CONFIGURATION:-Release}
esac
export CONFIGURATION
case "$COMMAND" in
######################################
# Clean
######################################
"clean")
find . -type d -name build -exec rm -r "{}" +\;
exit 0
;;
######################################
# Building for simulator
######################################
"build-simulator")
build_framework ZappMerchantLib iphonesimulator './build'
exit 0
;;
######################################
# Building for device
######################################
"build-device")
build_framework ZappMerchantLib iphoneos './build'
exit 0
;;
######################################
# Release packaging
######################################
"package-ios-simulator")
sh build.sh build-simulator
current_dir="$(pwd)"
pushd build/
rm -rf package/Release-iphonesimulator
mkdir -p package
cd package
cp "$current_dir/README.md" .
cp -r ../Release-iphonesimulator .
rm -rf ../Release-iphonesimulator
rm -rf ../ZappMerchantLib.build
rm -rf ../XCBuildData
printf "\n\nFramework created for simulator in package -> Release-iphonesimulator directory\n\n\n"
package_dir=$(pwd)
popd
exit 0
;;
"package-ios-device")
sh build.sh build-device
current_dir="$(pwd)"
pushd build/
rm -rf package/Release-iphoneos
mkdir -p package
cd package
cp "$current_dir/README.md" .
cp -r ../Release-iphoneos .
rm -rf ../Release-iphoneos
rm -rf ../ZappMerchantLib.build
rm -rf ../XCBuildData
printf "\n\nFramework created for device in package -> Release-iphoneos directory\n\n\n"
package_dir=$(pwd)
popd
;;
*)
echo "Unknown command '$COMMAND'"
usage
exit 1
;;
esac