FROM windows-clang
ARG JOBS_COUNT=16
ARG LIBS_BUILD_NUMBER=9999

ENV CUR_QT_VERSION=6.9.2

RUN  wget -nv http://shstk.ru/files/qt-all-${CUR_QT_VERSION}.zip \
 && unzip -o qt-all-${CUR_QT_VERSION}.zip -d /soft/qt \
 && rm -f qt-all-${CUR_QT_VERSION}.zip
COPY create_links.sh /soft/qt/gcc_64/lib/create_links.sh
RUN cd /soft/qt/gcc_64/lib/ && chmod +x ./create_links.sh && sh ./create_links.sh
RUN chmod +x /soft/qt/gcc_64/libexec/*
RUN chmod +x /soft/qt/gcc_64/bin/*
 
RUN ln -s /usr/x86_64-w64-mingw32/include/windows.h /usr/x86_64-w64-mingw32/include/Windows.h

WORKDIR /soft
RUN echo "hello!"
RUN git clone -b master --single-branch --depth 1 --recursive https://git.shstk.ru/SHS/shstk.git

WORKDIR /soft/shstk_build_host
RUN cmake -G Ninja -DICU=0 -DCROSSTOOLS=1 -DBUILD_NUMBER=${LIBS_BUILD_NUMBER} ../shstk \
 && cmake --build ./ --target install -j${JOBS_COUNT} \
 && rm -rf ./* && ldconfig

WORKDIR /soft/shstk_build_windows
RUN cmake -G Ninja -DCMAKE_BUILD_TYPE=Release \
 -DCMAKE_TOOLCHAIN_FILE=/soft/toolchain-Windows.cmake \
 -DCMAKE_INSTALL_PREFIX=/soft/windows \
 -DCMAKE_PREFIX_PATH=/soft/qt/mingw_64 \
 -DQT_HOST_PATH=/soft/qt/gcc_64 \
 -DICU=0 -DLOCAL=1 -DQGLENGINE=1 -DQGLVIEW=0 -DPIP_BUILD_OPENCL=0 -DBUILD_NUMBER=${LIBS_BUILD_NUMBER} \
 -DOpenCL_INCLUDE_DIRS=/soft/windows/include \
 ../shstk/ \
 && cmake --build ./ --target install -j${JOBS_COUNT} && rm -rf ./*

#RUN git clone -b v8 --single-branch --depth 1 https://git.shstk.ru/SHS/qtcreator.git /soft/qt-creator-plugins
#rm /soft/toolchain-Windows.cmake
#cp toolchain-Windows.cmake clangformatbaseindenter.patch clangformatutils.patch /soft/
#apt-get update && apt-get install -y qttools5-dev-tools
#cp -vf /usr/bin/qhelpgenerator /usr/bin/qcollectiongenerator /usr/x86_64-w64-mingw32/lib/zlib1.dll /soft/windows/bin/

#WORKDIR /soft
#RUN git clone -b "8.0" --depth 1 --recursive https://github.com/qt-creator/qt-creator.git /soft/qt-creator
#RUN patch /soft/qt-creator/src/plugins/clangformat/clangformatbaseindenter.cpp /soft/qt-creator-plugins/build_files/clangformatbaseindenter.patch
#RUN patch /soft/qt-creator/src/plugins/clangformat/clangformatutils.cpp /soft/qt-creator-plugins/build_files/clangformatutils.patch

WORKDIR /soft
#RUN git clone -b "15.0" --depth 1 --recursive https://github.com/qt-creator/qt-creator.git
#RUN git clone -b "v18.0.2" --depth 1 --recursive https://github.com/qt-creator/qt-creator.git
RUN git clone -b "v19.0.0" --depth 1 --recursive https://github.com/qt-creator/qt-creator.git

RUN wget https://go.dev/dl/go1.25.4.linux-amd64.tar.gz && tar -xf /soft/go*.linux-amd64.tar.gz -C /soft/windows/
ENV PATH=/soft/windows/go/bin:$PATH

WORKDIR /soft/qt-creator_build
RUN cmake -DCMAKE_BUILD_TYPE=Release \
 -DCMAKE_TOOLCHAIN_FILE=/soft/toolchain-Windows.cmake \
 -DCMAKE_INSTALL_PREFIX=/soft/windows/qt-creator \
 -DCMAKE_PREFIX_PATH=/soft/qt/mingw_64 \
 -DQT_HOST_PATH=/soft/qt/gcc_64 \
 -DQT_NO_PRIVATE_MODULE_WARNING=1 \
 -DWITH_QMLDESIGNER=0 \
 -DBUILD_WITH_PCH=0 \
 -Drcc_OPTIONS="--no-zstd" \
 ../qt-creator
RUN make -k -j${JOBS_COUNT} || true
RUN make -k -j${JOBS_COUNT} -i install || true

WORKDIR /soft/windows/qt-creator
RUN cp -vfr /soft/qt/mingw_64/plugins ./
RUN cp -vfr /soft/qt/mingw_64/qml ./
RUN cp -vfr /soft/qt/mingw_64/translations ./
RUN mv -vf ./libexec/qtcreator/* ./bin/ && rm -rf ./libexec
