FROM ubuntu:14.04
MAINTAINER Junegunn Choi <junegunn.c@gmail.com>

# apt-get
RUN apt-get update && apt-get -y upgrade && \
    apt-get install -y --force-yes git curl build-essential

# Install Go 1.4
RUN cd / && curl \
    https://storage.googleapis.com/golang/go1.4.2.linux-amd64.tar.gz | \
    tar -xz && mv go go1.4 && \
    sed -i 's@#define PTHREAD_KEYS_MAX 128@@' /go1.4/src/runtime/cgo/gcc_android_arm.c

ENV GOPATH /go
ENV GOROOT /go1.4
ENV PATH /go1.4/bin:$PATH

RUN cd / && \
    curl -O http://dl.google.com/android/ndk/android-ndk-r10e-linux-x86_64.bin && \
    chmod 755 /android-ndk* && /android-ndk-r10e-linux-x86_64.bin && \
    mv android-ndk-r10e /android-ndk

RUN cd /android-ndk && bash ./build/tools/make-standalone-toolchain.sh --platform=android-21 --install-dir=/ndk --arch=arm

ENV NDK_CC /ndk/bin/arm-linux-androideabi-gcc

RUN cd $GOROOT/src && \
    CC_FOR_TARGET=$NDK_CC GOOS=android GOARCH=arm GOARM=7 ./make.bash

RUN cd / && curl \
    http://ftp.gnu.org/gnu/ncurses/ncurses-5.9.tar.gz | \
    tar -xz && cd /ncurses-5.9 && \
    ./configure CC=$NDK_CC CFLAGS="-fPIE -march=armv7-a -mfpu=neon -mhard-float -Wl,--no-warn-mismatch" LDFLAGS="-march=armv7-a -Wl,--no-warn-mismatch" --host=arm-linux --enable-overwrite --enable-const --without-cxx-binding  --without-shared --without-debug --enable-widec --enable-ext-colors --enable-ext-mouse --enable-pc-files --with-pkg-config-libdir=$PKG_CONFIG_LIBDIR --without-manpages --without-ada --disable-shared --without-tests --prefix=/ndk/sysroot/usr --with-default-terminfo-dirs=/usr/share/terminfo --with-terminfo-dirs=/usr/share/terminfo ac_cv_header_locale_h=n ac_cv_func_getpwent=no ac_cv_func_getpwnam=no ac_cv_func_getpwuid=no && \
    sed -i 's@#define HAVE_LOCALE_H 1@/* #undef HAVE_LOCALE_H */@' include/ncurses_cfg.h && \
    make && \
    sed -i '0,/echo.*/{s/echo.*/exit 0/}' misc/run_tic.sh && \
    make install && \
    mv /ndk/sysroot/usr/lib/libncursesw.a /ndk/sysroot/usr/lib/libncurses.a

# Volume
VOLUME /go

# Default CMD
CMD cd /go/src/github.com/junegunn/fzf/src && /bin/bash
