Native Build of Qt 5.4.1 on a Raspberry Pi

From Qt Wiki
Jump to: navigation, search
This article may require cleanup to meet the Qt Wiki's quality standards. Reason: Merge with Native_Build_of_Qt5_on_a_Raspberry_Pi
Please improve this article if you can. Remove the {{cleanup}} tag and add this page to Updated pages list after it's clean.

This is an update to the wiki page Native_Build_of_Qt5_on_a_Raspberry_Pi using a Raspberry Pi 2 and a Qt source tarball on Raspbian Wheezy.

In the following, a working setup for using Qt on the linux console with EGLFS and a touchscreen is established.

Compilation took ~8 hours without overclocking the Pi 2 which can be attributed to

  • compiling the source on an external USB HDD (in contrast to the very slow SD card), and
  • making use of the Raspberry Pi 2's multicore CPU.

In addition to the configuration used in Native_Build_of_Qt5_on_a_Raspberry_Pi, support for

  • tslib (touchscreen interface)
  • pkg-config

have been added.

Preparation

For the following steps we asume that

  • the build is done for user pi locally
  • the Qt tarball has been downloaded to ~/qt-everywhere-opensource-src-5.4.1.tar.gz
  • an external USB HDD is available and can be mounted to /media/usb
  • the Qt binaries should be installed to /usr/local/qt5

Unpacking source to an external USB HDD

Using this method the tree will still be located logically in the user's home directory so that it can be moved there after compilation finished and the external USB HDD removed.

 sudo mkdir -p /media/usb
 # put proper device here instead of /dev/sdXX!
 sudo mount /dev/sdXX /media/usb
 sudo mkdir /media/usb/build
 sudo chown pi /media/usb/build
 cd /media/usb/build
 tar zxvf ~/qt-everywhere-opensource-src-5.4.1.tar.gz
 
 # now bind it to ~/opt/qt-everywhere-opensource-src-5.4.1
 mkdir -p ~/opt/qt-everywhere-opensource-src-5.4.1
 sudo mount --bind /media/usb/build/qt-everywhere-opensource-src-5.4.1 /home/pi/opt/qt-everywhere-opensource-src-5.4.1
 cd ~/opt/qt-everywhere-opensource-src-5.4.1
 ls

Increasing available RAM for concurrent compilation

Although the Raspberry Pi 2 comes with 1 GB of RAM, this still isn't enough for compiling QtWebkit with more than one concurrent compilation process. By default, raspbian maintains a 100 MB swapfile. Assuming that the external USB HDD has sufficient size, a larger swapfile will be put there. Alternatively, a swap partition could have been used.

 # disable and remove swap file
 sudo dphys-swapfile swapoff
 sudo dphys-swapfile uninstall
 
 # edit /etc/dphys-swapfile to read
 #  #CONF_SWAPSIZE=100
 #  CONF_SWAPFILE=/media/usb/swap
 
 # create and enable new swap file
 sudo dphys-swapfile setup
 sudo dphys-swapfile swapon
 
# if you get:
# swapon: /media/usb/swap: read swap header failed: Invalid argument
# reboot and rerun:
#  sudo mount /dev/sdXX /media/usb
#  sudo mount --bind /media/usb/build/qt-everywhere-opensource-src-5.4.1 /home/pi/opt/qt-everywhere-opensource-src-5.4.1
#  cd ~/opt/qt-everywhere-opensource-src-5.4.1

# check that a ~2GB swap file is active now
 cat /proc/swaps

Configure and compile Qt source code

Installing dependencies

 sudo apt-get update
 sudo apt-get dist-upgrade
 sudo apt-get install libfontconfig1-dev libdbus-1-dev libfreetype6-dev libudev-dev libicu-dev \
  libsqlite3-dev libxslt1-dev libssl-dev libasound2-dev libavcodec-dev libavformat-dev libswscale-dev \
  libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev gstreamer-tools gstreamer0.10-plugins-good \
  gstreamer0.10-plugins-bad libraspberrypi-dev libpulse-dev libx11-dev libglib2.0-dev libcups2-dev \
  freetds-dev libsqlite0-dev libpq-dev libiodbc2-dev libmysqlclient-dev firebird-dev libpng12-dev \
  libjpeg62-dev libgst-dev libxext-dev libxcb1 libxcb1-dev libx11-xcb1 libx11-xcb-dev libxcb-keysyms1 \
  libxcb-keysyms1-dev libxcb-image0 libxcb-image0-dev libxcb-shm0 libxcb-shm0-dev libxcb-icccm4 \
  libxcb-icccm4-dev libxcb-sync0 libxcb-sync0-dev libxcb-render-util0 libxcb-render-util0-dev \
  libxcb-xfixes0-dev libxrender-dev libxcb-shape0-dev libxcb-randr0-dev libxcb-glx0-dev libxi-dev \
  libdrm-dev flex ruby gperf bison libts-dev
 sudo apt-get clean

