# Taken from https://github.com/fffaraz/docker-qt
# Example usage:
#   $ docker build --force-rm -t fulcrum-builder/qt6:linux .
#   $ docker run --rm -it -v $(pwd):/work fulcrum-builder/qt6:linux
FROM ubuntu:focal
LABEL maintainer="Calin Culianu <calin.culianu@gmail.com>"
ENTRYPOINT ["/bin/bash"]

ENV DEBIAN_FRONTEND=noninteractive
ENV LC_ALL=C.UTF-8

RUN \
    apt -qy update && \
    apt -qy upgrade && \
    apt -qy install build-essential pkg-config cmake gdb git iputils-ping nano perl python3 valgrind wget autoconf && \
    apt -qy install libbz2-dev zlib1g-dev libssl-dev libgnutls30 libnss3-dev libxslt-dev libxml2-dev  && \
    apt -qy autoremove && \
    apt -qy autoclean

RUN \
    apt -qy install software-properties-common && \
    add-apt-repository -y ppa:ubuntu-toolchain-r/test && \
    apt -qy update && \
    apt -qy install gcc-13 g++-13 cpp-13 && \
    update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-13 131 \
                        --slave /usr/bin/g++ g++ /usr/bin/g++-13 \
                        --slave /usr/bin/gcov gcov /usr/bin/gcov-13 && \
    apt -qy autoremove && \
    apt -qy autoclean

# Install latest CMake 3.25.x (bionic, focal, or jammy only)
RUN \
    add-apt-repository -y ppa:ecal/cmake-3.25 && \
    apt -qy update && \
    apt -y install cmake ninja-build && \
    apt -qy autoremove && apt -qy autoclean

# Ensure we statically link libstdc++ otherwise produced binaries won't be compatible with stock systems
ENV LDFLAGS="-static-libstdc++"

RUN \
    mkdir -p /opt/local/qt && \
    cd /opt && \
    echo "💬  \033[1;36mDownloading Qt sources ...\033[0m" && \
    wget -q https://download.qt.io/official_releases/qt/6.10/6.10.0/single/qt-everywhere-src-6.10.0.tar.xz && \
    echo "💬  \033[1;36mExtracting archive ...\033[0m" && \
    tar -xf qt-everywhere-src-6.10.0.tar.xz && \
    rm qt-everywhere-src-6.10.0.tar.xz && \
    cd qt-everywhere-src-6.10.0 && \
    echo "💬  \033[1;36mConfiguring Qt ...\033[0m" && \
    ./configure -opensource -confirm-license -release -static -make libs -nomake tests -nomake examples -nomake tools \
        -prefix /opt/local/qt -no-gui -no-sse2 -no-sse3 -no-ssse3 -no-sse4.1 -no-sse4.2 -no-avx -no-avx2 -no-avx512 \
        -openssl-linked -no-shared -c++std c++20 -no-widgets -no-dbus -no-cups -no-freetype -no-fontconfig -no-gif \
        -no-ico -no-libpng -no-libjpeg -strip -no-opengl -no-glib -no-harfbuzz -no-sql-sqlite -no-sql-mysql \
        -qpa linuxfb -no-feature-accessibility -no-linuxfb -no-xcb -no-feature-sqlmodel -no-feature-itemmodeltester \
        -no-feature-sessionmanager -no-feature-vnc -no-icu -qt-pcre -system-zlib -no-tiff -no-webp -no-libinput \
        -no-feature-action -no-feature-animation -no-feature-clipboard -no-feature-cups -no-feature-cursor \
        -no-feature-desktopservices -no-feature-draganddrop -no-feature-jalalicalendar -no-feature-movie \
        -no-feature-pdf -no-feature-picture -no-feature-valgrind -skip multimedia -skip serialbus -skip tools \
        -skip gamepad -skip serialport -skip sensors -skip quickcontrols2 -skip speech -no-sbom -no-jemalloc \
        -no-gtk -skip qt3d -skip qt5compat -skip qtactiveqt -skip qtcharts -skip qtcoap -skip qtconnectivity \
        -skip qtdatavis3d -skip qtdeclarative -skip qtdoc -skip qtgraphs -skip qtgrpc -skip qthttpserver \
        -skip qtimageformats -skip qtlanguageserver -skip qtlocation -skip qtlottie -skip qtmqtt -skip qtmultimedia \
        -skip qtnetworkauth -skip qtopcua -skip qtpositioning -skip qtquick3d -skip qtquick3dphysics \
        -skip qtquickeffectmaker -skip qtquicktimeline -skip qtremoteobjects -skip qtscxml -skip qtsensors \
        -skip qtserialbus -skip qtserialport -skip qtshadertools -skip qtspeech -skip qtsvg -skip qttools \
        -skip qttranslations -skip qtvirtualkeyboard -skip qtwayland -skip qtwebchannel -skip qtwebengine \
        -skip qtwebsockets -skip qtwebview -no-feature-xml -no-feature-testlib -no-feature-sql -no-feature-concurrent && \
    echo "" && echo "💬  \033[1;36mCompiling Qt ...\033[0m" && \
    cmake --build . --parallel && \
    echo "" && echo "💬  \033[1;36mInstalling Qt ...\033[0m" && \
    cmake --install . && \
    cd /opt && \
    echo "" && echo "💬  \033[1;36mCleaning up ...\033[0m" && \
    rm -rf qt-everywhere-src-6.10.0 && \
    echo "" && echo "👍  \033[1;32mGCC Version:\033[0m" && \
    gcc --version && \
    echo "👍  \033[1;32mQt Version:\033[0m" && \
    /opt/local/qt/bin/qmake --version

ENV PATH="${PATH}:/opt/local/qt/bin"
ENV FORCE_STATIC_SSL=1
