-
Notifications
You must be signed in to change notification settings - Fork 1
/
WinMake.sh
238 lines (190 loc) · 8.1 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
#!/bin/bash
QT_PATH='/c/Qt'
QT_VERSION=5.15.2
CERTIFICATE_THUMBPRINT="e9b444fffb1375ece027e40d8637b6da3fdaaf0e"
TIMESTAMP_URL="http://timestamp.digicert.com" #http://timestamp.comodoca.com/rfc3161
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 ;;
'test') BUILD='test' ; DO_PACKAGE=0 ;;
'package') BUILD='release' ; DO_PACKAGE=1 ;;
*)
echo "Invalid operation!" >&2
exit 1
;;
esac
DIST_NAME='qtext'
DIST_VERSION=`grep VERSION src/QText.pro | head -1 | cut -d'=' -f2 | awk '{print $$1}' | tr -d '"'`
CMD_QMAKE=`ls $QT_PATH/$QT_VERSION/**/bin/qmake.exe | sort | tail -1`
CMD_MAKE=`ls $QT_PATH/Tools/**/bin/mingw32-make.exe | sort | tail -1`
if [[ ! -f "$CMD_QMAKE" ]]; then
echo -e "${ESCAPE_ERROR}Cannot find qmake!${ESCAPE_RESET}" >&2
exit 1
fi
QMAKE_DIR=`dirname $CMD_QMAKE`
if [[ ! -f "$CMD_MAKE" ]]; then
echo -e "${ESCAPE_ERROR}Cannot find make!${ESCAPE_RESET}" >&2
exit 1
fi
OPENSSL_DIR=$QT_PATH/Tools/QtCreator/bin
if [[ ! -f "$OPENSSL_DIR/libcrypto-1_1-x64.dll" ]] || [[ ! -f "$OPENSSL_DIR/libssl-1_1-x64.dll" ]]; then
echo -e "${ESCAPE_WARNING}Cannot find OpenSSL files.${ESCAPE_RESET}" >&2
fi
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
if [[ ! -f "$CMD_SIGNTOOL" ]]; then
echo -e "${ESCAPE_WARNING}Cannot find signtool!${ESCAPE_RESET}" >&2
fi
echo -e "QMake directory ...: ${ESCAPE_INFO}$QMAKE_DIR${ESCAPE_RESET}"
echo -e "QMake executable ..: ${ESCAPE_INFO}$CMD_QMAKE${ESCAPE_RESET}"
echo -e "Make executable ...: ${ESCAPE_INFO}$CMD_MAKE${ESCAPE_RESET}"
echo -e "SignTool executable: ${ESCAPE_INFO}$CMD_SIGNTOOL${ESCAPE_RESET}"
HAS_UNCOMMITTED_RESULT=`git diff --quiet ; 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
PATH=$PATH:`dirname $CMD_MAKE`
$CMD_QMAKE -spec win32-g++ CONFIG+=$BUILD ../src/QText.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/qtext.exe ../bin/QText.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/Qt5Network.dll ../bin/
cp $QMAKE_DIR/Qt5PrintSupport.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/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/QText.exe
else
"$CMD_SIGNTOOL" sign -s "My" -sha1 $CERTIFICATE_THUMBPRINT -v ../bin/QText.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
INNOSETUP_PATH='/c/Program Files (x86)/Inno Setup 6/ISCC.exe'
if [[ ! -f "$INNOSETUP_PATH" ]]; then
echo -e "${ESCAPE_ERROR}Cannot find InnoSetup 6!${ESCAPE_RESET}" >&2
exit 1
fi
cd ..
"$INNOSETUP_PATH" package/win/QText.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
fi
;;
'debug')
cp debug/qtext.exe ../bin/QText.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/Qt5Network.dll ../bin/
cp $QMAKE_DIR/Qt5PrintSupport.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/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
;;
'test')
cp $QMAKE_DIR/libgcc_s_seh-1.dll release/
cp $QMAKE_DIR/libstdc++-6.dll release/
cp $QMAKE_DIR/libwinpthread-1.dll release/
cp $QMAKE_DIR/Qt5Core.dll release/
cp $QMAKE_DIR/Qt5Gui.dll release/
cp $QMAKE_DIR/Qt5Network.dll release/
cp $QMAKE_DIR/Qt5PrintSupport.dll release/
cp $QMAKE_DIR/Qt5Test.dll release/
cp $QMAKE_DIR/Qt5Widgets.dll release/
echo
cd release
./qtexttests.exe \
| GREP_COLOR='01;31' grep --color=always -e '^FAIL! ' -e '^' \
| GREP_COLOR='01;32' grep --color=always -e '^PASS ' -e '^'
if [[ $? -ne 0 ]]; then
echo -e "${ESCAPE_ERROR}Testing failed!${ESCAPE_RESET}" >&2
exit 1
fi
;;
esac
fi