In Raspbian Jessie, the package libjpeg62-dev has been removed. libjpeg62-turbo-dev can be used alternatively.
As well libxcb-sync0 should be changed to libxcb-sync1 and libxcb-sync0-dev to libxcb-sync-dev
In Raspbian Jessie for Qt 5.6 you have to to add libxcb-xinerama0 libxcb-xinerama0-dev

Configuring the Qt source

In contrast to the original wiki article, no manual adjustment of files seems to be necessary in order to properly build Qt on the Raspberry Pi. Not all functionality and modules were tested though, so YMMV.

./configure -v -opengl es2 -tslib -force-pkg-config -device linux-rasp-pi-g++ -device-option CROSS_COMPILE=/usr/bin/ \
 -opensource -confirm-license -optimized-qmake -reduce-exports -release -qt-pcre -make libs \
 -prefix /usr/local/qt5 2>&1 | tee config.out

To compile Qt 5.7 in Rpi3, you need to add the flag -no-use-gold-linker to configure. Apparently gnu gold linker has issues with ARMv8.

./configure -v -opengl es2 -tslib -force-pkg-config -device linux-rasp-pi-g++ -device-option CROSS_COMPILE=/usr/bin/ \
 -opensource -confirm-license -optimized-qmake -reduce-exports -release -qt-pcre -make libs -no-use-gold-linker \
 -prefix /usr/local/qt5 2>&1 | tee config.out

Make sure that configuration succeeded. Look closely at the output from all errors as some features might be quietly disabled.

Compilation

Although the Raspberry Pi 2 provides four CPU cores, using all of them proved to be slightly unstable despite of the measures taken at the top of this page. Using three of them worked fine and led to a "satisfactory" compilation time (~12 hrs).

 time make -j3 2>&1 | tee make.out

Installation and Cleanup

Installation

 sudo make install

For using the installed version of Qt, it is convenient to have a setup file, e.g. ~/setup_qt.sh, which can be source'd if necessary. It should contain at least the following lines for setting up path variables:

 export LD_LIBRARY_PATH=/usr/local/qt5/lib
 export PATH=/usr/local/qt5/bin:$PATH

Additionally, it can be convenient to set additional variables depending on the periphery devices connected to the Pi, i.e. a touchscreen:

 # hides mouse cursor
 export QT_QPA_EGLFS_HIDECURSOR=1
 # enables tslib plugin for touch screen
 export QT_QPA_GENERIC_PLUGINS=Tslib
 # disables evdev mouse input (to avoid getting duplicated input from tslib AND evdev)
 export QT_QPA_EGLFS_DISABLE_INPUT=1
 # set physical display dimensions for proper font sizes etc.
 # Qt should print a warning if this is necessary
 export QT_QPA_EGLFS_PHYSICAL_WIDTH=154
 export QT_QPA_EGLFS_PHYSICAL_HEIGHT=86

Cleaning up

Now some of the steps from #Preparation could be reversed:

 # unbind source directory and copy source tree to SD card
 sudo unmount /home/pi/opt/qt-everywhere-opensource-src-5.4.1
 rsync -av /media/usb/build/qt-everywhere-opensource-src-5.4.1/ /home/pi/opt/qt-everywhere-opensource-src-5.4.1
 # sudo rm -rf /media/usb/build
 
 # revert to small swap file on SD card
 sudo dphys-swapfile swapoff
 sudo dphys-swapfile uninstall
 # if the last step fails, continue with the following steps
 # everything should be fine after a reboot
 # the swap file has to be deleted manually after that though
 
 # edit /etc/dphys-swapfile to read
 #  CONF_SWAPSIZE=100
 
 # create and enable new swap file
 sudo dphys-swapfile setup
 sudo dphys-swapfile swapon

Additional Remarks

Up-to-date tslib support

At the time of writing, the Raspbian package for tslib did not support all popular touchscreen controllers used with the Raspberry Pi, in particular the D-WAV Scientific Co., Ltd eGalax TouchScreen (from lsusb). As the library is plugin based, it could be updated without recompiling Qt.

 git clone git://github.com/kergoth/tslib.git
 cd tslib
 ./autogen.sh
 ./configure
 make -j4
 sudo make install

