-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.sh
executable file
·267 lines (215 loc) · 7.36 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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
#!/bin/bash
set -e
CUSTOM_PROJECT_NAME=scrypt
PROJECT_PATH=$(cd `dirname $0`; pwd)
BUILD_DIR="./build"
OS_TYPE="Unknown"
GetOSType(){
uNames=`uname -s`
osName=${uNames: 0: 4}
if [ "$osName" == "Darw" ] # Darwin
then
OS_TYPE="Darwin"
elif [ "$osName" == "Linu" ] # Linux
then
OS_TYPE="Linux"
elif [ "$osName" == "MING" ] # MINGW, windows, git-bash
then
OS_TYPE="Windows"
else
OS_TYPE="Unknown"
fi
}
GetOSType
PackageFiles(){
cd ${BUILD_DIR}
echo currnt run path with $(pwd)
zip -q -r lib${CUSTOM_PROJECT_NAME}_all_platforms.zip ./${CUSTOM_PROJECT_NAME}
cd ../
}
BuildMacX64() {
echo "----------------build with Darwin-------------------x86_64-----------------"
mkdir -p ${BUILD_DIR}/darwin/x86_64
cd ${BUILD_DIR}/darwin/x86_64
if [[ "$OS_TYPE" == "Darwin" ]]; then
cmake ../../../ -DBUILD_ARCH=x86_64 -DCMAKE_OSX_DEPLOYMENT_TARGET=12.0
else
cmake ../../../ -DCMAKE_TOOLCHAIN_FILE=${PROJECT_PATH}/toolchain_darwin_x86_64.cmake -DBUILD_ARCH=x86_64 -DCMAKE_OSX_DEPLOYMENT_TARGET=12.0
fi
cmake ../../../ -DBUILD_ARCH=x86_64
cmake --build .
cd ../../../
echo current path $(pwd)
cp -f ${BUILD_DIR}/darwin/x86_64/lib${CUSTOM_PROJECT_NAME}.a ${BUILD_DIR}/../lib/darwin/lib${CUSTOM_PROJECT_NAME}.a
}
BuildMacARM64() {
echo "----------------build with Darwin-------------------arm64-----------------"
mkdir -p ${BUILD_DIR}/darwin/arm64
cd ${BUILD_DIR}/darwin/arm64
if [[ "$OS_TYPE" == "Darwin" ]]; then
cmake ../../../ -DBUILD_ARCH=arm64 -DCMAKE_OSX_DEPLOYMENT_TARGET=12.0
else
cmake ../../../ -DCMAKE_TOOLCHAIN_FILE=${PROJECT_PATH}/toolchain_darwin_arm64.cmake -DBUILD_ARCH=arm64 -DCMAKE_OSX_DEPLOYMENT_TARGET=12.0
fi
cmake ../../../ -DBUILD_ARCH=arm64
cmake --build .
cd ../../../
cp -f ${BUILD_DIR}/darwin/arm64/lib${CUSTOM_PROJECT_NAME}_arm64.a ${BUILD_DIR}/../lib/darwin/lib${CUSTOM_PROJECT_NAME}_arm64.a
}
BuildMacUniversal() {
echo "----------------build with Darwin---------------"
rm -rf ${BUILD_DIR}/darwin
rm -rf ${BUILD_DIR}/${CUSTOM_PROJECT_NAME}/darwin
mkdir -p ${BUILD_DIR}/${CUSTOM_PROJECT_NAME}/darwin
BuildMacX64
BuildMacARM64
echo "dylib包arch信息" `lipo -info ${PROJECT_PATH}/lib/darwin/lib${CUSTOM_PROJECT_NAME}.a`
echo "dylib包arch信息" `lipo -info ${PROJECT_PATH}/lib/darwin/lib${CUSTOM_PROJECT_NAME}_arm64.a`
}
BuildLinuxX64() {
echo "----------------build with Linux-------------------x86_64-----------------"
mkdir -p ${BUILD_DIR}/linux/x86_64
cd ${BUILD_DIR}/linux/x86_64
if [[ "$OS_TYPE" == "Linux" ]];then
cmake ../../../ -DBUILD_ARCH=x86_64
else
cmake ../../../ -DCMAKE_TOOLCHAIN_FILE=${PROJECT_PATH}/toolchain_linux_x86_64.cmake -DBUILD_ARCH=x86_64
fi
cmake --build .
cd ../../../
echo `pwd`
cp -f ${BUILD_DIR}/linux/x86_64/lib${CUSTOM_PROJECT_NAME}.a ${BUILD_DIR}/../lib/linux/lib${CUSTOM_PROJECT_NAME}.a
}
BuildLinuxARM64() {
echo "----------------build with Linux-------------------arm64-----------------"
mkdir -p ${BUILD_DIR}/linux/arm64
cd ${BUILD_DIR}/linux/arm64
if [[ "$OS_TYPE" == "Linux" ]];then
cmake ../../../ -DBUILD_ARCH=arm64
else
cmake ../../../ -DCMAKE_TOOLCHAIN_FILE=${PROJECT_PATH}/toolchain_linux_arm64.cmake -DBUILD_ARCH=arm64
fi
cmake --build .
cd ../../../
echo `pwd`
cp -f ${BUILD_DIR}/linux/arm64/lib${CUSTOM_PROJECT_NAME}_arm64.a ${BUILD_DIR}/../lib/linux/lib${CUSTOM_PROJECT_NAME}_arm64.a
}
BuildLinuxUniversal() {
echo "----------------build with Linux---------------"
rm -rf ${BUILD_DIR}/linux
rm -rf ${BUILD_DIR}/${CUSTOM_PROJECT_NAME}/linux
mkdir -p ${BUILD_DIR}/${CUSTOM_PROJECT_NAME}/linux
BuildLinuxX64 && BuildLinuxARM64
}
BuildWindowsX64() {
echo "----------------build with Windows-------------------x86_64-----------------"
mkdir -p ${BUILD_DIR}/windows/x86_64
cd ${BUILD_DIR}/windows/x86_64
if [[ "$OS_TYPE" == "Windows" ]];then
cmake ../../../ -DBUILD_ARCH=x86_64
else
cmake ../../../ -DCMAKE_TOOLCHAIN_FILE=${PROJECT_PATH}/toolchain_windows_x86_64.cmake -DBUILD_ARCH=x86_64
fi
cmake --build .
cd ../../../
cp -f ${BUILD_DIR}/windows/x86_64/lib${CUSTOM_PROJECT_NAME}.a ${BUILD_DIR}/../lib/windows/lib${CUSTOM_PROJECT_NAME}.a
}
BuildWindowsARM64() {
echo "----------------build with Windows-------------------arm64-----------------"
mkdir -p ${BUILD_DIR}/windows/arm64
cd ${BUILD_DIR}/windows/arm64
if [[ "$OS_TYPE" == "Windows" ]];then
cmake ../../../ -DBUILD_ARCH=arm64
else
cmake ../../../ -DCMAKE_TOOLCHAIN_FILE=${PROJECT_PATH}/toolchain_windows_arm64.cmake -DBUILD_ARCH=arm64
fi
cmake --build .
cd ../../../
cp -f ${BUILD_DIR}/windows/arm64/lib${CUSTOM_PROJECT_NAME}_arm64.a ${BUILD_DIR}/../lib/windows/lib${CUSTOM_PROJECT_NAME}_arm64.a
}
BuildWindowsUniversal() {
echo "----------------build with Windows---------------"
rm -rf ${BUILD_DIR}/windows
rm -rf ${BUILD_DIR}/${CUSTOM_PROJECT_NAME}/windows
mkdir -p ${BUILD_DIR}/${CUSTOM_PROJECT_NAME}/windows
BuildWindowsX64
# BuildWindowsARM64
}
function BuildAndroid() {
ANDROID_ABI=${1:-${ANDROID_ABI}}
echo "----------------build with Android-------------------${ANDROID_ABI}-----------------"
local A_BUILD_DIR="${BUILD_DIR}/android/${ANDROID_ABI}"
mkdir -p ${A_BUILD_DIR} \
&& mkdir -p ${BUILD_DIR}/${CUSTOM_PROJECT_NAME}/android/${ANDROID_ABI} \
&& cd ${A_BUILD_DIR} \
&& cmake ../../../ \
-DCMAKE_TOOLCHAIN_FILE=${ANDROID_NDK_HOME}/build/cmake/android.toolchain.cmake \
-DANDROID_ABI=${ANDROID_ABI} \
-DANDROID_PLATFORM=android-21 \
&& cmake --build . \
&& cd ../../../
echo curren path $(pwd)
cp -f ${A_BUILD_DIR}/lib${CUSTOM_PROJECT_NAME}.a ${BUILD_DIR}/../lib/android/${ANDROID_ABI}/lib${CUSTOM_PROJECT_NAME}.a
}
function BuildAndroid_All() {
echo "----------------build with Android---------------"
if [ -z "$ANDROID_NDK_HOME" ]; then
echo "[ANDROID_NDK_HOME|ANDROID_NDK] Not Set, Must Install Android NDK And Add [ANDROID_NDK_HOME|ANDROID_NDK] System Path"
return 1
fi
rm -rf ${BUILD_DIR}/android
rm -rf ${BUILD_DIR}/${CUSTOM_PROJECT_NAME}/android
BuildAndroid armeabi-v7a \
&& BuildAndroid arm64-v8a \
&& BuildAndroid x86 \
&& BuildAndroid x86_64
}
BuildAll() {
local RELEASE_DIR=${BUILD_DIR}/${CUSTOM_PROJECT_NAME}
rm -rf ${RELEASE_DIR}
mkdir -p ${RELEASE_DIR}
mkdir -p ${RELEASE_DIR}/include
cp -f ./include/* ${RELEASE_DIR}/include
BuildMacUniversal
BuildLinuxUniversal
BuildWindowsUniversal
BuildAndroid_All
PackageFiles
}
case "$1" in
all)
BuildAll
;;
ubuntu-*)
echo "Linux"
BuildLinuxUniversal
;;
linux*)
echo "Linux"
BuildLinuxUniversal
;;
centos-*)
echo "Linux"
BuildLinuxUniversal
;;
macos*)
echo "Darwin"
BuildMacUniversal
;;
darwin*)
echo "Darwin"
BuildMacUniversal
;;
windows*)
echo "Windows"
BuildWindowsUniversal
;;
android)
echo "Android"
BuildAndroid_All
;;
*)
echo "Must start with [all|Linux|Darwin/MacOS|Windows|Android]"
exit 1
;;
esac