# Dockerfile to build aria2 Windows binary using ubuntu mingw-w64 # cross compiler chain. # # $ sudo docker build -t aria2-mingw -f Dockerfile.mingw . # # After successful build, windows binary is located at # /aria2/src/aria2c.exe. You can copy the binary to the current dir # using following command (replace $PWD with any other full path if desired): # # $ sudo docker run --rm -v $PWD:/output aria2-mingw # Additional arguments can be set with --build-arg. For example, to build local source code instead of # the latest master on github, set SOURCE=local: # # $ sudo docker build -t aria2-mingw -f Dockerfile.mingw --build-arg SOURCE=local . # # Available build parameters: # SOURCE - "git" (default) to use Aria2 code from github. "local" to copy current directory. # GIT_TAG - if SOURCE=git (default), set which branch or tag to download. # LIBARIA2 - disable (default) / enable -- should the libaria2 library be built # ARIA2_STATIC - yes (default) / no -- compile as a dynamic or static code # # Note that LIBARIA2 and ARIA2_STATIC params might not work for older versions. # ARG SOURCE=git ARG GIT_TAG=master ARG LIBARIA2=disable ARG ARIA2_STATIC=yes FROM ubuntu:20.04 as build_base MAINTAINER Tatsuhiro Tsujikawa # Change HOST to x86_64-w64-mingw32 to build 64-bit binary ENV HOST i686-w64-mingw32 # It would be better to use nearest ubuntu archive mirror for faster # downloads. # RUN sed -ie 's/archive\.ubuntu/jp.archive.ubuntu/g' /etc/apt/sources.list RUN apt-get update && \ DEBIAN_FRONTEND="noninteractive" \ apt-get install -y --no-install-recommends \ make binutils autoconf automake autotools-dev libtool \ patch ca-certificates \ pkg-config git curl dpkg-dev gcc-mingw-w64 g++-mingw-w64 \ autopoint libcppunit-dev libxml2-dev libgcrypt20-dev lzip RUN curl -L -O https://gmplib.org/download/gmp/gmp-6.2.1.tar.lz && \ curl -L -O https://github.com/libexpat/libexpat/releases/download/R_2_4_1/expat-2.4.1.tar.bz2 && \ curl -L -O https://www.sqlite.org/2021/sqlite-autoconf-3360000.tar.gz && \ curl -L -O http://zlib.net/zlib-1.2.11.tar.gz && \ curl -L -O https://c-ares.haxx.se/download/c-ares-1.17.2.tar.gz && \ curl -L -O https://www.libssh2.org/download/libssh2-1.9.0.tar.gz && \ curl -L -O https://github.com/libssh2/libssh2/commit/ba149e804ef653cc05ed9803dfc94519ce9328f7.patch RUN tar xf gmp-6.2.1.tar.lz && \ cd gmp-6.2.1 && \ ./configure \ --disable-shared \ --enable-static \ --prefix=/usr/local/$HOST \ --host=$HOST \ --disable-cxx \ --enable-fat \ CFLAGS="-mtune=generic -O2 -g0" && \ make install RUN tar xf expat-2.4.1.tar.bz2 && \ cd expat-2.4.1 && \ ./configure \ --disable-shared \ --enable-static \ --prefix=/usr/local/$HOST \ --host=$HOST \ --build=`dpkg-architecture -qDEB_BUILD_GNU_TYPE` && \ make install RUN tar xf sqlite-autoconf-3360000.tar.gz && \ cd sqlite-autoconf-3360000 && \ ./configure \ --disable-shared \ --enable-static \ --prefix=/usr/local/$HOST \ --host=$HOST \ --build=`dpkg-architecture -qDEB_BUILD_GNU_TYPE` && \ make install RUN tar xf zlib-1.2.11.tar.gz && \ cd zlib-1.2.11 && \ CC=$HOST-gcc \ AR=$HOST-ar \ LD=$HOST-ld \ RANLIB=$HOST-ranlib \ STRIP=$HOST-strip \ ./configure \ --prefix=/usr/local/$HOST \ --libdir=/usr/local/$HOST/lib \ --includedir=/usr/local/$HOST/include \ --static && \ make install RUN tar xf c-ares-1.17.2.tar.gz && \ cd c-ares-1.17.2 && \ ./configure \ --disable-shared \ --enable-static \ --without-random \ --prefix=/usr/local/$HOST \ --host=$HOST \ --build=`dpkg-architecture -qDEB_BUILD_GNU_TYPE` \ LIBS="-lws2_32" && \ make install RUN tar xf libssh2-1.9.0.tar.gz && \ cd libssh2-1.9.0 && \ patch -p1 < ../ba149e804ef653cc05ed9803dfc94519ce9328f7.patch && \ ./configure \ --disable-shared \ --enable-static \ --prefix=/usr/local/$HOST \ --host=$HOST \ --build=`dpkg-architecture -qDEB_BUILD_GNU_TYPE` \ --without-openssl \ --with-wincng \ LIBS="-lws2_32" && \ make install # # The above "build_base" stage builds common steps, # before copying/downloading aria2 source code. The following # two steps will either copy sources from the local dir, # or will download a specific tag/branch from github. # The last stage will use the needed stage, running the delayed steps. # ARG SOURCE GIT_TAG LIBARIA2 ARIA2_STATIC FROM build_base as build_local ONBUILD COPY . /aria2 ARG SOURCE GIT_TAG LIBARIA2 ARIA2_STATIC FROM build_base as build_git ONBUILD ADD https://api.github.com/repos/aria2/aria2/git/refs/heads/${GIT_TAG} version.json ONBUILD RUN echo "Downloading '${GIT_TAG}' from https://github.com/aria2/aria2" && \ git clone https://github.com/aria2/aria2 --depth 1 --branch "${GIT_TAG}" ARG SOURCE GIT_TAG LIBARIA2 ARIA2_STATIC FROM build_${SOURCE} RUN cd /aria2 && \ autoreconf -i && \ export LIBARIA2=${LIBARIA2} && \ export ARIA2_STATIC=${ARIA2_STATIC} && \ ./mingw-config && \ make && \ (test -f /aria2/src/aria2c.exe && $HOST-strip /aria2/src/aria2c.exe) && \ (test -f /aria2/src/main.o && $HOST-strip /aria2/src/main.o) CMD test ! -d /output && \ echo 'The /output dir is not set. Use "docker run -v $PWD:/output ..." to copy build results into the current dir. To explore this container, append "bash" at the end of docker run command.' || \ cp -v /aria2/src/aria2c.exe* /aria2/src/main.o /output