Unfortunately, the libts-0.0-0 package from Raspbian Wheezy cannot be removed easily without breaking dependencies, so some 'hacking' has to be done:

 mkdir tslib_backup
 sudo mv /usr/lib/arm-linux-gnueabihf/libts* tslib_backup
 sudo mv /usr/lib/arm-linux-gnueabihf/ts tslib_backup
 sudo mv /usr/local/lib/libts* /usr/local/lib/ts /usr/lib/arm-linux-gnueabihf
 (cd /usr/lib/arm-linux-gnueabihf && sudo ln -s libts-1.0.so.0 libts-0.0.so.0)

In Raspbian Jessie, the libts-0.0.0 does not seem to be required by any other package, so the previous hack can be ignored and the files installed directly to /usr and /etc:

...
./configure --prefix /usr --sysconfdir /etc
...

Now uncomment module_raw input in /etc/ts.conf and set a few environment variables:

 export TSLIB_FBDEVICE=/dev/fb0
 export TSLIB_CONSOLEDEVICE=none
 export TSLIB_TSDEVICE=/dev/input/by-id/`ls /dev/input/by-id/ | grep "eGalax"`
 export TSLIB_CONFFILE=/etc/ts.conf
 export TSLIB_CALIBFILE=/etc/pointercal
 export TSLIB_PLUGINDIR=/usr/lib/arm-linux-gnueabihf/ts

The touchscreen can be calibrated using ts_calibrate and tested with ts_test. It might be useful to add those environment variables to ~/setup_qt.sh as well.

Full native build of Qt 5.5.1 (+docs) and Qt-creator 3.6.0 on a Raspberry Pi 2

After a few weeks of experimenting with configuration settings, dependencies and bugs, I came to this installation protocol. Save it as a textfile on a memorystick, so that you can read it while installing on your Raspberry Pi. The full install can be done in 28 hours.

You start with Raspbian Jessie.

The resulting Qt-creator must be run using an external swapfile: if it doesn't get enough memory, it will crash without a warning.

#!/not/runnable

### various resources
http://wiki.qt.io/Native_Build_of_Qt5_on_a_Raspberry_Pi
http://wiki.qt.io/Native_Build_of_Qt_5.4.1_on_a_Raspberry_Pi
https://www.raspberrypi.org/forums/viewtopic.php?f=66&t=18200
http://bernaerts.dyndns.org/linux/323-lubuntu-trusty-empty-trash-menu
http://wiki.qt.io/RaspberryPi2EGLFS
https://wiki.qt.io/Building_Qt_Documentation

### FULL NATIVE BUILD OF QT 5.5.1 (WITH DOCS) AND QTCREATOR 3.6.0
### ON A RASPBERRY PI 2
###
### For this procedure you will need:
### - a Raspberry Pi 2 (ethernet connected)
### - a 8GB SDHC Card on which you start burning a fresh copy of Raspbian Jessie
### - a 32GB SDHC Card that will hold your final result
### - a vfat formatted usb memory stick, on which you put this file.
###       put the stick in your pi so that you will be able to copy lines
###       from it into the system terminal. Also, you can correct errors in
###       the procedure for your future reference.
### - an ext4 formatted external usb harddisk drive, that will be the workhorse here:
###       it will host the swapfile and the sources and objects of the various
###       compilations - for speed.
### When you start up raspbian with these disks connected, the OS will automount
###       them, and if you choose to have the system show the mounted disks
###       on the desktop (rightclick on desktop, choose settings, third tab),
###       the system will show you the UUID by which these disks are known to
###       the system. Make a note of them in this file.
###
### THIS IS AN INSTALLATION PROTOCOL, NOT A PROGRAM. IT SHOULD NOT BE RUN AS IS.
### COPY THE COMMANDS INTO A TERMINAL WINDOW. 
### SOME COMMANDS MAY BE ENTERED AS A GROUP THROUGH A MULTI-LINE COPY-AND-PASTE, 
### BUT BEWARE THAT SOME COMMANDS WILL BREAK THIS. (E.G. APT-GET INSTALL WILL)
### ALSO, BE SURE TO READ THE TEXT IN THE COMMENTS. IT CONTAINS INSTRUCTIONS.

######################### START WITH JESSIE ON A 8GB SDHC CARD ##################

### the start: 
###    in raspiconfig expand the filesystem, set your password, 
###    enable all interfaces, give 128MB to video, set timezone and keyboard.
###    I succeeded with locale en_US, but you will have to find out for 
###    yourself if the compilation also works with other locales.

