qt5-llvm-mingw-docker/qt_build
2020-04-23 17:57:50 +02:00

867 lines
30 KiB
Bash

#!/usr/bin/env bash
# --------------------------------------
# -------- FOLDERS DEFINED HERE --------
if [ ! "${CUSTOM_DIRECTORY}" == "YES" ]; then
# Build Directory
BUILD_DIR=~/build
# Prefix Directory
PREFIX_DIR=~/dev
# Source Directory
SOURCE_DIR=~/src
# Qt Directories
QT_SHARE_DIR="${PREFIX_DIR}/share"
QT_SYSCONF_DIR="${PREFIX_DIR}/etc/xdg"
fi
# --------------------------------------
# -------- VERSION DEFINED HERE --------
if [ ! "${CUSTOM_VERSION}" == "YES" ]; then
# Third Party
LIBJPEGTURBO_VERSION=2.0.4
LIBRESSL_VERSION=3.0.2
OPENSSL_VERSION=1.1.1f
ICU_VERSION=66.1
# Qt Framework
QT_SERIES=5.12
QT_BUILD=8
fi
# --------------------------------------
# ---------- CUSTOM SSL FLAGS ----------
if [ ! "${CUSTOM_SSL}" == "YES" ]; then
# Custom OpenSSL installation method
CUSTOM_OPENSSL_INSTALL=YES
# Use OpenSSL instead of LibreSSL
USE_OPENSSL=YES
fi
# --------------------------------------
# ----------- QT BUILD FLAGS -----------
if [ ! "${CUSTOM_QT_FLAGS}" == "YES" ]; then
QT_FLAGS="-qt-libpng -qt-zlib -qt-freetype -opengl desktop -skip qtactiveqt -skip qtconnectivity -skip qtlocation -skip qtmultimedia -skip qtwebengine -skip qtwebglplugin"
fi
if [ ! "${CUSTOM_QT_NOMAKE_FLAGS}" == "YES" ]; then
QT_NOMAKE_FLAGS="-nomake tests -nomake examples"
fi
if [ ! "${CUSTOM_QT_BUILDTYPE_FLAGS}" == "YES" ]; then
QT_BUILDTYPE_FLAGS="-release"
fi
# --------------------------------------
# --------- CPU VARIABLES HERE ---------
if [ "${CPU_THREADS}" == "" ]; then
local NPROC_PATH=$(command -v nproc)
if [ ! "${NPROC_PATH}" == "" ]; then
CPU_THREADS=$(nproc --all)
else
CPU_THREADS=4
fi
fi
# --------------------------------------
# --------- CUSTOM BUILD FLAGS ---------
if [ ! "${CUSTOM_BUILD}" == "YES" ]; then
# Projects being build
BUILD_QT=YES
BUILD_JPG=YES
BUILD_SSL=YES
BUILD_ICU=NO
fi
# --------------------------------------
# ----------- CUSTOM LINKING -----------
if [ ! "${CUSTOM_LINK}" == "YES" ]; then
# Projects being linked
LINK_JPG=YES
LINK_SSL=YES
LINK_ICU=NO
fi
# --------------------------------------
# ----- DON'T EDIT BELOW THIS LINE -----
# --------------------------------------
# libjpeg-turbo Script
function libjpegturbo_init {
mkdir -p "${BUILD_DIR}/libjpeg-turbo-${LIBJPEGTURBO_VERSION}_${TARGET_PLATFORM}"
cd "${BUILD_DIR}/libjpeg-turbo-${LIBJPEGTURBO_VERSION}_${TARGET_PLATFORM}"
}
function libjpegturbo_build {
cd "${BUILD_DIR}/libjpeg-turbo-${LIBJPEGTURBO_VERSION}_${TARGET_PLATFORM}"
cmake ${CMAKE_GENERATOR_FLAGS} -DCMAKE_BUILD_TYPE=Release -DENABLE_SHARED=OFF -DCMAKE_INSTALL_PREFIX="${PREFIX_DIR}/libjpeg-turbo-${LIBJPEGTURBO_VERSION}_${TARGET_PLATFORM}" -DCMAKE_INSTALL_LIBDIR="${PREFIX_DIR}/lib/${COMPILER}/libjpeg-turbo-${LIBJPEGTURBO_VERSION}" -DCMAKE_INSTALL_INCLUDEDIR="${PREFIX_DIR}/include/libjpeg-turbo-${LIBJPEGTURBO_VERSION}" "${CMAKE_TOOLCHAIN_FLAGS}" "${SOURCE_DIR_LIBJPEGTURBO}"
${CMAKE_GENERATOR}
}
function libjpegturbo_install {
cd "${BUILD_DIR}/libjpeg-turbo-${LIBJPEGTURBO_VERSION}_${TARGET_PLATFORM}"
${CMAKE_GENERATOR_INSTALL}
}
function libjpegturbo_clean {
cd "${BUILD_DIR}/libjpeg-turbo-${LIBJPEGTURBO_VERSION}_${TARGET_PLATFORM}"
rm -rf "${BUILD_DIR}/libjpeg-turbo-${LIBJPEGTURBO_VERSION}_${TARGET_PLATFORM}"
}
function libjpegturbo_strip {
cd "${PREFIX_DIR}/libjpeg-turbo-${LIBJPEGTURBO_VERSION}_${TARGET_PLATFORM}"
rm -rf "${PREFIX_DIR}/libjpeg-turbo-${LIBJPEGTURBO_VERSION}_${TARGET_PLATFORM}"
}
function libjpegturbo_register {
QT_LIBS_FLAGS="${QT_LIBS_FLAGS} -system-libjpeg -L ${PREFIX_DIR}/lib/${COMPILER}/libjpeg-turbo-${LIBJPEGTURBO_VERSION} -I ${PREFIX_DIR}/include/libjpeg-turbo-${LIBJPEGTURBO_VERSION}"
}
function libjpegturbo_source {
local VERSION=$1
local ARCHIVE=libjpeg-turbo-${VERSION}
mkdir -p "${SOURCE_DIR}"
cd "${SOURCE_DIR}"
if [ ! -d "${ARCHIVE}" ]; then
wget -O ${ARCHIVE}.tar.gz "https://github.com/libjpeg-turbo/libjpeg-turbo/archive/${VERSION}.tar.gz"
tar xfz ${ARCHIVE}.tar.gz
fi
SOURCE_DIR_LIBJPEGTURBO="${SOURCE_DIR}/${ARCHIVE}"
}
# LibreSSL script
function libressl_init {
mkdir -p "${BUILD_DIR}/libressl-${LIBRESSL_VERSION}_${TARGET_PLATFORM}_${TARGET_TYPE}"
cd "${BUILD_DIR}/libressl-${LIBRESSL_VERSION}_${TARGET_PLATFORM}_${TARGET_TYPE}"
}
function libressl_build {
cd "${BUILD_DIR}/libressl-${LIBRESSL_VERSION}_${TARGET_PLATFORM}_${TARGET_TYPE}"
if [ "${TARGET_TYPE}" == "static" ]; then
local EXTRA_FLAGS=--disable-shared
else
local EXTRA_FLAGS=
fi
if [ "${USE_CLANG}" == "YES" ]; then
local CC=${COMPILER}-clang
local CXX=${COMPILER}-clang++
elif [ "${USE_GCC}" == "YES" ]; then
local CC=${COMPILER}-gcc
local CXX=${COMPILER}-g++
else
local CC=${COMPILER}-cc
local CXX=${COMPILER}-c++
fi
CC=${CC} CXX=${CXX} ${SOURCE_DIR_LIBRESSL}/configure --host=${COMPILER} ${EXTRA_FLAGS} --prefix "${PREFIX_DIR}/lib/${COMPILER}/libressl-${LIBRESSL_VERSION}${TARGET_SUFFIX}" --bindir="${PREFIX_DIR}/lib/${COMPILER}/libressl-${LIBRESSL_VERSION}${TARGET_SUFFIX}/bin" --libdir="${PREFIX_DIR}/lib/${COMPILER}/libressl-${LIBRESSL_VERSION}${TARGET_SUFFIX}/lib" --includedir="${PREFIX_DIR}/include/libressl-${LIBRESSL_VERSION}"
${MAKE_GENERATOR}
}
function libressl_install {
cd "${BUILD_DIR}/libressl-${LIBRESSL_VERSION}_${TARGET_PLATFORM}_${TARGET_TYPE}"
${MAKE_GENERATOR_INSTALL}
ln -sf "${PREFIX_DIR}/include/libressl-${LIBRESSL_VERSION}" "${PREFIX_DIR}/lib/${COMPILER}/libressl-${LIBRESSL_VERSION}${TARGET_SUFFIX}/include"
}
function libressl_clean {
cd "${BUILD_DIR}/libressl-${LIBRESSL_VERSION}_${TARGET_PLATFORM}_${TARGET_TYPE}"
rm -rf "${BUILD_DIR}/libressl-${LIBRESSL_VERSION}_${TARGET_PLATFORM}_${TARGET_TYPE}"
}
function libressl_strip {
cd "${PREFIX_DIR}/lib/${COMPILER}/libressl-${LIBRESSL_VERSION}${TARGET_SUFFIX}"
if [ "${TARGET_OS}" == "Windows" ]; then
rm -rf bin/*.exe etc share
else
rm -rf etc share
fi
}
function libressl_register {
export OPENSSL_LIBS="-L${PREFIX_DIR}/lib/${COMPILER}/libressl-${LIBRESSL_VERSION}${TARGET_SUFFIX} -lssl -lcrypto"
QT_LIBS_FLAGS="${QT_LIBS_FLAGS} -openssl-linked -L ${PREFIX_DIR}/lib/${COMPILER}/libressl-${LIBRESSL_VERSION}${TARGET_SUFFIX}/lib -I ${PREFIX_DIR}/include/libressl-${LIBRESSL_VERSION}"
}
function libressl_source {
local VERSION=$1
local ARCHIVE=libressl-${VERSION}
mkdir -p "${SOURCE_DIR}"
cd "${SOURCE_DIR}"
if [ ! -d "${ARCHIVE}" ]; then
wget -O ${ARCHIVE}.tar.gz "https://fastly.cdn.openbsd.org/pub/OpenBSD/LibreSSL/${ARCHIVE}.tar.gz"
tar xfz ${ARCHIVE}.tar.gz
fi
SOURCE_DIR_LIBRESSL="${SOURCE_DIR}/${ARCHIVE}"
SOURCE_DIR_SSL="${SOURCE_DIR}/${ARCHIVE}"
}
# OpenSSL script
function openssl_init {
mkdir -p "${BUILD_DIR}/openssl-${OPENSSL_VERSION}_${TARGET_PLATFORM}_${TARGET_TYPE}"
cd "${BUILD_DIR}/openssl-${OPENSSL_VERSION}_${TARGET_PLATFORM}_${TARGET_TYPE}"
}
function openssl_build {
cd "${BUILD_DIR}/openssl-${OPENSSL_VERSION}_${TARGET_PLATFORM}_${TARGET_TYPE}"
if [ "${TARGET_TYPE}" == "shared" ]; then
local EXTRA_FLAGS=shared
else
local EXTRA_FLAGS=no-shared
fi
"${SOURCE_DIR_OPENSSL}/Configure" ${SSL_PLATFORM} ${EXTRA_FLAGS} --cross-compile-prefix=${COMPILER}- --prefix="${PREFIX_DIR}/lib/${COMPILER}/openssl-${OPENSSL_VERSION}${TARGET_SUFFIX}"
${MAKE_GENERATOR}
}
function openssl_install {
cd "${BUILD_DIR}/openssl-${OPENSSL_VERSION}_${TARGET_PLATFORM}_${TARGET_TYPE}"
if [ "${CUSTOM_OPENSSL_INSTALL}" == "YES" ]; then
mkdir -p "${PREFIX_DIR}/lib/${COMPILER}/openssl-${OPENSSL_VERSION}${TARGET_SUFFIX}" \
"${PREFIX_DIR}/lib/${COMPILER}/openssl-${OPENSSL_VERSION}${TARGET_SUFFIX}/bin" \
"${PREFIX_DIR}/lib/${COMPILER}/openssl-${OPENSSL_VERSION}${TARGET_SUFFIX}/include" \
"${PREFIX_DIR}/lib/${COMPILER}/openssl-${OPENSSL_VERSION}${TARGET_SUFFIX}/include/openssl" \
"${PREFIX_DIR}/lib/${COMPILER}/openssl-${OPENSSL_VERSION}${TARGET_SUFFIX}/lib" \
"${PREFIX_DIR}/lib/${COMPILER}/openssl-${OPENSSL_VERSION}${TARGET_SUFFIX}/lib/pkgconfig"
if [ "${TARGET_TYPE}" == "shared" ]; then
cp -Rf lib*.dll "${PREFIX_DIR}/lib/${COMPILER}/openssl-${OPENSSL_VERSION}${TARGET_SUFFIX}/bin/"
cp -Rf libcrypto.dll.a libssl.dll.a "${PREFIX_DIR}/lib/${COMPILER}/openssl-${OPENSSL_VERSION}${TARGET_SUFFIX}/lib/"
fi
cp -Rf libcrypto.a libssl.a "${PREFIX_DIR}/lib/${COMPILER}/openssl-${OPENSSL_VERSION}${TARGET_SUFFIX}/lib/"
cp -Rf libcrypto.pc libssl.pc openssl.pc "${PREFIX_DIR}/lib/${COMPILER}/openssl-${OPENSSL_VERSION}${TARGET_SUFFIX}/lib/pkgconfig/"
cp -Rf include/openssl/*.h "${PREFIX_DIR}/lib/${COMPILER}/openssl-${OPENSSL_VERSION}${TARGET_SUFFIX}/include/openssl/"
cd "${SOURCE_DIR_OPENSSL}"
cp -Rf include/openssl/*.h "${PREFIX_DIR}/lib/${COMPILER}/openssl-${OPENSSL_VERSION}${TARGET_SUFFIX}/include/openssl/"
cd "${BUILD_DIR}/openssl-${OPENSSL_VERSION}_${TARGET_PLATFORM}_${TARGET_TYPE}"
else
${MAKE_GENERATOR_INSTALL}
fi
ln -sf "${PREFIX_DIR}/lib/${COMPILER}/openssl-${OPENSSL_VERSION}${TARGET_SUFFIX}/include" "${PREFIX_DIR}/include/openssl-${OPENSSL_VERSION}"
}
function openssl_clean {
cd "${BUILD_DIR}/openssl-${OPENSSL_VERSION}_${TARGET_PLATFORM}_${TARGET_TYPE}"
rm -rf "${BUILD_DIR}/openssl-${OPENSSL_VERSION}_${TARGET_PLATFORM}_${TARGET_TYPE}"
}
function openssl_strip {
cd "${PREFIX_DIR}/lib/${COMPILER}/openssl-${OPENSSL_VERSION}${TARGET_SUFFIX}"
if [ ! "${CUSTOM_OPENSSL_INSTALL}" == "YES" ]; then
if [ "${TARGET_OS}" == "Windows" ]; then
rm -rf bin/*.exe etc share
else
rm -rf etc share
fi
fi
}
function openssl_register {
if [ "${TARGET_OS}" == "Windows" ]; then
if [ "${TARGET_TYPE}" == "static" ]; then
local EXTRA_SSLLIBS="-lws2_32 -lgdi32 -lcrypt32"
else
local EXTRA_SSLLIBS=
fi
fi
export OPENSSL_LIBS="-L${PREFIX_DIR}/lib/${COMPILER}/openssl-${OPENSSL_VERSION}${TARGET_SUFFIX}/lib -lssl -lcrypto ${EXTRA_SSLLIBS}"
QT_LIBS_FLAGS="${QT_LIBS_FLAGS} -openssl-linked -L ${PREFIX_DIR}/lib/${COMPILER}/openssl-${OPENSSL_VERSION}${TARGET_SUFFIX}/lib -I ${PREFIX_DIR}/lib/${COMPILER}/openssl-${OPENSSL_VERSION}${TARGET_SUFFIX}/include"
}
function openssl_source {
local VERSION=$1
local ARCHIVE=openssl-${VERSION}
mkdir -p "${SOURCE_DIR}"
cd "${SOURCE_DIR}"
if [ ! -d "${ARCHIVE}" ]; then
wget -O ${ARCHIVE}.tar.gz "https://www.openssl.org/source/${ARCHIVE}.tar.gz"
tar xfz ${ARCHIVE}.tar.gz
fi
SOURCE_DIR_OPENSSL="${SOURCE_DIR}/${ARCHIVE}"
SOURCE_DIR_SSL="${SOURCE_DIR}/${ARCHIVE}"
}
# ICU script
function icu_init {
mkdir -p "${BUILD_DIR}/icu4c-${ICU_VERSION}_${TARGET_PLATFORM}_${TARGET_TYPE}" \
"${BUILD_DIR}/icu4c-${ICU_VERSION}_native" \
"${BUILD_DIR}/icu4c-${ICU_VERSION}_stdthreads_${TARGET_PLATFORM}"
cd "${BUILD_DIR}/icu4c-${ICU_VERSION}_${TARGET_PLATFORM}_${TARGET_TYPE}"
}
function icu_build_native {
cd "${BUILD_DIR}/icu4c-${ICU_VERSION}_native"
"${SOURCE_DIR_ICU}/configure" --disable-samples --disable-tests
${MAKE_GENERATOR}
}
function icu_build_stdthreads {
cd "${BUILD_DIR}/icu4c-${ICU_VERSION}_stdthreads_${TARGET_PLATFORM}"
cmake ${CMAKE_GENERATOR_FLAGS} -DMINGW_STDTHREADS_GENERATE_STDHEADERS=ON "${CMAKE_TOOLCHAIN_FLAGS}" "${SOURCE_DIR_ICU_MINGW_STD_THREADS}"
${CMAKE_GENERATOR}
}
function icu_build {
icu_build_native
icu_build_stdthreads
cd "${BUILD_DIR}/icu4c-${ICU_VERSION}_${TARGET_PLATFORM}_${TARGET_TYPE}"
if [ "${TARGET_TYPE}" == "static" ]; then
local EXTRA_FLAGS=--disable-shared
local DATA_PACKAGING=static
else
local EXTRA_FLAGS=
local DATA_PACKAGING=library
fi
if [ "${USE_CLANG}" == "YES" ]; then
local CC=${COMPILER}-clang
local CXX=${COMPILER}-clang++
elif [ "${USE_GCC}" == "YES" ]; then
local CC=${COMPILER}-gcc
local CXX=${COMPILER}-g++
else
local CC=${COMPILER}-cc
local CXX=${COMPILER}-c++
fi
CC=${CC} CXX=${CXX} CXXFLAGS="-I${BUILD_DIR}/icu4c-${ICU_VERSION}_stdthreads_${TARGET_PLATFORM}/cmake_stdheaders_generator/cmake_stdheaders_generator" "${SOURCE_DIR_ICU}/configure" --host=${COMPILER} ${EXTRA_FLAGS} --disable-samples --disable-tests --prefix="${PREFIX_DIR}/icu4c-${ICU_VERSION}_${TARGET_PLATFORM}_${TARGET_TYPE}" --libdir="${PREFIX_DIR}/lib/${COMPILER}/icu4c-${ICU_VERSION}${TARGET_SUFFIX}" --includedir="${PREFIX_DIR}/include/icu4c-${ICU_VERSION}" --with-cross-build="${BUILD_DIR}/icu4c-${ICU_VERSION}_native" --with-data-packaging=${DATA_PACKAGING}
${MAKE_GENERATOR}
}
function icu_install {
cd "${BUILD_DIR}/icu4c-${ICU_VERSION}_${TARGET_PLATFORM}_${TARGET_TYPE}"
${MAKE_GENERATOR_INSTALL}
}
function icu_clean_native {
cd "${BUILD_DIR}/icu4c-${ICU_VERSION}_native"
rm -rf "${BUILD_DIR}/icu4c-${ICU_VERSION}_native"
}
function icu_clean_stdthreads {
cd "${BUILD_DIR}/icu4c-${ICU_VERSION}_stdthreads_${TARGET_PLATFORM}"
rm -rf "${BUILD_DIR}/icu4c-${ICU_VERSION}_stdthreads_${TARGET_PLATFORM}"
}
function icu_clean {
cd "${BUILD_DIR}/icu4c-${ICU_VERSION}_${TARGET_PLATFORM}_${TARGET_TYPE}"
rm -rf "${BUILD_DIR}/icu4c-${ICU_VERSION}_${TARGET_PLATFORM}_${TARGET_TYPE}"
icu_clean_native
icu_clean_stdthreads
}
function icu_strip {
cd "${PREFIX_DIR}/icu4c-${ICU_VERSION}_${TARGET_PLATFORM}_${TARGET_TYPE}"
rm -rf "${PREFIX_DIR}/icu4c-${ICU_VERSION}_${TARGET_PLATFORM}_${TARGET_TYPE}"
}
function icu_register {
export ICU_LIBS="-L${PREFIX_DIR}/lib/${COMPILER}/icu4c-${ICU_VERSION}${TARGET_SUFFIX} -licuin -licuuc -licudt"
QT_LIBS_FLAGS="${QT_LIBS_FLAGS} -icu -L ${PREFIX_DIR}/lib/${COMPILER}/icu4c-${ICU_VERSION}${TARGET_SUFFIX} -I ${PREFIX_DIR}/include/icu4c-${ICU_VERSION}"
}
function icu_source {
local VERSION=$1
local ARCHIVE=icu4c-${VERSION}
mkdir -p "${SOURCE_DIR}" \
"${SOURCE_DIR}/${ARCHIVE}"
cd "${SOURCE_DIR}"
if [ ! -d "${ARCHIVE}/icu" ]; then
local LVERSION=$(echo ${VERSION} | sed -e "s/\./-/g")
local UVERSION=$(echo ${VERSION} | sed -e "s/\./_/g")
wget -O ${ARCHIVE}.tar.gz "https://github.com/unicode-org/icu/releases/download/release-${LVERSION}/icu4c-${UVERSION}-src.tgz"
tar xfz ${ARCHIVE}.tar.gz --directory "${SOURCE_DIR}/${ARCHIVE}"
fi
if [ -d "${ARCHIVE}/mingw-std-threads" ]; then
cd ${ARCHIVE}/mingw-std-threads
git reset --hard
git pull
cd "${SOURCE_DIR}"
else
git clone "https://github.com/Syping/mingw-std-threads.git" ${ARCHIVE}/mingw-std-threads
fi
SOURCE_DIR_ICU="${SOURCE_DIR}/${ARCHIVE}/icu/source"
SOURCE_DIR_ICU_MINGW_STD_THREADS="${SOURCE_DIR}/${ARCHIVE}/mingw-std-threads"
}
# Qt script
function qt_init {
mkdir -p "${BUILD_DIR}/qt_${QT_VERSION}_${TARGET_PLATFORM}_${TARGET_TYPE}"
cd "${BUILD_DIR}/qt_${QT_VERSION}_${TARGET_PLATFORM}_${TARGET_TYPE}"
}
function qt_build {
cd "${BUILD_DIR}/qt_${QT_VERSION}_${TARGET_PLATFORM}_${TARGET_TYPE}"
if [ -f "config.cache" ]; then
rm -rf *
fi
"${SOURCE_DIR_QT}/configure" -prefix "${PREFIX_DIR}/lib/${COMPILER}/qt_${QT_VERSION}${TARGET_SUFFIX}" -headerdir "${PREFIX_DIR}/include/qt_${QT_VERSION}" -datadir "${QT_SHARE_DIR}/qt_${QT_VERSION}" -sysconfdir "${QT_SYSCONF_DIR}" -device-option CROSS_COMPILE=${COMPILER}- -xplatform ${QT_XPLATFORM} ${QT_BUILDTYPE_FLAGS} -${TARGET_TYPE} ${QT_FLAGS} ${QT_LIBS_FLAGS} ${QT_NOMAKE_FLAGS} ${TARGET_FLAGS} -opensource -confirm-license ${QT_EXTRA_FLAGS}
${MAKE_GENERATOR}
}
function qt_install {
cd "${BUILD_DIR}/qt_${QT_VERSION}_${TARGET_PLATFORM}_${TARGET_TYPE}"
${MAKE_GENERATOR_INSTALL}
ln -sf "${PREFIX_DIR}/include/qt_${QT_VERSION}" "${PREFIX_DIR}/lib/${COMPILER}/qt_${QT_VERSION}${TARGET_SUFFIX}/include"
}
function qt_clean {
cd "${BUILD_DIR}/qt_${QT_VERSION}_${TARGET_PLATFORM}_${TARGET_TYPE}"
rm -rf "${BUILD_DIR}/qt_${QT_VERSION}_${TARGET_PLATFORM}_${TARGET_TYPE}"
}
function qt_strip {
cd "${PREFIX_DIR}/lib/${COMPILER}/qt_${QT_VERSION}${TARGET_SUFFIX}"
rm -rf bin/*.exe doc
}
function qt_source {
local SERIES=$1
local BUILD=$2
local VERSION=${SERIES}.${BUILD}
if [ "$1" == "5.6" ] || [ "$1" == "5.9" ]; then
local ARCHIVE=qt-everywhere-opensource-src-${VERSION}
else
local ARCHIVE=qt-everywhere-src-${VERSION}
fi
mkdir -p "${SOURCE_DIR}"
cd "${SOURCE_DIR}"
if [ ! -d "${ARCHIVE}" ]; then
wget -O ${ARCHIVE}.tar.xz "https://download.qt.io/official_releases/qt/${SERIES}/${VERSION}/single/${ARCHIVE}.tar.xz"
tar xfJ ${ARCHIVE}.tar.xz
fi
QT_VERSION=${VERSION}
SOURCE_DIR_QT="${SOURCE_DIR}/${ARCHIVE}"
}
function qt_patch {
cd "${SOURCE_DIR_QT}"
if [ -f "qtbase/config.tests/openssl/openssl.cpp" ]; then
rm -f qtbase/config.tests/openssl/openssl.cpp
touch qtbase/config.tests/openssl/openssl.cpp
echo -e "#include <openssl/opensslv.h>\n#if !defined(OPENSSL_VERSION_NUMBER) || OPENSSL_VERSION_NUMBER-0 < 0x0090700fL\n#error \"OpenSSL >= 0.9.7 is required\"\n#endif\n#include <openssl/ssl.h>\n#if OPENSSL_VERSION_NUMBER-0 >= 0x10002000L && !defined(OPENSSL_NO_EC) && !defined(SSL_CTRL_SET_CURVES)\n#error \"OpenSSL was reported as >= 1.0.2 but is missing required features, possibly it's libressl which is unsupported\"\n#endif\nint main(){}" > qtbase/config.tests/openssl/openssl.cpp
fi
}
# QtStylePlugins script
function qtstyleplugins_init {
mkdir -p "${BUILD_DIR}/qtstyleplugins-${QT_VERSION}_${TARGET_PLATFORM}_${TARGET_TYPE}"
cd "${BUILD_DIR}/qtstyleplugins-${QT_VERSION}_${TARGET_PLATFORM}_${TARGET_TYPE}"
}
function qtstyleplugins_build {
cd "${BUILD_DIR}/qtstyleplugins-${QT_VERSION}_${TARGET_PLATFORM}_${TARGET_TYPE}"
"${PREFIX_DIR}/lib/${COMPILER}/qt_${QT_VERSION}${TARGET_SUFFIX}/bin/qmake" "${SOURCE_DIR_QTSTYLEPLUGINS}/qtstyleplugins.pro"
${MAKE_GENERATOR}
}
function qtstyleplugins_install {
cd "${BUILD_DIR}/qtstyleplugins-${QT_VERSION}_${TARGET_PLATFORM}_${TARGET_TYPE}"
${MAKE_GENERATOR_INSTALL}
}
function qtstyleplugins_clean {
cd "${BUILD_DIR}/qtstyleplugins-${QT_VERSION}_${TARGET_PLATFORM}_${TARGET_TYPE}"
rm -rf "${BUILD_DIR}/qtstyleplugins-${QT_VERSION}_${TARGET_PLATFORM}_${TARGET_TYPE}"
}
function qtstyleplugins_source {
mkdir -p "${SOURCE_DIR}"
cd "${SOURCE_DIR}"
if [ -d "qtstyleplugins-${QT_VERSION}" ]; then
cd qtstyleplugins-${QT_VERSION}
git reset --hard
git pull
cd "${SOURCE_DIR}"
else
git clone "https://code.qt.io/qt/qtstyleplugins.git" "qtstyleplugins-${QT_VERSION}"
fi
SOURCE_DIR_QTSTYLEPLUGINS="${SOURCE_DIR}/qtstyleplugins-${QT_VERSION}"
}
# Dependency checking script
function manage_dependency {
local TAR_PATH=$(command -v tar)
if [ "${TAR_PATH}" == "" ]; then
echo "Missing tar dependency, please install it!"
exit 1
fi
local GZIP_PATH=$(command -v gzip)
if [ "${GZIP_PATH}" == "" ]; then
echo "Missing gzip dependency, please install it!"
exit 1
fi
local XZ_PATH=$(command -v xz)
if [ "${XZ_PATH}" == "" ]; then
echo "Missing xz-utils dependency, please install it!"
exit 1
fi
local NINJA_PATH=$(command -v ninja)
if [ "${NINJA_PATH}" == "" ]; then
local GMAKE_PATH=$(command -v gmake)
if [ "${GMAKE_PATH}" == "" ]; then
local MAKE_PATH=$(command -v make)
if [ "${MAKE_PATH}" == "" ]; then
echo "Missing make generators, please install one!"
exit 1
else
CMAKE_GENERATOR="${MAKE_PATH} -j${CPU_THREADS}"
CMAKE_GENERATOR_INSTALL="${MAKE_PATH} install"
fi
else
CMAKE_GENERATOR="${GMAKE_PATH} -j${CPU_THREADS}"
CMAKE_GENERATOR_INSTALL="${GMAKE_PATH} install"
fi
else
CMAKE_GENERATOR_FLAGS="-GNinja"
CMAKE_GENERATOR="${NINJA_PATH}"
CMAKE_GENERATOR_INSTALL="${NINJA_PATH} install"
fi
local GMAKE_PATH=$(command -v gmake)
if [ "${GMAKE_PATH}" == "" ]; then
local MAKE_PATH=$(command -v make)
if [ "${MAKE_PATH}" == "" ]; then
echo "Missing make generators, please install one!"
exit 1
else
MAKE_GENERATOR="${MAKE_PATH} -j${CPU_THREADS}"
MAKE_GENERATOR_INSTALL="${MAKE_PATH} install"
fi
else
MAKE_GENERATOR="${GMAKE_PATH} -j${CPU_THREADS}"
MAKE_GENERATOR_INSTALL="${GMAKE_PATH} install"
fi
if [ "${BUILD_SSL}" == "YES" ]; then
if [ "${USE_OPENSSL}" == "YES" ]; then
local PERL_PATH=$(command -v perl)
if [ "${PERL_PATH}" == "" ]; then
echo "OpenSSL missing Perl dependency, please install it!"
exit 1
fi
fi
fi
if [ "${BUILD_JPG}" == "YES" ]; then
local CMAKE_PATH=$(command -v cmake)
if [ "${CMAKE_PATH}" == "" ]; then
echo "libjpeg-turbo missing CMake dependency, please install it!"
exit 1
fi
local NASM_PATH=$(command -v nasm)
if [ "${NASM_PATH}" == "" ]; then
echo "libjpeg-turbo missing NASM dependency, please install it!"
exit 1
fi
fi
if [ "${BUILD_ICU}" == "YES" ]; then
local CMAKE_PATH=$(command -v cmake)
if [ "${CMAKE_PATH}" == "" ]; then
echo "ICU missing CMake dependency, please install it!"
exit 1
fi
local GIT_PATH=$(command -v git)
if [ "${GIT_PATH}" == "" ]; then
echo "ICU missing git dependency, please install it!"
exit 1
fi
local CC_PATH=$(command -v cc)
if [ "${CC_PATH}" == "" ]; then
echo "ICU missing C Compiler, please install one!"
exit 1
fi
local CXX_PATH=$(command -v c++)
if [ "${CXX_PATH}" == "" ]; then
echo "ICU missing C++ Compiler, please install one!"
exit 1
fi
fi
if [ "${BUILD_QT}" == "YES" ]; then
local GIT_PATH=$(command -v git)
if [ "${GIT_PATH}" == "" ]; then
echo "Qt missing git dependency, please install it!"
exit 1
fi
local PERL_PATH=$(command -v perl)
if [ "${PERL_PATH}" == "" ]; then
echo "Qt missing Perl dependency, please install it!"
exit 1
fi
local PYTHON_PATH=$(command -v python)
if [ "${PYTHON_PATH}" == "" ]; then
echo "Qt missing Python dependency, please install it!"
exit 1
fi
local CC_PATH=$(command -v cc)
if [ "${CC_PATH}" == "" ]; then
echo "Qt missing C Compiler, please install one!"
exit 1
fi
local CXX_PATH=$(command -v c++)
if [ "${CXX_PATH}" == "" ]; then
echo "Qt missing C++ Compiler, please install one!"
exit 1
fi
fi
}
# General build script
function build_init {
mkdir -p "${BUILD_DIR}"
cd "${BUILD_DIR}"
}
function build_type {
TARGET_PLATFORM=$1
if [ "${TARGET_PLATFORM}" == "mingw32" ] || [ "${TARGET_PLATFORM}" == "i686-w64-mingw32" ]; then
TARGET_PLATFORM=mingw32
COMPILER=i686-w64-mingw32
if [ "${MINGW_USE_CLANG}" == "YES" ]; then
USE_CLANG=YES
QT_XPLATFORM=win32-clang-g++
local SET_CC=$(command -v ${COMPILER}-clang)
local SET_CXX=$(command -v ${COMPILER}-clang++)
else
USE_GCC=YES
QT_XPLATFORM=win32-g++
local SET_CC=$(command -v ${COMPILER}-gcc)
local SET_CXX=$(command -v ${COMPILER}-g++)
fi
SSL_PLATFORM=mingw
TARGET_OS=Windows
TARGET_CPU=X86
local SET_RC=$(command -v ${COMPILER}-windres)
if [ "${SET_CC}" == "" ] || [ "${SET_CXX}" == "" ] || [ "${SET_RC}" == "" ]; then
echo "Incomplete or missing ${TARGET_PLATFORM} compiler for current build, please install one!"
exit 1
fi
echo -e "set(CMAKE_SYSTEM_NAME ${TARGET_OS})\nset(CMAKE_SYSTEM_PROCESSOR ${TARGET_CPU})\nset(CMAKE_C_COMPILER ${SET_CC})\nset(CMAKE_CXX_COMPILER ${SET_CXX})\nset(CMAKE_RC_COMPILER ${SET_RC})" > "${BUILD_DIR}/cmake.${TARGET_PLATFORM}.toolchain"
CMAKE_TOOLCHAIN_FLAGS="-DCMAKE_TOOLCHAIN_FILE=${BUILD_DIR}/cmake.${TARGET_PLATFORM}.toolchain"
elif [ "${TARGET_PLATFORM}" == "mingw64" ] || [ "${TARGET_PLATFORM}" == "x86_64-w64-mingw32" ]; then
TARGET_PLATFORM=mingw64
COMPILER=x86_64-w64-mingw32
if [ "${MINGW_USE_CLANG}" == "YES" ]; then
USE_CLANG=YES
QT_XPLATFORM=win32-clang-g++
local SET_CC=$(command -v ${COMPILER}-clang)
local SET_CXX=$(command -v ${COMPILER}-clang++)
else
USE_GCC=YES
QT_XPLATFORM=win32-g++
local SET_CC=$(command -v ${COMPILER}-gcc)
local SET_CXX=$(command -v ${COMPILER}-g++)
fi
SSL_PLATFORM=mingw64
TARGET_OS=Windows
TARGET_CPU=AMD64
local SET_RC=$(command -v ${COMPILER}-windres)
if [ "${SET_CC}" == "" ] || [ "${SET_CXX}" == "" ] || [ "${SET_RC}" == "" ]; then
echo "Incomplete or missing ${TARGET_PLATFORM} compiler for current build, please install one!"
exit 1
fi
echo -e "set(CMAKE_SYSTEM_NAME ${TARGET_OS})\nset(CMAKE_SYSTEM_PROCESSOR ${TARGET_CPU})\nset(CMAKE_C_COMPILER ${SET_CC})\nset(CMAKE_CXX_COMPILER ${SET_CXX})\nset(CMAKE_RC_COMPILER ${SET_RC})" > "${BUILD_DIR}/cmake.${TARGET_PLATFORM}.toolchain"
CMAKE_TOOLCHAIN_FLAGS="-DCMAKE_TOOLCHAIN_FILE=${BUILD_DIR}/cmake.${TARGET_PLATFORM}.toolchain"
else
COMPILER=${TARGET_PLATFORM}
if [ "${CUSTOM_USE_CLANG}" == "YES" ]; then
USE_CLANG=YES
local SET_CC=$(command -v ${COMPILER}-clang)
local SET_CXX=$(command -v ${COMPILER}-clang++)
elif [ "${CUSTOM_USE_GCC}" == "YES" ]; then
USE_GCC=YES
local SET_CC=$(command -v ${COMPILER}-gcc)
local SET_CXX=$(command -v ${COMPILER}-g++)
else
local SET_CC=$(command -v ${COMPILER}-cc)
local SET_CXX=$(command -v ${COMPILER}-c++)
fi
if [ "${SET_CC}" == "" ] || [ "${SET_CXX}" == "" ]; then
echo "Incomplete or missing ${TARGET_PLATFORM} compiler for current build, please install one!"
exit 1
fi
if [ "${BUILD_QT}" == "YES" ]; then
if [ "${QT_XPLATFORM}" == "" ]; then
echo "QT_XPLATFORM environment value not set, please set!"
exit 1
fi
fi
if [ "${BUILD_SSL}" == "YES" ]; then
if [ "${USE_OPENSSL}" == "YES" ]; then
if [ "${SSL_PLATFORM}" == "" ]; then
echo "SSL_PLATFORM environment value not set, please set!"
exit 1
fi
fi
fi
if [ "${TARGET_OS}" == "" ]; then
echo "TARGET_OS environment value not set, please set!"
exit 1
fi
if [ "${TARGET_CPU}" == "" ]; then
echo "TARGET_CPU environment value not set, please set!"
exit 1
fi
echo -e "set(CMAKE_SYSTEM_NAME ${TARGET_OS})\nset(CMAKE_SYSTEM_PROCESSOR ${TARGET_CPU})\nset(CMAKE_C_COMPILER ${SET_CC})\nset(CMAKE_CXX_COMPILER ${SET_CXX})" > "${BUILD_DIR}/cmake.${TARGET_PLATFORM}.toolchain"
CMAKE_TOOLCHAIN_FLAGS="-DCMAKE_TOOLCHAIN_FILE=${BUILD_DIR}/cmake.${TARGET_PLATFORM}.toolchain"
fi
TARGET_TYPE=$2
TARGET_SUFFIX=$3
}
function build_clean_env {
# Clear environment values
export ICU_LIBS=
export OPENSSL_LIBS=
QT_LIBS_FLAGS=
USE_CLANG=
USE_GCC=
local EXTRA_COMMAND=$1
if [ "${EXTRA_COMMAND}" == "reregister" ]; then
if [ "${LINK_JPG}" == "YES" ]; then
libjpegturbo_register
fi
fi
}
function build_tl_set {
build_type $1
if [ "${BUILD_JPG}" == "YES" ]; then
libjpegturbo_init
libjpegturbo_build
libjpegturbo_install
libjpegturbo_strip
libjpegturbo_clean
fi
if [ "${LINK_JPG}" == "YES" ]; then
libjpegturbo_register
fi
}
function build_set {
build_type $1 $2 $3
if [ "${BUILD_SSL}" == "YES" ]; then
if [ "${USE_OPENSSL}" == "YES" ]; then
openssl_init
openssl_build
openssl_install
openssl_strip
openssl_clean
else
libressl_init
libressl_build
libressl_install
libressl_strip
libressl_clean
fi
fi
if [ "${LINK_SSL}" == "YES" ]; then
if [ "${USE_OPENSSL}" == "YES" ]; then
openssl_register
else
libressl_register
fi
fi
if [ "${BUILD_ICU}" == "YES" ]; then
icu_init
icu_build
icu_install
icu_strip
icu_clean
fi
if [ "${LINK_ICU}" == "YES" ]; then
icu_register
fi
if [ "${BUILD_QT}" == "YES" ]; then
qt_init
qt_build
qt_install
qt_strip
qt_clean
if [ "${TARGET_TYPE}" == "shared" ]; then
qtstyleplugins_init
qtstyleplugins_build
qtstyleplugins_install
qtstyleplugins_clean
fi
fi
}
# Runtime execution script
set +e
manage_dependency
build_init
libjpegturbo_source ${LIBJPEGTURBO_VERSION}
if [ "${USE_OPENSSL}" == "YES" ]; then
openssl_source ${OPENSSL_VERSION}
else
libressl_source ${LIBRESSL_VERSION}
fi
icu_source ${ICU_VERSION}
qt_source ${QT_SERIES} ${QT_BUILD}
if [ ! "${USE_OPENSSL}" == "YES" ]; then
qt_patch
fi
qtstyleplugins_source
# Custom build
if [ "${CUSTOM_SET}" == "YES" ]; then
build_clean_env
build_tl_set ${TARGET_PLATFORM}
if [ "${CUSTOM_SET_TYPE}" == "all" ]; then
build_set ${TARGET_PLATFORM} shared _d
build_clean_env reregister
build_set ${TARGET_PLATFORM} static _s
elif [ "${CUSTOM_SET_TYPE}" == "mshared" ]; then
build_set ${TARGET_PLATFORM} shared _d
elif [ "${CUSTOM_SET_TYPE}" == "mstatic" ]; then
build_set ${TARGET_PLATFORM} static _s
elif [ "${CUSTOM_SET_TYPE}" == "static" ]; then
build_set ${TARGET_PLATFORM} static
else
build_set ${TARGET_PLATFORM} shared
fi
fi
# Windows 32-Bit builds
if [ ! "${BUILD_MINGW32_SHARED}" == "NO" ] || [ ! "${BUILD_MINGW32_STATIC}" == "NO" ]; then
build_clean_env
build_tl_set mingw32
fi
if [ ! "${BUILD_MINGW32_SHARED}" == "NO" ]; then
build_set mingw32 shared _d
build_clean_env reregister
fi
if [ ! "${BUILD_MINGW32_STATIC}" == "NO" ]; then
build_set mingw32 static _s
build_clean_env reregister
fi
# Windows 64-Bit builds
if [ ! "${BUILD_MINGW64_SHARED}" == "NO" ] || [ ! "${BUILD_MINGW64_STATIC}" == "NO" ]; then
build_clean_env
build_tl_set mingw64
fi
if [ ! "${BUILD_MINGW64_SHARED}" == "NO" ]; then
build_set mingw64 shared _d
build_clean_env reregister
fi
if [ ! "${BUILD_MINGW64_STATIC}" == "NO" ]; then
build_set mingw64 static _s
build_clean_env reregister
fi