# Note 22.04 was the first LTS with Qt6
FROM ubuntu:22.04
MAINTAINER Chris Cannam <cannam@all-day-breakfast.com>
RUN apt-get update && \
    apt-get install -y \
    software-properties-common \
    build-essential \
    libbz2-dev \
    libfftw3-dev \
    libfishsound1-dev \
    libid3tag0-dev \
    liblo-dev \
    liblrdf0-dev \
    libmad0-dev \
    liboggz2-dev \
    libopus-dev \
    libopusfile-dev \
    libpulse-dev \
    libasound2-dev \
    libjack-dev \
    libsamplerate-dev \
    libsndfile-dev \
    libsord-dev \
    libxml2-utils \
    qt6-base-dev \
    qt6-pdf-dev \
    qt6-base-dev-tools \
    libqt6svg6-dev \
    raptor2-utils \
    git \
    mercurial \
    autoconf \
    automake \
    libtool \
    lintian \
    curl \
    wget \
    unzip \
    smlnj \
    ninja-build \
    libglib2.0-dev \
    python3-pip

RUN apt-get clean && rm -rf /var/lib/apt/lists/*

RUN git config --global http.postBuffer 4M

WORKDIR /root
RUN pip3 install meson

WORKDIR /root
RUN git clone https://github.com/sandstorm-io/capnproto
WORKDIR capnproto
RUN git checkout v1.0.2
WORKDIR c++
RUN autoreconf -i && ./configure --enable-shared=no --enable-static=yes && make -j3 && make install

WORKDIR /root
RUN wget https://breakfastquay.com/files/releases/rubberband-4.0.0.tar.bz2
RUN tar xvjf rubberband-4.0.0.tar.bz2
WORKDIR rubberband-4.0.0
RUN meson setup build -Ddefault_library=static && ninja -C build && ninja -C build install

WORKDIR /root

COPY id_rsa_build .ssh/id_rsa_build
COPY known_hosts .ssh/known_hosts
RUN chmod 600 .ssh/id_rsa_build .ssh/known_hosts
RUN echo '{"accounts": {"sourcehut": "~breakfastquay"}}' > .repoint.json
RUN ( echo '[ui]' ; echo 'ssh = ssh -i /root/.ssh/id_rsa_build' ) > .hgrc

# The explicit revision number here is to make sure the following git
# clone is not cached from a different revision
RUN echo Cloning revision [[REVISION]]

RUN git clone https://github.com/sonic-visualiser/sonic-visualiser
WORKDIR sonic-visualiser
RUN git checkout [[REVISION]]

RUN ./repoint install
RUN meson setup build --buildtype release
RUN ninja -C build

RUN deploy/linux/deploy-deb.sh [[RELEASE]] amd64
RUN tar cvf output-deb.tar *.deb && cp output-deb.tar /tmp/