raspiconfig (from the Menu) expand filesystem + reboot
sudo apt-get update
sudo apt-get dist-upgrade
### while you're in the terminal: adjust font and fontsize to your taste

### create directories to mount our external hd and memorystick on.

sudo mkdir /media/usbhd
sudo mkdir /media/usbstick

### unmount the automounted disks, and prepare fstab: 
###    add lines for your external harddisk and
###    memorystick, You should test these settings before
###    you start and keep a copy of these lines in a textfile
###    (this textfile) on the memorystick. 

sudo umount /dev/sda1
sudo umount /dev/sdb1
sudo leafpad /etc/fstab
---------------------------------------------
UUID=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx /media/usbhd ext4 defaults 0 0
UUID=xxxx-xxxx /media/usbstick vfat defaults,uid=pi,gid=pi 0 0
---------------------------------------------

### while you're still in leafpad: adjust font and fontsize to your taste.
### now mount the usb disks:

sudo mount /media/usbstick
sudo mount /media/usbhd

### prepare for swapfile on harddisk - keep these files on the memory stick

cp /etc/dphys-swapfile /media/usbstick/dphys-swapfile.sdhcswap
cp /etc/dphys-swapfile /media/usbstick/dphys-swapfile.usbhdswap

leafpad /media/usbstick/dphys-swapfile.sdhcswap
-------- edit so that these lines are (un)commented like this:
CONF_SWAPFILE=/var/swap
#CONF_SWAPFILE=/media/usbhd/swap
CONF_SWAPSIZE=100
#CONF_SWAPSIZE=2048
#CONF_SWAPFACTOR=2
-----------------------------------------------------------

leafpad /media/usbstick/dphys-swapfile.usbhdswap
--------edit so that these lines are (un)commented like this:
#CONF_SWAPFILE=/var/swap
CONF_SWAPFILE=/media/usbhd/swap
#CONF_SWAPSIZE=100
CONF_SWAPSIZE=2048
#CONF_SWAPFACTOR=2
-----------------------------------------------------------

### install some programs that you will want to have anyway (choose your own)

sudo apt-get install synaptic gparted arduino \
gimp gimp-help-common gimp-help-en gimp-data gimp-data-extras

### disable screen blanking: install xscreensaver and then go to
###    Menu/Preferences/Screensaver. Allow the application to start,
###    and then set it to disabled.

sudo apt-get install xscreensaver 

### add script to empty trashcan by rightclick
### when you install this, you can use this command after your next boot

sudo apt-get install trash-cli
mkdir --parents /home/pi/.local/share/file-manager/actions
wget -O /home/pi/.local/share/file-manager/actions/ask-trash-empty.desktop https://raw.githubusercontent.com/NicolasBernaerts/ubuntu-scripts/master/lubuntu/trash-empty/ask-trash-empty.desktop
sudo wget -O /usr/local/bin/ask-trash-empty https://raw.githubusercontent.com/NicolasBernaerts/ubuntu-scripts/master/lubuntu/trash-empty/ask-trash-empty
sudo chmod +x /usr/local/bin/ask-trash-empty
### adapt the following two files to meet the needs of your locale
#leafpad /home/pi/.local/share/file-manager/actions/ask-trash-empty.desktop
#sudo leafpad /usr/local/bin/ask-trash-empty

### make the clock more useful (clock settings in right upper corner of screen)
### Suggested clock display string (without the quotes): 
"wk %W  %a %d-%m-%Y  %R"

### change the color settings for the cpu usage monitor (right upper corner)
### Foreground color: #A7DC6C (green)
### Background color: #FFFFFF (white)

### change the background

cd /home/pi/Pictures
mkdir backgrounds
cd backgrounds
wget http://reichertbrothers.com/images/qt-logo.png
### now rightclick on the desktop to change the background and color settings
### Background color: #17430E (green)
### Also adjust Appearance Settings (in Menu/Preferences)
### Menu bar color: #6D4721 (brown)
### System Highlight color: #1200FF (blue)
### All other colors: #FFFFFF (white)
### Adjust font and fontsize to your taste

### some links to files that otherwise will not be found
sudo ln -s /opt/vc/include/interface/vcos/pthreads/vcos_futex_mutex.h /opt/vc/include/interface/vcos/vcos_futex_mutex.h
sudo ln -s /opt/vc/include/interface/vcos/pthreads/vcos_platform.h /opt/vc/include/interface/vcos/vcos_platform.h
sudo ln -s /opt/vc/include/interface/vcos/pthreads/vcos_platform_types.h /opt/vc/include/interface/vcos/vcos_platform_types.h
sudo ln -s /opt/vc/include/interface/vmcs_host/linux/vchost_config.h /opt/vc/include/interface/vmcs_host/vchost_config.h

