Advertisement
Guest User

Build-Environment for QT5-Apps on the Raspberry Pi

a guest
Feb 20th, 2015
637
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 3.63 KB | None | 0 0
  1. #!/bin/bash
  2. #
  3. # this script creates a build environment for
  4. # QT5-based applications for the Raspberry Pi
  5. #
  6. # the script is tested on Ubuntu 14 32 Bit
  7.  
  8. # first we need to set the LANG to a default value
  9. export LANG=C
  10.  
  11. # we need some commands
  12. testCommands()
  13. {
  14.   sudo apt-get install build-essential
  15.   echo "checking needed programs";
  16.   [ -x /usr/bin/wget ] || exit 1;
  17.   [ -x /usr/bin/git ] ||  exit 2;
  18.   [ -x /usr/bin/unzip ] || exit 3;
  19.   [ -x /sbin/fdisk ] || exit 4;
  20.   [ -x /bin/grep ] || exit 5;
  21.   [ -x /usr/bin/awk ] || exit 6;
  22.   echo "done";
  23. }
  24.  
  25. # here we fetch the current raspbian image and mount them
  26. getRootFs()
  27. {
  28.   echo "getting Raspberry Pi image";
  29.   mkdir rootfs;
  30.   wget http://downloads.raspberrypi.org/raspbian/images/raspbian-2015-02-17/2015-02-16-raspbian-wheezy.zip;
  31.   unzip 2015-02-16-raspbian-wheezy.zip;
  32.   # UNITS and START are needed to calculate the offset for the mount command
  33.   UNITS=$(/sbin/fdisk -l 2015-02-16-raspbian-wheezy.img|grep Units|awk '{print $9}');
  34.   START=$(/sbin/fdisk -l 2015-02-16-raspbian-wheezy.img|grep img2|awk '{print $2}');
  35.   OFFSET=$(($UNITS * $START))
  36.   sudo mount -t ext4 -o offset=$OFFSET $PWD/2015-02-16-raspbian-wheezy.img $PWD/rootfs
  37. }
  38.  
  39. # we need a cross-compiler and a couple of variables to use them
  40. getCompiler()
  41. {
  42.   git clone https://github.com/raspberrypi/tools.git
  43.   cat > variables.sh <<EOF
  44. PWD=$(pwd)
  45. export TOOLCHAIN=$PWD/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian
  46. export PATH=$PWD/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin:$PATH
  47. export ROOTFS=$PWD/rootfs
  48. export CC='arm-linux-gnueabihf-gcc -march=armv4t -mtune=arm920t'
  49. export CXX='arm-linux-gnueabihf-g++ -march=armv4t -mtune=arm920t'
  50. export CROSS_COMPILE=arm-linux-gnueabihf-
  51. export LDFLAGS="-L$PWD/rootfs/usr/lib -L$PWD/rootfs/usr/local/qt5pi/lib"
  52. export CFLAGS="-I$PWD/rootfs/usr/include -I$PWD/rootfs/usr/local/qt5pi/include"
  53. export CXXFLAGS="-I$PWD/rootfs/usr/include -I$PWD/rootfs/usr/local/qt5pi/include"
  54. export QTDIR=/usr/local/qt5pi
  55. EOF
  56.   PWD=$(pwd)
  57.   # fix the library paths in the raspberry image
  58.   git clone git://gitorious.org/cross-compile-tools/cross-compile-tools.git
  59.   sudo cross-compile-tools/fixQualifiedLibraryPaths $PWD/rootfs/ $PWD/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/arm-linux-gnueabihf-gcc
  60. }
  61.  
  62. # here we cross-compile QT 5.4.0. we start with qtbase. after that
  63. # we compile the additional modules
  64. getQt5()
  65. {
  66.   wget http://download.qt-project.org/official_releases/qt/5.4/5.4.0/single/qt-everywhere-opensource-src-5.4.0.tar.gz
  67.   tar xvfz qt-everywhere-opensource-src-5.4.0.tar.gz
  68.  
  69.   pushd qt-everywhere-opensource-src-5.4.0
  70.   pushd qtbase
  71.   ./configure -prefix /usr/local/qt5pi -release \
  72.     -opensource -confirm-license -device linux-rasp-pi-g++ \
  73.     -make libs -optimized-qmake -device-option \
  74.     CROSS_COMPILE=$ROOT/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/arm-linux-gnueabihf- \
  75.     -nomake tests -nomake examples -reduce-exports \
  76.     -sysroot $ROOT/rootfs -opengl es2
  77.   make && sudo make install
  78.   popd
  79.   for i in qtactiveqt qtandroidextras qtbase qtconnectivity \
  80.              qtdeclarative qtdoc qtenginio qtgraphicaleffects \
  81.              qtimageformats qtlocation qtmultimedia qtquick1 \
  82.              qtquickcontrols qtscript qtsensors qtserialport \
  83.              qtsvg qttools qttranslations qtwebchannel \
  84.              qtwebengine qtwebkit qtwebsockets qtxmlpatterns
  85.   do
  86.     pushd $i
  87.     /usr/local/qt5pi/bin/qmake && make && sudo make install
  88.     popd
  89.   done
  90.   popd
  91. }
  92.  
  93.  
  94. testCommands;
  95. mkdir Raspberry
  96. pushd Raspberry
  97. ROOT=$(pwd)
  98. getRootFs
  99. getCompiler
  100. getQt5
  101. echo "QT5 built"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement