-
Notifications
You must be signed in to change notification settings - Fork 0
/
WinMake.sh
279 lines (224 loc) · 9.34 KB
/
WinMake.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
268
269
270
271
272
273
274
275
276
277
278
279
#!/bin/bash
QT_PATH='/c/Qt'
CERTIFICATE_THUMBPRINT="e9b444fffb1375ece027e40d8637b6da3fdaaf0e"
TIMESTAMP_URL="http://timestamp.digicert.com"
if [ -t 1 ]; then
ESCAPE_RESET="\E[0m"
ESCAPE_INFO="\E[36;1m"
ESCAPE_WARNING="\E[33;1m"
ESCAPE_ERROR="\E[31;1m"
ESCAPE_RESULT="\E[32;1m"
fi
if [[ "$2" != "" ]]; then
echo "Invalid argument count!" >&2
exit 1
fi
case $1 in
'') BUILD='release' ; DO_PACKAGE=0 ;;
'clean') BUILD='' ; DO_PACKAGE=0 ;;
'debug') BUILD='debug' ; DO_PACKAGE=0 ;;
'release') BUILD='release' ; DO_PACKAGE=0 ;;
'package') BUILD='release' ; DO_PACKAGE=1 ;;
*)
echo "Invalid operation!" >&2
exit 1
;;
esac
DIST_NAME='barecam'
DIST_VERSION=`grep VERSION src/BareCam.pro | head -1 | cut -d'=' -f2 | awk '{print $$1}' | tr -d '"' | xargs`
CMD_QMAKE=`ls $QT_PATH/**/**/bin/qmake.exe | sort | tail -1`
CMD_MAKE=`ls $QT_PATH/Tools/**/bin/mingw32-make.exe | sort | tail -1`
QMAKE_DIR=`dirname $CMD_QMAKE`
OPENSSL_DIR=$QT_PATH/Tools/QtCreator/bin
CMD_CERTUTIL=`command -v certutil`
if [[ ! -f "$CMD_CERTUTIL" ]]; then
echo -e "${ESCAPE_WARNING}Cannot find certutil!${ESCAPE_RESET}" >&2
CERTIFICATE_THUMBPRINT=""
elif [[ "$CERTIFICATE_THUMBPRINT" == "" ]]; then
echo -e "${ESCAPE_WARNING}No signing certificate thumbprint!${ESCAPE_RESET}" >&2
else
$CMD_CERTUTIL -silent -verifystore -user My $CERTIFICATE_THUMBPRINT > /dev/null
if [[ $? -ne 0 ]]; then
echo -e "${ESCAPE_WARNING}Cannot validate certificate thumbprint!${ESCAPE_RESET}" >&2
CERTIFICATE_THUMBPRINT=""
fi
fi
CMD_SIGNTOOL=""
for SIGNTOOL_PATH in "/c/Program Files (x86)/Microsoft SDKs/ClickOnce/SignTool/signtool.exe" \
"/c/Program Files (x86)/Windows Kits/10/App Certification Kit/signtool.exe" \
"/c/Program Files (x86)/Windows Kits/10/bin/x86/signtool.exe"; do
if [[ -f "$SIGNTOOL_PATH" ]]; then
CMD_SIGNTOOL="$SIGNTOOL_PATH"
break
fi
done
CMD_INNOSETUP=""
for INNOSETUP_PATH in "/c/Program Files (x86)/Inno Setup 6/ISCC.exe"; do
if [[ -f "$INNOSETUP_PATH" ]]; then
CMD_INNOSETUP="$INNOSETUP_PATH"
break
fi
done
CMD_WINRAR=""
for WINRAR_PATH in "/c/Program Files/WinRAR/WinRAR.exe"; do
if [[ -f "$WINRAR_PATH" ]]; then
CMD_WINRAR="$WINRAR_PATH"
break
fi
done
if [[ -d "$QMAKE_DIR" ]]; then
echo -e "QMake directory ....: ${ESCAPE_INFO}$QMAKE_DIR${ESCAPE_RESET}"
else
echo -e "QMake directory ....: ${ESCAPE_ERROR}Not found!${ESCAPE_RESET}"
fi
if [[ -f "$CMD_QMAKE" ]]; then
echo -e "QMake executable ...: ${ESCAPE_INFO}$CMD_QMAKE${ESCAPE_RESET}"
else
echo -e "QMake executable ...: ${ESCAPE_ERROR}Not found!${ESCAPE_RESET}"
fi
if [[ -f "$CMD_QMAKE" ]]; then
echo -e "Make executable ....: ${ESCAPE_INFO}$CMD_MAKE${ESCAPE_RESET}"
else
echo -e "Make executable ....: ${ESCAPE_ERROR}Not found!${ESCAPE_RESET}"
fi
if [[ -f "$OPENSSL_DIR/libcrypto-1_1-x64.dll" ]] && [[ -f "$OPENSSL_DIR/libssl-1_1-x64.dll" ]]; then
echo -e "OpenSSL directory ..: ${ESCAPE_INFO}$OPENSSL_DIR${ESCAPE_RESET}"
else
echo -e "OpenSSL directory ..: ${ESCAPE_WARNING}Not found!${ESCAPE_RESET}"
fi
if [[ -f "$CMD_SIGNTOOL" ]]; then
echo -e "SignTool executable : ${ESCAPE_INFO}$CMD_SIGNTOOL${ESCAPE_RESET}"
else
echo -e "SignTool executable : ${ESCAPE_WARNING}Not found!${ESCAPE_RESET}"
fi
if [[ -f "$CMD_INNOSETUP" ]]; then
echo -e "InnoSetup executable: ${ESCAPE_INFO}$CMD_INNOSETUP${ESCAPE_RESET}"
else
echo -e "InnoSetup executable: ${ESCAPE_ERROR}Not found!${ESCAPE_RESET}"
fi
if [[ -f "$CMD_WINRAR" ]]; then
echo -e "WinRAR executable ..: ${ESCAPE_INFO}$CMD_WINRAR${ESCAPE_RESET}"
else
echo -e "WinRAR executable ..: ${ESCAPE_WARNING}Not found!${ESCAPE_RESET}"
fi
HAS_UNCOMMITTED_RESULT=`git diff --quiet ; echo $?`
echo
rm bin/* 2> /dev/null
rm -r bin/platforms 2> /dev/null
rm -r bin/styles 2> /dev/null
mkdir -p bin
rm -R build/ 2> /dev/null
mkdir -p build
cd build
if [[ "$BUILD" != "" ]]; then
if [[ ! -f "$CMD_QMAKE" ]]; then
echo -e "${ESCAPE_ERROR}Cannot find qmake!${ESCAPE_RESET}" >&2
exit 1
fi
if [[ ! -f "$CMD_MAKE" ]]; then
echo -e "${ESCAPE_ERROR}Cannot find make!${ESCAPE_RESET}" >&2
exit 1
fi
PATH=$PATH:`dirname $CMD_MAKE`
$CMD_QMAKE -spec win32-g++ CONFIG+=$BUILD ../src/BareCam.pro
if [[ $? -ne 0 ]]; then
echo -e "${ESCAPE_ERROR}QMake failed!${ESCAPE_RESET}" >&2
exit 1
fi
$CMD_MAKE -f Makefile
if [[ $? -ne 0 ]]; then
echo -e "${ESCAPE_ERROR}Make failed!${ESCAPE_RESET}" >&2
exit 1
fi
case $BUILD in
'release')
cp release/barecam.exe ../bin/BareCam.exe
cp $QMAKE_DIR/libgcc_s_seh-1.dll ../bin/
cp $QMAKE_DIR/libstdc++-6.dll ../bin/
cp $QMAKE_DIR/libwinpthread-1.dll ../bin/
cp $QMAKE_DIR/Qt5Core.dll ../bin/
cp $QMAKE_DIR/Qt5Gui.dll ../bin/
cp $QMAKE_DIR/Qt5Multimedia.dll ../bin/
cp $QMAKE_DIR/Qt5MultimediaWidgets.dll ../bin/
cp $QMAKE_DIR/Qt5Network.dll ../bin/
cp $QMAKE_DIR/Qt5Widgets.dll ../bin/
cp $OPENSSL_DIR/libcrypto-1_1-x64.dll ../bin/
cp $OPENSSL_DIR/libssl-1_1-x64.dll ../bin/
mkdir ../bin/mediaservice
cp $QMAKE_DIR/../plugins/mediaservice/dsengine.dll ../bin/mediaservice/
cp $QMAKE_DIR/../plugins/mediaservice/qtmedia_audioengine.dll ../bin/mediaservice/
mkdir ../bin/platforms
cp $QMAKE_DIR/../plugins/platforms/qwindows.dll ../bin/platforms/
mkdir ../bin/styles
cp $QMAKE_DIR/../plugins/styles/qwindowsvistastyle.dll ../bin/styles/
if [[ "$CERTIFICATE_THUMBPRINT" != "" ]] && [[ -f "$CMD_SIGNTOOL" ]]; then
echo
if [[ "$TIMESTAMP_URL" != "" ]]; then
"$CMD_SIGNTOOL" sign -s "My" -sha1 $CERTIFICATE_THUMBPRINT -tr $TIMESTAMP_URL -v ../bin/BareCam.exe
else
"$CMD_SIGNTOOL" sign -s "My" -sha1 $CERTIFICATE_THUMBPRINT -v ../bin/BareCam.exe
fi
fi
if [[ $HAS_UNCOMMITTED_RESULT -ne 0 ]] && [[ "$BUILD" == 'release' ]]; then
echo -e "${ESCAPE_WARNING}Uncommitted changes present.${ESCAPE_RESET}" >&2
fi
echo -e "${ESCAPE_RESULT}Release build completed.${ESCAPE_RESET}" >&2
if [[ $DO_PACKAGE -ne 0 ]]; then
echo
if [[ ! -f "$CMD_INNOSETUP" ]]; then
echo -e "${ESCAPE_ERROR}Cannot find InnoSetup 6!${ESCAPE_RESET}" >&2
exit 1
fi
cd ..
"$CMD_INNOSETUP" package/win/BareCam.iss
if [[ $? -eq 0 ]]; then
LAST_PACKAGE=`ls -t dist/*.exe | head -1`
if [[ "$CERTIFICATE_THUMBPRINT" != "" ]] && [[ -f "$CMD_SIGNTOOL" ]]; then
echo
if [[ "$TIMESTAMP_URL" != "" ]]; then
"$CMD_SIGNTOOL" sign -s "My" -sha1 $CERTIFICATE_THUMBPRINT -tr $TIMESTAMP_URL -v $LAST_PACKAGE
else
"$CMD_SIGNTOOL" sign -s "My" -sha1 $CERTIFICATE_THUMBPRINT -v $LAST_PACKAGE
fi
fi
echo
echo -e "${ESCAPE_RESULT}Package created ($LAST_PACKAGE).${ESCAPE_RESET}" >&2
else
echo -e "${ESCAPE_ERROR}Packaging failed!${ESCAPE_RESET}" >&2
exit 1
fi
# make ZIP
ZIP_NAME="dist/$DIST_NAME-$DIST_VERSION.zip"
"$CMD_WINRAR" a -afzip -ep -m5 $ZIP_NAME bin/*
if [[ $? -eq 0 ]]; then
echo -e "${ESCAPE_RESULT}Package created ($ZIP_NAME).${ESCAPE_RESET}" >&2
else
echo -e "${ESCAPE_ERROR}Packaging failed ($ZIP_NAME)!${ESCAPE_RESET}" >&2
exit 1
fi
fi
;;
'debug')
cp debug/barecam.exe ../bin/BareCam.exe
cp $QMAKE_DIR/libgcc_s_seh-1.dll ../bin/
cp $QMAKE_DIR/libstdc++-6.dll ../bin/
cp $QMAKE_DIR/libwinpthread-1.dll ../bin/
cp $QMAKE_DIR/Qt5Core.dll ../bin/
cp $QMAKE_DIR/Qt5Gui.dll ../bin/
cp $QMAKE_DIR/Qt5Multimedia.dll ../bin/
cp $QMAKE_DIR/Qt5MultimediaWidgets.dll ../bin/
cp $QMAKE_DIR/Qt5Network.dll ../bin/
cp $QMAKE_DIR/Qt5Widgets.dll ../bin/
cp $OPENSSL_DIR/libcrypto-1_1-x64.dll ../bin/
cp $OPENSSL_DIR/libssl-1_1-x64.dll ../bin/
mkdir ../bin/mediaservice
cp $QMAKE_DIR/../plugins/mediaservice/dsengine.dll ../bin/mediaservice/
cp $QMAKE_DIR/../plugins/mediaservice/qtmedia_audioengine.dll ../bin/mediaservice/
mkdir ../bin/platforms
cp $QMAKE_DIR/../plugins/platforms/qwindows.dll ../bin/platforms/
mkdir ../bin/styles
cp $QMAKE_DIR/../plugins/styles/qwindowsvistastyle.dll ../bin/styles/
echo -e "${ESCAPE_RESULT}Debug build completed.${ESCAPE_RESET}" >&2
;;
esac
fi