### fix the egl/gles library nonsense
### http://wiki.qt.io/RaspberryPi2EGLFS

sudo mv /usr/lib/arm-linux-gnueabihf/libEGL.so.1.0.0  /usr/lib/arm-linux-gnueabihf/libEGL.so.1.0.0.backup
sudo mv /usr/lib/arm-linux-gnueabihf/libGLESv2.so.2.0.0 /usr/lib/arm-linux-gnueabihf/libGLESv2.so.2.0.0.backup
sudo ln -s /opt/vc/lib/libEGL.so /usr/lib/arm-linux-gnueabihf/libEGL.so.1.0.0
sudo ln -s /opt/vc/lib/libGLESv2.so /usr/lib/arm-linux-gnueabihf/libGLESv2.so.2.0.0

### download the packages to be installed, create some directories and links

mkdir /home/pi/opt
cd /home/pi/opt
wget http://download.qt.io/official_releases/qt/5.5/5.5.1/single/qt-everywhere-opensource-src-5.5.1.tar.gz
wget http://download.qt.io/official_releases/qtcreator/3.6/3.6.0/qt-creator-opensource-src-3.6.0.tar.gz
mkdir -p /home/pi/opt/qt-everywhere-opensource-src-5.5.1
mkdir -p /home/pi/opt/qt-creator-opensource-src-3.6.0
ln -s /home/pi/opt/qt-everywhere-opensource-src-5.5.1 /home/pi/opt/qt5
ln -s /home/pi/opt/qt-creator-opensource-src-3.6.0 /home/pi/opt/qtcreator

### prepare Qt's environment variables. Make one scriptfile, and add
###    a 'source' line to call it at the end of both .bashrc and .profile

leafpad /home/pi/setup_qt.sh
----------------------------------------------------------
export LD_LIBRARY_PATH=/usr/local/qt5/lib
export PATH=/usr/local/qt5/bin:$PATH
# hides mouse cursor
#export QT_QPA_EGLFS_HIDECURSOR=1
# enables tslib plugin for touch screen
#export QT_QPA_GENERIC_PLUGINS=Tslib
# disables evdev mouse input (to avoid getting duplicated input from tslib AND evdev)
#export QT_QPA_EGLFS_DISABLE_INPUT=1
# set physical display dimensions for proper font sizes etc.
# Qt should print a warning if this is necessary
#export QT_QPA_EGLFS_PHYSICAL_WIDTH=154
#export QT_QPA_EGLFS_PHYSICAL_HEIGHT=86
---------------------------------------------------------------
 
echo source /home/pi/setup_qt.sh >> /home/pi/.bashrc
echo source /home/pi/setup_qt.sh >> /home/pi/.profile
 
### instruct pkg_config where to find additional .pc files. Make one scriptfile, and add
###    a 'source' line to call it at the end of both .bashrc and .profile

leafpad /home/pi/setup_general.sh 
--------------------------------------------------------------------------
export PKG_CONFIG_PATH=/usr/lib/arm-linux-gnueabihf/pkgconfig
--------------------------------------------------------------------------

echo source /home/pi/setup_general.sh >> /home/pi/.bashrc
echo source /home/pi/setup_general.sh >> /home/pi/.profile

### unmount the mounted disks, and prepare fstab for the backup.
### if you fail to comment these lines out, your system will
### fail to start if these disks are not present.

sudo umount /media/usbhd
sudo umount /media/usbstick
sudo leafpad /etc/fstab
---------------------------------------------
#UUID=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx /media/usbhd ext4 defaults 0 0
#UUID=xxxx-xxxx /media/usbstick vfat defaults,uid=pi,gid=pi 0 0
---------------------------------------------

### shutdown and make a backup of the 8GB SDHC card.
### then, copy the backup file unto your 32GB SDHC card, and put it in the Pi.

sudo shutdown now

######################### BACKUP 8GB ###########################################
######################### CONTINUE ON A COPY ON A 32GB SDHC CARD ###############

### uncomment your harddisk and memorystick in fstab 
###    so that they will be found on next boot

sudo leafpad /etc/fstab
---------------------------------------------
UUID=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx /media/usbhd ext4 defaults 0 0
UUID=xxxx-xxxx /media/usbstick vfat defaults,uid=pi,gid=pi 0 0
---------------------------------------------

### expand filesystem (raspiconfig in the Menu)
### if raspiconfig doesn't make you reboot, do it now.

sudo reboot

### install dependencies

