-
Notifications
You must be signed in to change notification settings - Fork 2
/
bakeqtpi.bash
executable file
·452 lines (395 loc) · 12.2 KB
/
bakeqtpi.bash
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
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
#!/bin/bash
#This script will download, set up, compile QT5, and set up the SDCard image ready to use.
#Pass -h to use https for git
SCRIPT_DIR=$PWD
OPT_DIRECTORY=~/opt
QTBASE=$OPT_DIRECTORY/qt5
#Some sensible defaults
if [[ "$OSTYPE" =~ darwin.* ]]
then
CROSSCOMPILETOOLS=$OPT_DIRECTORY/trismers-cross-compile-tools-osx
CROSSCOMPILER=$OPT_DIRECTORY/arm-linux-gnueabihf-osx
else
CROSSCOMPILETOOLS=$OPT_DIRECTORY/cross-compile-tools
CROSSCOMPILER=$OPT_DIRECTORY/gcc-4.7-linaro-rpi-gnueabihf
fi
CROSSCOMPILERPATH=$CROSSCOMPILER/bin/arm-linux-gnueabihf-gcc
MOUNT=$OPT_DIRECTORY/rasp-pi-image
ROOTFS=$OPT_DIRECTORY/rasp-pi-rootfs
QT5PIPREFIX=/usr/local/qt5pi
QT5ROOTFSPREFIX=$ROOTFS/usr/local/qt5pi
#Raspbian image and download stuff
RASPBIAN=2012-10-28-wheezy-raspbian
RASPBIAN_HTTP=http://ftp.snt.utwente.nl/pub/software/rpi/images/raspbian/$RASPBIAN/$RASPBIAN.zip
RASPBIAN_TORRENT=http://downloads.raspberrypi.org/images/raspbian/$RASPBIAN/$RASPBIAN.zip.torrent
CUSTOM_RASPBIAN=""
WGET_OPT="-nc -c"
command -v sudo >/dev/null 2>&1 || { echo >&2 "Sudo needs to be installed for the fixQualifiedLibraryPaths script to work"; exit 1; }
#Debugfs path
DEBUGFS=/usr/local/Cellar/e2fsprogs/*/sbin/debugfs
#Git repos
if [[ "$OSTYPE" =~ darwin.* ]]
then
CROSSCOMPILEGIT="gitorious.org/~trismer/cross-compile-tools/trismers-cross-compile-tools-osx.git"
else
CROSSCOMPILEGIT="gitorious.org/cross-compile-tools/cross-compile-tools.git "
fi
QT_GIT="gitorious.org/qt/qt5.git"
GIT=GIT
QT5_PACKAGE_VER=5.0.0
QT5_PACKAGE_DOWNLOAD=http://releases.qt-project.org/qt5/$QT5_PACKAGE_VER/single/qt-everywhere-opensource-src-$QT5_PACKAGE_VER.tar.gz
INITREPOARGS="--no-webkit -f"
CONFIGURE_OPTIONS=""
#Work out how many concurrent threads to run
if [[ "$OSTYPE" =~ darwin.* ]]
then
CORES=`sysctl -a | grep machdep.cpu.thread_count | awk '{print $2}'`
else
CORES=`grep -c '^processor' /proc/cpuinfo`
fi
CORES=`echo $CORES | grep '^[[:digit:]]*$'`
if [ "$CORES" == "" ]
then
CORES=1
echo "CPU Core count failed, defaulting to single thread compilation"
else
echo "Using $CORES threads for compilation"
fi
#Parse arguments
while test $# -gt 0
do
case $1 in
# Normal option processing
-h | --help)
# usage and help
echo "Usage:"
echo " ./bakeqtpi.bash [options]"
echo "options:"
echo " --package Downloads and builds the official QT5 Package from qt-project.org"
echo " --http Tells git and init-repository to use http(s)"
echo " --httppi Tells the script to download the Raspbian image using http/wget"
echo " --torrentpi Tells the script to download the Raspbian image using torrent/ctorrent"
echo " --raspbian <path> Use custom raspbian. Note, you can point this to your SD card, assuming it's a standard"
echo " raspbian sd card using --raspbian /dev/sdX (Don't put the partition number in)"
echo " --confclean Runs 'make confclean' before running ./configure"
echo " -v, --version Version Info"
echo " -h, --help Help and usage info"
exit
;;
-v | --version)
# version info
echo "Version 0.1"
exit
;;
--package)
QT5_PACKAGE=1
;;
--http)
GIT=HTTPS
;;
--httppi)
HTTPPI=1
;;
--torrentpi)
TORRENT=1
;;
--raspbian)
shift
CUSTOM_RASPBIAN=$1
;;
--confclean)
CONFCLEAN=1
;;
# Special cases
--)
break
;;
--*)
# error unknown (long) option $1
;;
-?)
# error unknown (short) option $1
;;
# FUN STUFF HERE:
# Split apart combined short options
-*)
split=$1
shift
set -- $(echo "$split" | cut -c 2- | sed 's/./-& /g') "$@"
continue
;;
# Done with options
*)
break
;;
esac
shift
done
if [ "$GIT" == "HTTPS" ]; then
CROSSCOMPILEGIT="https://git."$CROSSCOMPILEGIT
QT_GIT="https://git."$QT_GIT
INITREPOARGS="$INITREPOARGS --http"
else
CROSSCOMPILEGIT="git://"$CROSSCOMPILEGIT
QT_GIT="git://"$QT_GIT
fi
function error {
case "$1" in
1) echo "Error making directories"
;;
2) echo "Error downloading raspbian image"
;;
3) echo "Error mounting raspbian image"
;;
4) echo "Error downloading cross compilation tools"
;;
5) echo "Error extracting cross compilation tools"
;;
6) echo "Error cloning qt5 repo"
;;
7) echo "Error initialising qt5 repo"
;;
8) echo "Error running fixQualifiedLibraryPaths"
;;
9) echo "Configuring QT Failed"
;;
10) echo "Make failed for QTBase"
;;
*) echo "Unknown error"
;;
esac
exit -1
}
#Download and mount the Raspbian image, tested on OS X and Ubuntu
function downloadAndMountPi {
cd $OPT_DIRECTORY
if [ "$CUSTOM_RASPBIAN" == "" ]; then
echo "Downloading Raspbian"
if [ "$TORRENT" == 1 ]; then
dl="T"
elif [ "$HTTPPI" == 1 ];then
dl="H"
else
echo "Would you like to download the Raspbian image using HTTP(H) or ctorrent(T)"
read -e dl
while [[ ! $dl =~ [TtHh] ]]; do
echo "Please type H for HTTP or T for ctorrent"
read dl
done
fi
if [[ $dl =~ [Hh] ]]; then
wget $WGET_OPT $RASPBIAN_HTTP || error 2
else
wget $WGET_OPT $RASPBIAN_TORRENT || error 2
ctorrent -a -e - $RASPBIAN.zip.torrent || error 2
fi
unzip $RASPBIAN.zip || error 2
RASPBIAN_IMG=$RASPBIAN.img
else
RASPBIAN_IMG=$CUSTOM_RASPBIAN
fi
echo "Using Raspbian image at $CUSTOM_RASPBIAN"
echo "Mounting raspbian image"
if [[ "$OSTYPE" =~ darwin.* ]];
then
if [ -d $MOUNT ]; then
hdiutil detach $MOUNT
fi
#echo "hdiutil attach -mountpoint $SCRIPT_DIR $MOUNT $RASPBIAN_IMG"
DISK=`hdiutil attach -mountpoint $MOUNT $RASPBIAN_IMG | grep Linux | awk '{print $1}'`
if [[ ! "$DISK" =~ /dev/disk* ]]; then
error 3
fi
echo "rdump lib $ROOTFS" > $OPT_DIRECTORY/rdump.lst
echo "rdump opt $ROOTFS" >> $OPT_DIRECTORY/rdump.lst
echo "rdump usr $ROOTFS" >> $OPT_DIRECTORY/rdump.lst
echo "rdump var $ROOTFS" >> $OPT_DIRECTORY/rdump.lst
if [ ! -d $ROOTFS ]; then
mkdir $ROOTFS
$DEBUGFS -f $OPT_DIRECTORY/rdump.lst $DISK || error 3
fi
else
if [ ! -d $ROOTFS ]; then
if [ "$(id -u)" != "0" ]; then
sudo mkdir $ROOTFS || error 3
else
mkdir $ROOTFS || error 3
fi
else
if [ "$(id -u)" != "0" ]; then
sudo umount $ROOTFS
else
umount $ROOTFS
fi
fi
if [ "$(id -u)" != "0" ]; then
sudo mount -o loop,offset=62914560 $RASPBIAN_IMG $ROOTFS || error 3
else
mount -o loop,offset=62914560 $RASPBIAN_IMG $ROOTFS || error 3
fi
fi
echo "Raspbian mounted"
}
#Download and extract cross compiler and tools
function dlcc {
cd $OPT_DIRECTORY
echo "Downloading Cross compiler and extra tools"
if [[ "$OSTYPE" =~ darwin.* ]]
then
wget $WGET_OPT http://trismer.com/downloads/arm-linux-gnueabihf-osx-2012-08-28.tar.gz || error 4
tar -xf arm-linux-gnueabihf-osx-2012-08-28.tar.gz || error 5
CROSSCOMPILER=$OPT_DIRECTORY/arm-linux-gnueabihf-osx
CROSSCOMPILERPATH=$CROSSCOMPILER/bin/arm-linux-gnueabihf-gcc
#create symbolic link for readelf
ln -s $CROSSCOMPILER/bin/arm-linux-gnueabihf-readelf readelf
export PATH=$OPT_DIRECTORY:$PATH
else
wget $WGET_OPT http://blueocean.qmh-project.org/gcc-4.7-linaro-rpi-gnueabihf.tbz || error 4
tar -xf gcc-4.7-linaro-rpi-gnueabihf.tbz || error 5
CROSSCOMPILERPATH=$CROSSCOMPILER/bin/arm-linux-gnueabihf-gcc
fi
if [ ! -d $CROSSCOMPILETOOLS/.git ]; then
git clone $CROSSCOMPILEGIT || error 4
else
cd $CROSSCOMPILETOOLS && git pull && cd $OPT_DIRECTORY
fi
echo "Cross Compilation tools downloaded and extracted"
}
function dlqt {
if [ ! "$QT5_PACKAGE" == 1 ];
then
echo "Cloning QT Code"
cd $OPT_DIRECTORY
if [ ! -d $OPT_DIRECTORY/qt5/.git ]; then
git clone $QT_GIT || error 6
else
cd $OPT_DIRECTORY/qt5/ && git pull
cd $CROSSCOMPILETOOLS
./syncQt5
cd $OPT_DIRECTORY
fi
cd qt5
while [ ! -e $OPT_DIRECTORY/qt5/.initialised ]
do
./init-repository $INITREPOARGS && touch $OPT_DIRECTORY/qt5/.initialised
done || error 7
echo "Code cloned"
#cd $OPT_DIRECTORY/qt5/qtjsbackend
#git fetch https://codereview.qt-project.org/p/qt/qtjsbackend refs/changes/56/27256/4 && git cherry-pick FETCH_HEAD
else
echo "Donwloading QT5 Package"
cd $OPT_DIRECTORY
wget $WGET_OPT $QT5_PACKAGE_DOWNLOAD || error 4
tar -xf qt-everywhere-opensource-src-$QT5_PACKAGE_VER.tar.gz
echo "QT5 Downloaded"
fi
}
function prepcctools {
cd $CROSSCOMPILETOOLS
echo "Fixing Qualified Library Paths, whatever that means..."
./fixQualifiedLibraryPaths $ROOTFS $CROSSCOMPILERPATH || error 8
cd $OPT_DIRECTORY/$QT5_SOURCE_DIRECTORY/qtbase
}
function configureandmakeqtbase {
echo "Configuring QT Base"
CONFIGURE_OPTIONS="-opengl es2 -device linux-rasp-pi-g++ -device-option CROSS_COMPILE=$CROSSCOMPILER/bin/arm-linux-gnueabihf- -sysroot $ROOTFS -opensource -confirm-license -optimized-qmake -release -make libs -prefix $QT5PIPREFIX -no-pch"
if [ ! -f /etc/redhat-release ]
then
CONFIGURE_OPTIONS="$CONFIGURE_OPTIONS -reduce-exports -reduce-relocations"
fi
cd $OPT_DIRECTORY/$QT5_SOURCE_DIRECTORY/qtbase
if [ "$CONFCLEAN" == 1 ]; then
echo "Cleaning first"
rm -f $OPT_DIRECTORY/$QT5_SOURCE_DIRECTORY/qtbase/.CONFIGURED
cd $OPT_DIRECTORY/$QT5_SOURCE_DIRECTORY/qtbase
make confclean
fi
if [ ! -e $OPT_DIRECTORY/$QT5_SOURCE_DIRECTORY/qtbase/.CONFIGURED ]; then
./configure $CONFIGURE_OPTIONS && touch $OPT_DIRECTORY/$QT5_SOURCE_DIRECTORY/qtbase/.CONFIGURED || error 9
fi
echo "Making QT Base"
make -j $CORES || error 10
}
function installqtbase {
echo "Installing QT Base"
cd $OPT_DIRECTORY/$QT5_SOURCE_DIRECTORY/qtbase
if [ "$(id -u)" != "0" ]; then
sudo make install
sudo cp -r $QT5PIPREFIX/mkspecs $QT5ROOTFSPREFIX/
else
make install
cp -r $QT5PIPREFIX/mkspecs $QT5ROOTFSPREFIX/
fi
echo "QT Base Installed"
}
function makemodules {
echo "Making QT Modules $QT_COMPILE_LIST"
for i in $QT_COMPILE_LIST
do
if [ ! -e "$OPT_DIRECTORY/$QT5_SOURCE_DIRECTORY/$i/.COMPILED" ]; then
if [ "$(id -u)" != "0" ]; then
cd $OPT_DIRECTORY/$QT5_SOURCE_DIRECTORY/$i && echo "Building $i" && sleep 3 && $QT5PIPREFIX/bin/qmake . && make -j $CORES && sudo make install && touch .COMPILED
else
cd $OPT_DIRECTORY/$QT5_SOURCE_DIRECTORY/$i && echo "Building $i" && sleep 3 && $QT5PIPREFIX/bin/qmake . && make -j $CORES && make install && touch .COMPILED
fi
cd $OPT_DIRECTORY/$QT5_SOURCE_DIRECTORY/
fi
done
cd $OPT_DIRECTORY/$QT5_SOURCE_DIRECTORY/qtdeclarative/examples/demos/samegame
$QT5PIPREFIX/bin/qmake .
make -j $CORES
sudo make install
for i in $QT_COMPILE_LIST
do
if [ -e "$OPT_DIRECTORY/$QT5_SOURCE_DIRECTORY/$i/.COMPILED" ]
then
echo "Compiled $i"
else
echo "Failed $i"
fi
done
}
function copyToImage {
if [[ "$OSTYPE" =~ darwin.* ]]
then
cd $ROOTFS
tar -czf $OPT_DIRECTORY/qt5pi.tgz usr/local/qt5pi
echo "Adding qt5pi.tgz to the Raspbian image at /"
$DEBUGFS -w -R "rm qt5pi.tgz" $DISK
$DEBUGFS -w -R "write $OPT_DIRECTORY/qt5pi.tgz qt5pi.tgz" $DISK
echo "Extract qt5pi.tgz on your pi at /"
echo "Unmounting image"
hdiutil detach $MOUNT
fi
}
#Start of script
if [ ! "$QT5_PACKAGE" == 1 ]; then
echo "Would you like to build from GIT(G) or Package(P)?"
read -e option
while [[ ! $option =~ [GgPp] ]]; do
echo "Please type G for Git or P for package"
read option
done
if [[ $option =~ [Pp] ]]; then
QT5_PACKAGE=1
fi
fi
if [ "$QT5_PACKAGE" == 1 ]; then
QT_COMPILE_LIST="qtimageformats qtsvg qtjsbackend qtscript qtxmlpatterns qtdeclarative qtgraphicaleffects qtquick1 qtmultimedia qtwebkit"
QT5_SOURCE_DIRECTORY="qt-everywhere-opensource-src-$QT5_PACKAGE_VER"
echo "Building from Package"
else
QT_COMPILE_LIST="qtimageformats qtsvg qtjsbackend qtscript qtxmlpatterns qtdeclarative qtsensors qt3d qtgraphicaleffects qtlocation qtquick1 qtsystems qtmultimedia"
QT5_SOURCE_DIRECTORY="qt5"
echo "Building from Git"
fi
mkdir -p $OPT_DIRECTORY || error 1
cd $OPT_DIRECTORY || error 1
downloadAndMountPi
dlcc
dlqt
prepcctools
configureandmakeqtbase
installqtbase
makemodules
copyToImage