File indexing completed on 2022-08-06 12:40:19

0001 #!/bin/bash
0002 # This script can be used to build Kid3 together with static libraries for the
0003 # Windows and Mac versions of Kid3. Linux and BSD users do not need it because
0004 # the libraries can be installed from their repositories, but they can use it
0005 # to generate a self contained package with a minimum of dependencies.
0006 #
0007 # First you have to install the necessary tools:
0008 #
0009 # For Windows:
0010 #
0011 # Install Qt, you should use the MinGW which comes with Qt and add msys2
0012 # to build the libraries. Additional dependencies can be installed using
0013 # Chocolatey, e.g.
0014 # choco install cmake docbook-bundle ninja python3 Wget xsltproc yasm
0015 # Install additional packages in the MSYS2 MinGW 64-bit shell:
0016 # pacman -S git patch make autoconf automake nasm libtool
0017 # Start the msys shell, add Qt and cmake to the path and start this script.
0018 #
0019 # export QTPREFIX=/c/Qt/5.12.8/mingw73_64
0020 # test -z "${PATH##$QTPREFIX*}" ||
0021 # PATH=$QTPREFIX/bin:$QTPREFIX/../../Tools/mingw730_64/bin:$QTPREFIX/../../Tools/mingw730_64/opt/bin:$PROGRAMFILES/CMake/bin:$PATH
0022 # ../kid3/build.sh
0023 #
0024 # You can also build a Windows version from Linux using the MinGW cross
0025 # compiler.
0026 # COMPILER=cross-mingw QTPREFIX=/path/to/Qt5.6.3-mingw/5.6.3/mingw49_32 ../kid3/build.sh
0027 #
0028 # For Mac:
0029 #
0030 # Install XCode with the command line tools and Qt. The other build dependencies
0031 # can be installed with Homebrew, for instance:
0032 # brew install cmake ninja autoconf automake libtool xz nasm docbook-xsl
0033 # Then call from a build directory
0034 # QTPREFIX=/path/to/Qt/5.9.7/clang_64 ../kid3/build.sh
0035 #
0036 # You can also build a macOS version from Linux using the osxcross toolchain.
0037 # COMPILER=cross-macos QTPREFIX=/path/to/Qt5.9.7-mac/5.9.7/clang_64 ../kid3/build.sh
0038 # or
0039 # COMPILER=cross-macos QTPREFIX=/path/to/Qt5.9.7-mac/5.9.7/clang_64 QTBINARYDIR=/path/to/Qt5.9.7-linux/5.9.7/gcc_64/bin ../kid3/build.sh
0040 #
0041 # For Android:
0042 #
0043 # Install Qt and a compatible Android SDK and NDK, for example Qt 5.9.7, NDK 10e or Qt 5.12.2, NDK 19c.
0044 # COMPILER=cross-android QTPREFIX=/path/to/Qt/5.9.7/android_armv7 ANDROID_SDK_ROOT=/path/to/sdk ANDROID_NDK_ROOT=/path/to/ndk-bundle ../build.sh
0045 #
0046 # For Linux:
0047 #
0048 # To build a self-contained Linux package use
0049 # COMPILER=gcc-self-contained QTPREFIX=/path/to/Qt5.15.2-linux/5.15.2/gcc_64 ../kid3/build.sh
0050 #
0051 # When cross compiling make sure that the host Qt version is not larger than
0052 # the target Qt version, otherwise moc and plugins will fail. To provide
0053 # host Qt binaries of a suitable version, set the QTBINARYDIR environment
0054 # variable.
0055 #
0056 # The source code for the libraries is downloaded from Debian and Ubuntu
0057 # repositories. If the files are no longer available, use a later version,
0058 # it should still work.
0059 #
0060 # build.sh will download, build and install zlib, libogg, libvorbis,
0061 # flac, id3lib, taglib, ffmpeg, chromaprint, mp4v2. When the libraries
0062 # are built, the Kid3 package is built. It is also possible to build only
0063 # the libraries or only the Kid3 package.
0064 #
0065 # ../kid3/build.sh libs
0066 # ../kid3/build.sh package
0067 
0068 # Exit if an error occurs
0069 set -e
0070 shopt -s extglob
0071 
0072 thisdir=$(pwd)
0073 srcdir=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
0074 
0075 kernel=$(uname)
0076 test ${kernel:0:5} = "MINGW" && kernel="MINGW"
0077 
0078 verify_not_in_srcdir() {
0079   if test -f CMakeLists.txt; then
0080     echo "Do not run this script from the source directory!"
0081     echo "Start it from a build directory at the same level as the source directory."
0082     exit 1
0083   fi
0084 }
0085 
0086 verify_in_srcdir() {
0087   if ! test -f CMakeLists.txt; then
0088     echo "Run this task from the source directory!"
0089     exit 1
0090   fi
0091 }
0092 
0093 # Administrative subtasks
0094 
0095 # Changes version and date strings in all known Kid3 files.
0096 if test "$1" = "changeversion"; then
0097   OLDVER=$2
0098   NEWVER=$3
0099   if test -z "$OLDVER" || test -z "$NEWVER"; then
0100     echo "Usage: $0 $1 old-version-nr new-version-nr [--finalize], e.g. $0 $1 0.8 0.9"
0101     exit 1
0102   fi
0103 
0104   echo "### Change version and date strings"
0105 
0106   DATE=$(LC_TIME=C date)
0107   DATE_R=$(date -R)
0108   DATE_F=$(date +"%F")
0109   DATE_Y=$(date +"%Y")
0110 
0111   OLDMAJOR=$(echo $OLDVER | cut -f 1 -d .)
0112   OLDMINOR=$(echo $OLDVER | cut -f 2 -d .)
0113   OLDPATCH=$(echo $OLDVER | cut -f 3 -d .)
0114   test -z $OLDPATCH && OLDPATCH=0
0115 
0116   NEWMAJOR=$(echo $NEWVER | cut -f 1 -d .)
0117   NEWMINOR=$(echo $NEWVER | cut -f 2 -d .)
0118   NEWPATCH=$(echo $NEWVER | cut -f 3 -d .)
0119   test -z $NEWPATCH && NEWPATCH=0
0120 
0121   cd "$srcdir"
0122   grep -qF "kid3 (${NEWVER}-0)" deb/changelog ||
0123   sed -i "1 i\
0124 kid3 (${NEWVER}-0) unstable; urgency=low\n\n  * New upstream release.\n\n\
0125  -- Urs Fleisch <ufleisch@users.sourceforge.net>  ${DATE_R}\n" deb/changelog
0126   grep -qF "<releaseinfo>${NEWVER}</releaseinfo>" doc/en/index.docbook ||
0127   sed -i "s/^<releaseinfo>${OLDVER}<\/releaseinfo>$/<releaseinfo>${NEWVER}<\/releaseinfo>/; s/^<year>[0-9]\+<\/year>$/<year>${DATE_Y}<\/year>/; s/^<date>[0-9-]\+<\/date>$/<date>${DATE_F}<\/date>/" doc/en/index.docbook
0128   sed -i "s/PROJECTVERSION=\"${OLDVER}\"/PROJECTVERSION=\"${NEWVER}\"/" translations/extract-merge.sh
0129   # kid3.spec is used by f-droid to detect a new version, it should be updated exactly before the release.
0130   if test "$4" = "--finalize"; then
0131     sed -i "s/^Version:        ${OLDVER}$/Version:        ${NEWVER}/" kid3.spec
0132     OLDCODE=$(sed -n "s/ \+set(QT_ANDROID_APP_VERSION_CODE \([0-9]\+\))/\1/p" CMakeLists.txt)
0133     NEWCODE=$[ $OLDCODE + 1 ]
0134     sed -i "s/\( \+set(QT_ANDROID_APP_VERSION_CODE \)\([0-9]\+\))/\1$NEWCODE)/" CMakeLists.txt
0135   fi
0136   sed -i "s/^Copyright 2003-[0-9]\+ Urs Fleisch <ufleisch@users.sourceforge.net>$/Copyright 2003-${DATE_Y} Urs Fleisch <ufleisch@users.sourceforge.net>/" deb/copyright
0137   grep -qF "* Release ${NEWVER}" ChangeLog ||
0138   sed -i "1 i\
0139 ${DATE}  Urs Fleisch  <ufleisch@users.sourceforge.net>\n\n\t* Release ${NEWVER}\n" ChangeLog
0140   sed -i "s/PROJECT_NUMBER         = ${OLDVER}/PROJECT_NUMBER         = ${NEWVER}/" Doxyfile
0141   sed -i "s/set(CPACK_PACKAGE_VERSION_MAJOR ${OLDMAJOR})/set(CPACK_PACKAGE_VERSION_MAJOR ${NEWMAJOR})/; s/set(CPACK_PACKAGE_VERSION_MINOR ${OLDMINOR})/set(CPACK_PACKAGE_VERSION_MINOR ${NEWMINOR})/; s/set(CPACK_PACKAGE_VERSION_PATCH ${OLDPATCH})/set(CPACK_PACKAGE_VERSION_PATCH ${NEWPATCH})/; s/set(RELEASE_YEAR [0-9]\+)/set(RELEASE_YEAR ${DATE_Y})/" CMakeLists.txt
0142   grep -qF "<release version=\"${NEWVER}\"" src/app/org.kde.kid3.appdata.xml ||
0143   sed -i "s,^  <releases>.*,&\n    <release version=\"${NEWVER}\" date=\"${DATE_F}\"/>," src/app/org.kde.kid3.appdata.xml
0144   grep -q "for ver in .*'${NEWVER}'" packaging/craft/extragear/kid3/kid3.py ||
0145   sed -i -r "s/(for ver in \[[^]]*'${OLDVER}')\]:/\1, '${NEWVER}']:/" packaging/craft/extragear/kid3/kid3.py
0146   sed -i "s,https://download.kde.org/stable/kid3/${OLDVER}/kid3-${OLDVER}.tar.xz,https://download.kde.org/stable/kid3/${NEWVER}/kid3-${NEWVER}.tar.xz," packaging/flatpak/org.kde.kid3-stable.json
0147   cd - >/dev/null
0148   exit 0
0149 fi # changeversion
0150 
0151 if test "$1" = "cleanuppo"; then
0152   echo "### Clean up .po files"
0153 
0154   for f in $srcdir/translations/po/*/*.po; do
0155     sed -i "/#, \(fuzzy, \)\?qt-\(plural-\)\?format/ d; /#, kde-format/ d; /^#~ msg/ d" $f
0156   done
0157   exit 0
0158 fi # cleanuppo
0159 
0160 if test "$1" = "makearchive"; then
0161   VERSION=$2
0162   if test -z "$VERSION"; then
0163     VERSION=$(date +"%Y%m%d")
0164   fi
0165 
0166   DIR=kid3-$VERSION
0167   TGZ=$DIR.tar.gz
0168   if test -e "$TGZ"; then
0169     echo "$TGZ already exists!"
0170     exit 1
0171   fi
0172 
0173   cd $srcdir
0174   git archive --format=tar --prefix=$DIR/ HEAD | gzip >$thisdir/$TGZ
0175   cd - >/dev/null
0176   exit 0
0177 fi # makearchive
0178 
0179 # Build a docker image to build binary Kid3 packages.
0180 # The docker image can then be started using "rundocker".
0181 # You can then build all packages using
0182 # kid3/build.sh rundocker $HOME/projects/kid3/src/build-all.sh
0183 # You need:
0184 # - Kid3 project checked out in ~/projects/kid3/src/kid3
0185 # Linux:
0186 # - Qt 5.15.2 Linux in ~/Development/Qt5.15.2-linux/5.15.2/gcc_64/
0187 # Windows:
0188 # - MinGW cross compiler in /opt/mxe/
0189 # - Qt 5.15.2 MinGW64 in ~/Development/Qt5.15.2-mingw64/5.15.2/mingw81_64/
0190 # Mac:
0191 # - Mac cross compiler in /opt/osxcross/
0192 # - Qt 5.15.2 Mac in ~/Development/Qt5.15.2-mac/5.15.2/clang_64/
0193 # Android:
0194 # - Java JDK 8 in /opt/jdk8/
0195 # - Android SDK in ~/Development/android/sdk/
0196 # - Android NDK in ~/Development/android/sdk/android-ndk-r19c/
0197 # - Qt 5.12.12 Android in ~/Development/Qt5.12.12-android/5.12.12/android_armv7/
0198 # - Sign key in ~/Development/ufleisch-release-key.keystore
0199 # - Gradle cache in ~/.gradle/
0200 if test "$1" = "makedocker"; then
0201   verify_not_in_srcdir
0202   if ! test -f build-all.sh; then
0203     cat >build-all.sh <<"EOF"
0204 #!/bin/bash
0205 cd "$(dirname "${BASH_SOURCE[0]}")"
0206 set -e
0207 (cd linux_build && \
0208    COMPILER=gcc-self-contained \
0209    QTPREFIX=$HOME/Development/Qt5.15.2-linux/5.15.2/gcc_64 \
0210    ../kid3/build.sh)
0211 (cd mingw64_build && \
0212    PATH=/opt/mxe/usr/bin:$PATH \
0213    COMPILER=cross-mingw \
0214    QTPREFIX=$HOME/Development/Qt5.15.2-mingw64/5.15.2/mingw81_64 \
0215    ../kid3/build.sh)
0216 (cd macos_build && \
0217    COMPILER=cross-macos \
0218    QTPREFIX=$HOME/Development/Qt5.15.2-mac/5.15.2/clang_64 \
0219    OSXPREFIX=/opt/osxcross/target \
0220    ../kid3/build.sh)
0221 (cd android_build && \
0222    COMPILER=cross-android \
0223    QTPREFIX=$HOME/Development/Qt5.12.12-android/5.12.12/android_armv7 \
0224    JAVA_HOME=/opt/jdk8 \
0225    ANDROID_SDK_ROOT=$HOME/Development/android/sdk \
0226    ANDROID_NDK_ROOT=$ANDROID_SDK_ROOT/android-ndk-r19c \
0227    ../kid3/build.sh)
0228 EOF
0229     chmod +x build-all.sh
0230   fi
0231   mkdir -p docker_image_context
0232   cd docker_image_context
0233   echo "### Build docker image"
0234   UNAME=$(uname)
0235   if hash podman 2>/dev/null; then
0236     DOCKER=podman
0237   elif [ -z "${UNAME##MINGW*}" ] || [ -z "${UNAME##MSYS*}" ] || id -Gn | grep -qw "docker\(root\)\?"; then
0238     DOCKER=docker
0239   else
0240     DOCKER="sudo docker"
0241   fi
0242   $DOCKER build --build-arg USER=${USER} --build-arg UID=$(id -u) -t ufleisch/kid3dev:bullseye . -f-<<"EOF"
0243 FROM debian:bullseye-slim
0244 RUN apt-get update && apt-get install -y --no-install-recommends \
0245 devscripts build-essential lintian debhelper extra-cmake-modules \
0246 libkf5kio-dev libkf5doctools-dev qtmultimedia5-dev qtdeclarative5-dev \
0247 qttools5-dev qttools5-dev-tools qtdeclarative5-dev-tools \
0248 qml-module-qtquick2 cmake python libid3-3.8.3-dev libflac++-dev \
0249 libvorbis-dev libtag1-dev libchromaprint-dev libavformat-dev \
0250 libavcodec-dev docbook-xsl pkg-config libreadline-dev xsltproc \
0251 debian-keyring dput-ng python3-distro-info sudo curl less \
0252 locales ninja-build ccache p7zip-full genisoimage \
0253 clang llvm nasm lib32z1 chrpath libpulse-mainloop-glib0
0254 ARG USER
0255 ARG UID
0256 RUN adduser --quiet --disabled-password --uid $UID --gecos "User" $USER && \
0257 echo "$USER:$USER" | chpasswd && usermod -aG sudo $USER && \
0258 locale-gen en_US.UTF-8 && \
0259 mkdir -p /home/$USER/projects/kid3 /home/$USER/Development
0260 USER $USER
0261 CMD bash
0262 EOF
0263   exit 0
0264 fi
0265 
0266 # Run docker image created with "makedocker".
0267 if test "$1" = "rundocker"; then
0268   echo "### Run docker image"
0269   shift
0270   UNAME=$(uname)
0271   if hash podman 2>/dev/null; then
0272     DOCKER=podman
0273     USERNSARG=--userns=keep-id
0274   elif [ -z "${UNAME##MINGW*}" ] || [ -z "${UNAME##MSYS*}" ] || id -Gn | grep -qw "docker\(root\)\?"; then
0275     DOCKER=docker
0276     USERNSARG=
0277   else
0278     DOCKER="sudo docker"
0279     USERNSARG=
0280   fi
0281   $DOCKER run $USERNSARG --rm -it -e LANG=C.UTF-8 \
0282          -v $HOME/projects/kid3:$HOME/projects/kid3 \
0283          -v $HOME/.gradle:$HOME/.gradle \
0284          -v $HOME/.gnupg:$HOME/.gnupg:ro \
0285          -v /opt/osxcross:/opt/osxcross:ro \
0286          -v /opt/mxe:/opt/mxe:ro \
0287          -v /opt/jdk8:/opt/jdk8:ro \
0288          -v $HOME/Development:$HOME/Development:ro ufleisch/kid3dev:bullseye "$@"
0289   exit 0
0290 fi
0291 
0292 # Build flatpak
0293 if test "$1" = "flatpak"; then
0294   verify_not_in_srcdir
0295   echo "### Build flatpak"
0296   flatpak-builder --sandbox --force-clean --ccache --repo=repo --subject="Build of org.kde.kid3 $(date --iso-8601=seconds)" app "$srcdir/packaging/flatpak/org.kde.kid3-local.json"
0297   exit 0
0298 fi
0299 
0300 # Build Debian package.
0301 if test "$1" = "deb"; then
0302   verify_in_srcdir
0303   echo "### Build Debian package"
0304   shift
0305   test -d debian && rm -rf debian
0306   cp -R deb debian
0307   # The PPA version (e.g. trusty1) can be given as a parameter to prepare
0308   # a PPA upload. The source archive kid3_${version}.orig.tar.gz must be
0309   # in the parent directory.
0310   ppaversion=$1
0311   if test -n "$ppaversion"; then
0312     distribution=${ppaversion%%[0-9]*}
0313   else
0314     distribution=$(lsb_release -sc)
0315   fi
0316 
0317   if test -n "$ppaversion"; then
0318     version=$(sed -e 's/^kid3 (\([0-9\.-]\+\).*$/\1/;q' debian/changelog)
0319     DEBEMAIL="Urs Fleisch <ufleisch@users.sourceforge.net>" \
0320     dch --newversion=${version}${ppaversion} --distribution=$distribution --urgency=low \
0321     "No-change backport to $distribution."
0322     sed -i -e 's/^Maintainer:.*$/Maintainer: Urs Fleisch <ufleisch@users.sourceforge.net>/;/^Uploaders:/,+1d' debian/control
0323     debuild -S -sa &&
0324     echo "PPA upload ready for $distribution. Use:" &&
0325     echo "cd ..; dput ppa:ufleisch/kid3 kid3_${version}${ppaversion}_source.changes"
0326   else
0327     rm -rf debian/source debian/watch
0328     debuild
0329   fi
0330   exit 0
0331 fi
0332 
0333 # End of subtasks
0334 
0335 verify_not_in_srcdir
0336 
0337 target=${*:-libs package}
0338 
0339 qt_version=5.15.2
0340 zlib_version=1.2.8
0341 zlib_patchlevel=5
0342 libogg_version=1.3.4
0343 libogg_patchlevel=0.1
0344 libvorbis_version=1.3.7
0345 libvorbis_patchlevel=1
0346 ffmpeg3_version=3.2.14
0347 ffmpeg3_patchlevel=1~deb9u1
0348 ffmpeg_version=5.0.1
0349 ffmpeg_patchlevel=3
0350 libflac_version=1.3.4
0351 libflac_patchlevel=2
0352 id3lib_version=3.8.3
0353 id3lib_patchlevel=16.3
0354 taglib_version=1.12
0355 taglib_githash=4e7f844ea6439a5a90546feba359832b2ce2e2e8
0356 chromaprint_version=1.5.1
0357 chromaprint_patchlevel=2
0358 mp4v2_version=2.1.1
0359 
0360 # Try to find the configuration from an existing build.
0361 if test -z "$COMPILER"; then
0362   if test -f mingw.cmake; then
0363     COMPILER=cross-mingw
0364     QTPREFIX=$(sed -ne '1 s/set(QT_PREFIX \([^)]\+\))/\1/p' mingw.cmake)
0365   elif test -f osxcross.cmake; then
0366     COMPILER=cross-macos
0367     QTPREFIX=$(sed -ne '1 s/set(QT_PREFIX \([^)]\+\))/\1/p' osxcross.cmake)
0368   elif test $(ls openssl-*/Setenv-android.sh 2>/dev/null | wc -l) != "0"; then
0369     COMPILER=cross-android
0370     test -f kid3/CMakeCache.txt &&
0371       QTPREFIX=$(sed -ne 's/^QT_QMAKE_EXECUTABLE[^=]*=\(.*\)\/bin\/qmake$/\1/p' kid3/CMakeCache.txt)
0372   elif grep -q "CMAKE_CXX_COMPILER.*g++-4\.8" kid3/CMakeCache.txt 2>/dev/null; then
0373     COMPILER=gcc-self-contained
0374     QTPREFIX=$(sed -ne 's/^QT_QMAKE_EXECUTABLE[^=]*=\(.*\)\/bin\/qmake$/\1/p' kid3/CMakeCache.txt)
0375   elif grep -q "^CMAKE_BUILD_TYPE.*=Debug$" kid3/CMakeCache.txt 2>/dev/null; then
0376     COMPILER=gcc-debug
0377     QTPREFIX=$(sed -ne 's/^QT_QMAKE_EXECUTABLE[^=]*=\(.*\)\/bin\/qmake$/\1/p' kid3/CMakeCache.txt)
0378   fi
0379 fi
0380 
0381 compiler=${COMPILER:-gcc}
0382 echo -n "### Building $target with $compiler"
0383 if test -n "$QTPREFIX"; then
0384   echo -n " using $QTPREFIX"
0385 fi
0386 echo "."
0387 
0388 if [[ "$QTPREFIX" =~ /([0-9]+)\.([0-9]+)\.([0-9]+)/ ]]; then
0389   qt_nr=$(printf "%d%02d%02d" ${BASH_REMATCH[1]} ${BASH_REMATCH[2]} ${BASH_REMATCH[3]})
0390   qt_version=$(printf "%d.%d.%d" ${BASH_REMATCH[1]} ${BASH_REMATCH[2]} ${BASH_REMATCH[3]})
0391   qt_version_major=${BASH_REMATCH[1]}
0392 else
0393   echo "Could not extract Qt version from $QTPREFIX, assuming $qt_version"
0394   if [[ "$qt_version" =~ ^([0-9]+)\.([0-9]+)\.([0-9]+)$ ]]; then
0395     qt_nr=$(printf "%d%02d%02d" ${BASH_REMATCH[1]} ${BASH_REMATCH[2]} ${BASH_REMATCH[3]})
0396     qt_version_major=${BASH_REMATCH[1]}
0397   fi
0398 fi
0399 
0400 if test "$qt_nr" -ge 51204; then
0401   # Since Qt 5.12.4, OpenSSL 1.1.1 is supported
0402   openssl_version=1.1.1g
0403 else
0404   openssl_version=1.0.2u
0405 fi
0406 
0407 if test "$compiler" = "gcc-self-contained"; then
0408   if test "$qt_nr" -lt 51500; then
0409     gcc_self_contained_cc="gcc-4.8"
0410     gcc_self_contained_cxx="g++-4.8"
0411   else
0412     gcc_self_contained_cc="gcc"
0413     gcc_self_contained_cxx="g++"
0414   fi
0415 fi
0416 
0417 if test "$compiler" = "cross-mingw"; then
0418   if test -n "$QTPREFIX" && test -z "${QTPREFIX%%*64?(/)}"; then
0419     cross_host="x86_64-w64-mingw32"
0420     if hash ${cross_host}-gcc-posix 2>/dev/null; then
0421       _crossprefix=${cross_host}-
0422       # Qt uses posix threads, but x86_64-w64-mingw32-gcc uses win32 thread model.
0423       _crosssuffix=-posix
0424     elif hash ${cross_host}.shared-gcc 2>/dev/null; then
0425       _crossprefix=${cross_host}.shared-
0426       _crosssuffix=
0427     fi
0428   else
0429     cross_host="i686-w64-mingw32"
0430     _crossprefix=${cross_host}-
0431     _crosssuffix=
0432     # FFmpeg > 3 is not compatible with Windows XP
0433     ffmpeg_version=$ffmpeg3_version
0434     ffmpeg_patchlevel=$ffmpeg3_patchlevel
0435   fi
0436 elif test "$compiler" = "cross-macos"; then
0437   osxprefix=${OSXPREFIX:-/opt/osxcross/target}
0438   # e.g. x86_64-apple-darwin17
0439   cross_host=$($osxprefix/bin/o64-clang --version | grep Target | cut -d' ' -f2)
0440   _crossprefix=${cross_host}-
0441   # e.g. $osxprefix/SDK/MacOSX10.13.sdk
0442   osxsdk=($osxprefix/SDK/*.sdk)
0443 fi
0444 
0445 if [[ $target = *"libs"* ]]; then
0446 
0447 if test "$compiler" = "gcc-debug"; then
0448   export CFLAGS="-fPIC"
0449   export CXXFLAGS="-fPIC"
0450   FLAC_BUILD_OPTION="--enable-debug"
0451   ID3LIB_BUILD_OPTION="--enable-debug=minimum"
0452   AV_BUILD_OPTION="--enable-debug=3 --enable-pic --extra-ldexeflags=-pie"
0453   CMAKE_BUILD_OPTION="-DCMAKE_BUILD_TYPE=Debug"
0454 elif test "$compiler" = "gcc-self-contained"; then
0455   export CC=$gcc_self_contained_cc
0456   export CXX=$gcc_self_contained_cxx
0457   export CFLAGS="-O2 -fPIC"
0458   export CXXFLAGS="-O2 -fPIC"
0459   FLAC_BUILD_OPTION="--enable-debug"
0460   ID3LIB_BUILD_OPTION="--enable-debug=minimum"
0461   AV_BUILD_OPTION="--enable-debug=1 --enable-pic --extra-ldexeflags=-pie"
0462   CMAKE_BUILD_OPTION="-DCMAKE_BUILD_TYPE=RelWithDebInfo"
0463 else
0464   FLAC_BUILD_OPTION="--enable-debug"
0465   ID3LIB_BUILD_OPTION="--enable-debug=minimum"
0466   AV_BUILD_OPTION="--enable-debug=1"
0467   CMAKE_BUILD_OPTION="-DCMAKE_BUILD_TYPE=RelWithDebInfo"
0468 fi
0469 
0470 if ! which cmake >/dev/null; then
0471   echo "cmake not found."
0472   return 2>/dev/null
0473   exit 1
0474 fi
0475 
0476 if test $kernel = "MSYS_NT-6.1"; then
0477   kernel="MINGW"
0478   CONFIGURE_OPTIONS="--build=x86_64-w64-mingw32 --target=i686-w64-mingw32"
0479 fi
0480 if test $kernel = "MINGW"; then
0481   # Use mingw from Qt
0482   if test -n "$QTPREFIX"; then
0483     test -z "${PATH##$QTPREFIX*}" || PATH=$QTPREFIX/bin:$QTPREFIX/../../Tools/mingw492_32/bin:$QTPREFIX/../../Tools/mingw492_32/opt/bin:$PATH
0484   else
0485     echo "QTPREFIX is not set"
0486     exit 1
0487   fi
0488   CMAKE_OPTIONS="-G \"MSYS Makefiles\" -DCMAKE_INSTALL_PREFIX=/usr/local"
0489   CONFIGURE_OPTIONS+=" --prefix=/usr/local"
0490 elif test $kernel = "Darwin"; then
0491   CMAKE_OPTIONS="-G \"Unix Makefiles\""
0492 fi
0493 
0494 if test "$compiler" = "cross-mingw"; then
0495   CMAKE_OPTIONS="$CMAKE_OPTIONS -DCMAKE_TOOLCHAIN_FILE=$thisdir/mingw.cmake"
0496   CONFIGURE_OPTIONS="--host=${cross_host}"
0497   if test "$cross_host" = "x86_64-w64-mingw32"; then
0498     export CC=${_crossprefix}gcc${_crosssuffix}
0499     export CXX=${_crossprefix}g++${_crosssuffix}
0500   fi
0501 elif test "$compiler" = "cross-macos"; then
0502   CMAKE_OPTIONS="$CMAKE_OPTIONS -DCMAKE_TOOLCHAIN_FILE=$thisdir/osxcross.cmake -DCMAKE_C_FLAGS=\"-O2 -mmacosx-version-min=10.7\" -DCMAKE_CXX_FLAGS=\"-O2 -mmacosx-version-min=10.7 -fvisibility=hidden -fvisibility-inlines-hidden -stdlib=libc++\" -DCMAKE_EXE_LINKER_FLAGS=-stdlib=libc++ -DCMAKE_MODULE_LINKER_FLAGS=-stdlib=libc++ -DCMAKE_SHARED_LINKER_FLAGS=-stdlib=libc++"
0503   CONFIGURE_OPTIONS="--host=${cross_host}"
0504   export CC=${_crossprefix}clang
0505   export CXX=${_crossprefix}clang++
0506   export AR=${_crossprefix}ar
0507   export CFLAGS="-O2 $ARCH_FLAG -mmacosx-version-min=10.7"
0508   export CXXFLAGS="-O2 $ARCH_FLAG -mmacosx-version-min=10.7 -stdlib=libc++"
0509   export LDFLAGS="$ARCH_FLAG -mmacosx-version-min=10.7 -stdlib=libc++"
0510 fi
0511 
0512 if test $kernel = "MINGW" || test "$compiler" = "cross-mingw"; then
0513   # Build zlib only for Windows.
0514   ZLIB_ROOT_PATH="$thisdir/zlib-$zlib_version/inst/usr/local"
0515   TAGLIB_ZLIB_ROOT_OPTION="-DZLIB_ROOT=${ZLIB_ROOT_PATH}"
0516   CHROMAPRINT_ZLIB_OPTION="-DEXTRA_LIBS=\"-L${ZLIB_ROOT_PATH}/lib -lz\""
0517 fi
0518 
0519 if test $kernel = "Darwin"; then
0520   ARCH=$(uname -m)
0521   #ARCH=i386
0522   if test "$ARCH" = "i386"; then
0523     # To build a 32-bit Mac OS X version of Kid3 use:
0524     # cmake -G "Unix Makefiles" -DCMAKE_CXX_FLAGS="-arch i386" -DCMAKE_C_FLAGS="-arch i386" -DCMAKE_EXE_LINKER_FLAGS="-arch i386" -DQT_QMAKE_EXECUTABLE=/usr/local/Trolltech/Qt-${qt_version}-i386/bin/qmake -DCMAKE_BUILD_TYPE=Release -DWITH_FFMPEG=ON -DCMAKE_INSTALL_PREFIX= ../kid3
0525     # Building multiple architectures needs ARCH_FLAG="-arch i386 -arch x86_64",
0526     # CONFIGURE_OPTIONS="--disable-dependency-tracking", but it fails with libav.
0527     ARCH_FLAG="-arch i386"
0528     export CC=gcc
0529     export CXX=g++
0530   else
0531     ARCH_FLAG="-Xarch_x86_64"
0532   fi
0533   if [[ $(sw_vers -productVersion) = 10.1* || $(sw_vers -productVersion) = 11.* ]]; then
0534     CMAKE_OPTIONS="$CMAKE_OPTIONS -DCMAKE_C_FLAGS=\"-O2 $ARCH_FLAG -mmacosx-version-min=10.7\" -DCMAKE_CXX_FLAGS=\"-O2 $ARCH_FLAG -mmacosx-version-min=10.7 -fvisibility=hidden -fvisibility-inlines-hidden -stdlib=libc++\" -DCMAKE_EXE_LINKER_FLAGS=\"$ARCH_FLAG -stdlib=libc++\" -DCMAKE_MODULE_LINKER_FLAGS=\"$ARCH_FLAG -stdlib=libc++\" -DCMAKE_SHARED_LINKER_FLAGS=\"$ARCH_FLAG -stdlib=libc++\""
0535     export CFLAGS="-O2 $ARCH_FLAG -mmacosx-version-min=10.7"
0536     export CXXFLAGS="-O2 $ARCH_FLAG -mmacosx-version-min=10.7 -stdlib=libc++"
0537     export LDFLAGS="$ARCH_FLAG -mmacosx-version-min=10.7 -stdlib=libc++"
0538   else
0539     CMAKE_OPTIONS="$CMAKE_OPTIONS -DCMAKE_C_FLAGS=\"-O2 $ARCH_FLAG -mmacosx-version-min=10.5\" -DCMAKE_CXX_FLAGS=\"-O2 $ARCH_FLAG -mmacosx-version-min=10.5 -fvisibility=hidden -fvisibility-inlines-hidden\""
0540     export CFLAGS="-O2 $ARCH_FLAG -mmacosx-version-min=10.5"
0541     export CXXFLAGS="-O2 $ARCH_FLAG -mmacosx-version-min=10.5"
0542     export LDFLAGS="$ARCH_FLAG -mmacosx-version-min=10.5"
0543   fi
0544 fi # Darwin
0545 
0546 if which wget >/dev/null; then
0547   DOWNLOAD=wget
0548 else
0549   DOWNLOAD="curl -skfLO"
0550 fi
0551 
0552 test -d buildroot || mkdir buildroot
0553 BUILDROOT=`pwd`/buildroot/
0554 
0555 fixcmakeinst() {
0556   if test -d inst && test $kernel = "MINGW"; then
0557     cd inst
0558     if test -d prg; then
0559       rm -rf usr
0560       mv prg/msys usr
0561       rmdir prg
0562     elif test -d msys; then
0563       rm -rf usr
0564       mv msys/1.0 usr
0565       rmdir msys
0566     elif test -d MinGW; then
0567       mv MinGW usr
0568     elif test -d msys64; then
0569       rm -rf usr
0570       mv msys64/usr .
0571       rmdir msys64
0572     elif test -d msys32; then
0573       rm -rf usr
0574       mv msys32/usr .
0575       rmdir msys32
0576     fi
0577     cd ..
0578   fi
0579 }
0580 
0581 
0582 # Download sources
0583 
0584 test -d source || mkdir source
0585 cd source
0586 
0587 if test -n "${taglib_githash}"; then
0588   # Download an archive for a git hash
0589   if ! test -f taglib-${taglib_githash}.tar.gz; then
0590     $DOWNLOAD https://github.com/taglib/taglib/archive/${taglib_githash}.tar.gz
0591     mv ${taglib_githash}.tar.gz taglib-${taglib_githash}.tar.gz
0592   fi
0593 elif test -n "${taglib_version##v*}"; then
0594   test -f taglib-${taglib_version}.tar.gz ||
0595     $DOWNLOAD http://taglib.github.io/releases/taglib-${taglib_version}.tar.gz
0596 else
0597   # Download an archive for a git tag
0598   if ! test -f taglib-${taglib_version##v}.tar.gz; then
0599     $DOWNLOAD https://github.com/taglib/taglib/archive/${taglib_version}.tar.gz
0600     mv ${taglib_version}.tar.gz taglib-${taglib_version##v}.tar.gz
0601   fi
0602   taglib_version=${taglib_version##v}
0603 fi
0604 
0605 if test "$compiler" != "cross-android"; then
0606 
0607   test -f flac_${libflac_version}-${libflac_patchlevel}.debian.tar.xz ||
0608     $DOWNLOAD http://ftp.de.debian.org/debian/pool/main/f/flac/flac_${libflac_version}-${libflac_patchlevel}.debian.tar.xz
0609   test -f flac_${libflac_version}.orig.tar.xz ||
0610     $DOWNLOAD http://ftp.de.debian.org/debian/pool/main/f/flac/flac_${libflac_version}.orig.tar.xz
0611 
0612   test -f id3lib3.8.3_${id3lib_version}-${id3lib_patchlevel}.debian.tar.xz ||
0613     $DOWNLOAD http://ftp.de.debian.org/debian/pool/main/i/id3lib3.8.3/id3lib3.8.3_${id3lib_version}-${id3lib_patchlevel}.debian.tar.xz
0614   test -f id3lib3.8.3_${id3lib_version}.orig.tar.gz ||
0615     $DOWNLOAD http://ftp.de.debian.org/debian/pool/main/i/id3lib3.8.3/id3lib3.8.3_${id3lib_version}.orig.tar.gz
0616 
0617   test -f libogg_${libogg_version}-${libogg_patchlevel}.diff.gz ||
0618     $DOWNLOAD http://ftp.de.debian.org/debian/pool/main/libo/libogg/libogg_${libogg_version}-${libogg_patchlevel}.diff.gz
0619   test -f libogg_${libogg_version}.orig.tar.gz ||
0620     $DOWNLOAD http://ftp.de.debian.org/debian/pool/main/libo/libogg/libogg_${libogg_version}.orig.tar.gz
0621 
0622   test -f libvorbis_${libvorbis_version}-${libvorbis_patchlevel}.debian.tar.xz ||
0623     $DOWNLOAD http://ftp.de.debian.org/debian/pool/main/libv/libvorbis/libvorbis_${libvorbis_version}-${libvorbis_patchlevel}.debian.tar.xz
0624   test -f libvorbis_${libvorbis_version}.orig.tar.gz ||
0625     $DOWNLOAD http://ftp.de.debian.org/debian/pool/main/libv/libvorbis/libvorbis_${libvorbis_version}.orig.tar.gz
0626 
0627   if test -n "$ZLIB_ROOT_PATH"; then
0628     test -f zlib_${zlib_version}.dfsg-${zlib_patchlevel}.debian.tar.xz ||
0629       $DOWNLOAD http://ftp.de.debian.org/debian/pool/main/z/zlib/zlib_${zlib_version}.dfsg-${zlib_patchlevel}.debian.tar.xz
0630     test -f zlib_${zlib_version}.dfsg.orig.tar.gz ||
0631       $DOWNLOAD http://ftp.de.debian.org/debian/pool/main/z/zlib/zlib_${zlib_version}.dfsg.orig.tar.gz
0632   fi
0633 
0634   test -f ffmpeg_${ffmpeg_version}.orig.tar.xz ||
0635     $DOWNLOAD http://ftp.de.debian.org/debian/pool/main/f/ffmpeg/ffmpeg_${ffmpeg_version}.orig.tar.xz
0636   test -f ffmpeg_${ffmpeg_version}-${ffmpeg_patchlevel}.debian.tar.xz ||
0637     $DOWNLOAD http://ftp.de.debian.org/debian/pool/main/f/ffmpeg/ffmpeg_${ffmpeg_version}-${ffmpeg_patchlevel}.debian.tar.xz
0638 
0639   test -f chromaprint_${chromaprint_version}.orig.tar.gz ||
0640     $DOWNLOAD http://ftp.de.debian.org/debian/pool/main/c/chromaprint/chromaprint_${chromaprint_version}.orig.tar.gz
0641   test -f chromaprint_${chromaprint_version}-${chromaprint_patchlevel}.debian.tar.xz ||
0642     $DOWNLOAD http://ftp.de.debian.org/debian/pool/main/c/chromaprint/chromaprint_${chromaprint_version}-${chromaprint_patchlevel}.debian.tar.xz
0643 
0644   test -f mp4v2-${mp4v2_version}.tar.bz2 ||
0645     $DOWNLOAD https://github.com/enzo1982/mp4v2/releases/download/v${mp4v2_version}/mp4v2-${mp4v2_version}.tar.bz2
0646 
0647 fi # !cross-android
0648 
0649 if test "$compiler" = "cross-android" || test "$compiler" = "gcc-self-contained" || test "$compiler" = "gcc-debug" \
0650    || ( ( test "$compiler" = "cross-mingw" || test "$kernel" = "MINGW" ) && test "${openssl_version:0:3}" != "1.0" ); then
0651   # See http://doc.qt.io/qt-5/opensslsupport.html
0652   test -f Setenv-android.sh ||
0653     $DOWNLOAD https://wiki.openssl.org/images/7/70/Setenv-android.sh
0654   test -f openssl-${openssl_version}.tar.gz ||
0655     $DOWNLOAD https://www.openssl.org/source/openssl-${openssl_version}.tar.gz
0656 fi
0657 
0658 # Create patch files
0659 
0660 if test "$compiler" = "cross-mingw" || test "$compiler" = "cross-macos"; then
0661   if test -n "$QTBINARYDIR"; then
0662     _qt_bin_dir=$QTBINARYDIR
0663   else
0664     for d in $thisdir/qtbase5-dev-tools* /usr/lib/${HOSTTYPE/i686/i386}-linux-gnu/qt5/bin /usr/bin; do
0665       if test -x $d/moc; then
0666         _qt_bin_dir=$d
0667         break
0668       fi
0669     done
0670   fi
0671   if test -n "$QTPREFIX"; then
0672     _qt_prefix=$QTPREFIX
0673   else
0674     if test "$compiler" = "cross-mingw"; then
0675       for d in /windows/Qt/${qt_version}/mingw* /windows/Qt/Qt${qt_version}/${qt_version}/mingw* $thisdir/Qt*-mingw/${qt_version}/mingw*; do
0676         if test -d $d; then
0677           _qt_prefix=$d
0678           break
0679         fi
0680       done
0681     elif test "$compiler" = "cross-macos"; then
0682       for d in $thisdir/Qt*-mac/${qt_version}/clang_64 $HOME/Development/Qt*-mac/${qt_version}/clang_64; do
0683         if test -d $d; then
0684           _qt_prefix=$d
0685           break
0686         fi
0687       done
0688     fi
0689   fi
0690 fi # cross-mingw || cross-macos
0691 if test "$compiler" = "cross-mingw"; then
0692   if ! test -f $thisdir/mingw.cmake; then
0693     cat >$thisdir/mingw.cmake <<EOF
0694 set(QT_PREFIX ${_qt_prefix})
0695 
0696 set(CMAKE_SYSTEM_NAME Windows)
0697 set(CMAKE_C_COMPILER ${_crossprefix}gcc${_crosssuffix})
0698 set(CMAKE_CXX_COMPILER ${_crossprefix}g++${_crosssuffix})
0699 set(CMAKE_RC_COMPILER ${_crossprefix}windres)
0700 set(CMAKE_FIND_ROOT_PATH /usr/${cross_host} \${QT_PREFIX} $thisdir/buildroot/usr/local ${ZLIB_ROOT_PATH} $thisdir/ffmpeg-${ffmpeg_version}/inst/usr/local)
0701 set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
0702 set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
0703 set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
0704 
0705 EOF
0706     if test "$qt_version_major" = "6"; then
0707       _qt_libexec_dir=${_qt_bin_dir%bin}libexec
0708       cat >>$thisdir/mingw.cmake <<EOF
0709 set(QT_BINARY_DIR ${_qt_bin_dir})
0710 set(QT_LIBEXEC_DIR ${_qt_libexec_dir})
0711 set(QT_LIBRARY_DIR  \${QT_PREFIX}/lib)
0712 set(QT_QTCORE_LIBRARY   \${QT_PREFIX}/lib/libQt${qt_version_major}Core.a)
0713 set(QT_QTCORE_INCLUDE_DIR \${QT_PREFIX}/include/QtCore)
0714 set(QT_MKSPECS_DIR  \${QT_PREFIX}/mkspecs)
0715 set(QT_MOC_EXECUTABLE  \${QT_LIBEXEC_DIR}/moc)
0716 set(QT_UIC_EXECUTABLE  \${QT_LIBEXEC_DIR}/uic)
0717 
0718 foreach (_exe moc rcc uic tracegen cmake_automoc_parser qlalr lprodump lrelease-pro lupdate-pro)
0719   if (NOT TARGET Qt${qt_version_major}::\${_exe})
0720     add_executable(Qt${qt_version_major}::\${_exe} IMPORTED)
0721     set_target_properties(Qt${qt_version_major}::\${_exe} PROPERTIES
0722       IMPORTED_LOCATION \${QT_LIBEXEC_DIR}/\${_exe}
0723     )
0724   endif ()
0725 endforeach (_exe)
0726 foreach (_exe lupdate lrelease qtpaths androiddeployqt androidtestrunner lconvert)
0727   if (NOT TARGET Qt${qt_version_major}::\${_exe})
0728     add_executable(Qt${qt_version_major}::\${_exe} IMPORTED)
0729     set_target_properties(Qt${qt_version_major}::\${_exe} PROPERTIES
0730       IMPORTED_LOCATION \${QT_BINARY_DIR}/\${_exe}
0731     )
0732   endif ()
0733 endforeach (_exe)
0734 foreach (_exe qmake)
0735   if (NOT TARGET Qt${qt_version_major}::\${_exe})
0736     add_executable(Qt${qt_version_major}::\${_exe} IMPORTED)
0737     set_target_properties(Qt${qt_version_major}::\${_exe} PROPERTIES
0738       IMPORTED_LOCATION \${QT_PREFIX}/bin/\${_exe}
0739     )
0740   endif ()
0741 endforeach (_exe)
0742 EOF
0743     else
0744       cat >>$thisdir/mingw.cmake <<EOF
0745 set(QT_BINARY_DIR ${_qt_bin_dir})
0746 set(QT_LIBRARY_DIR  \${QT_PREFIX}/lib)
0747 set(QT_QTCORE_LIBRARY   \${QT_PREFIX}/lib/libQt${qt_version_major}Core.a)
0748 set(QT_QTCORE_INCLUDE_DIR \${QT_PREFIX}/include/QtCore)
0749 set(QT_MKSPECS_DIR  \${QT_PREFIX}/mkspecs)
0750 set(QT_MOC_EXECUTABLE  \${QT_BINARY_DIR}/moc)
0751 set(QT_UIC_EXECUTABLE  \${QT_BINARY_DIR}/uic)
0752 
0753 foreach (_exe moc rcc lupdate lrelease uic)
0754   if (NOT TARGET Qt${qt_version_major}::\${_exe})
0755     add_executable(Qt${qt_version_major}::\${_exe} IMPORTED)
0756     set_target_properties(Qt${qt_version_major}::\${_exe} PROPERTIES
0757       IMPORTED_LOCATION \${QT_BINARY_DIR}/\${_exe}
0758     )
0759   endif ()
0760 endforeach (_exe)
0761 EOF
0762     fi
0763   fi
0764 elif test "$compiler" = "cross-macos"; then
0765   test -z ${PATH##$osxprefix/*} || PATH=$osxprefix/bin:$osxsdk/usr/bin:$PATH
0766   if ! test -f $thisdir/osxcross.cmake; then
0767     cat >$thisdir/osxcross.cmake <<EOF
0768 if (POLICY CMP0025)
0769   cmake_policy(SET CMP0025 NEW)
0770 endif (POLICY CMP0025)
0771 
0772 set(QT_PREFIX $_qt_prefix)
0773 
0774 set (CMAKE_SYSTEM_NAME Darwin)
0775 set (CMAKE_C_COMPILER $osxprefix/lib/ccache/bin/${_crossprefix}clang)
0776 set (CMAKE_CXX_COMPILER $osxprefix/lib/ccache/bin/${_crossprefix}clang++)
0777 set (CMAKE_FIND_ROOT_PATH $osxprefix/${cross_host};$osxsdk/usr;$osxprefix/${cross_host};$osxsdk;$osxsdk/System/Library/Frameworks/OpenGL.framework/Versions/A/Headers;\${QT_PREFIX};$thisdir/buildroot/usr/local)
0778 set (CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
0779 set (CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
0780 set (CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
0781 set (CMAKE_AR:FILEPATH ${_crossprefix}ar)
0782 set (CMAKE_RANLIB:FILEPATH ${_crossprefix}ranlib)
0783 
0784 EOF
0785     if test "$qt_version_major" = "6"; then
0786       _qt_libexec_dir=${_qt_bin_dir%bin}libexec
0787       cat >>$thisdir/osxcross.cmake <<EOF
0788 set(QT_INCLUDE_DIRS_NO_SYSTEM ON)
0789 set(QT_BINARY_DIR ${_qt_bin_dir})
0790 set(QT_LIBEXEC_DIR ${_qt_libexec_dir})
0791 set(QT_LIBRARY_DIR  \${QT_PREFIX}/lib)
0792 set(Qt${qt_version_major}Core_DIR \${QT_PREFIX}/lib/cmake/Qt${qt_version_major}Core)
0793 set(QT_MKSPECS_DIR  \${QT_PREFIX}/mkspecs)
0794 set(QT_MOC_EXECUTABLE  \${QT_LIBEXEC_DIR}/moc)
0795 set(QT_UIC_EXECUTABLE  \${QT_LIBEXEC_DIR}/uic)
0796 
0797 foreach (_exe moc rcc uic tracegen cmake_automoc_parser qlalr lprodump lrelease-pro lupdate-pro)
0798   if (NOT TARGET Qt${qt_version_major}::\${_exe})
0799     add_executable(Qt${qt_version_major}::\${_exe} IMPORTED)
0800     set_target_properties(Qt${qt_version_major}::\${_exe} PROPERTIES
0801       IMPORTED_LOCATION \${QT_LIBEXEC_DIR}/\${_exe}
0802     )
0803   endif ()
0804 endforeach (_exe)
0805 foreach (_exe lupdate lrelease qtpaths androiddeployqt androidtestrunner lconvert)
0806   if (NOT TARGET Qt${qt_version_major}::\${_exe})
0807     add_executable(Qt${qt_version_major}::\${_exe} IMPORTED)
0808     set_target_properties(Qt${qt_version_major}::\${_exe} PROPERTIES
0809       IMPORTED_LOCATION \${QT_BINARY_DIR}/\${_exe}
0810     )
0811   endif ()
0812 endforeach (_exe)
0813 foreach (_exe qmake)
0814   if (NOT TARGET Qt${qt_version_major}::\${_exe})
0815     add_executable(Qt${qt_version_major}::\${_exe} IMPORTED)
0816     set_target_properties(Qt${qt_version_major}::\${_exe} PROPERTIES
0817       IMPORTED_LOCATION \${QT_PREFIX}/bin/\${_exe}
0818     )
0819   endif ()
0820 endforeach (_exe)
0821 EOF
0822     else
0823       cat >>$thisdir/osxcross.cmake <<EOF
0824 set(QT_INCLUDE_DIRS_NO_SYSTEM ON)
0825 set(QT_BINARY_DIR ${_qt_bin_dir})
0826 set(QT_LIBRARY_DIR  \${QT_PREFIX}/lib)
0827 set(Qt${qt_version_major}Core_DIR \${QT_PREFIX}/lib/cmake/Qt${qt_version_major}Core)
0828 set(QT_MKSPECS_DIR  \${QT_PREFIX}/mkspecs)
0829 set(QT_MOC_EXECUTABLE  \${QT_BINARY_DIR}/moc)
0830 set(QT_UIC_EXECUTABLE  \${QT_BINARY_DIR}/uic)
0831 
0832 foreach (_exe moc rcc lupdate lrelease uic)
0833   if (NOT TARGET Qt${qt_version_major}::\${_exe})
0834     add_executable(Qt${qt_version_major}::\${_exe} IMPORTED)
0835     set_target_properties(Qt${qt_version_major}::\${_exe} PROPERTIES
0836       IMPORTED_LOCATION \${QT_BINARY_DIR}/\${_exe}
0837     )
0838   endif ()
0839 endforeach (_exe)
0840 EOF
0841     fi
0842   fi
0843 fi # cross-mingw, cross-macos
0844 
0845 cd ..
0846 
0847 
0848 # Extract and patch sources
0849 
0850 if ! test -d taglib-${taglib_version}; then
0851   echo "### Extracting taglib"
0852 
0853   if test -n "${taglib_githash}"; then
0854     tar xzf source/taglib-${taglib_githash}.tar.gz
0855     mv taglib-${taglib_githash} taglib-${taglib_version}
0856   else
0857     tar xzf source/taglib-${taglib_version}.tar.gz
0858   fi
0859   cd taglib-${taglib_version}/
0860   if test "$cross_host" = "x86_64-w64-mingw32"; then
0861     if test -f $srcdir/packaging/patches/taglib-${taglib_githash}-win00-large_file.patch; then
0862       patch -p1 <$srcdir/packaging/patches/taglib-${taglib_githash}-win00-large_file.patch
0863     else
0864       patch -p1 <$srcdir/packaging/patches/taglib-${taglib_version}-win00-large_file.patch
0865     fi
0866   fi
0867   cd ..
0868 fi
0869 
0870 if test "$compiler" != "cross-android"; then
0871 
0872   if test -n "$ZLIB_ROOT_PATH"; then
0873     if ! test -d zlib-${zlib_version}; then
0874       echo "### Extracting zlib"
0875 
0876       tar xzf source/zlib_${zlib_version}.dfsg.orig.tar.gz
0877       cd zlib-${zlib_version}/
0878 
0879       tar xJf ../source/zlib_${zlib_version}.dfsg-${zlib_patchlevel}.debian.tar.xz || true
0880       echo Can be ignored: Cannot create symlink to debian.series
0881       for f in $(cat debian/patches/debian.series); do patch -p1 <debian/patches/$f; done
0882       cd ..
0883     fi
0884   fi
0885 
0886   if ! test -d libogg-${libogg_version}; then
0887     echo "### Extracting libogg"
0888 
0889     tar xzf source/libogg_${libogg_version}.orig.tar.gz
0890     cd libogg-${libogg_version}/
0891     gunzip -c ../source/libogg_${libogg_version}-${libogg_patchlevel}.diff.gz | patch -p1
0892     if test $kernel = "Darwin" || test "$compiler" = "cross-macos"; then
0893       patch -p1 <$srcdir/packaging/patches/libogg-1.3.4-00-mac.patch
0894     fi
0895     cd ..
0896   fi
0897 
0898   if ! test -d libvorbis-${libvorbis_version}; then
0899     echo "### Extracting libvorbis"
0900 
0901     tar xzf source/libvorbis_${libvorbis_version}.orig.tar.gz
0902     cd libvorbis-${libvorbis_version}/
0903     tar xJf ../source/libvorbis_${libvorbis_version}-${libvorbis_patchlevel}.debian.tar.xz
0904     for f in $(cat debian/patches/series); do patch -p1 <debian/patches/$f; done
0905     test -f win32/VS2010/libogg.props.orig || mv win32/VS2010/libogg.props win32/VS2010/libogg.props.orig
0906     sed "s/<LIBOGG_VERSION>1.2.0</<LIBOGG_VERSION>$libogg_version</" win32/VS2010/libogg.props.orig >win32/VS2010/libogg.props
0907     cd ..
0908   fi
0909 
0910   if ! test -d flac-${libflac_version}; then
0911     echo "### Extracting libflac"
0912 
0913     tar xJf source/flac_${libflac_version}.orig.tar.xz
0914     cd flac-${libflac_version}/
0915     tar xJf ../source/flac_${libflac_version}-${libflac_patchlevel}.debian.tar.xz
0916     for f in $(cat debian/patches/series); do patch -p1 <debian/patches/$f; done
0917     patch -p1 <$srcdir/packaging/patches/flac-1.2.1-00-size_t_max.patch
0918     if test $kernel = "Darwin"; then
0919       patch -p1 <$srcdir/packaging/patches/flac-1.2.1-mac00-fink.patch
0920       patch -p0 <patches/nasm.h.patch
0921     fi
0922     cd ..
0923   fi
0924 
0925   if ! test -d id3lib-${id3lib_version}; then
0926     echo "### Extracting id3lib"
0927 
0928     tar xzf source/id3lib3.8.3_${id3lib_version}.orig.tar.gz
0929     cd id3lib-${id3lib_version}/
0930     tar xJf ../source/id3lib3.8.3_${id3lib_version}-${id3lib_patchlevel}.debian.tar.xz
0931     for f in $(cat debian/patches/series); do patch --binary -p1 <debian/patches/$f; done
0932     patch -p1 <$srcdir/packaging/patches/id3lib-3.8.3-win00-mingw.patch
0933     patch -p1 <$srcdir/packaging/patches/id3lib-3.8.3-win01-tempfile.patch
0934     test -f makefile.win32.orig || mv makefile.win32 makefile.win32.orig
0935     sed 's/-W3 -WX -GX/-W3 -EHsc/; s/-MD -D "WIN32" -D "_DEBUG"/-MDd -D "WIN32" -D "_DEBUG"/' makefile.win32.orig >makefile.win32
0936     cd ..
0937   fi
0938 
0939   if ! test -d ffmpeg-${ffmpeg_version}; then
0940     echo "### Extracting ffmpeg"
0941 
0942     tar xJf source/ffmpeg_${ffmpeg_version}.orig.tar.xz || true
0943     cd ffmpeg-${ffmpeg_version}/
0944     tar xJf ../source/ffmpeg_${ffmpeg_version}-${ffmpeg_patchlevel}.debian.tar.xz || true
0945     for f in $(cat debian/patches/series); do patch -p1 <debian/patches/$f; done
0946     cd ..
0947   fi
0948 
0949   if ! test -d chromaprint-${chromaprint_version}; then
0950     echo "### Extracting chromaprint"
0951 
0952     tar xzf source/chromaprint_${chromaprint_version}.orig.tar.gz
0953     cd chromaprint-${chromaprint_version}/
0954     tar xJf ../source/chromaprint_${chromaprint_version}-${chromaprint_patchlevel}.debian.tar.xz
0955     for f in $(cat debian/patches/series); do patch -p1 <debian/patches/$f; done
0956     cd ..
0957   fi
0958 
0959   if ! test -d mp4v2-${mp4v2_version}; then
0960     echo "### Extracting mp4v2"
0961 
0962     tar xjf source/mp4v2-${mp4v2_version}.tar.bz2
0963   fi
0964 
0965 fi # !cross-android
0966 
0967 if test "$compiler" = "cross-android"; then
0968 
0969   if ! test -d openssl-${openssl_version}; then
0970     echo "### Extracting openssl"
0971 
0972     tar xzf source/openssl-${openssl_version}.tar.gz
0973     cp source/Setenv-android.sh openssl-${openssl_version}/
0974     cd openssl-${openssl_version}/
0975     sed -i 's/\r$//' Setenv-android.sh
0976     test -n "$ANDROID_NDK_ROOT" && \
0977       sed -i "s#^ANDROID_NDK_ROOT=.*#ANDROID_NDK_ROOT=$ANDROID_NDK_ROOT#" \
0978         Setenv-android.sh
0979     chmod +x Setenv-android.sh
0980     patch -p0 <$srcdir/packaging/patches/openssl-1.1.1-android00-setenv.patch
0981     cd ..
0982   fi
0983 
0984 elif test "$compiler" = "gcc-self-contained" || test "$compiler" = "gcc-debug" \
0985      || ( ( test "$compiler" = "cross-mingw" || test "$kernel" = "MINGW" ) && test "${openssl_version:0:3}" != "1.0" ); then
0986 
0987   if ! test -d openssl-${openssl_version}; then
0988     echo "### Extracting openssl"
0989     tar xzf source/openssl-${openssl_version}.tar.gz
0990   fi
0991 
0992 fi # cross-android
0993 
0994 # Build from sources
0995 
0996 test -d bin || mkdir bin
0997 
0998 _chocoInstall=${ChocolateyInstall//\\/\/}
0999 _chocoInstall=${_chocoInstall/C:/\/c}
1000 for d in "$DOCBOOK_XSL_DIR" /usr/share/xml/docbook/stylesheet/nwalsh /usr/share/xml/docbook/xsl-stylesheets-* /usr/local/Cellar/docbook-xsl/*/docbook-xsl /opt/local/share/xsl/docbook-xsl $_chocoInstall/lib/docbook-bundle/docbook-xsl-*; do
1001   if test -e $d/xhtml/docbook.xsl; then
1002     _docbook_xsl_dir=$d
1003     break
1004   fi
1005 done
1006 
1007 if test "$compiler" = "cross-android"; then
1008 
1009   _java_root=${JAVA_HOME:-/usr/lib/jvm/java-8-openjdk-amd64}
1010   _android_sdk_root=${ANDROID_SDK_ROOT:-/opt/android/sdk}
1011   _android_ndk_root=${ANDROID_NDK_ROOT:-$_android_sdk_root/ndk-bundle}
1012   _android_platform=${ANDROID_PLATFORM:-23}
1013   _android_ccache=$(which ccache || true)
1014   _android_qt_root=${QTPREFIX:-/opt/qt5/5.9.7/android_armv7}
1015   _android_toolchain_cmake=$_android_ndk_root/build/cmake/android.toolchain.cmake
1016   test -f $_android_toolchain_cmake ||
1017     _android_toolchain_cmake=$srcdir/android/qt-android-cmake/toolchain/android.toolchain.cmake
1018   test -f $_android_qt_root/bin/qmake ||
1019     _android_qt_root=/opt/qt5/5.9.7/android_armv7
1020   if test -z "${_android_qt_root%%*x86}"; then
1021     _android_abi=x86
1022     _android_prefix=i686-linux-android
1023   else
1024     _android_abi=armeabi-v7a
1025     _android_prefix=arm-linux-androideabi
1026   fi
1027   if test ! -d openssl-${openssl_version}/inst; then
1028     echo "### Building OpenSSL"
1029 
1030     cd openssl-${openssl_version}/
1031     if test "$_android_abi" = "x86"; then
1032       sed -i 's/^_ANDROID_EABI=.*$/_ANDROID_EABI=x86-4.9/; s/^_ANDROID_ARCH=.*$/_ANDROID_ARCH=arch-x86/' Setenv-android.sh
1033     else
1034       sed -i 's/^_ANDROID_EABI=.*$/_ANDROID_EABI=arm-linux-androideabi-4.9/; s/^_ANDROID_ARCH=.*$/_ANDROID_ARCH=arch-arm/' Setenv-android.sh
1035     fi
1036     sed -i "s#^_ANDROID_NDK=.*#ANDROID_NDK_ROOT=$_android_ndk_root#" Setenv-android.sh
1037     sed -i '/FIPS_SIG location/,/^fi$/ d' Setenv-android.sh
1038     if test -d $_android_ndk_root/toolchains/llvm; then
1039       sed -i 's/^_ANDROID_EABI=.*$/_ANDROID_EABI=llvm/' Setenv-android.sh
1040     fi
1041     . ./Setenv-android.sh
1042     if test "${openssl_version:0:3}" = "1.0"; then
1043       ./Configure shared android
1044     else
1045       ANDROID_NDK_HOME=$ANDROID_NDK_ROOT ./Configure shared android-armeabi
1046     fi
1047     if test -d $_android_ndk_root/toolchains/llvm; then
1048       if test "$_android_abi" = "x86"; then
1049         sed -i 's/^CC=.*$/CC= i686-linux-android16-clang/; s/ -mandroid//' Makefile
1050       else
1051         sed -i 's/^CC=.*$/CC= armv7a-linux-androideabi16-clang/; s/ -mandroid//' Makefile
1052       fi
1053     fi
1054 
1055     if test "${openssl_version:0:3}" = "1.0"; then
1056       make CALC_VERSIONS="SHLIB_COMPAT=; SHLIB_SOVER=" build_libs
1057       _ssl_lib_suffix=.so
1058     else
1059       make ANDROID_NDK_HOME=$ANDROID_NDK_ROOT SHLIB_VERSION_NUMBER= SHLIB_EXT=_1_1.so build_libs
1060       _ssl_lib_suffix=_1_1.so
1061     fi
1062     mkdir -p inst/usr/local/lib
1063     cp --dereference libssl${_ssl_lib_suffix} libcrypto${_ssl_lib_suffix} inst/usr/local/lib/
1064     $_android_prefix-strip -s inst/usr/local/lib/*.so
1065     cd inst
1066     tar czf ../../bin/openssl-${openssl_version}.tgz usr
1067     cd ../..
1068     tar xmzf bin/openssl-${openssl_version}.tgz -C $BUILDROOT
1069   fi
1070 
1071   if ! test -f $BUILDROOT/usr/local/lib/libtag.a; then
1072     echo "### Building taglib"
1073 
1074     cd taglib-${taglib_version}/
1075     cmake -DBUILD_SHARED_LIBS=OFF -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=$BUILDROOT/usr/local -DANDROID_NDK=$_android_ndk_root -DANDROID_ABI=$_android_abi -DCMAKE_TOOLCHAIN_FILE=$_android_toolchain_cmake -DANDROID_PLATFORM=$_android_platform -DANDROID_CCACHE=$_android_ccache -DCMAKE_MAKE_PROGRAM=make
1076     make install
1077     cd ..
1078   fi
1079 
1080   if ! test -d kid3; then
1081     echo "### Creating kid3 build directory"
1082     mkdir kid3
1083     test -e $HOME/Development/ufleisch-release-key.keystore && cp -s $HOME/Development/ufleisch-release-key.keystore kid3/
1084     cat >kid3/run-cmake.sh <<EOF
1085 #!/bin/bash
1086 _java_root=$_java_root
1087 _android_sdk_root=$_android_sdk_root
1088 _android_ndk_root=$_android_ndk_root
1089 _android_platform=$_android_platform
1090 _android_ccache=$_android_ccache
1091 _android_abi=$_android_abi
1092 _android_qt_root=$_android_qt_root
1093 _android_keystore_path=\$(pwd)/ufleisch-release-key.keystore
1094 _android_keystore_alias=ufleisch_android
1095 if ! test -f "\$_android_keystore_path"; then
1096   _android_keystore_path=
1097   _android_keystore_alias=
1098 fi
1099 _buildprefix=\$(cd ..; pwd)/buildroot/usr/local
1100 # Pass -DQT_ANDROID_USE_GRADLE=ON to use Gradle instead of ANT.
1101 cmake -DJAVA_HOME=\$_java_root -DQT_ANDROID_SDK_ROOT=\$_android_sdk_root -DANDROID_NDK=\$_android_ndk_root -DAPK_ALL_TARGET=OFF -DANDROID_ABI=\$_android_abi -DANDROID_EXTRA_LIBS_DIR=\$_buildprefix/lib -DANDROID_KEYSTORE_PATH=\$_android_keystore_path -DANDROID_KEYSTORE_ALIAS=\$_android_keystore_alias -DCMAKE_TOOLCHAIN_FILE=$_android_toolchain_cmake -DANDROID_PLATFORM=$_android_platform -DANDROID_CCACHE=$_android_ccache -DQT_QMAKE_EXECUTABLE=\$_android_qt_root/bin/qmake -DCMAKE_BUILD_TYPE=Release -DDOCBOOK_XSL_DIR=${_docbook_xsl_dir} -DPYTHON_EXECUTABLE=/usr/bin/python -DXSLTPROC=/usr/bin/xsltproc -DGZIP_EXECUTABLE=/bin/gzip -DTAGLIBCONFIG_EXECUTABLE=\$_buildprefix/bin/taglib-config -DCMAKE_MAKE_PROGRAM=make $srcdir
1102 EOF
1103     chmod +x kid3/run-cmake.sh
1104   fi
1105 
1106 else #  cross-android
1107 
1108   if test "$1" = "clean"; then
1109     for d in zlib-${zlib_version} libogg-${libogg_version} \
1110              libvorbis-${libvorbis_version} flac-${libflac_version} \
1111              id3lib-${id3lib_version} taglib-${taglib_version} \
1112              ffmpeg-${ffmpeg_version} chromaprint-${chromaprint_version} \
1113              mp4v2-${mp4v2_version}; do
1114       test -d $d/inst && rm -rf $d/inst
1115     done
1116   fi
1117 
1118   if ( test "$compiler" = "gcc-self-contained" || test "$compiler" = "gcc-debug" ) && test ! -d openssl-${openssl_version}/inst; then
1119     echo "### Building OpenSSL"
1120 
1121     cd openssl-${openssl_version}
1122     ./Configure shared enable-ec_nistp_64_gcc_128 linux-x86_64 -Wa,--noexecstack
1123     make depend || true
1124     make build_libs
1125     mkdir -p inst/usr/local/ssl
1126     cp --dereference libssl.so libcrypto.so inst/usr/local/ssl/
1127     strip -s inst/usr/local/ssl/*.so
1128     cd inst
1129     tar czf ../../bin/openssl-${openssl_version}.tgz usr
1130     cd ../..
1131     tar xmzf bin/openssl-${openssl_version}.tgz -C $BUILDROOT
1132 
1133   elif ( ( test "$compiler" = "cross-mingw" || test "$kernel" = "MINGW" ) && test "${openssl_version:0:3}" != "1.0" ) \
1134        && test ! -d openssl-${openssl_version}/inst; then
1135     echo "### Building OpenSSL"
1136 
1137     cd openssl-${openssl_version}
1138     if test "$cross_host" = "x86_64-w64-mingw32" || [[ $(uname) =~ ^MINGW64 ]]; then
1139       _target=mingw64
1140     else
1141       _target=mingw
1142     fi
1143     if test -z "${cross_host}"; then
1144       _crossprefix=
1145     fi
1146     if test "$cross_host" = "x86_64-w64-mingw32"; then
1147       _cctmp=$CC
1148       CC=gcc${_crosssuffix}
1149     fi
1150     ./Configure shared enable-ec_nistp_64_gcc_128 $_target --cross-compile-prefix=$_crossprefix
1151     make depend || true
1152     make build_libs
1153     if test "$cross_host" = "x86_64-w64-mingw32"; then
1154       CC=$_cctmp
1155     fi
1156     mkdir -p inst/usr/local/ssl
1157     cp lib{ssl,crypto}*.dll inst/usr/local/ssl/
1158     ${_crossprefix}strip -s inst/usr/local/ssl/*.dll
1159     cd inst
1160     tar czf ../../bin/openssl-${openssl_version}.tgz usr
1161     cd ../..
1162     tar xmzf bin/openssl-${openssl_version}.tgz -C $BUILDROOT
1163   fi
1164 
1165   if test -n "$ZLIB_ROOT_PATH" && test ! -d zlib-${zlib_version}/inst; then
1166     echo "### Building zlib"
1167 
1168     cd zlib-${zlib_version}/
1169     if test $kernel = "MINGW"; then
1170       make -f win32/Makefile.gcc
1171       make install -f win32/Makefile.gcc INCLUDE_PATH=`pwd`/inst/usr/local/include LIBRARY_PATH=`pwd`/inst/usr/local/lib BINARY_PATH=`pwd`/inst/usr/local/bin
1172     elif test "$compiler" = "cross-mingw"; then
1173       make -f win32/Makefile.gcc LOC=-g PREFIX=${_crossprefix}
1174       make install -f win32/Makefile.gcc INCLUDE_PATH=`pwd`/inst/usr/local/include LIBRARY_PATH=`pwd`/inst/usr/local/lib BINARY_PATH=`pwd`/inst/usr/local/bin
1175     else
1176       CFLAGS="$CFLAGS -g -O3 -Wall -DNO_FSEEKO" ./configure --static
1177       sed 's/LIBS=$(STATICLIB) $(SHAREDLIB) $(SHAREDLIBV)/LIBS=$(STATICLIB)/' Makefile >Makefile.inst
1178       mkdir -p inst/usr/local
1179       make install -f Makefile.inst prefix=`pwd`/inst/usr/local
1180     fi
1181     cd inst
1182     tar czf ../../bin/zlib-${zlib_version}.tgz usr
1183     cd ../..
1184     tar xmzf bin/zlib-${zlib_version}.tgz -C $BUILDROOT
1185   fi
1186 
1187   if test ! -d libogg-${libogg_version}/inst; then
1188     echo "### Building libogg"
1189 
1190     cd libogg-${libogg_version}/
1191     test -f Makefile || ./configure --enable-shared=no --enable-static=yes $CONFIGURE_OPTIONS
1192     make
1193     mkdir -p inst
1194     make install DESTDIR=`pwd`/inst
1195     cd inst
1196     tar czf ../../bin/libogg-${libogg_version}.tgz usr
1197     cd ../..
1198     tar xmzf bin/libogg-${libogg_version}.tgz -C $BUILDROOT
1199   fi
1200 
1201   if test ! -d libvorbis-${libvorbis_version}/inst; then
1202     echo "### Building libvorbis"
1203 
1204     cd libvorbis-${libvorbis_version}/
1205     if test "$compiler" = "cross-mingw"; then
1206       test -f Makefile || CFLAGS="$CFLAGS -g" PKG_CONFIG= ./configure --enable-shared=no --enable-static=yes --with-ogg=$thisdir/libogg-$libogg_version/inst/usr/local $CONFIGURE_OPTIONS
1207     else
1208       test -f Makefile || CFLAGS="$CFLAGS -g" ./configure --enable-shared=no --enable-static=yes --with-ogg=$thisdir/libogg-$libogg_version/inst/usr/local $CONFIGURE_OPTIONS
1209     fi
1210     make
1211     mkdir -p inst
1212     make install DESTDIR=`pwd`/inst
1213     cd inst
1214     tar czf ../../bin/libvorbis-${libvorbis_version}.tgz usr
1215     cd ../..
1216     tar xmzf bin/libvorbis-${libvorbis_version}.tgz -C $BUILDROOT
1217   fi
1218 
1219   if test ! -d flac-${libflac_version}/inst; then
1220     echo "### Building libflac"
1221 
1222     cd flac-${libflac_version}/
1223     autoreconf -i
1224     configure_args="--enable-shared=no --enable-static=yes --with-ogg=$thisdir/libogg-$libogg_version/inst/usr/local --disable-thorough-tests --disable-doxygen-docs --disable-xmms-plugin $FLAC_BUILD_OPTION $CONFIGURE_OPTIONS"
1225     if test $kernel = "Darwin"; then
1226       configure_args="$configure_args --disable-asm-optimizations"
1227     fi
1228     test -f Makefile || ./configure $configure_args
1229     # On msys32, an error "changed before entering" occurred, can be fixed by
1230     # modifying /usr/share/perl5/core_perl/File/Path.pm
1231     # my $Need_Stat_Check = !($^O eq 'MSWin32' || $^O eq 'msys');
1232     make V=1
1233     mkdir -p inst
1234     make install DESTDIR=`pwd`/inst
1235     cd inst
1236     tar czf ../../bin/flac-${libflac_version}.tgz usr
1237     cd ../..
1238     tar xmzf bin/flac-${libflac_version}.tgz -C $BUILDROOT
1239   fi
1240 
1241   if test ! -d id3lib-${id3lib_version}/inst; then
1242     echo "### Building id3lib"
1243 
1244     cd id3lib-${id3lib_version}/
1245     if test $kernel = "MINGW" || test "$compiler" = "cross-mingw"; then
1246       sed -i 's/^@ID3_NEEDDEBUG_TRUE@ID3_DEBUG_LIBS = -lcwd -lbfd -liberty$/@ID3_NEEDDEBUG_TRUE@ID3_DEBUG_LIBS =/' examples/Makefile.in
1247     fi
1248     autoconf
1249     configure_args="--enable-shared=no --enable-static=yes $ID3LIB_BUILD_OPTION $CONFIGURE_OPTIONS"
1250     if test $kernel = "MINGW"; then
1251       configure_args="$configure_args --build=mingw32"
1252     fi
1253     test -f Makefile || CPPFLAGS=-I/usr/local/include LDFLAGS="$LDFLAGS -L/usr/local/lib" ./configure $configure_args
1254     SED=sed make
1255     mkdir -p inst
1256     make install DESTDIR=`pwd`/inst
1257     cd inst
1258     tar czf ../../bin/id3lib-${id3lib_version}.tgz usr
1259     cd ../..
1260     tar xmzf bin/id3lib-${id3lib_version}.tgz -C $BUILDROOT
1261   fi
1262 
1263   if test ! -d taglib-${taglib_version}/inst; then
1264     echo "### Building taglib"
1265 
1266     cd taglib-${taglib_version}/
1267     test -f Makefile || eval cmake -DINCLUDE_DIRECTORIES=/usr/local/include -DLINK_DIRECTORIES=/usr/local/lib -DBUILD_SHARED_LIBS=OFF $TAGLIB_ZLIB_ROOT_OPTION $CMAKE_BUILD_OPTION $CMAKE_OPTIONS
1268     make VERBOSE=1
1269     mkdir -p inst
1270     make install DESTDIR=`pwd`/inst
1271     fixcmakeinst
1272     cd inst
1273     tar czf ../../bin/taglib-${taglib_version}.tgz usr
1274     cd ../..
1275     tar xmzf bin/taglib-${taglib_version}.tgz -C $BUILDROOT
1276   fi
1277 
1278   if test ! -d ffmpeg-${ffmpeg_version}/inst; then
1279     echo "### Building ffmpeg"
1280 
1281     cd ffmpeg-${ffmpeg_version}
1282     # configure needs yasm and pr
1283     # On msys, make >= 3.81 is needed.
1284     # Most options taken from
1285     # http://oxygene.sk/lukas/2011/04/minimal-audio-only-ffmpeg-build-with-mingw32/
1286     # Disable-sse avoids a SEGFAULT under MinGW.
1287     # Later versions (tested with libav-HEAD-5d2be71) do not have
1288     # --enable-ffmpeg and additionally need --disable-mmx --disable-mmxext.
1289     # The two --disable-hwaccel were added for MinGW-builds GCC 4.7.2.
1290     # The --extra-cflags=-march=i486 is to avoid error "Threading is enabled, but
1291     # there is no implementation of atomic operations available", libav bug 471.
1292     if test "$compiler" = "cross-mingw"; then
1293       # mkstemp is not available when building on Windows
1294       sed -i 's/check_func  mkstemp/disable  mkstemp/' ./configure
1295       sed -i 's/^\(.*-Werror=missing-prototypes\)/#\1/' ./configure
1296       AV_CONFIGURE_OPTIONS="--cross-prefix=${_crossprefix} --arch=x86 --target-os=mingw32 --sysinclude=/usr/${cross_host}/include"
1297       if test -n "${cross_host##x86_64*}"; then
1298         AV_CONFIGURE_OPTIONS="$AV_CONFIGURE_OPTIONS --extra-cflags=-march=i486"
1299       else
1300         AV_CONFIGURE_OPTIONS="$AV_CONFIGURE_OPTIONS --extra-ldflags=-lbcrypt"
1301       fi
1302       test -n "$CC" && AV_CONFIGURE_OPTIONS="$AV_CONFIGURE_OPTIONS --cc=$CC"
1303       test -n "$CXX" && AV_CONFIGURE_OPTIONS="$AV_CONFIGURE_OPTIONS --cxx=$CXX"
1304     elif test $kernel = "MINGW"; then
1305       # mkstemp is not available when building with mingw from Qt
1306       sed -i 's/check_func  mkstemp/disable  mkstemp/' ./configure
1307       if ! [[ $(uname) =~ ^MINGW64 ]]; then
1308         AV_CONFIGURE_OPTIONS="--extra-cflags=-march=i486"
1309       else
1310         AV_CONFIGURE_OPTIONS="--extra-ldflags=-lbcrypt"
1311       fi
1312       if test $(uname) = "MSYS_NT-6.1"; then
1313         AV_CONFIGURE_OPTIONS="$AV_CONFIGURE_OPTIONS --target-os=mingw32"
1314       fi
1315     elif test "$compiler" = "cross-macos"; then
1316       AV_CONFIGURE_OPTIONS="--disable-iconv --enable-cross-compile --cross-prefix=${_crossprefix} --arch=x86 --target-os=darwin --cc=$CC --cxx=$CXX"
1317     elif test "$compiler" = "gcc-debug" || test "$compiler" = "gcc-self-contained"; then
1318       test -n "$CC" && AV_CONFIGURE_OPTIONS="$AV_CONFIGURE_OPTIONS --cc=$CC"
1319       test -n "$CXX" && AV_CONFIGURE_OPTIONS="$AV_CONFIGURE_OPTIONS --cxx=$CXX"
1320     fi
1321     if test $kernel = "Darwin" || test $kernel = "MINGW"; then
1322       AV_CONFIGURE_OPTIONS="$AV_CONFIGURE_OPTIONS --disable-iconv"
1323     fi
1324     AV_CONFIGURE_OPTIONS="$AV_CONFIGURE_OPTIONS $AV_BUILD_OPTION"
1325     ./configure \
1326       --disable-shared \
1327       --enable-static \
1328       --disable-avdevice \
1329       --disable-avfilter \
1330       --disable-pthreads \
1331       --disable-swscale \
1332       --disable-network \
1333       --disable-muxers \
1334       --disable-demuxers \
1335       --disable-sse \
1336       --disable-doc \
1337       --enable-rdft \
1338       --enable-demuxer=aac \
1339       --enable-demuxer=ac3 \
1340       --enable-demuxer=ape \
1341       --enable-demuxer=asf \
1342       --enable-demuxer=flac \
1343       --enable-demuxer=matroska_audio \
1344       --enable-demuxer=mp3 \
1345       --enable-demuxer=mpc \
1346       --enable-demuxer=mov \
1347       --enable-demuxer=mpc8 \
1348       --enable-demuxer=ogg \
1349       --enable-demuxer=tta \
1350       --enable-demuxer=wav \
1351       --enable-demuxer=wv \
1352       --disable-bsfs \
1353       --disable-filters \
1354       --disable-parsers \
1355       --enable-parser=aac \
1356       --enable-parser=ac3 \
1357       --enable-parser=mpegaudio \
1358       --disable-protocols \
1359       --enable-protocol=file \
1360       --disable-indevs \
1361       --disable-outdevs \
1362       --disable-encoders \
1363       --disable-decoders \
1364       --enable-decoder=aac \
1365       --enable-decoder=ac3 \
1366       --enable-decoder=alac \
1367       --enable-decoder=ape \
1368       --enable-decoder=flac \
1369       --enable-decoder=mp1 \
1370       --enable-decoder=mp2 \
1371       --enable-decoder=mp3 \
1372       --enable-decoder=mpc7 \
1373       --enable-decoder=mpc8 \
1374       --enable-decoder=tta \
1375       --enable-decoder=vorbis \
1376       --enable-decoder=wavpack \
1377       --enable-decoder=wmav1 \
1378       --enable-decoder=wmav2 \
1379       --enable-decoder=pcm_alaw \
1380       --enable-decoder=pcm_dvd \
1381       --enable-decoder=pcm_f32be \
1382       --enable-decoder=pcm_f32le \
1383       --enable-decoder=pcm_f64be \
1384       --enable-decoder=pcm_f64le \
1385       --enable-decoder=pcm_s16be \
1386       --enable-decoder=pcm_s16le \
1387       --enable-decoder=pcm_s16le_planar \
1388       --enable-decoder=pcm_s24be \
1389       --enable-decoder=pcm_daud \
1390       --enable-decoder=pcm_s24le \
1391       --enable-decoder=pcm_s32be \
1392       --enable-decoder=pcm_s32le \
1393       --enable-decoder=pcm_s8 \
1394       --enable-decoder=pcm_u16be \
1395       --enable-decoder=pcm_u16le \
1396       --enable-decoder=pcm_u24be \
1397       --enable-decoder=pcm_u24le \
1398       --enable-decoder=rawvideo \
1399       --disable-videotoolbox \
1400       --disable-vaapi \
1401       --disable-vdpau \
1402       --disable-hwaccel=h264_dxva2 \
1403       --disable-hwaccel=mpeg2_dxva2 $AV_CONFIGURE_OPTIONS
1404     make V=1
1405     mkdir -p inst
1406     make install DESTDIR=`pwd`/inst
1407     cd inst
1408     tar czf ../../bin/ffmpeg-${ffmpeg_version}.tgz usr
1409     cd ../..
1410     tar xmzf bin/ffmpeg-${ffmpeg_version}.tgz -C $BUILDROOT
1411   fi
1412 
1413   if test ! -d chromaprint-${chromaprint_version}/inst; then
1414     echo "### Building chromaprint"
1415 
1416     # The zlib library path was added for MinGW-builds GCC 4.7.2.
1417     cd chromaprint-${chromaprint_version}/
1418     test -f Makefile || eval cmake -DBUILD_SHARED_LIBS=OFF -DBUILD_TESTS=OFF $CHROMAPRINT_ZLIB_OPTION -DFFMPEG_ROOT=$thisdir/ffmpeg-${ffmpeg_version}/inst/usr/local $CMAKE_BUILD_OPTION $CMAKE_OPTIONS
1419     make VERBOSE=1
1420     mkdir -p inst
1421     make install DESTDIR=`pwd`/inst
1422     fixcmakeinst
1423     cd inst
1424     tar czf ../../bin/chromaprint-${chromaprint_version}.tgz usr
1425     cd ../..
1426     tar xmzf bin/chromaprint-${chromaprint_version}.tgz -C $BUILDROOT
1427   fi
1428 
1429   if test ! -d mp4v2-${mp4v2_version}/inst; then
1430     echo "### Building mp4v2"
1431 
1432     cd mp4v2-${mp4v2_version}/
1433     test -f Makefile || eval cmake -DBUILD_SHARED=OFF -DBUILD_UTILS=OFF -DBUILD_SHARED_LIBS=OFF $CMAKE_BUILD_OPTION $CMAKE_OPTIONS
1434     make VERBOSE=1
1435     mkdir -p inst
1436     make install DESTDIR=`pwd`/inst
1437     fixcmakeinst
1438     cd inst
1439     tar czf ../../bin/mp4v2-${mp4v2_version}.tgz usr
1440     cd ../..
1441     tar xmzf bin/mp4v2-${mp4v2_version}.tgz -C $BUILDROOT
1442   fi
1443 
1444 
1445   if ! test -d kid3; then
1446     echo "### Creating kid3 build directory"
1447 
1448     mkdir kid3
1449     if test "$compiler" = "cross-mingw"; then
1450       cat >kid3/run-cmake.sh <<EOF
1451 #!/bin/bash
1452 cmake -GNinja $CMAKE_BUILD_OPTION -DCMAKE_TOOLCHAIN_FILE=$thisdir/mingw.cmake -DCMAKE_INSTALL_PREFIX= -DWITH_FFMPEG=ON -DWITH_MP4V2=ON -DCMAKE_CXX_FLAGS="-g -O2 -DMP4V2_USE_STATIC_LIB" -DDOCBOOK_XSL_DIR=${_docbook_xsl_dir} ../../kid3
1453 EOF
1454     elif test "$compiler" = "cross-macos"; then
1455       cat >kid3/run-cmake.sh <<EOF
1456 #!/bin/bash
1457 test -z \${PATH##$osxprefix/*} || PATH=$osxprefix/bin:$osxsdk/usr/bin:\$PATH
1458 cmake -GNinja $CMAKE_BUILD_OPTION -DCMAKE_TOOLCHAIN_FILE=$thisdir/osxcross.cmake -DCMAKE_INSTALL_PREFIX= -DWITH_FFMPEG=ON -DWITH_MP4V2=ON -DCMAKE_CXX_FLAGS="-g -O2 -DMP4V2_USE_STATIC_LIB" -DDOCBOOK_XSL_DIR=${_docbook_xsl_dir} ../../kid3
1459 EOF
1460     elif test "$compiler" = "gcc-self-contained"; then
1461       if test -n "$QTPREFIX"; then
1462         _qt_prefix=$QTPREFIX
1463       else
1464         for d in /opt/qt5/${qt_version}/gcc_64 /opt/qt5/Qt${qt_version}/${qt_version}/gcc_64 $thisdir/Qt*-linux/${qt_version}/gcc_64; do
1465           if test -d $d; then
1466             _qt_prefix=$d
1467             break
1468           fi
1469         done
1470       fi
1471       taglib_config_version=$taglib_version
1472       taglib_config_version=${taglib_config_version%beta*}
1473       cat >kid3/run-cmake.sh <<EOF
1474 #!/bin/bash
1475 BUILDPREFIX=\$(cd ..; pwd)/buildroot/usr/local
1476 export PKG_CONFIG_PATH=\$BUILDPREFIX/lib/pkgconfig
1477 cmake -GNinja -DCMAKE_CXX_COMPILER=${gcc_self_contained_cxx} -DCMAKE_C_COMPILER=${gcc_self_contained_cc} -DQT_QMAKE_EXECUTABLE=${_qt_prefix}/bin/qmake -DWITH_READLINE=OFF -DBUILD_SHARED_LIBS=ON -DLINUX_SELF_CONTAINED=ON -DWITH_TAGLIB=OFF -DHAVE_TAGLIB=1 -DTAGLIB_LIBRARIES:STRING="-L\$BUILDPREFIX/lib -ltag -lz" -DTAGLIB_CFLAGS:STRING="-I\$BUILDPREFIX/include/taglib -I\$BUILDPREFIX/include -DTAGLIB_STATIC" -DTAGLIB_VERSION:STRING="${taglib_config_version}" -DWITH_QML=ON -DCMAKE_CXX_FLAGS_DEBUG:STRING="-g -DID3LIB_LINKOPTION=1 -DFLAC__NO_DLL" -DCMAKE_INCLUDE_PATH=\$BUILDPREFIX/include -DCMAKE_LIBRARY_PATH=\$BUILDPREFIX/lib -DCMAKE_PROGRAM_PATH=\$BUILDPREFIX/bin -DWITH_FFMPEG=ON -DFFMPEG_ROOT=\$BUILDPREFIX -DWITH_MP4V2=ON $CMAKE_BUILD_OPTION -DWITH_APPS="Qt;CLI" -DCMAKE_INSTALL_PREFIX= -DWITH_BINDIR=. -DWITH_DATAROOTDIR=. -DWITH_DOCDIR=. -DWITH_TRANSLATIONSDIR=. -DWITH_LIBDIR=. -DWITH_PLUGINSDIR=./plugins ../../kid3
1478 EOF
1479     elif test $kernel = "Darwin"; then
1480       _qt_prefix=${QTPREFIX:-/usr/local/Trolltech/Qt${qt_version}/${qt_version}/clang_64}
1481       cat >kid3/run-cmake.sh <<EOF
1482 #!/bin/bash
1483 INCLUDE=../buildroot/usr/local/include LIB=../buildroot/usr/local/lib cmake -GNinja -DCMAKE_BUILD_TYPE=RelWithDebInfo -DQT_QMAKE_EXECUTABLE=${_qt_prefix}/bin/qmake -DCMAKE_INSTALL_PREFIX= -DWITH_FFMPEG=ON -DWITH_MP4V2=ON -DWITH_DOCBOOKDIR=${_docbook_xsl_dir} ../../kid3
1484 EOF
1485     elif test $kernel = "MINGW"; then
1486       _qtToolsMingw=($QTPREFIX/../../Tools/mingw*)
1487       _qtToolsMingw=$(realpath $_qtToolsMingw)
1488       cat >kid3/run-cmake.sh <<EOF
1489 #!/bin/bash
1490 INCLUDE=../buildroot/usr/local/include LIB=../buildroot/usr/local/lib cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=RelWithDebInfo -DQT_QMAKE_EXECUTABLE=${QTPREFIX}/bin/qmake -DCMAKE_INSTALL_PREFIX= -DWITH_FFMPEG=ON -DWITH_MP4V2=ON -DWITH_DOCBOOKDIR=${_docbook_xsl_dir:-$HOME/prg/docbook-xsl-1.72.0} ../../kid3
1491 EOF
1492       _qtPrefixWin=${QTPREFIX//\//\\}
1493       _qtPrefixWin=${_qtPrefixWin/\\c/C:}
1494       _qtToolsMingwWin=${_qtToolsMingw//\//\\}
1495       _qtToolsMingwWin=${_qtToolsMingwWin/\\c/C:}
1496       _docbookXslDirWin=${_docbook_xsl_dir//\//\\}
1497       _docbookXslDirWin=${_docbookXslDirWin/\\c/C:}
1498       cat >kid3/build.bat <<EOF
1499 set INCLUDE=../buildroot/usr/local/include
1500 set LIB=../buildroot/usr/local/lib
1501 echo ;%PATH%; | find /C /I ";$_qtPrefixWin\bin;"
1502 if errorlevel 1 (
1503   path $_qtPrefixWin\bin;$_qtToolsMingwWin\bin;$_qtToolsMingwWin\opt\bin;C:\Python38;%PATH%
1504 )
1505 cmake -GNinja -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_INSTALL_PREFIX= -DWITH_FFMPEG=ON -DWITH_MP4V2=ON -DWITH_DOCBOOKDIR=${_docbookXslDirWin:-%HOME%/prg/docbook-xsl-1.72.0} ../../kid3
1506 EOF
1507       cat >kid3/run.bat <<EOF
1508 set thisdir=%~dp0
1509 echo ;%PATH%; | find /C /I ";$_qtPrefixWin\bin;"
1510 if errorlevel 1 (
1511   path $_qtPrefixWin\bin;$_qtToolsMingwWin\bin;$_qtToolsMingwWin\opt\bin;C:\Python38;%HOME%\prg\dumpbin;%PATH%
1512 )
1513 echo ;%PATH%; | find /C /I ";%thisdir%src\core;"
1514 if errorlevel 1 (
1515   path %thisdir%src\core;%thisdir%src\gui;%PATH%
1516 )
1517 set QT_PLUGIN_PATH=$_qtPrefixWin\plugins
1518 start src\app\qt\kid3
1519 EOF
1520     elif test "$compiler" = "gcc-debug"; then
1521       taglib_config_version=$taglib_version
1522       taglib_config_version=${taglib_config_version%beta*}
1523       cat >kid3/run-cmake.sh <<EOF
1524 #!/bin/bash
1525 BUILDPREFIX=\$(cd ..; pwd)/buildroot/usr/local
1526 export PKG_CONFIG_PATH=\$BUILDPREFIX/lib/pkgconfig
1527 cmake -GNinja -DBUILD_SHARED_LIBS=ON -DQT_QMAKE_EXECUTABLE=${QT_PREFIX}/bin/qmake -DLINUX_SELF_CONTAINED=ON -DWITH_READLINE=OFF -DWITH_TAGLIB=OFF -DHAVE_TAGLIB=1 -DTAGLIB_LIBRARIES:STRING="-L\$BUILDPREFIX/lib -ltag -lz" -DTAGLIB_CFLAGS:STRING="-I\$BUILDPREFIX/include/taglib -I\$BUILDPREFIX/include -DTAGLIB_STATIC" -DTAGLIB_VERSION:STRING="${taglib_config_version}" -DWITH_QML=ON -DCMAKE_CXX_FLAGS_DEBUG:STRING="-g -DID3LIB_LINKOPTION=1 -DFLAC__NO_DLL" -DCMAKE_INCLUDE_PATH=\$BUILDPREFIX/include -DCMAKE_LIBRARY_PATH=\$BUILDPREFIX/lib -DCMAKE_PROGRAM_PATH=\$BUILDPREFIX/bin -DWITH_FFMPEG=ON -DFFMPEG_ROOT=\$BUILDPREFIX -DWITH_MP4V2=ON $CMAKE_BUILD_OPTION -DWITH_APPS="Qt;CLI" -DCMAKE_INSTALL_PREFIX= -DWITH_BINDIR=. -DWITH_DATAROOTDIR=. -DWITH_DOCDIR=. -DWITH_TRANSLATIONSDIR=. -DWITH_LIBDIR=. -DWITH_PLUGINSDIR=./plugins ../../kid3
1528 EOF
1529     else
1530       taglib_config_version=$taglib_version
1531       taglib_config_version=${taglib_config_version%beta*}
1532       cat >kid3/run-cmake.sh <<EOF
1533 #!/bin/bash
1534 BUILDPREFIX=\$(cd ..; pwd)/buildroot/usr/local
1535 export PKG_CONFIG_PATH=\$BUILDPREFIX/lib/pkgconfig
1536 cmake -GNinja -DBUILD_SHARED_LIBS=ON -DLINUX_SELF_CONTAINED=ON -DWITH_TAGLIB=OFF -DHAVE_TAGLIB=1 -DTAGLIB_LIBRARIES:STRING="-L\$BUILDPREFIX/lib -ltag -lz" -DTAGLIB_CFLAGS:STRING="-I\$BUILDPREFIX/include/taglib -I\$BUILDPREFIX/include -DTAGLIB_STATIC" -DTAGLIB_VERSION:STRING="${taglib_config_version}" -DWITH_QML=ON -DCMAKE_CXX_FLAGS_DEBUG:STRING="-g -DID3LIB_LINKOPTION=1 -DFLAC__NO_DLL" -DCMAKE_INCLUDE_PATH=\$BUILDPREFIX/include -DCMAKE_LIBRARY_PATH=\$BUILDPREFIX/lib -DCMAKE_PROGRAM_PATH=\$BUILDPREFIX/bin -DWITH_FFMPEG=ON -DFFMPEG_ROOT=\$BUILDPREFIX -DWITH_MP4V2=ON $CMAKE_BUILD_OPTION -DWITH_APPS="Qt;CLI" -DCMAKE_INSTALL_PREFIX= -DWITH_BINDIR=. -DWITH_DATAROOTDIR=. -DWITH_DOCDIR=. -DWITH_TRANSLATIONSDIR=. -DWITH_LIBDIR=. -DWITH_PLUGINSDIR=./plugins ../../kid3
1537 EOF
1538     fi
1539     chmod +x kid3/run-cmake.sh
1540   fi
1541 
1542 fi # cross-android, else
1543 fi # libs
1544 
1545 if [[ $target = *"package"* ]]; then
1546   echo "### Building kid3 package"
1547 
1548   pushd kid3 >/dev/null
1549   if test -f run-cmake.sh && ! test -f Makefile && ! test -f build.ninja; then
1550     ./run-cmake.sh
1551   fi
1552   if test "$compiler" = "cross-mingw"; then
1553     ninja
1554     _version=$(grep VERSION config.h | cut -d'"' -f2)
1555     if test -z "${cross_host##x86_64*}"; then
1556       _gccDll=libgcc_s_seh-1.dll
1557       _instdir=kid3-$_version-win32-x64
1558     else
1559       _gccDll=libgcc_s_dw2-1.dll
1560       _instdir=kid3-$_version-win32
1561     fi
1562     test -d $_instdir && rm -rf $_instdir
1563     mkdir -p $_instdir
1564     DESTDIR=$(pwd)/$_instdir ninja install/strip
1565 
1566     _plugin_qt_version=$(grep "Created by.*Qt" src/plugins/musicbrainzimport/moc_musicbrainzimportplugin.cpp)
1567     _plugin_qt_version=${_plugin_qt_version##* \(Qt }
1568     _plugin_qt_version=${_plugin_qt_version%%\)*}
1569     _plugin_qt_version_nr=${_plugin_qt_version//./}
1570     if test $_plugin_qt_version_nr -gt ${qt_version//./}; then
1571       echo "Plugin Qt version $_plugin_qt_version is larger than Qt version $qt_version."
1572       echo "Loading plugins will fail!"
1573       exit 1
1574     fi
1575 
1576     cp -f translations/*.qm doc/*/kid3*.html $_instdir
1577 
1578     _qtBinDir=${QTPREFIX}/bin
1579     for f in Qt${qt_version_major}Core.dll Qt${qt_version_major}Network.dll Qt${qt_version_major}Gui.dll Qt${qt_version_major}Xml.dll Qt${qt_version_major}Widgets.dll Qt${qt_version_major}Multimedia.dll Qt${qt_version_major}Qml.dll Qt${qt_version_major}Quick.dll $_gccDll libstdc++-6.dll libwinpthread-1.dll; do
1580       cp $_qtBinDir/$f $_instdir
1581     done
1582 
1583     _qtTranslationsDir=${QTPREFIX}/translations
1584     for f in translations/*.qm; do
1585       l=${f#*_};
1586       l=${l%.qm};
1587       test -f $_qtTranslationsDir/qtbase_$l.qm && cp $_qtTranslationsDir/qtbase_$l.qm $_instdir
1588     done
1589 
1590     rm -f $_instdir.zip
1591     7z a $_instdir.zip $_instdir
1592   elif test "$compiler" = "cross-macos"; then
1593     test -z ${PATH##$osxprefix/*} || PATH=$osxprefix/bin:$osxsdk/usr/bin:$PATH
1594     rm -rf inst
1595     DESTDIR=$(pwd)/inst ninja install/strip
1596     ln -s /Applications inst/Applications
1597     genisoimage -V "Kid3" -D -R -apple -no-pad -o uncompressed.dmg inst
1598     _version=$(grep VERSION config.h | cut -d'"' -f2)
1599     dmg dmg uncompressed.dmg kid3-$_version-Darwin.dmg
1600     rm uncompressed.dmg
1601   elif test "$compiler" = "cross-android"; then
1602     JAVA_HOME=$(grep _java_root= run-cmake.sh | cut -d'=' -f2) make apk
1603     _version=$(grep VERSION config.h | cut -d'"' -f2)
1604     for prefix in android/build/outputs/apk/release/android-release android/build/outputs/apk/android-release android/bin/QtApp-release; do
1605       for suffix in signed unsigned; do
1606         _apkpath=${prefix}-${suffix}.apk
1607         if test -f $_apkpath; then
1608           cp -a $_apkpath kid3-$_version-android.apk
1609           break 2
1610         fi
1611       done
1612     done
1613   elif test "$compiler" = "gcc-self-contained"; then
1614     ninja package
1615     _tgz=(kid3-*-Linux.tar.gz)
1616     test -f "$_tgz" && mv $_tgz ${_tgz%%tar.gz}tgz
1617   elif test "$compiler" = "gcc-debug"; then
1618     ninja
1619   else
1620     if test -f build.ninja; then
1621       ninja package
1622     else
1623       make package
1624     fi
1625   fi
1626   popd >/dev/null
1627 fi # package
1628 
1629 echo "### Built successfully"