sudo apt-get install libfontconfig1-dev libdbus-1-dev libfreetype6-dev libudev-dev libicu-dev libsqlite3-dev \
libxslt1-dev libssl-dev libasound2-dev libavcodec-dev libavformat-dev libswscale-dev libgstreamer0.10-dev \
libgstreamer-plugins-base0.10-dev gstreamer-tools gstreamer0.10-plugins-good gstreamer0.10-plugins-bad \
libraspberrypi-dev libpulse-dev libx11-dev libglib2.0-dev libcups2-dev freetds-dev libsqlite0-dev libpq-dev \
libiodbc2-dev libmysqlclient-dev firebird-dev libpng12-dev libjpeg62-turbo-dev libgst-dev libxext-dev libxcb1 libxcb1-dev \
libx11-xcb1 libx11-xcb-dev libxcb-keysyms1 libxcb-keysyms1-dev libxcb-image0 libxcb-image0-dev libxcb-shm0 \
libxcb-shm0-dev libxcb-icccm4 libxcb-icccm4-dev libxcb-sync1 libxcb-sync-dev libxcb-render-util0 \
libxcb-render-util0-dev libxcb-xfixes0-dev libxrender-dev libxcb-shape0-dev libxcb-randr0-dev libxcb-glx0-dev \
libxi-dev libdrm-dev libinput-dev mtdev-tools libmtdev-dev libproxy-dev libts-dev pkg-config pulseaudio \
libxcb-xkb-dev libxkbcommon-dev libxkbcommon-x11-dev libharfbuzz-dev \
gperf bison flex cmake cmake-data libatspi-dev \
dhelp 2>&1 | tee -a /home/pi/Desktop/o00_install.txt 

### clean up
 
sudo apt-get clean

### unpack sources. this can be done simultaneously with the apt-get install above,
###    if you open a second terminal window to do it in.

mkdir /media/usbhd/build
sudo chown pi /media/usbhd/build
cd  /media/usbhd/build
tar zxvf /home/pi/opt/qt-everywhere-opensource-src-5.5.1.tar.gz
tar zxvf /home/pi/opt/qt-creator-opensource-src-3.6.0.tar.gz
ls

### setup harddisk swapfile

sudo dphys-swapfile swapoff
sudo dphys-swapfile uninstall
sudo cp /media/usbstick/dphys-swapfile.usbhdswap /etc/dphys-swapfile
sudo chmod 644 /etc/dphys-swapfile
sudo dphys-swapfile setup
sudo dphys-swapfile swapon

### mount directories: both build directories, and an include directory
###     that will otherwise not be found.
###     These mounts only last for the duration of the session: if you
###     have to reboot after this for any reason, you will have to 
###     mount these again.

sudo mount --bind /media/usbhd/build/qt-everywhere-opensource-src-5.5.1 /home/pi/opt/qt-everywhere-opensource-src-5.5.1
sudo mount --bind /media/usbhd/build/qt-creator-opensource-src-3.6.0 /home/pi/opt/qt-creator-opensource-src-3.6.0
sudo mount --bind /opt/vc/include /usr/local/include
cd /home/pi/opt/qt-everywhere-opensource-src-5.5.1
ls

### configure Qt and check output
###    this is a crucial step. You can shorten compile time by taking out '-make examples'
###    If you do not want to make the docs, you can leave out '-make tools' as well,
###    but then you will have to make some missing components further on to be able
###    to install qt-creator as well.

./configure -v -opengl es2 -device linux-rasp-pi-g++ -tslib -force-pkg-config \
-device-option CROSS_COMPILE=/usr/bin/ -opensource \
-confirm-license -optimized-qmake -reduce-exports -release -qt-pcre \
-make libs -make tools -make examples \
-system-zlib -system-libjpeg -system-libpng -system-xcb -system-xkbcommon \
-system-freetype -system-harfbuzz \
-warnings-are-errors \
-prefix /usr/local/qt5 2>&1 | tee -a /home/pi/Desktop/o01_configure.txt
leafpad /home/pi/Desktop/o01_configure.txt

### make Qt and check output
###
###   'make' compile time as measured:
###       real  923m50.661s (15 hours 23 minutes)
###       user 2331m56.200s (three cores x real time)
###       sys   117m32.790s

time make -j3 2>&1 | tee -a /home/pi/Desktop/o02_make.txt
leafpad /home/pi/Desktop/o02_make.txt &

### install Qt and check output

sudo make install -j3 2>&1 | tee -a /home/pi/Desktop/o03_make_install.txt
leafpad /home/pi/Desktop/o03_make_install.txt

