# Preface

This document contains instructions on how to build and package ROSA ImageWriter (further referred to as RIW) as portable application.

Generally, the process looks like this:

1. Compile Qt from sources with static linking.
2. Build RIW using this Qt version, thus having a single executable binary.
3. Build the RIW translation files from TS sources.
4. Put these translations into the `lang` subdirectory near the RIW executable.
5. Also copy the same languages from Qt translations into `lang`.
6. Add the `LICENSE.html` and `README.html` files.
7. Package the result into appropriate distributable archive.

However, some actions may differ depending on the operating system you are working with. Refer to one of the following sections for details.

## Windows

This scenario was tested under Windows 7 SP1 Pro x64, using SDK from Microsoft Visual Studio 2015 Community Edition Update 3.

### Configuring and building Qt

Here we suppose that the following paths are used:

Qt sources: | C:\Programs\Qt-static\5.6.1-src\
Qt build directory: | C:\Programs\Qt-static\5.6.1-build\
Qt installation directory: | C:\Programs\Qt-static\5.6.1\

From further on we will omit the prefix `C:\Programs\Qt-static\`.

1. Open the 32-bit SDK command prompt, change directory to `5.6.1-build\`.
2. Configure the Qt. For decreasing RIW executable size and speed up Qt build process, we recommend to turn off all unused features and modules. The following command can be used:
   ..\5.6.1-src\configure -prefix C:\Programs\Qt-static\5.6.1 -opensource -confirm-license -release -static -static-runtime -target xp -qmake -gui -widgets -accessibility -no-angle -no-audio-backend -no-dbus -no-direct2d -no-directwrite -no-evdev -no-eventfd -no-fontconfig -no-freetype -no-gif -no-harfbuzz -no-iconv -no-icu -no-inotify -largefile -no-libjpeg -qt-libpng -mp -no-mtdev -no-native-gestures -no-nis -no-opengl -no-openssl -no-openvg -qt-pcre -no-plugin-manifests -no-qml-debug -qreal double -rtti -no-sql-db2 -no-sql-ibase -no-sql-mysql -no-sql-oci -no-sql-odbc -no-sql-psql -no-sql-sqlite -no-sql-sqlite2 -no-sql-tds -no-ssl -strip -no-style-fusion -qt-style-windows -qt-style-windowsxp -qt-style-windowsvista -no-system-proxies -no-use-gold-linker -warnings-are-errors -no-wmf-backend -qt-zlib -nomake examples -nomake tests -skip qtactiveqt -skip qtandroidextras -skip qtconnectivity -skip qtdeclarative -skip qtdoc -skip qtlocation -skip qtmacextras -skip qtmultimedia -skip qtquickcontrols -skip qtquickcontrols2 -skip qtscript -skip qtsensors -skip qtserialbus -skip qtserialport -skip qtwayland -skip qtwebchannel -skip qtwebengine -skip qtwebsockets -skip qtwebview -skip qtx11extras -skip qtxmlpatterns
3. When configuring completes, check carefully the status information. Particularly, make sure that correct toolchain is used, otherwise you'll have to specify the toolchain manually (using the `QMAKESPEC` variable) and reconfigure Qt.
4. Now run `nmake` and then `nmake install`.
5. Add Qt binaries path to the environment variable PATH:
   set PATH=C:\Programs\Qt-static\5.6.1\bin;%PATH%

### Building RIW

Now we can build RIW. It is better to do it in a separate subdirectory to avoid polluting the sources with temporary files.

1. Create a new directory and go there. Here we suppose that it is subdirectory `build\` in RIW sources.
2. Run the commands:
   qmake ..\RosaImageWriter.pro
   nmake Release
   lrelease ..\RosaImageWriter.pro
3. If you have digital certificate you can sign the executable file `release\RosaImageWriter.exe` to allow validation and improve Windows UAC prompt displayed when RIW is started.
4. All files are now ready, we can package them:
   mkdir pkg\RosaImageWriter\lang
   copy release\RosaImageWriter.exe pkg\RosaImageWriter\
   copy ..\doc\README.html pkg\RosaImageWriter\
   copy ..\doc\LICENSE.html pkg\RosaImageWriter\
   copy ..\lang\*.qm pkg\RosaImageWriter\lang\
   copy C:\Programs\Qt-static\5.6.1\translations\qtbase_ru.qm pkg\RosaImageWriter\lang\
   copy C:\Programs\Qt-static\5.6.1\translations\qtbase_de.qm pkg\RosaImageWriter\lang\
   copy C:\Programs\Qt-static\5.6.1\translations\qtbase_fr.qm pkg\RosaImageWriter\lang\
   cd pkg
   7z a RosaImageWriter-win.zip RosaImageWriter
   Please, keep in mind that if new RIW translations appear, the commands given above should be amended to also include Qt translations on the same languages. If translation is split into separate files you need only the `qtbase_xx.qm` file, otherwise get the main `qt_xx.qm` file.
   The last command uses 7-Zip archiver to create ZIP archive; you can use any other tool for that purpose. ZIP format is recommended for distributing the application: though it is not the best one in terms of compression, it's supported by all decompressors and even by Windows itself, so users will have no trouble unpacking it.
5. The file `RosaImageWriter-win.zip` is ready for publishing.

## Linux

This scenario was tested under ROSA Desktop Fresh R5 i586 and x86_64, using gcc 4.9.2.

### Configuring and building Qt

Here we suppose that the following paths are used:

Qt sources: | ~/Qt-static/5.6.1-src/
Qt build directory: | ~/Qt-static/5.6.1-build/
Qt installation directory: | ~/Qt-static/5.6.1/

From further on we will omit the prefix `~/Qt-static/`.

1. First, you might want to fix the default build flags. There are two issues in sight:
   - Some debug information remains in the executables even with debug options turned off and executable stripped.
   - `libstdc++` library uses symbol versions massively. So, the executable we get may not run on a different operating system because of the version mismatch. If you want to avoid this you can use static linking for `libstdc++`. Of course, you'll need a static version of it (e.g. in ROSA the package `libstdc++-static-devel` or `lib64stdc++-static-devel` should be installed).
   To fix these two issues, open the file `5.6.1-src/qtbase/mkspecs/linux-g++/qmake.conf` and add the following directives to the end of the file:
   QMAKE_CFLAGS += -fno-asynchronous-unwind-tables
   QMAKE_CXXFLAGS += -fno-asynchronous-unwind-tables
   QMAKE_LFLAGS += -static-libstdc++
2. Now, open terminal, change directory to `5.6.1-build/`.
3. Configure the Qt. For decreasing RIW executable size and speed up Qt build process, we recommend to turn off all unused features and modules. The following command can be used:
   ../5.6.1-src/configure -prefix ~/Qt-static/5.6.1 -opensource -confirm-license -release -static -optimized-qmake -gui -widgets -accessibility -no-alsa -no-cups -no-dbus -no-directfb -no-eglfs -no-evdev -fontconfig -qt-freetype -no-gif -no-glib -no-gtkstyle -qt-harfbuzz -no-iconv -no-icu -no-journald -no-kms -largefile -no-libjpeg -qt-libpng -no-linuxfb -no-mtdev -no-nis -no-opengl -no-openssl -no-pch -qt-pcre -no-pkg-config -no-pulseaudio -no-qml-debug -qreal double -reduce-relocations -no-rpath -no-sql-db2 -no-sql-ibase -no-sql-mysql -no-sql-oci -no-sql-odbc -no-sql-psql -no-sql-sqlite -no-sql-sqlite2 -no-sql-tds -strip -no-system-proxies -use-gold-linker -no-warnings-are-errors -xcb -qt-xcb -no-xcb-xlib -xinput2 -qt-xkbcommon -qt-zlib -nomake examples -nomake tests -skip qtactiveqt -skip qtandroidextras -skip qtconnectivity -skip qtdeclarative -skip qtdoc -skip qtlocation -skip qtmacextras -skip qtmultimedia -skip qtquickcontrols -skip qtquickcontrols2 -skip qtscript -skip qtsensors -skip qtserialbus -skip qtserialport -skip qtwayland -skip qtwebchannel -skip qtwebengine -skip qtwebsockets -skip qtwebview -skip qtwinextras -skip qtxmlpatterns -no-libudev
4. When configuring completes, check carefully the status information. Particularly, make sure that correct toolchain is used, otherwise you'll have to specify the toolchain manually (using the `QMAKESPEC` variable) and reconfigure Qt.
5. Now run `make` and then `make install`.
6. Add Qt binaries path to the environment variable PATH:
   export PATH=~/Qt-static/5.6.1/bin:$PATH

### Building RIW

Now we can build RIW. It is better to do it in a separate subdirectory to avoid polluting the sources with temporary files.

1. Create a new directory and go there. Here we suppose that it is subdirectory `build/` in RIW sources.
2. Run the commands:
   qmake ../RosaImageWriter.pro
   make
   lrelease ../RosaImageWriter.pro
3. All files are now ready, we can package them:
   mkdir -p pkg/RosaImageWriter/lang
   cp RosaImageWriter ../doc/README.html ../doc/LICENSE.html pkg/RosaImageWriter/
   cp ../lang/*.qm ~/Qt-static/5.6.1/translations/{qtbase_ru,qtbase_de,qtbase_fr}.qm pkg/RosaImageWriter/lang/
   cd pkg
   tar cJf RosaImageWriter-lin.tar.xz RosaImageWriter
   Please, keep in mind that if new RIW translations appear, the commands given above should be amended to also include Qt translations on the same languages. If translation is split into separate files you need only the `qtbase_xx.qm` file, otherwise get the main `qt_xx.qm` file.
4. The file `RosaImageWriter-lin.tar.xz` is ready for publishing.

## Mac OS X

This scenario was tested under OS X 10.8.5 Mountain Lion with Xcode 5.1.1, and OS X 10.10.4 Yosemite with Xcode 6.4.

### Configuring and building Qt

Here we suppose that the following paths are used:

Qt sources: | ~/Qt-static/5.6.1-src/
Qt build directory: | ~/Qt-static/5.6.1-build/
Qt installation directory: | ~/Qt-static/5.6.1/

From further on we will omit the prefix `~/Qt-static/`.

1. If you installed Xcode first time you need to start it and accept the license agreement. Otherwise command-line build tools will not work.
2. Open terminal, change directory to `5.6.1-build/`.
3. Configure the Qt. For decreasing RIW executable size and speed up Qt build process, we recommend to turn off all unused features and modules. The following command can be used:
   ../5.6.1-src/configure -prefix ~/Qt-static/5.6.1 -opensource -confirm-license -release -static -optimized-qmake -gui -widgets -accessibility -no-alsa -no-cups -no-dbus -no-directfb -no-eglfs -no-evdev -no-fontconfig -no-freetype -no-gif -no-glib -no-gtkstyle -qt-harfbuzz -no-iconv -no-icu -no-journald -no-kms -largefile -no-libjpeg -qt-libpng -no-linuxfb -no-mtdev -no-nis -no-opengl -no-openssl -no-pch -qt-pcre -no-pkg-config -no-pulseaudio -no-qml-debug -qreal double -no-reduce-relocations -no-rpath -no-sql-db2 -no-sql-ibase -no-sql-mysql -no-sql-oci -no-sql-odbc -no-sql-psql -no-sql-sqlite -no-sql-sqlite2 -no-sql-tds -strip -no-system-proxies -no-use-gold-linker -no-warnings-are-errors -no-xcb -no-xcb-xlib -no-xinput2 -qt-xkbcommon -qt-zlib -nomake examples -nomake tests -skip qtactiveqt -skip qtandroidextras -skip qtconnectivity -skip qtdeclarative -skip qtdoc -skip qtlocation -skip qtmultimedia -skip qtquickcontrols -skip qtquickcontrols2 -skip qtscript -skip qtsensors -skip qtserialbus -skip qtserialport -skip qtwayland -skip qtwebchannel -skip qtwebengine -skip qtwebsockets -skip qtwebview -skip qtwinextras -skip qtx11extras -skip qtxmlpatterns -no-libudev -no-framework
4. When configuring completes, check carefully the status information.
5. Now run `make` and then `make install`.
6. Add Qt binaries path to the environment variable PATH:
   export PATH=~/Qt-static/5.6.1/bin:$PATH

### Building RIW

Now we can build RIW. It is better to do it in a separate subdirectory to avoid polluting the sources with temporary files.

1. Create a new directory and go there. Here we suppose that it is subdirectory `build/` in RIW sources.
2. Run the commands:
   qmake ../RosaImageWriter.pro
   make
   lrelease ../RosaImageWriter.pro
3. The application bundle is now ready, we can supply it with additional files and package it:
   mkdir pkg
   mv RosaImageWriter.app pkg/
   mkdir pkg/RosaImageWriter.app/Contents/MacOS/lang
   cp ../doc/README.html ../doc/LICENSE.html pkg/
   cp ../lang/*.qm ~/Qt-static/5.6.1/translations/{qtbase_ru,qtbase_de,qtbase_fr}.qm pkg/RosaImageWriter.app/Contents/MacOS/lang/
   hdiutil create -format UDBZ -volname 'ROSA ImageWriter' -scrub -srcfolder pkg/ temp.dmg
   hdiutil convert temp.dmg -format UDBZ -o RosaImageWriter-osx.dmg
   rm -f temp.dmg
   (Converting from UDBZ to UDBZ is not required but, though it looks strange, it might decrease the DMG image size by 4%.)
   Please, keep in mind that if new RIW translations appear, the commands given above should be amended to also include Qt translations on the same languages. If translation is split into separate files you need only the `qtbase_xx.qm` file, otherwise get the main `qt_xx.qm` file.
4. The file `RosaImageWriter-osx.dmg` is ready for publishing.

Copyright © 2016 NTC IT ROSA LLC