forked from sailfishos/sdk-build-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
buildifw_qt5.sh
executable file
·255 lines (213 loc) · 6.77 KB
/
buildifw_qt5.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
#!/bin/bash
#
# Builds installer framework and optionally uploads it to a server
#
# Copyright (C) 2014 Jolla Oy
# Contact: Juha Kallioinen <[email protected]>
# All rights reserved.
#
# You may use this file under the terms of BSD license as follows:
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# * Neither the name of the Jolla Ltd nor the
# names of its contributors may be used to endorse or promote products
# derived from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR
# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
UNAME_SYSTEM=$(uname -s)
UNAME_ARCH=$(uname -m)
# some default values
OPT_UPLOAD_HOST=10.0.0.20
OPT_UPLOAD_USER=sdkinstaller
OPT_UPLOAD_PATH=/var/www/sailfishos
IFW_BUILD_DIR=ifw-build-2.0.1
if [[ $UNAME_SYSTEM == "Linux" ]] || [[ $UNAME_SYSTEM == "Darwin" ]]; then
OPT_QTDIR=$HOME/invariant/qt-everywhere-opensource-src-5.5.0-static-build
OPT_IFW_SRC=$HOME/invariant/installer-framework-2.0.1
else
OPT_QTDIR="c:\invariant\qt-everywhere-opensource-src-5.5.0-static-build-msvc2012"
OPT_IFW_SRC="c:\invariant\installer-framework-2.0.1"
fi
fail() {
echo "FAIL: $@"
exit 1
}
usage() {
cat <<EOF
Build Installer Framework and optionally upload the result to a server
Usage:
$(basename $0) [OPTION]
Current values are displayed in [ ]s.
Options:
-ifw | --ifw-src <DIR> Installer FW source directory [$OPT_IFW_SRC]
-qt | --qt-dir <DIR> Static Qt (install) directory [$OPT_QTDIR]
-u | --upload <DIR> upload local build result to [$OPT_UPLOAD_HOST] as user [$OPT_UPLOAD_USER]
the uploaded build will be copied to [$OPT_UPLOAD_PATH/<DIR>]
the upload directory will be created if it is not there
-uh | --uhost <HOST> override default upload host
-up | --upath <PATH> override default upload path
-uu | --uuser <USER> override default upload user
-y | --non-interactive answer yes to all questions presented by the script
-h | --help this help
EOF
# exit if any argument is given
[[ -n "$1" ]] && exit 1
}
# handle commandline options
while [[ ${1:-} ]]; do
case "$1" in
-ifw | --ifw-src ) shift
OPT_IFW_SRC=$1; shift
;;
-qt | --qt-dir ) shift
OPT_QTDIR=$1; shift
;;
-u | --upload ) shift
OPT_UPLOAD=1
OPT_UL_DIR=$1; shift
if [[ -z $OPT_UL_DIR ]]; then
fail "upload option requires a directory name"
fi
;;
-uh | --uhost ) shift;
OPT_UPLOAD_HOST=$1; shift
;;
-up | --upath ) shift;
OPT_UPLOAD_PATH=$1; shift
;;
-uu | --uuser ) shift;
OPT_UPLOAD_USER=$1; shift
;;
-y | --non-interactive ) shift
OPT_YES=1
;;
-h | --help ) shift
usage quit
;;
* )
usage quit
;;
esac
done
if [[ ! -d $OPT_QTDIR ]]; then
fail "Qt directory [$OPT_QTDIR] not found"
fi
if [[ ! -d $OPT_IFW_SRC ]]; then
fail "Installer framework source directory [$OPT_IFW_SRC] not found"
fi
# summary
cat <<EOF
Summary of chosen actions:
1) Build Installer Framework
- Use [$PWD] as the build directory
- Installer Framework source directory [$OPT_IFW_SRC]
- Static Qt directory [$OPT_QTDIR]
EOF
if [[ -n $OPT_UPLOAD ]]; then
echo " 2) Upload build result as user [$OPT_UPLOAD_USER] to [$OPT_UPLOAD_HOST:$OPT_UPLOAD_PATH/$OPT_UL_DIR]"
else
echo " 2) Do NOT upload build result anywhere"
fi
# confirm
if [[ -z $OPT_YES ]]; then
while true; do
read -p "Do you want to continue? (y/n) " answer
case $answer in
[Yy]*)
break ;;
[Nn]*)
echo "Ok, exiting"
exit 0
;;
*)
echo "Please answer yes or no."
;;
esac
done
fi
build_unix() {
export QTDIR=$OPT_QTDIR
export PATH=$QTDIR/qtbase/bin:$PATH
rm -rf $IFW_BUILD_DIR
mkdir -p $IFW_BUILD_DIR
pushd $IFW_BUILD_DIR
$QTDIR/qtbase/bin/qmake -r $OPT_IFW_SRC/installerfw.pro
make -j$(getconf _NPROCESSORS_ONLN)
popd
}
build_windows() {
rm -rf $IFW_BUILD_DIR
mkdir -p $IFW_BUILD_DIR
pushd $IFW_BUILD_DIR
# create the build script for windows
cat <<EOF > build-windows.bat
@echo off
if DEFINED ProgramFiles(x86) set _programs=%ProgramFiles(x86)%
if Not DEFINED ProgramFiles(x86) set _programs=%ProgramFiles%
set QTDIR=$OPT_QTDIR
set QMAKESPEC=win32-msvc2012
set PATH=%PATH%;c:\invariant\bin
call "%_programs%\Microsoft Visual Studio 12.0\VC\vcvarsall.bat"
call %QTDIR%\qtbase\bin\qmake -r $OPT_IFW_SRC\installerfw.pro
call jom
EOF
# execute the bat
cmd //c build-windows.bat
popd
}
# if any step below fails, exit
set -e
# record start time
BUILD_START=$(date +%s)
if [[ $UNAME_SYSTEM == "Linux" ]] || [[ $UNAME_SYSTEM == "Darwin" ]]; then
build_unix
else
build_windows
fi
IFW_PACKAGE_NAME="InstallerFW.7z"
if [[ $UNAME_SYSTEM == "Linux" ]]; then
if [[ $UNAME_ARCH == "x86_64" ]]; then
BUILD_ARCH="linux-64"
else
BUILD_ARCH="linux-32"
fi
elif [[ $UNAME_SYSTEM == "Darwin" ]]; then
BUILD_ARCH="mac"
else
BUILD_ARCH="windows"
fi
pushd $IFW_BUILD_DIR
# install results
mkdir -p ifw
cp -a bin ifw
7z a -mx=9 $IFW_PACKAGE_NAME ifw
# record end time
BUILD_END=$(date +%s)
time=$(( BUILD_END - BUILD_START ))
hour=$(( $time / 3600 ))
mins=$(( $time / 60 - 60*$hour ))
secs=$(( $time - 3600*$hour - 60*$mins ))
echo Time used for IFW build: $(printf "%02d:%02d:%02d" $hour $mins $secs)
if [[ -n "$OPT_UPLOAD" ]]; then
echo "Uploading $IFW_PACKAGE_NAME ..."
# create upload dir
ssh $OPT_UPLOAD_USER@$OPT_UPLOAD_HOST mkdir -p $OPT_UPLOAD_PATH/$OPT_UL_DIR/$BUILD_ARCH
scp $IFW_PACKAGE_NAME $OPT_UPLOAD_USER@$OPT_UPLOAD_HOST:$OPT_UPLOAD_PATH/$OPT_UL_DIR/$BUILD_ARCH/
fi
popd