### check if qmake and qhelpgenerator are being found correctly
### qhelpgenerator is needed to make the docs

which qmake
which qhelpgenerator

### test if qmake actually works (escape with ctrl-alt-backspace)

cp -r /home/pi/opt/qt5/qtbase/examples/opengl/cube /home/pi/
cd /home/pi/cube
qmake
make
./cube

### add some missing components necessary for qtcreator
### this is only necessary if you don't configure '-make tools', and you do
### want to build qt-creator, but you do not want to build the docs.
### To build the docs, you need to specify '-make tools' in the configuration.
#
# cd /home/pi/opt/qt-everywhere-opensource-src-5.5.1/qttools/src/designer/src/lib
# qmake
# time make -j3 2>&1 | tee -a /home/pi/Desktop/o04_make_lib.txt
# sudo make install -j3 2>&1 | tee -a /home/pi/Desktop/o05_make_install_lib.txt
# cd /home/pi/opt/qt-everywhere-opensource-src-5.5.1/qttools/src/designer/src/components
# qmake
# time make -j3 2>&1 | tee -a /home/pi/Desktop/o06_make_components.txt
# sudo make install -j3 2>&1 | tee -a /home/pi/Desktop/o07_make_install_components.txt

### patch botan.cpp and botan.h according to these links to work properly on ARM.
###     once you have done this, keep a copy of the patched files
###     on your memorystick for future use.

cd /home/pi/opt/qt-creator-opensource-src-3.6.0/src/libs/3rdparty/botan
cp botan.h botan.h.backup
cp botan.cpp botan.cpp.backup
leafpad botan.h &
epiphany https://codereview.qt-project.org/#/c/79728/1/src/libs/3rdparty/botan/botan.h &
leafpad botan.cpp &
epiphany https://codereview.qt-project.org/#/c/79728/1/src/libs/3rdparty/botan/botan.cpp &
cp /home/pi/opt/qt-creator-opensource-src-3.6.0/src/libs/3rdparty/botan/botan.h /media/usbstick/botan.h
cp /home/pi/opt/qt-creator-opensource-src-3.6.0/src/libs/3rdparty/botan/botan.cpp /media/usbstick/botan.cpp

### now, if you later have to perform this patch again - given the same sources -, 
###     you can simply do this instead:

mv /home/pi/opt/qt-creator-opensource-src-3.6.0/src/libs/3rdparty/botan/botan.h \
   /home/pi/opt/qt-creator-opensource-src-3.6.0/src/libs/3rdparty/botan/botan.h.backup
mv /home/pi/opt/qt-creator-opensource-src-3.6.0/src/libs/3rdparty/botan/botan.cpp \
   /home/pi/opt/qt-creator-opensource-src-3.6.0/src/libs/3rdparty/botan/botan.cpp.backup
cp /media/usbstick/botan.h \
   /home/pi/opt/qt-creator-opensource-src-3.6.0/src/libs/3rdparty/botan/botan.h
cp /media/usbstick/botan.cpp \
   /home/pi/opt/qt-creator-opensource-src-3.6.0/src/libs/3rdparty/botan/botan.cpp

### now let us install qt-creator too
###
###   'make' compile time as measured:
###     real 344m16.585s (5 hours 44 minutes)
###     user 988m 9.000s (three cores x real time)
###     sys   38m50.120s

cd /home/pi/opt/qt-creator-opensource-src-3.6.0
qmake -r 2>&1 | tee -a /home/pi/Desktop/o08_qc_qmake-r.txt
time make -j3 2>&1 | tee -a /home/pi/Desktop/o09_qc_make.txt
sudo make install -j3 2>&1 | tee -a /home/pi/Desktop/o10_qc_make_install.txt

### Create an entry for Qt-creator in the menu.
###    Choose Menu/Preferences/Main Menu Editor, and add the item Qt-creator to the
###    'Programming' menu. The command is /bin/qtcreator
###    As icon you may use the picture that you downloaded before.
###    (It's in ~/Pictures/backgrounds )

### some Makefiles are now owned by root. Have to mend this first

