12c593315Sopenharmony_ci# vim: ft=dockerfile:
22c593315Sopenharmony_ci# Dockerfile to build nghttp2 android binary
32c593315Sopenharmony_ci#
42c593315Sopenharmony_ci# $ sudo docker build -t nghttp2-android - < Dockerfile.android
52c593315Sopenharmony_ci#
62c593315Sopenharmony_ci# After successful build, android binaries are located under
72c593315Sopenharmony_ci# /root/build/nghttp2.  You can copy the binary using docker cp.  For
82c593315Sopenharmony_ci# example, to copy nghttpx binary to host file system location
92c593315Sopenharmony_ci# /path/to/dest, do this:
102c593315Sopenharmony_ci#
112c593315Sopenharmony_ci# $ sudo docker run -v /path/to/dest:/out nghttp2-android cp /root/build/nghttp2/src/nghttpx /out
122c593315Sopenharmony_ci
132c593315Sopenharmony_ci
142c593315Sopenharmony_ci# Only use standalone-toolchain for reduce size
152c593315Sopenharmony_ciFROM ubuntu:22.04
162c593315Sopenharmony_ciMAINTAINER Tatsuhiro Tsujikawa
172c593315Sopenharmony_ci
182c593315Sopenharmony_ciENV NDK_VERSION r25b
192c593315Sopenharmony_ciENV NDK /root/android-ndk-$NDK_VERSION
202c593315Sopenharmony_ciENV TOOLCHAIN $NDK/toolchains/llvm/prebuilt/linux-x86_64
212c593315Sopenharmony_ciENV TARGET aarch64-linux-android
222c593315Sopenharmony_ciENV API 33
232c593315Sopenharmony_ciENV AR $TOOLCHAIN/bin/llvm-ar
242c593315Sopenharmony_ciENV CC $TOOLCHAIN/bin/$TARGET$API-clang
252c593315Sopenharmony_ciENV CXX $TOOLCHAIN/bin/$TARGET$API-clang++
262c593315Sopenharmony_ciENV LD $TOOLCHAIN/bin/ld
272c593315Sopenharmony_ciENV RANDLIB $TOOLCHAIN/bin/llvm-ranlib
282c593315Sopenharmony_ciENV STRIP $TOOLCHAIN/bin/llvm-strip
292c593315Sopenharmony_ciENV PREFIX /root/usr/local
302c593315Sopenharmony_ci
312c593315Sopenharmony_ciWORKDIR /root
322c593315Sopenharmony_ciRUN apt-get update && \
332c593315Sopenharmony_ci    apt-get install -y unzip make binutils autoconf \
342c593315Sopenharmony_ci      automake autotools-dev libtool pkg-config git \
352c593315Sopenharmony_ci      curl dpkg-dev libxml2-dev genisoimage libc6-i386 \
362c593315Sopenharmony_ci      lib32stdc++6 && \
372c593315Sopenharmony_ci    rm -rf /var/cache/apt/*
382c593315Sopenharmony_ci
392c593315Sopenharmony_ci# Download NDK
402c593315Sopenharmony_ciRUN curl -L -O https://dl.google.com/android/repository/android-ndk-$NDK_VERSION-linux.zip && \
412c593315Sopenharmony_ci   unzip -q android-ndk-$NDK_VERSION-linux.zip && \
422c593315Sopenharmony_ci   rm android-ndk-$NDK_VERSION-linux.zip
432c593315Sopenharmony_ci
442c593315Sopenharmony_ci# Setup version of libraries
452c593315Sopenharmony_ciENV OPENSSL_VERSION 1.1.1q
462c593315Sopenharmony_ciENV LIBEV_VERSION 4.33
472c593315Sopenharmony_ciENV ZLIB_VERSION 1.2.13
482c593315Sopenharmony_ciENV CARES_VERSION 1.18.1
492c593315Sopenharmony_ciENV NGHTTP2_VERSION master
502c593315Sopenharmony_ci
512c593315Sopenharmony_ciWORKDIR /root/build
522c593315Sopenharmony_ciRUN curl -L -O https://www.openssl.org/source/openssl-$OPENSSL_VERSION.tar.gz && \
532c593315Sopenharmony_ci    tar xf openssl-$OPENSSL_VERSION.tar.gz && \
542c593315Sopenharmony_ci    rm openssl-$OPENSSL_VERSION.tar.gz
552c593315Sopenharmony_ci
562c593315Sopenharmony_ciWORKDIR /root/build/openssl-$OPENSSL_VERSION
572c593315Sopenharmony_ciRUN export ANDROID_NDK_HOME=$NDK PATH=$TOOLCHAIN/bin:$PATH && \
582c593315Sopenharmony_ci    ./Configure no-shared --prefix=$PREFIX android-arm64 && \
592c593315Sopenharmony_ci    make && make install_sw
602c593315Sopenharmony_ci
612c593315Sopenharmony_ciWORKDIR /root/build
622c593315Sopenharmony_ciRUN curl -L -O http://dist.schmorp.de/libev/Attic/libev-$LIBEV_VERSION.tar.gz && \
632c593315Sopenharmony_ci    tar xf libev-$LIBEV_VERSION.tar.gz && \
642c593315Sopenharmony_ci    rm libev-$LIBEV_VERSION.tar.gz
652c593315Sopenharmony_ci
662c593315Sopenharmony_ciWORKDIR /root/build/libev-$LIBEV_VERSION
672c593315Sopenharmony_ciRUN ./configure \
682c593315Sopenharmony_ci    --host=$TARGET \
692c593315Sopenharmony_ci    --build=`dpkg-architecture -qDEB_BUILD_GNU_TYPE` \
702c593315Sopenharmony_ci    --prefix=$PREFIX \
712c593315Sopenharmony_ci    --disable-shared \
722c593315Sopenharmony_ci    --enable-static \
732c593315Sopenharmony_ci    CPPFLAGS=-I$PREFIX/include \
742c593315Sopenharmony_ci    LDFLAGS=-L$PREFIX/lib && \
752c593315Sopenharmony_ci    make install
762c593315Sopenharmony_ci
772c593315Sopenharmony_ciWORKDIR /root/build
782c593315Sopenharmony_ciRUN curl -L -O https://zlib.net/zlib-$ZLIB_VERSION.tar.gz && \
792c593315Sopenharmony_ci    tar xf zlib-$ZLIB_VERSION.tar.gz && \
802c593315Sopenharmony_ci    rm zlib-$ZLIB_VERSION.tar.gz
812c593315Sopenharmony_ci
822c593315Sopenharmony_ciWORKDIR /root/build/zlib-$ZLIB_VERSION
832c593315Sopenharmony_ciRUN HOST=$TARGET \
842c593315Sopenharmony_ci    ./configure \
852c593315Sopenharmony_ci    --prefix=$PREFIX \
862c593315Sopenharmony_ci    --libdir=$PREFIX/lib \
872c593315Sopenharmony_ci    --includedir=$PREFIX/include \
882c593315Sopenharmony_ci    --static && \
892c593315Sopenharmony_ci    make install
902c593315Sopenharmony_ci
912c593315Sopenharmony_ci
922c593315Sopenharmony_ciWORKDIR /root/build
932c593315Sopenharmony_ciRUN curl -L -O https://c-ares.haxx.se/download/c-ares-$CARES_VERSION.tar.gz && \
942c593315Sopenharmony_ci    tar xf c-ares-$CARES_VERSION.tar.gz && \
952c593315Sopenharmony_ci    rm c-ares-$CARES_VERSION.tar.gz
962c593315Sopenharmony_ci
972c593315Sopenharmony_ciWORKDIR /root/build/c-ares-$CARES_VERSION
982c593315Sopenharmony_ciRUN ./configure \
992c593315Sopenharmony_ci      --host=$TARGET \
1002c593315Sopenharmony_ci      --build=`dpkg-architecture -qDEB_BUILD_GNU_TYPE` \
1012c593315Sopenharmony_ci      --prefix=$PREFIX \
1022c593315Sopenharmony_ci      --disable-shared && \
1032c593315Sopenharmony_ci    make install
1042c593315Sopenharmony_ci
1052c593315Sopenharmony_ciWORKDIR /root/build
1062c593315Sopenharmony_ciRUN git clone https://github.com/nghttp2/nghttp2 -b $NGHTTP2_VERSION --depth 1
1072c593315Sopenharmony_ciWORKDIR /root/build/nghttp2
1082c593315Sopenharmony_ciRUN autoreconf -i && \
1092c593315Sopenharmony_ci    ./configure \
1102c593315Sopenharmony_ci    --enable-app \
1112c593315Sopenharmony_ci    --disable-shared \
1122c593315Sopenharmony_ci    --host=$TARGET \
1132c593315Sopenharmony_ci    --build=`dpkg-architecture -qDEB_BUILD_GNU_TYPE` \
1142c593315Sopenharmony_ci    --without-libxml2 \
1152c593315Sopenharmony_ci    --disable-examples \
1162c593315Sopenharmony_ci    --disable-threads \
1172c593315Sopenharmony_ci      CPPFLAGS="-fPIE -I$PREFIX/include" \
1182c593315Sopenharmony_ci      PKG_CONFIG_LIBDIR="$PREFIX/lib/pkgconfig" \
1192c593315Sopenharmony_ci      LDFLAGS="-fPIE -pie -L$PREFIX/lib" && \
1202c593315Sopenharmony_ci    make && \
1212c593315Sopenharmony_ci    $STRIP src/nghttpx src/nghttpd src/nghttp
122