FROM ubuntu:14.04
MAINTAINER Chris Cannam <cannam@all-day-breakfast.com>
RUN apt-get update && \
    apt-get install -y \
    software-properties-common \
    build-essential \
    libbz2-dev \
    libxml2-utils \
    libgl1-mesa-dev \
    git \
    mercurial \
    curl wget \
    mlton \
    autoconf automake libtool lintian

RUN apt-add-repository -y ppa:beineri/opt-qt-5.10.1-trusty
RUN apt-get update && \
    apt-get install -y \
    qt510base \
    qt510svg
RUN apt-get clean && rm -rf /var/lib/apt/lists/*

RUN locale-gen en_US.UTF-8
ENV LANG en_US.UTF-8  
ENV LANGUAGE en_US:en  
ENV LC_ALL en_US.UTF-8

# Ensure that everything subsequent is re-run when a new revision is
# being built (rather than being cached)
RUN echo [[REVISION]]

WORKDIR /root
COPY id_dsa_build .ssh/id_dsa_build
COPY known_hosts .ssh/known_hosts
RUN chmod 600 .ssh/id_dsa_build .ssh/known_hosts
RUN echo '{"accounts": {"bitbucket": "cannam"}}' > .repoint.json
RUN ( echo '[ui]' ; echo 'ssh = ssh -i /root/.ssh/id_dsa_build' ) > .hgrc

WORKDIR /
RUN hg clone -r[[REVISION]] ssh://hg@bitbucket.org/cannam/easyhg

WORKDIR /easyhg
COPY appimagetool-x86_64.AppImage appimagetool-x86_64.AppImage
RUN chmod +x appimagetool-x86_64.AppImage
ENV QTDIR /opt/qt510
ENV PATH /opt/qt510/bin:$PATH
RUN qmake -r
RUN make

RUN hg clone https://code.soundsoftware.ac.uk/hg/easyhg-kdiff3 easyhg-kdiff3-src
WORKDIR easyhg-kdiff3-src/kdiff3/src-QT4
RUN qmake -r kdiff3.pro
RUN make
RUN cp kdiff3 ../../../easyhg-kdiff3

WORKDIR /easyhg
RUN deploy/linux/deploy-appimage.sh
RUN tar cvf output-appimage.tar *.AppImage && cp output-appimage.tar ..