### first check if this is indeed the case
ls -l /home/pi/opt/qt-everywhere-opensource-src-5.5.1/qtwebkit/Source/WebKit/qt/examples/
ls -l /home/pi/opt/qt-everywhere-opensource-src-5.5.1/qtwebkit/Source/WebKit/qt/examples/platformplugin/
### if so, repair the damage
sudo chown pi /home/pi/opt/qt-everywhere-opensource-src-5.5.1/qtwebkit/Source/WebKit/qt/examples/Makefile 
sudo chgrp pi /home/pi/opt/qt-everywhere-opensource-src-5.5.1/qtwebkit/Source/WebKit/qt/examples/Makefile 
sudo chown pi /home/pi/opt/qt-everywhere-opensource-src-5.5.1/qtwebkit/Source/WebKit/qt/examples/platformplugin/Makefile 
sudo chgrp pi /home/pi/opt/qt-everywhere-opensource-src-5.5.1/qtwebkit/Source/WebKit/qt/examples/platformplugin/Makefile 

### make documentation
###    do not use the option -j3 here: these operations are too intensive on disk 
###    usage and/or memory usage.
###
###   'make qmake_all' time as measured:
###      real 88m17.720s (1 hour 28 minutes)
###      user 78m44.200s
###      sys   6m21.480s
###
###   'make docs' compile time as measured:
###      real 181m49.501s (3 hours 1 minute)
###      user 172m57.010s
###      sys    4m20.540s

cd /home/pi/opt/qt-everywhere-opensource-src-5.5.1
time make qmake_all 2>&1 | tee -a /home/pi/Desktop/o11_make_qmake_all.txt
time make docs 2>&1 | tee -a /home/pi/Desktop/o12_make_docs.txt
sudo make install_docs 2>&1 | tee -a /home/pi/Desktop/o13_make_install_docs.txt

### install the documentation for the dependencies as well (optional)

sudo apt-get install bison-doc gettext-doc krb5-doc libasound2-doc at-spi-doc \
libglib2.0-doc gstreamer0.10-doc icu-doc postgresql-doc-9.4 sqlite-doc \
sqlite3-doc libtemplate-perl-doc libxcb-doc \
libxext-doc 2>&1 | tee -a /home/pi/Desktop/o14_install_doc.txt

### revert to small swap file on SD card

sudo dphys-swapfile swapoff
sudo dphys-swapfile uninstall
sudo cp /media/usbstick/dphys-swapfile.sdhcswap /etc/dphys-swapfile
sudo chmod 644 /etc/dphys-swapfile
sudo dphys-swapfile setup
sudo dphys-swapfile swapon

### unbind source directories and copy source trees to SDHC card

cd
sudo umount /home/pi/opt/qt-everywhere-opensource-src-5.5.1
sudo umount /home/pi/opt/qt-creator-opensource-src-3.6.0
rsync -av /media/usbhd/build/qt-everywhere-opensource-src-5.5.1/ /home/pi/opt/qt-everywhere-opensource-src-5.5.1
rsync -av /media/usbhd/build/qt-creator-opensource-src-3.6.0/ /home/pi/opt/qt-creator-opensource-src-3.6.0

### move the logfiles to their proper place

mv /home/pi/Desktop/o??_qc_* /home/pi/opt/qtcreator
mv /home/pi/Desktop/o??_*    /home/pi/opt/qt5

### remove the sources from the external harddisk

sudo rm -rf /media/usbhd/build

### free the external disks from the filesystem

sudo umount /media/usbstick
sudo umount /media/usbhd
sudo eject /dev/sda
sudo eject /dev/sdb
sudo leafpad /etc/fstab
---------------------------------------------
#UUID=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx /media/usbhd ext4 defaults 0 0
#UUID=xxxx-xxxx /media/usbstick vfat defaults,uid=pi,gid=pi 0 0
---------------------------------------------

### end of installation. It's time to make a backup of your 32GB SDHC card.

sudo shutdown now

Using version 5.5.1

#Build on a USB FAT memory stick, I needed to mount with dmask and fmask set.
sudo mount -o dmask=022,fmask=022 /dev/sda1 /media/usb
sudo mount -o dmask=022,fmask=022 --bind /media/usb/build/qt-everywhere-opensource-src-5.5.1 /home/pi/opt/qt-everywhere-opensource-src-5.5.1 

#Next I had to set the configure scripts to execute bit
cd /home/pi/opt/qt-everywhere-opensource-src-5.5.1 
sudo chmod +x $( find . -name configure -print )  # something like that

#And every now and then the compilation failed with unable to find library wherein neither hard nor soft links were possible I commanded bash
pushd ~/opt/qt-everywhere-opensource-src-5.5.1/qtbase/lib
for a in *.so.5.5.1 ; do if [[ ! -a ${a%.5.5.1} ]] ; then echo cp $a ${a%.5.5.1} ; fi ; done | sudo bash
popd

#more generally
find . -name 'libQt5Whaterver*' -print
#copy all three files and duplicate the *.so.5.5.1 file as *.so into qtbase/lib